Add more constructors.

This commit is contained in:
Maciej Babinski 2018-05-18 22:39:36 -05:00 committed by Jakob Botsch Nielsen
parent 9235b4a0c4
commit ba12abead9
2 changed files with 85 additions and 49 deletions

View File

@ -378,6 +378,8 @@ struct rcHeightfieldLayer
/// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet /// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet
struct rcHeightfieldLayerSet struct rcHeightfieldLayerSet
{ {
rcHeightfieldLayerSet();
~rcHeightfieldLayerSet();
rcHeightfieldLayer* layers; ///< The layers in the set. [Size: #nlayers] rcHeightfieldLayer* layers; ///< The layers in the set. [Size: #nlayers]
int nlayers; ///< The number of layers in the set. int nlayers; ///< The number of layers in the set.
}; };
@ -397,6 +399,8 @@ struct rcContour
/// @ingroup recast /// @ingroup recast
struct rcContourSet struct rcContourSet
{ {
rcContourSet();
~rcContourSet();
rcContour* conts; ///< An array of the contours in the set. [Size: #nconts] rcContour* conts; ///< An array of the contours in the set. [Size: #nconts]
int nconts; ///< The number of contours in the set. int nconts; ///< The number of contours in the set.
float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)]
@ -413,6 +417,8 @@ struct rcContourSet
/// @ingroup recast /// @ingroup recast
struct rcPolyMesh struct rcPolyMesh
{ {
rcPolyMesh();
~rcPolyMesh();
unsigned short* verts; ///< The mesh vertices. [Form: (x, y, z) * #nverts] unsigned short* verts; ///< The mesh vertices. [Form: (x, y, z) * #nverts]
unsigned short* polys; ///< Polygon and neighbor data. [Length: #maxpolys * 2 * #nvp] unsigned short* polys; ///< Polygon and neighbor data. [Length: #maxpolys * 2 * #nvp]
unsigned short* regs; ///< The region id assigned to each polygon. [Length: #maxpolys] unsigned short* regs; ///< The region id assigned to each polygon. [Length: #maxpolys]

View File

@ -98,7 +98,6 @@ rcHeightfield* rcAllocHeightfield()
{ {
return rcNew<rcHeightfield>(RC_ALLOC_PERM); return rcNew<rcHeightfield>(RC_ALLOC_PERM);
} }
rcHeightfield::rcHeightfield() rcHeightfield::rcHeightfield()
: width() : width()
, height() , height()
@ -141,22 +140,22 @@ void rcFreeCompactHeightfield(rcCompactHeightfield* chf)
} }
rcCompactHeightfield::rcCompactHeightfield() rcCompactHeightfield::rcCompactHeightfield()
: width(0), : width(),
height(0), height(),
spanCount(0), spanCount(),
walkableHeight(0), walkableHeight(),
walkableClimb(0), walkableClimb(),
borderSize(0), borderSize(),
maxDistance(0), maxDistance(),
maxRegions(0), maxRegions(),
bmin(), bmin(),
bmax(), bmax(),
cs(0), cs(),
ch(0), ch(),
cells(0), cells(),
spans(0), spans(),
dist(0), dist(),
areas(0) areas()
{ {
} }
rcCompactHeightfield::~rcCompactHeightfield() rcCompactHeightfield::~rcCompactHeightfield()
@ -169,60 +168,91 @@ rcCompactHeightfield::~rcCompactHeightfield()
rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet() rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet()
{ {
rcHeightfieldLayerSet* lset = (rcHeightfieldLayerSet*)rcAlloc(sizeof(rcHeightfieldLayerSet), RC_ALLOC_PERM); return rcNew<rcHeightfieldLayerSet>(RC_ALLOC_PERM);
memset(lset, 0, sizeof(rcHeightfieldLayerSet));
return lset;
} }
void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* lset) void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* lset)
{ {
if (!lset) return; rcDelete(lset);
for (int i = 0; i < lset->nlayers; ++i) }
rcHeightfieldLayerSet::rcHeightfieldLayerSet()
: layers(), nlayers() {}
rcHeightfieldLayerSet::~rcHeightfieldLayerSet()
{
for (int i = 0; i < nlayers; ++i)
{ {
rcFree(lset->layers[i].heights); rcFree(layers[i].heights);
rcFree(lset->layers[i].areas); rcFree(layers[i].areas);
rcFree(lset->layers[i].cons); rcFree(layers[i].cons);
} }
rcFree(lset->layers); rcFree(layers);
rcFree(lset);
} }
rcContourSet* rcAllocContourSet() rcContourSet* rcAllocContourSet()
{ {
rcContourSet* cset = (rcContourSet*)rcAlloc(sizeof(rcContourSet), RC_ALLOC_PERM); return rcNew<rcContourSet>(RC_ALLOC_PERM);
memset(cset, 0, sizeof(rcContourSet));
return cset;
} }
void rcFreeContourSet(rcContourSet* cset) void rcFreeContourSet(rcContourSet* cset)
{ {
if (!cset) return; rcDelete(cset);
for (int i = 0; i < cset->nconts; ++i)
{
rcFree(cset->conts[i].verts);
rcFree(cset->conts[i].rverts);
}
rcFree(cset->conts);
rcFree(cset);
} }
rcContourSet::rcContourSet()
: conts(),
nconts(),
bmin(),
bmax(),
cs(),
ch(),
width(),
height(),
borderSize(),
maxError() {}
rcContourSet::~rcContourSet()
{
for (int i = 0; i < nconts; ++i)
{
rcFree(conts[i].verts);
rcFree(conts[i].rverts);
}
rcFree(conts);
}
rcPolyMesh* rcAllocPolyMesh() rcPolyMesh* rcAllocPolyMesh()
{ {
rcPolyMesh* pmesh = (rcPolyMesh*)rcAlloc(sizeof(rcPolyMesh), RC_ALLOC_PERM); return rcNew<rcPolyMesh>(RC_ALLOC_PERM);
memset(pmesh, 0, sizeof(rcPolyMesh));
return pmesh;
} }
void rcFreePolyMesh(rcPolyMesh* pmesh) void rcFreePolyMesh(rcPolyMesh* pmesh)
{ {
if (!pmesh) return; rcDelete(pmesh);
rcFree(pmesh->verts); }
rcFree(pmesh->polys);
rcFree(pmesh->regs); rcPolyMesh::rcPolyMesh()
rcFree(pmesh->flags); : verts(),
rcFree(pmesh->areas); polys(),
rcFree(pmesh); regs(),
flags(),
areas(),
nverts(),
npolys(),
maxpolys(),
nvp(),
bmin(),
bmax(),
cs(),
ch(),
borderSize(),
maxEdgeError() {}
rcPolyMesh::~rcPolyMesh()
{
rcFree(verts);
rcFree(polys);
rcFree(regs);
rcFree(flags);
rcFree(areas);
} }
rcPolyMeshDetail* rcAllocPolyMeshDetail() rcPolyMeshDetail* rcAllocPolyMeshDetail()