38 bool operator()(G3D::Ray
const& ray,
uint32 entry,
float& distance,
bool pStopAtFirstHit =
true)
59 TC_LOG_DEBUG(
"maps",
"LocationInfoCallback: trying to intersect '{}'",
prims[entry].name);
79 : iMapID(mapID), iBasePath(basePath)
97 float distance = pMaxDist;
100 if (intersectionCallBack.
didHit())
102 return intersectionCallBack.
didHit();
108 float maxDist = (pos2 - pos1).magnitude();
110 if (maxDist == std::numeric_limits<float>::max() || !std::isfinite(maxDist))
114 ASSERT(maxDist < std::numeric_limits<float>::max());
116 if (maxDist < 1e-10f)
119 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
134 float maxDist = (pPos2 - pPos1).magnitude();
136 ASSERT(maxDist < std::numeric_limits<float>::max());
138 if (maxDist < 1e-10f)
140 pResultHitPos = pPos2;
143 Vector3 dir = (pPos2 - pPos1) / maxDist;
144 G3D::Ray ray(pPos1, dir);
145 float dist = maxDist;
148 pResultHitPos = pPos1 + dir * dist;
151 if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
153 pResultHitPos = pResultHitPos + dir * pModifyDist;
157 pResultHitPos = pPos1;
162 pResultHitPos = pResultHitPos + dir * pModifyDist;
168 pResultHitPos = pPos2;
178 float height = G3D::finf();
179 Vector3 dir = Vector3(0, 0, -1);
180 G3D::Ray ray(pPos, dir);
181 float maxDist = maxSearchDist;
184 height = pPos.z - maxDist;
191 using FileDeleter =
decltype(Trinity::unique_ptr_deleter<FILE*, &::fclose>());
205 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
211 while (parentMapId != -1)
214 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
229 std::string basePath = vmapPath;
230 if (!basePath.empty() && basePath.back() !=
'/' && basePath.back() !=
'\\')
231 basePath.push_back(
'/');
235 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
257 TC_LOG_DEBUG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '{}'", fname);
258 std::string fullname =
iBasePath + fname;
259 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
268 if (!
readChunk(rf.get(), chunk,
"NODE", 4)
291 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [{}, {}]", tileX, tileY);
310 uint32 numSpawnIndices = 0;
313 if (numSpawns != numSpawnIndices)
315 tileReferenceVals.reserve(numSpawns);
326 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element (spawn {}) referenced in tile {} by map {}", spawn.
ID, fileResult.
Name,
iMapID);
333 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedVal,
iTreeValues.size(), fileResult.
Name);
345 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [{}, {}]", tileX, tileY);
355 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
357 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID={}", spawn.
ID);
361 tileReferenceVals.push_back(referencedVal);
365 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : cannot read model from file (spawn index {}) referenced in tile {} by map {}", i, fileResult.
Name,
iMapID);
383 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:{} X:{} Y:{}",
iMapID, tileX, tileY);
387 for (
uint32 referencedVal : tile.mapped())
391 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model ID: {} - Map:{} X:{} Y:{}",
396 if (!
iTreeValues[referencedVal].RemoveTileReference())
#define TC_LOG_DEBUG(filterType__, message__,...)
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_METRIC_EVENT(category, title, description)
void intersectPoint(G3D::Vector3 const &p, IsectCallback &intersectCallback) const
void intersectRay(G3D::Ray const &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirst=false) const
bool readFromFile(FILE *rf)
StaticMapTreeLocationInfo & locInfo
ModelInstance const * prims
LocationInfoCallback(ModelInstance const *val, StaticMapTreeLocationInfo &info)
void operator()(Vector3 const &point, uint32 entry)
bool operator()(G3D::Ray const &ray, uint32 entry, float &distance, bool pStopAtFirstHit=true)
MapRayCallback(ModelInstance const *val, ModelIgnoreFlags ignoreFlags)
ModelInstance const * prims
bool intersectRay(G3D::Ray const &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
void UnloadMapTile(uint32 tileX, uint32 tileY)
std::vector< ModelInstance > iTreeValues
~StaticMapTree()
Make sure to call unloadMap() to unregister acquired model references before destroying.
std::span< ModelInstance const > getModelInstances() const
static uint32 packTileID(uint32 tileX, uint32 tileY)
LoadResult InitMap(std::string const &fname)
StaticMapTree(uint32 mapID, std::string const &basePath)
loadedTileMap iLoadedTiles
LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager *vm)
bool getIntersectionTime(G3D::Ray const &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
float getHeight(G3D::Vector3 const &pPos, float maxSearchDist) const
static LoadResult CanLoadMap(std::string const &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager *vm)
bool isInLineOfSight(G3D::Vector3 const &pos1, G3D::Vector3 const &pos2, ModelIgnoreFlags ignoreFlags) const
bool GetLocationInfo(G3D::Vector3 const &pos, StaticMapTreeLocationInfo &info) const
bool getObjectHitPos(G3D::Vector3 const &pos1, G3D::Vector3 const &pos2, G3D::Vector3 &pResultHitPos, float pModifyDist) const
static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
std::shared_ptr< WorldModel > acquireModelInstance(std::string const &basepath, std::string const &filename)
int32 getParentMapId(uint32 mapId) const
static std::string getMapFileName(uint32 mapId)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
TileFileOpenResult OpenMapTileFile(std::string const &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager *vm)
static bool readFromFile(FILE *rf, ModelSpawn &spawn)
ModelInstance const * hitInstance
decltype(Trinity::unique_ptr_deleter< FILE *, &::fclose >()) FileDeleter
std::unique_ptr< FILE, FileDeleter > TileFile
std::unique_ptr< FILE, FileDeleter > SpawnIndicesFile