summaryrefslogtreecommitdiff
path: root/src/koopatlas/mapdata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/koopatlas/mapdata.cpp')
-rw-r--r--src/koopatlas/mapdata.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/koopatlas/mapdata.cpp b/src/koopatlas/mapdata.cpp
new file mode 100644
index 0000000..37565ea
--- /dev/null
+++ b/src/koopatlas/mapdata.cpp
@@ -0,0 +1,147 @@
+#include "koopatlas/mapdata.h"
+
+
+dKPMapData_c::dKPMapData_c() {
+ data = 0;
+ fixedUp = false;
+ tilesetLoaders = 0;
+ tilesetsLoaded = false;
+}
+
+dKPMapData_c::~dKPMapData_c() {
+ m_fileLoader.unload();
+
+ unloadTilesets();
+}
+
+bool dKPMapData_c::load(const char *filename) {
+ OSReport("Loading %s\n", filename);
+ data = (dKPMapFile_s*)m_fileLoader.load(filename);
+ OSReport("%p\n", data);
+
+ if (data == 0)
+ return false;
+
+ if (!fixedUp)
+ fixup();
+
+ return loadTilesets();
+}
+
+bool dKPMapData_c::loadTilesets() {
+ if (tilesetsLoaded)
+ return true;
+
+ OSReport("Loading tilesets: %d\n", data->tilesetCount);
+ if (tilesetLoaders == 0)
+ tilesetLoaders = new dDvdLoader_c[data->tilesetCount];
+
+ bool result = true;
+
+ for (int i = 0; i < data->tilesetCount; i++) {
+ char *filename = ((char*)data) + (data->tilesets[i].dummy[3] - 0x10000000);
+ OSReport("Loading tileset: %s\n", filename);
+ result &= (tilesetLoaders[i].load(filename) != 0);
+ }
+
+ if (result) {
+ tilesetsLoaded = true;
+
+ for (int i = 0; i < data->tilesetCount; i++) {
+ data->tilesets[i].dummy[3] = (((u32)tilesetLoaders[i].buffer & ~0xC0000000) >> 5);
+ }
+ }
+
+ return tilesetsLoaded;
+}
+
+void dKPMapData_c::unloadTilesets() {
+ if (tilesetLoaders != 0)
+ delete[] tilesetLoaders;
+}
+
+void dKPMapData_c::fixup() {
+ fixedUp = true;
+
+ fixRef(data->layers);
+
+ for (int iLayer = 0; iLayer < data->layerCount; iLayer++) {
+ dKPLayer_s *layer = fixRef(data->layers[iLayer]);
+
+ switch (layer->type) {
+ case dKPLayer_s::OBJECTS:
+ fixRef(layer->tileset);
+ break;
+
+ case dKPLayer_s::DOODADS:
+ for (int iDood = 0; iDood < layer->doodadCount; iDood++) {
+ dKPDoodad_s *doodad = fixRef(layer->doodads[iDood]);
+
+ fixRef(doodad->texObj);
+ fixTexObjSafe(doodad->texObj);
+ }
+ break;
+
+ case dKPLayer_s::PATHS:
+ fixRef(layer->paths);
+ fixRef(layer->nodes);
+
+ for (int iPath = 0; iPath < layer->pathCount; iPath++) {
+ dKPPath_s *path = fixRef(layer->paths[iPath]);
+
+ fixRef(path->start);
+ fixRef(path->end);
+
+ fixRef(path->tileLayer);
+ fixRef(path->doodadLayer);
+ }
+
+ for (int iNode = 0; iNode < layer->nodeCount; iNode++) {
+ dKPNode_s *node = fixRef(layer->nodes[iNode]);
+
+ for (int i = 0; i < 4; i++)
+ fixRef(node->exits[i]);
+
+ fixRef(node->tileLayer);
+ fixRef(node->doodadLayer);
+
+ if (node->type == dKPNode_s::CHANGE)
+ fixRef(node->destMap);
+ }
+ break;
+ }
+ }
+
+ fixRef(data->unlocks);
+
+ for (int iUnlock = 0; iUnlock < data->unlockCount; iUnlock++) {
+ dKPUnlock_s *unlock = &data->unlocks[iUnlock];
+
+ fixRef(unlock->targetPath);
+ }
+
+ fixRef(data->tilesets);
+}
+
+
+/******************************************************************************
+ * Generic Layer
+ ******************************************************************************/
+
+
+/******************************************************************************
+ * Tile Layer
+ ******************************************************************************/
+
+
+/******************************************************************************
+ * Doodad Layer
+ ******************************************************************************/
+
+
+/******************************************************************************
+ * Path Layer
+ ******************************************************************************/
+
+
+