mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
minor changes to avoid compiler warnings and genrally clean up
This commit is contained in:
parent
54beeff1c6
commit
b83a894e91
@ -63,7 +63,7 @@ UniqueIdAllocator(U32 min, U32 max)
|
|||||||
for (U32 i=0; i<_size; ++i) {
|
for (U32 i=0; i<_size; ++i) {
|
||||||
_table[i]=i+1;
|
_table[i]=i+1;
|
||||||
}
|
}
|
||||||
_table[_size-1]=-1;
|
_table[_size-1]=IndexEnd;
|
||||||
_next_free=0;
|
_next_free=0;
|
||||||
_last_free=_size-1;
|
_last_free=_size-1;
|
||||||
_free=_size;
|
_free=_size;
|
||||||
@ -86,18 +86,19 @@ UniqueIdAllocator::
|
|||||||
// Access:
|
// Access:
|
||||||
// Description: Receive an id between _min and _max (that were passed
|
// Description: Receive an id between _min and _max (that were passed
|
||||||
// to the constructor).
|
// to the constructor).
|
||||||
// -1 is returned if no ids are available.
|
// IndexEnd is returned if no ids are available.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
U32 UniqueIdAllocator::
|
U32 UniqueIdAllocator::
|
||||||
allocate() {
|
allocate() {
|
||||||
if (_next_free==-1) {
|
if (_next_free==IndexEnd) {
|
||||||
// ...all ids allocated.
|
// ...all ids allocated.
|
||||||
uniqueIdAllocator_warning("allocate Error: no more free ids.");
|
uniqueIdAllocator_warning("allocate Error: no more free ids.");
|
||||||
return -1;
|
return IndexEnd;
|
||||||
}
|
}
|
||||||
U32 id=_min+_next_free;
|
U32 id=_min+_next_free;
|
||||||
_next_free=_table[_next_free];
|
_next_free=_table[_next_free];
|
||||||
nassertr(_table[id-_min]=-2, -1); // this assignment is debug only.
|
// This assert will not fire because it is assigning not comparing. This is intentional.
|
||||||
|
nassertr(_table[id-_min]=IndexAllocated, IndexEnd); // this assignment is debug only.
|
||||||
--_free;
|
--_free;
|
||||||
uniqueIdAllocator_debug("allocate() returning "<<id);
|
uniqueIdAllocator_debug("allocate() returning "<<id);
|
||||||
return id;
|
return id;
|
||||||
@ -116,10 +117,10 @@ free(U32 index) {
|
|||||||
nassertv(index>=_min); // Attempt to free out-of-range id.
|
nassertv(index>=_min); // Attempt to free out-of-range id.
|
||||||
nassertv(index<=_max); // Attempt to free out-of-range id.
|
nassertv(index<=_max); // Attempt to free out-of-range id.
|
||||||
index=index-_min; // Convert to _table index.
|
index=index-_min; // Convert to _table index.
|
||||||
nassertv(_table[index]==-2); // Attempt to free non-allocated id.
|
nassertv(_table[index]==IndexAllocated); // Attempt to free non-allocated id.
|
||||||
_table[index]=-1; // Mark this element as the end of the list.
|
_table[index]=IndexEnd; // Mark this element as the end of the list.
|
||||||
_table[_last_free]=index;
|
_table[_last_free]=index;
|
||||||
if (_next_free==-1) {
|
if (_next_free==IndexEnd) {
|
||||||
// ...the free list was empty.
|
// ...the free list was empty.
|
||||||
_next_free=index;
|
_next_free=index;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,10 @@ typedef unsigned long U32;
|
|||||||
// plus a few bytes of management data. e.g. 10,000
|
// plus a few bytes of management data. e.g. 10,000
|
||||||
// ID numbers will use 40KB.
|
// ID numbers will use 40KB.
|
||||||
//
|
//
|
||||||
|
// Also be advised that ID -1 and -2 are used internally by
|
||||||
|
// the allocator. If allocate returns IndexEnd (-1) then
|
||||||
|
// the allocator is out of free ID numbers.
|
||||||
|
//
|
||||||
// There are other implementations that can better leverage
|
// There are other implementations that can better leverage
|
||||||
// runs of used or unused IDs or use bit arrays for the
|
// runs of used or unused IDs or use bit arrays for the
|
||||||
// IDs. But, it takes extra work to track the age of
|
// IDs. But, it takes extra work to track the age of
|
||||||
@ -52,7 +56,11 @@ PUBLISHED:
|
|||||||
float percent_used() const;
|
float percent_used() const;
|
||||||
void output(ostream& os, bool verbose=false) const;
|
void output(ostream& os, bool verbose=false) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const U32 IndexEnd=(U32)-1;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static const U32 IndexAllocated=(U32)-2;
|
||||||
U32* _table;
|
U32* _table;
|
||||||
U32 _min;
|
U32 _min;
|
||||||
U32 _max;
|
U32 _max;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user