From c1d167ae14e810e6820a0b98635ede09027a0947 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 2 Aug 2007 22:32:47 +0000 Subject: (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class. --- src/engine.h | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'src/engine.h') diff --git a/src/engine.h b/src/engine.h index cd238b8a6..6ee7d18c4 100644 --- a/src/engine.h +++ b/src/engine.h @@ -262,40 +262,32 @@ static inline const RoadVehicleInfo* RoadVehInfo(EngineID e) * Engine Replacement stuff ************************************************************************/ +struct EngineRenew; /** - * Struct to store engine replacements. DO NOT USE outside of engine.c. Is + * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is * placed here so the only exception to this rule, the saveload code, can use * it. */ -struct EngineRenew { - EngineRenewID index; - EngineID from; - EngineID to; - EngineRenew *next; - GroupID group_id; -}; +DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) /** - * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is + * Struct to store engine replacements. DO NOT USE outside of engine.c. Is * placed here so the only exception to this rule, the saveload code, can use * it. */ -DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) +struct EngineRenew : PoolItem { + EngineID from; + EngineID to; + EngineRenew *next; + GroupID group_id; -/** - * Check if a EngineRenew really exists. - */ -static inline bool IsValidEngineRenew(const EngineRenew *er) -{ - return er->from != INVALID_ENGINE; -} + EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {} + ~EngineRenew() { this->from = INVALID_ENGINE; } -static inline void DeleteEngineRenew(EngineRenew *er) -{ - er->from = INVALID_ENGINE; -} + bool IsValid() const { return this->from != INVALID_ENGINE; } +}; -#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_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->IsValid()) #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) -- cgit v1.2.3-70-g09d2