// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION // // This software is supplied under the terms of a license agreement or // nondisclosure agreement with Emergent Game Technologies and may not // be copied or disclosed except in accordance with the terms of that // agreement. // // Copyright (c) 1996-2007 Emergent Game Technologies. // All Rights Reserved. // // Emergent Game Technologies, Chapel Hill, North Carolina 27517 // http://www.emergent.net //--------------------------------------------------------------------------- template inline NiTPoolContainer::NiTPoolContainer(unsigned int uiSize) : m_uiSize(uiSize), m_pkNext(NULL) { if (uiSize > 0) { m_pkObjectArray = TAlloc::Allocate(uiSize); NIASSERT(m_pkObjectArray != NULL); } else { m_pkObjectArray = NULL; } } //--------------------------------------------------------------------------- template inline NiTPoolContainer::~NiTPoolContainer() { TAlloc::Deallocate(m_pkObjectArray); NiDelete m_pkNext; } //--------------------------------------------------------------------------- template inline T* NiTPoolContainer::GetObject(unsigned int uiIndex) { if (uiIndex >= m_uiSize) return NULL; return &m_pkObjectArray[uiIndex]; } //--------------------------------------------------------------------------- template inline void NiTPoolContainer::SetNext(NiTPoolContainer* pkNext) { m_pkNext = pkNext; } //--------------------------------------------------------------------------- template inline NiTPool::NiTPool(unsigned int uiInitialSize) : m_pkContainers(NULL), m_uiCurrentSize(uiInitialSize), m_uiInitialSize(uiInitialSize) { NIASSERT(uiInitialSize > 0); } //--------------------------------------------------------------------------- template inline NiTPool::~NiTPool() { m_kFreeObjects.RemoveAll(); NiDelete m_pkContainers; } //--------------------------------------------------------------------------- template inline T* NiTPool::GetFreeObject() { if (m_kFreeObjects.GetSize() == 0) { CreateNewObjects(m_uiCurrentSize); m_uiCurrentSize *= 2; } T* pkReturn = m_kFreeObjects.GetAt(0); m_kFreeObjects.RemoveAt(0); return pkReturn; } //--------------------------------------------------------------------------- template inline void NiTPool::ReleaseObject(T* pkObject) { m_kFreeObjects.AddUnique(pkObject); } //--------------------------------------------------------------------------- template inline void NiTPool::CreateNewObjects(unsigned int uiSize) { NiTPoolContainer* pkNewContainer = NiNew NiTPoolContainer(uiSize); for (unsigned int i = 0; i < uiSize; i++) { m_kFreeObjects.Add(pkNewContainer->GetObject(i)); } pkNewContainer->SetNext(m_pkContainers); m_pkContainers = pkNewContainer; } //--------------------------------------------------------------------------- template inline void NiTPool::PurgeAllObjects() { m_kFreeObjects.RemoveAll(); NiDelete m_pkContainers; m_pkContainers = NULL; m_uiCurrentSize = m_uiInitialSize; } //--------------------------------------------------------------------------- template inline NiTObjectPool::NiTObjectPool(unsigned int uiInitialSize) : NiTPool >(uiInitialSize) { } //--------------------------------------------------------------------------- template inline NiTPrimitivePool::NiTPrimitivePool(unsigned int uiInitialSize) : NiTPool >(uiInitialSize) { } //---------------------------------------------------------------------------