DynamicNavigationMesh.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Navigation/NavigationMesh.h"
  24. class dtTileCache;
  25. struct dtTileCacheAlloc;
  26. struct dtTileCacheCompressor;
  27. struct dtTileCacheMeshProcess;
  28. struct dtTileCacheLayer;
  29. struct dtTileCacheContourSet;
  30. struct dtTileCachePolyMesh;
  31. namespace Atomic
  32. {
  33. class OffMeshConnection;
  34. class Obstacle;
  35. class ATOMIC_API DynamicNavigationMesh : public NavigationMesh
  36. {
  37. OBJECT(DynamicNavigationMesh)
  38. friend class Obstacle;
  39. friend struct MeshProcess;
  40. public:
  41. /// Constructor.
  42. DynamicNavigationMesh(Context*);
  43. /// Destructor.
  44. virtual ~DynamicNavigationMesh();
  45. /// Register with engine context.
  46. static void RegisterObject(Context*);
  47. /// Build/rebuild the entire navigation mesh.
  48. virtual bool Build();
  49. /// Build/rebuild a portion of the navigation mesh.
  50. virtual bool Build(const BoundingBox& boundingBox);
  51. /// Visualize the component as debug geometry.
  52. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  53. /// Set navigation data attribute.
  54. virtual void SetNavigationDataAttr(const PODVector<unsigned char>& value);
  55. /// Return navigation data attribute.
  56. virtual PODVector<unsigned char> GetNavigationDataAttr() const;
  57. protected:
  58. struct TileCacheData;
  59. /// Subscribe to events when assigned to a node.
  60. virtual void OnNodeSet(Node*);
  61. /// Trigger the tile cache to make updates to the nav mesh if necessary.
  62. void HandleSceneSubsystemUpdate(StringHash eventType, VariantMap& eventData);
  63. /// Used by Obstacle class to add itself to the tile cache, if 'silent' an event will not be raised.
  64. void AddObstacle(Obstacle* obstacle, bool silent = false);
  65. /// Used by Obstacle class to update itself.
  66. void ObstacleChanged(Obstacle* obstacle);
  67. /// Used by Obstacle class to remove itself from the tile cache, if 'silent' an event will not be raised.
  68. void RemoveObstacle(Obstacle*, bool silent = false);
  69. /// Build one tile of the navigation mesh. Return true if successful.
  70. int BuildTile(Vector<NavigationGeometryInfo>& geometryList, int x, int z, TileCacheData*);
  71. /// Off-mesh connections to be rebuilt in the mesh processor.
  72. PODVector<OffMeshConnection*> CollectOffMeshConnections(const BoundingBox& bounds);
  73. /// Release the navigation mesh, query, and tile cache.
  74. virtual void ReleaseNavigationMesh();
  75. private:
  76. /// Free the tile cache.
  77. void ReleaseTileCache();
  78. /// Detour tile cache instance that works with the nav mesh.
  79. dtTileCache* tileCache_;
  80. /// Used by dtTileCache to allocate blocks of memory.
  81. dtTileCacheAlloc* allocator_;
  82. /// Used by dtTileCache to compress the original tiles to use when reconstructing for changes.
  83. dtTileCacheCompressor* compressor_;
  84. /// Mesh processer used by Detour, in this case a 'pass-through' processor.
  85. dtTileCacheMeshProcess* meshProcessor_;
  86. /// Maximum number of obstacle objects allowed.
  87. unsigned maxObstacles_;
  88. };
  89. }