Mercurial > hg > openttd
changeset 4974:c95f3fb53dcd draft
(svn r6977) Use the pool macros for the EngineRenew pool
author | tron <tron@openttd.org> |
---|---|
date | Sat, 28 Oct 2006 11:08:52 +0000 |
parents | 41cbe5852a02 |
children | 806e348f1bc1 |
files | engine.c engine.h saveload.c |
diffstat | 3 files changed, 11 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/engine.c +++ b/engine.c @@ -450,13 +450,9 @@ * Engine Replacement stuff ************************************************************************/ -static void EngineRenewPoolNewBlock(uint start_item); /* Forward declare for initializer of _engine_renew_pool */ -enum { - ENGINE_RENEW_POOL_BLOCK_SIZE_BITS = 3, - ENGINE_RENEW_POOL_MAX_BLOCKS = 8000, -}; +static void EngineRenewPoolNewBlock(uint start_item); -MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, NULL, 0, 0, NULL }; +DEFINE_POOL(EngineRenew, EngineRenew, EngineRenewPoolNewBlock, NULL) static void EngineRenewPoolNewBlock(uint start_item) { @@ -464,7 +460,7 @@ /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. * TODO - This is just a temporary stage, this will be removed. */ - for (er = GetEngineRenew(start_item); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL) { + for (er = GetEngineRenew(start_item); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) { er->index = start_item++; er->from = INVALID_ENGINE; } @@ -477,7 +473,7 @@ /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. * TODO - This is just a temporary stage, this will be removed. */ - for (er = GetEngineRenew(0); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL) { + for (er = GetEngineRenew(0); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) { if (IsValidEngineRenew(er)) continue; er->to = INVALID_ENGINE; @@ -486,7 +482,7 @@ } /* Check if we can add a block to the pool */ - if (AddBlockToPool(&_engine_renew_pool)) return AllocateEngineRenew(); + if (AddBlockToPool(&_EngineRenew_pool)) return AllocateEngineRenew(); return NULL; } @@ -603,7 +599,7 @@ while ((index = SlIterateArray()) != -1) { EngineRenew *er; - if (!AddBlockIfNeeded(&_engine_renew_pool, index)) + if (!AddBlockIfNeeded(&_EngineRenew_pool, index)) error("EngineRenews: failed loading savegame: too many EngineRenews"); er = GetEngineRenew(index); @@ -670,6 +666,6 @@ void InitializeEngines(void) { /* Clean the engine renew pool and create 1 block in it */ - CleanPool(&_engine_renew_pool); - AddBlockToPool(&_engine_renew_pool); + CleanPool(&_EngineRenew_pool); + AddBlockToPool(&_EngineRenew_pool); }
--- a/engine.h +++ b/engine.h @@ -236,15 +236,7 @@ * placed here so the only exception to this rule, the saveload code, can use * it. */ -extern MemoryPool _engine_renew_pool; - -/** - * Get the current size of the EngineRenewPool - */ -static inline uint16 GetEngineRenewPoolSize(void) -{ - return _engine_renew_pool.total_items; -} +DECLARE_POOL(EngineRenew, EngineRenew, 3, 8000) /** * Check if a EngineRenew really exists. @@ -259,19 +251,9 @@ er->from = INVALID_ENGINE; } -#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL) if (er->from != INVALID_ENGINE) if (IsValidEngineRenew(er)) +#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->from != INVALID_ENGINE) if (IsValidEngineRenew(er)) #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) -/** - * DO NOT USE outside of engine.c. Is - * placed here so the only exception to this rule, the saveload code, can use - * it. - */ -static inline EngineRenew *GetEngineRenew(uint16 index) -{ - return (EngineRenew*)GetItemFromPool(&_engine_renew_pool, index); -} - /** * A list to group EngineRenew directives together (such as per-player).
--- a/saveload.c +++ b/saveload.c @@ -1273,7 +1273,7 @@ return GetRoadStop(index); } case REF_ENGINE_RENEWS: { - if (!AddBlockIfNeeded(&_engine_renew_pool, index)) + if (!AddBlockIfNeeded(&_EngineRenew_pool, index)) error("EngineRenews: failed loading savegame: too many EngineRenews"); return GetEngineRenew(index); }