aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision/Models
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-04-24 23:28:42 +0200
committerShauren <shauren.trinity@gmail.com>2021-04-25 00:11:36 +0200
commitbb8f22ed2013f8cb6b9d61c738f2ebd96b83722f (patch)
tree37e089d220d7c5967266fc71b30ef36de81e67c3 /src/common/Collision/Models
parent4e00cb7c157a0bd25a0b48a80a1f71a1817010bf (diff)
Core/Vmaps: Reduce memory used by vmaps (and their size, slightly)
Diffstat (limited to 'src/common/Collision/Models')
-rw-r--r--src/common/Collision/Models/GameObjectModel.cpp3
-rw-r--r--src/common/Collision/Models/GameObjectModel.h2
-rw-r--r--src/common/Collision/Models/ModelInstance.cpp12
-rw-r--r--src/common/Collision/Models/ModelInstance.h26
-rw-r--r--src/common/Collision/Models/WorldModel.h3
5 files changed, 27 insertions, 19 deletions
diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp
index 148ecff9066..65a530e7c0e 100644
--- a/src/common/Collision/Models/GameObjectModel.cpp
+++ b/src/common/Collision/Models/GameObjectModel.cpp
@@ -98,7 +98,7 @@ void LoadGameObjectModelList(std::string const& dataPath)
GameObjectModel::~GameObjectModel()
{
if (iModel)
- ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->releaseModelInstance(name);
+ ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->releaseModelInstance(iModel->GetName());
}
bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
@@ -120,7 +120,6 @@ bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> model
if (!iModel)
return false;
- name = it->second.name;
iPos = modelOwner->GetPosition();
iScale = modelOwner->GetScale();
iInvScale = 1.f / iScale;
diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h
index 38406b12701..c10a8bfdea2 100644
--- a/src/common/Collision/Models/GameObjectModel.h
+++ b/src/common/Collision/Models/GameObjectModel.h
@@ -57,8 +57,6 @@ class TC_COMMON_API GameObjectModel /*, public Intersectable*/
{
GameObjectModel() : _collisionEnabled(false), iInvScale(0), iScale(0), iModel(nullptr), isWmo(false) { }
public:
- std::string name;
-
const G3D::AABox& getBounds() const { return iBound; }
~GameObjectModel();
diff --git a/src/common/Collision/Models/ModelInstance.cpp b/src/common/Collision/Models/ModelInstance.cpp
index 385702a25ad..28a0bd51d25 100644
--- a/src/common/Collision/Models/ModelInstance.cpp
+++ b/src/common/Collision/Models/ModelInstance.cpp
@@ -24,9 +24,9 @@ using G3D::Ray;
namespace VMAP
{
- ModelInstance::ModelInstance(ModelSpawn const& spawn, WorldModel* model) : ModelSpawn(spawn), iModel(model)
+ ModelInstance::ModelInstance(ModelSpawn const& spawn, WorldModel* model) : ModelMinimalData(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();
+ iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif() * spawn.iRot.y / 180.f, G3D::pif() * spawn.iRot.x / 180.f, G3D::pif() * spawn.iRot.z / 180.f).inverse();
iInvScale = 1.f / iScale;
}
@@ -152,7 +152,7 @@ namespace VMAP
bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn& spawn)
{
uint32 check = 0, nameLen;
- check += fread(&spawn.flags, sizeof(uint32), 1, rf);
+ check += fread(&spawn.flags, sizeof(uint8), 1, rf);
// EoF?
if (!check)
{
@@ -160,7 +160,7 @@ namespace VMAP
std::cout << "Error reading ModelSpawn!\n";
return false;
}
- check += fread(&spawn.adtId, sizeof(uint16), 1, rf);
+ check += fread(&spawn.adtId, sizeof(uint8), 1, rf);
check += fread(&spawn.ID, sizeof(uint32), 1, rf);
check += fread(&spawn.iPos, sizeof(float), 3, rf);
check += fread(&spawn.iRot, sizeof(float), 3, rf);
@@ -198,8 +198,8 @@ namespace VMAP
bool ModelSpawn::writeToFile(FILE* wf, ModelSpawn const& spawn)
{
uint32 check = 0;
- check += fwrite(&spawn.flags, sizeof(uint32), 1, wf);
- check += fwrite(&spawn.adtId, sizeof(uint16), 1, wf);
+ check += fwrite(&spawn.flags, sizeof(uint8), 1, wf);
+ check += fwrite(&spawn.adtId, sizeof(uint8), 1, wf);
check += fwrite(&spawn.ID, sizeof(uint32), 1, wf);
check += fwrite(&spawn.iPos, sizeof(float), 3, wf);
check += fwrite(&spawn.iRot, sizeof(float), 3, wf);
diff --git a/src/common/Collision/Models/ModelInstance.h b/src/common/Collision/Models/ModelInstance.h
index b342a14fdc6..bba48669d00 100644
--- a/src/common/Collision/Models/ModelInstance.h
+++ b/src/common/Collision/Models/ModelInstance.h
@@ -39,28 +39,35 @@ namespace VMAP
MOD_PARENT_SPAWN = 1 << 2
};
- class TC_COMMON_API ModelSpawn
+ struct ModelMinimalData
{
- public:
- //mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
- uint32 flags;
- uint16 adtId;
+ //Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi
+ uint8 flags;
+ uint8 adtId;
uint32 ID;
G3D::Vector3 iPos;
G3D::Vector3 iRot;
float iScale;
G3D::AABox iBound;
+#ifdef VMAP_DEBUG
std::string name;
- bool operator==(ModelSpawn const& other) const { return ID == other.ID; }
- //uint32 hashCode() const { return ID; }
- // temp?
+#endif
+
+ bool operator==(ModelMinimalData const& other) const { return ID == other.ID; }
G3D::AABox const& getBounds() const { return iBound; }
+ };
+
+ struct TC_COMMON_API ModelSpawn : public ModelMinimalData
+ {
+#ifndef VMAP_DEBUG
+ std::string name;
+#endif
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 ModelMinimalData
{
public:
ModelInstance() : iInvScale(0.0f), iModel(nullptr) { }
@@ -70,6 +77,7 @@ namespace VMAP
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;
+ G3D::Matrix3 const& GetInvRot() { return iInvRot; }
WorldModel* getWorldModel() { return iModel; }
protected:
G3D::Matrix3 iInvRot;
diff --git a/src/common/Collision/Models/WorldModel.h b/src/common/Collision/Models/WorldModel.h
index 093a4ea84ed..8e2c97501e1 100644
--- a/src/common/Collision/Models/WorldModel.h
+++ b/src/common/Collision/Models/WorldModel.h
@@ -117,11 +117,14 @@ namespace VMAP
bool writeFile(const std::string &filename);
bool readFile(const std::string &filename);
void getGroupModels(std::vector<GroupModel>& outGroupModels);
+ std::string const& GetName() const { return name; }
+ void SetName(std::string newName) { name = std::move(newName); }
uint32 Flags;
protected:
uint32 RootWMOID;
std::vector<GroupModel> groupModels;
BIH groupTree;
+ std::string name;
};
} // namespace VMAP