1
0
Fork 0

(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.

release/0.6
rubidium 2007-08-03 20:18:38 +00:00
parent 9741094464
commit 2dd7a5d296
8 changed files with 30 additions and 48 deletions

View File

@ -1943,8 +1943,8 @@ void IndustryMonthlyLoop()
void InitializeIndustries() void InitializeIndustries()
{ {
CleanPool(&_Industry_pool); _Industry_pool.CleanPool();
AddBlockToPool(&_Industry_pool); _Industry_pool.AddBlockToPool();
ResetIndustryCounts(); ResetIndustryCounts();
_industry_sort_dirty = true; _industry_sort_dirty = true;

View File

@ -20,7 +20,7 @@ STATIC_OLD_POOL(SoundInternal, FileEntry, 3, 1000, NULL, NULL)
FileEntry *AllocateFileEntry() FileEntry *AllocateFileEntry()
{ {
if (_sound_count == GetSoundInternalPoolSize()) { if (_sound_count == GetSoundInternalPoolSize()) {
if (!AddBlockToPool(&_SoundInternal_pool)) return NULL; if (!_SoundInternal_pool.AddBlockToPool()) return NULL;
} }
return GetSoundInternal(_sound_count++); return GetSoundInternal(_sound_count++);
@ -29,7 +29,7 @@ FileEntry *AllocateFileEntry()
void InitializeSoundPool() void InitializeSoundPool()
{ {
CleanPool(&_SoundInternal_pool); _SoundInternal_pool.CleanPool();
_sound_count = 0; _sound_count = 0;
/* Copy original sound data to the pool */ /* Copy original sound data to the pool */

View File

@ -62,7 +62,7 @@ SpriteGroup *AllocateSpriteGroup()
{ {
/* This is totally different to the other pool allocators, as we never remove an item from the pool. */ /* This is totally different to the other pool allocators, as we never remove an item from the pool. */
if (_spritegroup_count == GetSpriteGroupPoolSize()) { if (_spritegroup_count == GetSpriteGroupPoolSize()) {
if (!AddBlockToPool(&_SpriteGroup_pool)) return NULL; if (!_SpriteGroup_pool.AddBlockToPool()) return NULL;
} }
return GetSpriteGroup(_spritegroup_count++); return GetSpriteGroup(_spritegroup_count++);
@ -71,7 +71,7 @@ SpriteGroup *AllocateSpriteGroup()
void InitializeSpriteGroupPool() void InitializeSpriteGroupPool()
{ {
CleanPool(&_SpriteGroup_pool); _SpriteGroup_pool.CleanPool();
_spritegroup_count = 0; _spritegroup_count = 0;
} }

View File

@ -106,24 +106,6 @@ struct OldMemoryPool : public OldMemoryPoolBase {
} }
}; };
/**
* Those are the wrappers:
* CleanPool cleans the pool up, but you can use AddBlockToPool directly again
* (no need to call CreatePool!)
* AddBlockToPool adds 1 more block to the pool. Returns false if there is no
* more room
*/
static inline void CleanPool(OldMemoryPoolBase *array) { array->CleanPool(); }
static inline bool AddBlockToPool(OldMemoryPoolBase *array) { return array->AddBlockToPool(); }
/**
* Adds blocks to the pool if needed (and possible) till index fits inside the pool
*
* @return Returns false if adding failed
*/
static inline bool AddBlockIfNeeded(OldMemoryPoolBase *array, uint index) { return array->AddBlockIfNeeded(index); }
/** /**
* Generic function to initialize a new block in a pool. * Generic function to initialize a new block in a pool.
* @param start_item the first item that needs to be initialized * @param start_item the first item that needs to be initialized

View File

@ -302,14 +302,14 @@ static void UnInitializeGame()
UnInitializeAirports(); UnInitializeAirports();
/* Uninitialize variables that are allocated dynamically */ /* Uninitialize variables that are allocated dynamically */
CleanPool(&_Town_pool); _Town_pool.CleanPool();
CleanPool(&_Industry_pool); _Industry_pool.CleanPool();
CleanPool(&_Station_pool); _Station_pool.CleanPool();
CleanPool(&_Vehicle_pool); _Vehicle_pool.CleanPool();
CleanPool(&_Sign_pool); _Sign_pool.CleanPool();
CleanPool(&_Order_pool); _Order_pool.CleanPool();
CleanPool(&_Group_pool); _Group_pool.CleanPool();
CleanPool(&_CargoPacket_pool); _CargoPacket_pool.CleanPool();
free((void*)_town_sort); free((void*)_town_sort);
free((void*)_industry_sort); free((void*)_industry_sort);

View File

@ -1269,8 +1269,8 @@ bool CheckForValidOrders(const Vehicle* v)
void InitializeOrders() void InitializeOrders()
{ {
CleanPool(&_Order_pool); _Order_pool.CleanPool();
AddBlockToPool(&_Order_pool); _Order_pool.AddBlockToPool();
_backup_orders_tile = 0; _backup_orders_tile = 0;
} }

View File

@ -1122,8 +1122,8 @@ static bool InitMem()
{ {
_ts.count = 0; _ts.count = 0;
CleanPool(&_Savegame_pool); _Savegame_pool.CleanPool();
AddBlockToPool(&_Savegame_pool); _Savegame_pool.AddBlockToPool();
/* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */ /* A block from the pool is a contigious area of memory, so it is safe to write to it sequentially */
_sl.bufsize = GetSavegamePoolSize(); _sl.bufsize = GetSavegamePoolSize();
@ -1133,14 +1133,14 @@ static bool InitMem()
static void UnInitMem() static void UnInitMem()
{ {
CleanPool(&_Savegame_pool); _Savegame_pool.CleanPool();
} }
static void WriteMem(uint size) static void WriteMem(uint size)
{ {
_ts.count += size; _ts.count += size;
/* Allocate new block and new buffer-pointer */ /* Allocate new block and new buffer-pointer */
AddBlockIfNeeded(&_Savegame_pool, _ts.count); _Savegame_pool.AddBlockIfNeeded(_ts.count);
_sl.buf = GetSavegame(_ts.count); _sl.buf = GetSavegame(_ts.count);
} }
@ -1343,37 +1343,37 @@ static void *IntToReference(uint index, SLRefType rt)
switch (rt) { switch (rt) {
case REF_ORDER: { case REF_ORDER: {
if (!AddBlockIfNeeded(&_Order_pool, index)) if (!_Order_pool.AddBlockIfNeeded(index))
error("Orders: failed loading savegame: too many orders"); error("Orders: failed loading savegame: too many orders");
return GetOrder(index); return GetOrder(index);
} }
case REF_VEHICLE: { case REF_VEHICLE: {
if (!AddBlockIfNeeded(&_Vehicle_pool, index)) if (!_Vehicle_pool.AddBlockIfNeeded(index))
error("Vehicles: failed loading savegame: too many vehicles"); error("Vehicles: failed loading savegame: too many vehicles");
return GetVehicle(index); return GetVehicle(index);
} }
case REF_STATION: { case REF_STATION: {
if (!AddBlockIfNeeded(&_Station_pool, index)) if (!_Station_pool.AddBlockIfNeeded(index))
error("Stations: failed loading savegame: too many stations"); error("Stations: failed loading savegame: too many stations");
return GetStation(index); return GetStation(index);
} }
case REF_TOWN: { case REF_TOWN: {
if (!AddBlockIfNeeded(&_Town_pool, index)) if (!_Town_pool.AddBlockIfNeeded(index))
error("Towns: failed loading savegame: too many towns"); error("Towns: failed loading savegame: too many towns");
return GetTown(index); return GetTown(index);
} }
case REF_ROADSTOPS: { case REF_ROADSTOPS: {
if (!AddBlockIfNeeded(&_RoadStop_pool, index)) if (!_RoadStop_pool.AddBlockIfNeeded(index))
error("RoadStops: failed loading savegame: too many RoadStops"); error("RoadStops: failed loading savegame: too many RoadStops");
return GetRoadStop(index); return GetRoadStop(index);
} }
case REF_ENGINE_RENEWS: { case REF_ENGINE_RENEWS: {
if (!AddBlockIfNeeded(&_EngineRenew_pool, index)) if (!_EngineRenew_pool.AddBlockIfNeeded(index))
error("EngineRenews: failed loading savegame: too many EngineRenews"); error("EngineRenews: failed loading savegame: too many EngineRenews");
return GetEngineRenew(index); return GetEngineRenew(index);
} }
case REF_CARGO_PACKET: { case REF_CARGO_PACKET: {
if (!AddBlockIfNeeded(&_CargoPacket_pool, index)) if (!_CargoPacket_pool.AddBlockIfNeeded(index))
error("CargoPackets: failed loading savegame: too many Cargo packets"); error("CargoPackets: failed loading savegame: too many Cargo packets");
return GetCargoPacket(index); return GetCargoPacket(index);
} }
@ -1386,7 +1386,7 @@ static void *IntToReference(uint index, SLRefType rt)
if (index == INVALID_VEHICLE) if (index == INVALID_VEHICLE)
return NULL; return NULL;
if (!AddBlockIfNeeded(&_Vehicle_pool, index)) if (!_Vehicle_pool.AddBlockIfNeeded(index))
error("Vehicles: failed loading savegame: too many vehicles"); error("Vehicles: failed loading savegame: too many vehicles");
return GetVehicle(index); return GetVehicle(index);
} }

View File

@ -2292,8 +2292,8 @@ void InitializeTowns()
Subsidy *s; Subsidy *s;
/* Clean the town pool and create 1 block in it */ /* Clean the town pool and create 1 block in it */
CleanPool(&_Town_pool); _Town_pool.CleanPool();
AddBlockToPool(&_Town_pool); _Town_pool.AddBlockToPool();
memset(_subsidies, 0, sizeof(_subsidies)); memset(_subsidies, 0, sizeof(_subsidies));
for (s=_subsidies; s != endof(_subsidies); s++) for (s=_subsidies; s != endof(_subsidies); s++)