RecastSmartPointer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <DetourNavMesh.h>
  10. #include <DetourNavMeshQuery.h>
  11. #include <Recast.h>
  12. #include <AzCore/std/smart_ptr/unique_ptr.h>
  13. namespace RecastNavigation
  14. {
  15. template <typename T>
  16. struct CustomRecastDeleter;
  17. //! A memory management helper for various Recast objects that require different methods to free memory.
  18. template <typename T>
  19. using RecastPointer = AZStd::unique_ptr<T, CustomRecastDeleter<T>>;
  20. template <>
  21. struct CustomRecastDeleter<rcHeightfield>
  22. {
  23. void operator ()(rcHeightfield* p)
  24. {
  25. rcFreeHeightField(p);
  26. }
  27. };
  28. template <>
  29. struct CustomRecastDeleter<rcCompactHeightfield>
  30. {
  31. void operator ()(rcCompactHeightfield* p)
  32. {
  33. rcFreeCompactHeightfield(p);
  34. }
  35. };
  36. template <>
  37. struct CustomRecastDeleter<rcContourSet>
  38. {
  39. void operator ()(rcContourSet* p)
  40. {
  41. rcFreeContourSet(p);
  42. }
  43. };
  44. template <>
  45. struct CustomRecastDeleter<rcPolyMesh>
  46. {
  47. void operator ()(rcPolyMesh* p)
  48. {
  49. rcFreePolyMesh(p);
  50. }
  51. };
  52. template <>
  53. struct CustomRecastDeleter<rcPolyMeshDetail>
  54. {
  55. void operator ()(rcPolyMeshDetail* p)
  56. {
  57. rcFreePolyMeshDetail(p);
  58. }
  59. };
  60. template <>
  61. struct CustomRecastDeleter<dtNavMesh>
  62. {
  63. void operator ()(dtNavMesh* p)
  64. {
  65. dtFreeNavMesh(p);
  66. }
  67. };
  68. template <>
  69. struct CustomRecastDeleter<dtNavMeshQuery>
  70. {
  71. void operator ()(dtNavMeshQuery* p)
  72. {
  73. dtFreeNavMeshQuery(p);
  74. }
  75. };
  76. } // namespace RecastNavigation