25#include <G3D/Vector3.h>
54 if (fread(dest,
sizeof(
char), len, rf) != len)
return false;
55 return memcmp(dest, compare, len) == 0;
59 iEnableLineOfSightCalc(true),
60 iEnableHeightCalc(true),
61 thread_safe_environment(true),
62 GetLiquidFlagsPtr([](
uint32 ) {
return 0u; }),
63 IsVMAPDisabledForPtr([](
uint32 ,
uint8 ) {
return false; }),
64 LoadPathOnlyModels(
false)
83 for (
auto const& [mapId, childMapIds] : mapData)
86 for (
uint32 childMapId : childMapIds)
103 constexpr float mid = 0.5f * 64.0f * 533.33333333f;
130 instanceTree =
iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId,
nullptr)).first;
132 ABORT_MSG(
"Invalid mapId %u tile [%u, %u] passed to VMapManager after startup in thread unsafe environment",
136 if (!instanceTree->second)
139 std::unique_ptr<StaticMapTree> newTree = std::make_unique<StaticMapTree>(mapId, basePath);
140 LoadResult treeInitResult = newTree->InitMap(mapFileName);
142 return treeInitResult;
144 instanceTree->second = std::move(newTree);
147 return instanceTree->second->LoadMapTile(x, y,
this);
155 instanceTree->second->UnloadMapTile(x, y);
156 if (instanceTree->second->numLoadedTiles() == 0)
157 instanceTree->second =
nullptr;
166 instanceTree->second->UnloadMap();
167 if (instanceTree->second->numLoadedTiles() == 0)
168 instanceTree->second =
nullptr;
183 return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags);
193 bool VMapManager::getObjectHitPos(
uint32 mapId,
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float& rx,
float &ry,
float& rz,
float modifyDist)
202 G3D::Vector3 resultPos;
203 bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist);
231 float height = instanceTree->second->getHeight(pos, maxSearchDist);
232 if (!(height < G3D::finf()))
244 InstanceTreeMap::const_iterator instanceTree =
GetMapTree(mapId);
249 if (instanceTree->second->GetLocationInfo(pos, info))
258 data.
liquidInfo.emplace(liquidType, liquidLevel);
273 std::shared_ptr<ManagedModel> worldmodel;
279 worldmodel = model.lock();
281 return std::shared_ptr<WorldModel>(worldmodel, &worldmodel->Model);
283 worldmodel = std::make_shared<ManagedModel>(*
this, key);
284 if (!worldmodel->Model.readFile(basepath + filename +
".vmo"))
286 TC_LOG_ERROR(
"misc",
"VMapManager: could not load '{}{}.vmo'", basepath, filename);
289 TC_LOG_DEBUG(
"maps",
"VMapManager: loading file '{}{}'", basepath, filename);
293 return std::shared_ptr<WorldModel>(worldmodel, &worldmodel->Model);
301 TC_LOG_DEBUG(
"maps",
"VMapManager: unloading file '{}'", filename);
305 TC_LOG_ERROR(
"misc",
"VMapManager: trying to unload non-loaded file '{}'", filename);
315 InstanceTreeMap::const_iterator mapTree =
GetMapTree(mapId);
317 return mapTree->second->getModelInstances();
326 return int32(itr->second);
#define TC_LOG_DEBUG(filterType__, message__,...)
#define TC_LOG_ERROR(filterType__, message__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
#define VMAP_INVALID_HEIGHT_VALUE
uint32 GetLiquidType() const
uint32 GetMogpFlags() const
ManagedModel(ManagedModel const &)=delete
ManagedModel(ManagedModel &&)=delete
ManagedModel(VMapManager &mgr, std::string const &name)
std::string const & _name
ManagedModel & operator=(ManagedModel const &)=delete
ManagedModel & operator=(ManagedModel &&)=delete
bool GetLiquidLevel(G3D::Vector3 const &p, LocationInfo &info, float &liqHeight) const
static LoadResult CanLoadMap(std::string const &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager *vm)
bool getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional< uint8 > reqLiquidType, AreaAndLiquidData &data) const
bool getObjectHitPos(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist)
bool isLineOfSightCalcEnabled() const
LoadResult existsMap(std::string const &basePath, uint32 mapId, uint32 x, uint32 y)
bool isHeightCalcEnabled() const
LoadResult loadMap(std::string const &basePath, uint32 mapId, uint32 x, uint32 y)
void unloadMap(uint32 mapId, uint32 x, uint32 y)
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
float getHeight(uint32 mapId, float x, float y, float z, float maxSearchDist)
bool isMapLoadingEnabled() const
ModelFileMap iLoadedModelFiles
static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
std::shared_ptr< WorldModel > acquireModelInstance(std::string const &basepath, std::string const &filename)
std::unordered_map< uint32, uint32 > iParentMapData
std::mutex LoadedModelFilesLock
GetLiquidFlagsFn GetLiquidFlagsPtr
int32 getParentMapId(uint32 mapId) const
InstanceTreeMap iInstanceMapTrees
void InitializeThreadUnsafe(std::unordered_map< uint32, std::vector< uint32 > > const &mapData)
static std::string getMapFileName(uint32 mapId)
std::span< ModelInstance const > getModelsOnMap(uint32 mapId) const
bool thread_safe_environment
bool isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags)
IsVMAPDisabledForFn IsVMAPDisabledForPtr
void releaseModelInstance(std::string const &filename)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
static G3D::Vector3 convertPositionToInternalRep(float x, float y, float z)
@ VMAP_DISABLE_LIQUIDSTATUS
Optional< AreaInfo > areaInfo
Optional< LiquidInfo > liquidInfo
GroupModel const * hitModel
ModelInstance const * hitInstance