2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Main rendering loop
|
2007-07-31 18:08:40 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
|
|
|
|
|
|
|
#include "saga/actor.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/font.h"
|
2005-05-23 02:23:34 +00:00
|
|
|
#include "saga/gfx.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/objectmap.h"
|
2005-05-23 02:23:34 +00:00
|
|
|
#include "saga/puzzle.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/render.h"
|
2005-05-23 02:23:34 +00:00
|
|
|
#include "saga/scene.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
|
|
|
|
#include "common/timer.h"
|
|
|
|
#include "common/system.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
const char *test_txt = "The quick brown fox jumped over the lazy dog. She sells sea shells down by the sea shore.";
|
2005-07-14 17:46:21 +00:00
|
|
|
const char *pauseString = "PAWS GAME";
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
Render::Render(SagaEngine *vm, OSystem *system) {
|
2004-08-01 12:06:12 +00:00
|
|
|
_vm = vm;
|
|
|
|
_system = system;
|
|
|
|
_initialized = false;
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Initialize FPS timer callback
|
2006-10-22 15:42:29 +00:00
|
|
|
_vm->_timer->installTimerProc(&fpsTimerCallback, 1000000, this);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-09 16:23:45 +00:00
|
|
|
_backGroundSurface.create(_vm->getDisplayWidth(), _vm->getDisplayHeight(), 1);
|
2004-07-31 23:00:48 +00:00
|
|
|
|
2004-08-01 07:56:08 +00:00
|
|
|
_flags = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_initialized = true;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
Render::~Render(void) {
|
2006-10-22 15:42:29 +00:00
|
|
|
_vm->_timer->removeTimerProc(&fpsTimerCallback);
|
2005-07-09 16:23:45 +00:00
|
|
|
_backGroundSurface.free();
|
2004-07-31 23:33:14 +00:00
|
|
|
|
|
|
|
_initialized = false;
|
2004-07-31 23:00:48 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
bool Render::initialized() {
|
|
|
|
return _initialized;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-09 16:23:45 +00:00
|
|
|
void Render::drawScene() {
|
|
|
|
Surface *backBufferSurface;
|
2005-07-14 17:46:21 +00:00
|
|
|
char txtBuffer[20];
|
|
|
|
Point mousePoint;
|
|
|
|
Point textPoint;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-09 16:23:45 +00:00
|
|
|
assert(_initialized);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2007-07-02 13:44:29 +00:00
|
|
|
_renderedFrameCount++;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-09 16:23:45 +00:00
|
|
|
backBufferSurface = _vm->_gfx->getBackBuffer();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Get mouse coordinates
|
2005-07-14 17:46:21 +00:00
|
|
|
mousePoint = _vm->mousePos();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-29 17:42:33 +00:00
|
|
|
if (!(_flags & (RF_DEMO_SUBST | RF_PLACARD | RF_MAP))) {
|
2004-12-29 16:10:53 +00:00
|
|
|
// Display scene background
|
2005-05-22 11:59:22 +00:00
|
|
|
_vm->_scene->draw();
|
2004-12-29 16:10:53 +00:00
|
|
|
|
2005-06-04 15:02:17 +00:00
|
|
|
if (_vm->_interface->getFadeMode() != kFadeOut) {
|
2005-05-23 02:23:34 +00:00
|
|
|
if (_vm->_puzzle->isActive()) {
|
2005-07-14 17:46:21 +00:00
|
|
|
_vm->_puzzle->movePiece(mousePoint);
|
2005-05-23 02:23:34 +00:00
|
|
|
_vm->_actor->drawSpeech();
|
2005-05-31 01:03:13 +00:00
|
|
|
} else {
|
|
|
|
// Draw queued actors
|
2005-07-05 15:15:35 +00:00
|
|
|
if (!(_flags & RF_DISABLE_ACTORS))
|
|
|
|
_vm->_actor->drawActors();
|
2005-05-23 02:23:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-07 00:57:43 +00:00
|
|
|
if (getFlags() & RF_OBJECTMAP_TEST) {
|
|
|
|
if (_vm->_scene->_objectMap)
|
2005-07-14 17:46:21 +00:00
|
|
|
_vm->_scene->_objectMap->draw(backBufferSurface, mousePoint, kITEColorBrightWhite, kITEColorBlack);
|
2005-01-07 00:57:43 +00:00
|
|
|
if (_vm->_scene->_actionMap)
|
2005-07-14 17:46:21 +00:00
|
|
|
_vm->_scene->_actionMap->draw(backBufferSurface, mousePoint, kITEColorRed, kITEColorBlack);
|
2005-01-07 00:57:43 +00:00
|
|
|
}
|
|
|
|
if (getFlags() & RF_ACTOR_PATH_TEST) {
|
|
|
|
_vm->_actor->drawPathTest();
|
|
|
|
}
|
2005-01-06 19:15:01 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-03 20:02:56 +00:00
|
|
|
if (_flags & RF_MAP)
|
|
|
|
_vm->_interface->mapPanelDrawCrossHair();
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
if ((_vm->_interface->getMode() == kPanelOption) ||
|
2005-05-29 15:39:35 +00:00
|
|
|
(_vm->_interface->getMode() == kPanelQuit) ||
|
|
|
|
(_vm->_interface->getMode() == kPanelLoad) ||
|
|
|
|
(_vm->_interface->getMode() == kPanelSave)) {
|
2005-05-22 11:59:22 +00:00
|
|
|
_vm->_interface->drawOption();
|
2005-05-29 15:39:35 +00:00
|
|
|
|
|
|
|
if (_vm->_interface->getMode() == kPanelQuit) {
|
|
|
|
_vm->_interface->drawQuit();
|
|
|
|
}
|
|
|
|
if (_vm->_interface->getMode() == kPanelLoad) {
|
|
|
|
_vm->_interface->drawLoad();
|
|
|
|
}
|
|
|
|
if (_vm->_interface->getMode() == kPanelSave) {
|
|
|
|
_vm->_interface->drawSave();
|
|
|
|
}
|
2005-05-22 11:59:22 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 03:28:21 +00:00
|
|
|
if (_vm->_interface->getMode() == kPanelProtect) {
|
|
|
|
_vm->_interface->drawProtect();
|
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Draw queued text strings
|
2005-07-14 17:46:21 +00:00
|
|
|
_vm->_scene->drawTextList(backBufferSurface);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Handle user input
|
2004-08-11 14:04:12 +00:00
|
|
|
_vm->processInput();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Display rendering information
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_flags & RF_SHOW_FPS) {
|
2005-07-14 17:46:21 +00:00
|
|
|
sprintf(txtBuffer, "%d", _fps);
|
2005-11-03 18:20:12 +00:00
|
|
|
textPoint.x = backBufferSurface->w - _vm->_font->getStringWidth(kKnownFontSmall, txtBuffer, 0, kFontOutline);
|
2005-07-14 17:46:21 +00:00
|
|
|
textPoint.y = 2;
|
|
|
|
|
2005-11-03 18:20:12 +00:00
|
|
|
_vm->_font->textDraw(kKnownFontSmall, backBufferSurface, txtBuffer, textPoint, kITEColorBrightWhite, kITEColorBlack, kFontOutline);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Display "paused game" message, if applicable
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_flags & RF_RENDERPAUSE) {
|
2005-11-03 18:20:12 +00:00
|
|
|
textPoint.x = (backBufferSurface->w - _vm->_font->getStringWidth(kKnownFontPause, pauseString, 0, kFontOutline)) / 2;
|
2005-07-14 17:46:21 +00:00
|
|
|
textPoint.y = 90;
|
|
|
|
|
2005-11-03 18:20:12 +00:00
|
|
|
_vm->_font->textDraw(kKnownFontPause, backBufferSurface, pauseString, textPoint, kITEColorBrightWhite, kITEColorBlack, kFontOutline);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Update user interface
|
2005-07-14 17:46:21 +00:00
|
|
|
_vm->_interface->update(mousePoint, UPDATE_MOUSEMOVE);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Display text formatting test, if applicable
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_flags & RF_TEXT_TEST) {
|
2005-07-14 17:46:21 +00:00
|
|
|
Rect rect(mousePoint.x, mousePoint.y, mousePoint.x + 100, mousePoint.y + 50);
|
2005-11-03 18:20:12 +00:00
|
|
|
_vm->_font->textDrawRect(kKnownFontMedium, backBufferSurface, test_txt, rect,
|
2005-07-14 17:46:21 +00:00
|
|
|
kITEColorBrightWhite, kITEColorBlack, (FontEffectFlags)(kFontOutline | kFontCentered));
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Display palette test, if applicable
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_flags & RF_PALETTE_TEST) {
|
2005-07-09 16:23:45 +00:00
|
|
|
backBufferSurface->drawPalette();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
_system->copyRectToScreen((byte *)backBufferSurface->pixels, backBufferSurface->w, 0, 0,
|
2005-07-09 16:23:45 +00:00
|
|
|
backBufferSurface->w, backBufferSurface->h);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 19:41:47 +00:00
|
|
|
_system->updateScreen();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
void Render::fpsTimerCallback(void *refCon) {
|
|
|
|
((Render *)refCon)->fpsTimer();
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
void Render::fpsTimer(void) {
|
2007-07-02 13:44:29 +00:00
|
|
|
_fps = _renderedFrameCount;
|
|
|
|
_renderedFrameCount = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|