mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-22 21:19:27 +01:00
(svn r6977) Use the pool macros for the EngineRenew pool
This commit is contained in:
parent
da500bc3e6
commit
1a4a7984a7
20
engine.c
20
engine.c
@ -450,13 +450,9 @@ bool IsEngineBuildable(uint engine, byte type)
|
|||||||
* Engine Replacement stuff
|
* Engine Replacement stuff
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
static void EngineRenewPoolNewBlock(uint start_item); /* Forward declare for initializer of _engine_renew_pool */
|
static void EngineRenewPoolNewBlock(uint start_item);
|
||||||
enum {
|
|
||||||
ENGINE_RENEW_POOL_BLOCK_SIZE_BITS = 3,
|
|
||||||
ENGINE_RENEW_POOL_MAX_BLOCKS = 8000,
|
|
||||||
};
|
|
||||||
|
|
||||||
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)
|
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.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* 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->index = start_item++;
|
||||||
er->from = INVALID_ENGINE;
|
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.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* 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;
|
if (IsValidEngineRenew(er)) continue;
|
||||||
|
|
||||||
er->to = INVALID_ENGINE;
|
er->to = INVALID_ENGINE;
|
||||||
@ -486,7 +482,7 @@ static EngineRenew *AllocateEngineRenew(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -603,7 +599,7 @@ static void Load_ERNW(void)
|
|||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
EngineRenew *er;
|
EngineRenew *er;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_engine_renew_pool, index))
|
if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
|
||||||
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
||||||
|
|
||||||
er = GetEngineRenew(index);
|
er = GetEngineRenew(index);
|
||||||
@ -670,6 +666,6 @@ const ChunkHandler _engine_chunk_handlers[] = {
|
|||||||
void InitializeEngines(void)
|
void InitializeEngines(void)
|
||||||
{
|
{
|
||||||
/* Clean the engine renew pool and create 1 block in it */
|
/* Clean the engine renew pool and create 1 block in it */
|
||||||
CleanPool(&_engine_renew_pool);
|
CleanPool(&_EngineRenew_pool);
|
||||||
AddBlockToPool(&_engine_renew_pool);
|
AddBlockToPool(&_EngineRenew_pool);
|
||||||
}
|
}
|
||||||
|
22
engine.h
22
engine.h
@ -236,15 +236,7 @@ typedef struct EngineRenew EngineRenew;
|
|||||||
* placed here so the only exception to this rule, the saveload code, can use
|
* placed here so the only exception to this rule, the saveload code, can use
|
||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
extern MemoryPool _engine_renew_pool;
|
DECLARE_POOL(EngineRenew, EngineRenew, 3, 8000)
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current size of the EngineRenewPool
|
|
||||||
*/
|
|
||||||
static inline uint16 GetEngineRenewPoolSize(void)
|
|
||||||
{
|
|
||||||
return _engine_renew_pool.total_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a EngineRenew really exists.
|
* Check if a EngineRenew really exists.
|
||||||
@ -259,19 +251,9 @@ static inline void DeleteEngineRenew(EngineRenew *er)
|
|||||||
er->from = INVALID_ENGINE;
|
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)
|
#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 list to group EngineRenew directives together (such as per-player).
|
||||||
|
@ -1273,7 +1273,7 @@ static void *IntToReference(uint index, SLRefType rt)
|
|||||||
return GetRoadStop(index);
|
return GetRoadStop(index);
|
||||||
}
|
}
|
||||||
case REF_ENGINE_RENEWS: {
|
case REF_ENGINE_RENEWS: {
|
||||||
if (!AddBlockIfNeeded(&_engine_renew_pool, index))
|
if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
|
||||||
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
||||||
return GetEngineRenew(index);
|
return GetEngineRenew(index);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user