(svn r6974) use the pool macros for the SpriteGroup pool
authortron
Sat, 28 Oct 2006 10:55:26 +0000
changeset 4971 0a3653c45b5a
parent 4970 d5b2b619f48c
child 4972 af023b864bad
(svn r6974) use the pool macros for the SpriteGroup pool
newgrf_spritegroup.c
--- a/newgrf_spritegroup.c	Sat Oct 28 10:54:20 2006 +0000
+++ b/newgrf_spritegroup.c	Sat Oct 28 10:55:26 2006 +0000
@@ -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 @@
 	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;
 }