From 4b440c0ac3040267be036e536c3e1ad69a5ef49d Mon Sep 17 00:00:00 2001 From: Treeki Date: Tue, 15 Mar 2011 04:52:35 +0100 Subject: refactored WorldMap to use the same init method as Nintendo (function chains) --- src/worldmap.cpp | 239 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 117 deletions(-) (limited to 'src') diff --git a/src/worldmap.cpp b/src/worldmap.cpp index d537ff6..cd43a47 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -18,22 +18,30 @@ dScNewerWorldMap_c *dScNewerWorldMap_c::build() { return c; } - -/*ChainedFunc *initFunctions[] = { +bool WMInit_StartLoading(void*); +bool WMInit_LoadSIAnims(void*); +bool WMInit_EndLoading(void*); +bool WMInit_LoadResources(void*); +bool WMInit_SetupWait(void*); +bool WMInit_SetupExtra(void*); +bool WMInit_SetupWipe(void*); + +ChainedFunc initFunctions[] = { WMInit_StartLoading, - WMInit_LoadResources, + WMInit_LoadSIAnims, WMInit_EndLoading, - WMInit_CreateManagers, + WMInit_LoadResources, WMInit_SetupWait, + WMInit_SetupExtra, WMInit_SetupWipe }; - dScNewerWorldMap_c::dScNewerWorldMap_c() { - initChain.setup( + initChain.setup(initFunctions, 6); setInitChain(initChain); -}*/ +} + #define SELC_SETUP_DONE(sc) (*((bool*)(((u32)(sc))+0xD38))) @@ -88,12 +96,106 @@ dScNewerWorldMap_c::dScNewerWorldMap_c() { #define CONT_DONE(cont) (*((bool*)(((u32)(cont))+0x2D7))) #define CONT_UNK3(cont) (*((bool*)(((u32)(cont))+0x2E0))) +bool WMInit_StartLoading(void *ptr) { + DVD_Start(); + return true; +} + +bool WMInit_LoadSIAnims(void *ptr) { + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_kinoko", 0); + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_fireflower", 0); + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_iceflower", 0); + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_penguin", 0); + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_propeller", 0); + DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_star", 0); + return true; +} + +bool WMInit_EndLoading(void *ptr) { + if (DVD_StillLoading(GetDVDClass2())) + return false; + + DVD_End(); + return true; +} + +bool WMInit_LoadResources(void *ptr) { + dScNewerWorldMap_c *wm = (dScNewerWorldMap_c*)ptr; + return wm->resMng.loadSet("SMGoldwood"); +} + +bool WMInit_SetupWait(void *ptr) { + dScNewerWorldMap_c *wm = (dScNewerWorldMap_c*)ptr; + + bool success = true; + + success &= CSMENU_SETUP_DONE(wm->csMenu); + success &= SELC_SETUP_DONE(wm->selectCursor); + success &= NPCHG_SETUP_DONE(wm->numPeopleChange); + success &= YESNO_SETUP_DONE(wm->yesNoWindow); + success &= CONT_SETUP_DONE(wm->continueObj); + success &= STKI_SETUP_DONE(wm->stockItem); + success &= SIS_SETUP_DONE(wm->stockItemShadow); + success &= EASYP_SETUP_DONE(wm->easyPairing); + + return success; +} + +bool WMInit_SetupExtra(void *ptr) { + // ok, now we can set up other required shit + dScNewerWorldMap_c *wm = (dScNewerWorldMap_c*)ptr; + + // first up: player models for Stocked Items + for (int i = 0; i < 4; i++) { + void *obj = CreateChildObject(WM_2D_PLAYER, wm, i, 0, 0); + STKI_2DPLAYER(wm->stockItem,i) = obj; + NPCHG_2DPLAYER(wm->numPeopleChange,i) = obj; + } + + // next: items for the Powerup screen + for (int i = 0; i < 7; i++) { + void *obj = CreateChildObject(WM_ITEM, wm, i, 0, 0); + STKI_ITEM(wm->stockItem,i) = obj; + } + + // since we've got all the resources, set up the path data too + wm->pathData.load(wm->resMng['PATH']); + + SaveBlock *save = GetSaveFile()->GetBlock(-1); + if (save->current_path_node >= wm->pathData.pointCount()) { + wm->currentPoint = wm->pathData.getPath(0)->startPoint; + } else { + wm->currentPoint = wm->pathData.getPoint(save->current_path_node); + } + + // and now Player setup + wm->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, wm, 0, 2); + wm->player->modelHandler->mdlClass->setPowerup(2); + wm->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f); + wm->player->pos = wm->currentPoint->position; + + return true; +} + +bool WMInit_SetupWipe(void *ptr) { + dScNewerWorldMap_c *wm = (dScNewerWorldMap_c*)ptr; + + if (wm->hasUninitialisedProcesses()) + return false; + + return true; +} + + + + + // Todo: remove level menu related states from here -#define STATE_START_DVD 0 +/*#define STATE_START_DVD 0 #define STATE_LOAD_RES 1 #define STATE_END_DVD 2 -#define STATE_SETUP_WAIT 3 +#define STATE_SETUP_WAIT 3*/ #define STATE_LIMBO 4 #define STATE_CONTINUE_WAIT 5 #define STATE_NORMAL 6 @@ -173,6 +275,16 @@ int dScNewerWorldMap_c::onCreate() { this->continueObj = CreateParentedObject(CONTINUE, this, 0, 0); + // check if we need to handle Continue + if (CheckIfContinueShouldBeActivated()) { + this->state = STATE_CONTINUE_WAIT; + CONT_UNK1(this->continueObj) = true; + CONT_UNK2(this->continueObj) = true; + CONT_UNK3(this->continueObj) = false; + } else { + this->state = STATE_NORMAL; + } + this->stockItem = CreateParentedObject(STOCK_ITEM, this, 0, 0); this->stockItemShadow = CreateParentedObject(STOCK_ITEM_SHADOW, this, 0, 0); STKI_SHADOW(this->stockItem) = this->stockItemShadow; @@ -181,8 +293,6 @@ int dScNewerWorldMap_c::onCreate() { CreateParentedObject(WORLD_CAMERA, this, 0, 0); - this->state = STATE_START_DVD; - *CurrentDrawFunc = NewerMapDrawFunc; // level info @@ -212,6 +322,7 @@ int dScNewerWorldMap_c::onExecute() { if (QueryGlobal5758(0xFFFFFFFF)) return true; if (CheckIfWeCantDoStuff()) return true; + if (this->state == STATE_LIMBO) return true; /**************************************************************************/ // Read Wiimote Buttons @@ -223,112 +334,6 @@ int dScNewerWorldMap_c::onExecute() { // State Specific switch (this->state) { - /**********************************************************************/ - // STATE_START_DVD : Set up DVD - case STATE_START_DVD: - - DVD_Start(); - this->state = STATE_LOAD_RES; - - break; - - /**********************************************************************/ - // STATE_LOAD_RES : Load extra stuff we need - case STATE_LOAD_RES: - - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_kinoko", 0); - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_fireflower", 0); - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_iceflower", 0); - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_penguin", 0); - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_propeller", 0); - DVD_LoadFile(GetDVDClass(), "WorldMap", "SI_star", 0); - //DVD_LoadFile(GetDVDClass(), "Object", "fruits_kusa_gake", 0); - - this->state = STATE_END_DVD; - - break; - - /**********************************************************************/ - // STATE_END_DVD : Wait for files to load, end DVD - // Also, load the WM Set files - case STATE_END_DVD: { - - bool didEndDVD = false, didWMSetLoad = false; - - if (!DVD_StillLoading(GetDVDClass2())) { - if (DVD_End()) { - didEndDVD = true; - } - } - - didWMSetLoad = resMng.loadSet("SMGoldwood"); - - if (didEndDVD && didWMSetLoad) - this->state = STATE_SETUP_WAIT; - - } break; - - /**********************************************************************/ - // STATE_SETUP_WAIT : Waiting for the world map managers to be set up - case STATE_SETUP_WAIT: { - - bool success = true; - - success &= CSMENU_SETUP_DONE(this->csMenu); - success &= SELC_SETUP_DONE(this->selectCursor); - success &= NPCHG_SETUP_DONE(this->numPeopleChange); - success &= YESNO_SETUP_DONE(this->yesNoWindow); - success &= CONT_SETUP_DONE(this->continueObj); - success &= STKI_SETUP_DONE(this->stockItem); - success &= SIS_SETUP_DONE(this->stockItemShadow); - success &= EASYP_SETUP_DONE(this->easyPairing); - - if (success) { - // ok, now we can set up other required shit - - // first up: player models for Stocked Items - for (int i = 0; i < 4; i++) { - void *obj = CreateChildObject(WM_2D_PLAYER, this, i, 0, 0); - STKI_2DPLAYER(this->stockItem,i) = obj; - NPCHG_2DPLAYER(this->numPeopleChange,i) = obj; - } - - // next: items for the Powerup screen - for (int i = 0; i < 7; i++) { - void *obj = CreateChildObject(WM_ITEM, this, i, 0, 0); - STKI_ITEM(this->stockItem,i) = obj; - } - - // now, check if we need to handle Continue - if (CheckIfContinueShouldBeActivated()) { - this->state = STATE_CONTINUE_WAIT; - CONT_UNK1(this->continueObj) = true; - CONT_UNK2(this->continueObj) = true; - CONT_UNK3(this->continueObj) = false; - } else { - this->state = STATE_NORMAL; - } - - // since we've got all the resources, set up the path data too - pathData.load(resMng['PATH']); - - SaveBlock *save = GetSaveFile()->GetBlock(-1); - - if (save->current_path_node >= pathData.pointCount()) { - this->currentPoint = pathData.getPath(0)->startPoint; - } else { - this->currentPoint = pathData.getPoint(save->current_path_node); - } - - // and now Player setup - this->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, this, 0, 2); - this->player->modelHandler->mdlClass->setPowerup(2); - this->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f); - this->player->pos = this->currentPoint->position; -s } - - } break; - /**********************************************************************/ // STATE_CONTINUE_WAIT : Waiting for the Continue anim to finish case STATE_CONTINUE_WAIT: -- cgit v1.2.3