27 bool operator()(
const G3D::Ray& ray,
uint32 entry,
float& distance,
bool pStopAtFirstHit=
true)
29 bool result =
prims[entry].intersectRay(ray, distance, pStopAtFirstHit);
47 SF_LOG_DEBUG(
"maps",
"AreaInfoCallback: trying to intersect '%s'",
prims[entry].name.c_str());
63 SF_LOG_DEBUG(
"maps",
"LocationInfoCallback: trying to intersect '%s'",
prims[entry].name.c_str());
78 std::stringstream tilefilename;
79 tilefilename.fill(
'0');
80 tilefilename << std::setw(4) << mapID <<
'_';
82 tilefilename << std::setw(2) << tileY <<
'_' << std::setw(2) << tileX <<
".vmtile";
83 return tilefilename.str();
89 iTree.intersectPoint(pos, intersectionCallBack);
105 iTree.intersectPoint(pos, intersectionCallBack);
106 return intersectionCallBack.
result;
115 iBasePath.push_back(
'/');
134 float distance = pMaxDist;
136 iTree.intersectRay(pRay, intersectionCallBack, distance, pStopAtFirstHit);
137 if (intersectionCallBack.
didHit())
139 return intersectionCallBack.
didHit();
145 float maxDist = (pos2 - pos1).magnitude();
147 if (maxDist == std::numeric_limits<float>::max() ||
148 maxDist == std::numeric_limits<float>::infinity())
152 ASSERT(maxDist < std::numeric_limits<float>::max());
154 if (maxDist < 1e-10f)
157 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist);
172 float maxDist = (pPos2 - pPos1).magnitude();
174 ASSERT(maxDist < std::numeric_limits<float>::max());
176 if (maxDist < 1e-10f)
178 pResultHitPos = pPos2;
181 Vector3 dir = (pPos2 - pPos1)/maxDist;
182 G3D::Ray ray(pPos1, dir);
183 float dist = maxDist;
186 pResultHitPos = pPos1 + dir * dist;
189 if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
191 pResultHitPos = pResultHitPos + dir*pModifyDist;
195 pResultHitPos = pPos1;
200 pResultHitPos = pResultHitPos + dir*pModifyDist;
206 pResultHitPos = pPos2;
216 float height = G3D::inf();
217 Vector3 dir = Vector3(0, 0, -1);
218 G3D::Ray ray(pPos, dir);
219 float maxDist = maxSearchDist;
222 height = pPos.z - maxDist;
231 std::string basePath = vmapPath;
232 if (basePath.length() > 0 && basePath[basePath.length()-1] !=
'/' && basePath[basePath.length()-1] !=
'\\')
233 basePath.push_back(
'/');
236 FILE* rf = fopen(fullname.c_str(),
"rb");
249 std::string tilefile = basePath +
getTileFileName(mapID, tileX, tileY);
250 FILE* tf = fopen(tilefile.c_str(),
"rb");
268 VMAP_DEBUG_LOG(
"maps",
"StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str());
269 bool success =
false;
270 std::string fullname =
iBasePath + fname;
271 FILE* rf = fopen(fullname.c_str(),
"rb");
307 VMAP_ERROR_LOG(
"misc",
"StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'", spawn.
name.c_str());
322 for (
uint32 refCount = 0; refCount < i->second; ++refCount)
342 VMAP_ERROR_LOG(
"misc",
"StaticMapTree::LoadMapTile() : tree has not been initialized [%u, %u]", tileX, tileY);
348 FILE* tf = fopen(tilefile.c_str(),
"rb");
356 if (result && fread(&numSpawns,
sizeof(
uint32), 1, tf) != 1)
358 for (
uint32 i=0; i<numSpawns && result; ++i)
368 VMAP_ERROR_LOG(
"misc",
"StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [%u, %u]", tileX, tileY);
373 if (fread(&referencedVal,
sizeof(
uint32), 1, tf) == 1)
392 SF_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
394 SF_LOG_DEBUG(
"maps",
"StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.
ID);
415 loadedTileMap::iterator tile =
iLoadedTiles.find(tileID);
418 VMAP_ERROR_LOG(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:%u X:%u Y:%u",
iMapID, tileX, tileY);
424 FILE* tf = fopen(tilefile.c_str(),
"rb");
432 if (fread(&numSpawns,
sizeof(
uint32), 1, tf) != 1)
434 for (
uint32 i=0; i<numSpawns && result; ++i)
447 if (fread(&referencedNode,
sizeof(
uint32), 1, tf) != 1)
452 VMAP_ERROR_LOG(
"misc",
"StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)", spawn.
name.c_str(), spawn.
ID);
#define SF_LOG_DEBUG(filterType__,...)
#define VMAP_DEBUG_LOG(FILTER,...)
#define VMAP_ERROR_LOG(FILTER,...)
AreaInfoCallback(ModelInstance *val)
void operator()(const Vector3 &point, uint32 entry)
LocationInfoCallback(ModelInstance *val, LocationInfo &info)
void operator()(const Vector3 &point, uint32 entry)
bool operator()(const G3D::Ray &ray, uint32 entry, float &distance, bool pStopAtFirstHit=true)
MapRayCallback(ModelInstance *val)
static bool readFromFile(FILE *rf, ModelSpawn &spawn)
bool getIntersectionTime(const G3D::Ray &pRay, float &pMaxDist, bool pStopAtFirstHit) const
StaticMapTree(uint32 mapID, const std::string &basePath)
bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
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 isInLineOfSight(const G3D::Vector3 &pos1, const G3D::Vector3 &pos2) const
bool getObjectHitPos(const G3D::Vector3 &pos1, const G3D::Vector3 &pos2, G3D::Vector3 &pResultHitPos, float pModifyDist) const
static uint32 packTileID(uint32 tileX, uint32 tileY)
ModelInstance * iTreeValues
loadedTileMap iLoadedTiles
loadedSpawnMap iLoadedSpawns
bool InitMap(const std::string &fname, VMapManager2 *vm)
bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) 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)
static std::string getMapFileName(unsigned int mapId)
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)