From ef862a2973c0aa13932edc5d446ed04f7ad110c9 Mon Sep 17 00:00:00 2001 From: tron Date: Sat, 28 Oct 2006 10:55:26 +0000 Subject: (svn r6974) use the pool macros for the SpriteGroup pool --- newgrf_spritegroup.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/newgrf_spritegroup.c b/newgrf_spritegroup.c index 5ae33f4cb..1935dd4ea 100644 --- a/newgrf_spritegroup.c +++ b/newgrf_spritegroup.c @@ -8,13 +8,10 @@ #include "newgrf_spritegroup.h" #include "date.h" -enum { - SPRITEGROUP_POOL_BLOCK_SIZE_BITS = 4, /* (1 << 4) == 16 items */ - SPRITEGROUP_POOL_MAX_BLOCKS = 8000, -}; +static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item); static uint _spritegroup_count = 0; -static MemoryPool _spritegroup_pool; +STATIC_POOL(SpriteGroup, SpriteGroup, 4, 8000, NULL, SpriteGroupPoolCleanBlock); void DestroySpriteGroup(SpriteGroup *group) { @@ -45,29 +42,26 @@ static void SpriteGroupPoolCleanBlock(uint start_item, uint end_item) uint 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 */ SpriteGroup *AllocateSpriteGroup(void) { /* 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 (!AddBlockToPool(&_spritegroup_pool)) return NULL; + if (_spritegroup_count == GetSpriteGroupPoolSize()) { + if (!AddBlockToPool(&_SpriteGroup_pool)) return NULL; } - return (SpriteGroup*)GetItemFromPool(&_spritegroup_pool, _spritegroup_count++); + return GetSpriteGroup(_spritegroup_count++); } void InitializeSpriteGroupPool(void) { - CleanPool(&_spritegroup_pool); + CleanPool(&_SpriteGroup_pool); _spritegroup_count = 0; } -- cgit v1.2.3-70-g09d2