From 61dbce80e98e0cf470bbbae9e7a3792f6b12fb84 Mon Sep 17 00:00:00 2001 From: grahamboree Date: Sun, 20 Mar 2016 18:42:14 -0400 Subject: [PATCH] Added Constructor and Destructor to rcHeightfield. --- Recast/Include/Recast.h | 8 ++++++++ Recast/Source/Recast.cpp | 42 +++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Recast/Include/Recast.h b/Recast/Include/Recast.h index 2adcdcb..c0088ce 100644 --- a/Recast/Include/Recast.h +++ b/Recast/Include/Recast.h @@ -293,6 +293,9 @@ struct rcSpanPool /// @ingroup recast struct rcHeightfield { + rcHeightfield(); + ~rcHeightfield(); + int width; ///< The width of the heightfield. (Along the x-axis in cell units.) int height; ///< The height of the heightfield. (Along the z-axis in cell units.) float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] @@ -302,6 +305,11 @@ struct rcHeightfield rcSpan** spans; ///< Heightfield of spans (width*height). rcSpanPool* pools; ///< Linked list of span pools. rcSpan* freelist; ///< The next free span. + +private: + // Explicitly-disabled copy constructor and copy assignment operator. + rcHeightfield(const rcHeightfield&); + rcHeightfield& operator=(const rcHeightfield&); }; /// Provides information on the content of a cell column in a compact heightfield. diff --git a/Recast/Source/Recast.cpp b/Recast/Source/Recast.cpp index 46bc8b7..76e64b9 100644 --- a/Recast/Source/Recast.cpp +++ b/Recast/Source/Recast.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "Recast.h" #include "RecastAlloc.h" #include "RecastAssert.h" @@ -72,23 +73,39 @@ void rcContext::log(const rcLogCategory category, const char* format, ...) rcHeightfield* rcAllocHeightfield() { - rcHeightfield* hf = (rcHeightfield*)rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM); - memset(hf, 0, sizeof(rcHeightfield)); - return hf; + return new (rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM)) rcHeightfield; +} + +rcHeightfield::rcHeightfield() + : width() + , height() + , bmin() + , bmax() + , cs() + , ch() + , spans() + , pools() + , freelist() +{ +} + +rcHeightfield::~rcHeightfield() +{ + // Delete span array. + rcFree(spans); + // Delete span pools. + while (pools) + { + rcSpanPool* next = pools->next; + rcFree(pools); + pools = next; + } } void rcFreeHeightField(rcHeightfield* hf) { if (!hf) return; - // Delete span array. - rcFree(hf->spans); - // Delete span pools. - while (hf->pools) - { - rcSpanPool* next = hf->pools->next; - rcFree(hf->pools); - hf->pools = next; - } + hf->~rcHeightfield(); rcFree(hf); } @@ -109,7 +126,6 @@ void rcFreeCompactHeightfield(rcCompactHeightfield* chf) rcFree(chf); } - rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet() { rcHeightfieldLayerSet* lset = (rcHeightfieldLayerSet*)rcAlloc(sizeof(rcHeightfieldLayerSet), RC_ALLOC_PERM);