Skip to content

Commit

Permalink
Improve ".debug los check" command (#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamemechanicwow authored Dec 4, 2023
1 parent faaccc2 commit b772fc4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/game/Commands/DebugCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
// VMAPS
#include "VMapFactory.h"
#include "ModelInstance.h"
#include "GameObjectModel.h"
// MMAPS
#include "MoveMap.h" // for mmap manager
#include "PathFinder.h" // for mmap commands
Expand Down Expand Up @@ -1657,9 +1658,17 @@ bool ChatHandler::HandleDebugLoSCommand(char*)
VMAP::ModelInstance* spawn = m_session->GetPlayer()->GetMap()->FindCollisionModel(x0, y0, z0, x1, y1, z1);

if (!spawn)
SendSysMessage("* No collision found.");
SendSysMessage("* No collision with static objects found.");
else
PSendSysMessage("* Collision at '%s' [%f %f %f]", spawn->name.c_str(), spawn->iPos.x, spawn->iPos.y, spawn->iPos.z);
PSendSysMessage("* Collision with static object at '%s' [%f %f %f]", spawn->name.c_str(), spawn->iPos.x, spawn->iPos.y, spawn->iPos.z);

GameObjectModel const* dynObj = m_session->GetPlayer()->GetMap()->FindDynamicObjectCollisionModel(x0, y0, z0, x1, y1, z1);

if (!dynObj)
SendSysMessage("* No collision with dynamic objects found.");
else
PSendSysMessage("* Collision with dynamic object at '%s' [%f %f %f]", dynObj->name.c_str(), dynObj->getPosition().x, dynObj->getPosition().y, dynObj->getPosition().z);

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,16 @@ VMAP::ModelInstance* Map::FindCollisionModel(float x1, float y1, float z1, float
return VMAP::VMapFactory::createOrGetVMapManager()->FindCollisionModel(GetId(), x1, y1, z1, x2, y2, z2);
}

GameObjectModel const* Map::FindDynamicObjectCollisionModel(float x1, float y1, float z1, float x2, float y2, float z2)
{
ASSERT(MaNGOS::IsValidMapCoord(x1, y1, z1));
ASSERT(MaNGOS::IsValidMapCoord(x2, y2, z2));
Vector3 const pos1 = Vector3(x1, y1, z1);
Vector3 const pos2 = Vector3(x2, y2, z2);
std::shared_lock<std::shared_timed_mutex> lock(_dynamicTree_lock);
return _dynamicTree.getObjectHit(pos1, pos2);
}

void Map::RemoveGameObjectModel(const GameObjectModel &model)
{
std::lock_guard<std::shared_timed_mutex> lock(_dynamicTree_lock);
Expand Down
1 change: 1 addition & 0 deletions src/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ class Map : public GridRefManager<NGridType>
bool GetWalkRandomPosition(GenericTransport* t, float &x, float &y, float &z, float maxRadius, uint32 moveAllowedFlags = 0xF) const;
bool GetSwimRandomPosition(float& x, float& y, float& z, float radius, GridMapLiquidData& liquid_status, bool randomRange = true) const;
VMAP::ModelInstance* FindCollisionModel(float x1, float y1, float z1, float x2, float y2, float z2);
GameObjectModel const* FindDynamicObjectCollisionModel(float x1, float y1, float z1, float x2, float y2, float z2);

void Balance() { _dynamicTree.balance(); }
void RemoveGameObjectModel(const GameObjectModel& model);
Expand Down
31 changes: 31 additions & 0 deletions src/game/vmap/DynamicTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ struct DynamicTreeIntersectionCallback_WithLogger
bool didHit() const { return did_hit; }
};

struct DynamicTreeIntersectionCallback_findCollisionObject
{
bool did_hit;
GameObjectModel const* hitObj;
DynamicTreeIntersectionCallback_findCollisionObject() : did_hit(false), hitObj(nullptr) {}
bool operator()(G3D::Ray const &r, GameObjectModel const &obj, float& distance, bool stopAtFirst, bool ignoreM2Model)
{
bool hit = obj.intersectRay(r, distance, stopAtFirst, ignoreM2Model);
if (hit)
{
hitObj = &obj;
did_hit = true;
}
return did_hit;
}
bool didHit() const { return did_hit; }
};

//=========================================================
/**
If intersection is found within pMaxDist, sets pMaxDist to intersection distance and returns true.
Expand Down Expand Up @@ -282,3 +300,16 @@ float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist)
return v.z - maxSearchDist;
return -G3D::inf();
}

GameObjectModel const* DynamicMapTree::getObjectHit(Vector3 const& pPos1, Vector3 const& pPos2) const
{
float distance = (pPos2 - pPos1).magnitude();
Vector3 const dir = (pPos2 - pPos1) / distance;
G3D::Ray const ray(pPos1, dir);

DynamicTreeIntersectionCallback_findCollisionObject callback;
impl.intersectRay(ray, callback, distance, pPos2, false);
if (callback.hitObj)
return callback.hitObj;
return nullptr;
}
1 change: 1 addition & 0 deletions src/game/vmap/DynamicTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DynamicMapTree
bool getIntersectionTime(G3D::Ray const& ray, G3D::Vector3 const& endPos, float& maxDist) const;
bool getObjectHitPos(G3D::Vector3 const& pPos1, G3D::Vector3 const& pPos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
bool getObjectHitPos(float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float pModifyDist) const;
GameObjectModel const* getObjectHit(G3D::Vector3 const& pPos1, G3D::Vector3 const& pPos2) const;
float getHeight(float x, float y, float z, float maxSearchDist) const;

void insert(GameObjectModel const&);
Expand Down

0 comments on commit b772fc4

Please sign in to comment.