// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Types/BaseTypes.h" #include "Engine/Platform/CriticalSection.h" #include "NavMeshData.h" class NavigationScene; class dtNavMesh; class dtNavMeshQuery; class NavMeshTile { public: int32 X; int32 Y; int32 Layer; NavigationScene* Scene; BytesContainer Data; }; class FLAXENGINE_API NavMesh { private: dtNavMesh* _navMesh; dtNavMeshQuery* _navMeshQuery; float _tileSize; Array _tiles; public: NavMesh(); ~NavMesh(); public: /// /// The NavMesh object locker. /// CriticalSection Locker; /// /// Gets the size of the tile (in world-units). Returns zero if not initialized yet. /// /// The tile size. FORCE_INLINE float GetTileSize() const { return _tileSize; } dtNavMesh* GetNavMesh() const { return _navMesh; } dtNavMeshQuery* GetNavMeshQuery() const { return _navMeshQuery; } int32 GetTilesCapacity() const; public: /// /// Sets the size of the tile (if not assigned). Disposes the mesh if added tiles have different size. /// /// The size of the tile. void SetTileSize(float tileSize); /// /// Ensures the navmesh capacity for adding new tiles. Performs resizing if needed. /// /// The new tiles amount. void EnsureCapacity(int32 tilesToAddCount); /// /// Adds the tiles from the given scene to the runtime navmesh. /// /// The navigation scene. void AddTiles(NavigationScene* scene); /// /// Adds the tile from the given scene to the runtime navmesh. /// /// The navigation scene. /// The tile data. void AddTile(NavigationScene* scene, NavMeshTileData& tileData); /// /// Removes all the tiles from the navmesh that has been added from the given navigation scene. /// /// The scene. void RemoveTiles(NavigationScene* scene); /// /// Removes the tile from the navmesh. /// /// The tile X coordinate. /// The tile Y coordinate. /// The tile layer. void RemoveTile(int32 x, int32 y, int32 layer); /// /// Removes all the tiles that custom prediction callback marks. /// /// The prediction callback, returns true for tiles to remove and false for tiles to preserve. /// The user data passed to the callback method. void RemoveTiles(bool (*prediction)(const NavMesh* navMesh, const NavMeshTile& tile, void* customData), void* userData); /// /// Releases the navmesh. /// void Dispose(); private: void AddTileInternal(NavigationScene* scene, NavMeshTileData& tileData); };