mirror of
https://github.com/Relintai/godot-lportal.git
synced 2024-11-11 10:52:09 +01:00
Improved pool
This commit is contained in:
parent
805b6153b6
commit
7f5eb565e1
@ -13,36 +13,29 @@ LPlanesPool::LPlanesPool()
|
||||
|
||||
void LPlanesPool::Reset()
|
||||
{
|
||||
memset(m_ucTaken, 0, sizeof ( m_ucTaken));
|
||||
m_uiCount = 0;
|
||||
for (int n=0; n<POOL_MAX; n++)
|
||||
{
|
||||
m_ucFreeList[n] = POOL_MAX - n - 1;
|
||||
}
|
||||
|
||||
m_uiNumFree = POOL_MAX;
|
||||
}
|
||||
|
||||
unsigned int LPlanesPool::Request()
|
||||
{
|
||||
// can't do, pool run out
|
||||
if (m_uiCount >= POOL_MAX)
|
||||
if (!m_uiNumFree)
|
||||
return -1;
|
||||
|
||||
// could be done more efficiently .. NYI
|
||||
for (unsigned int n=0; n<POOL_MAX; n++)
|
||||
{
|
||||
if (m_ucTaken[n] == 0)
|
||||
{
|
||||
m_ucTaken[n] = 255;
|
||||
m_uiCount++;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
m_uiNumFree--;
|
||||
return m_ucFreeList[m_uiNumFree];
|
||||
|
||||
assert (0);
|
||||
}
|
||||
|
||||
void LPlanesPool::Free(unsigned int ui)
|
||||
{
|
||||
assert (ui <= POOL_MAX);
|
||||
assert (m_ucTaken[ui]);
|
||||
assert (m_uiCount);
|
||||
assert (m_uiNumFree < POOL_MAX);
|
||||
|
||||
m_ucTaken[ui] = 0;
|
||||
m_uiCount--;
|
||||
m_ucFreeList[m_uiNumFree] = ui;
|
||||
m_uiNumFree++;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
LPlanesPool();
|
||||
private:
|
||||
LVector<Plane> m_Planes[ POOL_MAX];
|
||||
unsigned char m_ucTaken[POOL_MAX];
|
||||
unsigned int m_uiCount;
|
||||
|
||||
uint8_t m_ucFreeList[POOL_MAX];
|
||||
uint32_t m_uiNumFree;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user