summaryrefslogtreecommitdiff
path: root/src/koopatlas/core.cpp
diff options
context:
space:
mode:
authorColin Noga <Tempus@chronometry.ca>2012-02-27 12:34:56 -0600
committerColin Noga <Tempus@chronometry.ca>2012-02-27 12:34:56 -0600
commitd6924bebc44bf904ec3e9ed8126614f67a04df88 (patch)
tree159e94b87aa174b4bc86f565db975adfab729efe /src/koopatlas/core.cpp
parent12e4a674748be41a0105f6a7b3b8132d0a3a65b4 (diff)
parent21d7e41b006b88aa79821610661fefc8fe14b7ca (diff)
downloadkamek-d6924bebc44bf904ec3e9ed8126614f67a04df88.tar.gz
kamek-d6924bebc44bf904ec3e9ed8126614f67a04df88.zip
Merge branch 'level-select' of ssh://treeki.rustedlogic.net:30000/Kamek into level-select
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);