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
23 #include "sludge/allfiles.h"
24 #include "sludge/backdrop.h"
25 #include "sludge/cursors.h"
26 #include "sludge/event.h"
27 #include "sludge/fonttext.h"
28 #include "sludge/freeze.h"
29 #include "sludge/graphics.h"
30 #include "sludge/newfatal.h"
31 #include "sludge/objtypes.h"
32 #include "sludge/people.h"
33 #include "sludge/region.h"
34 #include "sludge/sludge.h"
35 #include "sludge/sludger.h"
36 #include "sludge/speech.h"
37 #include "sludge/sprites.h"
38 #include "sludge/sprbanks.h"
39 #include "sludge/statusba.h"
40 #include "sludge/zbuffer.h"
41
42 namespace Sludge {
43
freezeGraphics()44 void GraphicsManager::freezeGraphics() {
45
46 int w = _winWidth;
47 int h = _winHeight;
48
49 _freezeSurface.create(w, h, *g_sludge->getScreenPixelFormat());
50
51 displayBase();
52 _freezeSurface.copyFrom(_renderSurface);
53 }
54
freeze()55 bool GraphicsManager::freeze() {
56 FrozenStuffStruct *newFreezer = new FrozenStuffStruct;
57 if (!checkNew(newFreezer))
58 return false;
59
60 // Grab a copy of the current scene
61 freezeGraphics();
62 newFreezer->backdropSurface.copyFrom(_backdropSurface);
63 newFreezer->sceneWidth = _sceneWidth;
64 newFreezer->sceneHeight = _sceneHeight;
65 newFreezer->cameraX = _cameraX;
66 newFreezer->cameraY = _cameraY;
67 newFreezer->cameraZoom = _cameraZoom;
68
69 newFreezer->lightMapSurface.copyFrom(_lightMap);
70 newFreezer->lightMapNumber = _lightMapNumber;
71
72 newFreezer->parallaxStuff = _parallaxStuff;
73 _parallaxStuff = NULL;
74 newFreezer->zBufferSprites = _zBuffer->sprites;
75 newFreezer->zBufferNumber = _zBuffer->originalNum;
76 newFreezer->zPanels = _zBuffer->numPanels;
77 _zBuffer->sprites = NULL;
78 // resizeBackdrop kills parallax stuff, light map, z-buffer...
79 if (!killResizeBackdrop(_winWidth, _winHeight))
80 return fatal("Can't create new temporary backdrop buffer");
81
82 // Copy the old scene to the new backdrop
83 _backdropSurface.copyFrom(_freezeSurface);
84 _backdropExists = true;
85
86 _vm->_peopleMan->freeze(newFreezer);
87
88 StatusStuff *newStatusStuff = new StatusStuff;
89 if (!checkNew(newStatusStuff))
90 return false;
91 newFreezer->frozenStatus = copyStatusBarStuff(newStatusStuff);
92
93 _vm->_regionMan->freeze(newFreezer);
94 _vm->_cursorMan->freeze(newFreezer);
95 _vm->_speechMan->freeze(newFreezer);
96 _vm->_evtMan->freeze(newFreezer);
97
98 newFreezer->next = _frozenStuff;
99 _frozenStuff = newFreezer;
100
101 return true;
102 }
103
howFrozen()104 int GraphicsManager::howFrozen() {
105 int a = 0;
106 FrozenStuffStruct *f = _frozenStuff;
107 while (f) {
108 a++;
109 f = f->next;
110 }
111 return a;
112 }
113
unfreeze(bool killImage)114 void GraphicsManager::unfreeze(bool killImage) {
115 FrozenStuffStruct *killMe = _frozenStuff;
116
117 if (!_frozenStuff)
118 return;
119
120 _sceneWidth = _frozenStuff->sceneWidth;
121 _sceneHeight = _frozenStuff->sceneHeight;
122
123 _cameraX = _frozenStuff->cameraX;
124 _cameraY = _frozenStuff->cameraY;
125 _vm->_evtMan->mouseX() = (int)(_vm->_evtMan->mouseX() * _cameraZoom);
126 _vm->_evtMan->mouseY() = (int)(_vm->_evtMan->mouseY() * _cameraZoom);
127 _cameraZoom = _frozenStuff->cameraZoom;
128 _vm->_evtMan->mouseX() = (int)(_vm->_evtMan->mouseX() / _cameraZoom);
129 _vm->_evtMan->mouseY() = (int)(_vm->_evtMan->mouseY() / _cameraZoom);
130
131 g_sludge->_peopleMan->resotre(_frozenStuff);
132 g_sludge->_regionMan->resotre(_frozenStuff);
133
134 killLightMap();
135
136 _lightMap.copyFrom(_frozenStuff->lightMapSurface);
137 _lightMapNumber = _frozenStuff->lightMapNumber;
138 if (_lightMapNumber) {
139 loadLightMap(_lightMapNumber);
140 }
141
142 if (killImage)
143 killBackDrop();
144 _backdropSurface.copyFrom(_frozenStuff->backdropSurface);
145 _backdropExists = true;
146
147 _zBuffer->sprites = _frozenStuff->zBufferSprites;
148 killZBuffer();
149 _zBuffer->originalNum = _frozenStuff->zBufferNumber;
150 _zBuffer->numPanels = _frozenStuff->zPanels;
151 if (_zBuffer->numPanels) {
152 setZBuffer(_zBuffer->originalNum);
153 }
154
155 killParallax();
156 _parallaxStuff = _frozenStuff->parallaxStuff;
157 _vm->_cursorMan->resotre(_frozenStuff);
158 restoreBarStuff(_frozenStuff->frozenStatus);
159 _vm->_evtMan->restore(_frozenStuff);
160 _vm->_speechMan->restore(_frozenStuff);
161
162 _frozenStuff = _frozenStuff->next;
163
164 // free current frozen screen struct
165 if (killMe->backdropSurface.getPixels())
166 killMe->backdropSurface.free();
167 if (killMe->lightMapSurface.getPixels())
168 killMe->lightMapSurface.free();
169 delete killMe;
170 killMe = NULL;
171
172 }
173
174 } // End of namespace Sludge
175