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(3) << mapID <<
'_';
79 tilefilename << std::setw(2) << tileY <<
'_' << std::setw(2) << tileX <<
".vmtile";
80 return tilefilename.str();
87 return intersectionCallBack.
result;
91 iMapID(mapID), iIsTiled(false), iTreeValues(nullptr),
92 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;
209 std::string basePath = vmapPath;
210 if (basePath.length() > 0 && basePath[basePath.length()-1] !=
'/' && basePath[basePath.length()-1] !=
'\\')
211 basePath.push_back(
'/');
216 FILE* rf = fopen(fullname.c_str(),
"rb");
229 std::string tilefile = basePath +
getTileFileName(mapID, tileX, tileY);
230 FILE* tf = fopen(tilefile.c_str(),
"rb");
248 TC_LOG_DEBUG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '{}'", fname);
249 bool success =
false;
250 std::string fullname =
iBasePath + fname;
251 FILE* rf = fopen(fullname.c_str(),
"rb");
263 success =
readChunk(rf, chunk,
"GOBJ", 4);
287 TC_LOG_ERROR(
"misc",
"StaticMapTree::InitMap() : could not acquire WorldModel pointer for '{}'", spawn.
name);
299 for (std::pair<uint32 const, uint32>& iLoadedSpawn :
iLoadedSpawns)
302 for (
uint32 refCount = 0; refCount < iLoadedSpawn.second; ++refCount)
322 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [{}, {}]", tileX, tileY);
328 FILE* tf = fopen(tilefile.c_str(),
"rb");
336 if (result && fread(&numSpawns,
sizeof(
uint32), 1, tf) != 1)
338 for (
uint32 i=0; i<numSpawns && result; ++i)
348 TC_LOG_ERROR(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [{}, {}]", tileX, tileY);
353 if (fread(&referencedVal,
sizeof(
uint32), 1, tf) == 1)
359 TC_LOG_ERROR(
"maps",
"StaticMapTree::LoadMapTile() : invalid tree element ({}/{}) referenced in tile {}", referencedVal,
iNTreeValues, tilefile);
371 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
373 TC_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID={}", spawn.
ID);
387 "Map: " + std::to_string(
iMapID) +
" TileX: " + std::to_string(tileX) +
" TileY: " + std::to_string(tileY));
396 loadedTileMap::iterator tile =
iLoadedTiles.find(tileID);
399 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:{} X:{} Y:{}",
iMapID, tileX, tileY);
405 FILE* tf = fopen(tilefile.c_str(),
"rb");
413 if (fread(&numSpawns,
sizeof(
uint32), 1, tf) != 1)
415 for (
uint32 i=0; i<numSpawns && result; ++i)
428 if (fread(&referencedNode,
sizeof(
uint32), 1, tf) != 1)
433 TC_LOG_ERROR(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '{}' (ID:{})", spawn.
name, spawn.
ID);
447 "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)
bool intersectRay(G3D::Ray const &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
static bool readFromFile(FILE *rf, ModelSpawn &spawn)
static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
StaticMapTree(uint32 mapID, const std::string &basePath)
bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm)
~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)
bool getIntersectionTime(const G3D::Ray &pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
ModelInstance * iTreeValues
loadedTileMap iLoadedTiles
loadedSpawnMap iLoadedSpawns
bool InitMap(const std::string &fname, 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)
void releaseModelInstance(const std::string &filename)
WorldModel * acquireModelInstance(const std::string &basepath, const std::string &filename, uint32 flags=0)
static std::string getMapFileName(unsigned int mapId)
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)