39 bool operator()(
const G3D::Ray& ray,
uint32 entry,
float& distance,
bool pStopAtFirstHit =
true)
60 TC_LOG_DEBUG(
"maps",
"LocationInfoCallback: trying to intersect '{}'",
prims[entry].name);
75 std::stringstream tilefilename;
76 tilefilename.fill(
'0');
77 tilefilename << std::setw(4) << mapID <<
'_';
79 tilefilename << std::setw(2) << tileY <<
'_' << std::setw(2) << tileX <<
".vmtile";
80 return tilefilename.str();
87 return intersectionCallBack.
result;
91 : iMapID(mapID), iTreeValues(nullptr), iNTreeValues(0), iBasePath(basePath)
114 float distance = pMaxDist;
117 if (intersectionCallBack.
didHit())
119 return intersectionCallBack.
didHit();
125 float maxDist = (pos2 - pos1).magnitude();
127 if (maxDist == std::numeric_limits<float>::max() || !std::isfinite(maxDist))
131 ASSERT(maxDist < std::numeric_limits<float>::max());
133 if (maxDist < 1e-10f)
136 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
151 float maxDist = (pPos2 - pPos1).magnitude();
153 ASSERT(maxDist < std::numeric_limits<float>::max());
155 if (maxDist < 1e-10f)
157 pResultHitPos = pPos2;
160 Vector3 dir = (pPos2 - pPos1) / maxDist;
161 G3D::Ray ray(pPos1, dir);
162 float dist = maxDist;
165 pResultHitPos = pPos1 + dir * dist;
168 if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
170 pResultHitPos = pResultHitPos + dir * pModifyDist;
174 pResultHitPos = pPos1;
179 pResultHitPos = pResultHitPos + dir * pModifyDist;
185 pResultHitPos = pPos2;
195 float height = G3D::finf();
196 Vector3 dir = Vector3(0, 0, -1);
197 G3D::Ray ray(pPos, dir);
198 float maxDist = maxSearchDist;
201 height = pPos.z - maxDist;
210 result.
File = fopen(result.
Name.c_str(),
"rb");
215 while (parentMapId != -1)
218 result.
File = fopen(result.
Name.c_str(),
"rb");
233 std::string basePath = vmapPath;
234 if (basePath.length() > 0 && basePath[basePath.length() - 1] !=
'/' && basePath[basePath.length() - 1] !=
'\\')
235 basePath.push_back(
'/');
240 FILE* rf = fopen(fullname.c_str(),
"rb");
258 std::string tilefile = basePath +
getTileFileName(mapID, tileX, tileY);
259 FILE* tf = fopen(tilefile.c_str(),
"rb");
277 TC_LOG_DEBUG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '{}'", fname);
278 std::string fullname =
iBasePath + fname;
279 FILE* rf = fopen(fullname.c_str(),
"rb");
301 uint32 spawnIndicesSize = 0;
307 if (fread(&spawnId,
sizeof(
uint32), 1, rf) == 1)
322 for (std::pair<uint32 const, uint32>& iLoadedSpawn :
iLoadedSpawns)
324 for (
uint32 refCount = 0; refCount < iLoadedSpawn.second; ++refCount)
339 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [{}, {}]", tileX, tileY);
364 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [{}, {}]", tileX, tileY);
370 uint32 referencedVal = spawnIndex->second;
375 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedVal,
iNTreeValues, fileResult.
Name);
387 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
389 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID={}", spawn.
ID);
398 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element (spawn {}) referenced in tile {} by map {}", spawn.
ID, fileResult.
Name,
iMapID);
404 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : cannot read model from file (spawn index {}) referenced in tile {} by map {}", i, fileResult.
Name,
iMapID);
409 fclose(fileResult.
File);
414 "Map: " + std::to_string(
iMapID) +
" TileX: " + std::to_string(tileX) +
" TileY: " + std::to_string(tileY));
423 loadedTileMap::iterator tile =
iLoadedTiles.find(tileID);
426 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:{} X:{} Y:{}",
iMapID, tileX, tileY);
439 if (fread(&numSpawns,
sizeof(
uint32), 1, fileResult.
File) != 1)
441 for (
uint32 i = 0; i < numSpawns && result; ++i)
455 uint32 referencedNode = spawnIndex->second;
457 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '{}' (ID:{})", spawn.
name, spawn.
ID);
468 fclose(fileResult.
File);
473 "Map: " + std::to_string(
iMapID) +
" TileX: " + std::to_string(tileX) +
" TileY: " + std::to_string(tileY));
#define TC_LOG_DEBUG(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
#define TC_METRIC_EVENT(category, title, description)
bool readFromFile(FILE *rf)
void intersectPoint(const G3D::Vector3 &p, IsectCallback &intersectCallback) const
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirst=false) const
LocationInfoCallback(ModelInstance *val, LocationInfo &info)
void operator()(Vector3 const &point, uint32 entry)
MapRayCallback(ModelInstance *val, ModelIgnoreFlags ignoreFlags)
bool operator()(const G3D::Ray &ray, uint32 entry, float &distance, bool pStopAtFirstHit=true)
WorldModel const * getWorldModel() const
bool intersectRay(G3D::Ray const &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
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)
static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY)
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
ModelInstance * iTreeValues
LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm)
std::unordered_map< uint32, uint32 > iSpawnIndices
loadedTileMap iLoadedTiles
static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2 *vm)
loadedSpawnMap iLoadedSpawns
static TileFileOpenResult OpenMapTileFile(std::string const &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
void UnloadMap(VMapManager2 *vm)
int32 getParentMapId(uint32 mapId) const
void releaseModelInstance(std::string const &filename)
static std::string getMapFileName(unsigned int mapId)
WorldModel * acquireModelInstance(std::string const &basepath, std::string const &filename)
std::string const & GetName() const
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
static bool readFromFile(FILE *rf, ModelSpawn &spawn)