diff options
-rw-r--r-- | saga/actionmap.cpp | 123 | ||||
-rw-r--r-- | saga/actionmap.h | 18 | ||||
-rw-r--r-- | saga/actor.cpp | 22 | ||||
-rw-r--r-- | saga/render.cpp | 3 | ||||
-rw-r--r-- | saga/saga.cpp | 4 | ||||
-rw-r--r-- | saga/saga.h | 2 | ||||
-rw-r--r-- | saga/scene.cpp | 18 | ||||
-rw-r--r-- | saga/scene.h | 6 |
8 files changed, 58 insertions, 138 deletions
diff --git a/saga/actionmap.cpp b/saga/actionmap.cpp index b37485c05c..b3e647f0e0 100644 --- a/saga/actionmap.cpp +++ b/saga/actionmap.cpp @@ -32,30 +32,7 @@ namespace Saga { -static void CF_action_info(int argc, char *argv[], void *refCon); - -int ActionMap::reg(void) { - CVAR_RegisterFunc(CF_action_info, - "action_info", NULL, R_CVAR_NONE, 0, 0, this); - return R_SUCCESS; -} - -ActionMap::ActionMap(SagaEngine *vm) : _vm(vm) { - debug(0, "ACTIONMAP Module: Initializing..."); - - _exits_loaded = 0; - _exits_tbl = NULL; - _n_exits = 0; - - _initialized = true; -} - -ActionMap::~ActionMap(void) { - freeMap(); -} - - -int ActionMap::loadMap(const byte * exmap_res, size_t exmap_res_len) { +ActionMap::ActionMap(SagaEngine *vm, const byte * exmap_res, size_t exmap_res_len) : _vm(vm) { // Loads exit map data from specified exit map resource R_ACTIONMAP_ENTRY *exmap_entry; Point *exmap_pt_tbl; @@ -63,7 +40,6 @@ int ActionMap::loadMap(const byte * exmap_res, size_t exmap_res_len) { int exit_ct; int i, pt; - assert(_initialized); assert(exmap_res != NULL); MemoryReadStream readS(exmap_res, exmap_res_len); @@ -71,31 +47,31 @@ int ActionMap::loadMap(const byte * exmap_res, size_t exmap_res_len) { // Load exits exit_ct = readS.readSint16LE(); if (exit_ct < 0) { - return R_FAILURE; + return; } exmap_entry = (R_ACTIONMAP_ENTRY *)malloc(exit_ct * sizeof *exmap_entry); if (exmap_entry == NULL) { warning("Memory allocation failure"); - return R_MEM; + return; } for (i = 0; i < exit_ct; i++) { exmap_entry[i].unknown00 = readS.readSint16LE(); exmap_entry[i].unknown02 = readS.readSint16LE(); - exmap_entry[i].exit_scene = readS.readSint16LE(); + exmap_entry[i].exitScene = readS.readSint16LE(); exmap_entry[i].unknown06 = readS.readSint16LE(); exmap_entry[i].pt_count = readS.readSint16LE(); if (exmap_entry[i].pt_count < 0) { free(exmap_entry); - return R_FAILURE; + return; } exmap_pt_tbl = (Point *)malloc(exmap_entry[i].pt_count * sizeof *exmap_pt_tbl); if (exmap_pt_tbl == NULL) { warning("Memory allocation failure"); - return R_MEM; + return; } for (pt = 0; pt < exmap_entry[i].pt_count; pt++) { @@ -106,103 +82,66 @@ int ActionMap::loadMap(const byte * exmap_res, size_t exmap_res_len) { exmap_entry[i].pt_tbl = exmap_pt_tbl; } - _exits_loaded = 1; - _n_exits = exit_ct; - _exits_tbl = exmap_entry; - - _exmap_res = exmap_res; - _exmap_res_len = exmap_res_len; - - return R_SUCCESS; + _nExits = exit_ct; + _exitsTbl = exmap_entry; } -int ActionMap::freeMap(void) { +ActionMap::~ActionMap(void) { // Frees the currently loaded exit map data R_ACTIONMAP_ENTRY *exmap_entry; int i; - if (!_exits_loaded) { - return R_SUCCESS; - } - - if (_exits_tbl) { - for (i = 0; i < _n_exits; i++) { - exmap_entry = &_exits_tbl[i]; + if (_exitsTbl) { + for (i = 0; i < _nExits; i++) { + exmap_entry = &_exitsTbl[i]; if (exmap_entry != NULL) free(exmap_entry->pt_tbl); } - free(_exits_tbl); + free(_exitsTbl); } - - _exits_loaded = 0; - _exits_tbl = NULL; - _n_exits = 0; - - return R_SUCCESS; } -int ActionMap::shutdown(void) { - return R_SUCCESS; -} - -int ActionMap::draw(R_SURFACE * ds, int color) { +int ActionMap::draw(R_SURFACE *ds, int color) { int i; - assert(_initialized); - - if (!_exits_loaded) { - return R_FAILURE; - } - - for (i = 0; i < _n_exits; i++) { - if (_exits_tbl[i].pt_count == 2) { + for (i = 0; i < _nExits; i++) { + if (_exitsTbl[i].pt_count == 2) { _vm->_gfx->drawFrame(ds, - &_exits_tbl[i].pt_tbl[0], - &_exits_tbl[i].pt_tbl[1], color); - } else if (_exits_tbl[i].pt_count > 2) { - _vm->_gfx->drawPolyLine(ds, _exits_tbl[i].pt_tbl, - _exits_tbl[i].pt_count, color); + &_exitsTbl[i].pt_tbl[0], + &_exitsTbl[i].pt_tbl[1], color); + } else if (_exitsTbl[i].pt_count > 2) { + _vm->_gfx->drawPolyLine(ds, _exitsTbl[i].pt_tbl, + _exitsTbl[i].pt_count, color); } } return R_SUCCESS; } -void ActionMap::actionInfo(int argc, char *argv[]) { +void ActionMap::info(void) { Point *pt; int i; int pt_i; - (void)(argc); - (void)(argv); - - if (!_exits_loaded) { - return; - } - - _vm->_console->print("%d exits loaded.\n", _n_exits); + _vm->_console->print("%d exits loaded.\n", _nExits); - for (i = 0; i < _n_exits; i++) { + for (i = 0; i < _nExits; i++) { _vm->_console->print ("Action %d: Exit to: %d; Pts: %d; Unk0: %d Unk2: %d Scr_N: %d", - i, _exits_tbl[i].exit_scene, - _exits_tbl[i].pt_count, - _exits_tbl[i].unknown00, - _exits_tbl[i].unknown02, - _exits_tbl[i].unknown06); + i, _exitsTbl[i].exitScene, + _exitsTbl[i].pt_count, + _exitsTbl[i].unknown00, + _exitsTbl[i].unknown02, + _exitsTbl[i].unknown06); - for (pt_i = 0; pt_i < _exits_tbl[i].pt_count; pt_i++) { - pt = &_exits_tbl[i].pt_tbl[pt_i]; + for (pt_i = 0; pt_i < _exitsTbl[i].pt_count; pt_i++) { + pt = &_exitsTbl[i].pt_tbl[pt_i]; _vm->_console->print(" pt: %d (%d, %d)", pt_i, pt->x, pt->y); } } } -static void CF_action_info(int argc, char *argv[], void *refCon) { - ((ActionMap *)refCon)->actionInfo(argc, argv); -} - } // End of namespace Saga diff --git a/saga/actionmap.h b/saga/actionmap.h index 0863bd1312..594ce24006 100644 --- a/saga/actionmap.h +++ b/saga/actionmap.h @@ -31,7 +31,7 @@ namespace Saga { struct R_ACTIONMAP_ENTRY { int unknown00; int unknown02; - int exit_scene; + int exitScene; int unknown06; int pt_count; @@ -41,26 +41,18 @@ struct R_ACTIONMAP_ENTRY { class ActionMap { public: int reg(void); - ActionMap(SagaEngine *vm); + ActionMap(SagaEngine *vm, const byte *exmap_res, size_t exmap_res_len); ~ActionMap(void); - int loadMap(const byte *exmap_res, size_t exmap_res_len); int draw(R_SURFACE *ds, int color); - int freeMap(void); - int shutdown(void); - - void actionInfo(int argc, char *argv[]); + void info(void); private: SagaEngine *_vm; - bool _initialized; - int _exits_loaded; - int _n_exits; - R_ACTIONMAP_ENTRY *_exits_tbl; - const byte *_exmap_res; - size_t _exmap_res_len; + int _nExits; + R_ACTIONMAP_ENTRY *_exitsTbl; }; } // End of namespace Saga diff --git a/saga/actor.cpp b/saga/actor.cpp index f11c23f267..9433be5a6e 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -906,9 +906,8 @@ int Actor::handleWalkIntent(R_ACTOR *actor, R_WALKINTENT *a_walkint, int *comple new_a_x = path_x + a_walkint->org.x; new_a_y = path_y + a_walkint->org.y; - if (a_walkint->x_dir == 1) { - - if (new_a_x >= node_p->node_pt.x) { + if (((a_walkint->x_dir == 1) && new_a_x >= node_p->node_pt.x) || + ((a_walkint->x_dir != 1) && (new_a_x <= node_p->node_pt.x))) { debug(2, "Path complete."); ys_dll_delete(walk_p); a_walkint->wi_active = 0; @@ -922,23 +921,6 @@ int Actor::handleWalkIntent(R_ACTOR *actor, R_WALKINTENT *a_walkint, int *comple actor->action = ACTION_IDLE; *complete_p = 1; return R_FAILURE; - } - } else { - if (new_a_x <= node_p->node_pt.x) { - debug(2, "Path complete."); - ys_dll_delete(walk_p); - a_walkint->wi_active = 0; - - // Release path semaphore - if (a_walkint->sem != NULL) { - _vm->_script->SThreadReleaseSem(a_walkint->sem); - } - - actor->action_frame = 0; - actor->action = ACTION_IDLE; - *complete_p = 1; - return R_FAILURE; - } } actor_x = (int)new_a_x; diff --git a/saga/render.cpp b/saga/render.cpp index b28b1f384e..0d1337e68b 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -34,7 +34,6 @@ #include "saga/scene.h" #include "saga/text.h" -#include "saga/actionmap.h" #include "saga/objectmap.h" #include "saga/render.h" @@ -137,7 +136,7 @@ int Render::drawScene() { // Display scene maps, if applicable if (getFlags() & RF_OBJECTMAP_TEST) { _omap->draw(backbuf_surface, &mouse_pt, _gfx->getWhite(), _gfx->getBlack()); - _vm->_actionMap->draw(backbuf_surface, _gfx->matchColor(R_RGB_RED)); + _vm->_scene->drawActionMap(backbuf_surface, _gfx->matchColor(R_RGB_RED)); } // Draw queued actors diff --git a/saga/saga.cpp b/saga/saga.cpp index 50f38437c2..6b1b2780c8 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -40,7 +40,6 @@ #include "saga/console.h" #include "saga/cvar_mod.h" #include "saga/events.h" -#include "saga/actionmap.h" #include "saga/font.h" #include "saga/game_mod.h" #include "saga/game.h" @@ -185,7 +184,6 @@ void SagaEngine::go() { _gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h); _isoMap = new IsoMap(_gfx); - _actionMap = new ActionMap(this); _objectMap = new ObjectMap(_gfx); _render = new Render(this, _system, _gfx, _objectMap); @@ -207,7 +205,6 @@ void SagaEngine::go() { _script->reg(); _render->reg(); _anim->reg(); - _actionMap->reg(); _objectMap->reg(); _previousTicks = _system->getMillis(); @@ -256,7 +253,6 @@ void SagaEngine::shutdown() { delete _interface; delete _render; - delete _actionMap; delete _isoMap; delete _objectMap; delete _sndRes; diff --git a/saga/saga.h b/saga/saga.h index 6aa4aabe34..63456c5a20 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -45,7 +45,6 @@ class Sound; class Music; class Anim; class Render; -class ActionMap; class IsoMap; class ObjectMap; class Gfx; @@ -100,7 +99,6 @@ public: Music *_music; Anim *_anim; Render *_render; - ActionMap *_actionMap; IsoMap *_isoMap; ObjectMap *_objectMap; Gfx *_gfx; diff --git a/saga/scene.cpp b/saga/scene.cpp index 72227eecf3..3eb0f1b64d 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -48,11 +48,15 @@ namespace Saga { static void CF_scenechange(int argc, char *argv[], void *refCon); static void CF_sceneinfo(int argc, char *argv[], void *refCon); +static void CF_actioninfo(int argc, char *argv[], void *refCon); + int Scene::reg() { CVAR_Register_I(&_sceneNumber, "scene", NULL, R_CVAR_READONLY, 0, 0); CVAR_RegisterFunc(CF_scenechange, "scene_change", "<Scene number>", R_CVAR_NONE, 1, 1, this); CVAR_RegisterFunc(CF_sceneinfo, "scene_info", NULL, R_CVAR_NONE, 0, 0, this); + CVAR_RegisterFunc(CF_actioninfo, + "action_info", NULL, R_CVAR_NONE, 0, 0, this); return R_SUCCESS; } @@ -678,10 +682,7 @@ int Scene::processSceneResources() { break; case SAGA_ACTION_MAP: debug(0, "Loading exit map resource..."); - if (_vm->_actionMap->loadMap(res_data, res_data_len) != R_SUCCESS) { - warning("Scene::ProcessSceneResources(): Error loading exit map resource"); - return R_FAILURE; - } + _actionMap = new ActionMap(_vm, res_data, res_data_len); break; case SAGA_ISO_TILESET: if (_sceneMode == R_SCENE_MODE_NORMAL) { @@ -851,7 +852,7 @@ int Scene::endScene() { _vm->_palanim->freePalAnim(); _vm->_objectMap->freeMem(); - _vm->_actionMap->freeMap(); + delete _actionMap; ys_dll_destroy(_animList); @@ -916,6 +917,13 @@ int Scene::SC_defaultScene(int param, R_SCENE_INFO *scene_info, void *refCon) { return ((Scene *)refCon)->defaultScene(param, scene_info); } +static void CF_actioninfo(int argc, char *argv[], void *refCon) { + (void)(argc); + (void)(argv); + + ((Scene *)refCon)->_actionMap->info(); +} + int Scene::defaultScene(int param, R_SCENE_INFO *scene_info) { R_EVENT event; diff --git a/saga/scene.h b/saga/scene.h index e787722c2d..6a7a0ce480 100644 --- a/saga/scene.h +++ b/saga/scene.h @@ -27,6 +27,7 @@ #define SAGA_SCENE_H #include "saga/text.h" +#include "saga/actionmap.h" namespace Saga { @@ -235,6 +236,8 @@ class Scene { void sceneInfoCmd(int argc, char *argv[]); void sceneChangeCmd(int argc, char *argv[]); + void drawActionMap(R_SURFACE *ds, int color) { _actionMap->draw(ds, color); } + private: int loadScene(int scene, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC *, int fadeIn); @@ -271,6 +274,9 @@ class Scene { static int SC_defaultScene(int param, R_SCENE_INFO *scene_info, void *refCon); int defaultScene(int param, R_SCENE_INFO *scene_info); + public: + ActionMap *_actionMap; + private: int IHNMStartProc(); int ITEStartProc(); |