scummvm/saga/render.cpp

184 lines
5.0 KiB
C++
Raw Normal View History

/* ScummVM - Scumm Interpreter
* Copyright (C) 2004-2005 The ScummVM project
*
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
2004-05-01 07:50:08 +00:00
// Main rendering loop
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"
#include "saga/gfx.h"
#include "saga/interface.h"
2004-08-02 16:20:35 +00:00
#include "saga/objectmap.h"
#include "saga/puzzle.h"
2004-08-02 16:20:35 +00:00
#include "saga/render.h"
#include "saga/scene.h"
#include "saga/text.h"
#include "common/timer.h"
#include "common/system.h"
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.";
Render::Render(SagaEngine *vm, OSystem *system) {
_vm = vm;
_system = system;
_initialized = false;
2004-05-01 07:50:08 +00:00
// Initialize FPS timer callback
Common::g_timer->installTimerProc(&fpsTimerCallback, 1000000, this);
_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-07-31 23:00:48 +00:00
_initialized = true;
}
2004-07-31 23:00:48 +00:00
Render::~Render(void) {
Common::g_timer->removeTimerProc(&fpsTimerCallback);
_backGroundSurface.free();
_initialized = false;
2004-07-31 23:00:48 +00:00
}
2004-07-31 23:00:48 +00:00
bool Render::initialized() {
return _initialized;
}
void Render::drawScene() {
Surface *backBufferSurface;
char txt_buf[20];
int fps_width;
Point mouse_pt;
assert(_initialized);
_frameCount++;
backBufferSurface = _vm->_gfx->getBackBuffer();
2004-05-01 07:50:08 +00:00
// Get mouse coordinates
mouse_pt = _vm->mousePos();
if (/*_vm->_interface->getMode() != kPanelPlacard*/!(_flags & (RF_PLACARD | RF_MAP))) {
// Display scene background
_vm->_scene->draw();
if (_vm->_interface->getFadeMode() != kFadeOut) {
if (_vm->_puzzle->isActive()) {
_vm->_puzzle->movePiece(mouse_pt);
_vm->_actor->drawSpeech();
} else {
// Draw queued actors
if (!(_flags & RF_DISABLE_ACTORS))
_vm->_actor->drawActors();
}
if (getFlags() & RF_OBJECTMAP_TEST) {
if (_vm->_scene->_objectMap)
_vm->_scene->_objectMap->draw(backBufferSurface, mouse_pt, kITEColorBrightWhite, kITEColorBlack);
if (_vm->_scene->_actionMap)
_vm->_scene->_actionMap->draw(backBufferSurface, mouse_pt, kITEColorRed, kITEColorBlack);
}
if (getFlags() & RF_ACTOR_PATH_TEST) {
_vm->_actor->drawPathTest();
}
}
}
if (_flags & RF_MAP)
_vm->_interface->mapPanelDrawCrossHair();
if ((_vm->_interface->getMode() == kPanelOption) ||
(_vm->_interface->getMode() == kPanelQuit) ||
(_vm->_interface->getMode() == kPanelLoad) ||
(_vm->_interface->getMode() == kPanelSave)) {
_vm->_interface->drawOption();
if (_vm->_interface->getMode() == kPanelQuit) {
_vm->_interface->drawQuit();
}
if (_vm->_interface->getMode() == kPanelLoad) {
_vm->_interface->drawLoad();
}
if (_vm->_interface->getMode() == kPanelSave) {
_vm->_interface->drawSave();
}
}
2004-05-01 07:50:08 +00:00
// Draw queued text strings
_vm->textDrawList(_vm->_scene->_textList, backBufferSurface);
2004-05-01 07:50:08 +00:00
// Handle user input
_vm->processInput();
2004-05-01 07:50:08 +00:00
// Display rendering information
2004-07-31 23:00:48 +00:00
if (_flags & RF_SHOW_FPS) {
sprintf(txt_buf, "%d", _fps);
2004-08-03 00:06:18 +00:00
fps_width = _vm->_font->getStringWidth(SMALL_FONT_ID, txt_buf, 0, FONT_NORMAL);
_vm->_font->draw(SMALL_FONT_ID, backBufferSurface, txt_buf, 0, backBufferSurface->w - fps_width, 2,
kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE);
}
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) {
int msg_len = strlen(PAUSEGAME_MSG);
int msg_w = _vm->_font->getStringWidth(BIG_FONT_ID, PAUSEGAME_MSG, msg_len, FONT_OUTLINE);
_vm->_font->draw(BIG_FONT_ID, backBufferSurface, PAUSEGAME_MSG, msg_len,
(backBufferSurface->w - msg_w) / 2, 90, kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE);
}
2004-05-01 07:50:08 +00:00
// Update user interface
_vm->_interface->update(mouse_pt, UPDATE_MOUSEMOVE);
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) {
_vm->textDraw(MEDIUM_FONT_ID, backBufferSurface, test_txt, mouse_pt.x, mouse_pt.y,
kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE | FONT_CENTERED);
}
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) {
backBufferSurface->drawPalette();
}
_system->copyRectToScreen((byte *)backBufferSurface->pixels, backBufferSurface->w, 0, 0,
backBufferSurface->w, backBufferSurface->h);
_system->updateScreen();
}
2004-07-31 23:00:48 +00:00
void Render::fpsTimerCallback(void *refCon) {
((Render *)refCon)->fpsTimer();
}
2004-07-31 23:00:48 +00:00
void Render::fpsTimer(void) {
_fps = _frameCount;
_frameCount = 0;
}
} // End of namespace Saga