godot-lportal/lplanes_pool.cpp

42 lines
597 B
C++
Raw Permalink Normal View History

#include "lplanes_pool.h"
LPlanesPool::LPlanesPool()
{
Reset();
// preallocate the vectors to a reasonable size
for (int n=0; n<POOL_MAX; n++)
{
m_Planes[n].reserve(32);
}
}
void LPlanesPool::Reset()
{
2019-09-25 08:48:35 +02:00
for (int n=0; n<POOL_MAX; n++)
{
m_ucFreeList[n] = POOL_MAX - n - 1;
}
m_uiNumFree = POOL_MAX;
}
unsigned int LPlanesPool::Request()
{
2019-09-25 08:48:35 +02:00
if (!m_uiNumFree)
return -1;
2019-09-25 08:48:35 +02:00
m_uiNumFree--;
return m_ucFreeList[m_uiNumFree];
}
void LPlanesPool::Free(unsigned int ui)
{
assert (ui <= POOL_MAX);
2019-09-25 08:48:35 +02:00
assert (m_uiNumFree < POOL_MAX);
2019-09-25 08:48:35 +02:00
m_ucFreeList[m_uiNumFree] = ui;
m_uiNumFree++;
}