diff options
author | Eugene Sandulenko | 2004-07-31 23:00:48 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2004-07-31 23:00:48 +0000 |
commit | c5836541fe4632792f6c7dbab8f01bf0459c03c3 (patch) | |
tree | d449ef65e5606a5b4642b5f91df1b5d91f610dbd | |
parent | 2060a9475d30f2275b3ee7a464f4246e0b9826f0 (diff) | |
download | scummvm-rg350-c5836541fe4632792f6c7dbab8f01bf0459c03c3.tar.gz scummvm-rg350-c5836541fe4632792f6c7dbab8f01bf0459c03c3.tar.bz2 scummvm-rg350-c5836541fe4632792f6c7dbab8f01bf0459c03c3.zip |
Objectize render.cpp
svn-id: r14395
-rw-r--r-- | saga/animation.cpp | 4 | ||||
-rw-r--r-- | saga/events.cpp | 6 | ||||
-rw-r--r-- | saga/input.cpp | 12 | ||||
-rw-r--r-- | saga/music.h | 1 | ||||
-rw-r--r-- | saga/render.cpp | 115 | ||||
-rw-r--r-- | saga/render.h | 67 | ||||
-rw-r--r-- | saga/render_mod.h | 61 | ||||
-rw-r--r-- | saga/saga.cpp | 15 | ||||
-rw-r--r-- | saga/saga.h | 2 | ||||
-rw-r--r-- | saga/scene.cpp | 4 | ||||
-rw-r--r-- | saga/sndres.cpp | 3 |
11 files changed, 133 insertions, 157 deletions
diff --git a/saga/animation.cpp b/saga/animation.cpp index aa51f3104d..3f6848a0f1 100644 --- a/saga/animation.cpp +++ b/saga/animation.cpp @@ -29,7 +29,7 @@ #include "console_mod.h" #include "game_mod.h" #include "events_mod.h" -#include "render_mod.h" +#include "render.h" #include "animation.h" @@ -180,7 +180,7 @@ int Anim::play(uint16 anim_id, int vector_time) { GAME_GetDisplayInfo(&disp_info); - RENDER_GetBufferInfo(&buf_info); + _vm->_render->getBufferInfo(&buf_info); display_buf = buf_info.r_bg_buf; anim = AnimInfo.anim_tbl[anim_id]; diff --git a/saga/events.cpp b/saga/events.cpp index 069553e73a..b0011773f4 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -36,7 +36,7 @@ #include "interface_mod.h" #include "text_mod.h" #include "palanim_mod.h" -#include "render_mod.h" +#include "render.h" #include "game_mod.h" #include "sndres.h" #include "music.h" @@ -174,7 +174,7 @@ int HandleContinuous(R_EVENT *event) { case R_TRANSITION_EVENT: switch (event->op) { case EVENT_DISSOLVE: - RENDER_GetBufferInfo(&buf_info); + _vm->_render->getBufferInfo(&buf_info); SCENE_GetBGInfo(&bg_info); TRANSITION_Dissolve(buf_info.r_bg_buf, buf_info.r_bg_buf_w, buf_info.r_bg_buf_h, buf_info.r_bg_buf_w, bg_info.bg_buf, bg_info.bg_p, 0, event_pc); @@ -251,7 +251,7 @@ static int HandleOneShot(R_EVENT *event) { back_buf = GFX_GetBackBuffer(); - RENDER_GetBufferInfo(&rbuf_info); + _vm->_render->getBufferInfo(&rbuf_info); SCENE_GetBGInfo(&bginfo); bg_pt.x = bginfo.bg_x; diff --git a/saga/input.cpp b/saga/input.cpp index 62a897a630..1431a46706 100644 --- a/saga/input.cpp +++ b/saga/input.cpp @@ -26,7 +26,7 @@ #include "saga/actor_mod.h" #include "saga/console_mod.h" #include "saga/interface_mod.h" -#include "saga/render_mod.h" +#include "saga/render.h" #include "saga/scene_mod.h" #include "saga/script_mod.h" @@ -81,16 +81,16 @@ int SYSINPUT_ProcessInput() { INTERFACE_Draw(); break; case 282: // F1 - RENDER_ToggleFlag(RF_SHOW_FPS); + _vm->_render->toggleFlag(RF_SHOW_FPS); break; case 283: // F2 - RENDER_ToggleFlag(RF_PALETTE_TEST); + _vm->_render->toggleFlag(RF_PALETTE_TEST); break; case 284: // F3 - RENDER_ToggleFlag(RF_TEXT_TEST); + _vm->_render->toggleFlag(RF_TEXT_TEST); break; case 285: // F4 - RENDER_ToggleFlag(RF_OBJECTMAP_TEST); + _vm->_render->toggleFlag(RF_OBJECTMAP_TEST); break; case 9: // Tab STHREAD_DebugStep(); @@ -102,7 +102,7 @@ int SYSINPUT_ProcessInput() { break; case 19: // pause case 112: // p - RENDER_ToggleFlag(RF_RENDERPAUSE); + _vm->_render->toggleFlag(RF_RENDERPAUSE); break; case 27: // Esc // Skip to next scene skip target diff --git a/saga/music.h b/saga/music.h index 612cd264d8..bfaaa2d366 100644 --- a/saga/music.h +++ b/saga/music.h @@ -106,7 +106,6 @@ public: private: - SagaEngine *_vm; SoundMixer *_mixer; MusicPlayer *_player; diff --git a/saga/render.cpp b/saga/render.cpp index a697b64af0..b56a965123 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -40,21 +40,17 @@ #include "actionmap_mod.h" #include "objectmap_mod.h" -#include "render_mod.h" #include "render.h" namespace Saga { -static R_RENDER_MODULE RenderModule; -static OSystem *_system; - const char *test_txt = "The quick brown fox jumped over the lazy dog. She sells sea shells down by the sea shore."; -int RENDER_Register() { +int Render::reg(void) { return R_SUCCESS; } -int RENDER_Init(OSystem *system) { +Render::Render(OSystem *system) : _system(system), _initialized(false) { R_GAME_DISPLAYINFO disp_info; int tmp_w, tmp_h, tmp_bytepp; @@ -62,19 +58,19 @@ int RENDER_Init(OSystem *system) { GAME_GetDisplayInfo(&disp_info); if (GFX_Init(system, disp_info.logical_w, disp_info.logical_h) != R_SUCCESS) { - return R_FAILURE; + return; } // Initialize FPS timer callback - g_timer->installTimerProc(&RENDER_FpsTimer, 1000, _vm); + g_timer->installTimerProc(&fpsTimerCallback, 1000000, this); // Create background buffer - RenderModule.r_bg_buf_w = disp_info.logical_w; - RenderModule.r_bg_buf_h = disp_info.logical_h; - RenderModule.r_bg_buf = (byte *)calloc(disp_info.logical_w, disp_info.logical_h); + _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); - if (RenderModule.r_bg_buf == NULL) { - return R_MEM; + if (_bg_buf == NULL) { + return; } // Allocate temp buffer for animation decoding, @@ -83,25 +79,30 @@ int RENDER_Init(OSystem *system) { tmp_h = disp_info.logical_h + 4; // BG unbanking requres extra rows tmp_bytepp = 1; - RenderModule.r_tmp_buf = (byte *)calloc(1, tmp_w * tmp_h * tmp_bytepp); - if (RenderModule.r_tmp_buf == NULL) { - - free(RenderModule.r_bg_buf); - return R_MEM; + _tmp_buf = (byte *)calloc(1, tmp_w * tmp_h * tmp_bytepp); + if (_tmp_buf == NULL) { + free(_bg_buf); + return; } - RenderModule.r_tmp_buf_w = tmp_w; - RenderModule.r_tmp_buf_h = tmp_h; + _tmp_buf_w = tmp_w; + _tmp_buf_h = tmp_h; + + _backbuf_surface = GFX_GetBackBuffer(); - RenderModule.r_backbuf_surface = GFX_GetBackBuffer(); + _initialized = true; +} - _system = system; - RenderModule.initialized = 1; +Render::~Render(void) { + free(_bg_buf); + free(_tmp_buf); +} - return R_SUCCESS; +bool Render::initialized() { + return _initialized; } -int RENDER_DrawScene() { +int Render::drawScene() { R_SURFACE *backbuf_surface; R_GAME_DISPLAYINFO disp_info; R_SCENE_INFO scene_info; @@ -111,13 +112,13 @@ int RENDER_DrawScene() { int fps_width; R_POINT mouse_pt; - if (!RenderModule.initialized) { + if (!_initialized) { return R_FAILURE; } - RenderModule.r_framecount++; + _framecount++; - backbuf_surface = RenderModule.r_backbuf_surface; + backbuf_surface = _backbuf_surface; // Get mouse coordinates mouse_pt = SYSINPUT_GetMousePos(); @@ -131,7 +132,7 @@ int RENDER_DrawScene() { SCENE_Draw(backbuf_surface); // Display scene maps, if applicable - if (RENDER_GetFlags() & RF_OBJECTMAP_TEST) { + if (getFlags() & RF_OBJECTMAP_TEST) { OBJECTMAP_Draw(backbuf_surface, &mouse_pt, GFX_GetWhite(), GFX_GetBlack()); ACTIONMAP_Draw(backbuf_surface, GFX_MatchColor(R_RGB_RED)); } @@ -148,15 +149,15 @@ int RENDER_DrawScene() { SYSINPUT_ProcessInput(); // Display rendering information - if (RenderModule.r_flags & RF_SHOW_FPS) { - sprintf(txt_buf, "%d", RenderModule.r_fps); + if (_flags & RF_SHOW_FPS) { + sprintf(txt_buf, "%d", _fps); 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); } // Display "paused game" message, if applicable - if (RenderModule.r_flags & RF_RENDERPAUSE) { + if (_flags & RF_RENDERPAUSE) { int msg_len = strlen(R_PAUSEGAME_MSG); 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, @@ -168,13 +169,13 @@ int RENDER_DrawScene() { INTERFACE_Update(&mouse_pt, UPDATE_MOUSEMOVE); // Display text formatting test, if applicable - if (RenderModule.r_flags & RF_TEXT_TEST) { + if (_flags & RF_TEXT_TEST) { TEXT_Draw(MEDIUM_FONT_ID, backbuf_surface, test_txt, mouse_pt.x, mouse_pt.y, GFX_GetWhite(), GFX_GetBlack(), FONT_OUTLINE | FONT_CENTERED); } // Display palette test, if applicable - if (RenderModule.r_flags & RF_PALETTE_TEST) { + if (_flags & RF_PALETTE_TEST) { GFX_DrawPalette(backbuf_surface); } @@ -188,47 +189,49 @@ int RENDER_DrawScene() { return R_SUCCESS; } -unsigned int RENDER_GetFrameCount() { - return RenderModule.r_framecount; +unsigned int Render::getFrameCount() { + return _framecount; } -unsigned int RENDER_ResetFrameCount() { - unsigned int framecount = RenderModule.r_framecount; +unsigned int Render::resetFrameCount() { + unsigned int framecount = _framecount; - RenderModule.r_framecount = 0; + _framecount = 0; return framecount; } -void RENDER_FpsTimer(void *refCon) { - RenderModule.r_fps = RenderModule.r_framecount; - RenderModule.r_framecount = 0; +void Render::fpsTimerCallback(void *refCon) { + ((Render *)refCon)->fpsTimer(); +} - return; +void Render::fpsTimer(void) { + _fps = _framecount; + _framecount = 0; } -unsigned int RENDER_GetFlags() { - return RenderModule.r_flags; +unsigned int Render::getFlags() { + return _flags; } -void RENDER_SetFlag(unsigned int flag) { - RenderModule.r_flags |= flag; +void Render::setFlag(unsigned int flag) { + _flags |= flag; } -void RENDER_ToggleFlag(unsigned int flag) { - RenderModule.r_flags ^= flag; +void Render::toggleFlag(unsigned int flag) { + _flags ^= flag; } -int RENDER_GetBufferInfo(R_BUFFER_INFO *r_bufinfo) { +int Render::getBufferInfo(R_BUFFER_INFO *r_bufinfo) { assert(r_bufinfo != NULL); - r_bufinfo->r_bg_buf = RenderModule.r_bg_buf; - r_bufinfo->r_bg_buf_w = RenderModule.r_bg_buf_w; - r_bufinfo->r_bg_buf_h = RenderModule.r_bg_buf_h; + 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; - r_bufinfo->r_tmp_buf = RenderModule.r_tmp_buf; - r_bufinfo->r_tmp_buf_w = RenderModule.r_tmp_buf_w; - r_bufinfo->r_tmp_buf_h = RenderModule.r_tmp_buf_h; + 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; } diff --git a/saga/render.h b/saga/render.h index 33f586f1a3..bece807252 100644 --- a/saga/render.h +++ b/saga/render.h @@ -26,37 +26,68 @@ #ifndef SAGA_RENDER_H_ #define SAGA_RENDER_H_ -namespace Saga { +#include "saga/sprite_mod.h" -// Render module CVAR defaults -#define R_FULLSCREEN_DEFAULT 0 -#define R_DOUBLERES_DEFAULT 1 -#define R_HICOLOR_DEFAULT 1 +namespace Saga { #define R_PAUSEGAME_MSG "PAWS GAME" +enum RENDER_FLAGS { + RF_SHOW_FPS = 0x01, + RF_PALETTE_TEST = 0x02, + RF_TEXT_TEST = 0x04, + RF_OBJECTMAP_TEST = 0x08, + RF_RENDERPAUSE = 0x10, + RF_GAMEPAUSE = 0x20 +}; -struct R_RENDER_MODULE { - int initialized; - - // Module data - R_SURFACE *r_backbuf_surface; - +struct R_BUFFER_INFO { byte *r_bg_buf; int r_bg_buf_w; int r_bg_buf_h; byte *r_tmp_buf; int r_tmp_buf_w; int r_tmp_buf_h; +}; - R_SPRITELIST *r_test_sprite; +class Render { +public: + int reg(void); + Render(OSystem *system); + ~Render(void); + bool initialized(); + int drawScene(void); + unsigned int getFlags(void); + void setFlag(unsigned int); + void toggleFlag(unsigned int); + unsigned int getFrameCount(void); + unsigned int resetFrameCount(void); + int getBufferInfo(R_BUFFER_INFO *); - unsigned int r_fps; - unsigned int r_framecount; - unsigned int r_flags; - int r_mode; -}; +private: + static void fpsTimerCallback(void *refCon); + void fpsTimer(void); + + SagaEngine *_vm; + OSystem *_system; + bool _initialized; + + // Module data + R_SURFACE *_backbuf_surface; -void RENDER_FpsTimer(void *refCon); + byte *_bg_buf; + int _bg_buf_w; + int _bg_buf_h; + byte *_tmp_buf; + int _tmp_buf_w; + int _tmp_buf_h; + + R_SPRITELIST *_test_sprite; + + unsigned int _fps; + unsigned int _framecount; + unsigned int _flags; + int _mode; +}; } // End of namespace Saga diff --git a/saga/render_mod.h b/saga/render_mod.h deleted file mode 100644 index 49e5c03091..0000000000 --- a/saga/render_mod.h +++ /dev/null @@ -1,61 +0,0 @@ -/* 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$ - * - */ - -// Main rendering loop - public header - -#ifndef SAGA_RENDER_MOD_H__ -#define SAGA_RENDER_MOD_H__ - -namespace Saga { - -enum RENDER_FLAGS { - RF_SHOW_FPS = 0x01, - RF_PALETTE_TEST = 0x02, - RF_TEXT_TEST = 0x04, - RF_OBJECTMAP_TEST = 0x08, - RF_RENDERPAUSE = 0x10, - RF_GAMEPAUSE = 0x20 -}; - -struct R_BUFFER_INFO { - byte *r_bg_buf; - int r_bg_buf_w; - int r_bg_buf_h; - byte *r_tmp_buf; - int r_tmp_buf_w; - int r_tmp_buf_h; -}; - -int RENDER_Register(); -int RENDER_Init(OSystem *system); -int RENDER_DrawScene(); -unsigned int RENDER_GetFlags(); -void RENDER_SetFlag(unsigned int); -void RENDER_ToggleFlag(unsigned int); -unsigned int RENDER_GetFrameCount(void); -unsigned int RENDER_ResetFrameCount(void); -int RENDER_GetBufferInfo(R_BUFFER_INFO *); - -} // End of namespace Saga - -#endif diff --git a/saga/saga.cpp b/saga/saga.cpp index 5e98a36047..7433e294a7 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -37,7 +37,7 @@ #include "timer.h" #include "rscfile_mod.h" -#include "render_mod.h" +#include "render.h" #include "actor_mod.h" #include "animation.h" #include "console_mod.h" @@ -117,10 +117,8 @@ void SagaEngine::go() { // Register engine modules CON_Register(); // Register console cvars first - RENDER_Register(); GAME_Register(); - _anim->reg(); ACTIONMAP_Register(); OBJECTMAP_Register(); SCRIPT_Register(); @@ -196,7 +194,8 @@ void SagaEngine::go() { } // Initialize graphics - if (RENDER_Init(_system) != R_SUCCESS) { + _render = new Render(_system); + if (!_render->initialized()) { return; } @@ -206,6 +205,9 @@ void SagaEngine::go() { debug(0, "Sound disabled."); } + _render->reg(); + _anim->reg(); + SYSTIMER_ResetMSCounter(); // Begin Main Engine Loop @@ -213,7 +215,7 @@ void SagaEngine::go() { SCENE_Start(); for (;;) { - if (RENDER_GetFlags() & RF_RENDERPAUSE) { + if (_render->getFlags() & RF_RENDERPAUSE) { // Freeze time while paused SYSTIMER_ResetMSCounter(); } else { @@ -226,7 +228,7 @@ void SagaEngine::go() { STHREAD_ExecThreads(msec); } // Per frame processing - RENDER_DrawScene(); + _render->drawScene(); SYSTIMER_Sleep(0); } } @@ -242,6 +244,7 @@ void SagaEngine::shutdown() { CVAR_Shutdown(); EVENT_Shutdown(); + delete _render; delete _sndRes; // Shutdown system modules */ delete _music; diff --git a/saga/saga.h b/saga/saga.h index 1bd1d827d3..14069d925a 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -42,6 +42,7 @@ class SndRes; class Sound; class Music; class Anim; +class Render; using Common::MemoryReadStream; @@ -69,6 +70,7 @@ public: Sound *_sound; Music *_music; Anim *_anim; + Render *_render; private: int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len); diff --git a/saga/scene.cpp b/saga/scene.cpp index a5489dd3fa..e59d45c78e 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -38,7 +38,7 @@ #include "script_mod.h" #include "objectmap_mod.h" #include "palanim_mod.h" -#include "render_mod.h" +#include "render.h" #include "rscfile_mod.h" #include "text_mod.h" @@ -725,7 +725,7 @@ int SCENE_Draw(R_SURFACE *dst_s) { assert(SceneModule.init); - RENDER_GetBufferInfo(&buf_info); + _vm->_render->getBufferInfo(&buf_info); GAME_GetDisplayInfo(&disp_info); bg_pt.x = 0; diff --git a/saga/sndres.cpp b/saga/sndres.cpp index f7aca3be32..bb63d73665 100644 --- a/saga/sndres.cpp +++ b/saga/sndres.cpp @@ -36,7 +36,7 @@ namespace Saga { -SndRes::SndRes(SagaEngine *vm) { +SndRes::SndRes(SagaEngine *vm) : _vm(vm) { int result; /* Load sound module resource file contexts */ @@ -53,7 +53,6 @@ SndRes::SndRes(SagaEngine *vm) { // Grab sound resource information for the current game GAME_GetSoundInfo(&_snd_info); - _vm = vm; _init = 1; } |