Added Constructor and Destructor to rcHeightfield.

This commit is contained in:
grahamboree 2016-03-20 18:42:14 -04:00
parent d9c6fc58ce
commit 61dbce80e9
2 changed files with 37 additions and 13 deletions

View File

@ -293,6 +293,9 @@ struct rcSpanPool
/// @ingroup recast /// @ingroup recast
struct rcHeightfield struct rcHeightfield
{ {
rcHeightfield();
~rcHeightfield();
int width; ///< The width of the heightfield. (Along the x-axis in cell units.) 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.) 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)] 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). rcSpan** spans; ///< Heightfield of spans (width*height).
rcSpanPool* pools; ///< Linked list of span pools. rcSpanPool* pools; ///< Linked list of span pools.
rcSpan* freelist; ///< The next free span. 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. /// Provides information on the content of a cell column in a compact heightfield.

View File

@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <new>
#include "Recast.h" #include "Recast.h"
#include "RecastAlloc.h" #include "RecastAlloc.h"
#include "RecastAssert.h" #include "RecastAssert.h"
@ -72,23 +73,39 @@ void rcContext::log(const rcLogCategory category, const char* format, ...)
rcHeightfield* rcAllocHeightfield() rcHeightfield* rcAllocHeightfield()
{ {
rcHeightfield* hf = (rcHeightfield*)rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM); return new (rcAlloc(sizeof(rcHeightfield), RC_ALLOC_PERM)) rcHeightfield;
memset(hf, 0, sizeof(rcHeightfield)); }
return hf;
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) void rcFreeHeightField(rcHeightfield* hf)
{ {
if (!hf) return; if (!hf) return;
// Delete span array. hf->~rcHeightfield();
rcFree(hf->spans);
// Delete span pools.
while (hf->pools)
{
rcSpanPool* next = hf->pools->next;
rcFree(hf->pools);
hf->pools = next;
}
rcFree(hf); rcFree(hf);
} }
@ -109,7 +126,6 @@ void rcFreeCompactHeightfield(rcCompactHeightfield* chf)
rcFree(chf); rcFree(chf);
} }
rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet() rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet()
{ {
rcHeightfieldLayerSet* lset = (rcHeightfieldLayerSet*)rcAlloc(sizeof(rcHeightfieldLayerSet), RC_ALLOC_PERM); rcHeightfieldLayerSet* lset = (rcHeightfieldLayerSet*)rcAlloc(sizeof(rcHeightfieldLayerSet), RC_ALLOC_PERM);