1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 *
22 * Based on the original sources
23 * Faery Tale II -- The Halls of the Dead
24 * (c) 1993-1996 The Wyrmkeep Entertainment Co.
25 */
26
27 #include "common/config-manager.h"
28
29 #include "saga2/saga2.h"
30 #include "saga2/display.h"
31 #include "saga2/intrface.h"
32 #include "saga2/loadmsg.h"
33 #include "saga2/grabinfo.h"
34 #include "saga2/vpal.h"
35
36 namespace Saga2 {
37
38 extern bool delayReDraw;
39 extern BackWindow *mainWindow; // main window...
40
41 /* ===================================================================== *
42 Globals
43 * ===================================================================== */
44
45 bool paletteMayHaveChanged = false;
46
47
48 /* ===================================================================== *
49 Locals
50 * ===================================================================== */
51
52 static uint32 displayStatus = GraphicsInit;
53 static bool paletteSuspendFlag = false;
54
55
56 /* ===================================================================== *
57 Prototypes
58 * ===================================================================== */
59
60 void reDrawScreen(void);
61 void localCursorOn(void);
62 void localCursorOff(void);
63 void loadingScreen(void);
64 void resetInputDevices(void);
65 APPFUNC(cmdWindowFunc); // main window event handler
66 static void switchOn(void);
67 static void switchOff(void);
68
69 // ------------------------------------------------------------------------
70 // end game (normally)
71
endGame(void)72 void endGame(void) {
73 blackOut();
74 displayDisable(GameEnded);
75 g_vm->_gameRunning = false;
76 }
77
78
79 /* ===================================================================== *
80 Display initialization
81 * ===================================================================== */
82 void dayNightUpdate(void);
83 void fadeUp(void);
84 void displayUpdate(void);
85 void drawMainDisplay(void);
86
niceScreenStartup(void)87 void niceScreenStartup(void) {
88 if (ConfMan.hasKey("save_slot")) {
89 cleanupGameState();
90 loadSavedGameState(ConfMan.getInt("save_slot"));
91
92 if (GameMode::newmodeFlag)
93 GameMode::update();
94 updateActiveRegions();
95 }
96
97 blackOut();
98 disablePaletteChanges();
99 mainEnable();
100 closeLoadMode();
101 g_vm->_pointer->move(Point16(320, 240));
102 //g_vm->_pointer->hide();
103 enablePaletteChanges();
104 displayUpdate();
105 dayNightUpdate();
106 fadeUp();
107 g_vm->_pointer->manditoryShow(); // hide mouse pointer
108 reDrawScreen();
109 //g_vm->_pointer->show();
110 updateAllUserControls();
111 reDrawScreen();
112 g_vm->_mouseInfo->replaceObject();
113 g_vm->_mouseInfo->clearGauge();
114 g_vm->_mouseInfo->setText(NULL);
115 g_vm->_mouseInfo->setIntent(GrabInfo::WalkTo);
116 resetInputDevices();
117 }
118
119 // ------------------------------------------------------------------------
120 // backbuffer startup
121
initBackPanel(void)122 void initBackPanel(void) {
123 if (mainWindow)
124 return;
125
126 mainWindow = new BackWindow(
127 Rect16(0, 0, screenWidth, screenHeight),
128 0,
129 cmdWindowFunc);
130 if (mainWindow == nullptr)
131 error("Error initializing the back panel");
132 }
133
134 /* ===================================================================== *
135 Display disable flags
136 * ===================================================================== */
137
138 // ------------------------------------------------------------------------
139 // enable / disable blitting
140
displayEnable(DisplayDisabledBecause reason,bool onOff)141 void displayEnable(DisplayDisabledBecause reason, bool onOff) {
142 bool prev = displayEnabled();
143 if (!onOff)
144 displayStatus |= reason;
145 else
146 displayStatus &= (~reason);
147 if (prev != displayEnabled()) {
148 if (displayEnabled())
149 switchOn();
150 else
151 switchOff();
152 }
153 }
154
155 // ------------------------------------------------------------------------
156 // This is a check to see if blitting is enabled
157
displayEnabled(uint32 mask)158 bool displayEnabled(uint32 mask) {
159 return true;
160 }
161
displayOkay(void)162 bool displayOkay(void) {
163 return displayEnabled();
164 }
165
166
167 // ------------------------------------------------------------------------
168 // Main on/off swiotch for display
169
mainEnable(void)170 void mainEnable(void) {
171 displayEnable(GameNotInitialized);
172 }
173
174 // ------------------------------------------------------------------------
175 // This is a check to see if blitting is enabled
176
mainDisable(void)177 void mainDisable(void) {
178 displayDisable(GameNotInitialized);
179 }
180
181 // ------------------------------------------------------------------------
182 // On/Off hooks
183
switchOn(void)184 static void switchOn(void) {
185 enableUserControls();
186 }
187
switchOff(void)188 static void switchOff(void) {
189 disableUserControls();
190 }
191
192 /* ===================================================================== *
193 Palette disable hooks
194 * ===================================================================== */
195
enablePaletteChanges(void)196 void enablePaletteChanges(void) {
197 paletteSuspendFlag = false;
198 paletteMayHaveChanged = true;
199 }
200
disablePaletteChanges(void)201 void disablePaletteChanges(void) {
202 paletteSuspendFlag = true;
203 }
204
paletteChangesEnabled(void)205 bool paletteChangesEnabled(void) {
206 return !paletteSuspendFlag;
207 }
208
209
210 /* ===================================================================== *
211 Refresh
212 * ===================================================================== */
213
214 // ------------------------------------------------------------------------
215 // notice that screen may be dirty
216
delayedDisplayEnable(void)217 void delayedDisplayEnable(void) {
218 delayReDraw = false;
219 }
220
221 // ------------------------------------------------------------------------
222 // notice that palette may be dirty
223
externalPaletteIntrusion(void)224 void externalPaletteIntrusion(void) {
225 paletteMayHaveChanged = true;
226 }
227
228 // ------------------------------------------------------------------------
229 // force a full screen redraw
230
reDrawScreen(void)231 void reDrawScreen(void) {
232 //dispMM("refresh");
233 Rect16 r = Rect16(0, 0, 640, 480);
234 if (mainWindow && displayEnabled()) {
235 //updateAllUserControls();
236 drawMainDisplay();
237 mainWindow->invalidate(&r);
238 delayReDraw = false;
239 if (paletteMayHaveChanged) {
240 paletteMayHaveChanged = false;
241 g_vm->_pal->assertCurrentPalette();
242 paletteMayHaveChanged = false;
243 }
244 } else
245 delayReDraw = true;
246 //mainWindow->invalidate(r);
247 }
248
249
250 /* ===================================================================== *
251 Clear screen
252 * ===================================================================== */
253
blackOut(void)254 void blackOut(void) {
255 g_vm->_mainPort.drawMode = drawModeReplace;
256 g_vm->_mainPort.setColor(0); // fill screen with color
257 g_vm->_mainPort.fillRect(Rect16(0, 0, 640, 480));
258 g_vm->_pal->lightsOut();
259 }
260
261
262 /* ===================================================================== *
263 Loading screen
264 * ===================================================================== */
265
266 // ------------------------------------------------------------------------
267 // enable / disable blitting
268
showLoadMessage(void)269 void showLoadMessage(void) {
270 uint32 saved = displayStatus;
271 displayStatus = 0;
272 loadingScreen();
273 displayStatus = saved;
274 }
275
276
277 /* ===================================================================== *
278 Video mode save and restore for videos
279 * ===================================================================== */
280
pushVidState(void)281 void pushVidState(void) {
282 }
283
popVidState(void)284 void popVidState(void) {
285 }
286
287 } // end of namespace Saga2
288