summaryrefslogtreecommitdiff
path: root/src/koopatlas/core.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-02-27 18:54:32 +0100
committerTreeki <treeki@gmail.com>2012-02-27 18:54:32 +0100
commit21d7e41b006b88aa79821610661fefc8fe14b7ca (patch)
treed9abd10293781666afc31fc4af5b6de503e2867c /src/koopatlas/core.cpp
parente45c4a7a24a6a58804261d73c14f008bff1b5a68 (diff)
downloadkamek-21d7e41b006b88aa79821610661fefc8fe14b7ca.tar.gz
kamek-21d7e41b006b88aa79821610661fefc8fe14b7ca.zip
switching between multiple maps
Diffstat (limited to '')
-rw-r--r--src/koopatlas/core.cpp113
1 files changed, 99 insertions, 14 deletions
diff --git a/src/koopatlas/core.cpp b/src/koopatlas/core.cpp
index 7eaa339..f7acf00 100644
--- a/src/koopatlas/core.cpp
+++ b/src/koopatlas/core.cpp
@@ -47,7 +47,8 @@ dScKoopatlas_c *dScKoopatlas_c::build() {
bool WMInit_StartLoading(void*);
bool WMInit_LoadSIAnims(void*);
bool WMInit_EndLoading(void*);
-bool WMInit_LoadResources(void*);
+bool WMInit_LoadResources1(void*);
+bool WMInit_LoadResources2(void*);
bool WMInit_SetupWait(void*);
bool WMInit_SetupExtra(void*);
bool WMInit_SetupWipe(void*);
@@ -56,14 +57,15 @@ ChainedFunc initFunctions[] = {
WMInit_StartLoading,
WMInit_LoadSIAnims,
WMInit_EndLoading,
- WMInit_LoadResources,
+ WMInit_LoadResources1,
+ WMInit_LoadResources2,
WMInit_SetupWait,
WMInit_SetupExtra,
WMInit_SetupWipe
};
dScKoopatlas_c::dScKoopatlas_c() : state(this) {
- initChain.setup(initFunctions, 7);
+ initChain.setup(initFunctions, 8);
setInitChain(initChain);
}
@@ -154,13 +156,28 @@ bool WMInit_EndLoading(void *ptr) {
return true;
}
-bool WMInit_LoadResources(void *ptr) {
- SpammyReport("WMInit_LoadResources returning true\n");
+bool WMInit_LoadResources1(void *ptr) {
+ SpammyReport("WMInit_LoadResources1 returning true\n");
dScKoopatlas_c *wm = (dScKoopatlas_c*)ptr;
- return
- wm->mapData.load("/Maps/yat.kpbin") &&
- wm->levelInfoLoader.load("/NewerRes/LevelInfo.bin");
+
+ bool result1 = wm->mapListLoader.load("/Maps/List.txt");
+ bool result2 = wm->levelInfoLoader.load("/NewerRes/LevelInfo.bin");
+ return result1 && result2;
+}
+
+bool WMInit_LoadResources2(void *ptr) {
+ SpammyReport("WMInit_LoadResources2 returning true\n");
+
+ dScKoopatlas_c *wm = (dScKoopatlas_c*)ptr;
+
+ if (wm->mapPath == 0) {
+ wm->mapPath = wm->getMapNameForIndex(wm->currentMapID);
+ if (wm->mapPath == 0)
+ wm->mapPath = wm->getMapNameForIndex(0);
+ }
+
+ return wm->mapData.load(wm->mapPath);
}
bool WMInit_SetupWait(void *ptr) {
@@ -339,13 +356,12 @@ int dScKoopatlas_c::onCreate() {
SpammyReport("setting NewerMapDrawFunc\n");
*CurrentDrawFunc = NewerMapDrawFunc;
- // level info
- /*SpammyReport("loading level info file\n");
- levelInfoFile.open("/NewerRes/LevelInfo.bin");
- SpammyReport("preparing level info\n");
- levelInfo.load(levelInfoFile.ptr());*/
-
SpammyReport("onCreate() completed\n");
+
+ // Prepare this first
+ SaveBlock *save = GetSaveFile()->GetBlock(-1);
+ currentMapID = save->current_world;
+
return true;
}
@@ -361,6 +377,7 @@ int dScKoopatlas_c::onDelete() {
DVD_FreeFile(GetDVDClass2(), "SI_star");
levelInfoLoader.unload();
+ mapListLoader.unload();
return true;
}
@@ -831,6 +848,74 @@ void dScKoopatlas_c::startLevel(dLevelInfo_c::entry_s *entry) {
}
+u32 dScKoopatlas_c::iterateMapList(u32(*callback)(u32,const char *,int,int), u32 userData, int *ptrIndex) {
+ u8 *ptr = (u8*)mapListLoader.buffer;
+ u8 *strStart = ptr;
+ u8 *end = ptr + mapListLoader.size;
+ int index = 0;
+
+ while (true) {
+ u8 chr = *ptr;
+ if (chr == 13) {
+ ++ptr;
+ continue;
+ }
+
+ if (chr == 10 || chr == 0 || ptr >= end) {
+ if (strStart == ptr) {
+ // Blank string, ignore
+ ++strStart;
+ ++ptr;
+ continue;
+ }
+
+ // Change the linefeed to a NUL so we can use the line as a C string later
+ if (ptr < end)
+ *ptr = 0;
+
+ u32 ret = callback(userData, (const char*)strStart, ptr - strStart, index);
+ if (ptrIndex)
+ *ptrIndex = index;
+ if (ret > 0)
+ return ret;
+
+ strStart = ++ptr;
+ ++index;
+
+ if (ptr >= end)
+ break;
+
+ } else {
+ ++ptr;
+ }
+ }
+
+ return 0;
+}
+
+static u32 _cb_getIndex(u32 userData, const char *str, int size, int index) {
+ if (index == userData)
+ return (u32)str;
+ else
+ return 0;
+}
+
+static u32 _cb_searchName(u32 userData, const char *str, int size, int index) {
+ if (strncmp(str, (const char*)userData, size) == 0)
+ return (u32)(index+1);
+ else
+ return 0;
+}
+
+const char *dScKoopatlas_c::getMapNameForIndex(int index) {
+ return (const char *)iterateMapList(&_cb_getIndex, (u32)index, 0);
+}
+
+int dScKoopatlas_c::getIndexForMapName(const char *name) {
+ return ((int)iterateMapList(&_cb_searchName, (u32)name, 0)) - 1;
+}
+
+
void NewerMapDrawFunc() {
Reset3DState();
SetCurrentCameraID(0);