From 40e07bbd2ae9cf57a55bf75086b8b2d997ae4d33 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 2 Mar 2012 19:50:04 +0400 Subject: [PATCH 1/7] Feature #161 (In Progress) Load REC_PGRD records Struct sizes seems correct, but floats is broken --- CMakeLists.txt | 7 ++++++ components/esm/loadpgrd.cpp | 45 ++++++++++++++++++++++++++++++++-- components/esm/loadpgrd.hpp | 23 ++++++++++++++++- components/esm_store/store.hpp | 4 +-- 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fb0ee34c..3e116d875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,13 @@ if (APPLE) "${APP_BUNDLE_DIR}/Contents/Resources/OpenMW.icns" COPYONLY) # prepare plugins + if (${CMAKE_BUILD_TYPE} MATCHES "Release" OR + ${CMAKE_BUILD_TYPE} MATCHES "RelWithDebugInfo") + set(OGRE_PLUGIN_DIR ${OGRE_PLUGIN_DIR_REL}) + else() + set(OGRE_PLUGIN_DIR ${OGRE_PLUGIN_DIR_DBG}) + endif() + foreach(plugin ${USED_OGRE_PLUGINS}) configure_file("${OGRE_PLUGIN_DIR}/${plugin}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${plugin}.dylib" diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index b0727b0c0..2242599b3 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -3,10 +3,22 @@ namespace ESM { +PathGrid::~PathGrid() { + if (points != NULL) { + delete[] points; + points = NULL; + } + if (edges != NULL) { + delete[] edges; + edges = NULL; + } +} + void PathGrid::load(ESMReader &esm) { esm.getHNT(data, "DATA", 12); cell = esm.getHNString("NAME"); + std::cout << "loading PGRD for " << cell << std::endl; // Remember this file position context = esm.getContext(); @@ -14,10 +26,26 @@ void PathGrid::load(ESMReader &esm) // Check that the sizes match up. Size = 16 * s2 (path points?) if (esm.isNextSub("PGRP")) { - esm.skipHSub(); + esm.getSubHeader(); int size = esm.getSubSize(); + std::cout << "PGRP size is " << size << std::endl; if (size != 16 * data.s2) esm.fail("Path grid table size mismatch"); + else + { + pointCount = data.s2; + std::cout << "Path grid points count for cell `" << data.x + << " " << data.y << "` is " << data.s2 << std::endl; + points = new Point[pointCount]; + esm.getExact(points, size); + for (int i = 0; i < pointCount; ++i) + { + std::cout << i << "'s point: " << points[i].x; + std::cout << " " << points[i].y; + std::cout << " " << points[i].z; + std::cout << std::endl; + } + } } // Size varies. Path grid chances? Connections? Multiples of 4 @@ -25,10 +53,23 @@ void PathGrid::load(ESMReader &esm) // it later. if (esm.isNextSub("PGRC")) { - esm.skipHSub(); + esm.getSubHeader(); int size = esm.getSubSize(); if (size % 4 != 0) esm.fail("PGRC size not a multiple of 4"); + else + { + edgeCount = size / sizeof(Edge); + std::cout << "Path grid edge count for cell " << data.x + << " " << data.y << " is " << size << std::endl; + edges = new Edge[edgeCount]; + esm.getExact(edges, size); + for (int i = 0; i < edgeCount; ++i) + { + std::cout << i << "'s edge: " << edges[i].v0 << " " + << edges[i].v1 << std::endl; + } + } } } diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 8c030d314..b8f97c661 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -19,12 +19,33 @@ struct PathGrid short s2; // Number of path points? Size of PGRP block is always 16 * s2; }; // 12 bytes +#pragma pack(push, 1) + struct Point // path grid point + { + float x, y, z; // Location of point + int unknown; // Possibly flag for coloring/user-placed vs auto-generated + }; // 16 bytes + + struct Edge // path grid edge + { + int v0, v1; // index of points connected with this edge + }; // 8 bytes +#pragma pack(pop) + std::string cell; // Cell name DATAstruct data; + + Point *points; + int pointCount; + + Edge *edges; + int edgeCount; + ESM_Context context; // Context so we can return here later and // finish the job - void load(ESMReader &esm); + + ~PathGrid(); }; } #endif diff --git a/components/esm_store/store.hpp b/components/esm_store/store.hpp index e3bbf9e82..e5d173cb8 100644 --- a/components/esm_store/store.hpp +++ b/components/esm_store/store.hpp @@ -74,7 +74,7 @@ namespace ESMS ScriptListT