38 bool operator()(
const G3D::Ray& ray,
uint32 entry,
float& distance,
bool pStopAtFirstHit =
true)
59 TC_LOG_DEBUG(
"maps",
"LocationInfoCallback: trying to intersect '{}'",
prims[entry].name);
81 return intersectionCallBack.
result;
85 : iMapID(mapID), iBasePath(basePath)
105 float distance = pMaxDist;
108 if (intersectionCallBack.
didHit())
110 return intersectionCallBack.
didHit();
116 float maxDist = (pos2 - pos1).magnitude();
118 if (maxDist == std::numeric_limits<float>::max() || !std::isfinite(maxDist))
122 ASSERT(maxDist < std::numeric_limits<float>::max());
124 if (maxDist < 1e-10f)
127 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
142 float maxDist = (pPos2 - pPos1).magnitude();
144 ASSERT(maxDist < std::numeric_limits<float>::max());
146 if (maxDist < 1e-10f)
148 pResultHitPos = pPos2;
151 Vector3 dir = (pPos2 - pPos1) / maxDist;
152 G3D::Ray ray(pPos1, dir);
153 float dist = maxDist;
156 pResultHitPos = pPos1 + dir * dist;
159 if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
161 pResultHitPos = pResultHitPos + dir * pModifyDist;
165 pResultHitPos = pPos1;
170 pResultHitPos = pResultHitPos + dir * pModifyDist;
176 pResultHitPos = pPos2;
186 float height = G3D::finf();
187 Vector3 dir = Vector3(0, 0, -1);
188 G3D::Ray ray(pPos, dir);
189 float maxDist = maxSearchDist;
192 height = pPos.z - maxDist;
199 using FileDeleter =
decltype(Trinity::unique_ptr_deleter<FILE*, &::fclose>());
213 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
219 while (parentMapId != -1)
222 result.
TileFile.reset(fopen(result.
Name.c_str(),
"rb"));
237 std::string basePath = vmapPath;
238 if (basePath.length() > 0 && basePath[basePath.length() - 1] !=
'/' && basePath[basePath.length() - 1] !=
'\\')
239 basePath.push_back(
'/');
242 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
264 TC_LOG_DEBUG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '{}'", fname);
265 std::string fullname =
iBasePath + fname;
266 auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(),
"rb"));
275 if (!
readChunk(rf.get(), chunk,
"NODE", 4)
298 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [{}, {}]", tileX, tileY);
316 uint32 numSpawnIndices = 0;
319 if (numSpawns != numSpawnIndices)
330 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [{}, {}]", tileX, tileY);
336 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element (spawn {}) referenced in tile {} by map {}", spawn.
ID, fileResult.
Name,
iMapID);
343 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedVal,
iTreeValues.size(), fileResult.
Name);
354 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
356 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID={}", spawn.
ID);
363 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : cannot read model from file (spawn index {}) referenced in tile {} by map {}", i, fileResult.
Name,
iMapID);
372 "Map: " + std::to_string(
iMapID) +
" TileX: " + std::to_string(tileX) +
" TileY: " + std::to_string(tileY));
381 loadedTileMap::iterator tile =
iLoadedTiles.find(tileID);
384 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:{} X:{} Y:{}",
iMapID, tileX, tileY);
397 if (fread(&numSpawns,
sizeof(
uint32), 1, fileResult.
TileFile.get()) != 1)
399 uint32 numSpawnIndices = 0;
402 if (numSpawns != numSpawnIndices)
404 for (
uint32 i = 0; i < numSpawns && result; ++i)
412 uint32 referencedNode = 0;
415 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element (spawn {}) referenced in tile {} by map {}", spawn.
ID, fileResult.
Name,
iMapID);
422 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedNode,
iTreeValues.size(), fileResult.
Name);
428 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '{}' (ID:{})", spawn.
name, spawn.
ID);
429 else if (!
iTreeValues[referencedNode].RemoveTileReference())
436 "Map: " + std::to_string(
iMapID) +
" TileX: " + std::to_string(tileX) +
" TileY: " + std::to_string(tileY));
#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)
MapRayCallback(ModelInstance const *val, ModelIgnoreFlags ignoreFlags)
bool operator()(const G3D::Ray &ray, uint32 entry, float &distance, bool pStopAtFirstHit=true)
ModelInstance const * prims
bool intersectRay(G3D::Ray const &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
std::vector< ModelInstance > iTreeValues
StaticMapTree(uint32 mapID, const std::string &basePath)
~StaticMapTree()
Make sure to call unloadMap() to unregister acquired model references before destroying.
void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm)
bool getObjectHitPos(const G3D::Vector3 &pos1, const G3D::Vector3 &pos2, G3D::Vector3 &pResultHitPos, float pModifyDist) const
static uint32 packTileID(uint32 tileX, uint32 tileY)
LoadResult InitMap(std::string const &fname)
bool getIntersectionTime(const G3D::Ray &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm)
loadedTileMap iLoadedTiles
static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2 *vm)
void getModelInstances(ModelInstance *&models, uint32 &count)
bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const
bool isInLineOfSight(const G3D::Vector3 &pos1, const G3D::Vector3 &pos2, ModelIgnoreFlags ignoreFlags) const
float getHeight(const G3D::Vector3 &pPos, float maxSearchDist) const
int32 getParentMapId(uint32 mapId) const
std::shared_ptr< WorldModel > acquireModelInstance(std::string const &basepath, std::string const &filename)
static std::string getMapFileName(unsigned int mapId)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
TileFileOpenResult OpenMapTileFile(std::string const &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2 *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