diff options
Diffstat (limited to 'src/common/Collision')
| -rw-r--r-- | src/common/Collision/BoundingIntervalHierarchyWrapper.h | 3 | ||||
| -rw-r--r-- | src/common/Collision/DynamicTree.cpp | 8 | ||||
| -rw-r--r-- | src/common/Collision/DynamicTree.h | 3 | ||||
| -rw-r--r-- | src/common/Collision/Management/MMapManager.cpp | 419 | ||||
| -rw-r--r-- | src/common/Collision/Management/MMapManager.h | 87 | ||||
| -rw-r--r-- | src/common/Collision/Maps/MMapDefines.h | 97 | ||||
| -rw-r--r-- | src/common/Collision/Models/GameObjectModel.h | 21 | ||||
| -rw-r--r-- | src/common/Collision/RegularGrid.h | 7 |
8 files changed, 34 insertions, 611 deletions
diff --git a/src/common/Collision/BoundingIntervalHierarchyWrapper.h b/src/common/Collision/BoundingIntervalHierarchyWrapper.h index 85048da58bc..03c6f0268c8 100644 --- a/src/common/Collision/BoundingIntervalHierarchyWrapper.h +++ b/src/common/Collision/BoundingIntervalHierarchyWrapper.h @@ -19,6 +19,7 @@ #define TRINITYCORE_BOUNDING_INTERVAL_HIERARCHY_WRAPPER_H #include "BoundingIntervalHierarchy.h" +#include <span> #include <unordered_map> template<class T, class BoundsFunc = BoundsTrait<T> > @@ -115,6 +116,8 @@ public: MDLCallback<IsectCallback> callback(intersectCallback, m_objects.data(), m_objects.size()); m_tree.intersectPoint(point, callback); } + + std::span<T const* const> getObjects() const { return m_objects; } }; #endif // TRINITYCORE_BOUNDING_INTERVAL_HIERARCHY_WRAPPER_H diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp index 85dc9d52618..129c1a41878 100644 --- a/src/common/Collision/DynamicTree.cpp +++ b/src/common/Collision/DynamicTree.cpp @@ -36,7 +36,7 @@ int CHECK_TREE_PERIOD = 200; } // namespace template<> struct PositionTrait< GameObjectModel> { - static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.getPosition(); } + static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.GetPosition(); } }; template<> struct BoundsTrait< GameObjectModel> { @@ -280,3 +280,9 @@ bool DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, PhaseShift } return false; } + +std::span<GameObjectModel const* const> DynamicMapTree::getModelsInGrid(uint32 gx, uint32 gy) const +{ + // convert from map tile X/Y to RegularGrid internal representation + return impl->getObjects(63 - int32(gx), 63 - int32(gy)); +} diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h index 11d701ebd7c..73c667acb29 100644 --- a/src/common/Collision/DynamicTree.h +++ b/src/common/Collision/DynamicTree.h @@ -21,6 +21,7 @@ #include "Define.h" #include "Optional.h" #include <memory> +#include <span> namespace G3D { @@ -59,6 +60,8 @@ public: void balance(); void update(uint32 diff); + + std::span<GameObjectModel const* const> getModelsInGrid(uint32 gx, uint32 gy) const; }; #endif // _DYNTREE_H diff --git a/src/common/Collision/Management/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp deleted file mode 100644 index d0862a49156..00000000000 --- a/src/common/Collision/Management/MMapManager.cpp +++ /dev/null @@ -1,419 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "MMapManager.h" -#include "Errors.h" -#include "Hash.h" -#include "Log.h" -#include "MMapDefines.h" -#include "Memory.h" -#include <algorithm> - -namespace MMAP -{ - constexpr char MAP_FILE_NAME_FORMAT[] = "{}mmaps/{:04}.mmap"; - constexpr char TILE_FILE_NAME_FORMAT[] = "{}mmaps/{:04}_{:02}_{:02}.mmtile"; - - using NavMeshPtr = std::unique_ptr<dtNavMesh, decltype(Trinity::unique_ptr_deleter<dtNavMesh*, &::dtFreeNavMesh>())>; - using NavMeshQueryPtr = std::unique_ptr<dtNavMeshQuery, decltype(Trinity::unique_ptr_deleter<dtNavMeshQuery*, &::dtFreeNavMeshQuery>())>; - - typedef std::unordered_map<std::pair<uint32, uint32>, NavMeshQueryPtr> NavMeshQuerySet; - typedef std::unordered_map<uint32, dtTileRef> MMapTileSet; - - // dummy struct to hold map's mmap data - struct MMapData - { - explicit MMapData(NavMeshPtr&& mesh) : navMesh(std::move(mesh)) { } - - // we have to use single dtNavMeshQuery for every instance, since those are not thread safe - NavMeshQuerySet navMeshQueries; // instanceId to query - - NavMeshPtr navMesh; - MMapTileSet loadedTileRefs; // maps [map grid coords] to [dtTile] - }; - - // ######################## MMapManager ######################## - MMapManager::MMapManager() = default; - MMapManager::~MMapManager() = default; - - MMapManager* MMapManager::instance() - { - static MMapManager instance; - return &instance; - } - - void MMapManager::InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData) - { - // the caller must pass the list of all mapIds that will be used in the MMapManager lifetime - for (auto const& [mapId, childMapIds] : mapData) - { - loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr)); - for (uint32 childMapId : childMapIds) - parentMapData[childMapId] = mapId; - } - - thread_safe_environment = false; - } - - MMapDataSet::const_iterator MMapManager::GetMMapData(uint32 mapId) const - { - // return the iterator if found or end() if not found/NULL - MMapDataSet::const_iterator itr = loadedMMaps.find(mapId); - if (itr != loadedMMaps.cend() && !itr->second) - itr = loadedMMaps.cend(); - - return itr; - } - - LoadResult MMapManager::loadMapData(std::string_view basePath, uint32 mapId) - { - // we already have this map loaded? - MMapDataSet::iterator itr = loadedMMaps.find(mapId); - if (itr != loadedMMaps.end()) - { - if (itr->second) - return LoadResult::AlreadyLoaded; - } - else - { - if (thread_safe_environment) - itr = loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr)).first; - else - ABORT_MSG("Invalid mapId %u passed to MMapManager after startup in thread unsafe environment", mapId); - } - - // load and init dtNavMesh - read parameters from file - dtNavMeshParams params; - if (LoadResult paramsResult = parseNavMeshParamsFile(basePath, mapId, ¶ms); paramsResult != LoadResult::Success) - return paramsResult; - - NavMeshPtr mesh(dtAllocNavMesh()); - ASSERT(mesh); - if (dtStatusFailed(mesh->init(¶ms))) - { - TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {:04}", mapId); - return LoadResult::LibraryError; - } - - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Loaded {:04}.mmap", mapId); - - // store inside our map list - itr->second.reset(new MMapData(std::move(mesh))); - return LoadResult::Success; - } - - LoadResult MMapManager::parseNavMeshParamsFile(std::string_view basePath, uint32 mapId, dtNavMeshParams* params, - std::vector<OffMeshData>* offmeshConnections /*= nullptr*/) - { - std::string fileName = Trinity::StringFormat(MAP_FILE_NAME_FORMAT, basePath, mapId); - auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "rb")); - if (!file) - { - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '{}'", fileName); - return LoadResult::FileNotFound; - } - - MmapNavMeshHeader fileHeader; - if (fread(&fileHeader, sizeof(MmapNavMeshHeader), 1, file.get()) != 1) - { - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '{}'", fileName); - return LoadResult::ReadFromFileFailed; - } - - if (fileHeader.mmapMagic != MMAP_MAGIC) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap {:04}.mmap", mapId); - return LoadResult::VersionMismatch; - } - - if (fileHeader.mmapVersion != MMAP_VERSION) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: {:04}.mmap was built with generator v{}, expected v{}", - mapId, fileHeader.mmapVersion, MMAP_VERSION); - return LoadResult::VersionMismatch; - } - - memcpy(params, &fileHeader.params, sizeof(dtNavMeshParams)); - - if (offmeshConnections) - { - offmeshConnections->resize(fileHeader.offmeshConnectionCount); - if (fread(offmeshConnections->data(), sizeof(OffMeshData), offmeshConnections->size(), file.get()) != offmeshConnections->size()) - { - offmeshConnections->clear(); - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read offmesh connections from file '{}'", fileName); - return LoadResult::ReadFromFileFailed; - } - } - - return LoadResult::Success; - } - - uint32 MMapManager::packTileID(int32 x, int32 y) - { - return uint32(x << 16 | y); - } - - LoadResult MMapManager::loadMap(std::string_view basePath, uint32 mapId, int32 x, int32 y) - { - // make sure the mmap is loaded and ready to load tiles - switch (LoadResult mapResult = loadMapData(basePath, mapId)) - { - case LoadResult::Success: - case LoadResult::AlreadyLoaded: - break; - default: - return mapResult; - } - - // get this mmap data - MMapData* mmap = loadedMMaps[mapId].get(); - ASSERT(mmap->navMesh); - - // check if we already have this tile loaded - uint32 packedGridPos = packTileID(x, y); - if (mmap->loadedTileRefs.contains(packedGridPos)) - return LoadResult::AlreadyLoaded; - - // load this tile :: mmaps/MMMM_XX_YY.mmtile - std::string fileName = Trinity::StringFormat(TILE_FILE_NAME_FORMAT, basePath, mapId, x, y); - auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "rb")); - if (!file) - { - auto parentMapItr = parentMapData.find(mapId); - if (parentMapItr != parentMapData.end()) - { - fileName = Trinity::StringFormat(TILE_FILE_NAME_FORMAT, basePath, parentMapItr->second, x, y); - file.reset(fopen(fileName.c_str(), "rb")); - } - } - - if (!file) - { - TC_LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '{}'", fileName); - return LoadResult::FileNotFound; - } - - // read header - MmapTileHeader fileHeader; - if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file.get()) != 1) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap {:04}_{:02}_{:02}.mmtile", mapId, x, y); - return LoadResult::ReadFromFileFailed; - } - - if (fileHeader.mmapMagic != MMAP_MAGIC) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap {:04}_{:02}_{:02}.mmtile", mapId, x, y); - return LoadResult::VersionMismatch; - } - - if (fileHeader.mmapVersion != MMAP_VERSION) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: {:04}_{:02}_{:02}.mmtile was built with generator v{}, expected v{}", - mapId, x, y, fileHeader.mmapVersion, MMAP_VERSION); - return LoadResult::VersionMismatch; - } - - long pos = ftell(file.get()); - fseek(file.get(), 0, SEEK_END); - if (pos < 0 || static_cast<int32>(fileHeader.size) > ftell(file.get()) - pos) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: {:04}_{:02}_{:02}.mmtile has corrupted data size", mapId, x, y); - return LoadResult::ReadFromFileFailed; - } - - fseek(file.get(), pos, SEEK_SET); - - auto data = Trinity::make_unique_ptr_with_deleter<&::dtFree>(dtAlloc(fileHeader.size, DT_ALLOC_PERM)); - ASSERT(data); - - size_t result = fread(data.get(), fileHeader.size, 1, file.get()); - if (!result) - { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header or data in mmap {:04}_{:02}_{:02}.mmtile", mapId, x, y); - return LoadResult::ReadFromFileFailed; - } - - dtMeshHeader* header = static_cast<dtMeshHeader*>(data.get()); - dtTileRef tileRef = 0; - - // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed - if (dtStatusSucceed(mmap->navMesh->addTile(static_cast<unsigned char*>(data.release()), fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef))) - { - mmap->loadedTileRefs.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef)); - ++loadedTiles; - TC_LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile {:04}[{:02}, {:02}] into {:04}[{:02}, {:02}]", mapId, x, y, mapId, header->x, header->y); - return LoadResult::Success; - } - else - { - TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load {:04}_{:02}_{:02}.mmtile into navmesh", mapId, x, y); - return LoadResult::LibraryError; - } - } - - bool MMapManager::loadMapInstance(std::string_view basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId) - { - switch (loadMapData(basePath, meshMapId)) - { - case LoadResult::Success: - case LoadResult::AlreadyLoaded: - break; - default: - return false; - } - - MMapData* mmap = loadedMMaps[meshMapId].get(); - auto [queryItr, inserted] = mmap->navMeshQueries.try_emplace({ instanceMapId, instanceId }, nullptr); - if (!inserted) - return true; - - // allocate mesh query - NavMeshQueryPtr query(dtAllocNavMeshQuery()); - ASSERT(query); - if (dtStatusFailed(query->init(mmap->navMesh.get(), 1024))) - { - mmap->navMeshQueries.erase(queryItr); - TC_LOG_ERROR("maps", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId {:04} instanceId {}", instanceMapId, instanceId); - return false; - } - - TC_LOG_DEBUG("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId {:04} instanceId {}", instanceMapId, instanceId); - queryItr->second = std::move(query); - return true; - } - - bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y) - { - // check if we have this map loaded - MMapDataSet::const_iterator itr = GetMMapData(mapId); - if (itr == loadedMMaps.end()) - { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map. {:04}_{:02}_{:02}.mmtile", mapId, x, y); - return false; - } - - MMapData* mmap = itr->second.get(); - - // check if we have this tile loaded - uint32 packedGridPos = packTileID(x, y); - auto tileRef = mmap->loadedTileRefs.extract(packedGridPos); - if (!tileRef) - { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh tile. {:04}{:02}{:02}.mmtile", mapId, x, y); - return false; - } - - // unload, and mark as non loaded - if (dtStatusFailed(mmap->navMesh->removeTile(tileRef.mapped(), nullptr, nullptr))) - { - // this is technically a memory leak - // if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used - // we cannot recover from this error - assert out - TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload {:04}_{:02}_{:02}.mmtile from navmesh", mapId, x, y); - ABORT(); - } - else - { - --loadedTiles; - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile {:04}[{:02}, {:02}] from {:03}", mapId, x, y, mapId); - return true; - } - - return false; - } - - bool MMapManager::unloadMap(uint32 mapId) - { - MMapDataSet::iterator itr = loadedMMaps.find(mapId); - if (itr == loadedMMaps.end() || !itr->second) - { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map {:04}", mapId); - return false; - } - - // unload all tiles from given map - MMapData* mmap = itr->second.get(); - for (auto const& [tileId, tileRef] : mmap->loadedTileRefs) - { - uint32 x = (tileId >> 16); - uint32 y = (tileId & 0x0000FFFF); - if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, nullptr, nullptr))) - TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload {:04}_{:02}_{:02}.mmtile from navmesh", mapId, x, y); - else - { - --loadedTiles; - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile {:04}[{:02}, {:02}] from {:04}", mapId, x, y, mapId); - } - } - - itr->second = nullptr; - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded {:04}.mmap", mapId); - - return true; - } - - bool MMapManager::unloadMapInstance(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId) - { - // check if we have this map loaded - MMapDataSet::const_iterator itr = GetMMapData(meshMapId); - if (itr == loadedMMaps.end()) - { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded navmesh map {:04}", meshMapId); - return false; - } - - MMapData* mmap = itr->second.get(); - std::size_t erased = mmap->navMeshQueries.erase({ instanceMapId, instanceId }); - if (!erased) - { - TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId {:04} instanceId {}", instanceMapId, instanceId); - return false; - } - - TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Unloaded mapId {:04} instanceId {}", instanceMapId, instanceId); - - return true; - } - - dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId) - { - MMapDataSet::const_iterator itr = GetMMapData(mapId); - if (itr == loadedMMaps.end()) - return nullptr; - - return itr->second->navMesh.get(); - } - - dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId) - { - auto itr = GetMMapData(meshMapId); - if (itr == loadedMMaps.end()) - return nullptr; - - auto queryItr = itr->second->navMeshQueries.find({ instanceMapId, instanceId }); - if (queryItr == itr->second->navMeshQueries.end()) - return nullptr; - - return queryItr->second.get(); - } -} diff --git a/src/common/Collision/Management/MMapManager.h b/src/common/Collision/Management/MMapManager.h deleted file mode 100644 index b48b773555b..00000000000 --- a/src/common/Collision/Management/MMapManager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef _MMAP_MANAGER_H -#define _MMAP_MANAGER_H - -#include "Define.h" -#include "MMapDefines.h" -#include <DetourNavMeshQuery.h> -#include <memory> -#include <string_view> -#include <unordered_map> -#include <vector> - -// move map related classes -namespace MMAP -{ - struct MMapData; - - typedef std::unordered_map<uint32, std::unique_ptr<MMapData>> MMapDataSet; - - enum class LoadResult : uint8 - { - Success, - AlreadyLoaded, - FileNotFound, - VersionMismatch, - ReadFromFileFailed, - LibraryError - }; - - // singleton class - // holds all all access to mmap loading unloading and meshes - class TC_COMMON_API MMapManager - { - public: - MMapManager(); - MMapManager(MMapManager const& other) = delete; - MMapManager(MMapManager&& other) noexcept = delete; - MMapManager& operator=(MMapManager const& other) = delete; - MMapManager& operator=(MMapManager&& other) noexcept = delete; - ~MMapManager(); - - static MMapManager* instance(); - - void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData); - static LoadResult parseNavMeshParamsFile(std::string_view basePath, uint32 mapId, dtNavMeshParams* params, std::vector<OffMeshData>* offmeshConnections = nullptr); - LoadResult loadMap(std::string_view basePath, uint32 mapId, int32 x, int32 y); - bool loadMapInstance(std::string_view basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId); - bool unloadMap(uint32 mapId, int32 x, int32 y); - bool unloadMap(uint32 mapId); - bool unloadMapInstance(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId); - - // the returned [dtNavMeshQuery const*] is NOT threadsafe - dtNavMeshQuery const* GetNavMeshQuery(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId); - dtNavMesh const* GetNavMesh(uint32 mapId); - - uint32 getLoadedTilesCount() const { return loadedTiles; } - uint32 getLoadedMapsCount() const { return uint32(loadedMMaps.size()); } - private: - LoadResult loadMapData(std::string_view basePath, uint32 mapId); - uint32 packTileID(int32 x, int32 y); - - MMapDataSet::const_iterator GetMMapData(uint32 mapId) const; - MMapDataSet loadedMMaps; - uint32 loadedTiles = 0; - bool thread_safe_environment = true; - - std::unordered_map<uint32, uint32> parentMapData; - }; -} - -#endif diff --git a/src/common/Collision/Maps/MMapDefines.h b/src/common/Collision/Maps/MMapDefines.h deleted file mode 100644 index 522112ebe62..00000000000 --- a/src/common/Collision/Maps/MMapDefines.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MMapDefines_h__ -#define MMapDefines_h__ - -#include "Define.h" -#include <DetourNavMesh.h> - -inline uint32 constexpr MMAP_MAGIC = 0x4d4d4150; // 'MMAP' -inline uint32 constexpr MMAP_VERSION = 16; - -struct MmapNavMeshHeader -{ - uint32 mmapMagic = MMAP_MAGIC; - uint32 mmapVersion = MMAP_VERSION; - dtNavMeshParams params = { }; - uint32 offmeshConnectionCount = 0; -}; - -static_assert(sizeof(MmapNavMeshHeader) == 40); - -struct MmapTileHeader -{ - uint32 mmapMagic = MMAP_MAGIC; - uint32 dtVersion = DT_NAVMESH_VERSION; - uint32 mmapVersion = MMAP_VERSION; - uint32 size = 0; - char usesLiquids = true; - char padding[3] = { }; -}; - -// All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files -static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size"); -static_assert(sizeof(MmapTileHeader) == sizeof(MmapTileHeader::mmapMagic) + - sizeof(MmapTileHeader::dtVersion) + - sizeof(MmapTileHeader::mmapVersion) + - sizeof(MmapTileHeader::size) + - sizeof(MmapTileHeader::usesLiquids) + - sizeof(MmapTileHeader::padding), "MmapTileHeader has uninitialized padding fields"); - -enum NavArea -{ - NAV_AREA_EMPTY = 0, - // areas 1-60 will be used for destructible areas (currently skipped in vmaps, WMO with flag 1) - // ground is the highest value to make recast choose ground over water when merging surfaces very close to each other (shallow water would be walkable) - NAV_AREA_GROUND = 11, - NAV_AREA_GROUND_STEEP = 10, - NAV_AREA_WATER = 9, - NAV_AREA_MAGMA_SLIME = 8, // don't need to differentiate between them - NAV_AREA_MAX_VALUE = NAV_AREA_GROUND, - NAV_AREA_MIN_VALUE = NAV_AREA_MAGMA_SLIME, - NAV_AREA_ALL_MASK = 0x3F // max allowed value -}; - -enum NavTerrainFlag : uint16 -{ - NAV_EMPTY = 0x00, - NAV_GROUND = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_GROUND), - NAV_GROUND_STEEP = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_GROUND_STEEP), - NAV_WATER = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_WATER), - NAV_MAGMA_SLIME = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_MAGMA_SLIME) -}; - -enum OffMeshConnectionFlag : uint8 -{ - OFFMESH_CONNECTION_FLAG_BIDIRECTIONAL = 0x01 -}; - -struct OffMeshData -{ - uint32 MapId; - uint32 TileX; - uint32 TileY; - float From[3]; - float To[3]; - float Radius; - OffMeshConnectionFlag ConnectionFlags; - uint8 AreaId; - NavTerrainFlag Flags; -}; - -#endif // MMapDefines_h__ diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h index 2ea99f61e20..f82c1f6860c 100644 --- a/src/common/Collision/Models/GameObjectModel.h +++ b/src/common/Collision/Models/GameObjectModel.h @@ -21,15 +21,11 @@ #include "Define.h" #include <G3D/AABox.h> #include <G3D/Matrix3.h> +#include <G3D/Quat.h> #include <G3D/Ray.h> #include <G3D/Vector3.h> #include <memory> -namespace G3D -{ -class Quat; -} - namespace VMAP { class WorldModel; @@ -53,25 +49,33 @@ public: virtual bool IsInPhase(PhaseShift const& /*phaseShift*/) const = 0; virtual G3D::Vector3 GetPosition() const = 0; virtual G3D::Quat GetRotation() const = 0; + virtual int64 GetPackedRotation() const = 0; virtual float GetScale() const = 0; virtual void DebugVisualizeCorner(G3D::Vector3 const& /*corner*/) const = 0; }; class TC_COMMON_API GameObjectModel /*, public Intersectable*/ { - GameObjectModel() : iCollisionEnabled(false), iLosBlockingDisabled(false), iInvScale(0), iScale(0), iModel(nullptr) { } + GameObjectModel() : iCollisionEnabled(false), iLosBlockingDisabled(false), iIncludeInNavMesh(false), iInvScale(0), iScale(0), iModel(nullptr) { } public: const G3D::AABox& getBounds() const { return iBound; } ~GameObjectModel(); - const G3D::Vector3& getPosition() const { return iPos;} + uint32 GetDisplayId() const { return owner->GetDisplayId(); } + G3D::Vector3 const& GetPosition() const { return iPos; } + G3D::Quat GetRotation() const { return owner->GetRotation(); } + G3D::Matrix3 const& GetInvRot() const { return iInvRot; } + int64 GetPackedRotation() const { return owner->GetPackedRotation(); } + float GetScale() const { return iScale; } /* Enables/disables collision */ void EnableCollision(bool enable) { iCollisionEnabled = enable; } bool IsCollisionEnabled() const { return iCollisionEnabled; } void DisableLosBlocking(bool enable) { iLosBlockingDisabled = enable; } bool IsLosBlockingDisabled() const { return iLosBlockingDisabled; } + void IncludeInNavMesh(bool enable) { iIncludeInNavMesh = enable; } + bool IsIncludedInNavMesh() const { return iIncludeInNavMesh; } bool IsMapObject() const; uint8 GetNameSetId() const { return owner->GetNameSetId(); } @@ -83,11 +87,14 @@ public: bool UpdatePosition(); + std::shared_ptr<VMAP::WorldModel const> GetWorldModel() const { return iModel; } + private: bool initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath); bool iCollisionEnabled; ///< Is model ignored in all checks bool iLosBlockingDisabled; ///< Is model ignored during line of sight checks (but is always included in location/height checks) + bool iIncludeInNavMesh; ///< Is model included when generating navigation mesh G3D::AABox iBound; G3D::Matrix3 iInvRot; G3D::Vector3 iPos; diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h index 459388d2662..94f97b2cb5a 100644 --- a/src/common/Collision/RegularGrid.h +++ b/src/common/Collision/RegularGrid.h @@ -210,6 +210,13 @@ public: if (Node* node = nodes[cell.x][cell.y].get()) node->intersectRay(ray, intersectCallback, max_dist); } + + std::span<T const* const> getObjects(int x, int y) const + { + if (Node* n = nodes[x][y].get()) + return n->getObjects(); + return {}; + } }; #undef CELL_SIZE |
