diff options
-rw-r--r-- | engine.c | 20 | ||||
-rw-r--r-- | engine.h | 22 | ||||
-rw-r--r-- | saveload.c | 2 |
3 files changed, 11 insertions, 33 deletions
@@ -450,13 +450,9 @@ bool IsEngineBuildable(uint engine, byte type) * 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 @@ static void EngineRenewPoolNewBlock(uint start_item) /* 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 @@ static EngineRenew *AllocateEngineRenew(void) /* 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 @@ static EngineRenew *AllocateEngineRenew(void) } /* 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 @@ static void Load_ERNW(void) 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 @@ const ChunkHandler _engine_chunk_handlers[] = { 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); } @@ -236,15 +236,7 @@ typedef struct EngineRenew EngineRenew; * 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 @@ static inline void DeleteEngineRenew(EngineRenew *er) 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). diff --git a/saveload.c b/saveload.c index a1bea9dd4..f728f6024 100644 --- a/saveload.c +++ b/saveload.c @@ -1273,7 +1273,7 @@ static void *IntToReference(uint index, SLRefType rt) 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); } |