fixed a couple bugs in VoxelNodeBag

This commit is contained in:
ZappoMan 2013-04-26 00:46:29 -07:00
parent 17694b3f46
commit 2ba24e1716
2 changed files with 5 additions and 8 deletions

View file

@ -25,9 +25,6 @@ const int GROW_BAG_BY = 500;
// put a node into the bag
void VoxelNodeBag::insert(VoxelNode* node) {
printf("VoxelNodeBag::insert(node) node=");
node->printDebugDetails("");
// Search for where we should live in the bag (sorted)
// Note: change this to binary search... instead of linear!
int insertAt = _elementsInUse;
@ -60,13 +57,13 @@ node->printDebugDetails("");
if (oldBag) {
// copy old elements into the new bag, but leave a space where we need to
// insert the new node
memcpy(_bagElements, oldBag, insertAt);
memcpy(&_bagElements[insertAt+1], &oldBag[insertAt], (_elementsInUse-insertAt));
memcpy(_bagElements, oldBag, insertAt*sizeof(VoxelNode*));
memcpy(&_bagElements[insertAt+1], &oldBag[insertAt], (_elementsInUse-insertAt)*sizeof(VoxelNode*));
}
} else {
// move existing elements further back in the bag array, leave a space where we need to
// insert the new node
memcpy(&_bagElements[insertAt+1], &_bagElements[insertAt], (_elementsInUse-insertAt));
memmove(&_bagElements[insertAt+1], &_bagElements[insertAt], (_elementsInUse-insertAt)*sizeof(VoxelNode*));
}
_bagElements[insertAt] = node;
_elementsInUse++;

View file

@ -29,7 +29,7 @@ public:
void insert(VoxelNode* node); // put a node into the bag
VoxelNode* extract(); // pull a node out of the bag (could come in any order)
bool isEmpty() const { return (_elementsInUse > 0); }
bool isEmpty() const { return (_elementsInUse == 0); }
int count() const { return _elementsInUse; }
private: