aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/collision/Management/VMapManager2.cpp2
-rw-r--r--src/server/collision/Models/GameObjectModel.cpp49
-rw-r--r--src/server/collision/Models/GameObjectModel.h41
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp26
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h1
-rw-r--r--src/server/game/Entities/Transport/Transport.cpp2
-rw-r--r--src/server/game/World/World.cpp4
7 files changed, 74 insertions, 51 deletions
diff --git a/src/server/collision/Management/VMapManager2.cpp b/src/server/collision/Management/VMapManager2.cpp
index a1cdb5502a9..9594951196f 100644
--- a/src/server/collision/Management/VMapManager2.cpp
+++ b/src/server/collision/Management/VMapManager2.cpp
@@ -107,7 +107,7 @@ namespace VMAP
}
// load one tile (internal use only)
- bool VMapManager2::_loadMap(unsigned int mapId, const std::string& basePath, uint32 tileX, uint32 tileY)
+ bool VMapManager2::_loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY)
{
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree == iInstanceMapTrees.end())
diff --git a/src/server/collision/Models/GameObjectModel.cpp b/src/server/collision/Models/GameObjectModel.cpp
index dd1502c45b0..c40cb22a18c 100644
--- a/src/server/collision/Models/GameObjectModel.cpp
+++ b/src/server/collision/Models/GameObjectModel.cpp
@@ -20,13 +20,9 @@
#include "VMapManager2.h"
#include "VMapDefinitions.h"
#include "WorldModel.h"
-
#include "GameObjectModel.h"
#include "Log.h"
-#include "GameObject.h"
-#include "Object.h"
-#include "DBCStores.h"
-#include "World.h"
+#include "Timer.h"
using G3D::Vector3;
using G3D::Ray;
@@ -44,13 +40,11 @@ struct GameobjectModelData
typedef std::unordered_map<uint32, GameobjectModelData> ModelList;
ModelList model_list;
-void LoadGameObjectModelList()
+void LoadGameObjectModelList(std::string const& dataPath)
{
-#ifndef NO_CORE_FUNCS
uint32 oldMSTime = getMSTime();
-#endif
- FILE* model_list_file = fopen((sWorld->GetDataPath() + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
+ FILE* model_list_file = fopen((dataPath + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
if (!model_list_file)
{
VMAP_ERROR_LOG("misc", "Unable to open '%s' file.", VMAP::GAMEOBJECT_MODELS);
@@ -84,7 +78,7 @@ void LoadGameObjectModelList()
model_list.insert
(
- ModelList::value_type( displayId, GameobjectModelData(std::string(buff, name_length), AABox(v1, v2)) )
+ ModelList::value_type(displayId, GameobjectModelData(std::string(buff, name_length), AABox(v1, v2)))
);
}
@@ -98,9 +92,9 @@ GameObjectModel::~GameObjectModel()
((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->releaseModelInstance(name);
}
-bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info)
+bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
{
- ModelList::const_iterator it = model_list.find(info.Displayid);
+ ModelList::const_iterator it = model_list.find(modelOwner->GetDisplayId());
if (it == model_list.end())
return false;
@@ -112,21 +106,18 @@ bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayIn
return false;
}
- iModel = ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->acquireModelInstance(sWorld->GetDataPath() + "vmaps/", it->second.name);
+ iModel = ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->acquireModelInstance(dataPath + "vmaps/", it->second.name);
if (!iModel)
return false;
name = it->second.name;
- //flags = VMAP::MOD_M2;
- //adtId = 0;
- //ID = 0;
- iPos = Vector3(go.GetPositionX(), go.GetPositionY(), go.GetPositionZ());
- phasemask = go.GetPhaseMask();
- iScale = go.GetObjectScale();
+ iPos = modelOwner->GetPosition();
+ phasemask = modelOwner->GetPhaseMask();
+ iScale = modelOwner->GetScale();
iInvScale = 1.f / iScale;
- G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(go.GetOrientation(), 0, 0);
+ G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(modelOwner->GetOrientation(), 0, 0);
iInvRot = iRotation.inverse();
// transform bounding box:
mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
@@ -140,22 +131,18 @@ bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayIn
for (int i = 0; i < 8; ++i)
{
Vector3 pos(iBound.corner(i));
- go.SummonCreature(1, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN);
+ modelOwner->DebugVisualizeCorner(pos);
}
#endif
- owner = &go;
+ owner = std::move(modelOwner);
return true;
}
-GameObjectModel* GameObjectModel::Create(const GameObject& go)
+GameObjectModel* GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
{
- const GameObjectDisplayInfoEntry* info = sGameObjectDisplayInfoStore.LookupEntry(go.GetDisplayId());
- if (!info)
- return NULL;
-
GameObjectModel* mdl = new GameObjectModel();
- if (!mdl->initialize(go, *info))
+ if (!mdl->initialize(std::move(modelOwner), dataPath))
{
delete mdl;
return NULL;
@@ -166,7 +153,7 @@ GameObjectModel* GameObjectModel::Create(const GameObject& go)
bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const
{
- if (!(phasemask & ph_mask) || !owner->isSpawned())
+ if (!(phasemask & ph_mask) || !owner->IsSpawned())
return false;
float time = ray.intersectionTime(iBound);
@@ -203,7 +190,7 @@ bool GameObjectModel::UpdatePosition()
return false;
}
- iPos = Vector3(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ());
+ iPos = owner->GetPosition();
G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0);
iInvRot = iRotation.inverse();
@@ -219,7 +206,7 @@ bool GameObjectModel::UpdatePosition()
for (int i = 0; i < 8; ++i)
{
Vector3 pos(iBound.corner(i));
- owner->SummonCreature(1, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN);
+ owner->DebugVisualizeCorner(pos);
}
#endif
diff --git a/src/server/collision/Models/GameObjectModel.h b/src/server/collision/Models/GameObjectModel.h
index 43d299d6d8f..17669189af5 100644
--- a/src/server/collision/Models/GameObjectModel.h
+++ b/src/server/collision/Models/GameObjectModel.h
@@ -25,6 +25,7 @@
#include <G3D/Ray.h>
#include "Define.h"
+#include <memory>
namespace VMAP
{
@@ -34,21 +35,21 @@ namespace VMAP
class GameObject;
struct GameObjectDisplayInfoEntry;
-class GameObjectModel /*, public Intersectable*/
+class GameObjectModelOwnerBase
{
- uint32 phasemask;
- G3D::AABox iBound;
- G3D::Matrix3 iInvRot;
- G3D::Vector3 iPos;
- //G3D::Vector3 iRot;
- float iInvScale;
- float iScale;
- VMAP::WorldModel* iModel;
- GameObject const* owner;
-
- GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(NULL), owner(NULL) { }
- bool initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info);
+public:
+ virtual bool IsSpawned() const { return false; }
+ virtual uint32 GetDisplayId() const { return 0; }
+ virtual uint32 GetPhaseMask() const { return 0; }
+ virtual G3D::Vector3 GetPosition() const { return G3D::Vector3::zero(); }
+ virtual float GetOrientation() const { return 0.0f; }
+ virtual float GetScale() const { return 1.0f; }
+ virtual void DebugVisualizeCorner(G3D::Vector3 const& /*corner*/) const { }
+};
+class GameObjectModel /*, public Intersectable*/
+{
+ GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(NULL) { }
public:
std::string name;
@@ -66,9 +67,21 @@ public:
bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const;
- static GameObjectModel* Create(const GameObject& go);
+ static GameObjectModel* Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
bool UpdatePosition();
+
+private:
+ bool initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
+
+ uint32 phasemask;
+ G3D::AABox iBound;
+ G3D::Matrix3 iInvRot;
+ G3D::Vector3 iPos;
+ float iInvScale;
+ float iScale;
+ VMAP::WorldModel* iModel;
+ std::unique_ptr<GameObjectModelOwnerBase> owner;
};
#endif // _GAMEOBJECT_MODEL_H
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index d1e3d8a82af..bb0d1c79b1e 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -226,7 +226,7 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map* map, uint32 phaseMa
SetDisplayId(goinfo->displayId);
- m_model = GameObjectModel::Create(*this);
+ m_model = CreateModel();
// GAMEOBJECT_BYTES_1, index at 0, 1, 2 and 3
SetGoType(GameobjectTypes(goinfo->type));
SetGoState(go_state);
@@ -2128,7 +2128,7 @@ void GameObject::UpdateModel()
if (GetMap()->ContainsGameObjectModel(*m_model))
GetMap()->RemoveGameObjectModel(*m_model);
delete m_model;
- m_model = GameObjectModel::Create(*this);
+ m_model = CreateModel();
if (m_model)
GetMap()->InsertGameObjectModel(*m_model);
}
@@ -2321,3 +2321,25 @@ void GameObject::UpdateModelPosition()
GetMap()->InsertGameObjectModel(*m_model);
}
}
+
+class GameObjectModelOwnerImpl : public GameObjectModelOwnerBase
+{
+public:
+ explicit GameObjectModelOwnerImpl(GameObject const* owner) : _owner(owner) { }
+
+ virtual bool IsSpawned() const override { return _owner->isSpawned(); }
+ virtual uint32 GetDisplayId() const override { return _owner->GetDisplayId(); }
+ virtual uint32 GetPhaseMask() const override { return _owner->GetPhaseMask(); }
+ virtual G3D::Vector3 GetPosition() const override { return G3D::Vector3(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); }
+ virtual float GetOrientation() const override { return _owner->GetOrientation(); }
+ virtual float GetScale() const override { return _owner->GetObjectScale(); }
+ virtual void DebugVisualizeCorner(G3D::Vector3 const& corner) const override { _owner->SummonCreature(1, corner.x, corner.y, corner.z, 0, TEMPSUMMON_MANUAL_DESPAWN); }
+
+private:
+ GameObject const* _owner;
+};
+
+GameObjectModel* GameObject::CreateModel()
+{
+ return GameObjectModel::Create(Trinity::make_unique<GameObjectModelOwnerImpl>(this), sWorld->GetDataPath());
+}
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 9da4afd7957..7ef8ef2737d 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -850,6 +850,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Map
protected:
bool AIM_Initialize();
+ GameObjectModel* CreateModel();
void UpdateModel(); // updates model in case displayId were changed
uint32 m_spellId;
time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp
index 6d98a4c78b2..d6a130c0317 100644
--- a/src/server/game/Entities/Transport/Transport.cpp
+++ b/src/server/game/Entities/Transport/Transport.cpp
@@ -94,7 +94,7 @@ bool Transport::Create(uint32 guidlow, uint32 entry, uint32 mapid, float x, floa
SetName(goinfo->name);
UpdateRotationFields(0.0f, 1.0f);
- m_model = GameObjectModel::Create(*this);
+ m_model = CreateModel();
return true;
}
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index fc79f351a54..9c4cb1002c7 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -1299,7 +1299,7 @@ void World::LoadConfigSettings(bool reload)
sScriptMgr->OnConfigLoad(reload);
}
-extern void LoadGameObjectModelList();
+extern void LoadGameObjectModelList(std::string const& dataPath);
/// Initialize the World
void World::SetInitialWorldSettings()
@@ -1399,7 +1399,7 @@ void World::SetInitialWorldSettings()
sSpellMgr->LoadSpellInfoCustomAttributes();
TC_LOG_INFO("server.loading", "Loading GameObject models...");
- LoadGameObjectModelList();
+ LoadGameObjectModelList(m_dataPath);
TC_LOG_INFO("server.loading", "Loading Script Names...");
sObjectMgr->LoadScriptNames();