diff options
-rw-r--r-- | saga/actor.cpp | 12 | ||||
-rw-r--r-- | saga/actor.h | 2 | ||||
-rw-r--r-- | saga/interface.cpp | 14 | ||||
-rw-r--r-- | saga/render.cpp | 1 | ||||
-rw-r--r-- | saga/render.h | 2 | ||||
-rw-r--r-- | saga/saga.cpp | 6 | ||||
-rw-r--r-- | saga/saga.h | 2 | ||||
-rw-r--r-- | saga/sprite.cpp | 66 | ||||
-rw-r--r-- | saga/sprite.h | 28 | ||||
-rw-r--r-- | saga/sprite_mod.h | 44 |
10 files changed, 69 insertions, 108 deletions
diff --git a/saga/actor.cpp b/saga/actor.cpp index beffeff7a0..ae4d4dc534 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -31,7 +31,7 @@ #include "saga/rscfile_mod.h" #include "saga/script_mod.h" #include "saga/sndres.h" -#include "saga/sprite_mod.h" +#include "saga/sprite.h" #include "saga/font.h" #include "saga/text.h" #include "saga/sound.h" @@ -224,7 +224,7 @@ int Actor::drawList() { o_idx = ActorOrientationLUT[actor->orient]; sprite_num = actor->act_tbl[actor->action].dir[o_idx].frame_index; sprite_num += actor->action_frame; - SPRITE_DrawOccluded(back_buf, actor->sl_p, sprite_num, actor->s_pt.x, actor->s_pt.y); + _vm->_sprite->drawOccluded(back_buf, actor->sl_p, sprite_num, actor->s_pt.x, actor->s_pt.y); // If actor's current intent is to speak, oblige him by // displaying his dialogue @@ -342,13 +342,13 @@ int Actor::addActor(R_ACTOR * actor) { loadActorSpriteIndex(actor, actor->si_rn, &last_frame); - if (SPRITE_LoadList(actor->sl_rn, &actor->sl_p) != R_SUCCESS) { + if (_vm->_sprite->loadList(actor->sl_rn, &actor->sl_p) != R_SUCCESS) { return R_FAILURE; } - if (last_frame >= SPRITE_GetListLen(actor->sl_p)) { + if (last_frame >= _vm->_sprite->getListLen(actor->sl_p)) { debug(0, "Appending to sprite list %d.", actor->sl_rn); - if (SPRITE_AppendList(actor->sl_rn + 1, + if (_vm->_sprite->appendList(actor->sl_rn + 1, actor->sl_p) != R_SUCCESS) { return R_FAILURE; } @@ -718,7 +718,7 @@ int Actor::deleteActor(int index) { node = _tbl[index]; actor = (R_ACTOR *)ys_dll_get_data(node); - SPRITE_Free(actor->sl_p); + _vm->_sprite->freeSprite(actor->sl_p); ys_dll_delete(node); diff --git a/saga/actor.h b/saga/actor.h index 7b76eb14aa..210085e9c3 100644 --- a/saga/actor.h +++ b/saga/actor.h @@ -27,7 +27,7 @@ #define SAGA_ACTOR_H__ #include "saga/yslib.h" -#include "saga/sprite_mod.h" +#include "saga/sprite.h" namespace Saga { diff --git a/saga/interface.cpp b/saga/interface.cpp index a175a94081..5fb8b2a7ea 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -33,7 +33,7 @@ #include "saga/objectmap.h" #include "saga/rscfile_mod.h" #include "saga/script_mod.h" -#include "saga/sprite_mod.h" +#include "saga/sprite.h" #include "saga/interface_mod.h" #include "saga/interface.h" @@ -191,9 +191,9 @@ int INTERFACE_Init(void) { return R_FAILURE; } - SPRITE_LoadList(ITE_COMMAND_BUTTONSPRITES, &IfModule.c_panel.sprites); + _vm->_sprite->loadList(ITE_COMMAND_BUTTONSPRITES, &IfModule.c_panel.sprites); - SPRITE_LoadList(ITE_DEFAULT_PORTRAITS, &IfModule.def_portraits); + _vm->_sprite->loadList(ITE_DEFAULT_PORTRAITS, &IfModule.def_portraits); _vm->decodeBGImage(IfModule.c_panel.res, IfModule.c_panel.res_len, &IfModule.c_panel.img, &IfModule.c_panel.img_len, &IfModule.c_panel.img_w, &IfModule.c_panel.img_h); @@ -294,7 +294,7 @@ int INTERFACE_Draw() { lportrait_x = xbase + IfModule.i_desc.lportrait_x; lportrait_y = ybase + IfModule.i_desc.lportrait_y; - SPRITE_Draw(back_buf, IfModule.def_portraits, IfModule.active_portrait, lportrait_x, lportrait_y); + _vm->_sprite->draw(back_buf, IfModule.def_portraits, IfModule.active_portrait, lportrait_x, lportrait_y); return R_SUCCESS; } @@ -402,7 +402,7 @@ int HandleCommandClick(R_SURFACE *ds, R_POINT *imouse_pt) { button_x = x_base + IfModule.c_panel.buttons[set_button].x1; button_y = y_base + IfModule.c_panel.buttons[set_button].y1; - SPRITE_Draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[set_button]. + _vm->_sprite->draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[set_button]. active_sprite - 1, button_x, button_y); } @@ -410,7 +410,7 @@ int HandleCommandClick(R_SURFACE *ds, R_POINT *imouse_pt) { button_x = x_base + IfModule.c_panel.buttons[old_set_button].x1; button_y = y_base + IfModule.c_panel.buttons[old_set_button].y1; - SPRITE_Draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[old_set_button]. + _vm->_sprite->draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[old_set_button]. inactive_sprite - 1, button_x, button_y); } } @@ -464,7 +464,7 @@ int HandleCommandUpdate(R_SURFACE *ds, R_POINT *imouse_pt) { color, IfModule.i_desc.cmd_txt_shadowcol, FONT_SHADOW); if ((i == IfModule.c_panel.set_button) && (IfModule.c_panel.buttons[i].flags & BUTTON_BITMAP)) { - SPRITE_Draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[i].active_sprite - 1, + _vm->_sprite->draw(ds, IfModule.c_panel.sprites, IfModule.c_panel.buttons[i].active_sprite - 1, button_x, button_y); } } diff --git a/saga/render.cpp b/saga/render.cpp index cf1edfae53..182698de59 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -32,7 +32,6 @@ #include "saga/game_mod.h" #include "saga/interface_mod.h" #include "saga/scene_mod.h" -#include "saga/sprite_mod.h" #include "saga/text.h" #include "saga/actionmap.h" diff --git a/saga/render.h b/saga/render.h index cacf5d0840..c8c90c3eda 100644 --- a/saga/render.h +++ b/saga/render.h @@ -26,7 +26,7 @@ #ifndef SAGA_RENDER_H_ #define SAGA_RENDER_H_ -#include "saga/sprite_mod.h" +#include "saga/sprite.h" namespace Saga { diff --git a/saga/saga.cpp b/saga/saga.cpp index 528d290770..cf9c9764dc 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -51,7 +51,7 @@ #include "saga/scene_mod.h" #include "saga/sdata.h" #include "saga/sndres.h" -#include "saga/sprite_mod.h" +#include "saga/sprite.h" #include "saga/objectmap.h" #include "saga/sound.h" #include "saga/music.h" @@ -149,7 +149,7 @@ void SagaEngine::go() { _sndRes = new SndRes(this); EVENT_Init(); _font = new Font(this); - SPRITE_Init(); + _sprite = new Sprite(this); _anim = new Anim(this); _script = new Script(); _sdata = new SData(); @@ -245,7 +245,7 @@ void SagaEngine::shutdown() { SCENE_Shutdown(); delete _actor; delete _script; - SPRITE_Shutdown(); + delete _sprite; delete _font; CON_Shutdown(); CVAR_Shutdown(); diff --git a/saga/saga.h b/saga/saga.h index 1f0c8a107b..152fa17708 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -53,6 +53,7 @@ class SData; class Script; class Actor; class Font; +class Sprite; using Common::MemoryReadStream; @@ -105,6 +106,7 @@ public: Script *_script; Actor *_actor; Font *_font; + Sprite *_sprite; private: int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len); diff --git a/saga/sprite.cpp b/saga/sprite.cpp index 696949f64d..43c4d751e3 100644 --- a/saga/sprite.cpp +++ b/saga/sprite.cpp @@ -37,48 +37,38 @@ namespace Saga { -static R_SPRITE_MODULE SpriteModule = { 0, 0, 0, 0 }; - -int SPRITE_Init() { +Sprite::Sprite(SagaEngine *vm) : _vm(vm), _initialized(false) { int result; - if (SpriteModule.init) { - return R_FAILURE; - } - debug(0, "Initializing sprite subsystem..."); // Load sprite module resource context - result = GAME_GetFileContext(&SpriteModule.sprite_ctxt, R_GAME_RESOURCEFILE, 0); + result = GAME_GetFileContext(&_spriteContext, R_GAME_RESOURCEFILE, 0); if (result != R_SUCCESS) { - return R_FAILURE; + return; } - SpriteModule.decode_buf_len = R_DECODE_BUF_LEN; + _decodeBufLen = R_DECODE_BUF_LEN; - SpriteModule.decode_buf = (byte *)malloc(R_DECODE_BUF_LEN); - if (SpriteModule.decode_buf == NULL) { - return R_MEM; + _decodeBuf = (byte *)malloc(R_DECODE_BUF_LEN); + if (_decodeBuf == NULL) { + return; } - SpriteModule.init = 1; - - return R_SUCCESS; + _initialized = true; } -int SPRITE_Shutdown() { - if (!SpriteModule.init) { - return R_FAILURE; +Sprite::~Sprite(void) { + if (!_initialized) { + return; } debug(0, "Shutting down sprite subsystem..."); - free(SpriteModule.decode_buf); - - return R_SUCCESS; + free(_decodeBuf); } -int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) { +int Sprite::loadList(int resource_num, R_SPRITELIST **sprite_list_p) { R_SPRITELIST *new_slist; byte *spritelist_data; size_t spritelist_len; @@ -90,7 +80,7 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) { return R_MEM; } - if (RSC_LoadResource(SpriteModule.sprite_ctxt, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { + if (RSC_LoadResource(_spriteContext, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { return R_FAILURE; } @@ -120,7 +110,7 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) { return R_SUCCESS; } -int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) { +int Sprite::appendList(int resource_num, R_SPRITELIST *spritelist) { byte *spritelist_data; size_t spritelist_len; void *test_p; @@ -133,7 +123,7 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) { return R_FAILURE; } - if (RSC_LoadResource(SpriteModule.sprite_ctxt, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { + if (RSC_LoadResource(_spriteContext, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { return R_FAILURE; } @@ -164,11 +154,11 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) { return R_SUCCESS; } -int SPRITE_GetListLen(R_SPRITELIST *spritelist) { +int Sprite::getListLen(R_SPRITELIST *spritelist) { return spritelist->sprite_count; } -int SPRITE_Free(R_SPRITELIST *spritelist) { +int Sprite::freeSprite(R_SPRITELIST *spritelist) { int i; for (i = 0; i <= spritelist->append_count; i++) { @@ -182,7 +172,7 @@ int SPRITE_Free(R_SPRITELIST *spritelist) { return R_SUCCESS; } -int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { +int Sprite::draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { int offset; int offset_idx; byte *sprite_p; @@ -197,7 +187,7 @@ int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int sp int x_align; int y_align; - if (!SpriteModule.init) { + if (!_initialized) { return R_FAILURE; } @@ -228,10 +218,10 @@ int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int sp return 0; } - DecodeRLESprite(sprite_data_p, 64000, SpriteModule.decode_buf, s_width * s_height); + decodeRLESprite(sprite_data_p, 64000, _decodeBuf, s_width * s_height); buf_row_p = ds->buf + ds->buf_pitch * spr_y; - src_row_p = SpriteModule.decode_buf; + src_row_p = _decodeBuf; // Clip to right side of surface clip_width = s_width; @@ -258,7 +248,7 @@ int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int sp return R_SUCCESS; } -int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { +int Sprite::drawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { int offset; int offset_idx; byte *sprite_p; @@ -295,12 +285,12 @@ int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num SCENE_ZINFO zinfo; int actor_z; - if (!SpriteModule.init) { + if (!_initialized) { return R_FAILURE; } if (!SCENE_IsBGMaskPresent()) { - return SPRITE_Draw(ds, sprite_list, sprite_num, spr_x, spr_y); + return draw(ds, sprite_list, sprite_num, spr_x, spr_y); } if (sprite_num >= sprite_list->sprite_count) { @@ -366,10 +356,10 @@ int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num return R_SUCCESS; } - DecodeRLESprite(sprite_data_p, 64000, SpriteModule.decode_buf, s_width * s_height); + decodeRLESprite(sprite_data_p, 64000, _decodeBuf, s_width * s_height); // Finally, draw the occluded sprite - src_row_p = SpriteModule.decode_buf + ci.src_draw_x + (ci.src_draw_y * s_width); + src_row_p = _decodeBuf + ci.src_draw_x + (ci.src_draw_y * s_width); dst_row_p = ds->buf + ci.dst_draw_x + (ci.dst_draw_y * ds->buf_pitch); mask_row_p = mask_buf + ci.dst_draw_x + (ci.dst_draw_y * mask_w); @@ -404,7 +394,7 @@ int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num return R_SUCCESS; } -int DecodeRLESprite(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len) { +int Sprite::decodeRLESprite(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len) { int bg_runcount; int fg_runcount; const byte *inbuf_ptr; diff --git a/saga/sprite.h b/saga/sprite.h index ece166e9de..2d65a3b2bf 100644 --- a/saga/sprite.h +++ b/saga/sprite.h @@ -56,15 +56,29 @@ struct R_SPRITELIST_tag { byte *sprite_data[R_APPENDMAX]; }; -struct R_SPRITE_MODULE { - int init; - R_RSCFILE_CONTEXT *sprite_ctxt; - byte *decode_buf; - size_t decode_buf_len; +typedef struct R_SPRITELIST_tag R_SPRITELIST; + +class Sprite { + public: + Sprite(SagaEngine *vm); + ~Sprite(void); + int loadList(int resource_num, R_SPRITELIST **sprite_list_p); + int appendList(int resource_num, R_SPRITELIST *spritelist); + int getListLen(R_SPRITELIST *spritelist); + int freeSprite(R_SPRITELIST *spritelist); + int draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y); + int drawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y); + + private: + int decodeRLESprite(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len); + + SagaEngine *_vm; + bool _initialized; + R_RSCFILE_CONTEXT *_spriteContext; + byte *_decodeBuf; + size_t _decodeBufLen; }; -int DecodeRLESprite(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len); - } // End of namespace Saga #endif diff --git a/saga/sprite_mod.h b/saga/sprite_mod.h deleted file mode 100644 index a91ab2c298..0000000000 --- a/saga/sprite_mod.h +++ /dev/null @@ -1,44 +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$ - * - */ - -// Sprite management module public header file - -#ifndef SAGA_SPRITE_MOD_H__ -#define SAGA_SPRITE_MOD_H__ - -namespace Saga { - -typedef struct R_SPRITELIST_tag R_SPRITELIST; - -int SPRITE_Init(); -int SPRITE_Shutdown(); -int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p); -int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist); -int SPRITE_GetListLen(R_SPRITELIST *spritelist); -int SPRITE_Free(R_SPRITELIST *spritelist); -int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y); -int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y); - -} // End of namespace Saga - -#endif |