2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:20:17 +00:00
|
|
|
* Copyright (C) 2004-2005 The ScummVM project
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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/gfx.h"
|
|
|
|
#include "saga/actor.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/font.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-04 20:28:57 +00:00
|
|
|
#include "saga/scene.h"
|
2004-08-03 00:40:16 +00:00
|
|
|
#include "saga/text.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
#include "saga/actionmap.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/objectmap.h"
|
|
|
|
|
|
|
|
#include "saga/render.h"
|
2004-08-02 12:41:40 +00:00
|
|
|
#include <common/timer.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.";
|
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-10-27 21:32:28 +00:00
|
|
|
GAME_DISPLAYINFO disp_info;
|
2004-04-12 21:40:49 +00:00
|
|
|
int tmp_w, tmp_h, tmp_bytepp;
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Initialize system graphics
|
2004-12-22 13:09:47 +00:00
|
|
|
_vm->getDisplayInfo(&disp_info);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Initialize FPS timer callback
|
2004-07-31 23:00:48 +00:00
|
|
|
g_timer->installTimerProc(&fpsTimerCallback, 1000000, this);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Create background buffer
|
2004-07-31 23:00:48 +00:00
|
|
|
_bg_buf_w = disp_info.logical_w;
|
|
|
|
_bg_buf_h = disp_info.logical_h;
|
|
|
|
_bg_buf = (byte *)calloc(disp_info.logical_w, disp_info.logical_h);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_bg_buf == NULL) {
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Allocate temp buffer for animation decoding,
|
|
|
|
// graphics scalers (2xSaI), etc.
|
2004-04-12 21:40:49 +00:00
|
|
|
tmp_w = disp_info.logical_w;
|
2004-05-01 07:50:08 +00:00
|
|
|
tmp_h = disp_info.logical_h + 4; // BG unbanking requres extra rows
|
2004-04-12 21:40:49 +00:00
|
|
|
tmp_bytepp = 1;
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_tmp_buf = (byte *)calloc(1, tmp_w * tmp_h * tmp_bytepp);
|
|
|
|
if (_tmp_buf == NULL) {
|
|
|
|
free(_bg_buf);
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_tmp_buf_w = tmp_w;
|
|
|
|
_tmp_buf_h = tmp_h;
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_backbuf_surface = _vm->_gfx->getBackBuffer();
|
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) {
|
|
|
|
free(_bg_buf);
|
|
|
|
free(_tmp_buf);
|
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
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
int Render::drawScene() {
|
2004-10-27 21:32:28 +00:00
|
|
|
SURFACE *backbuf_surface;
|
|
|
|
GAME_DISPLAYINFO disp_info;
|
|
|
|
SCENE_INFO scene_info;
|
2004-04-12 21:40:49 +00:00
|
|
|
SCENE_BGINFO bg_info;
|
2004-10-04 23:09:38 +00:00
|
|
|
Point bg_pt;
|
2004-04-12 21:40:49 +00:00
|
|
|
char txt_buf[20];
|
|
|
|
int fps_width;
|
2004-10-04 23:09:38 +00:00
|
|
|
Point mouse_pt;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
if (!_initialized) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_framecount++;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
backbuf_surface = _backbuf_surface;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Get mouse coordinates
|
2004-08-11 14:04:12 +00:00
|
|
|
mouse_pt = _vm->getMousePos();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getBGInfo(&bg_info);
|
2004-12-22 13:09:47 +00:00
|
|
|
_vm->getDisplayInfo(&disp_info);
|
2004-04-12 21:40:49 +00:00
|
|
|
bg_pt.x = 0;
|
|
|
|
bg_pt.y = 0;
|
|
|
|
|
2004-12-29 16:10:53 +00:00
|
|
|
if (!(_flags & RF_PLACARD)) {
|
|
|
|
// Display scene background
|
|
|
|
_vm->_scene->draw(backbuf_surface);
|
|
|
|
|
2005-01-07 00:57:43 +00:00
|
|
|
if (_vm->_interface->getMode() != kPanelFade) {
|
|
|
|
// Display scene maps, if applicable
|
|
|
|
if (getFlags() & RF_OBJECTMAP_TEST) {
|
|
|
|
if (_vm->_scene->_objectMap)
|
|
|
|
_vm->_scene->_objectMap->draw(backbuf_surface, mouse_pt, _vm->_gfx->getWhite(), _vm->_gfx->getBlack());
|
|
|
|
if (_vm->_scene->_actionMap)
|
|
|
|
_vm->_scene->_actionMap->draw(backbuf_surface, _vm->_gfx->matchColor(RGB_RED));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw queued actors
|
|
|
|
_vm->_actor->drawActors();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Draw queued text strings
|
2004-08-04 20:28:57 +00:00
|
|
|
_vm->_scene->getInfo(&scene_info);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-03 00:40:16 +00:00
|
|
|
_vm->textDrawList(scene_info.text_list, backbuf_surface);
|
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) {
|
|
|
|
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);
|
2004-10-30 22:13:48 +00:00
|
|
|
_vm->_font->draw(SMALL_FONT_ID, backbuf_surface, txt_buf, 0, backbuf_surface->w - fps_width, 2,
|
2004-10-07 23:02:19 +00:00
|
|
|
_vm->_gfx->getWhite(), _vm->_gfx->getBlack(), FONT_OUTLINE);
|
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) {
|
2004-10-27 21:32:28 +00:00
|
|
|
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, backbuf_surface, PAUSEGAME_MSG, msg_len,
|
2004-10-30 22:13:48 +00:00
|
|
|
(backbuf_surface->w - msg_w) / 2, 90, _vm->_gfx->getWhite(), _vm->_gfx->getBlack(), FONT_OUTLINE);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 07:50:08 +00:00
|
|
|
// Update user interface
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:26:41 +00:00
|
|
|
_vm->_interface->update(mouse_pt, 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) {
|
2004-08-03 00:40:16 +00:00
|
|
|
_vm->textDraw(MEDIUM_FONT_ID, backbuf_surface, test_txt, mouse_pt.x, mouse_pt.y,
|
2004-10-07 23:02:19 +00:00
|
|
|
_vm->_gfx->getWhite(), _vm->_gfx->getBlack(), FONT_OUTLINE | FONT_CENTERED);
|
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) {
|
2004-10-30 22:34:08 +00:00
|
|
|
drawPalette(backbuf_surface);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-30 22:13:48 +00:00
|
|
|
_system->copyRectToScreen((byte *)backbuf_surface->pixels, backbuf_surface->w, 0, 0,
|
|
|
|
backbuf_surface->w, backbuf_surface->h);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 19:41:47 +00:00
|
|
|
_system->updateScreen();
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
unsigned int Render::getFrameCount() {
|
|
|
|
return _framecount;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
unsigned int Render::resetFrameCount() {
|
|
|
|
unsigned int framecount = _framecount;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
_framecount = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
return framecount;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
_fps = _framecount;
|
|
|
|
_framecount = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
unsigned int Render::getFlags() {
|
|
|
|
return _flags;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
void Render::setFlag(unsigned int flag) {
|
|
|
|
_flags |= flag;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-29 16:10:53 +00:00
|
|
|
void Render::clearFlag(unsigned int flag) {
|
|
|
|
_flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
void Render::toggleFlag(unsigned int flag) {
|
|
|
|
_flags ^= flag;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int Render::getBufferInfo(BUFFER_INFO *bufinfo) {
|
|
|
|
assert(bufinfo != NULL);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
bufinfo->bg_buf = _bg_buf;
|
|
|
|
bufinfo->bg_buf_w = _bg_buf_w;
|
|
|
|
bufinfo->bg_buf_h = _bg_buf_h;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
bufinfo->tmp_buf = _tmp_buf;
|
|
|
|
bufinfo->tmp_buf_w = _tmp_buf_w;
|
|
|
|
bufinfo->tmp_buf_h = _tmp_buf_h;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|