#include "koopatlas/mapdata.h" // HELPER FUNCTIONS dKPPath_s *dKPNode_s::getOppositeExitTo(dKPPath_s *path) { for (int i = 0; i < 4; i++) { dKPPath_s *check = exits[i]; if (check != 0 && check != path) return check; } return 0; } int dKPLayer_s::findNodeID(dKPNode_s *node) { for (int i = 0; i < nodeCount; i++) if (nodes[i] == node) return i; return -1; } dKPMapData_c::dKPMapData_c() { data = 0; fixedUp = false; tilesetLoaders = 0; tilesetsLoaded = false; } dKPMapData_c::~dKPMapData_c() { unloadTilesets(); m_fileLoader.unload(); } bool dKPMapData_c::load(const char *filename) { data = (dKPMapFile_s*)m_fileLoader.load(filename, 0, mHeap::archiveHeap); if (data == 0) return false; if (!fixedUp) fixup(); bool didLoadTilesets = loadTilesets(); bool didLoadBG = (bgLoader.load("/Maps/Water.brres") != 0); bool didLoadNode = nodeLoader.load("/Maps/visCobCourse.brres"); return didLoadTilesets && didLoadBG && didLoadNode; } bool dKPMapData_c::loadTilesets() { if (tilesetsLoaded) return true; 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); 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) { for (int i = 0; i < data->tilesetCount; i++) { tilesetLoaders[i].unload(); } delete[] tilesetLoaders; } bgLoader.unload(); nodeLoader.unload(); } void dKPMapData_c::fixup() { fixedUp = true; fixRef(data->layers); fixRef(data->tilesets); 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: pathLayer = layer; 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); // FORWARDS COMPATIBILITY: // else if (node->type == dKPNode_s::LEVEL) { // break; // node->allocator.link(-1, GameHeaps[0], 0, 0x20); // nw4r::g3d::ResFile rf(nodeLoader.buffer); // rf.CheckRevision(); // rf.Init(); // rf.Bind(rf); // nw4r::g3d::ResMdl mdl = rf.GetResMdl("cobCourse"); // nw4r::g3d::ResAnmVis anmRes = rf.GetResAnmVis("cobCourse"); // node->model.setup(mdl, &node->allocator, 0x224, 1, 0); // node->color.setup(mdl, anmRes, &node->allocator, 0); // node->color.bind(&node->model, anmRes, 0); // node->model.bindAnim(&node->color, 0.0f); // SetupTextures_MapObj(&node->model, 0); // } } break; } } } /****************************************************************************** * Generic Layer ******************************************************************************/ /****************************************************************************** * Tile Layer ******************************************************************************/ /****************************************************************************** * Doodad Layer ******************************************************************************/ /****************************************************************************** * Path Layer ******************************************************************************/