diff options
Diffstat (limited to 'saga')
-rw-r--r-- | saga/animation.cpp | 47 | ||||
-rw-r--r-- | saga/animation.h | 28 | ||||
-rw-r--r-- | saga/events.cpp | 4 | ||||
-rw-r--r-- | saga/ihnm_introproc.cpp | 18 | ||||
-rw-r--r-- | saga/ite_introproc.cpp | 32 | ||||
-rw-r--r-- | saga/saga.cpp | 8 | ||||
-rw-r--r-- | saga/saga.h | 2 | ||||
-rw-r--r-- | saga/scene.cpp | 6 | ||||
-rw-r--r-- | saga/sceneproc.cpp | 6 | ||||
-rw-r--r-- | saga/sfuncs.cpp | 11 |
10 files changed, 91 insertions, 71 deletions
diff --git a/saga/animation.cpp b/saga/animation.cpp index c347a9c34b..162f9919c2 100644 --- a/saga/animation.cpp +++ b/saga/animation.cpp @@ -31,26 +31,24 @@ #include "events_mod.h" #include "render_mod.h" -#include "animation_mod.h" #include "animation.h" namespace Saga { static R_ANIMINFO AnimInfo; -int ANIM_Register() { +int Anim::reg() { CVAR_RegisterFunc(CF_anim_info, "anim_info", NULL, R_CVAR_NONE, 0, 0); return R_SUCCESS; } -int ANIM_Init() { +Anim::Anim(void) { AnimInfo.anim_limit = R_MAX_ANIMATIONS; AnimInfo.anim_count = 0; AnimInfo.initialized = 1; - return R_SUCCESS; } -int ANIM_Shutdown(void) { +Anim::~Anim(void) { uint16 i; for (i = 0; i < R_MAX_ANIMATIONS; i++) { @@ -58,10 +56,9 @@ int ANIM_Shutdown(void) { } AnimInfo.initialized = 0; - return R_SUCCESS; } -int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id_p) { +int Anim::load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id_p) { R_ANIMATION *new_anim; uint16 anim_id = 0; @@ -93,7 +90,7 @@ int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id new_anim->resdata_len = anim_resdata_len; if (GAME_GetGameType() == R_GAMETYPE_ITE) { - if (ANIM_GetNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames) != R_SUCCESS) { + if (getNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames) != R_SUCCESS) { warning("Error: Couldn't get animation frame count"); return R_FAILURE; } @@ -106,12 +103,12 @@ int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id } for (i = 0; i < new_anim->n_frames; i++) { - ANIM_GetFrameOffset(anim_resdata, anim_resdata_len, i + 1, &new_anim->frame_offsets[i]); + getFrameOffset(anim_resdata, anim_resdata_len, i + 1, &new_anim->frame_offsets[i]); } } else { new_anim->cur_frame_p = anim_resdata + SAGA_FRAME_HEADER_LEN; new_anim->cur_frame_len = anim_resdata_len - SAGA_FRAME_HEADER_LEN; - ANIM_GetNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames); + getNumFrames(anim_resdata, anim_resdata_len, &new_anim->n_frames); } // Set animation data @@ -134,7 +131,7 @@ int ANIM_Load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id return R_SUCCESS; } -int ANIM_Link(uint16 anim_id1, uint16 anim_id2) { +int Anim::link(uint16 anim_id1, uint16 anim_id2) { R_ANIMATION *anim1; R_ANIMATION *anim2; @@ -157,7 +154,7 @@ int ANIM_Link(uint16 anim_id1, uint16 anim_id2) { return R_SUCCESS; } -int ANIM_Play(uint16 anim_id, int vector_time) { +int Anim::play(uint16 anim_id, int vector_time) { R_EVENT event; R_ANIMATION *anim; R_ANIMATION *link_anim; @@ -195,20 +192,20 @@ int ANIM_Play(uint16 anim_id, int vector_time) { result = ITE_DecodeFrame(anim->resdata, anim->resdata_len, anim->frame_offsets[frame - 1], display_buf, disp_info.logical_w * disp_info.logical_h); if (result != R_SUCCESS) { - warning("ANIM_Play: Error decoding frame %u", anim->current_frame); + warning("ANIM::play: Error decoding frame %u", anim->current_frame); anim->play_flag = 0; return R_FAILURE; } } else { if (anim->cur_frame_p == NULL) { - warning("ANIM_Play: Frames exhausted"); + warning("ANIM::play: Frames exhausted"); return R_FAILURE; } result = IHNM_DecodeFrame(display_buf, disp_info.logical_w * disp_info.logical_h, anim->cur_frame_p, anim->cur_frame_len, &nextf_p, &nextf_len); if (result != R_SUCCESS) { - warning("ANIM_Play: Error decoding frame %u", anim->current_frame); + warning("ANIM::play: Error decoding frame %u", anim->current_frame); anim->play_flag = 0; return R_FAILURE; } @@ -270,12 +267,12 @@ int ANIM_Play(uint16 anim_id, int vector_time) { return R_SUCCESS; } -int ANIM_Reset() { +int Anim::reset() { uint16 i; for (i = 0; i < R_MAX_ANIMATIONS; i++) { - ANIM_Free(i); + freeId(i); } AnimInfo.anim_count = 0; @@ -283,7 +280,7 @@ int ANIM_Reset() { return R_SUCCESS; } -int ANIM_SetFlag(uint16 anim_id, uint16 flag) { +int Anim::setFlag(uint16 anim_id, uint16 flag) { R_ANIMATION *anim; if (anim_id > AnimInfo.anim_count) { @@ -300,7 +297,7 @@ int ANIM_SetFlag(uint16 anim_id, uint16 flag) { return R_SUCCESS; } -int ANIM_SetFrameTime(uint16 anim_id, int time) { +int Anim::setFrameTime(uint16 anim_id, int time) { R_ANIMATION *anim; if (anim_id > AnimInfo.anim_count) { @@ -317,7 +314,7 @@ int ANIM_SetFrameTime(uint16 anim_id, int time) { return R_SUCCESS; } -int ANIM_Free(uint16 anim_id) { +int Anim::freeId(uint16 anim_id) { R_ANIMATION *anim; if (anim_id > AnimInfo.anim_count) { @@ -345,7 +342,7 @@ int ANIM_Free(uint16 anim_id) { // sometimes less than number present in the .nframes member of the // animation header. For this reason, the function attempts to find // the last valid frame number, which it returns via 'n_frames' -int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames) { +int Anim::getNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames) { R_ANIMATION_HEADER ah; size_t offset; @@ -373,7 +370,7 @@ int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint1 if (ah.magic == 68) { for (x = ah.nframes; x > 0; x--) { - if (ANIM_GetFrameOffset(anim_resource, anim_resource_len, x, &offset) != R_SUCCESS) { + if (getFrameOffset(anim_resource, anim_resource_len, x, &offset) != R_SUCCESS) { return R_FAILURE; } @@ -390,7 +387,7 @@ int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint1 return R_FAILURE; } -int ITE_DecodeFrame(const byte *resdata, size_t resdata_len, size_t frame_offset, byte *buf, size_t buf_len) { +int Anim::ITE_DecodeFrame(const byte *resdata, size_t resdata_len, size_t frame_offset, byte *buf, size_t buf_len) { R_ANIMATION_HEADER ah; R_FRAME_HEADER fh; @@ -552,7 +549,7 @@ int ITE_DecodeFrame(const byte *resdata, size_t resdata_len, size_t frame_offset return R_SUCCESS; } -int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_p, +int Anim::IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_p, size_t thisf_len, const byte **nextf_p, size_t *nextf_len) { int in_ch; int decoded_data = 0; @@ -776,7 +773,7 @@ int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_ return R_SUCCESS; } -int ANIM_GetFrameOffset(const byte *resdata, size_t resdata_len, uint16 find_frame, size_t *frame_offset_p) { +int Anim::getFrameOffset(const byte *resdata, size_t resdata_len, uint16 find_frame, size_t *frame_offset_p) { R_ANIMATION_HEADER ah; uint16 num_frames; diff --git a/saga/animation.h b/saga/animation.h index 9cb0f95adb..2f92ff67fa 100644 --- a/saga/animation.h +++ b/saga/animation.h @@ -93,11 +93,31 @@ struct R_ANIMINFO { R_ANIMATION *anim_tbl[R_MAX_ANIMATIONS]; }; -int ANIM_GetNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames); -int ITE_DecodeFrame(const byte *anim_resource, size_t anim_resource_len, size_t frame_offset, byte *buf, size_t buf_len); -int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_p, +enum ANIM_FLAGS { + ANIM_LOOP = 0x01, + ANIM_ENDSCENE = 0x80 // When animation ends, dispatch scene end event +}; + +class Anim { +public: + int reg(void); + Anim(void); + ~Anim(void); + int load(const byte *anim_resdata, size_t anim_resdata_len, uint16 *anim_id_p); + int freeId(uint16 anim_id); + int play(uint16 anim_id, int vector_time); + int link(uint16 anim_id1, uint16 anim_id2); + int setFlag(uint16 anim_id, uint16 flag); + int setFrameTime(uint16 anim_id, int time); + int reset(void); +private: + int getNumFrames(const byte *anim_resource, size_t anim_resource_len, uint16 *n_frames); + int ITE_DecodeFrame(const byte *anim_resource, size_t anim_resource_len, size_t frame_offset, byte *buf, size_t buf_len); + int IHNM_DecodeFrame(byte *decode_buf, size_t decode_buf_len, const byte *thisf_p, size_t thisf_len, const byte **nextf_p, size_t *nextf_len); -int ANIM_GetFrameOffset(const byte *anim_resource, size_t anim_resource_len, uint16 find_frame, size_t *frame_offset); + int getFrameOffset(const byte *anim_resource, size_t anim_resource_len, uint16 find_frame, size_t *frame_offset); +}; + static void CF_anim_info(int argc, char *argv[]); } // End of namespace Saga diff --git a/saga/events.cpp b/saga/events.cpp index ad57acf43e..069553e73a 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -29,7 +29,7 @@ #include "yslib.h" -#include "animation_mod.h" +#include "animation.h" #include "console_mod.h" #include "scene_mod.h" #include "gfx_mod.h" @@ -270,7 +270,7 @@ static int HandleOneShot(R_EVENT *event) { case R_ANIM_EVENT: switch (event->op) { case EVENT_FRAME: - ANIM_Play(event->param, event->time); + _vm->_anim->play(event->param, event->time); break; default: break; diff --git a/saga/ihnm_introproc.cpp b/saga/ihnm_introproc.cpp index 521c1205d9..622df4c576 100644 --- a/saga/ihnm_introproc.cpp +++ b/saga/ihnm_introproc.cpp @@ -28,7 +28,7 @@ #include "reinherit.h" -#include "animation_mod.h" +#include "animation.h" #include "cvar_mod.h" #include "events_mod.h" #include "font_mod.h" @@ -119,9 +119,9 @@ int IHNM_IntroMovieProc1(int param, R_SCENE_INFO *scene_info) { event.param = SET_PALETTE; event.time = 0; EVENT_Queue(&event); - ANIM_SetFrameTime(0, R_IHNM_INTRO_FRAMETIME); - ANIM_SetFlag(0, ANIM_ENDSCENE); - ANIM_Play(0, 0); + _vm->_anim->setFrameTime(0, R_IHNM_INTRO_FRAMETIME); + _vm->_anim->setFlag(0, ANIM_ENDSCENE); + _vm->_anim->play(0, 0); break; default: break; @@ -173,8 +173,8 @@ int IHNM_IntroMovieProc2(int param, R_SCENE_INFO *scene_info) { q_event = EVENT_Chain(q_event, &event); - ANIM_SetFlag(0, ANIM_LOOP); - ANIM_Play(0, R_IHNM_PALFADE_TIME * 2); + _vm->_anim->setFlag(0, ANIM_LOOP); + _vm->_anim->play(0, R_IHNM_PALFADE_TIME * 2); // Queue end of scene after looping animation for a while event.type = R_ONESHOT_EVENT; @@ -233,7 +233,7 @@ int IHNM_IntroMovieProc3(int param, R_SCENE_INFO *scene_info) { q_event = EVENT_Chain(q_event, &event); - ANIM_Play(0, 0); + _vm->_anim->play(0, 0); // Queue end of scene after a while event.type = R_ONESHOT_EVENT; @@ -266,8 +266,8 @@ int IHNM_HateProc(int param, R_SCENE_INFO *scene_info) { q_event = EVENT_Queue(&event); - ANIM_SetFlag(0, ANIM_LOOP); - ANIM_Play(0, 0); + _vm->_anim->setFlag(0, ANIM_LOOP); + _vm->_anim->play(0, 0); break; default: break; diff --git a/saga/ite_introproc.cpp b/saga/ite_introproc.cpp index 3559f9f725..f1fbbec8e0 100644 --- a/saga/ite_introproc.cpp +++ b/saga/ite_introproc.cpp @@ -29,7 +29,7 @@ #include "yslib.h" -#include "animation_mod.h" +#include "animation.h" #include "cvar_mod.h" #include "events_mod.h" #include "font_mod.h" @@ -186,23 +186,23 @@ int ITE_IntroAnimProc(int param, R_SCENE_INFO *scene_info) { debug(0, "Intro animation procedure started."); debug(0, "Linking animation resources..."); - ANIM_SetFrameTime(0, ITE_INTRO_FRAMETIME); + _vm->_anim->setFrameTime(0, ITE_INTRO_FRAMETIME); // Link this scene's animation resources for continuous // playback - ANIM_Link(0, 1); - ANIM_Link(1, 2); - ANIM_Link(2, 3); - ANIM_Link(3, 4); - ANIM_Link(4, 5); - ANIM_Link(5, 6); + _vm->_anim->link(0, 1); + _vm->_anim->link(1, 2); + _vm->_anim->link(2, 3); + _vm->_anim->link(3, 4); + _vm->_anim->link(4, 5); + _vm->_anim->link(5, 6); // Scene should end on display of last animation frame - ANIM_SetFlag(6, ANIM_ENDSCENE); + _vm->_anim->setFlag(6, ANIM_ENDSCENE); debug(0, "Beginning animation playback."); - ANIM_Play(0, 0); + _vm->_anim->play(0, 0); // Queue intro music playback event.type = R_ONESHOT_EVENT; @@ -674,8 +674,8 @@ int ITE_IntroValleyProc(int param, R_SCENE_INFO *scene_info) { debug(0, "Beginning animation playback."); // Begin title screen background animation - ANIM_SetFlag(0, ANIM_LOOP); - ANIM_Play(0, 0); + _vm->_anim->setFlag(0, ANIM_LOOP); + _vm->_anim->play(0, 0); // Begin ITE title theme music _vm->_music->stop(); @@ -791,8 +791,8 @@ int ITE_IntroTreeHouseProc(int param, R_SCENE_INFO *scene_info) { event_delay = DISSOLVE_DURATION; // Begin title screen background animation - ANIM_SetFrameTime(0, 100); - ANIM_Play(0, event_delay); + _vm->_anim->setFrameTime(0, 100); + _vm->_anim->play(0, event_delay); // Queue game credits list text_entry.color = 255; @@ -900,8 +900,8 @@ int ITE_IntroFairePathProc(int param, R_SCENE_INFO *scene_info) { event_delay = DISSOLVE_DURATION; // Begin title screen background animation - ANIM_SetFlag(0, ANIM_LOOP); - ANIM_Play(0, event_delay); + _vm->_anim->setFlag(0, ANIM_LOOP); + _vm->_anim->play(0, event_delay); // Queue game credits list text_entry.color = 255; diff --git a/saga/saga.cpp b/saga/saga.cpp index 509fb85328..5e98a36047 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -39,7 +39,7 @@ #include "rscfile_mod.h" #include "render_mod.h" #include "actor_mod.h" -#include "animation_mod.h" +#include "animation.h" #include "console_mod.h" #include "cvar_mod.h" #include "events_mod.h" @@ -120,7 +120,7 @@ void SagaEngine::go() { RENDER_Register(); GAME_Register(); - ANIM_Register(); + _anim->reg(); ACTIONMAP_Register(); OBJECTMAP_Register(); SCRIPT_Register(); @@ -159,7 +159,7 @@ void SagaEngine::go() { EVENT_Init(); FONT_Init(); SPRITE_Init(); - ANIM_Init(); + _anim = new Anim(); ACTIONMAP_Init(); OBJECTMAP_Init(); ISOMAP_Init(); @@ -235,7 +235,6 @@ void SagaEngine::shutdown() { SCENE_Shutdown(); ACTOR_Shutdown(); SCRIPT_Shutdown(); - ANIM_Shutdown(); SPRITE_Shutdown(); OBJECTMAP_Shutdown(); FONT_Shutdown(); @@ -247,6 +246,7 @@ void SagaEngine::shutdown() { // Shutdown system modules */ delete _music; delete _sound; + delete _anim; _system->quit(); } diff --git a/saga/saga.h b/saga/saga.h index bcd3fdc8a0..57cafef9d4 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -41,6 +41,7 @@ namespace Saga { class SndRes; class Sound; class Music; +class Anim; using Common::MemoryReadStream; @@ -67,6 +68,7 @@ public: SndRes *_sndRes; Sound *_sound; Music *_music; + Anim *_anim; }; // FIXME: Global var. We use it until everything will be turned into objects diff --git a/saga/scene.cpp b/saga/scene.cpp index 39a7f02a22..d0285e5c0f 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -28,7 +28,7 @@ #include "yslib.h" #include "game_mod.h" -#include "animation_mod.h" +#include "animation.h" #include "console_mod.h" #include "cvar_mod.h" #include "events_mod.h" @@ -692,7 +692,7 @@ int ProcessSceneResources() { return R_MEM; } - if (ANIM_Load(SceneModule.reslist[i].res_data, + if (_vm->_anim->load(SceneModule.reslist[i].res_data, SceneModule.reslist[i].res_data_len, &new_anim_id) == R_SUCCESS) { } else { @@ -789,7 +789,7 @@ int SCENE_End() { } // Free animation info list - ANIM_Reset(); + _vm->_anim->reset(); PALANIM_Free(); OBJECTMAP_Free(); diff --git a/saga/sceneproc.cpp b/saga/sceneproc.cpp index 0abc334972..f34a7a20d8 100644 --- a/saga/sceneproc.cpp +++ b/saga/sceneproc.cpp @@ -28,7 +28,7 @@ #include "yslib.h" -#include "animation_mod.h" +#include "animation.h" #include "events_mod.h" #include "scene_mod.h" #include "palanim_mod.h" @@ -101,8 +101,8 @@ int InitialSceneProc(int param, R_SCENE_INFO *scene_info) { q_event = EVENT_Chain(q_event, &event); - ANIM_SetFlag(0, ANIM_LOOP); - ANIM_Play(0, delay_time); + _vm->_anim->setFlag(0, ANIM_LOOP); + _vm->_anim->play(0, delay_time); debug(0, "InitialSceneproc(): Scene started"); break; diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index ddfa77ee25..d98558cdc4 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -26,11 +26,12 @@ #include "reinherit.h" #include "actor_mod.h" -#include "animation_mod.h" +#include "animation.h" #include "console_mod.h" #include "interface_mod.h" #include "text_mod.h" +#include "saga.h" #include "script.h" #include "sfuncs.h" @@ -272,8 +273,8 @@ int SF_startAnim(R_SCRIPTFUNC_PARAMS) { frame_count = SDATA_ReadWordS(frame_parm); anim_id = SDATA_ReadWordS(anim_id_parm); - if (ANIM_Play(anim_id, 0) != R_SUCCESS) { - CON_Print(S_WARN_PREFIX "SF.26: ANIM_Play() failed. Anim id: %u\n", anim_id); + if (_vm->_anim->play(anim_id, 0) != R_SUCCESS) { + CON_Print(S_WARN_PREFIX "SF.26: Anim::play() failed. Anim id: %u\n", anim_id); return R_FAILURE; } @@ -487,8 +488,8 @@ int SF_linkAnim(R_SCRIPTFUNC_PARAMS) { anim_id1 = SDATA_ReadWordU(anim1_parm); anim_id2 = SDATA_ReadWordU(anim2_parm); - if (ANIM_Link(anim_id1, anim_id2) != R_SUCCESS) { - CON_Print(S_WARN_PREFIX "SF.41: ANIM_Link() failed. (%u->%u)\n", anim_id1, anim_id2); + if (_vm->_anim->link(anim_id1, anim_id2) != R_SUCCESS) { + CON_Print(S_WARN_PREFIX "SF.41: Anim::link() failed. (%u->%u)\n", anim_id1, anim_id2); return R_FAILURE; } |