Changeset - r7413:3ccdde9800e0
[Not reviewed]
master
0 15 0
rubidium - 17 years ago 2007-08-05 21:20:55
rubidium@openttd.org
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
15 files changed with 48 insertions and 67 deletions:
0 comments (0 inline, 0 general)
src/depot.cpp
Show inline comments
 
@@ -28,24 +28,26 @@ Depot *GetDepotByTile(TileIndex tile)
 
	FOR_ALL_DEPOTS(depot) {
 
		if (depot->xy == tile) return depot;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
/**
 
 * Clean up a depot
 
 */
 
Depot::~Depot()
 
{
 
	if (CleaningPool()) return;
 

	
 
	/* Clear the depot from all order-lists */
 
	RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
 

	
 
	/* Delete the depot-window */
 
	DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
 
	this->xy = 0;
 
}
 

	
 
void InitializeDepots()
 
{
 
	_Depot_pool.CleanPool();
 
	_Depot_pool.AddBlockToPool();
src/group.h
Show inline comments
 
@@ -20,26 +20,24 @@ struct Group : PoolItem<Group, GroupID, 
 
	StringID string_id;                     ///< Group Name
 

	
 
	uint16 num_vehicle;                     ///< Number of vehicles wich belong to the group
 
	PlayerID owner;                         ///< Group Owner
 
	VehicleTypeByte vehicle_type;           ///< Vehicle type of the group
 

	
 
	bool replace_protection;                ///< If set to true, the global autoreplace have no effect on the group
 
	uint16 num_engines[TOTAL_NUM_ENGINES];  ///< Caches the number of engines of each type the player owns (no need to save this)
 

	
 
	Group(StringID str = STR_NULL);
 
	virtual ~Group();
 

	
 
	void QuickFree();
 

	
 
	bool IsValid() const;
 
};
 

	
 

	
 
static inline bool IsValidGroupID(GroupID index)
 
{
 
	return index < GetGroupPoolSize() && GetGroup(index)->IsValid();
 
}
 

	
 
static inline bool IsDefaultGroupID(GroupID index)
 
{
 
	return index == DEFAULT_GROUP;
src/group_cmd.cpp
Show inline comments
 
@@ -41,33 +41,28 @@ static inline void UpdateNumEngineGroup(
 

	
 

	
 
DEFINE_OLD_POOL_GENERIC(Group, Group)
 

	
 

	
 
Group::Group(StringID str)
 
{
 
	this->string_id = str;
 
}
 

	
 
Group::~Group()
 
{
 
	this->QuickFree();
 
	DeleteName(this->string_id);
 
	this->string_id = STR_NULL;
 
}
 

	
 
void Group::QuickFree()
 
{
 
	DeleteName(this->string_id);
 
}
 

	
 
bool Group::IsValid() const
 
{
 
	return this->string_id != STR_NULL;
 
}
 

	
 
void InitializeGroup(void)
 
{
 
	_Group_pool.CleanPool();
 
	_Group_pool.AddBlockToPool();
 
}
 

	
 

	
src/oldpool.cpp
Show inline comments
 
@@ -9,31 +9,33 @@
 
#include "oldpool.h"
 
#include "helpers.hpp"
 

	
 
/**
 
 * Clean a pool in a safe way (does free all blocks)
 
 */
 
void OldMemoryPoolBase::CleanPool()
 
{
 
	uint i;
 

	
 
	DEBUG(misc, 4, "[Pool] (%s) cleaning pool..", this->name);
 

	
 
	this->cleaning_pool = true;
 
	/* Free all blocks */
 
	for (i = 0; i < this->current_blocks; i++) {
 
		if (this->clean_block_proc != NULL) {
 
			this->clean_block_proc(i * (1 << this->block_size_bits), (i + 1) * (1 << this->block_size_bits) - 1);
 
		}
 
		free(this->blocks[i]);
 
	}
 
	this->cleaning_pool = false;
 

	
 
	/* Free the block itself */
 
	free(this->blocks);
 

	
 
	/* Clear up some critical data */
 
	this->total_items = 0;
 
	this->current_blocks = 0;
 
	this->blocks = NULL;
 
	this->first_free_index = 0;
 
}
 

	
 
/**
src/oldpool.h
Show inline comments
 
@@ -16,39 +16,40 @@ typedef void OldMemoryPoolCleanBlock(uin
 
 *  please try to avoid manual calls!
 
 */
 
struct OldMemoryPoolBase {
 
	void CleanPool();
 
	bool AddBlockToPool();
 
	bool AddBlockIfNeeded(uint index);
 

	
 
protected:
 
	OldMemoryPoolBase(const char *name, uint max_blocks, uint block_size_bits, uint item_size,
 
				OldMemoryPoolNewBlock *new_block_proc, OldMemoryPoolCleanBlock *clean_block_proc) :
 
		name(name), max_blocks(max_blocks), block_size_bits(block_size_bits),
 
		new_block_proc(new_block_proc), clean_block_proc(clean_block_proc), current_blocks(0),
 
		total_items(0), item_size(item_size), first_free_index(0), blocks(NULL) {}
 
		total_items(0), cleaning_pool(false), item_size(item_size), first_free_index(0), blocks(NULL) {}
 

	
 
	const char* name;     ///< Name of the pool (just for debugging)
 

	
 
	const uint max_blocks;      ///< The max amount of blocks this pool can have
 
	const uint block_size_bits; ///< The size of each block in bits
 

	
 
	/// Pointer to a function that is called after a new block is added
 
	OldMemoryPoolNewBlock *new_block_proc;
 
	/// Pointer to a function that is called to clean a block
 
	OldMemoryPoolCleanBlock *clean_block_proc;
 

	
 
	uint current_blocks;        ///< How many blocks we have in our pool
 
	uint total_items;           ///< How many items we now have in this pool
 

	
 
	bool cleaning_pool;         ///< Are we currently cleaning the pool?
 
public:
 
	const uint item_size;       ///< How many bytes one block is
 
	uint first_free_index;      ///< The index of the first free pool item in this pool
 
	byte **blocks;              ///< An array of blocks (one block hold all the items)
 

	
 
	/**
 
	 * Get the size of this pool, i.e. the total number of items you
 
	 * can put into it at the current moment; the pool might still
 
	 * be able to increase the size of the pool.
 
	 * @return the size of the pool
 
	 */
 
	inline uint GetSize() const
 
@@ -75,24 +76,33 @@ public:
 
	{
 
		return this->current_blocks;
 
	}
 

	
 
	/**
 
	 * Get the name of this pool.
 
	 * @return the name
 
	 */
 
	inline const char *GetName() const
 
	{
 
		return this->name;
 
	}
 

	
 
	/**
 
	 * Is the pool in the cleaning phase?
 
	 * @return true if it is
 
	 */
 
	inline bool CleaningPool() const
 
	{
 
		return this->cleaning_pool;
 
	}
 
};
 

	
 
template <typename T>
 
struct OldMemoryPool : public OldMemoryPoolBase {
 
	OldMemoryPool(const char *name, uint max_blocks, uint block_size_bits, uint item_size,
 
				OldMemoryPoolNewBlock *new_block_proc, OldMemoryPoolCleanBlock *clean_block_proc) :
 
		OldMemoryPoolBase(name, max_blocks, block_size_bits, item_size, new_block_proc, clean_block_proc) {}
 

	
 
	/**
 
	 * Get the pool entry at the given index.
 
	 * @param index the index into the pool
 
	 * @pre index < this->GetSize()
 
@@ -112,69 +122,57 @@ struct OldMemoryPool : public OldMemoryP
 
 */
 
template <typename T, OldMemoryPool<T> *Tpool>
 
static void PoolNewBlock(uint start_item)
 
{
 
	for (T *t = Tpool->Get(start_item); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) {
 
		t = new (t) T();
 
		t->index = start_item++;
 
	}
 
}
 

	
 
/**
 
 * Generic function to free a new block in a pool.
 
 * This function uses QuickFree that is intended to only free memory that would be lost if the pool is freed.
 
 * @param start_item the first item that needs to be cleaned
 
 * @param end_item   the last item that needs to be cleaned
 
 */
 
template <typename T, OldMemoryPool<T> *Tpool>
 
static void PoolCleanBlock(uint start_item, uint end_item)
 
{
 
	for (uint i = start_item; i <= end_item; i++) {
 
		T *t = Tpool->Get(i);
 
		if (t->IsValid()) {
 
			t->QuickFree();
 
		}
 
		delete t;
 
	}
 
}
 

	
 

	
 
/**
 
 * Generalization for all pool items that are saved in the savegame.
 
 * It specifies all the mechanics to access the pool easily.
 
 */
 
template <typename T, typename Tid, OldMemoryPool<T> *Tpool>
 
struct PoolItem {
 
	/**
 
	 * The pool-wide index of this object.
 
	 */
 
	Tid index;
 

	
 
	/**
 
	 * We like to have the correct class destructed.
 
	 */
 
	virtual ~PoolItem()
 
	{
 
		if (this->index < Tpool->first_free_index) Tpool->first_free_index = this->index;
 
	}
 

	
 
	/**
 
	 * Called on each object when the pool is being destroyed, so one
 
	 * can free allocated memory without the need for freeing for
 
	 * example orders.
 
	 */
 
	virtual void QuickFree()
 
	{
 
	}
 

	
 
	/**
 
	 * An overriden version of new that allocates memory on the pool.
 
	 * @param size the size of the variable (unused)
 
	 * @return the memory that is 'allocated'
 
	 */
 
	void *operator new(size_t size)
 
	{
 
		return AllocateRaw();
 
	}
 

	
 
	/**
 
	 * 'Free' the memory allocated by the overriden new.
 
	 * @param p the memory to 'free'
 
@@ -232,54 +230,63 @@ struct PoolItem {
 
	 * @return true if and only if it is valid
 
	 */
 
	virtual bool IsValid() const
 
	{
 
		return false;
 
	}
 

	
 
protected:
 
	/**
 
	 * Allocate a pool item; possibly allocate a new block in the pool.
 
	 * @return the allocated pool item (or NULL when the pool is full).
 
	 */
 
	static T *AllocateRaw()
 
	static inline T *AllocateRaw()
 
	{
 
		return AllocateRaw(Tpool->first_free_index);
 
	}
 

	
 
	/**
 
	 * Allocate a pool item; possibly allocate a new block in the pool.
 
	 * @param first the first pool item to start searching
 
	 * @return the allocated pool item (or NULL when the pool is full).
 
	 */
 
	static T *AllocateRaw(uint &first)
 
	static inline T *AllocateRaw(uint &first)
 
	{
 
		uint last_minus_one = Tpool->GetSize() - 1;
 

	
 
		for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
 
			if (!t->IsValid()) {
 
				first = t->index;
 
				Tid index = t->index;
 

	
 
				memset(t, 0, Tpool->item_size);
 
				t->index = index;
 
				return t;
 
			}
 
		}
 

	
 
		/* Check if we can add a block to the pool */
 
		if (Tpool->AddBlockToPool()) return AllocateRaw(first);
 

	
 
		return NULL;
 
	}
 

	
 
	/**
 
	 * Are we cleaning this pool?
 
	 * @return true if we are
 
	 */
 
	static inline bool CleaningPool()
 
	{
 
		return Tpool->CleaningPool();
 
	}
 
};
 

	
 

	
 
#define OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \
 
	enum { \
 
		name##_POOL_BLOCK_SIZE_BITS = block_size_bits, \
 
		name##_POOL_MAX_BLOCKS      = max_blocks \
 
	};
 

	
 

	
 
#define OLD_POOL_ACCESSORS(name, type) \
 
	static inline type* Get##name(uint index) { return _##name##_pool.Get(index);  } \
src/signs.cpp
Show inline comments
 
@@ -19,33 +19,28 @@ SignID _new_sign_id;
 
uint _total_signs;
 

	
 
/* Initialize the sign-pool */
 
DEFINE_OLD_POOL_GENERIC(Sign, Sign)
 

	
 
Sign::Sign(StringID string)
 
{
 
	this->str = string;
 
}
 

	
 
Sign::~Sign()
 
{
 
	this->QuickFree();
 
	DeleteName(this->str);
 
	this->str = STR_NULL;
 
}
 

	
 
void Sign::QuickFree()
 
{
 
	DeleteName(this->str);
 
}
 

	
 
/**
 
 *
 
 * Update the coordinate of one sign
 
 * @param si Pointer to the Sign
 
 *
 
 */
 
static void UpdateSignVirtCoords(Sign *si)
 
{
 
	Point pt = RemapCoords(si->x, si->y, si->z);
 
	SetDParam(0, si->index);
 
	UpdateViewportSignPos(&si->sign, pt.x, pt.y - 6, STR_2806);
 
}
src/signs.h
Show inline comments
 
@@ -18,26 +18,24 @@ struct Sign : PoolItem<Sign, SignID, &_S
 
	byte         z;
 
	PlayerByte   owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games.
 

	
 
	/**
 
	 * Creates a new sign
 
	 */
 
	Sign(StringID string = STR_NULL);
 

	
 
	/** Destroy the sign */
 
	~Sign();
 

	
 
	bool IsValid() const { return this->str != STR_NULL; }
 

	
 
	void QuickFree();
 
};
 

	
 
enum {
 
	INVALID_SIGN = 0xFFFF,
 
};
 

	
 
extern SignID _new_sign_id;
 

	
 

	
 
static inline SignID GetMaxSignIndex()
 
{
 
	/* TODO - This isn't the real content of the function, but
src/station.cpp
Show inline comments
 
@@ -55,49 +55,46 @@ Station::Station(TileIndex tile)
 
}
 

	
 
/**
 
 * Clean up a station by clearing vehicle orders and invalidating windows.
 
 * Aircraft-Hangar orders need special treatment here, as the hangars are
 
 * actually part of a station (tiletype is STATION), but the order type
 
 * is OT_GOTO_DEPOT.
 
 */
 
Station::~Station()
 
{
 
	DEBUG(station, cDebugCtorLevel, "I-%3d", index);
 

	
 
	DeleteName(this->string_id);
 
	free(this->speclist);
 

	
 
	if (CleaningPool()) return;
 

	
 
	MarkDirty();
 
	RebuildStationLists();
 
	InvalidateWindowClasses(WC_STATION_LIST);
 

	
 
	DeleteWindowById(WC_STATION_VIEW, index);
 

	
 
	/* Now delete all orders that go to the station */
 
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, index);
 

	
 
	/* Subsidies need removal as well */
 
	DeleteSubsidyWithStation(index);
 

	
 
	xy = 0;
 

	
 
	for (CargoID c = 0; c < NUM_CARGO; c++) {
 
		goods[c].cargo.Truncate(0);
 
	}
 

	
 
	this->QuickFree();
 
}
 

	
 
void Station::QuickFree()
 
{
 
	DeleteName(this->string_id);
 
	free(this->speclist);
 
}
 

	
 
/** Called when new facility is built on the station. If it is the first facility
 
 * it initializes also 'xy' and 'random_bits' members */
 
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
 
{
 
	if (facilities == 0) {
 
		xy = facil_xy;
 
		random_bits = Random();
 
	}
 
	facilities |= new_facility_bit;
 
	owner = _current_player;
src/station.h
Show inline comments
 
@@ -150,26 +150,24 @@ struct Station : PoolItem<Station, Stati
 
	GoodsEntry goods[NUM_CARGO];
 

	
 
	uint16 random_bits;
 
	byte waiting_triggers;
 

	
 
	StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
 

	
 
	static const int cDebugCtorLevel = 5;
 

	
 
	Station(TileIndex tile = 0);
 
	virtual ~Station();
 

	
 
	void QuickFree();
 

	
 
	void AddFacility(byte new_facility_bit, TileIndex facil_xy);
 
	void MarkDirty() const;
 
	void MarkTilesDirty(bool cargo_change) const;
 
	bool TileBelongsToRailStation(TileIndex tile) const;
 
	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
 
	uint GetPlatformLength(TileIndex tile) const;
 
	bool IsBuoy() const;
 
	bool IsValid() const;
 
};
 

	
 
enum StationType {
 
	STATION_RAIL,
src/town.h
Show inline comments
 
@@ -151,26 +151,24 @@ struct Town : PoolItem<Town, TownID, &_T
 
	/* NOSAVE: The number of each type of building in the town. */
 
	BuildingCounts building_counts;
 

	
 
	/**
 
	 * Creates a new town
 
	 */
 
	Town(TileIndex tile = 0);
 

	
 
	/** Destroy the town */
 
	~Town();
 

	
 
	bool IsValid() const { return this->xy != 0; }
 

	
 
	void QuickFree();
 
};
 

	
 
struct HouseSpec {
 
	/* Standard properties */
 
	Year min_date;                     ///< introduction year of the house
 
	Year max_date;                     ///< last year it can be built
 
	byte population;                   ///< population (Zero on other tiles in multi tile house.)
 
	byte removal_cost;                 ///< cost multiplier for removing it
 
	StringID building_name;            ///< building name
 
	uint16 remove_rating_decrease;     ///< rating decrease if removed
 
	byte mail_generation;              ///< mail generation multiplier (tile based, as the acceptances below)
 
	byte cargo_acceptance[3];          ///< acceptance level for the cargo slots
src/town_cmd.cpp
Show inline comments
 
@@ -44,24 +44,28 @@
 

	
 
/* Initialize the town-pool */
 
DEFINE_OLD_POOL_GENERIC(Town, Town)
 

	
 
Town::Town(TileIndex tile)
 
{
 
	if (tile != 0) _total_towns++;
 
	this->xy = tile;
 
}
 

	
 
Town::~Town()
 
{
 
	DeleteName(this->townnametype);
 

	
 
	if (CleaningPool()) return;
 

	
 
	Industry *i;
 

	
 
	/* Delete town authority window
 
	 * and remove from list of sorted towns */
 
	DeleteWindowById(WC_TOWN_VIEW, this->index);
 
	_town_sort_dirty = true;
 
	_total_towns--;
 

	
 
	/* Delete all industries belonging to the town */
 
	FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
 

	
 
	/* Go through all tiles and delete those belonging to the town */
 
@@ -78,33 +82,27 @@ Town::~Town()
 
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				break;
 

	
 
			default:
 
				break;
 
		}
 
	}
 

	
 
	DeleteSubsidyWithTown(this->index);
 

	
 
	MarkWholeScreenDirty();
 

	
 
	this->QuickFree();
 
	this->xy = 0;
 
}
 

	
 
void Town::QuickFree()
 
{
 
	DeleteName(this->townnametype);
 
}
 

	
 
// Local
 
static int _grow_town_result;
 

	
 
static bool BuildTownHouse(Town *t, TileIndex tile);
 
static void DoBuildTownHouse(Town *t, TileIndex tile);
 

	
 
static void TownDrawHouseLift(const TileInfo *ti)
 
{
 
	AddChildSpriteScreen(SPR_LIFT, PAL_NONE, 14, 60 - GetLiftPosition(ti->tile));
 
}
 

	
 
typedef void TownDrawTileProc(const TileInfo *ti);
src/vehicle.cpp
Show inline comments
 
@@ -555,73 +555,73 @@ bool IsEngineCountable(const Vehicle *v)
 
		case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors
 
		case VEH_TRAIN:
 
			return !IsArticulatedPart(v) && // tenders and other articulated parts
 
			(!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines
 
		case VEH_ROAD: return IsRoadVehFront(v);
 
		case VEH_SHIP: return true;
 
		default: return false; // Only count player buildable vehicles
 
	}
 
}
 

	
 
void Vehicle::PreDestructor()
 
{
 
	if (CleaningPool()) return;
 

	
 
	if (IsValidStationID(this->last_station_visited)) {
 
		GetStation(this->last_station_visited)->loading_vehicles.remove(this);
 

	
 
		HideFillingPercent(this->fill_percent_te_id);
 
		this->fill_percent_te_id = INVALID_TE_ID;
 
	}
 

	
 
	if (IsEngineCountable(this)) {
 
		GetPlayer(this->owner)->num_engines[this->engine_type]--;
 
		if (this->owner == _local_player) InvalidateAutoreplaceWindow(this->engine_type, this->group_id);
 

	
 
		if (IsValidGroupID(this->group_id)) GetGroup(this->group_id)->num_engines[this->engine_type]--;
 
		if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
 
	}
 

	
 
	this->QuickFree();
 
	if (this->type == VEH_ROAD) ClearSlot(this);
 

	
 
	if (this->type != VEH_TRAIN || (this->type == VEH_TRAIN && (IsFrontEngine(this) || IsFreeWagon(this)))) {
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile);
 
	}
 

	
 
	this->cargo.Truncate(0);
 
	DeleteVehicleOrders(this);
 

	
 
	/* Now remove any artic part. This will trigger an other
 
	 *  destroy vehicle, which on his turn can remove any
 
	 *  other artic parts. */
 
	if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) {
 
		delete this->next;
 
	}
 
}
 

	
 
Vehicle::~Vehicle()
 
{
 
	DeleteName(this->string_id);
 

	
 
	if (CleaningPool()) return;
 

	
 
	UpdateVehiclePosHash(this, INVALID_COORD, 0);
 
	this->next_hash = NULL;
 
	this->next_new_hash = NULL;
 

	
 
	DeleteVehicleNews(this->index, INVALID_STRING_ID);
 

	
 
	new (this) InvalidVehicle();
 
}
 

	
 
void Vehicle::QuickFree()
 
{
 
	DeleteName(this->string_id);
 
}
 

	
 
/**
 
 * Deletes all vehicles in a chain.
 
 * @param v The first vehicle in the chain.
 
 *
 
 * @warning This function is not valid for any vehicle containing articulated
 
 * parts.
 
 */
 
void DeleteVehicleChain(Vehicle *v)
 
{
 
	assert(v->type != VEH_TRAIN && v->type != VEH_ROAD);
 

	
 
	do {
src/vehicle.h
Show inline comments
 
@@ -343,26 +343,24 @@ struct Vehicle : PoolItem<Vehicle, Vehic
 
	 * @return true if there is room to allocate all the vehicles
 
	 */
 
	static bool AllocateList(Vehicle **vl, int num);
 

	
 
	/** Create a new vehicle */
 
	Vehicle();
 

	
 
	/** Destroy all stuff that (still) needs the virtual functions to work properly */
 
	void PreDestructor();
 
	/** We want to 'destruct' the right class. */
 
	virtual ~Vehicle();
 

	
 
	void QuickFree();
 

	
 
	void BeginLoading();
 
	void LeaveStation();
 

	
 
	/**
 
	 * Handle the loading of the vehicle; when not it skips through dummy
 
	 * orders and does nothing in all other cases.
 
	 * @param mode is the non-first call for this vehicle in this tick?
 
	 */
 
	void HandleLoading(bool mode = false);
 

	
 
	/**
 
	 * Get a string 'representation' of the vehicle type.
src/waypoint.cpp
Show inline comments
 
@@ -395,35 +395,32 @@ void DrawWaypointSprite(int x, int y, in
 
	if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
 
		DrawDefaultWaypointSprite(x, y, railtype);
 
	}
 
}
 

	
 
Waypoint::Waypoint(TileIndex tile)
 
{
 
	this->xy = tile;
 
}
 

	
 
Waypoint::~Waypoint()
 
{
 
	if (this->string != STR_NULL) DeleteName(this->string);
 

	
 
	if (CleaningPool()) return;
 

	
 
	RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
 

	
 
	RedrawWaypointSign(this);
 
	this->xy = 0;
 

	
 
	this->QuickFree();
 
}
 

	
 
void Waypoint::QuickFree()
 
{
 
	if (this->string != STR_NULL) DeleteName(this->string);
 
}
 

	
 
bool Waypoint::IsValid() const
 
{
 
	return this->xy != 0;
 
}
 

	
 

	
 
/**
 
 * Fix savegames which stored waypoints in their old format
 
 */
 
void FixOldWaypoints()
src/waypoint.h
Show inline comments
 
@@ -21,26 +21,24 @@ struct Waypoint : PoolItem<Waypoint, Way
 
	ViewportSign sign; ///< Dimensions of sign (not saved)
 
	Date build_date;   ///< Date of construction
 

	
 
	byte stat_id;      ///< ID of waypoint within the waypoint class (not saved)
 
	uint32 grfid;      ///< ID of GRF file
 
	byte localidx;     ///< Index of station within GRF file
 

	
 
	byte deleted;      ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
 

	
 
	Waypoint(TileIndex tile = 0);
 
	~Waypoint();
 

	
 
	void QuickFree();
 

	
 
	bool IsValid() const;
 
};
 

	
 
static inline bool IsValidWaypointID(WaypointID index)
 
{
 
	return index < GetWaypointPoolSize() && GetWaypoint(index)->IsValid();
 
}
 

	
 
static inline void DeleteWaypoint(Waypoint *wp)
 
{
 
	wp->~Waypoint();
 
}
0 comments (0 inline, 0 general)