summaryrefslogtreecommitdiff
path: root/src/wm_map.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/wm_map.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/wm_map.cpp b/src/wm_map.cpp
new file mode 100644
index 0000000..83ed637
--- /dev/null
+++ b/src/wm_map.cpp
@@ -0,0 +1,103 @@
+#include "worldmap.h"
+
+dWMMap_c *dWMMap_c::instance = 0;
+
+dWMMap_c *dWMMap_c::build() {
+ OSReport("Creating WM_Map\n");
+
+ void *buffer = AllocFromGameHeap1(sizeof(dWMMap_c));
+ dWMMap_c *c = new(buffer) dWMMap_c;
+
+ OSReport("Created WM_Map @ %p\n", c);
+
+ instance = c;
+ return c;
+}
+
+
+
+
+int dWMMap_c::onCreate() {
+ // Get the resource
+ void *scnRes = dScNewerWorldMap_c::instance->resMng['SCN0'];
+ if (scnRes == 0) {
+ OSReport("Oops, couldn't get SCN0, try again later\n");
+ return false;
+ }
+
+ data = (WMSceneDataHeader*)scnRes;
+
+ // load up all the nodes, and fix up all the name offsets while we're at it
+ nodes = new WMSceneNode[data->nodeCount];
+
+ // link the mHeapAllocator so it can be used for models
+ allocator.link(-1, GameHeaps[0], 0, 0x20);
+
+ for (int i = 0; i < data->nodeCount; i++) {
+ WMSceneNode *node = &nodes[i];
+ WMSceneDataNode *nodeData = &data->nodes[i];
+
+ nodeData->modelName = (const char*)((u32)data + (u32)nodeData->modelName);
+ node->loadFrom(nodeData, &allocator);
+ }
+
+ allocator.unlink();
+
+ return true;
+}
+
+
+int dWMMap_c::onDelete() {
+ delete[] nodes;
+
+ return true;
+}
+
+
+int dWMMap_c::onExecute() {
+ return true;
+}
+
+
+int dWMMap_c::onDraw() {
+ for (int i = 0; i < data->nodeCount; i++) {
+ nodes[i].draw();
+ }
+
+ return true;
+}
+
+
+
+/* SCENE NODES */
+
+void WMSceneNode::loadFrom(WMSceneDataNode *data, mHeapAllocator_c *allocator) {
+ MapReport("Loading node: %c%c%c%c [%c%c%c%c:%s]\n",
+ data->nodeKey>>24,data->nodeKey>>16,data->nodeKey>>8,data->nodeKey,
+ data->brresKey>>24,data->brresKey>>16,data->brresKey>>8,data->brresKey,
+ data->modelName);
+
+ baseData = data;
+
+ void *brres = dScNewerWorldMap_c::instance->resMng[data->brresKey];
+ nw4r::g3d::ResFile resfile(brres);
+
+ void *mdl = resfile.GetResMdl(data->modelName);
+ MapReport("Obtained ResMdl: %p\n", mdl);
+
+ MapReport(model.setup(&mdl, allocator, 0, 1, 0) ? "Success\n" : "Fail\n");
+
+ // todo: more types
+ if (data->lmType == 0)
+ SetupTextures_Map(&model, 1);
+ else if (data->lmType == 1)
+ SetupTextures_MapObj(&model, 1);
+
+ model.setDrawMatrix(data->matrix);
+}
+
+
+void WMSceneNode::draw() {
+ model.scheduleForDrawing();
+}
+