(svn r6974) use the pool macros for the SpriteGroup pool
This commit is contained in:
		| @@ -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; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 tron
					tron