mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r6974) use the pool macros for the SpriteGroup pool
This commit is contained in:
parent
41e34a1c16
commit
ef862a2973
|
@ -8,13 +8,10 @@
|
||||||
#include "newgrf_spritegroup.h"
|
#include "newgrf_spritegroup.h"
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
|
|
||||||
enum {
|
static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item);
|
||||||
SPRITEGROUP_POOL_BLOCK_SIZE_BITS = 4, /* (1 << 4) == 16 items */
|
|
||||||
SPRITEGROUP_POOL_MAX_BLOCKS = 8000,
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint _spritegroup_count = 0;
|
static uint _spritegroup_count = 0;
|
||||||
static MemoryPool _spritegroup_pool;
|
STATIC_POOL(SpriteGroup, SpriteGroup, 4, 8000, NULL, SpriteGroupPoolCleanBlock);
|
||||||
|
|
||||||
void DestroySpriteGroup(SpriteGroup *group)
|
void DestroySpriteGroup(SpriteGroup *group)
|
||||||
{
|
{
|
||||||
|
@ -45,29 +42,26 @@ static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item)
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
for (i = start_item; i <= end_item; i++) {
|
for (i = start_item; i <= end_item; i++) {
|
||||||
DestroySpriteGroup((SpriteGroup*)GetItemFromPool(&_spritegroup_pool, i));
|
DestroySpriteGroup(GetSpriteGroup(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the SpriteGroup pool */
|
|
||||||
static MemoryPool _spritegroup_pool = { "SpriteGr", SPRITEGROUP_POOL_MAX_BLOCKS, SPRITEGROUP_POOL_BLOCK_SIZE_BITS, sizeof(SpriteGroup), NULL, &SpriteGroupPoolCleanBlock, 0, 0, NULL };
|
|
||||||
|
|
||||||
|
|
||||||
/* Allocate a new SpriteGroup */
|
/* Allocate a new SpriteGroup */
|
||||||
SpriteGroup *AllocateSpriteGroup(void)
|
SpriteGroup *AllocateSpriteGroup(void)
|
||||||
{
|
{
|
||||||
/* This is totally different to the other pool allocators, as we never remove an item from the pool. */
|
/* This is totally different to the other pool allocators, as we never remove an item from the pool. */
|
||||||
if (_spritegroup_count == _spritegroup_pool.total_items) {
|
if (_spritegroup_count == GetSpriteGroupPoolSize()) {
|
||||||
if (!AddBlockToPool(&_spritegroup_pool)) return NULL;
|
if (!AddBlockToPool(&_SpriteGroup_pool)) return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (SpriteGroup*)GetItemFromPool(&_spritegroup_pool, _spritegroup_count++);
|
return GetSpriteGroup(_spritegroup_count++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InitializeSpriteGroupPool(void)
|
void InitializeSpriteGroupPool(void)
|
||||||
{
|
{
|
||||||
CleanPool(&_spritegroup_pool);
|
CleanPool(&_SpriteGroup_pool);
|
||||||
|
|
||||||
_spritegroup_count = 0;
|
_spritegroup_count = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue