aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Collision')
-rw-r--r--src/common/Collision/BoundingIntervalHierarchy.h6
-rw-r--r--src/common/Collision/DynamicTree.cpp20
-rw-r--r--src/common/Collision/DynamicTree.h6
-rw-r--r--src/common/Collision/Management/IVMapManager.h6
-rw-r--r--src/common/Collision/Management/VMapManager2.cpp4
-rw-r--r--src/common/Collision/Management/VMapManager2.h4
-rw-r--r--src/common/Collision/Maps/MapDefines.h17
-rw-r--r--src/common/Collision/Maps/MapTree.cpp64
-rw-r--r--src/common/Collision/Maps/MapTree.h4
-rw-r--r--src/common/Collision/Models/ModelInstance.cpp20
-rw-r--r--src/common/Collision/Models/ModelInstance.h22
-rw-r--r--src/common/Collision/Models/WorldModel.cpp78
-rw-r--r--src/common/Collision/Models/WorldModel.h12
-rw-r--r--src/common/Collision/RegularGrid.h26
14 files changed, 164 insertions, 125 deletions
diff --git a/src/common/Collision/BoundingIntervalHierarchy.h b/src/common/Collision/BoundingIntervalHierarchy.h
index dedcba64307..2f73967f09d 100644
--- a/src/common/Collision/BoundingIntervalHierarchy.h
+++ b/src/common/Collision/BoundingIntervalHierarchy.h
@@ -79,8 +79,8 @@ class TC_COMMON_API BIH
}
public:
BIH() { init_empty(); }
- template< class BoundsFunc, class PrimArray >
- void build(const PrimArray &primitives, BoundsFunc &getBounds, uint32 leafSize = 3, bool printStats=false)
+ template <class BoundsFunc, class PrimArray>
+ void build(PrimArray const& primitives, BoundsFunc& getBounds, uint32 leafSize = 3, bool printStats = false)
{
if (primitives.size() == 0)
{
@@ -117,7 +117,7 @@ class TC_COMMON_API BIH
uint32 primCount() const { return uint32(objects.size()); }
template<typename RayCallback>
- void intersectRay(const G3D::Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst=false) const
+ void intersectRay(const G3D::Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst = false) const
{
float intervalMin = -1.f;
float intervalMax = -1.f;
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp
index b1f03aace13..5111ba7afa0 100644
--- a/src/common/Collision/DynamicTree.cpp
+++ b/src/common/Collision/DynamicTree.cpp
@@ -40,20 +40,20 @@ int CHECK_TREE_PERIOD = 200;
} // namespace
template<> struct HashTrait< GameObjectModel>{
- static size_t hashCode(const GameObjectModel& g) { return (size_t)(void*)&g; }
+ static size_t hashCode(GameObjectModel const& g) { return (size_t)(void*)&g; }
};
template<> struct PositionTrait< GameObjectModel> {
- static void getPosition(const GameObjectModel& g, G3D::Vector3& p) { p = g.getPosition(); }
+ static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.getPosition(); }
};
template<> struct BoundsTrait< GameObjectModel> {
- static void getBounds(const GameObjectModel& g, G3D::AABox& out) { out = g.getBounds();}
- static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();}
+ static void getBounds(GameObjectModel const& g, G3D::AABox& out) { out = g.getBounds();}
+ static void getBounds2(GameObjectModel const* g, G3D::AABox& out) { out = g->getBounds();}
};
/*
-static bool operator == (const GameObjectModel& mdl, const GameObjectModel& mdl2){
+static bool operator==(GameObjectModel const& mdl, GameObjectModel const& mdl2){
return &mdl == &mdl2;
}
*/
@@ -71,13 +71,13 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/
{
}
- void insert(const Model& mdl)
+ void insert(Model const& mdl)
{
base::insert(mdl);
++unbalanced_times;
}
- void remove(const Model& mdl)
+ void remove(Model const& mdl)
{
base::remove(mdl);
++unbalanced_times;
@@ -114,17 +114,17 @@ DynamicMapTree::~DynamicMapTree()
delete impl;
}
-void DynamicMapTree::insert(const GameObjectModel& mdl)
+void DynamicMapTree::insert(GameObjectModel const& mdl)
{
impl->insert(mdl);
}
-void DynamicMapTree::remove(const GameObjectModel& mdl)
+void DynamicMapTree::remove(GameObjectModel const& mdl)
{
impl->remove(mdl);
}
-bool DynamicMapTree::contains(const GameObjectModel& mdl) const
+bool DynamicMapTree::contains(GameObjectModel const& mdl) const
{
return impl->contains(mdl);
}
diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h
index 5581702a504..6ddbb33c221 100644
--- a/src/common/Collision/DynamicTree.h
+++ b/src/common/Collision/DynamicTree.h
@@ -53,9 +53,9 @@ public:
bool getAreaInfo(float x, float y, float& z, PhaseShift const& phaseShift, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
void getAreaAndLiquidData(float x, float y, float z, PhaseShift const& phaseShift, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const;
- void insert(const GameObjectModel&);
- void remove(const GameObjectModel&);
- bool contains(const GameObjectModel&) const;
+ void insert(GameObjectModel const&);
+ void remove(GameObjectModel const&);
+ bool contains(GameObjectModel const&) const;
void balance();
void update(uint32 diff);
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h
index 87c084f7f8c..3d760082e28 100644
--- a/src/common/Collision/Management/IVMapManager.h
+++ b/src/common/Collision/Management/IVMapManager.h
@@ -18,10 +18,10 @@
#ifndef _IVMAPMANAGER_H
#define _IVMAPMANAGER_H
-#include <string>
#include "Define.h"
#include "ModelIgnoreFlags.h"
#include "Optional.h"
+#include <string>
//===========================================================
@@ -82,9 +82,9 @@ namespace VMAP
virtual ~IVMapManager(void) { }
- virtual int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0;
+ virtual int loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
- virtual LoadResult existsMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0;
+ virtual LoadResult existsMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
virtual void unloadMap(unsigned int pMapId, int x, int y) = 0;
virtual void unloadMap(unsigned int pMapId) = 0;
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp
index 428ae6ba146..88494d0a0c7 100644
--- a/src/common/Collision/Management/VMapManager2.cpp
+++ b/src/common/Collision/Management/VMapManager2.cpp
@@ -99,7 +99,7 @@ namespace VMAP
return fname.str();
}
- int VMapManager2::loadMap(const char* basePath, unsigned int mapId, int x, int y)
+ int VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y)
{
int result = VMAP_LOAD_RESULT_IGNORED;
if (isMapLoadingEnabled())
@@ -387,7 +387,7 @@ namespace VMAP
}
}
- LoadResult VMapManager2::existsMap(const char* basePath, unsigned int mapId, int x, int y)
+ LoadResult VMapManager2::existsMap(char const* basePath, unsigned int mapId, int x, int y)
{
return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y, this);
}
diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h
index f16038264dc..76253faded4 100644
--- a/src/common/Collision/Management/VMapManager2.h
+++ b/src/common/Collision/Management/VMapManager2.h
@@ -101,7 +101,7 @@ namespace VMAP
void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
- int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override;
+ int loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
bool loadSingleMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
void unloadMap(unsigned int mapId, int x, int y) override;
@@ -131,7 +131,7 @@ namespace VMAP
{
return getMapFileName(mapId);
}
- virtual LoadResult existsMap(const char* basePath, unsigned int mapId, int x, int y) override;
+ virtual LoadResult existsMap(char const* basePath, unsigned int mapId, int x, int y) override;
void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
diff --git a/src/common/Collision/Maps/MapDefines.h b/src/common/Collision/Maps/MapDefines.h
index 4935e991259..50f7e93e4c3 100644
--- a/src/common/Collision/Maps/MapDefines.h
+++ b/src/common/Collision/Maps/MapDefines.h
@@ -1,3 +1,20 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef _MAPDEFINES_H
#define _MAPDEFINES_H
diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp
index 313a95d855b..04f914fb4f1 100644
--- a/src/common/Collision/Maps/MapTree.cpp
+++ b/src/common/Collision/Maps/MapTree.cpp
@@ -35,26 +35,26 @@ namespace VMAP
class MapRayCallback
{
public:
- MapRayCallback(ModelInstance* val, ModelIgnoreFlags ignoreFlags): prims(val), hit(false), flags(ignoreFlags) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit=true)
+ MapRayCallback(ModelInstance* val, ModelIgnoreFlags ignoreFlags) : prims(val), hit(false), flags(ignoreFlags) { }
+ bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit = true)
{
bool result = prims[entry].intersectRay(ray, distance, pStopAtFirstHit, flags);
if (result)
hit = true;
return result;
}
- bool didHit() { return hit; }
- protected:
- ModelInstance* prims;
- bool hit;
- ModelIgnoreFlags flags;
+ bool didHit() { return hit; }
+ protected:
+ ModelInstance* prims;
+ bool hit;
+ ModelIgnoreFlags flags;
};
class AreaInfoCallback
{
public:
- AreaInfoCallback(ModelInstance* val): prims(val) { }
- void operator()(const Vector3& point, uint32 entry)
+ AreaInfoCallback(ModelInstance* val) : prims(val) { }
+ void operator()(Vector3 const& point, uint32 entry)
{
#ifdef VMAP_DEBUG
TC_LOG_DEBUG("maps", "AreaInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
@@ -69,8 +69,8 @@ namespace VMAP
class LocationInfoCallback
{
public:
- LocationInfoCallback(ModelInstance* val, LocationInfo &info): prims(val), locInfo(info), result(false) { }
- void operator()(const Vector3& point, uint32 entry)
+ LocationInfoCallback(ModelInstance* val, LocationInfo& info) : prims(val), locInfo(info), result(false) { }
+ void operator()(Vector3 const& point, uint32 entry)
{
#ifdef VMAP_DEBUG
TC_LOG_DEBUG("maps", "LocationInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
@@ -80,7 +80,7 @@ namespace VMAP
}
ModelInstance* prims;
- LocationInfo &locInfo;
+ LocationInfo& locInfo;
bool result;
};
@@ -96,7 +96,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);
@@ -112,17 +112,17 @@ namespace VMAP
return false;
}
- bool StaticMapTree::GetLocationInfo(const Vector3 &pos, LocationInfo &info) const
+ bool StaticMapTree::GetLocationInfo(Vector3 const& 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, std::string const& basePath)
: iMapID(mapID), iTreeValues(nullptr), iNTreeValues(0), iBasePath(basePath)
{
- if (iBasePath.length() > 0 && iBasePath[iBasePath.length()-1] != '/' && iBasePath[iBasePath.length()-1] != '\\')
+ if (iBasePath.length() > 0 && iBasePath[iBasePath.length() - 1] != '/' && iBasePath[iBasePath.length() - 1] != '\\')
{
iBasePath.push_back('/');
}
@@ -141,7 +141,7 @@ namespace VMAP
Else, pMaxDist is not modified and returns false;
*/
- bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
float distance = pMaxDist;
MapRayCallback intersectionCallBack(iTreeValues, ignoreFlags);
@@ -152,7 +152,7 @@ namespace VMAP
}
//=========================================================
- bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2, ModelIgnoreFlags ignoreFlag) const
+ bool StaticMapTree::isInLineOfSight(Vector3 const& pos1, Vector3 const& pos2, ModelIgnoreFlags ignoreFlag) const
{
float maxDist = (pos2 - pos1).magnitude();
// return false if distance is over max float, in case of cheater teleporting to the end of the universe
@@ -165,7 +165,7 @@ namespace VMAP
if (maxDist < 1e-10f)
return true;
// direction with length of 1
- G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist);
+ G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
if (getIntersectionTime(ray, maxDist, true, ignoreFlag))
return false;
@@ -177,9 +177,9 @@ namespace VMAP
Return the hit pos or the original dest pos
*/
- bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const
+ bool StaticMapTree::getObjectHitPos(Vector3 const& pPos1, Vector3 const& pPos2, Vector3& pResultHitPos, float pModifyDist) const
{
- bool result=false;
+ bool result = false;
float maxDist = (pPos2 - pPos1).magnitude();
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too
ASSERT(maxDist < std::numeric_limits<float>::max());
@@ -189,7 +189,7 @@ namespace VMAP
pResultHitPos = pPos2;
return false;
}
- Vector3 dir = (pPos2 - pPos1)/maxDist; // direction with length of 1
+ Vector3 dir = (pPos2 - pPos1) / maxDist; // direction with length of 1
G3D::Ray ray(pPos1, dir);
float dist = maxDist;
if (getIntersectionTime(ray, dist, false, ModelIgnoreFlags::Nothing))
@@ -199,7 +199,7 @@ namespace VMAP
{
if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
{
- pResultHitPos = pResultHitPos + dir*pModifyDist;
+ pResultHitPos = pResultHitPos + dir * pModifyDist;
}
else
{
@@ -208,7 +208,7 @@ namespace VMAP
}
else
{
- pResultHitPos = pResultHitPos + dir*pModifyDist;
+ pResultHitPos = pResultHitPos + dir * pModifyDist;
}
result = true;
}
@@ -222,7 +222,7 @@ namespace VMAP
//=========================================================
- float StaticMapTree::getHeight(const Vector3& pPos, float maxSearchDist) const
+ float StaticMapTree::getHeight(Vector3 const& pPos, float maxSearchDist) const
{
float height = G3D::finf();
Vector3 dir = Vector3(0, 0, -1);
@@ -258,10 +258,10 @@ namespace VMAP
}
//=========================================================
- LoadResult StaticMapTree::CanLoadMap(const std::string &vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
+ LoadResult StaticMapTree::CanLoadMap(const std::string& vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
{
std::string basePath = vmapPath;
- if (basePath.length() > 0 && basePath[basePath.length()-1] != '/' && basePath[basePath.length()-1] != '\\')
+ if (basePath.length() > 0 && basePath[basePath.length() - 1] != '/' && basePath[basePath.length() - 1] != '\\')
basePath.push_back('/');
std::string fullname = basePath + VMapManager2::getMapFileName(mapID);
@@ -377,7 +377,7 @@ namespace VMAP
uint32 numSpawns = 0;
if (result && fread(&numSpawns, sizeof(uint32), 1, fileResult.File) != 1)
result = false;
- for (uint32 i=0; i<numSpawns && result; ++i)
+ for (uint32 i = 0; i < numSpawns && result; ++i)
{
// read model spawns
ModelSpawn spawn;
@@ -446,14 +446,14 @@ namespace VMAP
TileFileOpenResult fileResult = OpenMapTileFile(iBasePath, iMapID, tileX, tileY, vm);
if (fileResult.File)
{
- bool result=true;
+ bool result = true;
char chunk[8];
if (!readChunk(fileResult.File, chunk, VMAP_MAGIC, 8))
result = false;
uint32 numSpawns;
if (fread(&numSpawns, sizeof(uint32), 1, fileResult.File) != 1)
result = false;
- for (uint32 i=0; i<numSpawns && result; ++i)
+ for (uint32 i = 0; i < numSpawns && result; ++i)
{
// read model spawns
ModelSpawn spawn;
@@ -471,7 +471,7 @@ namespace VMAP
{
uint32 referencedNode = spawnIndex->second;
if (!iLoadedSpawns.count(referencedNode))
- TC_LOG_ERROR("misc", "StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)", spawn.name.c_str(), spawn.ID);
+ TC_LOG_ERROR("misc", "StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)", spawn.name.c_str(), spawn.ID);
else if (--iLoadedSpawns[referencedNode] == 0)
{
iTreeValues[referencedNode].setUnloaded();
@@ -488,7 +488,7 @@ namespace VMAP
"Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
}
- void StaticMapTree::getModelInstances(ModelInstance* &models, uint32 &count)
+ void StaticMapTree::getModelInstances(ModelInstance*& models, uint32& count)
{
models = iTreeValues;
count = iNTreeValues;
diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h
index a9eb70c6bab..d2012ea7a30 100644
--- a/src/common/Collision/Maps/MapTree.h
+++ b/src/common/Collision/Maps/MapTree.h
@@ -34,8 +34,8 @@ namespace VMAP
{
LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
int32 rootId;
- const ModelInstance* hitInstance;
- const GroupModel* hitModel;
+ ModelInstance const* hitInstance;
+ GroupModel const* hitModel;
float ground_Z;
};
diff --git a/src/common/Collision/Models/ModelInstance.cpp b/src/common/Collision/Models/ModelInstance.cpp
index 3689824e50b..385702a25ad 100644
--- a/src/common/Collision/Models/ModelInstance.cpp
+++ b/src/common/Collision/Models/ModelInstance.cpp
@@ -24,13 +24,13 @@ using G3D::Ray;
namespace VMAP
{
- ModelInstance::ModelInstance(const ModelSpawn &spawn, WorldModel* model): ModelSpawn(spawn), iModel(model)
+ ModelInstance::ModelInstance(ModelSpawn const& spawn, WorldModel* model) : ModelSpawn(spawn), iModel(model)
{
- iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif()*iRot.y/180.f, G3D::pif()*iRot.x/180.f, G3D::pif()*iRot.z/180.f).inverse();
- iInvScale = 1.f/iScale;
+ iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif() * iRot.y / 180.f, G3D::pif() * iRot.x / 180.f, G3D::pif() * iRot.z / 180.f).inverse();
+ iInvScale = 1.f / iScale;
}
- bool ModelInstance::intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool ModelInstance::intersectRay(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
if (!iModel)
{
@@ -63,7 +63,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)
{
@@ -97,7 +97,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)
{
@@ -133,7 +133,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;
@@ -149,7 +149,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);
@@ -195,9 +195,9 @@ namespace VMAP
return true;
}
- bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn &spawn)
+ bool ModelSpawn::writeToFile(FILE* wf, ModelSpawn const& spawn)
{
- uint32 check=0;
+ uint32 check = 0;
check += fwrite(&spawn.flags, sizeof(uint32), 1, wf);
check += fwrite(&spawn.adtId, sizeof(uint16), 1, wf);
check += fwrite(&spawn.ID, sizeof(uint32), 1, wf);
diff --git a/src/common/Collision/Models/ModelInstance.h b/src/common/Collision/Models/ModelInstance.h
index c5caf9599be..b342a14fdc6 100644
--- a/src/common/Collision/Models/ModelInstance.h
+++ b/src/common/Collision/Models/ModelInstance.h
@@ -51,25 +51,25 @@ namespace VMAP
float iScale;
G3D::AABox iBound;
std::string name;
- bool operator==(const ModelSpawn &other) const { return ID == other.ID; }
+ bool operator==(ModelSpawn const& other) const { return ID == other.ID; }
//uint32 hashCode() const { return ID; }
// temp?
- const G3D::AABox& getBounds() const { return iBound; }
+ G3D::AABox const& 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, ModelSpawn const& spawn);
};
- class TC_COMMON_API ModelInstance: public ModelSpawn
+ class TC_COMMON_API ModelInstance : public ModelSpawn
{
public:
- ModelInstance(): iInvScale(0.0f), iModel(nullptr) { }
- ModelInstance(const ModelSpawn &spawn, WorldModel* model);
+ ModelInstance() : iInvScale(0.0f), iModel(nullptr) { }
+ ModelInstance(ModelSpawn const& spawn, WorldModel* model);
void setUnloaded() { iModel = nullptr; }
- bool intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) 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;
+ bool intersectRay(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
+ void intersectPoint(G3D::Vector3 const& p, AreaInfo& info) const;
+ bool GetLocationInfo(G3D::Vector3 const& p, LocationInfo& info) const;
+ bool GetLiquidLevel(G3D::Vector3 const& p, LocationInfo& info, float& liqHeight) const;
WorldModel* getWorldModel() { return iModel; }
protected:
G3D::Matrix3 iInvRot;
diff --git a/src/common/Collision/Models/WorldModel.cpp b/src/common/Collision/Models/WorldModel.cpp
index a547a402b9d..9bbb6278950 100644
--- a/src/common/Collision/Models/WorldModel.cpp
+++ b/src/common/Collision/Models/WorldModel.cpp
@@ -31,7 +31,7 @@ template<> struct BoundsTrait<VMAP::GroupModel>
namespace VMAP
{
- bool IntersectTriangle(const MeshTriangle &tri, std::vector<Vector3>::const_iterator points, const G3D::Ray &ray, float &distance)
+ bool IntersectTriangle(MeshTriangle const& tri, std::vector<Vector3>::const_iterator points, G3D::Ray const& ray, float& distance)
{
static const float EPS = 1e-5f;
@@ -84,8 +84,8 @@ namespace VMAP
class TriBoundFunc
{
public:
- TriBoundFunc(std::vector<Vector3> &vert): vertices(vert.begin()) { }
- void operator()(const MeshTriangle &tri, G3D::AABox &out) const
+ TriBoundFunc(std::vector<Vector3>& vert): vertices(vert.begin()) { }
+ void operator()(MeshTriangle const& tri, G3D::AABox& out) const
{
G3D::Vector3 lo = vertices[tri.idx0];
G3D::Vector3 hi = lo;
@@ -101,7 +101,7 @@ namespace VMAP
// ===================== WmoLiquid ==================================
- WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3 &corner, uint32 type):
+ WmoLiquid::WmoLiquid(uint32 width, uint32 height, Vector3 const& corner, uint32 type) :
iTilesX(width), iTilesY(height), iCorner(corner), iType(type)
{
if (width && height)
@@ -116,7 +116,7 @@ namespace VMAP
}
}
- WmoLiquid::WmoLiquid(const WmoLiquid &other): iHeight(nullptr), iFlags(nullptr)
+ WmoLiquid::WmoLiquid(WmoLiquid const& other) : iHeight(nullptr), iFlags(nullptr)
{
*this = other; // use assignment operator...
}
@@ -127,7 +127,7 @@ namespace VMAP
delete[] iFlags;
}
- WmoLiquid& WmoLiquid::operator=(const WmoLiquid &other)
+ WmoLiquid& WmoLiquid::operator=(WmoLiquid const& other)
{
if (this == &other)
return *this;
@@ -154,7 +154,7 @@ namespace VMAP
return *this;
}
- bool WmoLiquid::GetLiquidHeight(const Vector3 &pos, float &liqHeight) const
+ bool WmoLiquid::GetLiquidHeight(Vector3 const& pos, float& liqHeight) const
{
// simple case
if (!iFlags)
@@ -163,18 +163,18 @@ namespace VMAP
return true;
}
- float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE;
+ float tx_f = (pos.x - iCorner.x) / LIQUID_TILE_SIZE;
uint32 tx = uint32(tx_f);
if (tx_f < 0.0f || tx >= iTilesX)
return false;
- float ty_f = (pos.y - iCorner.y)/LIQUID_TILE_SIZE;
+ float ty_f = (pos.y - iCorner.y) / LIQUID_TILE_SIZE;
uint32 ty = uint32(ty_f);
if (ty_f < 0.0f || ty >= iTilesY)
return false;
// check if tile shall be used for liquid level
// checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
- if ((iFlags[tx + ty*iTilesX] & 0x0F) == 0x0F)
+ if ((iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F)
return false;
// (dx, dy) coordinates inside tile, in [0, 1]^2
@@ -194,7 +194,7 @@ namespace VMAP
0 1
*/
- const uint32 rowOffset = iTilesX + 1;
+ uint32 const rowOffset = iTilesX + 1;
if (dx > dy) // case (a)
{
float sx = iHeight[tx+1 + ty * rowOffset] - iHeight[tx + ty * rowOffset];
@@ -242,7 +242,7 @@ namespace VMAP
return result;
}
- bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid* &out)
+ bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid*& out)
{
bool result = false;
WmoLiquid* liquid = new WmoLiquid();
@@ -278,7 +278,7 @@ namespace VMAP
return result;
}
- void WmoLiquid::getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const
+ void WmoLiquid::getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const
{
tilesX = iTilesX;
tilesY = iTilesY;
@@ -287,7 +287,7 @@ namespace VMAP
// ===================== GroupModel ==================================
- GroupModel::GroupModel(const GroupModel &other):
+ GroupModel::GroupModel(GroupModel const& other) :
iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID),
vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(nullptr)
{
@@ -295,7 +295,7 @@ namespace VMAP
iLiquid = new WmoLiquid(*other.iLiquid);
}
- void GroupModel::setMeshData(std::vector<Vector3> &vert, std::vector<MeshTriangle> &tri)
+ void GroupModel::setMeshData(std::vector<Vector3>& vert, std::vector<MeshTriangle>& tri)
{
vertices.swap(vert);
triangles.swap(tri);
@@ -315,7 +315,7 @@ namespace VMAP
// write vertices
if (result && fwrite("VERT", 1, 4, wf) != 4) result = false;
count = vertices.size();
- chunkSize = sizeof(uint32)+ sizeof(Vector3)*count;
+ chunkSize = sizeof(uint32) + sizeof(Vector3) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (!count) // models without (collision) geometry end here, unsure if they are useful
@@ -325,7 +325,7 @@ namespace VMAP
// write triangle mesh
if (result && fwrite("TRIM", 1, 4, wf) != 4) result = false;
count = triangles.size();
- chunkSize = sizeof(uint32)+ sizeof(MeshTriangle)*count;
+ chunkSize = sizeof(uint32) + sizeof(MeshTriangle) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) result = false;
@@ -394,12 +394,13 @@ namespace VMAP
struct GModelRayCallback
{
- GModelRayCallback(const std::vector<MeshTriangle> &tris, const std::vector<Vector3> &vert):
+ GModelRayCallback(std::vector<MeshTriangle> const& tris, const std::vector<Vector3> &vert):
vertices(vert.begin()), triangles(tris.begin()), hit(false) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool /*pStopAtFirstHit*/)
+ bool operator()(G3D::Ray const& ray, uint32 entry, float& distance, bool /*pStopAtFirstHit*/)
{
bool result = IntersectTriangle(triangles[entry], vertices, ray, distance);
- if (result) hit=true;
+ if (result)
+ hit = true;
return hit;
}
std::vector<Vector3>::const_iterator vertices;
@@ -407,7 +408,7 @@ namespace VMAP
bool hit;
};
- bool GroupModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
+ bool GroupModel::IntersectRay(G3D::Ray const& ray, float& distance, bool stopAtFirstHit) const
{
if (triangles.empty())
return false;
@@ -417,7 +418,7 @@ namespace VMAP
return callback.hit;
}
- bool GroupModel::IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const
+ bool GroupModel::IsInsideObject(Vector3 const& pos, Vector3 const& down, float& z_dist) const
{
if (triangles.empty() || !iBound.contains(pos))
return false;
@@ -431,7 +432,7 @@ namespace VMAP
return hit;
}
- bool GroupModel::GetLiquidLevel(const Vector3 &pos, float &liqHeight) const
+ bool GroupModel::GetLiquidLevel(Vector3 const& pos, float& liqHeight) const
{
if (iLiquid)
return iLiquid->GetLiquidHeight(pos, liqHeight);
@@ -454,7 +455,7 @@ namespace VMAP
// ===================== WorldModel ==================================
- void WorldModel::setGroupModels(std::vector<GroupModel> &models)
+ void WorldModel::setGroupModels(std::vector<GroupModel>& models)
{
groupModels.swap(models);
groupTree.build(groupModels, BoundsTrait<GroupModel>::getBounds, 1);
@@ -462,18 +463,19 @@ namespace VMAP
struct WModelRayCallBack
{
- WModelRayCallBack(const std::vector<GroupModel> &mod): models(mod.begin()), hit(false) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit)
+ WModelRayCallBack(std::vector<GroupModel> const& mod): models(mod.begin()), hit(false) { }
+ bool operator()(G3D::Ray const& ray, uint32 entry, float& distance, bool pStopAtFirstHit)
{
bool result = models[entry].IntersectRay(ray, distance, pStopAtFirstHit);
- if (result) hit=true;
+ if (result)
+ hit = true;
return hit;
}
std::vector<GroupModel>::const_iterator models;
bool hit;
};
- bool WorldModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool WorldModel::IntersectRay(G3D::Ray const& ray, float& distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
// If the caller asked us to ignore certain objects we should check flags
if ((ignoreFlags & ModelIgnoreFlags::M2) != ModelIgnoreFlags::Nothing)
@@ -495,14 +497,14 @@ namespace VMAP
class WModelAreaCallback {
public:
- WModelAreaCallback(const std::vector<GroupModel> &vals, const Vector3 &down):
+ WModelAreaCallback(std::vector<GroupModel> const& vals, Vector3 const& down) :
prims(vals.begin()), hit(vals.end()), minVol(G3D::finf()), zDist(G3D::finf()), zVec(down) { }
std::vector<GroupModel>::const_iterator prims;
std::vector<GroupModel>::const_iterator hit;
float minVol;
float zDist;
Vector3 zVec;
- void operator()(const Vector3& point, uint32 entry)
+ void operator()(Vector3 const& point, uint32 entry)
{
float group_Z;
//float pVol = prims[entry].GetBound().volume();
@@ -519,7 +521,7 @@ namespace VMAP
hit = prims + entry;
}
#ifdef VMAP_DEBUG
- const GroupModel &gm = prims[entry];
+ GroupModel const& 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);
@@ -530,7 +532,7 @@ namespace VMAP
}
};
- 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.empty())
return false;
@@ -549,7 +551,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.empty())
return false;
@@ -566,7 +568,7 @@ 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");
if (!wf)
@@ -580,14 +582,14 @@ namespace VMAP
if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) result = false;
// write group models
- count=groupModels.size();
+ count = groupModels.size();
if (count)
{
if (result && fwrite("GMOD", 1, 4, wf) != 4) result = false;
//chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
//if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
- for (uint32 i=0; i<groupModels.size() && result; ++i)
+ for (uint32 i = 0; i < groupModels.size() && result; ++i)
result = groupModels[i].writeToFile(wf);
// write group BIH
@@ -599,7 +601,7 @@ 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");
if (!rf)
@@ -623,7 +625,7 @@ namespace VMAP
if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
if (result) groupModels.resize(count);
//if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
- for (uint32 i=0; i<count && result; ++i)
+ for (uint32 i = 0; i < count && result; ++i)
result = groupModels[i].readFromFile(rf);
// read group BIH
diff --git a/src/common/Collision/Models/WorldModel.h b/src/common/Collision/Models/WorldModel.h
index 4392f9b194f..093a4ea84ed 100644
--- a/src/common/Collision/Models/WorldModel.h
+++ b/src/common/Collision/Models/WorldModel.h
@@ -47,11 +47,11 @@ namespace VMAP
class TC_COMMON_API WmoLiquid
{
public:
- WmoLiquid(uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type);
- WmoLiquid(const WmoLiquid &other);
+ WmoLiquid(uint32 width, uint32 height, G3D::Vector3 const& corner, uint32 type);
+ WmoLiquid(WmoLiquid const& other);
~WmoLiquid();
- WmoLiquid& operator=(const WmoLiquid &other);
- bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const;
+ WmoLiquid& operator=(WmoLiquid const& other);
+ bool GetLiquidHeight(G3D::Vector3 const& pos, float& liqHeight) const;
uint32 GetType() const { return iType; }
float *GetHeightStorage() { return iHeight; }
uint8 *GetFlagsStorage() { return iFlags; }
@@ -74,8 +74,8 @@ namespace VMAP
{
public:
GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(nullptr) { }
- GroupModel(const GroupModel &other);
- GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound):
+ GroupModel(GroupModel const& other);
+ GroupModel(uint32 mogpFlags, uint32 groupWMOID, G3D::AABox const& bound):
iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(nullptr) { }
~GroupModel() { delete iLiquid; }
diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h
index 5de9d80c893..953ddd44a35 100644
--- a/src/common/Collision/RegularGrid.h
+++ b/src/common/Collision/RegularGrid.h
@@ -1,3 +1,20 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef _REGULAR_GRID_H
#define _REGULAR_GRID_H
@@ -86,15 +103,18 @@ public:
struct Cell
{
int x, y;
- bool operator == (const Cell& c2) const { return x == c2.x && y == c2.y;}
+ bool operator==(Cell const& c2) const
+ {
+ return x == c2.x && y == c2.y;
+ }
static Cell ComputeCell(float fx, float fy)
{
- Cell c = { int(fx * (1.f/CELL_SIZE) + (CELL_NUMBER/2)), int(fy * (1.f/CELL_SIZE) + (CELL_NUMBER/2)) };
+ Cell c = { int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
return c;
}
- bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER;}
+ bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER; }
};
Node& getGrid(int x, int y)