26#include <G3D/Vector3.h>
44 for (std::pair<uint32 const, StaticMapTree*>& iInstanceMapTree :
iInstanceMapTrees)
46 delete iInstanceMapTree.second;
48 for (std::pair<std::string const, ManagedModel>& iLoadedModelFile :
iLoadedModelFiles)
50 delete iLoadedModelFile.second.getModel();
57 for (
uint32 const& mapId : mapIds)
66 const float mid = 0.5f * 64.0f * 533.33333333f;
77 std::stringstream fname;
115 instanceTree =
iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId,
nullptr)).first;
117 ABORT_MSG(
"Invalid mapId %u tile [%u, %u] passed to VMapManager2 after startup in thread unsafe environment",
118 mapId, tileX, tileY);
121 if (!instanceTree->second)
125 if (!newTree->
InitMap(mapFileName,
this))
130 instanceTree->second = newTree;
133 return instanceTree->second->
LoadMapTile(tileX, tileY,
this);
141 instanceTree->second->UnloadMap(
this);
142 if (instanceTree->second->numLoadedTiles() == 0)
144 delete instanceTree->second;
145 instanceTree->second =
nullptr;
155 instanceTree->second->UnloadMapTile(x, y,
this);
156 if (instanceTree->second->numLoadedTiles() == 0)
158 delete instanceTree->second;
159 instanceTree->second =
nullptr;
169 InstanceTreeMap::const_iterator instanceTree =
GetMapTree(mapId);
176 return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags);
187 bool VMapManager2::getObjectHitPos(
unsigned int mapId,
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float& rx,
float &ry,
float& rz,
float modifyDist)
191 InstanceTreeMap::const_iterator instanceTree =
GetMapTree(mapId);
197 bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist);
221 InstanceTreeMap::const_iterator instanceTree =
GetMapTree(mapId);
225 float height = instanceTree->second->getHeight(pos, maxSearchDist);
226 if (!(height < G3D::finf()))
238 InstanceTreeMap::const_iterator instanceTree =
GetMapTree(mapId);
243 if (instanceTree->second->GetLocationInfo(pos, info))
254 data.
liquidInfo.emplace(liquidType, liquidLevel);
276 if (!worldmodel->
readFile(basepath + filename +
".vmo"))
278 TC_LOG_ERROR(
"misc",
"VMapManager2: could not load '{}{}.vmo'", basepath, filename);
282 TC_LOG_DEBUG(
"maps",
"VMapManager2: loading file '{}{}'", basepath, filename);
287 model->second.setModel(worldmodel);
289 model->second.incRefCount();
290 return model->second.getModel();
301 TC_LOG_ERROR(
"misc",
"VMapManager2: trying to unload non-loaded file '{}'", filename);
304 if (model->second.decRefCount() == 0)
306 TC_LOG_DEBUG(
"maps",
"VMapManager2: unloading file '{}'", filename);
307 delete model->second.getModel();
#define VMAP_INVALID_HEIGHT_VALUE
#define TC_LOG_DEBUG(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
#define MAP_FILENAME_EXTENSION2
uint32 GetLiquidType() const
uint32 GetMogpFlags() const
bool isHeightCalcEnabled() const
bool isMapLoadingEnabled() const
bool isLineOfSightCalcEnabled() const
bool GetLiquidLevel(G3D::Vector3 const &p, LocationInfo &info, float &liqHeight) const
static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2 *vm)
bool InitMap(const std::string &fname, VMapManager2 *vm)
void InitializeThreadUnsafe(const std::vector< uint32 > &mapIds)
bool getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional< uint8 > reqLiquidType, AreaAndLiquidData &data) const override
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
void releaseModelInstance(const std::string &filename)
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
std::mutex LoadedModelFilesLock
ModelFileMap iLoadedModelFiles
void getInstanceMapTree(InstanceTreeMap &instanceMapTree)
IsVMAPDisabledForFn IsVMAPDisabledForPtr
static bool IsVMAPDisabledForDummy(uint32, uint8)
bool thread_safe_environment
virtual LoadResult existsMap(char const *basePath, unsigned int mapId, int x, int y) override
void unloadMap(unsigned int mapId, int x, int y) override
WorldModel * acquireModelInstance(const std::string &basepath, const std::string &filename, uint32 flags=0)
bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) override
bool getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist) override
InstanceTreeMap iInstanceMapTrees
GetLiquidFlagsFn GetLiquidFlagsPtr
static std::string getMapFileName(unsigned int mapId)
bool _loadMap(uint32 mapId, const std::string &basePath, uint32 tileX, uint32 tileY)
int loadMap(char const *pBasePath, unsigned int mapId, int x, int y) override
static uint32 GetLiquidFlagsDummy(uint32)
float getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist) override
bool readFile(const std::string &filename)
std::unordered_map< uint32, StaticMapTree * > InstanceTreeMap
@ VMAP_LOAD_RESULT_IGNORED
@ VMAP_DISABLE_LIQUIDSTATUS
Optional< AreaInfo > areaInfo
Optional< LiquidInfo > liquidInfo
GroupModel const * hitModel
ModelInstance const * hitInstance