summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-03-15 01:51:28 +0100
committerTreeki <treeki@gmail.com>2011-03-15 01:51:28 +0100
commitc73a4a4f79ae7974509b134cd3225307099a7900 (patch)
treeca5f9d0b4c8fd0966e74bdfb3bc864272fdb3d6f
parent793fc74bd957eea3930e30aae704e47adee5e015 (diff)
downloadkamek-c73a4a4f79ae7974509b134cd3225307099a7900.tar.gz
kamek-c73a4a4f79ae7974509b134cd3225307099a7900.zip
WorldMapData is now dWMPathData_c and loads its data from the resource manager
-rwxr-xr-xinclude/game.h12
-rw-r--r--setgen.py1
-rw-r--r--src/wmresourcemng.cpp20
-rw-r--r--src/worldmap.cpp47
-rw-r--r--src/worldmap.h7
-rw-r--r--src/worldmapdata.cpp75
-rw-r--r--src/worldmapdata.h60
7 files changed, 132 insertions, 90 deletions
diff --git a/include/game.h b/include/game.h
index 6df656f..13e5be2 100755
--- a/include/game.h
+++ b/include/game.h
@@ -792,10 +792,13 @@ struct Tree {
typedef bool (*ChainedFunc)(void*);
-struct FunctionChain {
+class FunctionChain {
+public:
ChainedFunc *functions;
u16 count;
u16 current;
+
+ void setup(ChainedFunc *functions, u16 count); // 8015F740
};
@@ -876,7 +879,7 @@ public:
class dScene_c : public dBase_c {
public:
- FunctionChain *funcChain;
+ FunctionChain *ptrToInitChain;
dScene_c();
@@ -890,6 +893,11 @@ public:
int afterDraw();
~dScene_c();
+
+
+ void setInitChain(FunctionChain &initChain) {
+ ptrToInitChain = &initChain;
+ }
};
class dActor_c : public dBase_c {
diff --git a/setgen.py b/setgen.py
index 07253f9..68d7f12 100644
--- a/setgen.py
+++ b/setgen.py
@@ -2,6 +2,7 @@ import struct
names = {}
names['PATH'] = '/Maps/forest/pathdata.bin'
+names['SCN0'] = '/Maps/forest/mainscene.bin'
names['3D00'] = '/Maps/forest/base.brres'
header = struct.pack('>4sI', b'MSet', len(names))
diff --git a/src/wmresourcemng.cpp b/src/wmresourcemng.cpp
index 088cef4..741abb2 100644
--- a/src/wmresourcemng.cpp
+++ b/src/wmresourcemng.cpp
@@ -63,12 +63,18 @@ bool dWMResourceMng_c::loadSet(const char *setName) {
// now try to load every resource
// if even ONE of them fails, then don't return true
- bool isLoadingComplete = true;
+ isLoadingComplete = true;
for (int i = 0; i < setData->count; i++) {
void *thisResource = resLoaders[i].load(setData->getName(i));
- MapReport("Load(%s) result: %p\n", setData->getName(i), thisResource);
+ u32 key = setData->entries[i].key;
+ char key1 = key >> 24;
+ char key2 = key >> 16;
+ char key3 = key >> 8;
+ char key4 = key & 0xFF;
+
+ MapReport("Load(%c%c%c%c:%s) result: %p\n", key>>24, key>>16, key>>8, key&0xFF, setData->getName(i), thisResource);
isLoadingComplete &= (thisResource != 0);
}
@@ -76,6 +82,8 @@ bool dWMResourceMng_c::loadSet(const char *setName) {
// if they are ALL loaded, then this will be true
if (isLoadingComplete) {
prepareResources();
+
+ MapReport("Loading completed!\n");
}
return isLoadingComplete;
@@ -83,14 +91,20 @@ bool dWMResourceMng_c::loadSet(const char *setName) {
void *dWMResourceMng_c::operator[](u32 key) {
- if (!isLoadingComplete)
+ MapReport("Obtaining resource %c%c%c%c\n", key>>24, key>>16, key>>8, key&0xFF);
+
+ if (!isLoadingComplete) {
+ MapReport("Loading is not complete. Returning 0\n");
return 0;
+ }
for (int i = 0; i < setData->count; i++) {
if (key == setData->entries[i].key)
return resLoaders[i].buffer;
}
+ MapReport("Not found!\n");
+
return 0;
}
diff --git a/src/worldmap.cpp b/src/worldmap.cpp
index d24710c..d537ff6 100644
--- a/src/worldmap.cpp
+++ b/src/worldmap.cpp
@@ -19,6 +19,23 @@ dScNewerWorldMap_c *dScNewerWorldMap_c::build() {
}
+/*ChainedFunc *initFunctions[] = {
+ WMInit_StartLoading,
+ WMInit_LoadResources,
+ WMInit_EndLoading,
+ WMInit_CreateManagers,
+ WMInit_SetupWait,
+ WMInit_SetupWipe
+};
+
+
+dScNewerWorldMap_c::dScNewerWorldMap_c() {
+ initChain.setup(
+
+ setInitChain(initChain);
+}*/
+
+
#define SELC_SETUP_DONE(sc) (*((bool*)(((u32)(sc))+0xD38)))
#define EASYP_SETUP_DONE(ep) (*((bool*)(((u32)(ep))+0x278)))
@@ -172,22 +189,8 @@ int dScNewerWorldMap_c::onCreate() {
levelInfoFile.open("/NewerRes/LevelInfo.bin");
levelInfo.load(levelInfoFile.ptr());
- // load the menu info
- SaveBlock *save = GetSaveFile()->GetBlock(-1);
-
LoadModel();
- wmData.load("/NewerRes/TestMap.wm");
-
-
- WMDataHeader *hdr = (WMDataHeader*)wmData.fh.filePtr;
- if (save->current_path_node >= hdr->pointCount) {
- this->currentPoint = wmData.getPath(0)->startPoint;
- } else {
- this->currentPoint = hdr->pointList[save->current_path_node];
- }
-
-
return true;
}
@@ -306,12 +309,23 @@ int dScNewerWorldMap_c::onExecute() {
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;
@@ -791,6 +805,7 @@ void dScNewerWorldMap_c::HandleMovement() {
else if (nowPressed & WPAD_DOWN && currentPoint->exits.asDirection.down.isValid())
StartMovementTo(DOWN);
+
if (nowPressed & WPAD_TWO)
ActivatePoint();
}
@@ -855,7 +870,7 @@ void dScNewerWorldMap_c::MoveThroughPath() {
SaveBlock *save = GetSaveFile()->GetBlock(-1);
//save->current_world = newPage; ?
- save->current_path_node = wmData.getPointID(this->currentPoint);
+ save->current_path_node = pathData.getPointID(this->currentPoint);
} else {
this->MoveToSegment(nextSegment);
}
diff --git a/src/worldmap.h b/src/worldmap.h
index 8ea7e4c..8813e6d 100644
--- a/src/worldmap.h
+++ b/src/worldmap.h
@@ -92,6 +92,10 @@ public:
// WORLD MAP CLASS LAYOUT
class dScNewerWorldMap_c : public dScene_c {
public:
+ dScNewerWorldMap_c();
+
+ FunctionChain initChain;
+
int state;
void *csMenu;
void *selectCursor;
@@ -106,6 +110,7 @@ public:
LevelInfo levelInfo;
dWMResourceMng_c resMng;
+ dWMPathData_c pathData;
mHeapAllocator_c allocator;
File modelFile;
@@ -115,8 +120,6 @@ public:
daWMPlayer_c *player;
- WorldMapData wmData;
-
bool isMoving;
WMPathPoint *currentPoint;
WMPathPoint *nextPoint;
diff --git a/src/worldmapdata.cpp b/src/worldmapdata.cpp
index 0473bbb..2f23afc 100644
--- a/src/worldmapdata.cpp
+++ b/src/worldmapdata.cpp
@@ -1,59 +1,59 @@
-#include "worldmapdata.h"
+#include "worldmap.h"
+
+dWMPathData_c::dWMPathData_c() {
-WorldMapData::WorldMapData() {
-
}
-WorldMapData::~WorldMapData() {
- FreeFile(&this->fh);
+dWMPathData_c::~dWMPathData_c() {
+
}
-bool WorldMapData::load(const char *filename) {
- OSReport("Loading WM Data file: %s\n", filename);
-
- u32 ptr = (u32)LoadFile(&this->fh, filename);
- WMDataHeader *header = (WMDataHeader*)ptr;
-
- OSReport("Loaded WM Data file @ %p\n", ptr);
-
+bool dWMPathData_c::load(void *data) {
+ MapReport("dWMPathData_c initialised with %p\n", data);
+
+ WMPathHeader *header = (WMPathHeader*)data;
+ this->data = header;
+
+ u32 ptr = (u32)data; // for easy addition! probably bad practice, but whatever..
+
// first off, fix the list pointers
header->pathList = (WMPathDef**)((u32)header->pathList + ptr);
header->pointList = (WMPathPoint**)((u32)header->pointList + ptr);
header->segmentList = (WMPathSegment**)((u32)header->segmentList + ptr);
header->actionList = (WMPathAction**)((u32)header->actionList + ptr);
-
+
// now, fix every pointer in the lists
- OSReport("Fixing up list pointers\n");
+ MapReport("Fixing up list pointers\n");
for (int i = 0; i < header->pathCount; i++)
header->pathList[i] = (WMPathDef*)((u32)header->pathList[i] + ptr);
-
+
for (int i = 0; i < header->pointCount; i++)
header->pointList[i] = (WMPathPoint*)((u32)header->pointList[i] + ptr);
-
+
for (int i = 0; i < header->segmentCount; i++)
header->segmentList[i] = (WMPathSegment*)((u32)header->segmentList[i] + ptr);
-
+
for (int i = 0; i < header->actionCount; i++)
header->actionList[i] = (WMPathAction*)((u32)header->actionList[i] + ptr);
-
+
// next up, fix every pointer in these structs
- OSReport("Fixing up path pointers [%d]\n", header->pathCount);
+ MapReport("Fixing up path pointers [%d]\n", header->pathCount);
for (int i = 0; i < header->pathCount; i++) {
WMPathDef *thisPath = header->pathList[i];
- //OSReport("Path @ %p - Index: %d - Segments: %d\n", thisPath, i, thisPath->segCount);
-
+ //MapReport("Path @ %p - Index: %d - Segments: %d\n", thisPath, i, thisPath->segCount);
+
thisPath->startPoint = header->pointList[(u32)thisPath->startPoint];
thisPath->endPoint = header->pointList[(u32)thisPath->endPoint];
-
+
for (int j = 0; j < thisPath->segCount; j++) {
thisPath->segments[j] = header->segmentList[(u32)thisPath->segments[j]];
}
}
-
- OSReport("Fixing up point pointers [%d]\n", header->pointCount);
+
+ MapReport("Fixing up point pointers [%d]\n", header->pointCount);
for (int i = 0; i < header->pointCount; i++) {
WMPathPoint *thisPoint = header->pointList[i];
-
+
for (int j = 0; j < 4; j++) {
if ((u32)thisPoint->exits.asArray[j].path == -1) {
thisPoint->exits.asArray[j].path = 0;
@@ -62,32 +62,31 @@ bool WorldMapData::load(const char *filename) {
}
}
}
-
- OSReport("Fixing up segment pointers [%d]\n", header->segmentCount);
+
+ MapReport("Fixing up segment pointers [%d]\n", header->segmentCount);
for (int i = 0; i < header->segmentCount; i++) {
WMPathSegment *thisSegment = header->segmentList[i];
-
+
if ((u32)thisSegment->action == -1) {
thisSegment->action = 0;
} else {
thisSegment->action = header->actionList[(u32)thisSegment->action];
}
}
-
- OSReport("Load complete\n");
-
+
+ MapReport("Load complete\n");
+
return true;
}
-int WorldMapData::getPointID(WMPathPoint *point) {
- WMDataHeader *header = (WMDataHeader*)this->fh.filePtr;
-
- for (int i = 0; i < header->pointCount; i++) {
- if (header->pointList[i] == point)
+int dWMPathData_c::getPointID(WMPathPoint *point) {
+ for (int i = 0; i < data->pointCount; i++) {
+ if (data->pointList[i] == point)
return i;
}
-
+
return -1;
}
+
diff --git a/src/worldmapdata.h b/src/worldmapdata.h
index 1d6a305..16322b0 100644
--- a/src/worldmapdata.h
+++ b/src/worldmapdata.h
@@ -1,7 +1,7 @@
#ifndef __NEWER_WORLDMAPDATA_H
#define __NEWER_WORLDMAPDATA_H
-#include "fileload.h"
+#include <common.h>
#include <rvl/mtx.h>
// Forward declarations
@@ -12,7 +12,7 @@ struct WMPathDef;
// here's a note: while most of these structs contain pointers to other structs,
// in the data file these fields actually contain an index into the lists
-// (defined in WMDataHeader)
+// (defined in WMPathHeader)
// WorldMapData::load() fixes these offsets.
/******************************************************************************/
@@ -26,7 +26,7 @@ struct WMPathDef;
struct WMPathEntrance {
WMPathDef *path;
bool isEndSide;
-
+
bool isValid() { return (this->path != 0); }
};
@@ -39,7 +39,7 @@ struct WMPathPoint {
NONE_TYPE,
LEVEL_TYPE
};
-
+
// Paths you arrive on when you press a direction when at this point
union {
struct {
@@ -50,11 +50,11 @@ struct WMPathPoint {
} asDirection;
WMPathEntrance asArray[4];
} exits;
-
+
// Point metadata
PointType type;
int params[4];
-
+
Vec position;
};
@@ -67,7 +67,7 @@ struct WMPathAction {
enum ActionType {
TELEPORT_TYPE // teleports to another submap
};
-
+
// Action metadata
ActionType type;
int params[4];
@@ -87,7 +87,7 @@ struct WMPathSegment {
short direction;
bool useLastDir;
bool alwaysSameDir;
-
+
// Optional Action that's triggered when the player touches this segment
WMPathAction *action;
};
@@ -100,7 +100,7 @@ struct WMPathDef {
// Path metadata
WMPathPoint *startPoint;
WMPathPoint *endPoint;
-
+
int segCount;
WMPathSegment *segments[1]; // variable-length array
};
@@ -108,15 +108,15 @@ struct WMPathDef {
-struct WMDataHeader {
+struct WMPathHeader {
u32 magic;
-
+
WMPathDef **pathList;
int pathCount;
-
+
WMPathPoint **pointList;
int pointCount;
-
+
WMPathSegment **segmentList;
int segmentCount;
@@ -126,24 +126,26 @@ struct WMDataHeader {
};
-class WorldMapData {
+class dWMPathData_c {
+private:
+ WMPathHeader *data;
+
public:
- WorldMapData();
- ~WorldMapData();
-
- bool load(const char *filename);
-
- FileHandle fh;
-
- int getPathCount() {
- return ((WMDataHeader*)fh.filePtr)->pathCount;
- }
-
- WMPathDef *getPath(int idx) {
- return ((WMDataHeader*)fh.filePtr)->pathList[idx];
- }
-
+ dWMPathData_c();
+ ~dWMPathData_c();
+
+ bool load(void *data);
+
+ int pathCount() { return data->pathCount; }
+ int pointCount() { return data->pointCount; }
+ int segmentCount() { return data->segmentCount; }
+
+ WMPathDef *getPath(int idx) { return data->pathList[idx]; }
+ WMPathPoint *getPoint(int idx) { return data->pointList[idx]; }
+ WMPathSegment *getSegment(int idx) { return data->segmentList[idx]; }
+
int getPointID(WMPathPoint *point);
};
#endif // __NEWER_WORLDMAPDATA_H
+