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);
76 return intersectionCallBack.
result;
80 : iMapID(mapID), iBasePath(basePath)
98 float distance = pMaxDist;
101 if (intersectionCallBack.
didHit())
103 return intersectionCallBack.
didHit();
109 float maxDist = (pos2 - pos1).magnitude();
111 if (maxDist == std::numeric_limits<float>::max() || !std::isfinite(maxDist))
115 ASSERT(maxDist < std::numeric_limits<float>::max());
117 if (maxDist < 1e-10f)
120 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
135 float maxDist = (pPos2 - pPos1).magnitude();
137 ASSERT(maxDist < std::numeric_limits<float>::max());
139 if (maxDist < 1e-10f)
141 pResultHitPos = pPos2;
144 Vector3 dir = (pPos2 - pPos1) / maxDist;
145 G3D::Ray ray(pPos1, dir);
146 float dist = maxDist;
149 pResultHitPos = pPos1 + dir * dist;
152 if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
154 pResultHitPos = pResultHitPos + dir * pModifyDist;
158 pResultHitPos = pPos1;
163 pResultHitPos = pResultHitPos + dir * pModifyDist;
169 pResultHitPos = pPos2;
179 float height = G3D::finf();
180 Vector3 dir = Vector3(0, 0, -1);
181 G3D::Ray ray(pPos, dir);
182 float maxDist = maxSearchDist;
185 height = pPos.z - maxDist;
192 using FileDeleter =
decltype(Trinity::unique_ptr_deleter<FILE*, &::fclose>());
206 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
212 while (parentMapId != -1)
215 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
230 std::string basePath = vmapPath;
231 if (!basePath.empty() && basePath.back() !=
'/' && basePath.back() !=
'\\')
232 basePath.push_back(
'/');
236 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
258 TC_LOG_DEBUG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '{}'", fname);
259 std::string fullname =
iBasePath + fname;
260 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
269 if (!
readChunk(rf.get(), chunk,
"NODE", 4)
292 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [{}, {}]", tileX, tileY);
311 uint32 numSpawnIndices = 0;
314 if (numSpawns != numSpawnIndices)
316 tileReferenceVals.reserve(numSpawns);
327 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element (spawn {}) referenced in tile {} by map {}", spawn.
ID, fileResult.
Name,
iMapID);
334 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedVal,
iTreeValues.size(), fileResult.
Name);
346 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [{}, {}]", tileX, tileY);
356 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
358 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID={}", spawn.
ID);
362 tileReferenceVals.push_back(referencedVal);
366 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : cannot read model from file (spawn index {}) referenced in tile {} by map {}", i, fileResult.
Name,
iMapID);
384 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:{} X:{} Y:{}",
iMapID, tileX, tileY);
388 for (
uint32 referencedVal : tile.mapped())
392 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model ID: {} - Map:{} X:{} Y:{}",
397 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)
LocationInfoCallback(ModelInstance const *val, LocationInfo &info)
ModelInstance const * prims
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)
bool GetLocationInfo(G3D::Vector3 const &pos, LocationInfo &info) const
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 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)
decltype(Trinity::unique_ptr_deleter< FILE *, &::fclose >()) FileDeleter
std::unique_ptr< FILE, FileDeleter > TileFile
std::unique_ptr< FILE, FileDeleter > SpawnIndicesFile