scummvm/saga/render.cpp

243 lines
5.6 KiB
C++
Raw Normal View History

/* ScummVM - Scumm Interpreter
* Copyright (C) 2004 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
#include "saga.h"
#include "gfx.h"
#include "timer.h"
#include "actor_mod.h"
#include "console_mod.h"
#include "cvar_mod.h"
#include "font_mod.h"
#include "game_mod.h"
#include "interface_mod.h"
#include "scene_mod.h"
#include "sprite_mod.h"
#include "text_mod.h"
2004-08-01 00:03:45 +00:00
#include "actionmap.h"
#include "objectmap_mod.h"
#include "render.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.";
2004-07-31 23:00:48 +00:00
int Render::reg(void) {
return R_SUCCESS;
}
Render::Render(SagaEngine *vm, OSystem *system, Gfx *gfx) {
_vm = vm;
_system = system;
_gfx = gfx;
_initialized = false;
R_GAME_DISPLAYINFO disp_info;
int tmp_w, tmp_h, tmp_bytepp;
2004-05-01 07:50:08 +00:00
// Initialize system graphics
GAME_GetDisplayInfo(&disp_info);
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-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-07-31 23:00:48 +00:00
if (_bg_buf == NULL) {
return;
}
2004-05-01 07:50:08 +00:00
// Allocate temp buffer for animation decoding,
// graphics scalers (2xSaI), etc.
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
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-07-31 23:00:48 +00:00
_tmp_buf_w = tmp_w;
_tmp_buf_h = tmp_h;
_backbuf_surface = _gfx->getBackBuffer();
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) {
free(_bg_buf);
free(_tmp_buf);
_initialized = false;
2004-07-31 23:00:48 +00:00
}
2004-07-31 23:00:48 +00:00
bool Render::initialized() {
return _initialized;
}
2004-07-31 23:00:48 +00:00
int Render::drawScene() {
R_SURFACE *backbuf_surface;
R_GAME_DISPLAYINFO disp_info;
R_SCENE_INFO scene_info;
SCENE_BGINFO bg_info;
R_POINT bg_pt;
char txt_buf[20];
int fps_width;
R_POINT mouse_pt;
2004-07-31 23:00:48 +00:00
if (!_initialized) {
return R_FAILURE;
}
2004-07-31 23:00:48 +00:00
_framecount++;
2004-07-31 23:00:48 +00:00
backbuf_surface = _backbuf_surface;
2004-05-01 07:50:08 +00:00
// Get mouse coordinates
mouse_pt = SYSINPUT_GetMousePos();
SCENE_GetBGInfo(&bg_info);
GAME_GetDisplayInfo(&disp_info);
bg_pt.x = 0;
bg_pt.y = 0;
2004-05-01 07:50:08 +00:00
// Display scene background
SCENE_Draw(backbuf_surface);
2004-05-01 07:50:08 +00:00
// Display scene maps, if applicable
2004-07-31 23:00:48 +00:00
if (getFlags() & RF_OBJECTMAP_TEST) {
OBJECTMAP_Draw(backbuf_surface, &mouse_pt, _gfx->getWhite(), _gfx->getBlack());
_vm->_actionMap->draw(backbuf_surface, _gfx->matchColor(R_RGB_RED));
}
2004-05-01 07:50:08 +00:00
// Draw queued actors
ACTOR_DrawList();
2004-05-01 07:50:08 +00:00
// Draw queued text strings
SCENE_GetInfo(&scene_info);
TEXT_DrawList(scene_info.text_list, backbuf_surface);
2004-05-01 07:50:08 +00:00
// Handle user input
SYSINPUT_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-05-01 07:50:08 +00:00
fps_width = FONT_GetStringWidth(SMALL_FONT_ID, txt_buf, 0, FONT_NORMAL);
FONT_Draw(SMALL_FONT_ID, backbuf_surface, txt_buf, 0, backbuf_surface->buf_w - fps_width, 2,
_gfx->getWhite(), _gfx->getBlack(), 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(R_PAUSEGAME_MSG);
2004-05-01 07:50:08 +00:00
int msg_w = FONT_GetStringWidth(BIG_FONT_ID, R_PAUSEGAME_MSG, msg_len, FONT_OUTLINE);
FONT_Draw(BIG_FONT_ID, backbuf_surface, R_PAUSEGAME_MSG, msg_len,
(backbuf_surface->buf_w - msg_w) / 2, 90, _gfx->getWhite(), _gfx->getBlack(), FONT_OUTLINE);
}
2004-05-01 07:50:08 +00:00
// Update user interface
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) {
2004-05-01 07:50:08 +00:00
TEXT_Draw(MEDIUM_FONT_ID, backbuf_surface, test_txt, mouse_pt.x, mouse_pt.y,
_gfx->getWhite(), _gfx->getBlack(), 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) {
_gfx->drawPalette(backbuf_surface);
}
2004-05-01 07:50:08 +00:00
// Draw console
CON_Draw(backbuf_surface);
_system->copyRectToScreen(backbuf_surface->buf, backbuf_surface->buf_w, 0, 0,
backbuf_surface->buf_w, backbuf_surface->buf_h);
_system->updateScreen();
return R_SUCCESS;
}
2004-07-31 23:00:48 +00:00
unsigned int Render::getFrameCount() {
return _framecount;
}
2004-07-31 23:00:48 +00:00
unsigned int Render::resetFrameCount() {
unsigned int framecount = _framecount;
2004-07-31 23:00:48 +00:00
_framecount = 0;
return framecount;
}
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;
}
2004-07-31 23:00:48 +00:00
unsigned int Render::getFlags() {
return _flags;
}
2004-07-31 23:00:48 +00:00
void Render::setFlag(unsigned int flag) {
_flags |= flag;
}
2004-07-31 23:00:48 +00:00
void Render::toggleFlag(unsigned int flag) {
_flags ^= flag;
}
2004-07-31 23:00:48 +00:00
int Render::getBufferInfo(R_BUFFER_INFO *r_bufinfo) {
assert(r_bufinfo != NULL);
2004-07-31 23:00:48 +00:00
r_bufinfo->r_bg_buf = _bg_buf;
r_bufinfo->r_bg_buf_w = _bg_buf_w;
r_bufinfo->r_bg_buf_h = _bg_buf_h;
2004-07-31 23:00:48 +00:00
r_bufinfo->r_tmp_buf = _tmp_buf;
r_bufinfo->r_tmp_buf_w = _tmp_buf_w;
r_bufinfo->r_tmp_buf_h = _tmp_buf_h;
return R_SUCCESS;
}
} // End of namespace Saga