diff --git a/src/game/vmap/BIH.cpp b/src/game/vmap/BIH.cpp index f642df394a3..a564e2d7026 100644 --- a/src/game/vmap/BIH.cpp +++ b/src/game/vmap/BIH.cpp @@ -18,7 +18,7 @@ #include "BIH.h" -void BIH::buildHierarchy(std::vector &tempTree, buildData &dat, BuildStats &stats) +void BIH::buildHierarchy(std::vector& tempTree, buildData& dat, BuildStats& stats) { // create space for the first node tempTree.push_back(3 << 30); // dummy leaf @@ -32,7 +32,7 @@ void BIH::buildHierarchy(std::vector &tempTree, buildData &dat, BuildSta subdivide(0, dat.numPrims - 1, tempTree, dat, gridBox, nodeBox, 0, 1, stats); } -void BIH::subdivide(int left, int right, std::vector &tempTree, buildData &dat, AABound &gridBox, AABound &nodeBox, int nodeIndex, int depth, BuildStats &stats) +void BIH::subdivide(int left, int right, std::vector& tempTree, buildData& dat, AABound& gridBox, AABound& nodeBox, int nodeIndex, int depth, BuildStats& stats) { if ((right - left + 1) <= dat.maxPrims || depth >= MAX_STACK_SIZE) { @@ -51,7 +51,7 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat prevAxis = axis; prevSplit = split; // perform quick consistency checks - Vector3 d( gridBox.hi - gridBox.lo ); + Vector3 d(gridBox.hi - gridBox.lo); if (d.x < 0 || d.y < 0 || d.z < 0) throw std::logic_error("negative node extents"); for (int i = 0; i < 3; i++) @@ -127,13 +127,15 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat if (right == rightOrig) { // all left - if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) { + if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) + { // we are stuck here - create a leaf stats.updateLeaf(depth, right - left + 1); createNode(tempTree, nodeIndex, left, right); return; } - if (clipL <= split) { + if (clipL <= split) + { // keep looping on left half gridBox.hi[axis] = split; prevClip = clipL; @@ -146,14 +148,16 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat else if (left > right) { // all right - if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) { + if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) + { // we are stuck here - create a leaf stats.updateLeaf(depth, right - left + 1); createNode(tempTree, nodeIndex, left, right); return; } right = rightOrig; - if (clipR >= split) { + if (clipR >= split) + { // keep looping on right half gridBox.lo[axis] = split; prevClip = clipR; @@ -175,14 +179,17 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat tempTree.push_back(0); tempTree.push_back(0); tempTree.push_back(0); - if (wasLeft) { + if (wasLeft) + { // create a node with a left child // write leaf node stats.updateInner(); tempTree[nodeIndex + 0] = (prevAxis << 30) | nextIndex; tempTree[nodeIndex + 1] = floatToRawIntBits(prevClip); tempTree[nodeIndex + 2] = floatToRawIntBits(G3D::inf()); - } else { + } + else + { // create a node with a right child // write leaf node stats.updateInner(); @@ -204,14 +211,17 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat // allocate left node int nl = right - left + 1; int nr = rightOrig - (right + 1) + 1; - if (nl > 0) { + if (nl > 0) + { tempTree.push_back(0); tempTree.push_back(0); tempTree.push_back(0); - } else + } + else nextIndex -= 3; // allocate right node - if (nr > 0) { + if (nr > 0) + { tempTree.push_back(0); tempTree.push_back(0); tempTree.push_back(0); @@ -238,7 +248,7 @@ void BIH::subdivide(int left, int right, std::vector &tempTree, buildDat stats.updateLeaf(depth + 1, 0); } -bool BIH::writeToFile(FILE *wf) const +bool BIH::writeToFile(FILE* wf) const { uint32 treeSize = tree.size(); uint32 check=0, count=0; @@ -252,7 +262,7 @@ bool BIH::writeToFile(FILE *wf) const return check == (3 + 3 + 2 + treeSize + count); } -bool BIH::readFromFile(FILE *rf) +bool BIH::readFromFile(FILE* rf) { uint32 treeSize; Vector3 lo, hi; diff --git a/src/game/vmap/BIH.h b/src/game/vmap/BIH.h index c263ddf0962..3c65283ba67 100644 --- a/src/game/vmap/BIH.h +++ b/src/game/vmap/BIH.h @@ -34,9 +34,9 @@ #define MAX_STACK_SIZE 64 #ifdef _MSC_VER - #define isnan(x) _isnan(x) +#define isnan(x) _isnan(x) #else - #define isnan(x) std::isnan(x) +#define isnan(x) std::isnan(x) #endif using G3D::Vector3; @@ -82,9 +82,9 @@ class BIH public: BIH() {}; template< class T, class BoundsFunc > - void build(const std::vector &primitives, BoundsFunc &getBounds, uint32 leafSize = 3, bool printStats=false) + void build(const std::vector& primitives, BoundsFunc& getBounds, uint32 leafSize = 3, bool printStats=false) { - if(primitives.size() == 0) + if (primitives.size() == 0) return; buildData dat; dat.maxPrims = leafSize; @@ -116,7 +116,7 @@ class BIH uint32 primCount() { return objects.size(); } template - void intersectRay(const Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst=false) const + void intersectRay(const Ray& r, RayCallback& intersectCallback, float& maxDist, bool stopAtFirst=false) const { float intervalMin = -1.f; float intervalMax = -1.f; @@ -154,7 +154,7 @@ class BIH uint32 offsetBack3[3]; // compute custom offsets from direction sign bit - for(int i=0; i<3; ++i) + for (int i=0; i<3; ++i) { offsetFront[i] = floatToRawIntBits(dir[i]) >> 31; offsetBack[i] = offsetFront[i] ^ 1; @@ -170,7 +170,8 @@ class BIH int stackPos = 0; int node = 0; - while (true) { + while (true) + { while (true) { uint32 tn = tree[node]; @@ -190,13 +191,15 @@ class BIH int back = offset + offsetBack3[axis]; node = back; // ray passes through far node only - if (tf < intervalMin) { + if (tf < intervalMin) + { intervalMin = (tb >= intervalMin) ? tb : intervalMin; continue; } node = offset + offsetFront3[axis]; // front // ray passes through near node only - if (tb > intervalMax) { + if (tb > intervalMax) + { intervalMax = (tf <= intervalMax) ? tf : intervalMax; continue; } @@ -214,9 +217,10 @@ class BIH { // leaf - test some objects int n = tree[node + 1]; - while (n > 0) { + while (n > 0) + { bool hit = intersectCallback(r, objects[offset], maxDist, stopAtFirst); - if(stopAtFirst && hit) return; + if (stopAtFirst && hit) return; --n; ++offset; } @@ -250,12 +254,13 @@ class BIH node = stack[stackPos].node; intervalMax = stack[stackPos].tfar; break; - } while (true); + } + while (true); } } template - void intersectPoint(const Vector3 &p, IsectCallback& intersectCallback) const + void intersectPoint(const Vector3& p, IsectCallback& intersectCallback) const { if (!bounds.contains(p)) return; @@ -264,7 +269,8 @@ class BIH int stackPos = 0; int node = 0; - while (true) { + while (true) + { while (true) { uint32 tn = tree[node]; @@ -284,12 +290,14 @@ class BIH int right = offset + 3; node = right; // point is in right node only - if (tl < p[axis]) { + if (tl < p[axis]) + { continue; } node = offset; // left // point is in left node only - if (tr > p[axis]) { + if (tr > p[axis]) + { continue; } // point is in both nodes @@ -302,7 +310,8 @@ class BIH { // leaf - test some objects int n = tree[node + 1]; - while (n > 0) { + while (n > 0) + { intersectCallback(p, objects[offset]); // !!! --n; ++offset; @@ -332,8 +341,8 @@ class BIH } } - bool writeToFile(FILE *wf) const; - bool readFromFile(FILE *rf); + bool writeToFile(FILE* wf) const; + bool readFromFile(FILE* rf); protected: std::vector tree; @@ -342,8 +351,8 @@ class BIH struct buildData { - uint32 *indices; - AABox *primBound; + uint32* indices; + AABox* primBound; uint32 numPrims; int maxPrims; }; @@ -369,29 +378,30 @@ class BIH int numBVH2; public: - BuildStats(): - numNodes(0), numLeaves(0), sumObjects(0), minObjects(0x0FFFFFFF), - maxObjects(0xFFFFFFFF), sumDepth(0), minDepth(0x0FFFFFFF), - maxDepth(0xFFFFFFFF), numBVH2(0) - { - for(int i=0; i<6; ++i) numLeavesN[i] = 0; - } + BuildStats(): + numNodes(0), numLeaves(0), sumObjects(0), minObjects(0x0FFFFFFF), + maxObjects(0xFFFFFFFF), sumDepth(0), minDepth(0x0FFFFFFF), + maxDepth(0xFFFFFFFF), numBVH2(0) + { + for (int i=0; i<6; ++i) numLeavesN[i] = 0; + } - void updateInner() { numNodes++; } - void updateBVH2() { numBVH2++; } - void updateLeaf(int depth, int n); - void printStats(); + void updateInner() { numNodes++; } + void updateBVH2() { numBVH2++; } + void updateLeaf(int depth, int n); + void printStats(); }; - void buildHierarchy(std::vector &tempTree, buildData &dat, BuildStats &stats); + void buildHierarchy(std::vector& tempTree, buildData& dat, BuildStats& stats); - void createNode(std::vector &tempTree, int nodeIndex, uint32 left, uint32 right) { + void createNode(std::vector& tempTree, int nodeIndex, uint32 left, uint32 right) + { // write leaf node tempTree[nodeIndex + 0] = (3 << 30) | left; tempTree[nodeIndex + 1] = right - left + 1; } - void subdivide(int left, int right, std::vector &tempTree, buildData &dat, AABound &gridBox, AABound &nodeBox, int nodeIndex, int depth, BuildStats &stats); + void subdivide(int left, int right, std::vector& tempTree, buildData& dat, AABound& gridBox, AABound& nodeBox, int nodeIndex, int depth, BuildStats& stats); }; #endif // _BIH_H diff --git a/src/game/vmap/IVMapManager.h b/src/game/vmap/IVMapManager.h index 793f010fd89..deed23a57e3 100644 --- a/src/game/vmap/IVMapManager.h +++ b/src/game/vmap/IVMapManager.h @@ -38,8 +38,8 @@ namespace VMAP VMAP_LOAD_RESULT_IGNORED, }; - #define VMAP_INVALID_HEIGHT -100000.0f // for check - #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case +#define VMAP_INVALID_HEIGHT -100000.0f // for check +#define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case //=========================================================== class IVMapManager @@ -66,11 +66,11 @@ namespace VMAP test if we hit an object. return true if we hit one. rx,ry,rz will hold the hit position or the dest position, if no intersection was found return a position, that is pReduceDist closer to the origin */ - virtual bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist) = 0; + virtual bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float pModifyDist) = 0; /** send debug commands */ - virtual bool processCommand(char *pCommand)= 0; + virtual bool processCommand(char* pCommand)= 0; /** Enable/disable LOS calculation @@ -85,15 +85,15 @@ namespace VMAP bool isLineOfSightCalcEnabled() const { return(iEnableLineOfSightCalc); } bool isHeightCalcEnabled() const { return(iEnableHeightCalc); } - bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc ); } + bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc); } virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const =0; /** Query world model area info. \param z gets adjusted to the ground height for which this are info is valid */ - virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0; - virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0; + virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const=0; + virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type) const=0; }; } diff --git a/src/game/vmap/MapTree.cpp b/src/game/vmap/MapTree.cpp index a88d2fb62a5..92312c9fe6f 100644 --- a/src/game/vmap/MapTree.cpp +++ b/src/game/vmap/MapTree.cpp @@ -34,7 +34,7 @@ namespace VMAP class MapRayCallback { public: - MapRayCallback(ModelInstance *val): prims(val), hit(false) {} + MapRayCallback(ModelInstance* val): prims(val), hit(false) {} bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit=true) { bool result = prims[entry].intersectRay(ray, distance, pStopAtFirstHit); @@ -42,16 +42,16 @@ namespace VMAP hit = true; return result; } - bool didHit(){ return hit; } + bool didHit() { return hit; } protected: - ModelInstance *prims; + ModelInstance* prims; bool hit; }; class AreaInfoCallback { public: - AreaInfoCallback(ModelInstance *val): prims(val) {} + AreaInfoCallback(ModelInstance* val): prims(val) {} void operator()(const Vector3& point, uint32 entry) { #ifdef VMAP_DEBUG @@ -60,14 +60,14 @@ namespace VMAP prims[entry].intersectPoint(point, aInfo); } - ModelInstance *prims; + ModelInstance* prims; AreaInfo aInfo; }; class LocationInfoCallback { public: - LocationInfoCallback(ModelInstance *val, LocationInfo &info): prims(val), locInfo(info), result(false) {} + LocationInfoCallback(ModelInstance* val, LocationInfo& info): prims(val), locInfo(info), result(false) {} void operator()(const Vector3& point, uint32 entry) { #ifdef VMAP_DEBUG @@ -77,8 +77,8 @@ namespace VMAP result = true; } - ModelInstance *prims; - LocationInfo &locInfo; + ModelInstance* prims; + LocationInfo& locInfo; bool result; }; @@ -95,7 +95,7 @@ namespace VMAP return tilefilename.str(); } - bool StaticMapTree::getAreaInfo(Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const + bool StaticMapTree::getAreaInfo(Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const { AreaInfoCallback intersectionCallBack(iTreeValues); iTree.intersectPoint(pos, intersectionCallBack); @@ -111,14 +111,14 @@ namespace VMAP return false; } - bool StaticMapTree::GetLocationInfo(const Vector3 &pos, LocationInfo &info) const + bool StaticMapTree::GetLocationInfo(const Vector3& pos, LocationInfo& info) const { LocationInfoCallback intersectionCallBack(iTreeValues, info); iTree.intersectPoint(pos, intersectionCallBack); return intersectionCallBack.result; } - StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath): + StaticMapTree::StaticMapTree(uint32 mapID, const std::string& basePath): iMapID(mapID), iTreeValues(0), iBasePath(basePath) { if (iBasePath.length() > 0 && (iBasePath[iBasePath.length()-1] != '/' && iBasePath[iBasePath.length()-1] != '\\')) @@ -138,7 +138,7 @@ namespace VMAP Else, pMaxDist is not modified and returns false; */ - bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit) const + bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit) const { float distance = pMaxDist; MapRayCallback intersectionCallBack(iTreeValues); @@ -230,14 +230,14 @@ namespace VMAP //========================================================= - bool StaticMapTree::CanLoadMap(const std::string &vmapPath, uint32 mapID, uint32 tileX, uint32 tileY) + bool StaticMapTree::CanLoadMap(const std::string& vmapPath, uint32 mapID, uint32 tileX, uint32 tileY) { std::string basePath = vmapPath; if (basePath.length() > 0 && (basePath[basePath.length()-1] != '/' && basePath[basePath.length()-1] != '\\')) basePath.append("/"); std::string fullname = basePath + VMapManager2::getMapFileName(mapID); bool success = true; - FILE *rf = fopen(fullname.c_str(), "rb"); + FILE* rf = fopen(fullname.c_str(), "rb"); if (!rf) return false; // TODO: check magic number when implemented... @@ -267,12 +267,12 @@ namespace VMAP //========================================================= - bool StaticMapTree::InitMap(const std::string &fname, VMapManager2 *vm) + bool StaticMapTree::InitMap(const std::string& fname, VMapManager2* vm) { DEBUG_LOG("Initializing StaticMapTree '%s'", fname.c_str()); bool success = true; std::string fullname = iBasePath + fname; - FILE *rf = fopen(fullname.c_str(), "rb"); + FILE* rf = fopen(fullname.c_str(), "rb"); if (!rf) return false; else @@ -301,7 +301,7 @@ namespace VMAP #endif if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn)) { - WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name); + WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name); DEBUG_LOG("StaticMapTree::InitMap(): loading %s", spawn.name.c_str()); if (model) { @@ -323,7 +323,7 @@ namespace VMAP //========================================================= - void StaticMapTree::UnloadMap(VMapManager2 *vm) + void StaticMapTree::UnloadMap(VMapManager2* vm) { for (loadedSpawnMap::iterator i = iLoadedSpawns.begin(); i != iLoadedSpawns.end(); ++i) { @@ -337,7 +337,7 @@ namespace VMAP //========================================================= - bool StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm) + bool StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm) { if (!iIsTiled) { @@ -371,7 +371,7 @@ namespace VMAP if (result) { // acquire model instance - WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name); + WorldModel* model = vm->acquireModelInstance(iBasePath, spawn.name); if (!model) ERROR_LOG("StaticMapTree::LoadMapTile() could not acquire WorldModel pointer for '%s'!", spawn.name.c_str()); @@ -413,7 +413,7 @@ namespace VMAP //========================================================= - void StaticMapTree::UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm) + void StaticMapTree::UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm) { uint32 tileID = packTileID(tileX, tileY); loadedTileMap::iterator tile = iLoadedTiles.find(tileID); diff --git a/src/game/vmap/MapTree.h b/src/game/vmap/MapTree.h index 661504d0b74..2bff44f190b 100644 --- a/src/game/vmap/MapTree.h +++ b/src/game/vmap/MapTree.h @@ -32,20 +32,20 @@ namespace VMAP struct LocationInfo { LocationInfo(): hitInstance(0), hitModel(0), ground_Z(-G3D::inf()) {}; - const ModelInstance *hitInstance; - const GroupModel *hitModel; + const ModelInstance* hitInstance; + const GroupModel* hitModel; float ground_Z; }; class StaticMapTree { - typedef UNORDERED_MAP loadedTileMap; - typedef UNORDERED_MAP loadedSpawnMap; + typedef UNORDERED_MAP loadedTileMap; + typedef UNORDERED_MAP loadedSpawnMap; private: uint32 iMapID; bool iIsTiled; BIH iTree; - ModelInstance *iTreeValues; // the tree entries + ModelInstance* iTreeValues; // the tree entries uint32 iNTreeValues; // Store all the map tile idents that are loaded for that map @@ -57,33 +57,33 @@ namespace VMAP std::string iBasePath; private: - bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit) const; + bool getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit) const; //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); } public: static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY); static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; } - static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID>>16; tileY = ID&0xFF; } - static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY); + static void unpackTileID(uint32 ID, uint32& tileX, uint32& tileY) { tileX = ID>>16; tileY = ID&0xFF; } + static bool CanLoadMap(const std::string& basePath, uint32 mapID, uint32 tileX, uint32 tileY); - StaticMapTree(uint32 mapID, const std::string &basePath); + StaticMapTree(uint32 mapID, const std::string& basePath); ~StaticMapTree(); bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2) const; bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const; float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const; - bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const; - bool GetLocationInfo(const Vector3 &pos, LocationInfo &info) const; + bool getAreaInfo(G3D::Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const; + bool GetLocationInfo(const Vector3& pos, LocationInfo& info) const; - bool InitMap(const std::string &fname, VMapManager2 *vm); - void UnloadMap(VMapManager2 *vm); - bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm); - void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm); + bool InitMap(const std::string& fname, VMapManager2* vm); + void UnloadMap(VMapManager2* vm); + bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm); + void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm); bool isTiled() const { return iIsTiled; } uint32 numLoadedTiles() const { return iLoadedTiles.size(); } #ifdef MMAP_GENERATOR public: - void getModelInstances(ModelInstance* &models, uint32 &count); + void getModelInstances(ModelInstance*& models, uint32& count); #endif }; diff --git a/src/game/vmap/ModelInstance.cpp b/src/game/vmap/ModelInstance.cpp index 33889c06900..0086c818db3 100644 --- a/src/game/vmap/ModelInstance.cpp +++ b/src/game/vmap/ModelInstance.cpp @@ -26,7 +26,7 @@ using G3D::Ray; namespace VMAP { - ModelInstance::ModelInstance(const ModelSpawn &spawn, WorldModel *model): ModelSpawn(spawn), iModel(model) + ModelInstance::ModelInstance(const ModelSpawn& spawn, WorldModel* model): ModelSpawn(spawn), iModel(model) { iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pi()*iRot.y/180.f, G3D::pi()*iRot.x/180.f, G3D::pi()*iRot.z/180.f).inverse(); iInvScale = 1.f/iScale; @@ -54,7 +54,7 @@ namespace VMAP Ray modRay(p, iInvRot * pRay.direction()); float distance = pMaxDist * iInvScale; bool hit = iModel->IntersectRay(modRay, distance, pStopAtFirstHit); - if(hit) + if (hit) { distance *= iScale; pMaxDist = distance; @@ -62,7 +62,7 @@ namespace VMAP return hit; } - void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo &info) const + void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo& info) const { if (!iModel) { @@ -96,7 +96,7 @@ namespace VMAP } } - bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo &info) const + bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const { if (!iModel) { @@ -132,7 +132,7 @@ namespace VMAP return false; } - bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo &info, float &liqHeight) const + bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const { // child bounds are defined in object space: Vector3 pModel = iInvRot * (p - iPos) * iInvScale; @@ -150,7 +150,7 @@ namespace VMAP return false; } - bool ModelSpawn::readFromFile(FILE *rf, ModelSpawn &spawn) + bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn& spawn) { uint32 check=0, nameLen; check += fread(&spawn.flags, sizeof(uint32), 1, rf); @@ -175,7 +175,7 @@ namespace VMAP spawn.iBound = G3D::AABox(bLow, bHigh); } check += fread(&nameLen, sizeof(uint32), 1, rf); - if(check != (has_bound ? 17 : 11)) + if (check != (has_bound ? 17 : 11)) { ERROR_LOG("Error reading ModelSpawn!"); return false; @@ -196,7 +196,7 @@ namespace VMAP return true; } - bool ModelSpawn::writeToFile(FILE *wf, const ModelSpawn &spawn) + bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn& spawn) { uint32 check=0; check += fwrite(&spawn.flags, sizeof(uint32), 1, wf); @@ -206,16 +206,16 @@ namespace VMAP check += fwrite(&spawn.iRot, sizeof(float), 3, wf); check += fwrite(&spawn.iScale, sizeof(float), 1, wf); bool has_bound = (spawn.flags & MOD_HAS_BOUND); - if(has_bound) // only WMOs have bound in MPQ, only available after computation + if (has_bound) // only WMOs have bound in MPQ, only available after computation { check += fwrite(&spawn.iBound.low(), sizeof(float), 3, wf); check += fwrite(&spawn.iBound.high(), sizeof(float), 3, wf); } uint32 nameLen = spawn.name.length(); check += fwrite(&nameLen, sizeof(uint32), 1, wf); - if(check != (has_bound ? 17 : 11)) return false; + if (check != (has_bound ? 17 : 11)) return false; check = fwrite(spawn.name.c_str(), sizeof(char), nameLen, wf); - if(check != nameLen) return false; + if (check != nameLen) return false; return true; } diff --git a/src/game/vmap/ModelInstance.h b/src/game/vmap/ModelInstance.h index 6c9ea6fc105..59334a5064b 100644 --- a/src/game/vmap/ModelInstance.h +++ b/src/game/vmap/ModelInstance.h @@ -51,30 +51,30 @@ namespace VMAP float iScale; G3D::AABox iBound; std::string name; - bool operator==(const ModelSpawn &other) const { return ID == other.ID; } + bool operator==(const ModelSpawn& other) const { return ID == other.ID; } //uint32 hashCode() const { return ID; } // temp? const G3D::AABox& getBounds() const { return iBound; } - static bool readFromFile(FILE *rf, ModelSpawn &spawn); - static bool writeToFile(FILE *rw, const ModelSpawn &spawn); + static bool readFromFile(FILE* rf, ModelSpawn& spawn); + static bool writeToFile(FILE* rw, const ModelSpawn& spawn); }; class ModelInstance: public ModelSpawn { public: ModelInstance(): iModel(0) {} - ModelInstance(const ModelSpawn &spawn, WorldModel *model); + ModelInstance(const ModelSpawn& spawn, WorldModel* model); void setUnloaded() { iModel = 0; } bool intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit) const; - void intersectPoint(const G3D::Vector3& p, AreaInfo &info) const; - bool GetLocationInfo(const G3D::Vector3& p, LocationInfo &info) const; - bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo &info, float &liqHeight) const; + void intersectPoint(const G3D::Vector3& p, AreaInfo& info) const; + bool GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const; + bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const; protected: G3D::Matrix3 iInvRot; float iInvScale; - WorldModel *iModel; + WorldModel* iModel; #ifdef MMAP_GENERATOR public: diff --git a/src/game/vmap/TileAssembler.cpp b/src/game/vmap/TileAssembler.cpp index 8acf0d25fa9..43a3102c580 100644 --- a/src/game/vmap/TileAssembler.cpp +++ b/src/game/vmap/TileAssembler.cpp @@ -34,12 +34,12 @@ using std::pair; template<> struct BoundsTrait { - static void getBounds(const VMAP::ModelSpawn* const &obj, G3D::AABox& out) { out = obj->getBounds(); } + static void getBounds(const VMAP::ModelSpawn* const& obj, G3D::AABox& out) { out = obj->getBounds(); } }; namespace VMAP { - bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len) + bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len) { if (fread(dest, sizeof(char), len, rf) != len) return false; return memcmp(dest, compare, len) == 0; @@ -113,7 +113,7 @@ namespace VMAP // write map tree file std::stringstream mapfilename; mapfilename << iDestDir << "/" << std::setfill('0') << std::setw(3) << map_iter->first << ".vmtree"; - FILE *mapfile = fopen(mapfilename.str().c_str(), "wb"); + FILE* mapfile = fopen(mapfilename.str().c_str(), "wb"); if (!mapfile) { success = false; @@ -143,11 +143,11 @@ namespace VMAP // <==== // write map tile files, similar to ADT files, only with extra BSP tree node info - TileMap &tileEntries = map_iter->second->TileEntries; + TileMap& tileEntries = map_iter->second->TileEntries; TileMap::iterator tile; for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile) { - const ModelSpawn &spawn = map_iter->second->UniqueEntries[tile->second]; + const ModelSpawn& spawn = map_iter->second->UniqueEntries[tile->second]; if (spawn.flags & MOD_WORLDSPAWN) // WDT spawn, saved as tile 65/65 currently... continue; uint32 nSpawns = tileEntries.count(tile->first); @@ -157,7 +157,7 @@ namespace VMAP uint32 x, y; StaticMapTree::unpackTileID(tile->first, x, y); tilefilename << std::setw(2) << x << "_" << std::setw(2) << y << ".vmtile"; - FILE *tilefile = fopen(tilefilename.str().c_str(), "wb"); + FILE* tilefile = fopen(tilefilename.str().c_str(), "wb"); // file header if (success && fwrite(VMAP_MAGIC, 1, 8, tilefile) != 8) success = false; // write number of tile spawns @@ -167,7 +167,7 @@ namespace VMAP { if (s) ++tile; - const ModelSpawn &spawn2 = map_iter->second->UniqueEntries[tile->second]; + const ModelSpawn& spawn2 = map_iter->second->UniqueEntries[tile->second]; success = success && ModelSpawn::writeToFile(tilefile, spawn2); // MapTree nodes to update when loading tile: std::map::iterator nIdx = modelNodeIdx.find(spawn2.ID); @@ -202,7 +202,7 @@ namespace VMAP bool TileAssembler::readMapSpawns() { std::string fname = iSrcDir + "/dir_bin"; - FILE *dirf = fopen(fname.c_str(), "rb"); + FILE* dirf = fopen(fname.c_str(), "rb"); if (!dirf) { printf("Could not read dir_bin file!\n"); @@ -224,7 +224,7 @@ namespace VMAP if (!ModelSpawn::readFromFile(dirf, spawn)) break; - MapSpawns *current; + MapSpawns* current; MapData::iterator map_iter = mapData.find(mapID); if (map_iter == mapData.end()) { @@ -240,7 +240,7 @@ namespace VMAP return success; } - bool TileAssembler::calculateTransformedBound(ModelSpawn &spawn) + bool TileAssembler::calculateTransformedBound(ModelSpawn& spawn) { std::string modelFilename = iSrcDir + "/" + spawn.name; ModelPosition modelPosition; @@ -248,7 +248,7 @@ namespace VMAP modelPosition.iScale = spawn.iScale; modelPosition.init(); - FILE *rf = fopen(modelFilename.c_str(), "rb"); + FILE* rf = fopen(modelFilename.c_str(), "rb"); if (!rf) { printf("ERROR: Can't open model file: %s\n", modelFilename.c_str()); @@ -262,9 +262,9 @@ namespace VMAP int readOperation = 1; // temporary use defines to simplify read/check code (close file and return at fail) - #define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \ +#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \ fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); }readOperation++; - #define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \ +#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \ fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); } READ_OR_RETURN(&ident, 8); @@ -278,7 +278,7 @@ namespace VMAP char blockId[5]; blockId[4] = 0; int blocksize; - float *vectorarray = 0; + float* vectorarray = 0; READ_OR_RETURN(&groups, sizeof(uint32)); READ_OR_RETURN(&wmoRootId, sizeof(uint32)); @@ -329,8 +329,8 @@ namespace VMAP } delete[] vectorarray; // drop of temporary use defines - #undef READ_OR_RETURN - #undef CMP_OR_RETURN +#undef READ_OR_RETURN +#undef CMP_OR_RETURN } spawn.iBound = modelBound + spawn.iPos; spawn.flags |= MOD_HAS_BOUND; @@ -354,12 +354,12 @@ namespace VMAP if (filename.length() >0) filename.append("/"); filename.append(pModelFilename); - FILE *rf = fopen(filename.c_str(), "rb"); + FILE* rf = fopen(filename.c_str(), "rb"); if (!rf) { printf("ERROR: Can't open model file in form: %s",pModelFilename.c_str()); - printf("... or form: %s",filename.c_str() ); + printf("... or form: %s",filename.c_str()); return false; } @@ -368,9 +368,9 @@ namespace VMAP int readOperation = 1; // temporary use defines to simplify read/check code (close file and return at fail) - #define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \ +#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \ fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); }readOperation++; - #define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \ +#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \ fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); } READ_OR_RETURN(&ident, 8); @@ -428,7 +428,7 @@ namespace VMAP READ_OR_RETURN(&nindexes, sizeof(uint32)); if (nindexes >0) { - uint16 *indexarray = new uint16[nindexes]; + uint16* indexarray = new uint16[nindexes]; READ_OR_RETURN(indexarray, nindexes*sizeof(uint16)); for (uint32 i=0; i0) { - float *vectorarray = new float[nvectors*3]; + float* vectorarray = new float[nvectors*3]; READ_OR_RETURN(vectorarray, nvectors*sizeof(float)*3); for (uint32 i=0; i iUniqueNameIds; unsigned int iCurrentUniqueNameId; MapData mapData; @@ -77,10 +77,10 @@ namespace VMAP bool convertWorld2(); bool readMapSpawns(); - bool calculateTransformedBound(ModelSpawn &spawn); + bool calculateTransformedBound(ModelSpawn& spawn); bool convertRawFile(const std::string& pModelFilename); - void setModelNameFilterMethod(bool (*pFilterMethod)(char *pName)) { iFilterMethod = pFilterMethod; } + void setModelNameFilterMethod(bool (*pFilterMethod)(char* pName)) { iFilterMethod = pFilterMethod; } std::string getDirEntryNameFromModName(unsigned int pMapId, const std::string& pModPosName); unsigned int getUniqueNameId(const std::string pName); }; diff --git a/src/game/vmap/VMapDefinitions.h b/src/game/vmap/VMapDefinitions.h index 05f33e56218..ae425d147e0 100644 --- a/src/game/vmap/VMapDefinitions.h +++ b/src/game/vmap/VMapDefinitions.h @@ -28,25 +28,25 @@ namespace VMAP const char RAW_VMAP_MAGIC[] = "VMAP003"; // used in extracted vmap files with raw data // defined in TileAssembler.cpp currently... - bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len); + bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len); } #ifndef NO_CORE_FUNCS - #include "Errors.h" - #include "Log.h" - #define ERROR_LOG(...) sLog.outError(__VA_ARGS__); +#include "Errors.h" +#include "Log.h" +#define ERROR_LOG(...) sLog.outError(__VA_ARGS__); #elif defined MMAP_GENERATOR - #include - #define MANGOS_ASSERT(x) assert(x) - #define DEBUG_LOG(...) 0 - #define DETAIL_LOG(...) 0 - #define ERROR_LOG(...) do{ printf("ERROR:"); printf(__VA_ARGS__); printf("\n"); } while(0) +#include +#define MANGOS_ASSERT(x) assert(x) +#define DEBUG_LOG(...) 0 +#define DETAIL_LOG(...) 0 +#define ERROR_LOG(...) do{ printf("ERROR:"); printf(__VA_ARGS__); printf("\n"); } while(0) #else - #include - #define MANGOS_ASSERT(x) assert(x) - #define DEBUG_LOG(...) do{ printf(__VA_ARGS__); printf("\n"); } while(0) - #define DETAIL_LOG(...) do{ printf(__VA_ARGS__); printf("\n"); } while(0) - #define ERROR_LOG(...) do{ printf("ERROR:"); printf(__VA_ARGS__); printf("\n"); } while(0) +#include +#define MANGOS_ASSERT(x) assert(x) +#define DEBUG_LOG(...) do{ printf(__VA_ARGS__); printf("\n"); } while(0) +#define DETAIL_LOG(...) do{ printf(__VA_ARGS__); printf("\n"); } while(0) +#define ERROR_LOG(...) do{ printf("ERROR:"); printf(__VA_ARGS__); printf("\n"); } while(0) #endif #endif // _VMAPDEFINITIONS_H diff --git a/src/game/vmap/VMapFactory.cpp b/src/game/vmap/VMapFactory.cpp index dee1386aa6f..257f13fa47b 100644 --- a/src/game/vmap/VMapFactory.cpp +++ b/src/game/vmap/VMapFactory.cpp @@ -26,10 +26,10 @@ namespace VMAP { void chompAndTrim(std::string& str) { - while(str.length() >0) + while (str.length() >0) { char lc = str[str.length()-1]; - if(lc == '\r' || lc == '\n' || lc == ' ' || lc == '"' || lc == '\'') + if (lc == '\r' || lc == '\n' || lc == ' ' || lc == '"' || lc == '\'') { str = str.substr(0,str.length()-1); } @@ -38,10 +38,10 @@ namespace VMAP break; } } - while(str.length() >0) + while (str.length() >0) { char lc = str[0]; - if(lc == ' ' || lc == '"' || lc == '\'') + if (lc == ' ' || lc == '"' || lc == '\'') { str = str.substr(1,str.length()-1); } @@ -52,7 +52,7 @@ namespace VMAP } } - IVMapManager *gVMapManager = 0; + IVMapManager* gVMapManager = 0; Table* iIgnoreSpellIds=0; //=============================================== @@ -62,14 +62,14 @@ namespace VMAP { bool result = false; unsigned int i; - for(i=pStartPos;ipStartPos) + if (i>pStartPos) { std::string idString = pString.substr(pStartPos, i-pStartPos); pStartPos = i+1; @@ -87,15 +87,15 @@ namespace VMAP void VMapFactory::preventSpellsFromBeingTestedForLoS(const char* pSpellIdString) { - if(!iIgnoreSpellIds) + if (!iIgnoreSpellIds) iIgnoreSpellIds = new Table(); - if(pSpellIdString != NULL) + if (pSpellIdString != NULL) { unsigned int pos =0; unsigned int id; std::string confString(pSpellIdString); chompAndTrim(confString); - while(getNextId(confString, pos, id)) + while (getNextId(confString, pos, id)) { iIgnoreSpellIds->set(id, true); } @@ -113,7 +113,7 @@ namespace VMAP // just return the instance IVMapManager* VMapFactory::createOrGetVMapManager() { - if(gVMapManager == 0) + if (gVMapManager == 0) gVMapManager= new VMapManager2(); // should be taken from config ... Please change if you like :-) return gVMapManager; } @@ -122,12 +122,12 @@ namespace VMAP // delete all internal data structures void VMapFactory::clear() { - if(iIgnoreSpellIds) + if (iIgnoreSpellIds) { delete iIgnoreSpellIds; iIgnoreSpellIds = NULL; } - if(gVMapManager) + if (gVMapManager) { delete gVMapManager; gVMapManager = NULL; diff --git a/src/game/vmap/VMapManager2.cpp b/src/game/vmap/VMapManager2.cpp index a8da984a51c..02cb040b3b8 100644 --- a/src/game/vmap/VMapManager2.cpp +++ b/src/game/vmap/VMapManager2.cpp @@ -105,13 +105,13 @@ namespace VMAP //========================================================= // load one tile (internal use only) - bool VMapManager2::_loadMap(unsigned int pMapId, const std::string &basePath, uint32 tileX, uint32 tileY) + bool VMapManager2::_loadMap(unsigned int pMapId, const std::string& basePath, uint32 tileX, uint32 tileY) { InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(pMapId); if (instanceTree == iInstanceMapTrees.end()) { std::string mapFileName = getMapFileName(pMapId); - StaticMapTree *newTree = new StaticMapTree(pMapId, basePath); + StaticMapTree* newTree = new StaticMapTree(pMapId, basePath); if (!newTree->InitMap(mapFileName, this)) return false; instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(pMapId, newTree)).first; @@ -174,7 +174,7 @@ namespace VMAP get the hit position and return true if we hit something otherwise the result pos will be the dest pos */ - bool VMapManager2::getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist) + bool VMapManager2::getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float pModifyDist) { bool result = false; rx=x2; @@ -224,7 +224,7 @@ namespace VMAP //========================================================= - bool VMapManager2::getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const + bool VMapManager2::getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const { bool result=false; InstanceTreeMap::const_iterator instanceTree = iInstanceMapTrees.find(pMapId); @@ -238,7 +238,7 @@ namespace VMAP return(result); } - bool VMapManager2::GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const + bool VMapManager2::GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type) const { InstanceTreeMap::const_iterator instanceTree = iInstanceMapTrees.find(pMapId); if (instanceTree != iInstanceMapTrees.end()) @@ -260,12 +260,12 @@ namespace VMAP //========================================================= - WorldModel* VMapManager2::acquireModelInstance(const std::string &basepath, const std::string &filename) + WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename) { ModelFileMap::iterator model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) { - WorldModel *worldmodel = new WorldModel(); + WorldModel* worldmodel = new WorldModel(); if (!worldmodel->readFile(basepath + filename + ".vmo")) { ERROR_LOG("VMapManager2: could not load '%s%s.vmo'!", basepath.c_str(), filename.c_str()); @@ -280,7 +280,7 @@ namespace VMAP return model->second.getModel(); } - void VMapManager2::releaseModelInstance(const std::string &filename) + void VMapManager2::releaseModelInstance(const std::string& filename) { ModelFileMap::iterator model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) @@ -288,7 +288,7 @@ namespace VMAP ERROR_LOG("VMapManager2: trying to unload non-loaded file '%s'!", filename.c_str()); return; } - if( model->second.decRefCount() == 0) + if (model->second.decRefCount() == 0) { DEBUG_LOG("VMapManager2: unloading file '%s'", filename.c_str()); delete model->second.getModel(); diff --git a/src/game/vmap/VMapManager2.h b/src/game/vmap/VMapManager2.h index ee43bc83fff..8befb630c9b 100644 --- a/src/game/vmap/VMapManager2.h +++ b/src/game/vmap/VMapManager2.h @@ -49,16 +49,16 @@ namespace VMAP { public: ManagedModel(): iModel(0), iRefCount(0) {} - void setModel(WorldModel *model) { iModel = model; } - WorldModel *getModel() { return iModel; } + void setModel(WorldModel* model) { iModel = model; } + WorldModel* getModel() { return iModel; } void incRefCount() { ++iRefCount; } int decRefCount() { return --iRefCount; } protected: - WorldModel *iModel; + WorldModel* iModel; int iRefCount; }; - typedef UNORDERED_MAP InstanceTreeMap; + typedef UNORDERED_MAP InstanceTreeMap; typedef UNORDERED_MAP ModelFileMap; class VMapManager2 : public IVMapManager @@ -68,7 +68,7 @@ namespace VMAP ModelFileMap iLoadedModelFiles; InstanceTreeMap iInstanceMapTrees; - bool _loadMap(uint32 pMapId, const std::string &basePath, uint32 tileX, uint32 tileY); + bool _loadMap(uint32 pMapId, const std::string& basePath, uint32 tileX, uint32 tileY); /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */ public: @@ -89,16 +89,16 @@ namespace VMAP /** fill the hit pos and return true, if an object was hit */ - bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist); + bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float pModifyDist); float getHeight(unsigned int pMapId, float x, float y, float z, float maxSearchDist); - bool processCommand(char *pCommand) { return false; } // for debug and extensions + bool processCommand(char* pCommand) { return false; } // for debug and extensions - bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const; - bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const; + bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const; + bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type) const; - WorldModel* acquireModelInstance(const std::string &basepath, const std::string &filename); - void releaseModelInstance(const std::string &filename); + WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename); + void releaseModelInstance(const std::string& filename); // what's the use of this? o.O virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const @@ -109,7 +109,7 @@ namespace VMAP #ifdef MMAP_GENERATOR public: - void getInstanceMapTree(InstanceTreeMap &instanceMapTree); + void getInstanceMapTree(InstanceTreeMap& instanceMapTree); #endif }; } diff --git a/src/game/vmap/VMapTools.h b/src/game/vmap/VMapTools.h index 9fb1500ce88..40ce92e5192 100644 --- a/src/game/vmap/VMapTools.h +++ b/src/game/vmap/VMapTools.h @@ -33,15 +33,17 @@ The collision detection is modified to return true, if we are inside an object. namespace VMAP { template - class IntersectionCallBack { - public: - TValue* closestEntity; - G3D::Vector3 hitLocation; - G3D::Vector3 hitNormal; - - void operator()(const G3D::Ray& ray, const TValue* entity, bool pStopAtFirstHit, float& distance) { - entity->intersect(ray, distance, pStopAtFirstHit, hitLocation, hitNormal); - } + class IntersectionCallBack + { + public: + TValue* closestEntity; + G3D::Vector3 hitLocation; + G3D::Vector3 hitNormal; + + void operator()(const G3D::Ray& ray, const TValue* entity, bool pStopAtFirstHit, float& distance) + { + entity->intersect(ray, distance, pStopAtFirstHit, hitLocation, hitNormal); + } }; //============================================================== @@ -50,101 +52,101 @@ namespace VMAP class MyCollisionDetection { - private: - public: - - static bool collisionLocationForMovingPointFixedAABox( - const G3D::Vector3& origin, - const G3D::Vector3& dir, - const G3D::AABox& box, - G3D::Vector3& location, - bool& Inside) - { - - // Integer representation of a floating-point value. + private: + public: + + static bool collisionLocationForMovingPointFixedAABox( + const G3D::Vector3& origin, + const G3D::Vector3& dir, + const G3D::AABox& box, + G3D::Vector3& location, + bool& Inside) + { + + // Integer representation of a floating-point value. #define IR(x) (reinterpret_cast(x)) - Inside = true; - const G3D::Vector3& MinB = box.low(); - const G3D::Vector3& MaxB = box.high(); - G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f); + Inside = true; + const G3D::Vector3& MinB = box.low(); + const G3D::Vector3& MaxB = box.high(); + G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f); - // Find candidate planes. - for (int i = 0; i < 3; ++i) - { - if (origin[i] < MinB[i]) + // Find candidate planes. + for (int i = 0; i < 3; ++i) { - location[i] = MinB[i]; - Inside = false; - - // Calculate T distances to candidate planes - if (IR(dir[i])) + if (origin[i] < MinB[i]) { - MaxT[i] = (MinB[i] - origin[i]) / dir[i]; + location[i] = MinB[i]; + Inside = false; + + // Calculate T distances to candidate planes + if (IR(dir[i])) + { + MaxT[i] = (MinB[i] - origin[i]) / dir[i]; + } } - } - else if (origin[i] > MaxB[i]) - { - location[i] = MaxB[i]; - Inside = false; - - // Calculate T distances to candidate planes - if (IR(dir[i])) + else if (origin[i] > MaxB[i]) { - MaxT[i] = (MaxB[i] - origin[i]) / dir[i]; + location[i] = MaxB[i]; + Inside = false; + + // Calculate T distances to candidate planes + if (IR(dir[i])) + { + MaxT[i] = (MaxB[i] - origin[i]) / dir[i]; + } } } - } - if (Inside) - { - // definite hit - location = origin; - return true; - } + if (Inside) + { + // definite hit + location = origin; + return true; + } - // Get largest of the maxT's for final choice of intersection - int WhichPlane = 0; - if (MaxT[1] > MaxT[WhichPlane]) - { - WhichPlane = 1; - } + // Get largest of the maxT's for final choice of intersection + int WhichPlane = 0; + if (MaxT[1] > MaxT[WhichPlane]) + { + WhichPlane = 1; + } - if (MaxT[2] > MaxT[WhichPlane]) - { - WhichPlane = 2; - } + if (MaxT[2] > MaxT[WhichPlane]) + { + WhichPlane = 2; + } - // Check final candidate actually inside box - if (IR(MaxT[WhichPlane]) & 0x80000000) - { - // Miss the box - return false; - } + // Check final candidate actually inside box + if (IR(MaxT[WhichPlane]) & 0x80000000) + { + // Miss the box + return false; + } - for (int i = 0; i < 3; ++i) - { - if (i != WhichPlane) + for (int i = 0; i < 3; ++i) { - location[i] = origin[i] + MaxT[WhichPlane] * dir[i]; - if ((location[i] < MinB[i]) || - (location[i] > MaxB[i])) + if (i != WhichPlane) { - // On this plane we're outside the box extents, so - // we miss the box - return false; + location[i] = origin[i] + MaxT[WhichPlane] * dir[i]; + if ((location[i] < MinB[i]) || + (location[i] > MaxB[i])) + { + // On this plane we're outside the box extents, so + // we miss the box + return false; + } } } - } - /* - // Choose the normal to be the plane normal facing into the ray - normal = G3D::Vector3::zero(); - normal[WhichPlane] = (dir[WhichPlane] > 0) ? -1.0 : 1.0; - */ - return true; + /* + // Choose the normal to be the plane normal facing into the ray + normal = G3D::Vector3::zero(); + normal[WhichPlane] = (dir[WhichPlane] > 0) ? -1.0 : 1.0; + */ + return true; #undef IR - } + } }; } #endif diff --git a/src/game/vmap/WorldModel.cpp b/src/game/vmap/WorldModel.cpp index 51bd6a6bcb9..74c13b2f999 100644 --- a/src/game/vmap/WorldModel.cpp +++ b/src/game/vmap/WorldModel.cpp @@ -31,7 +31,7 @@ template<> struct BoundsTrait namespace VMAP { - bool IntersectTriangle(const MeshTriangle &tri, std::vector::const_iterator points, const G3D::Ray &ray, float &distance) + bool IntersectTriangle(const MeshTriangle& tri, std::vector::const_iterator points, const G3D::Ray& ray, float& distance) { static const float EPS = 1e-5f; @@ -42,7 +42,8 @@ namespace VMAP const Vector3 p(ray.direction().cross(e2)); const float a = e1.dot(p); - if (abs(a) < EPS) { + if (abs(a) < EPS) + { // Determinant is ill-conditioned; abort early return false; } @@ -51,7 +52,8 @@ namespace VMAP const Vector3 s(ray.origin() - points[tri.idx0]); const float u = f * s.dot(p); - if ((u < 0.0f) || (u > 1.0f)) { + if ((u < 0.0f) || (u > 1.0f)) + { // We hit the plane of the m_geometry, but outside the m_geometry return false; } @@ -59,7 +61,8 @@ namespace VMAP const Vector3 q(s.cross(e1)); const float v = f * ray.direction().dot(q); - if ((v < 0.0f) || ((u + v) > 1.0f)) { + if ((v < 0.0f) || ((u + v) > 1.0f)) + { // We hit the plane of the triangle, but outside the triangle return false; } @@ -84,8 +87,8 @@ namespace VMAP class TriBoundFunc { public: - TriBoundFunc(std::vector &vert): vertices(vert.begin()) {} - void operator()(const MeshTriangle &tri, G3D::AABox &out) const + TriBoundFunc(std::vector& vert): vertices(vert.begin()) {} + void operator()(const MeshTriangle& tri, G3D::AABox& out) const { G3D::Vector3 lo = vertices[tri.idx0]; G3D::Vector3 hi = lo; @@ -101,14 +104,14 @@ namespace VMAP // ===================== WmoLiquid ================================== - WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3 &corner, uint32 type): + WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3& corner, uint32 type): iTilesX(width), iTilesY(height), iCorner(corner), iType(type) { iHeight = new float[(width+1)*(height+1)]; iFlags = new uint8[width*height]; } - WmoLiquid::WmoLiquid(const WmoLiquid &other): iHeight(0), iFlags(0) + WmoLiquid::WmoLiquid(const WmoLiquid& other): iHeight(0), iFlags(0) { *this = other; // use assignment operator... } @@ -119,7 +122,7 @@ namespace VMAP delete[] iFlags; } - WmoLiquid& WmoLiquid::operator=(const WmoLiquid &other) + WmoLiquid& WmoLiquid::operator=(const WmoLiquid& other) { if (this == &other) return *this; @@ -146,7 +149,7 @@ namespace VMAP return *this; } - bool WmoLiquid::GetLiquidHeight(const Vector3 &pos, float &liqHeight) const + bool WmoLiquid::GetLiquidHeight(const Vector3& pos, float& liqHeight) const { float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE; uint32 tx = uint32(tx_f); @@ -197,12 +200,12 @@ namespace VMAP uint32 WmoLiquid::GetFileSize() { return 2 * sizeof(uint32) + - sizeof(Vector3) + - (iTilesX + 1)*(iTilesY + 1) * sizeof(float) + - iTilesX * iTilesY; + sizeof(Vector3) + + (iTilesX + 1)*(iTilesY + 1) * sizeof(float) + + iTilesX * iTilesY; } - bool WmoLiquid::writeToFile(FILE *wf) + bool WmoLiquid::writeToFile(FILE* wf) { bool result = true; if (result && fwrite(&iTilesX, sizeof(uint32), 1, wf) != 1) result = false; @@ -216,10 +219,10 @@ namespace VMAP return result; } - bool WmoLiquid::readFromFile(FILE *rf, WmoLiquid *&out) + bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid*& out) { bool result = true; - WmoLiquid *liquid = new WmoLiquid(); + WmoLiquid* liquid = new WmoLiquid(); if (result && fread(&liquid->iTilesX, sizeof(uint32), 1, rf) != 1) result = false; if (result && fread(&liquid->iTilesY, sizeof(uint32), 1, rf) != 1) result = false; if (result && fread(&liquid->iCorner, sizeof(Vector3), 1, rf) != 1) result = false; @@ -238,7 +241,7 @@ namespace VMAP // ===================== GroupModel ================================== - GroupModel::GroupModel(const GroupModel &other): + GroupModel::GroupModel(const GroupModel& other): iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID), vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(0) { @@ -246,7 +249,7 @@ namespace VMAP iLiquid = new WmoLiquid(*other.iLiquid); } - void GroupModel::setMeshData(std::vector &vert, std::vector &tri) + void GroupModel::setMeshData(std::vector& vert, std::vector& tri) { vertices.swap(vert); triangles.swap(tri); @@ -254,7 +257,7 @@ namespace VMAP meshTree.build(triangles, bFunc); } - bool GroupModel::writeToFile(FILE *wf) + bool GroupModel::writeToFile(FILE* wf) { bool result = true; uint32 chunkSize, count; @@ -300,7 +303,7 @@ namespace VMAP return result; } - bool GroupModel::readFromFile(FILE *rf) + bool GroupModel::readFromFile(FILE* rf) { char chunk[8]; bool result = true; @@ -344,7 +347,7 @@ namespace VMAP struct GModelRayCallback { - GModelRayCallback(const std::vector &tris, const std::vector &vert): + GModelRayCallback(const std::vector& tris, const std::vector& vert): vertices(vert.begin()), triangles(tris.begin()), hit(false) {} bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit) { @@ -357,7 +360,7 @@ namespace VMAP bool hit; }; - bool GroupModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const + bool GroupModel::IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const { if (!triangles.size()) return false; @@ -366,7 +369,7 @@ namespace VMAP return callback.hit; } - bool GroupModel::IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const + bool GroupModel::IsInsideObject(const Vector3& pos, const Vector3& down, float& z_dist) const { if (!triangles.size() || !iBound.contains(pos)) return false; @@ -380,7 +383,7 @@ namespace VMAP return hit; } - bool GroupModel::GetLiquidLevel(const Vector3 &pos, float &liqHeight) const + bool GroupModel::GetLiquidLevel(const Vector3& pos, float& liqHeight) const { if (iLiquid) return iLiquid->GetLiquidHeight(pos, liqHeight); @@ -397,7 +400,7 @@ namespace VMAP // ===================== WorldModel ================================== - void WorldModel::setGroupModels(std::vector &models) + void WorldModel::setGroupModels(std::vector& models) { groupModels.swap(models); groupTree.build(groupModels, BoundsTrait::getBounds, 1); @@ -405,7 +408,7 @@ namespace VMAP struct WModelRayCallBack { - WModelRayCallBack(const std::vector &mod): models(mod.begin()), hit(false) {} + WModelRayCallBack(const std::vector& mod): models(mod.begin()), hit(false) {} bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit) { bool result = models[entry].IntersectRay(ray, distance, pStopAtFirstHit); @@ -416,7 +419,7 @@ namespace VMAP bool hit; }; - bool WorldModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const + bool WorldModel::IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const { // small M2 workaround, maybe better make separate class with virtual intersection funcs // in any case, there's no need to use a bound tree if we only have one submodel @@ -428,9 +431,10 @@ namespace VMAP return isc.hit; } - class WModelAreaCallback { + class WModelAreaCallback + { public: - WModelAreaCallback(const std::vector &vals, const Vector3 &down): + WModelAreaCallback(const std::vector& vals, const Vector3& down): prims(vals.begin()), hit(vals.end()), minVol(G3D::inf()), zDist(G3D::inf()), zVec(down) {} std::vector::const_iterator prims; std::vector::const_iterator hit; @@ -443,29 +447,29 @@ namespace VMAP //float pVol = prims[entry].GetBound().volume(); //if(pVol < minVol) //{ - /* if (prims[entry].iBound.contains(point)) */ - if (prims[entry].IsInsideObject(point, zVec, group_Z)) + /* if (prims[entry].iBound.contains(point)) */ + if (prims[entry].IsInsideObject(point, zVec, group_Z)) + { + //minVol = pVol; + //hit = prims + entry; + if (group_Z < zDist) { - //minVol = pVol; - //hit = prims + entry; - if (group_Z < zDist) - { - zDist = group_Z; - hit = prims + entry; - } + zDist = group_Z; + hit = prims + entry; + } #ifdef VMAP_DEBUG - const GroupModel &gm = prims[entry]; - printf("%10u %8X %7.3f,%7.3f,%7.3f | %7.3f,%7.3f,%7.3f | z=%f, p_z=%f\n", gm.GetWmoID(), gm.GetMogpFlags(), - gm.GetBound().low().x, gm.GetBound().low().y, gm.GetBound().low().z, - gm.GetBound().high().x, gm.GetBound().high().y, gm.GetBound().high().z, group_Z, point.z); + const GroupModel& gm = prims[entry]; + printf("%10u %8X %7.3f,%7.3f,%7.3f | %7.3f,%7.3f,%7.3f | z=%f, p_z=%f\n", gm.GetWmoID(), gm.GetMogpFlags(), + gm.GetBound().low().x, gm.GetBound().low().y, gm.GetBound().low().z, + gm.GetBound().high().x, gm.GetBound().high().y, gm.GetBound().high().z, group_Z, point.z); #endif - } + } //} //std::cout << "trying to intersect '" << prims[entry].name << "'\n"; } }; - bool WorldModel::IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const + bool WorldModel::IntersectPoint(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, AreaInfo& info) const { if (!groupModels.size()) return false; @@ -483,7 +487,7 @@ namespace VMAP return false; } - bool WorldModel::GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const + bool WorldModel::GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const { if (!groupModels.size()) return false; @@ -498,9 +502,9 @@ namespace VMAP return false; } - bool WorldModel::writeFile(const std::string &filename) + bool WorldModel::writeFile(const std::string& filename) { - FILE *wf = fopen(filename.c_str(), "wb"); + FILE* wf = fopen(filename.c_str(), "wb"); if (!wf) return false; @@ -532,9 +536,9 @@ namespace VMAP return result; } - bool WorldModel::readFile(const std::string &filename) + bool WorldModel::readFile(const std::string& filename) { - FILE *rf = fopen(filename.c_str(), "rb"); + FILE* rf = fopen(filename.c_str(), "rb"); if (!rf) return false; diff --git a/src/game/vmap/WorldModel.h b/src/game/vmap/WorldModel.h index c5020f74bfd..b44b7a372bd 100644 --- a/src/game/vmap/WorldModel.h +++ b/src/game/vmap/WorldModel.h @@ -36,7 +36,7 @@ namespace VMAP class MeshTriangle { public: - MeshTriangle(){}; + MeshTriangle() {}; MeshTriangle(uint32 na, uint32 nb, uint32 nc): idx0(na), idx1(nb), idx2(nc) {}; uint32 idx0; @@ -47,28 +47,28 @@ namespace VMAP class WmoLiquid { public: - WmoLiquid(uint32 width, uint32 height, const Vector3 &corner, uint32 type); - WmoLiquid(const WmoLiquid &other); + WmoLiquid(uint32 width, uint32 height, const Vector3& corner, uint32 type); + WmoLiquid(const WmoLiquid& other); ~WmoLiquid(); - WmoLiquid& operator=(const WmoLiquid &other); - bool GetLiquidHeight(const Vector3 &pos, float &liqHeight) const; + WmoLiquid& operator=(const WmoLiquid& other); + bool GetLiquidHeight(const Vector3& pos, float& liqHeight) const; uint32 GetType() const { return iType; } - float *GetHeightStorage() { return iHeight; } - uint8 *GetFlagsStorage() { return iFlags; } + float* GetHeightStorage() { return iHeight; } + uint8* GetFlagsStorage() { return iFlags; } uint32 GetFileSize(); - bool writeToFile(FILE *wf); - static bool readFromFile(FILE *rf, WmoLiquid *&liquid); + bool writeToFile(FILE* wf); + static bool readFromFile(FILE* rf, WmoLiquid*& liquid); private: WmoLiquid(): iHeight(0), iFlags(0) {}; uint32 iTilesX; //!< number of tiles in x direction, each uint32 iTilesY; Vector3 iCorner; //!< the lower corner uint32 iType; //!< liquid type - float *iHeight; //!< (tilesX + 1)*(tilesY + 1) height values - uint8 *iFlags; //!< info if liquid tile is used + float* iHeight; //!< (tilesX + 1)*(tilesY + 1) height values + uint8* iFlags; //!< info if liquid tile is used #ifdef MMAP_GENERATOR public: - void getPosInfo(uint32 &tilesX, uint32 &tilesY, Vector3 &corner) const; + void getPosInfo(uint32& tilesX, uint32& tilesY, Vector3& corner) const; #endif }; @@ -77,20 +77,20 @@ namespace VMAP { public: GroupModel(): iLiquid(0) {} - GroupModel(const GroupModel &other); - GroupModel(uint32 mogpFlags, uint32 groupWMOID, const AABox &bound): - iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(0) {} + GroupModel(const GroupModel& other); + GroupModel(uint32 mogpFlags, uint32 groupWMOID, const AABox& bound): + iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(0) {} ~GroupModel() { delete iLiquid; } //! pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry! - void setMeshData(std::vector &vert, std::vector &tri); - void setLiquidData(WmoLiquid *liquid) { iLiquid = liquid; } - bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const; - bool IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const; - bool GetLiquidLevel(const Vector3 &pos, float &liqHeight) const; + void setMeshData(std::vector& vert, std::vector& tri); + void setLiquidData(WmoLiquid* liquid) { iLiquid = liquid; } + bool IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const; + bool IsInsideObject(const Vector3& pos, const Vector3& down, float& z_dist) const; + bool GetLiquidLevel(const Vector3& pos, float& liqHeight) const; uint32 GetLiquidType() const; - bool writeToFile(FILE *wf); - bool readFromFile(FILE *rf); + bool writeToFile(FILE* wf); + bool readFromFile(FILE* rf); const G3D::AABox& GetBound() const { return iBound; } uint32 GetMogpFlags() const { return iMogpFlags; } uint32 GetWmoID() const { return iGroupWMOID; } @@ -101,11 +101,11 @@ namespace VMAP std::vector vertices; std::vector triangles; BIH meshTree; - WmoLiquid *iLiquid; + WmoLiquid* iLiquid; #ifdef MMAP_GENERATOR public: - void getMeshData(std::vector &vertices, std::vector &triangles, WmoLiquid* &liquid); + void getMeshData(std::vector& vertices, std::vector& triangles, WmoLiquid*& liquid); #endif }; /*! Holds a model (converted M2 or WMO) in its original coordinate space */ @@ -115,13 +115,13 @@ namespace VMAP WorldModel(): RootWMOID(0) {} //! pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry! - void setGroupModels(std::vector &models); + void setGroupModels(std::vector& models); void setRootWmoID(uint32 id) { RootWMOID = id; } - bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const; - bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const; - bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const; - bool writeFile(const std::string &filename); - bool readFile(const std::string &filename); + bool IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const; + bool IntersectPoint(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, AreaInfo& info) const; + bool GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const; + bool writeFile(const std::string& filename); + bool readFile(const std::string& filename); protected: uint32 RootWMOID; std::vector groupModels; @@ -129,7 +129,7 @@ namespace VMAP #ifdef MMAP_GENERATOR public: - void getGroupModels(std::vector &groupModels); + void getGroupModels(std::vector& groupModels); #endif }; } // namespace VMAP