Core/MMaps: Implemented dynamic mmap tile rebuilding for destructible objects

This commit is contained in:
Shauren
2025-11-06 19:42:17 +01:00
parent 556505d59a
commit 6a767c3bd6
10 changed files with 564 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ int CHECK_TREE_PERIOD = 200;
} // namespace
template<> struct PositionTrait< GameObjectModel> {
static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.getPosition(); }
static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.GetPosition(); }
};
template<> struct BoundsTrait< GameObjectModel> {

View File

@@ -21,15 +21,11 @@
#include "Define.h"
#include <G3D/AABox.h>
#include <G3D/Matrix3.h>
#include <G3D/Quat.h>
#include <G3D/Ray.h>
#include <G3D/Vector3.h>
#include <memory>
namespace G3D
{
class Quat;
}
namespace VMAP
{
class WorldModel;
@@ -53,25 +49,33 @@ public:
virtual bool IsInPhase(PhaseShift const& /*phaseShift*/) const = 0;
virtual G3D::Vector3 GetPosition() const = 0;
virtual G3D::Quat GetRotation() const = 0;
virtual int64 GetPackedRotation() const = 0;
virtual float GetScale() const = 0;
virtual void DebugVisualizeCorner(G3D::Vector3 const& /*corner*/) const = 0;
};
class TC_COMMON_API GameObjectModel /*, public Intersectable*/
{
GameObjectModel() : iCollisionEnabled(false), iLosBlockingDisabled(false), iInvScale(0), iScale(0), iModel(nullptr) { }
GameObjectModel() : iCollisionEnabled(false), iLosBlockingDisabled(false), iIncludeInNavMesh(false), iInvScale(0), iScale(0), iModel(nullptr) { }
public:
const G3D::AABox& getBounds() const { return iBound; }
~GameObjectModel();
const G3D::Vector3& getPosition() const { return iPos;}
uint32 GetDisplayId() const { return owner->GetDisplayId(); }
G3D::Vector3 const& GetPosition() const { return iPos; }
G3D::Quat GetRotation() const { return owner->GetRotation(); }
G3D::Matrix3 const& GetInvRot() const { return iInvRot; }
int64 GetPackedRotation() const { return owner->GetPackedRotation(); }
float GetScale() const { return iScale; }
/* Enables/disables collision */
void EnableCollision(bool enable) { iCollisionEnabled = enable; }
bool IsCollisionEnabled() const { return iCollisionEnabled; }
void DisableLosBlocking(bool enable) { iLosBlockingDisabled = enable; }
bool IsLosBlockingDisabled() const { return iLosBlockingDisabled; }
void IncludeInNavMesh(bool enable) { iIncludeInNavMesh = enable; }
bool IsIncludedInNavMesh() const { return iIncludeInNavMesh; }
bool IsMapObject() const;
uint8 GetNameSetId() const { return owner->GetNameSetId(); }
@@ -83,11 +87,14 @@ public:
bool UpdatePosition();
std::shared_ptr<VMAP::WorldModel const> GetWorldModel() const { return iModel; }
private:
bool initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
bool iCollisionEnabled; ///< Is model ignored in all checks
bool iLosBlockingDisabled; ///< Is model ignored during line of sight checks (but is always included in location/height checks)
bool iIncludeInNavMesh; ///< Is model included when generating navigation mesh
G3D::AABox iBound;
G3D::Matrix3 iInvRot;
G3D::Vector3 iPos;

View File

@@ -210,6 +210,13 @@ public:
if (Node* node = nodes[cell.x][cell.y].get())
node->intersectRay(ray, intersectCallback, max_dist);
}
std::span<T const* const> getObjects(int x, int y) const
{
if (Node* n = nodes[x][y].get())
return n->getObjects();
return {};
}
};
#undef CELL_SIZE

View File

@@ -50,8 +50,21 @@ namespace MMAP
// we have to use single dtNavMeshQuery for every instance, since those are not thread safe
NavMeshQuerySet navMeshQueries; // instanceId to query
static uint32 GetInstanceIdForMeshLookup([[maybe_unused]] uint32 mapId, [[maybe_unused]] uint32 instanceId)
static uint32 GetInstanceIdForMeshLookup(uint32 mapId, uint32 instanceId)
{
switch (mapId)
{
case 0: case 1: case 571: case 603: case 607: case 609: case 616: case 628: case 631: case 644: case 649: case 720:
case 732: case 754: case 755: case 861: case 938: case 940: case 962: case 967: case 1064: case 1076: case 1098:
case 1122: case 1126: case 1182: case 1205: case 1220: case 1265: case 1492: case 1523: case 1530: case 1579: case 1676:
case 1704: case 1705: case 1706: case 1707: case 1734: case 1756: case 1943: case 2076: case 2118: case 2160: case 2161:
case 2187: case 2212: case 2235: case 2237: case 2264: case 2450: case 2512: case 2586: case 2601: case 2654: case 2657:
case 2660: case 2669: case 2819: case 2828:
return instanceId;
default:
break;
}
// for maps that won't have dynamic mesh, return 0 to reuse the same mesh across all instances
return 0;
}
@@ -103,6 +116,11 @@ namespace MMAP
return itr;
}
bool MMapManager::isRebuildingTilesEnabledOnMap(uint32 mapId)
{
return MMapData::GetInstanceIdForMeshLookup(mapId, 1) != 0;
}
LoadResult MMapManager::loadMapData(std::string_view basePath, uint32 mapId, uint32 instanceId)
{
// we already have this map loaded?
@@ -441,7 +459,7 @@ namespace MMAP
TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Unloaded mapId {:04} instanceId {}", instanceMapId, instanceId);
}
dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId, uint32 instanceId)
dtNavMesh* MMapManager::GetNavMesh(uint32 mapId, uint32 instanceId)
{
MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())

View File

@@ -67,10 +67,13 @@ namespace MMAP
// the returned [dtNavMeshQuery const*] is NOT threadsafe
dtNavMeshQuery const* GetNavMeshQuery(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
dtNavMesh const* GetNavMesh(uint32 mapId, uint32 instanceId);
dtNavMesh* GetNavMesh(uint32 mapId, uint32 instanceId);
uint32 getLoadedTilesCount() const { return loadedTiles; }
uint32 getLoadedMapsCount() const { return uint32(loadedMMaps.size()); }
static bool isRebuildingTilesEnabledOnMap(uint32 mapId);
private:
LoadResult loadMapData(std::string_view basePath, uint32 mapId, uint32 instanceId);
uint32 packTileID(int32 x, int32 y);