1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
// Main rendering loop
#include "saga/saga.h"
#include "saga/actor.h"
#include "saga/font.h"
#include "saga/gfx.h"
#include "saga/interface.h"
#include "saga/objectmap.h"
#include "saga/puzzle.h"
#include "saga/render.h"
#include "saga/scene.h"
#include "common/timer.h"
#include "common/system.h"
namespace Saga {
const char *test_txt = "The quick brown fox jumped over the lazy dog. She sells sea shells down by the sea shore.";
const char *pauseStringITE = "PAWS GAME";
const char *pauseStringIHNM = "Game Paused";
Render::Render(SagaEngine *vm, OSystem *system) {
_vm = vm;
_system = system;
_initialized = false;
#ifdef SAGA_DEBUG
// Initialize FPS timer callback
_vm->_timer->installTimerProc(&fpsTimerCallback, 1000000, this);
#endif
_backGroundSurface.create(_vm->getDisplayWidth(), _vm->getDisplayHeight(), 1);
_flags = 0;
_initialized = true;
}
Render::~Render(void) {
#ifdef SAGA_DEBUG
_vm->_timer->removeTimerProc(&fpsTimerCallback);
#endif
_backGroundSurface.free();
_initialized = false;
}
bool Render::initialized() {
return _initialized;
}
void Render::drawScene() {
Surface *backBufferSurface;
Point mousePoint;
Point textPoint;
int curMode = _vm->_interface->getMode();
assert(_initialized);
#ifdef SAGA_DEBUG
_renderedFrameCount++;
#endif
backBufferSurface = _vm->_gfx->getBackBuffer();
// Get mouse coordinates
mousePoint = _vm->mousePos();
if (!(_flags & (RF_DEMO_SUBST | RF_MAP) || curMode == kPanelPlacard)) {
// Do not redraw the whole scene and the actors if the scene is fading out or
// if an overlay is drawn above it (e.g. the options menu)
if (_vm->_interface->getFadeMode() != kFadeOut &&
(curMode != kPanelOption && curMode != kPanelQuit &&
curMode != kPanelLoad && curMode != kPanelSave &&
curMode != kPanelProtect)) {
// Display scene background
if (!(_flags & RF_DISABLE_ACTORS) || _vm->getGameType() == GType_ITE)
_vm->_scene->draw();
if (_vm->_puzzle->isActive()) {
_vm->_puzzle->movePiece(mousePoint);
_vm->_actor->drawSpeech();
} else {
// Draw queued actors
if (!(_flags & RF_DISABLE_ACTORS))
_vm->_actor->drawActors();
}
#ifdef SAGA_DEBUG
if (getFlags() & RF_OBJECTMAP_TEST) {
if (_vm->_scene->_objectMap)
_vm->_scene->_objectMap->draw(backBufferSurface, mousePoint, kITEColorBrightWhite, kITEColorBlack);
if (_vm->_scene->_actionMap)
_vm->_scene->_actionMap->draw(backBufferSurface, mousePoint, kITEColorRed, kITEColorBlack);
}
#endif
#ifdef ACTOR_DEBUG
if (getFlags() & RF_ACTOR_PATH_TEST) {
_vm->_actor->drawPathTest();
}
#endif
}
}
if (_flags & RF_MAP)
_vm->_interface->mapPanelDrawCrossHair();
if ((curMode == kPanelOption) ||
(curMode == kPanelQuit) ||
(curMode == kPanelLoad) ||
(curMode == kPanelSave)) {
_vm->_interface->drawOption();
if (curMode == kPanelQuit) {
_vm->_interface->drawQuit();
}
if (curMode == kPanelLoad) {
_vm->_interface->drawLoad();
}
if (curMode == kPanelSave) {
_vm->_interface->drawSave();
}
}
if (curMode == kPanelProtect) {
_vm->_interface->drawProtect();
}
// Draw queued text strings
_vm->_scene->drawTextList();
// Handle user input
_vm->processInput();
#ifdef SAGA_DEBUG
// Display rendering information
if (_flags & RF_SHOW_FPS) {
char txtBuffer[20];
sprintf(txtBuffer, "%d", _fps);
textPoint.x = backBufferSurface->w - _vm->_font->getStringWidth(kKnownFontSmall, txtBuffer, 0, kFontOutline);
textPoint.y = 2;
_vm->_font->textDraw(kKnownFontSmall, backBufferSurface, txtBuffer, textPoint, kITEColorBrightWhite, kITEColorBlack, kFontOutline);
}
#endif
// Display "paused game" message, if applicable
if (_flags & RF_RENDERPAUSE) {
const char *pauseString = (_vm->getGameType() == GType_ITE) ? pauseStringITE : pauseStringIHNM;
textPoint.x = (backBufferSurface->w - _vm->_font->getStringWidth(kKnownFontPause, pauseString, 0, kFontOutline)) / 2;
textPoint.y = 90;
_vm->_font->textDraw(kKnownFontPause, pauseString, textPoint,
_vm->KnownColor2ColorId(kKnownColorBrightWhite), _vm->KnownColor2ColorId(kKnownColorBlack), kFontOutline);
}
// Update user interface
_vm->_interface->update(mousePoint, UPDATE_MOUSEMOVE);
#ifdef SAGA_DEBUG
// Display text formatting test, if applicable
if (_flags & RF_TEXT_TEST) {
Rect rect(mousePoint.x, mousePoint.y, mousePoint.x + 100, mousePoint.y + 50);
_vm->_font->textDrawRect(kKnownFontMedium, test_txt, rect,
kITEColorBrightWhite, kITEColorBlack, (FontEffectFlags)(kFontOutline | kFontCentered));
}
// Display palette test, if applicable
if (_flags & RF_PALETTE_TEST) {
backBufferSurface->drawPalette();
}
#endif
_system->copyRectToScreen((byte *)backBufferSurface->pixels, backBufferSurface->w, 0, 0,
backBufferSurface->w, backBufferSurface->h);
_system->updateScreen();
}
#ifdef SAGA_DEBUG
void Render::fpsTimerCallback(void *refCon) {
((Render *)refCon)->fpsTimer();
}
void Render::fpsTimer(void) {
_fps = _renderedFrameCount;
_renderedFrameCount = 0;
}
#endif
} // End of namespace Saga
|