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()
|
void LPlanesPool::Reset()
|
||||||
{
|
{
|
||||||
memset(m_ucTaken, 0, sizeof ( m_ucTaken));
|
for (int n=0; n<POOL_MAX; n++)
|
||||||
m_uiCount = 0;
|
{
|
||||||
|
m_ucFreeList[n] = POOL_MAX - n - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_uiNumFree = POOL_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int LPlanesPool::Request()
|
unsigned int LPlanesPool::Request()
|
||||||
{
|
{
|
||||||
// can't do, pool run out
|
if (!m_uiNumFree)
|
||||||
if (m_uiCount >= POOL_MAX)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// could be done more efficiently .. NYI
|
m_uiNumFree--;
|
||||||
for (unsigned int n=0; n<POOL_MAX; n++)
|
return m_ucFreeList[m_uiNumFree];
|
||||||
{
|
|
||||||
if (m_ucTaken[n] == 0)
|
|
||||||
{
|
|
||||||
m_ucTaken[n] = 255;
|
|
||||||
m_uiCount++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LPlanesPool::Free(unsigned int ui)
|
void LPlanesPool::Free(unsigned int ui)
|
||||||
{
|
{
|
||||||
assert (ui <= POOL_MAX);
|
assert (ui <= POOL_MAX);
|
||||||
assert (m_ucTaken[ui]);
|
assert (m_uiNumFree < POOL_MAX);
|
||||||
assert (m_uiCount);
|
|
||||||
|
|
||||||
m_ucTaken[ui] = 0;
|
m_ucFreeList[m_uiNumFree] = ui;
|
||||||
m_uiCount--;
|
m_uiNumFree++;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
LPlanesPool();
|
LPlanesPool();
|
||||||
private:
|
private:
|
||||||
LVector<Plane> m_Planes[ POOL_MAX];
|
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