Changeset - r18782:6453522c2154
[Not reviewed]
master
! ! !
truebrain - 12 years ago 2011-12-20 17:57:56
truebrain@openttd.org
(svn r23640) -Fix: stop using FORCEINLINE (1/3rd of the instances were, the others were still regular inline), but make sure inline is always a 'forced' inline (I am looking at you MSVC)
75 files changed with 673 insertions and 672 deletions:
0 comments (0 inline, 0 general)
src/3rdparty/squirrel/include/squirrel.h
Show inline comments
 
@@ -32,12 +32,16 @@ to the following restrictions:
 
#define _SQUIRREL_H_
 

	
 
#ifdef __cplusplus
 
extern "C" {
 
#endif
 

	
 
#if defined(_MSC_VER)
 
# define inline __forceinline
 
#endif /* _MSC_VER */
 

	
 
#if defined(_MSC_VER) && _MSC_VER >= 1400 // MSVC 2005 safety checks
 
# pragma warning(disable: 4996)   // '_wfopen' was declared deprecated
 
# define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
 
# define _CRT_NON_CONFORMING_SWPRINTFS // another deprecated stuff
 
#endif /* _MSC_VER >= 1400 */
 

	
src/aircraft.h
Show inline comments
 
@@ -87,13 +87,13 @@ struct Aircraft FINAL : public Specializ
 
	/**
 
	 * Check if the aircraft type is a normal flying device; eg
 
	 * not a rotor or a shadow
 
	 * @return Returns true if the aircraft is a helicopter/airplane and
 
	 * false if it is a shadow or a rotor
 
	 */
 
	FORCEINLINE bool IsNormalAircraft() const
 
	inline bool IsNormalAircraft() const
 
	{
 
		/* To be fully correct the commented out functionality is the proper one,
 
		 * but since value can only be 0 or 2, it is sufficient to only check <= 2
 
		 * return (this->subtype == AIR_HELICOPTER) || (this->subtype == AIR_AIRCRAFT); */
 
		return this->subtype <= AIR_AIRCRAFT;
 
	}
src/base_station_base.h
Show inline comments
 
@@ -136,24 +136,24 @@ struct BaseStation : StationPool::PoolIt
 

	
 
	/**
 
	 * Get the base station belonging to a specific tile.
 
	 * @param tile The tile to get the base station from.
 
	 * @return the station associated with that tile.
 
	 */
 
	static FORCEINLINE BaseStation *GetByTile(TileIndex tile)
 
	static inline BaseStation *GetByTile(TileIndex tile)
 
	{
 
		return BaseStation::Get(GetStationIndex(tile));
 
	}
 

	
 
	/**
 
	 * Check whether the base station currently is in use; in use means
 
	 * that it is not scheduled for deletion and that it still has some
 
	 * facilities left.
 
	 * @return true if still in use
 
	 */
 
	FORCEINLINE bool IsInUse() const
 
	inline bool IsInUse() const
 
	{
 
		return (this->facilities & ~FACIL_WAYPOINT) != 0;
 
	}
 

	
 
	static void PostDestructor(size_t index);
 
};
 
@@ -169,83 +169,83 @@ struct SpecializedStation : public BaseS
 
	static const StationFacility EXPECTED_FACIL = Tis_waypoint ? FACIL_WAYPOINT : FACIL_NONE; ///< Specialized type
 

	
 
	/**
 
	 * Set station type correctly
 
	 * @param tile The base tile of the station.
 
	 */
 
	FORCEINLINE SpecializedStation<T, Tis_waypoint>(TileIndex tile) :
 
	inline SpecializedStation<T, Tis_waypoint>(TileIndex tile) :
 
			BaseStation(tile)
 
	{
 
		this->facilities = EXPECTED_FACIL;
 
	}
 

	
 
	/**
 
	 * Helper for checking whether the given station is of this type.
 
	 * @param st the station to check.
 
	 * @return true if the station is the type we expect it to be.
 
	 */
 
	static FORCEINLINE bool IsExpected(const BaseStation *st)
 
	static inline bool IsExpected(const BaseStation *st)
 
	{
 
		return (st->facilities & FACIL_WAYPOINT) == EXPECTED_FACIL;
 
	}
 

	
 
	/**
 
	 * Tests whether given index is a valid index for station of this type
 
	 * @param index tested index
 
	 * @return is this index valid index of T?
 
	 */
 
	static FORCEINLINE bool IsValidID(size_t index)
 
	static inline bool IsValidID(size_t index)
 
	{
 
		return BaseStation::IsValidID(index) && IsExpected(BaseStation::Get(index));
 
	}
 

	
 
	/**
 
	 * Gets station with given index
 
	 * @return pointer to station with given index casted to T *
 
	 */
 
	static FORCEINLINE T *Get(size_t index)
 
	static inline T *Get(size_t index)
 
	{
 
		return (T *)BaseStation::Get(index);
 
	}
 

	
 
	/**
 
	 * Returns station if the index is a valid index for this station type
 
	 * @return pointer to station with given index if it's a station of this type
 
	 */
 
	static FORCEINLINE T *GetIfValid(size_t index)
 
	static inline T *GetIfValid(size_t index)
 
	{
 
		return IsValidID(index) ? Get(index) : NULL;
 
	}
 

	
 
	/**
 
	 * Get the station belonging to a specific tile.
 
	 * @param tile The tile to get the station from.
 
	 * @return the station associated with that tile.
 
	 */
 
	static FORCEINLINE T *GetByTile(TileIndex tile)
 
	static inline T *GetByTile(TileIndex tile)
 
	{
 
		return GetIfValid(GetStationIndex(tile));
 
	}
 

	
 
	/**
 
	 * Converts a BaseStation to SpecializedStation with type checking.
 
	 * @param st BaseStation pointer
 
	 * @return pointer to SpecializedStation
 
	 */
 
	static FORCEINLINE T *From(BaseStation *st)
 
	static inline T *From(BaseStation *st)
 
	{
 
		assert(IsExpected(st));
 
		return (T *)st;
 
	}
 

	
 
	/**
 
	 * Converts a const BaseStation to const SpecializedStation with type checking.
 
	 * @param st BaseStation pointer
 
	 * @return pointer to SpecializedStation
 
	 */
 
	static FORCEINLINE const T *From(const BaseStation *st)
 
	static inline const T *From(const BaseStation *st)
 
	{
 
		assert(IsExpected(st));
 
		return (const T *)st;
 
	}
 
};
 

	
src/cargo_type.h
Show inline comments
 
@@ -74,37 +74,37 @@ enum CargoTypes {
 
struct CargoArray {
 
private:
 
	uint amount[NUM_CARGO]; ///< Amount of each type of cargo.
 

	
 
public:
 
	/** Default constructor. */
 
	FORCEINLINE CargoArray()
 
	inline CargoArray()
 
	{
 
		this->Clear();
 
	}
 

	
 
	/** Reset all entries. */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		memset(this->amount, 0, sizeof(this->amount));
 
	}
 

	
 
	/**
 
	 * Read/write access to an amount of a specific cargo type.
 
	 * @param cargo Cargo type to access.
 
	 */
 
	FORCEINLINE uint &operator[](CargoID cargo)
 
	inline uint &operator[](CargoID cargo)
 
	{
 
		return this->amount[cargo];
 
	}
 

	
 
	/**
 
	 * Read-only access to an amount of a specific cargo type.
 
	 * @param cargo Cargo type to access.
 
	 */
 
	FORCEINLINE const uint &operator[](CargoID cargo) const
 
	inline const uint &operator[](CargoID cargo) const
 
	{
 
		return this->amount[cargo];
 
	}
 
};
 

	
 

	
src/cargopacket.cpp
Show inline comments
 
@@ -79,13 +79,13 @@ CargoPacket::CargoPacket(uint16 count, b
 

	
 
/**
 
 * Split this packet in two and return the split off part.
 
 * @param new_size Size of the remaining part.
 
 * @return Split off part, or NULL if no packet could be allocated!
 
 */
 
FORCEINLINE CargoPacket *CargoPacket::Split(uint new_size)
 
inline CargoPacket *CargoPacket::Split(uint new_size)
 
{
 
	if (!CargoPacket::CanAllocateItem()) return NULL;
 

	
 
	Money fs = this->feeder_share * new_size / static_cast<uint>(this->count);
 
	CargoPacket *cp_new = new CargoPacket(new_size, this->days_in_transit, this->source, this->source_xy, this->loaded_at_xy, fs, this->source_type, this->source_id);
 
	this->feeder_share -= fs;
 
@@ -94,13 +94,13 @@ FORCEINLINE CargoPacket *CargoPacket::Sp
 
}
 

	
 
/**
 
 * Merge another packet into this one.
 
 * @param cp Packet to be merged in.
 
 */
 
FORCEINLINE void CargoPacket::Merge(CargoPacket *cp)
 
inline void CargoPacket::Merge(CargoPacket *cp)
 
{
 
	this->count += cp->count;
 
	this->feeder_share += cp->feeder_share;
 
	delete cp;
 
}
 

	
src/cargopacket.h
Show inline comments
 
@@ -66,79 +66,79 @@ public:
 
	void Merge(CargoPacket *cp);
 

	
 
	/**
 
	 * Gets the number of 'items' in this packet.
 
	 * @return Item count.
 
	 */
 
	FORCEINLINE uint16 Count() const
 
	inline uint16 Count() const
 
	{
 
		return this->count;
 
	}
 

	
 
	/**
 
	 * Gets the amount of money already paid to earlier vehicles in
 
	 * the feeder chain.
 
	 * @return Feeder share.
 
	 */
 
	FORCEINLINE Money FeederShare() const
 
	inline Money FeederShare() const
 
	{
 
		return this->feeder_share;
 
	}
 

	
 
	/**
 
	 * Gets the number of days this cargo has been in transit.
 
	 * This number isn't really in days, but in 2.5 days (CARGO_AGING_TICKS = 185 ticks) and
 
	 * it is capped at 255.
 
	 * @return Length this cargo has been in transit.
 
	 */
 
	FORCEINLINE byte DaysInTransit() const
 
	inline byte DaysInTransit() const
 
	{
 
		return this->days_in_transit;
 
	}
 

	
 
	/**
 
	 * Gets the type of the cargo's source. industry, town or head quarter.
 
	 * @return Source type.
 
	 */
 
	FORCEINLINE SourceType SourceSubsidyType() const
 
	inline SourceType SourceSubsidyType() const
 
	{
 
		return this->source_type;
 
	}
 

	
 
	/**
 
	 * Gets the ID of the cargo's source. An IndustryID, TownID or CompanyID.
 
	 * @return Source ID.
 
	 */
 
	FORCEINLINE SourceID SourceSubsidyID() const
 
	inline SourceID SourceSubsidyID() const
 
	{
 
		return this->source_id;
 
	}
 

	
 
	/**
 
	 * Gets the ID of the station where the cargo was loaded for the first time.
 
	 * @return StationID.
 
	 */
 
	FORCEINLINE SourceID SourceStation() const
 
	inline SourceID SourceStation() const
 
	{
 
		return this->source;
 
	}
 

	
 
	/**
 
	 * Gets the coordinates of the cargo's source station.
 
	 * @return Source station's coordinates.
 
	 */
 
	FORCEINLINE TileIndex SourceStationXY() const
 
	inline TileIndex SourceStationXY() const
 
	{
 
		return this->source_xy;
 
	}
 

	
 
	/**
 
	 * Gets the coordinates of the cargo's last loading station.
 
	 * @return Last loading station's coordinates.
 
	 */
 
	FORCEINLINE TileIndex LoadedAtXY() const
 
	inline TileIndex LoadedAtXY() const
 
	{
 
		return this->loaded_at_xy;
 
	}
 

	
 

	
 
	static void InvalidateAllFrom(SourceType src_type, SourceID src);
 
@@ -200,49 +200,49 @@ public:
 
	void OnCleanPool();
 

	
 
	/**
 
	 * Returns a pointer to the cargo packet list (so you can iterate over it etc).
 
	 * @return Pointer to the packet list.
 
	 */
 
	FORCEINLINE const List *Packets() const
 
	inline const List *Packets() const
 
	{
 
		return &this->packets;
 
	}
 

	
 
	/**
 
	 * Checks whether this list is empty.
 
	 * @return True if and only if the list is empty.
 
	 */
 
	FORCEINLINE bool Empty() const
 
	inline bool Empty() const
 
	{
 
		return this->count == 0;
 
	}
 

	
 
	/**
 
	 * Returns the number of cargo entities in this list.
 
	 * @return The before mentioned number.
 
	 */
 
	FORCEINLINE uint Count() const
 
	inline uint Count() const
 
	{
 
		return this->count;
 
	}
 

	
 
	/**
 
	 * Returns source of the first cargo packet in this list.
 
	 * @return The before mentioned source.
 
	 */
 
	FORCEINLINE StationID Source() const
 
	inline StationID Source() const
 
	{
 
		return this->Empty() ? INVALID_STATION : this->packets.front()->source;
 
	}
 

	
 
	/**
 
	 * Returns average number of days in transit for a cargo entity.
 
	 * @return The before mentioned number.
 
	 */
 
	FORCEINLINE uint DaysInTransit() const
 
	inline uint DaysInTransit() const
 
	{
 
		return this->count == 0 ? 0 : this->cargo_days_in_transit / this->count;
 
	}
 

	
 

	
 
	void Append(CargoPacket *cp);
 
@@ -274,13 +274,13 @@ public:
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
 

	
 
	/**
 
	 * Returns total sum of the feeder share for all packets.
 
	 * @return The before mentioned number.
 
	 */
 
	FORCEINLINE Money FeederShare() const
 
	inline Money FeederShare() const
 
	{
 
		return this->feeder_share;
 
	}
 

	
 
	void AgeCargo();
 

	
src/cargotype.h
Show inline comments
 
@@ -82,42 +82,42 @@ struct CargoSpec {
 
	Money current_payment;
 

	
 
	/**
 
	 * Determines index of this cargospec
 
	 * @return index (in the CargoSpec::array array)
 
	 */
 
	FORCEINLINE CargoID Index() const
 
	inline CargoID Index() const
 
	{
 
		return this - CargoSpec::array;
 
	}
 

	
 
	/**
 
	 * Tests for validity of this cargospec
 
	 * @return is this cargospec valid?
 
	 * @note assert(cs->IsValid()) can be triggered when GRF config is modified
 
	 */
 
	FORCEINLINE bool IsValid() const
 
	inline bool IsValid() const
 
	{
 
		return this->bitnum != INVALID_CARGO;
 
	}
 

	
 
	/**
 
	 * Total number of cargospecs, both valid and invalid
 
	 * @return length of CargoSpec::array
 
	 */
 
	static FORCEINLINE size_t GetArraySize()
 
	static inline size_t GetArraySize()
 
	{
 
		return lengthof(CargoSpec::array);
 
	}
 

	
 
	/**
 
	 * Retrieve cargo details for the given cargo ID
 
	 * @param index ID of cargo
 
	 * @pre index is a valid cargo ID
 
	 */
 
	static FORCEINLINE CargoSpec *Get(size_t index)
 
	static inline CargoSpec *Get(size_t index)
 
	{
 
		assert(index < lengthof(CargoSpec::array));
 
		return &CargoSpec::array[index];
 
	}
 

	
 
	SpriteID GetCargoIcon() const;
src/command_type.h
Show inline comments
 
@@ -55,42 +55,42 @@ public:
 

	
 

	
 
	/**
 
	 * Adds the given cost to the cost of the command.
 
	 * @param cost the cost to add
 
	 */
 
	FORCEINLINE void AddCost(const Money &cost)
 
	inline void AddCost(const Money &cost)
 
	{
 
		this->cost += cost;
 
	}
 

	
 
	void AddCost(const CommandCost &cmd_cost);
 

	
 
	/**
 
	 * Multiplies the cost of the command by the given factor.
 
	 * @param factor factor to multiply the costs with
 
	 */
 
	FORCEINLINE void MultiplyCost(int factor)
 
	inline void MultiplyCost(int factor)
 
	{
 
		this->cost *= factor;
 
	}
 

	
 
	/**
 
	 * The costs as made up to this moment
 
	 * @return the costs
 
	 */
 
	FORCEINLINE Money GetCost() const
 
	inline Money GetCost() const
 
	{
 
		return this->cost;
 
	}
 

	
 
	/**
 
	 * The expense type of the cost
 
	 * @return the expense type
 
	 */
 
	FORCEINLINE ExpensesType GetExpensesType() const
 
	inline ExpensesType GetExpensesType() const
 
	{
 
		return this->expense_type;
 
	}
 

	
 
	/**
 
	 * Makes this #CommandCost behave like an error command.
 
@@ -134,22 +134,22 @@ public:
 
	}
 

	
 
	/**
 
	 * Did this command succeed?
 
	 * @return true if and only if it succeeded
 
	 */
 
	FORCEINLINE bool Succeeded() const
 
	inline bool Succeeded() const
 
	{
 
		return this->success;
 
	}
 

	
 
	/**
 
	 * Did this command fail?
 
	 * @return true if and only if it failed
 
	 */
 
	FORCEINLINE bool Failed() const
 
	inline bool Failed() const
 
	{
 
		return !this->success;
 
	}
 
};
 

	
 
/**
src/company_base.h
Show inline comments
 
@@ -121,38 +121,38 @@ struct Company : CompanyPool::PoolItem<&
 

	
 
	/**
 
	 * Is this company a valid company, controlled by the computer (a NoAI program)?
 
	 * @param index Index in the pool.
 
	 * @return \c true if it is a valid, computer controlled company, else \c false.
 
	 */
 
	static FORCEINLINE bool IsValidAiID(size_t index)
 
	static inline bool IsValidAiID(size_t index)
 
	{
 
		const Company *c = Company::GetIfValid(index);
 
		return c != NULL && c->is_ai;
 
	}
 

	
 
	/**
 
	 * Is this company a valid company, not controlled by a NoAI program?
 
	 * @param index Index in the pool.
 
	 * @return \c true if it is a valid, human controlled company, else \c false.
 
	 * @note If you know that \a index refers to a valid company, you can use #IsHumanID() instead.
 
	 */
 
	static FORCEINLINE bool IsValidHumanID(size_t index)
 
	static inline bool IsValidHumanID(size_t index)
 
	{
 
		const Company *c = Company::GetIfValid(index);
 
		return c != NULL && !c->is_ai;
 
	}
 

	
 
	/**
 
	 * Is this company a company not controlled by a NoAI program?
 
	 * @param index Index in the pool.
 
	 * @return \c true if it is a human controlled company, else \c false.
 
	 * @pre \a index must be a valid CompanyID.
 
	 * @note If you don't know whether \a index refers to a valid company, you should use #IsValidHumanID() instead.
 
	 */
 
	static FORCEINLINE bool IsHumanID(size_t index)
 
	static inline bool IsHumanID(size_t index)
 
	{
 
		return !Company::Get(index)->is_ai;
 
	}
 

	
 
	static void PostDestructor(size_t index);
 
};
src/core/alloc_func.hpp
Show inline comments
 
@@ -53,13 +53,13 @@ static inline void CheckAllocationConstr
 
 * @note the memory contains garbage data (i.e. possibly non-zero values).
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 */
 
template <typename T>
 
static FORCEINLINE T *MallocT(size_t num_elements)
 
static inline T *MallocT(size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
 
@@ -81,13 +81,13 @@ static FORCEINLINE T *MallocT(size_t num
 
 * @note the memory contains all zero values.
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 */
 
template <typename T>
 
static FORCEINLINE T *CallocT(size_t num_elements)
 
static inline T *CallocT(size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
 
@@ -107,13 +107,13 @@ static FORCEINLINE T *CallocT(size_t num
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param t_ptr the previous allocation to extend/shrink.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 */
 
template <typename T>
 
static FORCEINLINE T *ReallocT(T *t_ptr, size_t num_elements)
 
static inline T *ReallocT(T *t_ptr, size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
src/core/alloc_type.hpp
Show inline comments
 
@@ -45,32 +45,32 @@ struct SmallStackSafeStackAlloc {
 
#endif
 

	
 
	/**
 
	 * Gets a pointer to the data stored in this wrapper.
 
	 * @return the pointer.
 
	 */
 
	FORCEINLINE operator T *()
 
	inline operator T *()
 
	{
 
		return data;
 
	}
 

	
 
	/**
 
	 * Gets a pointer to the data stored in this wrapper.
 
	 * @return the pointer.
 
	 */
 
	FORCEINLINE T *operator -> ()
 
	inline T *operator -> ()
 
	{
 
		return data;
 
	}
 

	
 
	/**
 
	 * Gets a pointer to the last data element stored in this wrapper.
 
	 * @note needed because endof does not work properly for pointers.
 
	 * @return the 'endof' pointer.
 
	 */
 
	FORCEINLINE T *EndOf()
 
	inline T *EndOf()
 
	{
 
#if !defined(__NDS__)
 
		return endof(data);
 
#else
 
		return &data[len];
 
#endif
 
@@ -134,13 +134,13 @@ public:
 
	}
 

	
 
	/**
 
	 * Get the currently allocated buffer.
 
	 * @return the buffer
 
	 */
 
	FORCEINLINE const T *GetBuffer() const
 
	inline const T *GetBuffer() const
 
	{
 
		return this->buffer;
 
	}
 
};
 

	
 
/**
 
@@ -155,29 +155,29 @@ public:
 

	
 
	/**
 
	 * Memory allocator for a single class instance.
 
	 * @param size the amount of bytes to allocate.
 
	 * @return the given amounts of bytes zeroed.
 
	 */
 
	FORCEINLINE void *operator new(size_t size) { return CallocT<byte>(size); }
 
	inline void *operator new(size_t size) { return CallocT<byte>(size); }
 

	
 
	/**
 
	 * Memory allocator for an array of class instances.
 
	 * @param size the amount of bytes to allocate.
 
	 * @return the given amounts of bytes zeroed.
 
	 */
 
	FORCEINLINE void *operator new[](size_t size) { return CallocT<byte>(size); }
 
	inline void *operator new[](size_t size) { return CallocT<byte>(size); }
 

	
 
	/**
 
	 * Memory release for a single class instance.
 
	 * @param ptr  the memory to free.
 
	 */
 
	FORCEINLINE void operator delete(void *ptr) { free(ptr); }
 
	inline void operator delete(void *ptr) { free(ptr); }
 

	
 
	/**
 
	 * Memory release for an array of class instances.
 
	 * @param ptr  the memory to free.
 
	 */
 
	FORCEINLINE void operator delete[](void *ptr) { free(ptr); }
 
	inline void operator delete[](void *ptr) { free(ptr); }
 
};
 

	
 
#endif /* ALLOC_TYPE_HPP */
src/core/bitmath_func.hpp
Show inline comments
 
@@ -26,13 +26,13 @@
 
 * @param x The value to read some bits.
 
 * @param s The startposition to read some bits.
 
 * @param n The number of bits to read.
 
 * @return The selected bits, aligned to a LSB.
 
 */
 
template <typename T>
 
static FORCEINLINE uint GB(const T x, const uint8 s, const uint8 n)
 
static inline uint GB(const T x, const uint8 s, const uint8 n)
 
{
 
	return (x >> s) & (((T)1U << n) - 1);
 
}
 

	
 
/**
 
 * Set \a n bits in \a x starting at bit \a s to \a d
 
@@ -50,13 +50,13 @@ static FORCEINLINE uint GB(const T x, co
 
 * @param s The startposition for the new bits
 
 * @param n The size/window for the new bits
 
 * @param d The actually new bits to save in the defined position.
 
 * @return The new value of \a x
 
 */
 
template <typename T, typename U>
 
static FORCEINLINE T SB(T &x, const uint8 s, const uint8 n, const U d)
 
static inline T SB(T &x, const uint8 s, const uint8 n, const U d)
 
{
 
	x &= (T)(~((((T)1U << n) - 1) << s));
 
	x |= (T)(d << s);
 
	return x;
 
}
 

	
 
@@ -73,13 +73,13 @@ static FORCEINLINE T SB(T &x, const uint
 
 * @param s The startposition of the addition
 
 * @param n The size/window for the addition
 
 * @param i The value to add at the given startposition in the given window.
 
 * @return The new value of x
 
 */
 
template <typename T, typename U>
 
static FORCEINLINE T AB(T &x, const uint8 s, const uint8 n, const U i)
 
static inline T AB(T &x, const uint8 s, const uint8 n, const U i)
 
{
 
	const T mask = ((((T)1U << n) - 1) << s);
 
	x = (T)((x & ~mask) | ((x + (i << s)) & mask));
 
	return x;
 
}
 

	
 
@@ -92,13 +92,13 @@ static FORCEINLINE T AB(T &x, const uint
 
 *
 
 * @param x The value to check
 
 * @param y The position of the bit to check, started from the LSB
 
 * @return True if the bit is set, false else.
 
 */
 
template <typename T>
 
static FORCEINLINE bool HasBit(const T x, const uint8 y)
 
static inline bool HasBit(const T x, const uint8 y)
 
{
 
	return (x & ((T)1U << y)) != 0;
 
}
 

	
 
/**
 
 * Set a bit in a variable.
 
@@ -109,13 +109,13 @@ static FORCEINLINE bool HasBit(const T x
 
 *
 
 * @param x The variable to set a bit
 
 * @param y The bit position to set
 
 * @return The new value of the old value with the bit set
 
 */
 
template <typename T>
 
static FORCEINLINE T SetBit(T &x, const uint8 y)
 
static inline T SetBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x | ((T)1U << y));
 
}
 

	
 
/**
 
 * Sets several bits in a variable.
 
@@ -138,13 +138,13 @@ static FORCEINLINE T SetBit(T &x, const 
 
 *
 
 * @param x The variable to clear the bit
 
 * @param y The bit position to clear
 
 * @return The new value of the old value with the bit cleared
 
 */
 
template <typename T>
 
static FORCEINLINE T ClrBit(T &x, const uint8 y)
 
static inline T ClrBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x & ~((T)1U << y));
 
}
 

	
 
/**
 
 * Clears several bits in a variable.
 
@@ -167,13 +167,13 @@ static FORCEINLINE T ClrBit(T &x, const 
 
 *
 
 * @param x The varliable to toggle the bit
 
 * @param y The bit position to toggle
 
 * @return The new value of the old value with the bit toggled
 
 */
 
template <typename T>
 
static FORCEINLINE T ToggleBit(T &x, const uint8 y)
 
static inline T ToggleBit(T &x, const uint8 y)
 
{
 
	return x = (T)(x ^ ((T)1U << y));
 
}
 

	
 

	
 
/** Lookup table to check which bit is set in a 6 bit variable */
 
@@ -202,13 +202,13 @@ extern const uint8 _ffb_64[64];
 
 * be also zero to check the bits at 0x3F00.
 
 *
 
 * @param value The value to check the first bits
 
 * @return The position of the first bit which is set
 
 * @see FIND_FIRST_BIT
 
 */
 
static FORCEINLINE uint8 FindFirstBit2x64(const int value)
 
static inline uint8 FindFirstBit2x64(const int value)
 
{
 
	if ((value & 0xFF) == 0) {
 
		return FIND_FIRST_BIT((value >> 8) & 0x3F) + 8;
 
	} else {
 
		return FIND_FIRST_BIT(value & 0x3F);
 
	}
 
@@ -225,13 +225,13 @@ uint8 FindLastBit(uint64 x);
 
 * So, 110100 returns 110000, 000001 returns 000000, etc.
 
 *
 
 * @param value The value to clear the first bit
 
 * @return The new value with the first bit cleared
 
 */
 
template <typename T>
 
static FORCEINLINE T KillFirstBit(T value)
 
static inline T KillFirstBit(T value)
 
{
 
	return value &= (T)(value - 1);
 
}
 

	
 
/**
 
 * Counts the number of set bits in a variable.
 
@@ -260,25 +260,25 @@ static inline uint CountBits(T value)
 
 * Test whether \a value has exactly 1 bit set
 
 *
 
 * @param value the value to test.
 
 * @return does \a value have exactly 1 bit set?
 
 */
 
template <typename T>
 
static FORCEINLINE bool HasExactlyOneBit(T value)
 
static inline bool HasExactlyOneBit(T value)
 
{
 
	return value != 0 && (value & (value - 1)) == 0;
 
}
 

	
 
/**
 
 * Test whether \a value has at most 1 bit set
 
 *
 
 * @param value the value to test.
 
 * @return does \a value have at most 1 bit set?
 
 */
 
template <typename T>
 
static FORCEINLINE bool HasAtMostOneBit(T value)
 
static inline bool HasAtMostOneBit(T value)
 
{
 
	return (value & (value - 1)) == 0;
 
}
 

	
 
/**
 
 * ROtate x Left by n
 
@@ -286,13 +286,13 @@ static FORCEINLINE bool HasAtMostOneBit(
 
 * @note Assumes a byte has 8 bits
 
 * @param x The value which we want to rotate
 
 * @param n The number how many we waht to rotate
 
 * @return A bit rotated number
 
 */
 
template <typename T>
 
static FORCEINLINE T ROL(const T x, const uint8 n)
 
static inline T ROL(const T x, const uint8 n)
 
{
 
	return (T)(x << n | x >> (sizeof(x) * 8 - n));
 
}
 

	
 
/**
 
 * ROtate x Right by n
 
@@ -300,13 +300,13 @@ static FORCEINLINE T ROL(const T x, cons
 
 * @note Assumes a byte has 8 bits
 
 * @param x The value which we want to rotate
 
 * @param n The number how many we waht to rotate
 
 * @return A bit rotated number
 
 */
 
template <typename T>
 
static FORCEINLINE T ROR(const T x, const uint8 n)
 
static inline T ROR(const T x, const uint8 n)
 
{
 
	return (T)(x >> n | x << (sizeof(x) * 8 - n));
 
}
 

	
 
/**
 
 * Do an operation for each set bit in a value.
 
@@ -362,13 +362,13 @@ static FORCEINLINE T ROR(const T x, cons
 
#else
 
	/**
 
	 * Perform a 32 bits endianness bitswap on x.
 
	 * @param x the variable to bitswap
 
	 * @return the bitswapped value.
 
	 */
 
	static FORCEINLINE uint32 BSWAP32(uint32 x)
 
	static inline uint32 BSWAP32(uint32 x)
 
	{
 
#if !defined(__ICC) && defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4)  && __GNUC_MINOR__ >= 3))
 
		/* GCC >= 4.3 provides a builtin, resulting in faster code */
 
		return (uint32)__builtin_bswap32((int32)x);
 
#else
 
		return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
 
@@ -377,13 +377,13 @@ static FORCEINLINE T ROR(const T x, cons
 

	
 
	/**
 
	 * Perform a 16 bits endianness bitswap on x.
 
	 * @param x the variable to bitswap
 
	 * @return the bitswapped value.
 
	 */
 
	static FORCEINLINE uint16 BSWAP16(uint16 x)
 
	static inline uint16 BSWAP16(uint16 x)
 
	{
 
		return (x >> 8) | (x << 8);
 
	}
 
#endif /* __APPLE__ */
 

	
 
#endif /* BITMATH_FUNC_HPP */
src/core/endian_func.hpp
Show inline comments
 
@@ -37,18 +37,18 @@
 
	#define FROM_LE32(x) (x)
 
	#define TO_LE16(x)   (x)
 
	#define TO_LE32(x)   (x)
 
	#define TO_LE32X(x)  (x)
 
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
 

	
 
static FORCEINLINE uint16 ReadLE16Aligned(const void *x)
 
static inline uint16 ReadLE16Aligned(const void *x)
 
{
 
	return FROM_LE16(*(const uint16*)x);
 
}
 

	
 
static FORCEINLINE uint16 ReadLE16Unaligned(const void *x)
 
static inline uint16 ReadLE16Unaligned(const void *x)
 
{
 
#if OTTD_ALIGNMENT == 1
 
	return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
 
#else
 
	return FROM_LE16(*(const uint16*)x);
 
#endif /* OTTD_ALIGNMENT == 1 */
src/core/enum_type.hpp
Show inline comments
 
@@ -11,36 +11,36 @@
 

	
 
#ifndef ENUM_TYPE_HPP
 
#define ENUM_TYPE_HPP
 

	
 
/** Some enums need to have allowed incrementing (i.e. StationClassID) */
 
#define DECLARE_POSTFIX_INCREMENT(type) \
 
	FORCEINLINE type operator ++(type& e, int) \
 
	inline type operator ++(type& e, int) \
 
	{ \
 
		type e_org = e; \
 
		e = (type)((int)e + 1); \
 
		return e_org; \
 
	} \
 
	FORCEINLINE type operator --(type& e, int) \
 
	inline type operator --(type& e, int) \
 
	{ \
 
		type e_org = e; \
 
		e = (type)((int)e - 1); \
 
		return e_org; \
 
	}
 

	
 

	
 

	
 
/** Operators to allow to work with enum as with type safe bit set in C++ */
 
# define DECLARE_ENUM_AS_BIT_SET(mask_t) \
 
	FORCEINLINE mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \
 
	FORCEINLINE mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \
 
	FORCEINLINE mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
 
	FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
 
	FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
 
	FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
 
	FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
 
	inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \
 
	inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \
 
	inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
 
	inline mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
 
	inline mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
 
	inline mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
 
	inline mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
 

	
 

	
 
/**
 
 * Informative template class exposing basic enumeration properties used by several
 
 *  other templates below. Here we have only forward declaration. For each enum type
 
 *  we will create specialization derived from MakeEnumPropsT<>.
 
@@ -95,41 +95,41 @@ struct TinyEnumT {
 
	static const enum_type end = Props::end;        ///< enum end (i.e. TRACKDIR_END)
 
	static const enum_type invalid = Props::invalid;///< invalid value (i.e. INVALID_TRACKDIR)
 

	
 
	storage_type m_val;  ///< here we hold the actual value in small (i.e. byte) form
 

	
 
	/** Cast operator - invoked then the value is assigned to the Tenum_t type */
 
	FORCEINLINE operator enum_type () const
 
	inline operator enum_type () const
 
	{
 
		return (enum_type)m_val;
 
	}
 

	
 
	/** Assignment operator (from Tenum_t type) */
 
	FORCEINLINE TinyEnumT& operator = (enum_type e)
 
	inline TinyEnumT& operator = (enum_type e)
 
	{
 
		m_val = (storage_type)e;
 
		return *this;
 
	}
 

	
 
	/** Assignment operator (from Tenum_t type) */
 
	FORCEINLINE TinyEnumT& operator = (uint u)
 
	inline TinyEnumT& operator = (uint u)
 
	{
 
		m_val = (storage_type)u;
 
		return *this;
 
	}
 

	
 
	/** postfix ++ operator on tiny type */
 
	FORCEINLINE TinyEnumT operator ++ (int)
 
	inline TinyEnumT operator ++ (int)
 
	{
 
		TinyEnumT org = *this;
 
		if (++m_val >= end) m_val -= (storage_type)(end - begin);
 
		return org;
 
	}
 

	
 
	/** prefix ++ operator on tiny type */
 
	FORCEINLINE TinyEnumT& operator ++ ()
 
	inline TinyEnumT& operator ++ ()
 
	{
 
		if (++m_val >= end) m_val -= (storage_type)(end - begin);
 
		return *this;
 
	}
 
};
 

	
 
@@ -137,40 +137,40 @@ struct TinyEnumT {
 
/** Template of struct holding enum types (on most archs, enums are stored in an int32). No math operators are provided. */
 
template <typename enum_type, typename storage_type>
 
struct SimpleTinyEnumT {
 
	storage_type m_val;  ///< here we hold the actual value in small (i.e. byte) form
 

	
 
	/** Cast operator - invoked then the value is assigned to the storage_type */
 
	FORCEINLINE operator enum_type () const
 
	inline operator enum_type () const
 
	{
 
		return (enum_type)this->m_val;
 
	}
 

	
 
	/** Assignment operator (from enum_type) */
 
	FORCEINLINE SimpleTinyEnumT &operator = (enum_type e)
 
	inline SimpleTinyEnumT &operator = (enum_type e)
 
	{
 
		this->m_val = (storage_type)e;
 
		return *this;
 
	}
 

	
 
	/** Assignment operator (from general uint) */
 
	FORCEINLINE SimpleTinyEnumT &operator = (uint u)
 
	inline SimpleTinyEnumT &operator = (uint u)
 
	{
 
		this->m_val = (storage_type)u;
 
		return *this;
 
	}
 

	
 
	/** Bit math (or) assignment operator (from enum_type) */
 
	FORCEINLINE SimpleTinyEnumT &operator |= (enum_type e)
 
	inline SimpleTinyEnumT &operator |= (enum_type e)
 
	{
 
		this->m_val = (storage_type)((enum_type)this->m_val | e);
 
		return *this;
 
	}
 

	
 
	/** Bit math (and) assignment operator (from enum_type) */
 
	FORCEINLINE SimpleTinyEnumT &operator &= (enum_type e)
 
	inline SimpleTinyEnumT &operator &= (enum_type e)
 
	{
 
		this->m_val = (storage_type)((enum_type)this->m_val & e);
 
		return *this;
 
	}
 
};
 

	
src/core/math_func.hpp
Show inline comments
 
@@ -32,13 +32,13 @@
 
 *
 
 * @param a The first value
 
 * @param b The second value
 
 * @return The greater value or a if equals
 
 */
 
template <typename T>
 
static FORCEINLINE T max(const T a, const T b)
 
static inline T max(const T a, const T b)
 
{
 
	return (a >= b) ? a : b;
 
}
 

	
 
/**
 
 * Returns the minimum of two values.
 
@@ -48,13 +48,13 @@ static FORCEINLINE T max(const T a, cons
 
 *
 
 * @param a The first value
 
 * @param b The second value
 
 * @return The smaller value or b if equals
 
 */
 
template <typename T>
 
static FORCEINLINE T min(const T a, const T b)
 
static inline T min(const T a, const T b)
 
{
 
	return (a < b) ? a : b;
 
}
 

	
 
/**
 
 * Returns the minimum of two integer.
 
@@ -62,13 +62,13 @@ static FORCEINLINE T min(const T a, cons
 
 * This function returns the smaller value of two given integers.
 
 *
 
 * @param a The first integer
 
 * @param b The second integer
 
 * @return The smaller value
 
 */
 
static FORCEINLINE int min(const int a, const int b)
 
static inline int min(const int a, const int b)
 
{
 
	return min<int>(a, b);
 
}
 

	
 
/**
 
 * Returns the minimum of two unsigned integers.
 
@@ -76,26 +76,26 @@ static FORCEINLINE int min(const int a, 
 
 * This function returns the smaller value of two given unsigned integers.
 
 *
 
 * @param a The first unsigned integer
 
 * @param b The second unsigned integer
 
 * @return The smaller value
 
 */
 
static FORCEINLINE uint minu(const uint a, const uint b)
 
static inline uint minu(const uint a, const uint b)
 
{
 
	return min<uint>(a, b);
 
}
 

	
 
/**
 
 * Returns the absolute value of (scalar) variable.
 
 *
 
 * @note assumes variable to be signed
 
 * @param a The value we want to unsign
 
 * @return The unsigned value
 
 */
 
template <typename T>
 
static FORCEINLINE T abs(const T a)
 
static inline T abs(const T a)
 
{
 
	return (a < (T)0) ? -a : a;
 
}
 

	
 
/**
 
 * Return the smallest multiple of n equal or greater than x
 
@@ -103,13 +103,13 @@ static FORCEINLINE T abs(const T a)
 
 * @note n must be a power of 2
 
 * @param x The min value
 
 * @param n The base of the number we are searching
 
 * @return The smallest multiple of n equal or greater than x
 
 */
 
template <typename T>
 
static FORCEINLINE T Align(const T x, uint n)
 
static inline T Align(const T x, uint n)
 
{
 
	assert((n & (n - 1)) == 0 && n != 0);
 
	n--;
 
	return (T)((x + n) & ~((T)n));
 
}
 

	
 
@@ -121,13 +121,13 @@ static FORCEINLINE T Align(const T x, ui
 
 * @param x The min value
 
 * @param n The base of the number we are searching
 
 * @return The smallest multiple of n equal or greater than x
 
 * @see Align()
 
 */
 
template <typename T>
 
static FORCEINLINE T *AlignPtr(T *x, uint n)
 
static inline T *AlignPtr(T *x, uint n)
 
{
 
	assert_compile(sizeof(size_t) == sizeof(void *));
 
	return (T *)Align((size_t)x, n);
 
}
 

	
 
/**
 
@@ -145,13 +145,13 @@ static FORCEINLINE T *AlignPtr(T *x, uin
 
 * @param max the maximum of the interval.
 
 * @returns A value between min and max which is closest to a.
 
 * @see ClampU(uint, uint, uint)
 
 * @see Clamp(int, int, int)
 
 */
 
template <typename T>
 
static FORCEINLINE T Clamp(const T a, const T min, const T max)
 
static inline T Clamp(const T a, const T min, const T max)
 
{
 
	assert(min <= max);
 
	if (a <= min) return min;
 
	if (a >= max) return max;
 
	return a;
 
}
 
@@ -169,13 +169,13 @@ static FORCEINLINE T Clamp(const T a, co
 
 * @param a The value to clamp/truncate.
 
 * @param min The minimum of the interval.
 
 * @param max the maximum of the interval.
 
 * @returns A value between min and max which is closest to a.
 
 * @see ClampU(uint, uint, uint)
 
 */
 
static FORCEINLINE int Clamp(const int a, const int min, const int max)
 
static inline int Clamp(const int a, const int min, const int max)
 
{
 
	return Clamp<int>(a, min, max);
 
}
 

	
 
/**
 
 * Clamp an unsigned integer between an interval.
 
@@ -190,13 +190,13 @@ static FORCEINLINE int Clamp(const int a
 
 * @param a The value to clamp/truncate.
 
 * @param min The minimum of the interval.
 
 * @param max the maximum of the interval.
 
 * @returns A value between min and max which is closest to a.
 
 * @see Clamp(int, int, int)
 
 */
 
static FORCEINLINE uint ClampU(const uint a, const uint min, const uint max)
 
static inline uint ClampU(const uint a, const uint min, const uint max)
 
{
 
	return Clamp<uint>(a, min, max);
 
}
 

	
 
/**
 
 * Reduce a signed 64-bit int to a signed 32-bit one
 
@@ -209,25 +209,25 @@ static FORCEINLINE uint ClampU(const uin
 
 * 32-bits integer field and so the value is casted to int32 and returned.
 
 *
 
 * @param a The 64-bit value to clamps
 
 * @return The 64-bit value reduced to a 32-bit value
 
 * @see Clamp(int, int, int)
 
 */
 
static FORCEINLINE int32 ClampToI32(const int64 a)
 
static inline int32 ClampToI32(const int64 a)
 
{
 
	return (int32)Clamp<int64>(a, INT32_MIN, INT32_MAX);
 
}
 

	
 
/**
 
 * Reduce an unsigned 64-bit int to an unsigned 16-bit one
 
 *
 
 * @param a The 64-bit value to clamp
 
 * @return The 64-bit value reduced to a 16-bit value
 
 * @see ClampU(uint, uint, uint)
 
 */
 
static FORCEINLINE uint16 ClampToU16(const uint64 a)
 
static inline uint16 ClampToU16(const uint64 a)
 
{
 
	/* MSVC thinks, in its infinite wisdom, that int min(int, int) is a better
 
	 * match for min(uint64, uint) than uint64 min(uint64, uint64). As such we
 
	 * need to cast the UINT16_MAX to prevent MSVC from displaying its
 
	 * infinite loads of warnings. */
 
	return (uint16)min<uint64>(a, (uint64)UINT16_MAX);
 
@@ -238,13 +238,13 @@ static FORCEINLINE uint16 ClampToU16(con
 
 *
 
 * @param a The first scalar
 
 * @param b The second scalar
 
 * @return The absolute difference between the given scalars
 
 */
 
template <typename T>
 
static FORCEINLINE T Delta(const T a, const T b)
 
static inline T Delta(const T a, const T b)
 
{
 
	return (a < b) ? b - a : a - b;
 
}
 

	
 
/**
 
 * Checks if a value is between a window started at some base point.
 
@@ -256,13 +256,13 @@ static FORCEINLINE T Delta(const T a, co
 
 * @param x The value to check
 
 * @param base The base value of the interval
 
 * @param size The size of the interval
 
 * @return True if the value is in the interval, false else.
 
 */
 
template <typename T>
 
static FORCEINLINE bool IsInsideBS(const T x, const uint base, const uint size)
 
static inline bool IsInsideBS(const T x, const uint base, const uint size)
 
{
 
	return (uint)(x - base) < size;
 
}
 

	
 
/**
 
 * Checks if a value is in an interval.
 
@@ -272,47 +272,47 @@ static FORCEINLINE bool IsInsideBS(const
 
 * @param x The value to check
 
 * @param min The minimum of the interval
 
 * @param max The maximum of the interval
 
 * @see IsInsideBS()
 
 */
 
template <typename T>
 
static FORCEINLINE bool IsInsideMM(const T x, const uint min, const uint max)
 
static inline bool IsInsideMM(const T x, const uint min, const uint max)
 
{
 
	return (uint)(x - min) < (max - min);
 
}
 

	
 
/**
 
 * Type safe swap operation
 
 * @param a variable to swap with b
 
 * @param b variable to swap with a
 
 */
 
template <typename T>
 
static FORCEINLINE void Swap(T &a, T &b)
 
static inline void Swap(T &a, T &b)
 
{
 
	T t = a;
 
	a = b;
 
	b = t;
 
}
 

	
 
/**
 
 * Converts a "fract" value 0..255 to "percent" value 0..100
 
 * @param i value to convert, range 0..255
 
 * @return value in range 0..100
 
 */
 
static FORCEINLINE uint ToPercent8(uint i)
 
static inline uint ToPercent8(uint i)
 
{
 
	assert(i < 256);
 
	return i * 101 >> 8;
 
}
 

	
 
/**
 
 * Converts a "fract" value 0..65535 to "percent" value 0..100
 
 * @param i value to convert, range 0..65535
 
 * @return value in range 0..100
 
 */
 
static FORCEINLINE uint ToPercent16(uint i)
 
static inline uint ToPercent16(uint i)
 
{
 
	assert(i < 65536);
 
	return i * 101 >> 16;
 
}
 

	
 
int LeastCommonMultiple(int a, int b);
 
@@ -321,35 +321,35 @@ int GreatestCommonDivisor(int a, int b);
 
/**
 
 * Computes ceil(a / b) for non-negative a and b.
 
 * @param a Numerator
 
 * @param b Denominator
 
 * @return Quotient, rounded up
 
 */
 
static FORCEINLINE uint CeilDiv(uint a, uint b)
 
static inline uint CeilDiv(uint a, uint b)
 
{
 
	return (a + b - 1) / b;
 
}
 

	
 
/**
 
 * Computes ceil(a / b) * b for non-negative a and b.
 
 * @param a Numerator
 
 * @param b Denominator
 
 * @return a rounded up to the nearest multiple of b.
 
 */
 
static FORCEINLINE uint Ceil(uint a, uint b)
 
static inline uint Ceil(uint a, uint b)
 
{
 
	return CeilDiv(a, b) * b;
 
}
 

	
 
/**
 
 * Computes round(a / b) for signed a and unsigned b.
 
 * @param a Numerator
 
 * @param b Denominator
 
 * @return Quotient, rounded to nearest
 
 */
 
static FORCEINLINE int RoundDivSU(int a, uint b)
 
static inline int RoundDivSU(int a, uint b)
 
{
 
	if (a > 0) {
 
		/* 0.5 is rounded to 1 */
 
		return (a + (int)b / 2) / (int)b;
 
	} else {
 
		/* -0.5 is rounded to 0 */
src/core/mem_func.hpp
Show inline comments
 
@@ -19,39 +19,39 @@
 
 *
 
 * @param destination Pointer to the destination buffer
 
 * @param source Pointer to the source buffer
 
 * @param num number of items to be copied. (!not number of bytes!)
 
 */
 
template <typename T>
 
static FORCEINLINE void MemCpyT(T *destination, const T *source, size_t num = 1)
 
static inline void MemCpyT(T *destination, const T *source, size_t num = 1)
 
{
 
	memcpy(destination, source, num * sizeof(T));
 
}
 

	
 
/**
 
 * Type-safe version of memmove().
 
 *
 
 * @param destination Pointer to the destination buffer
 
 * @param source Pointer to the source buffer
 
 * @param num number of items to be copied. (!not number of bytes!)
 
 */
 
template <typename T>
 
static FORCEINLINE void MemMoveT(T *destination, const T *source, size_t num = 1)
 
static inline void MemMoveT(T *destination, const T *source, size_t num = 1)
 
{
 
	memmove(destination, source, num * sizeof(T));
 
}
 

	
 
/**
 
 * Type-safe version of memset().
 
 *
 
 * @param ptr Pointer to the destination buffer
 
 * @param value Value to be set
 
 * @param num number of items to be set (!not number of bytes!)
 
 */
 
template <typename T>
 
static FORCEINLINE void MemSetT(T *ptr, byte value, size_t num = 1)
 
static inline void MemSetT(T *ptr, byte value, size_t num = 1)
 
{
 
	memset(ptr, value, num * sizeof(T));
 
}
 

	
 
/**
 
 * Type-safe version of memcmp().
 
@@ -59,13 +59,13 @@ static FORCEINLINE void MemSetT(T *ptr, 
 
 * @param ptr1 Pointer to the first buffer
 
 * @param ptr2 Pointer to the second buffer
 
 * @param num Number of items to compare. (!not number of bytes!)
 
 * @return an int value indicating the relationship between the content of the two buffers
 
 */
 
template <typename T>
 
static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
 
static inline int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
 
{
 
	return memcmp(ptr1, ptr2, num * sizeof(T));
 
}
 

	
 
/**
 
 * Type safe memory reverse operation.
 
@@ -73,13 +73,13 @@ static FORCEINLINE int MemCmpT(const T *
 
 *  type of the pointers.
 
 *
 
 * @param ptr1 Start-pointer to the block of memory.
 
 * @param ptr2 End-pointer to the block of memory.
 
 */
 
template <typename T>
 
static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2)
 
static inline void MemReverseT(T *ptr1, T *ptr2)
 
{
 
	assert(ptr1 != NULL && ptr2 != NULL);
 
	assert(ptr1 < ptr2);
 

	
 
	do {
 
		Swap(*ptr1, *ptr2);
 
@@ -90,13 +90,13 @@ static FORCEINLINE void MemReverseT(T *p
 
 * Type safe memory reverse operation (overloaded)
 
 *
 
 * @param ptr Pointer to the block of memory.
 
 * @param num The number of items we want to reverse.
 
 */
 
template <typename T>
 
static FORCEINLINE void MemReverseT(T *ptr, size_t num)
 
static inline void MemReverseT(T *ptr, size_t num)
 
{
 
	assert(ptr != NULL);
 

	
 
	MemReverseT(ptr, ptr + (num - 1));
 
}
 

	
src/core/overflowsafe_type.hpp
Show inline comments
 
@@ -30,126 +30,126 @@ private:
 
public:
 
	OverflowSafeInt() : m_value(0) { }
 

	
 
	OverflowSafeInt(const OverflowSafeInt& other) { this->m_value = other.m_value; }
 
	OverflowSafeInt(const int64 int_)             { this->m_value = int_; }
 

	
 
	FORCEINLINE OverflowSafeInt& operator = (const OverflowSafeInt& other) { this->m_value = other.m_value; return *this; }
 
	inline OverflowSafeInt& operator = (const OverflowSafeInt& other) { this->m_value = other.m_value; return *this; }
 

	
 
	FORCEINLINE OverflowSafeInt operator - () const { return OverflowSafeInt(-this->m_value); }
 
	inline OverflowSafeInt operator - () const { return OverflowSafeInt(-this->m_value); }
 

	
 
	/**
 
	 * Safe implementation of addition.
 
	 * @param other the amount to add
 
	 * @note when the addition would yield more than T_MAX (or less than T_MIN),
 
	 *       it will be T_MAX (respectively T_MIN).
 
	 */
 
	FORCEINLINE OverflowSafeInt& operator += (const OverflowSafeInt& other)
 
	inline OverflowSafeInt& operator += (const OverflowSafeInt& other)
 
	{
 
		if ((T_MAX - abs(other.m_value)) < abs(this->m_value) &&
 
				(this->m_value < 0) == (other.m_value < 0)) {
 
			this->m_value = (this->m_value < 0) ? T_MIN : T_MAX ;
 
		} else {
 
			this->m_value += other.m_value;
 
		}
 
		return *this;
 
	}
 

	
 
	/* Operators for addition and substraction */
 
	FORCEINLINE OverflowSafeInt  operator +  (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result += other; return result; }
 
	FORCEINLINE OverflowSafeInt  operator +  (const int              other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
 
	FORCEINLINE OverflowSafeInt  operator +  (const uint             other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
 
	FORCEINLINE OverflowSafeInt& operator -= (const OverflowSafeInt& other)       { return *this += (-other); }
 
	FORCEINLINE OverflowSafeInt  operator -  (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result -= other; return result; }
 
	FORCEINLINE OverflowSafeInt  operator -  (const int              other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
 
	FORCEINLINE OverflowSafeInt  operator -  (const uint             other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
 
	inline OverflowSafeInt  operator +  (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result += other; return result; }
 
	inline OverflowSafeInt  operator +  (const int              other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
 
	inline OverflowSafeInt  operator +  (const uint             other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
 
	inline OverflowSafeInt& operator -= (const OverflowSafeInt& other)       { return *this += (-other); }
 
	inline OverflowSafeInt  operator -  (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result -= other; return result; }
 
	inline OverflowSafeInt  operator -  (const int              other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
 
	inline OverflowSafeInt  operator -  (const uint             other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
 

	
 
	FORCEINLINE OverflowSafeInt& operator ++ () { return *this += 1; }
 
	FORCEINLINE OverflowSafeInt& operator -- () { return *this += -1; }
 
	FORCEINLINE OverflowSafeInt operator ++ (int) { OverflowSafeInt org = *this; *this += 1; return org; }
 
	FORCEINLINE OverflowSafeInt operator -- (int) { OverflowSafeInt org = *this; *this += -1; return org; }
 
	inline OverflowSafeInt& operator ++ () { return *this += 1; }
 
	inline OverflowSafeInt& operator -- () { return *this += -1; }
 
	inline OverflowSafeInt operator ++ (int) { OverflowSafeInt org = *this; *this += 1; return org; }
 
	inline OverflowSafeInt operator -- (int) { OverflowSafeInt org = *this; *this += -1; return org; }
 

	
 
	/**
 
	 * Safe implementation of multiplication.
 
	 * @param factor the factor to multiply this with.
 
	 * @note when the multiplication would yield more than T_MAX (or less than T_MIN),
 
	 *       it will be T_MAX (respectively T_MIN).
 
	 */
 
	FORCEINLINE OverflowSafeInt& operator *= (const int factor)
 
	inline OverflowSafeInt& operator *= (const int factor)
 
	{
 
		if (factor != 0 && (T_MAX / abs(factor)) < abs(this->m_value)) {
 
			 this->m_value = ((this->m_value < 0) == (factor < 0)) ? T_MAX : T_MIN ;
 
		} else {
 
			this->m_value *= factor ;
 
		}
 
		return *this;
 
	}
 

	
 
	/* Operators for multiplication */
 
	FORCEINLINE OverflowSafeInt operator * (const int64  factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
 
	FORCEINLINE OverflowSafeInt operator * (const int    factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	FORCEINLINE OverflowSafeInt operator * (const uint   factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	FORCEINLINE OverflowSafeInt operator * (const uint16 factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	FORCEINLINE OverflowSafeInt operator * (const byte   factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	inline OverflowSafeInt operator * (const int64  factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
 
	inline OverflowSafeInt operator * (const int    factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	inline OverflowSafeInt operator * (const uint   factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	inline OverflowSafeInt operator * (const uint16 factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 
	inline OverflowSafeInt operator * (const byte   factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
 

	
 
	/* Operators for division */
 
	FORCEINLINE OverflowSafeInt& operator /= (const int64            divisor)       { this->m_value /= divisor; return *this; }
 
	FORCEINLINE OverflowSafeInt  operator /  (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; }
 
	FORCEINLINE OverflowSafeInt  operator /  (const int              divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; }
 
	FORCEINLINE OverflowSafeInt  operator /  (const uint             divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; }
 
	inline OverflowSafeInt& operator /= (const int64            divisor)       { this->m_value /= divisor; return *this; }
 
	inline OverflowSafeInt  operator /  (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; }
 
	inline OverflowSafeInt  operator /  (const int              divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; }
 
	inline OverflowSafeInt  operator /  (const uint             divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; }
 

	
 
	/* Operators for modulo */
 
	FORCEINLINE OverflowSafeInt& operator %= (const int  divisor)       { this->m_value %= divisor; return *this; }
 
	FORCEINLINE OverflowSafeInt  operator %  (const int  divisor) const { OverflowSafeInt result = *this; result %= divisor; return result; }
 
	inline OverflowSafeInt& operator %= (const int  divisor)       { this->m_value %= divisor; return *this; }
 
	inline OverflowSafeInt  operator %  (const int  divisor) const { OverflowSafeInt result = *this; result %= divisor; return result; }
 

	
 
	/* Operators for shifting */
 
	FORCEINLINE OverflowSafeInt& operator <<= (const int shift)       { this->m_value <<= shift; return *this; }
 
	FORCEINLINE OverflowSafeInt  operator <<  (const int shift) const { OverflowSafeInt result = *this; result <<= shift; return result; }
 
	FORCEINLINE OverflowSafeInt& operator >>= (const int shift)       { this->m_value >>= shift; return *this; }
 
	FORCEINLINE OverflowSafeInt  operator >>  (const int shift) const { OverflowSafeInt result = *this; result >>= shift; return result; }
 
	inline OverflowSafeInt& operator <<= (const int shift)       { this->m_value <<= shift; return *this; }
 
	inline OverflowSafeInt  operator <<  (const int shift) const { OverflowSafeInt result = *this; result <<= shift; return result; }
 
	inline OverflowSafeInt& operator >>= (const int shift)       { this->m_value >>= shift; return *this; }
 
	inline OverflowSafeInt  operator >>  (const int shift) const { OverflowSafeInt result = *this; result >>= shift; return result; }
 

	
 
	/* Operators for (in)equality when comparing overflow safe ints */
 
	FORCEINLINE bool operator == (const OverflowSafeInt& other) const { return this->m_value == other.m_value; }
 
	FORCEINLINE bool operator != (const OverflowSafeInt& other) const { return !(*this == other); }
 
	FORCEINLINE bool operator >  (const OverflowSafeInt& other) const { return this->m_value > other.m_value; }
 
	FORCEINLINE bool operator >= (const OverflowSafeInt& other) const { return this->m_value >= other.m_value; }
 
	FORCEINLINE bool operator <  (const OverflowSafeInt& other) const { return !(*this >= other); }
 
	FORCEINLINE bool operator <= (const OverflowSafeInt& other) const { return !(*this > other); }
 
	inline bool operator == (const OverflowSafeInt& other) const { return this->m_value == other.m_value; }
 
	inline bool operator != (const OverflowSafeInt& other) const { return !(*this == other); }
 
	inline bool operator >  (const OverflowSafeInt& other) const { return this->m_value > other.m_value; }
 
	inline bool operator >= (const OverflowSafeInt& other) const { return this->m_value >= other.m_value; }
 
	inline bool operator <  (const OverflowSafeInt& other) const { return !(*this >= other); }
 
	inline bool operator <= (const OverflowSafeInt& other) const { return !(*this > other); }
 

	
 
	/* Operators for (in)equality when comparing non-overflow safe ints */
 
	FORCEINLINE bool operator == (const int other) const { return this->m_value == other; }
 
	FORCEINLINE bool operator != (const int other) const { return !(*this == other); }
 
	FORCEINLINE bool operator >  (const int other) const { return this->m_value > other; }
 
	FORCEINLINE bool operator >= (const int other) const { return this->m_value >= other; }
 
	FORCEINLINE bool operator <  (const int other) const { return !(*this >= other); }
 
	FORCEINLINE bool operator <= (const int other) const { return !(*this > other); }
 
	inline bool operator == (const int other) const { return this->m_value == other; }
 
	inline bool operator != (const int other) const { return !(*this == other); }
 
	inline bool operator >  (const int other) const { return this->m_value > other; }
 
	inline bool operator >= (const int other) const { return this->m_value >= other; }
 
	inline bool operator <  (const int other) const { return !(*this >= other); }
 
	inline bool operator <= (const int other) const { return !(*this > other); }
 

	
 
	FORCEINLINE operator int64 () const { return this->m_value; }
 
	inline operator int64 () const { return this->m_value; }
 
};
 

	
 
/* Sometimes we got int64 operator OverflowSafeInt instead of vice versa. Handle that properly */
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator + (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator - (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator * (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator / (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator + (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator - (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator * (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator / (int64 a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 

	
 
/* Sometimes we got int operator OverflowSafeInt instead of vice versa. Handle that properly */
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator + (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator - (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator * (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator / (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator + (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator - (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator * (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator / (int   a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 

	
 
/* Sometimes we got uint operator OverflowSafeInt instead of vice versa. Handle that properly */
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator + (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator - (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator * (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator / (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator + (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator - (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator * (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator / (uint  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 

	
 
/* Sometimes we got byte operator OverflowSafeInt instead of vice versa. Handle that properly */
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator + (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator - (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator * (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> FORCEINLINE OverflowSafeInt<T, T_MAX, T_MIN> operator / (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator + (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b + (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator - (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return -b + (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator * (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return b * (uint)a; }
 
template <class T, int64 T_MAX, int64 T_MIN> inline OverflowSafeInt<T, T_MAX, T_MIN> operator / (byte  a, OverflowSafeInt<T, T_MAX, T_MIN> b) { return (OverflowSafeInt<T, T_MAX, T_MIN>)a / (int)b; }
 

	
 
typedef OverflowSafeInt<int64, INT64_MAX, INT64_MIN> OverflowSafeInt64;
 

	
 
#endif /* OVERFLOWSAFE_TYPE_HPP */
src/core/pool_type.hpp
Show inline comments
 
@@ -95,34 +95,34 @@ struct Pool : PoolBase {
 
	/**
 
	 * Returs Titem with given index
 
	 * @param index of item to get
 
	 * @return pointer to Titem
 
	 * @pre index < this->first_unused
 
	 */
 
	FORCEINLINE Titem *Get(size_t index)
 
	inline Titem *Get(size_t index)
 
	{
 
		assert(index < this->first_unused);
 
		return this->data[index];
 
	}
 

	
 
	/**
 
	 * Tests whether given index can be used to get valid (non-NULL) Titem
 
	 * @param index index to examine
 
	 * @return true if PoolItem::Get(index) will return non-NULL pointer
 
	 */
 
	FORCEINLINE bool IsValidID(size_t index)
 
	inline bool IsValidID(size_t index)
 
	{
 
		return index < this->first_unused && this->Get(index) != NULL;
 
	}
 

	
 
	/**
 
	 * Tests whether we can allocate 'n' items
 
	 * @param n number of items we want to allocate
 
	 * @return true if 'n' items can be allocated
 
	 */
 
	FORCEINLINE bool CanAllocate(size_t n = 1)
 
	inline bool CanAllocate(size_t n = 1)
 
	{
 
		bool ret = this->items <= Tmax_size - n;
 
#ifdef OTTD_ASSERT
 
		this->checked = ret ? n : 0;
 
#endif /* OTTD_ASSERT */
 
		return ret;
 
@@ -139,23 +139,23 @@ struct Pool : PoolBase {
 
		/**
 
		 * Allocates space for new Titem
 
		 * @param size size of Titem
 
		 * @return pointer to allocated memory
 
		 * @note can never fail (return NULL), use CanAllocate() to check first!
 
		 */
 
		FORCEINLINE void *operator new(size_t size)
 
		inline void *operator new(size_t size)
 
		{
 
			return Tpool->GetNew(size);
 
		}
 

	
 
		/**
 
		 * Marks Titem as free. Its memory is released
 
		 * @param p memory to free
 
		 * @note the item has to be allocated in the pool!
 
		 */
 
		FORCEINLINE void operator delete(void *p)
 
		inline void operator delete(void *p)
 
		{
 
			Titem *pn = (Titem *)p;
 
			assert(pn == Tpool->Get(pn->index));
 
			Tpool->FreeItem(pn->index);
 
		}
 

	
 
@@ -164,26 +164,26 @@ struct Pool : PoolBase {
 
		 * @param size size of Titem
 
		 * @param index index of item
 
		 * @return pointer to allocated memory
 
		 * @note can never fail (return NULL), use CanAllocate() to check first!
 
		 * @pre index has to be unused! Else it will crash
 
		 */
 
		FORCEINLINE void *operator new(size_t size, size_t index)
 
		inline void *operator new(size_t size, size_t index)
 
		{
 
			return Tpool->GetNew(size, index);
 
		}
 

	
 
		/**
 
		 * Allocates space for new Titem at given memory address
 
		 * @param size size of Titem
 
		 * @param ptr where are we allocating the item?
 
		 * @return pointer to allocated memory (== ptr)
 
		 * @note use of this is strongly discouraged
 
		 * @pre the memory must not be allocated in the Pool!
 
		 */
 
		FORCEINLINE void *operator new(size_t size, void *ptr)
 
		inline void *operator new(size_t size, void *ptr)
 
		{
 
			for (size_t i = 0; i < Tpool->first_unused; i++) {
 
				/* Don't allow creating new objects over existing.
 
				 * Even if we called the destructor and reused this memory,
 
				 * we don't know whether 'size' and size of currently allocated
 
				 * memory are the same (because of possible inheritance).
 
@@ -199,85 +199,85 @@ struct Pool : PoolBase {
 

	
 
		/**
 
		 * Tests whether we can allocate 'n' items
 
		 * @param n number of items we want to allocate
 
		 * @return true if 'n' items can be allocated
 
		 */
 
		static FORCEINLINE bool CanAllocateItem(size_t n = 1)
 
		static inline bool CanAllocateItem(size_t n = 1)
 
		{
 
			return Tpool->CanAllocate(n);
 
		}
 

	
 
		/**
 
		 * Returns current state of pool cleaning - yes or no
 
		 * @return true iff we are cleaning the pool now
 
		 */
 
		static FORCEINLINE bool CleaningPool()
 
		static inline bool CleaningPool()
 
		{
 
			return Tpool->cleaning;
 
		}
 

	
 
		/**
 
		 * Tests whether given index can be used to get valid (non-NULL) Titem
 
		 * @param index index to examine
 
		 * @return true if PoolItem::Get(index) will return non-NULL pointer
 
		 */
 
		static FORCEINLINE bool IsValidID(size_t index)
 
		static inline bool IsValidID(size_t index)
 
		{
 
			return Tpool->IsValidID(index);
 
		}
 

	
 
		/**
 
		 * Returs Titem with given index
 
		 * @param index of item to get
 
		 * @return pointer to Titem
 
		 * @pre index < this->first_unused
 
		 */
 
		static FORCEINLINE Titem *Get(size_t index)
 
		static inline Titem *Get(size_t index)
 
		{
 
			return Tpool->Get(index);
 
		}
 

	
 
		/**
 
		 * Returs Titem with given index
 
		 * @param index of item to get
 
		 * @return pointer to Titem
 
		 * @note returns NULL for invalid index
 
		 */
 
		static FORCEINLINE Titem *GetIfValid(size_t index)
 
		static inline Titem *GetIfValid(size_t index)
 
		{
 
			return index < Tpool->first_unused ? Tpool->Get(index) : NULL;
 
		}
 

	
 
		/**
 
		 * Returns first unused index. Useful when iterating over
 
		 * all pool items.
 
		 * @return first unused index
 
		 */
 
		static FORCEINLINE size_t GetPoolSize()
 
		static inline size_t GetPoolSize()
 
		{
 
			return Tpool->first_unused;
 
		}
 

	
 
		/**
 
		 * Returns number of valid items in the pool
 
		 * @return number of valid items in the pool
 
		 */
 
		static FORCEINLINE size_t GetNumItems()
 
		static inline size_t GetNumItems()
 
		{
 
			return Tpool->items;
 
		}
 

	
 
		/**
 
		 * Dummy function called after destructor of each member.
 
		 * If you want to use it, override it in PoolItem's subclass.
 
		 * @param index index of deleted item
 
		 * @note when this function is called, PoolItem::Get(index) == NULL.
 
		 * @note it's called only when !CleaningPool()
 
		 */
 
		static FORCEINLINE void PostDestructor(size_t index) { }
 
		static inline void PostDestructor(size_t index) { }
 
	};
 

	
 
private:
 
	static const size_t NO_FREE_ITEM = MAX_UVALUE(size_t); ///< Contant to indicate we can't allocate any more items
 

	
 
	/**
src/core/random_func.hpp
Show inline comments
 
@@ -78,29 +78,29 @@ void SetRandomSeed(uint32 seed);
 
		#define Random() DoRandom(__LINE__, __FILE__)
 
	#endif
 
	uint32 DoRandom(int line, const char *file);
 
	#define RandomRange(max) DoRandomRange(max, __LINE__, __FILE__)
 
	uint32 DoRandomRange(uint32 max, int line, const char *file);
 
#else
 
	static FORCEINLINE uint32 Random()
 
	static inline uint32 Random()
 
	{
 
		return _random.Next();
 
	}
 

	
 
	static FORCEINLINE uint32 RandomRange(uint32 max)
 
	static inline uint32 RandomRange(uint32 max)
 
	{
 
		return _random.Next(max);
 
	}
 
#endif
 

	
 
static FORCEINLINE uint32 InteractiveRandom()
 
static inline uint32 InteractiveRandom()
 
{
 
	return _interactive_random.Next();
 
}
 

	
 
static FORCEINLINE uint32 InteractiveRandomRange(uint32 max)
 
static inline uint32 InteractiveRandomRange(uint32 max)
 
{
 
	return _interactive_random.Next(max);
 
}
 

	
 
/**
 
 * Checks if a given randomize-number is below a given probability.
 
@@ -114,13 +114,13 @@ static FORCEINLINE uint32 InteractiveRan
 
 *
 
 * @param a The numerator of the fraction
 
 * @param b The denominator of the fraction, must of course not be null
 
 * @param r The given randomize-number
 
 * @return True if the probability given by r is less or equal to (a/b)
 
 */
 
static FORCEINLINE bool Chance16I(const uint a, const uint b, const uint32 r)
 
static inline bool Chance16I(const uint a, const uint b, const uint32 r)
 
{
 
	assert(b != 0);
 
	return (((uint16)r * b + b / 2) >> 16) < a;
 
}
 

	
 
/**
 
@@ -133,13 +133,13 @@ static FORCEINLINE bool Chance16I(const 
 
 * @param b The denominator of the fraction
 
 * @return True with (a/b) probability
 
 */
 
#ifdef RANDOM_DEBUG
 
	#define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
 
#else
 
static FORCEINLINE bool Chance16(const uint a, const uint b)
 
static inline bool Chance16(const uint a, const uint b)
 
{
 
	return Chance16I(a, b, Random());
 
}
 
#endif /* RANDOM_DEBUG */
 

	
 
/**
 
@@ -157,13 +157,13 @@ static FORCEINLINE bool Chance16(const u
 
 * @param r The variable to save the randomize-number from Random()
 
 * @return True in (a/b) percent
 
 */
 
#ifdef RANDOM_DEBUG
 
	#define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
 
#else
 
static FORCEINLINE bool Chance16R(const uint a, const uint b, uint32 &r)
 
static inline bool Chance16R(const uint a, const uint b, uint32 &r)
 
{
 
	r = Random();
 
	return Chance16I(a, b, r);
 
}
 
#endif /* RANDOM_DEBUG */
 

	
src/core/smallmap_type.hpp
Show inline comments
 
@@ -23,13 +23,13 @@
 
template <typename T, typename U>
 
struct SmallPair {
 
	T first;
 
	U second;
 

	
 
	/** Initializes this Pair with data */
 
	FORCEINLINE SmallPair(const T &first, const U &second) : first(first), second(second) { }
 
	inline SmallPair(const T &first, const U &second) : first(first), second(second) { }
 
};
 

	
 
/**
 
 * Implementation of simple mapping class. Both types have to be POD ("Plain Old Data")!
 
 * It has inherited accessors from SmallVector().
 
 * @tvar T Key type.
 
@@ -42,57 +42,57 @@ template <typename T, typename U, uint S
 
struct SmallMap : SmallVector<SmallPair<T, U>, S> {
 
	typedef ::SmallPair<T, U> Pair;
 
	typedef Pair *iterator;
 
	typedef const Pair *const_iterator;
 

	
 
	/** Creates new SmallMap. Data are initialized in SmallVector constructor */
 
	FORCEINLINE SmallMap() { }
 
	inline SmallMap() { }
 
	/** Data are freed in SmallVector destructor */
 
	FORCEINLINE ~SmallMap() { }
 
	inline ~SmallMap() { }
 

	
 
	/**
 
	 * Finds given key in this map
 
	 * @param key key to find
 
	 * @return &Pair(key, data) if found, this->End() if not
 
	 */
 
	FORCEINLINE Pair *Find(const T &key)
 
	inline Pair *Find(const T &key)
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			if (key == this->data[i].first) return &this->data[i];
 
		}
 
		return this->End();
 
	}
 

	
 
	/**
 
	 * Tests whether a key is assigned in this map.
 
	 * @param key key to test
 
	 * @return true iff the item is present
 
	 */
 
	FORCEINLINE bool Contains(const T &key)
 
	inline bool Contains(const T &key)
 
	{
 
		return this->Find(key) != this->End();
 
	}
 

	
 
	/**
 
	 * Removes given pair from this map
 
	 * @param pair pair to remove
 
	 * @note it has to be pointer to pair in this map. It is overwritten by the last item.
 
	 */
 
	FORCEINLINE void Erase(Pair *pair)
 
	inline void Erase(Pair *pair)
 
	{
 
		assert(pair >= this->Begin() && pair < this->End());
 
		*pair = this->data[--this->items];
 
	}
 

	
 
	/**
 
	 * Removes given key from this map
 
	 * @param key key to remove
 
	 * @return true iff the key was found
 
	 * @note last item is moved to its place, so don't increase your iterator if true is returned!
 
	 */
 
	FORCEINLINE bool Erase(const T &key)
 
	inline bool Erase(const T &key)
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			if (key == this->data[i].first) {
 
				this->data[i] = this->data[--this->items];
 
				return true;
 
			}
 
@@ -103,13 +103,13 @@ struct SmallMap : SmallVector<SmallPair<
 
	/**
 
	 * Adds new item to this map.
 
	 * @param key key
 
	 * @param data data
 
	 * @return true iff the key wasn't already present
 
	 */
 
	FORCEINLINE bool Insert(const T &key, const U &data)
 
	inline bool Insert(const T &key, const U &data)
 
	{
 
		if (this->Contains(key)) return false;
 
		Pair *n = this->Append();
 
		n->first = key;
 
		n->second = data;
 
		return true;
 
@@ -118,23 +118,23 @@ struct SmallMap : SmallVector<SmallPair<
 
	/**
 
	 * Returns data belonging to this key
 
	 * @param key key
 
	 * @return data belonging to this key
 
	 * @note if this key wasn't present, new entry is created
 
	 */
 
	FORCEINLINE U &operator[](const T &key)
 
	inline U &operator[](const T &key)
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			if (key == this->data[i].first) return this->data[i].second;
 
		}
 
		Pair *n = this->Append();
 
		n->first = key;
 
		return n->second;
 
	}
 

	
 
	FORCEINLINE void SortByKey()
 
	inline void SortByKey()
 
	{
 
		QSortT(this->Begin(), this->items, KeySorter);
 
	}
 

	
 
	static int CDECL KeySorter(const Pair *a, const Pair *b)
 
	{
src/core/smallvec_type.hpp
Show inline comments
 
@@ -62,35 +62,35 @@ public:
 
		free(this->data);
 
	}
 

	
 
	/**
 
	 * Remove all items from the list.
 
	 */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		/* In fact we just reset the item counter avoiding the need to
 
		 * probably reallocate the same amount of memory the list was
 
		 * previously using. */
 
		this->items = 0;
 
	}
 

	
 
	/**
 
	 * Remove all items from the list and free allocated memory.
 
	 */
 
	FORCEINLINE void Reset()
 
	inline void Reset()
 
	{
 
		this->items = 0;
 
		this->capacity = 0;
 
		free(data);
 
		data = NULL;
 
	}
 

	
 
	/**
 
	 * Compact the list down to the smallest block size boundary.
 
	 */
 
	FORCEINLINE void Compact()
 
	inline void Compact()
 
	{
 
		uint capacity = Align(this->items, S);
 
		if (capacity >= this->capacity) return;
 

	
 
		this->capacity = capacity;
 
		this->data = ReallocT(this->data, this->capacity);
 
@@ -98,13 +98,13 @@ public:
 

	
 
	/**
 
	 * Append an item and return it.
 
	 * @param to_add the number of items to append
 
	 * @return pointer to newly allocated item
 
	 */
 
	FORCEINLINE T *Append(uint to_add = 1)
 
	inline T *Append(uint to_add = 1)
 
	{
 
		uint begin = this->items;
 
		this->items += to_add;
 

	
 
		if (this->items > this->capacity) {
 
			this->capacity = Align(this->items, S);
 
@@ -117,13 +117,13 @@ public:
 
	/**
 
	 * Search for the first occurrence of an item.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to search for
 
	 * @return The position of the item, or End() when not present
 
	 */
 
	FORCEINLINE const T *Find(const T &item) const
 
	inline const T *Find(const T &item) const
 
	{
 
		const T *pos = this->Begin();
 
		const T *end = this->End();
 
		while (pos != end && *pos != item) pos++;
 
		return pos;
 
	}
 
@@ -131,13 +131,13 @@ public:
 
	/**
 
	 * Search for the first occurrence of an item.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to search for
 
	 * @return The position of the item, or End() when not present
 
	 */
 
	FORCEINLINE T *Find(const T &item)
 
	inline T *Find(const T &item)
 
	{
 
		T *pos = this->Begin();
 
		const T *end = this->End();
 
		while (pos != end && *pos != item) pos++;
 
		return pos;
 
	}
 
@@ -145,13 +145,13 @@ public:
 
	/**
 
	 * Search for the first occurrence of an item.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to search for
 
	 * @return The position of the item, or -1 when not present
 
	 */
 
	FORCEINLINE int FindIndex(const T &item)
 
	inline int FindIndex(const T &item)
 
	{
 
		int index = 0;
 
		T *pos = this->Begin();
 
		const T *end = this->End();
 
		while (pos != end && *pos != item) {
 
			pos++;
 
@@ -163,134 +163,134 @@ public:
 
	/**
 
	 * Tests whether a item is present in the vector.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to test for
 
	 * @return true iff the item is present
 
	 */
 
	FORCEINLINE bool Contains(const T &item) const
 
	inline bool Contains(const T &item) const
 
	{
 
		return this->Find(item) != this->End();
 
	}
 

	
 
	/**
 
	 * Removes given item from this vector
 
	 * @param item item to remove
 
	 * @note it has to be pointer to item in this map. It is overwritten by the last item.
 
	 */
 
	FORCEINLINE void Erase(T *item)
 
	inline void Erase(T *item)
 
	{
 
		assert(item >= this->Begin() && item < this->End());
 
		*item = this->data[--this->items];
 
	}
 

	
 
	/**
 
	 * Tests whether a item is present in the vector, and appends it to the end if not.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to test for
 
	 * @return true iff the item is was already present
 
	 */
 
	FORCEINLINE bool Include(const T &item)
 
	inline bool Include(const T &item)
 
	{
 
		bool is_member = this->Contains(item);
 
		if (!is_member) *this->Append() = item;
 
		return is_member;
 
	}
 

	
 
	/**
 
	 * Get the number of items in the list.
 
	 */
 
	FORCEINLINE uint Length() const
 
	inline uint Length() const
 
	{
 
		return this->items;
 
	}
 

	
 
	/**
 
	 * Get the pointer to the first item (const)
 
	 *
 
	 * @return the pointer to the first item
 
	 */
 
	FORCEINLINE const T *Begin() const
 
	inline const T *Begin() const
 
	{
 
		return this->data;
 
	}
 

	
 
	/**
 
	 * Get the pointer to the first item
 
	 *
 
	 * @return the pointer to the first item
 
	 */
 
	FORCEINLINE T *Begin()
 
	inline T *Begin()
 
	{
 
		return this->data;
 
	}
 

	
 
	/**
 
	 * Get the pointer behind the last valid item (const)
 
	 *
 
	 * @return the pointer behind the last valid item
 
	 */
 
	FORCEINLINE const T *End() const
 
	inline const T *End() const
 
	{
 
		return &this->data[this->items];
 
	}
 

	
 
	/**
 
	 * Get the pointer behind the last valid item
 
	 *
 
	 * @return the pointer behind the last valid item
 
	 */
 
	FORCEINLINE T *End()
 
	inline T *End()
 
	{
 
		return &this->data[this->items];
 
	}
 

	
 
	/**
 
	 * Get the pointer to item "number" (const)
 
	 *
 
	 * @param index the position of the item
 
	 * @return the pointer to the item
 
	 */
 
	FORCEINLINE const T *Get(uint index) const
 
	inline const T *Get(uint index) const
 
	{
 
		/* Allow access to the 'first invalid' item */
 
		assert(index <= this->items);
 
		return &this->data[index];
 
	}
 

	
 
	/**
 
	 * Get the pointer to item "number"
 
	 *
 
	 * @param index the position of the item
 
	 * @return the pointer to the item
 
	 */
 
	FORCEINLINE T *Get(uint index)
 
	inline T *Get(uint index)
 
	{
 
		/* Allow access to the 'first invalid' item */
 
		assert(index <= this->items);
 
		return &this->data[index];
 
	}
 

	
 
	/**
 
	 * Get item "number" (const)
 
	 *
 
	 * @param index the position of the item
 
	 * @return the item
 
	 */
 
	FORCEINLINE const T &operator[](uint index) const
 
	inline const T &operator[](uint index) const
 
	{
 
		assert(index < this->items);
 
		return this->data[index];
 
	}
 

	
 
	/**
 
	 * Get item "number"
 
	 *
 
	 * @param index the position of the item
 
	 * @return the item
 
	 */
 
	FORCEINLINE T &operator[](uint index)
 
	inline T &operator[](uint index)
 
	{
 
		assert(index < this->items);
 
		return this->data[index];
 
	}
 
};
 

	
 
@@ -313,13 +313,13 @@ public:
 
		this->Clear();
 
	}
 

	
 
	/**
 
	 * Remove all items from the list.
 
	 */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			free(this->data[i]);
 
		}
 

	
 
		this->items = 0;
 
@@ -344,13 +344,13 @@ public:
 
		this->Clear();
 
	}
 

	
 
	/**
 
	 * Remove all items from the list.
 
	 */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		for (uint i = 0; i < this->items; i++) {
 
			delete this->data[i];
 
		}
 

	
 
		this->items = 0;
src/core/sort_func.hpp
Show inline comments
 
@@ -22,13 +22,13 @@
 
 * @param base Pointer to the first element of the array to be sorted.
 
 * @param num Number of elements in the array pointed by base.
 
 * @param comparator Function that compares two elements.
 
 * @param desc Sort descending.
 
 */
 
template <typename T>
 
static FORCEINLINE void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
 
static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
 
{
 
	if (num < 2) return;
 

	
 
	qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator);
 

	
 
	if (desc) MemReverseT(base, num);
src/depot_base.h
Show inline comments
 
@@ -26,24 +26,24 @@ struct Depot : DepotPool::PoolItem<&_dep
 
	uint16 town_cn;    ///< The N-1th depot for this town (consecutive number)
 
	Date build_date;   ///< Date of construction
 

	
 
	Depot(TileIndex xy = INVALID_TILE) : xy(xy) {}
 
	~Depot();
 

	
 
	static FORCEINLINE Depot *GetByTile(TileIndex tile)
 
	static inline Depot *GetByTile(TileIndex tile)
 
	{
 
		return Depot::Get(GetDepotIndex(tile));
 
	}
 

	
 
	/**
 
	 * Is the "type" of depot the same as the given depot,
 
	 * i.e. are both a rail, road or ship depots?
 
	 * @param d The depot to compare to.
 
	 * @return true iff their types are equal.
 
	 */
 
	FORCEINLINE bool IsOfType(const Depot *d) const
 
	inline bool IsOfType(const Depot *d) const
 
	{
 
		return GetTileType(d->xy) == GetTileType(this->xy);
 
	}
 
};
 

	
 
#define FOR_ALL_DEPOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Depot, depot_index, var, start)
src/engine_base.h
Show inline comments
 
@@ -113,13 +113,13 @@ struct Engine : EnginePool::PoolItem<&_e
 
	uint16 GetRange() const;
 

	
 
	/**
 
	 * Check if the engine is a ground vehicle.
 
	 * @return True iff the engine is a train or a road vehicle.
 
	 */
 
	FORCEINLINE bool IsGroundVehicle() const
 
	inline bool IsGroundVehicle() const
 
	{
 
		return this->type == VEH_TRAIN || this->type == VEH_ROAD;
 
	}
 

	
 
	/**
 
	 * Retrieve the NewGRF the engine is tied to.
src/gfx.cpp
Show inline comments
 
@@ -66,30 +66,30 @@ struct DrawStringParams {
 
	DrawStringParams(TextColour colour, FontSize fontsize) : fontsize(fontsize), cur_colour(colour), prev_colour(colour) {}
 

	
 
	/**
 
	 * Switch to new colour \a c.
 
	 * @param c New colour to use.
 
	 */
 
	FORCEINLINE void SetColour(TextColour c)
 
	inline void SetColour(TextColour c)
 
	{
 
		assert(c >=  TC_BLUE && c <= TC_BLACK);
 
		this->prev_colour = this->cur_colour;
 
		this->cur_colour = c;
 
	}
 

	
 
	/** Switch to previous colour. */
 
	FORCEINLINE void SetPreviousColour()
 
	inline void SetPreviousColour()
 
	{
 
		Swap(this->cur_colour, this->prev_colour);
 
	}
 

	
 
	/**
 
	 * Switch to using a new font \a f.
 
	 * @param f New font to use.
 
	 */
 
	FORCEINLINE void SetFontSize(FontSize f)
 
	inline void SetFontSize(FontSize f)
 
	{
 
		this->fontsize = f;
 
	}
 
};
 

	
 
static ReusableBuffer<uint8> _cursor_backup;
src/goal_base.h
Show inline comments
 
@@ -27,18 +27,18 @@ struct Goal : GoalPool::PoolItem<&_goal_
 
	GoalTypeID dst;      ///< Index of type
 
	char *text;          ///< Text of the goal.
 

	
 
	/**
 
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
 
	 */
 
	FORCEINLINE Goal() { }
 
	inline Goal() { }
 

	
 
	/**
 
	 * (Empty) destructor has to be defined else operator delete might be called with NULL parameter
 
	 */
 
	FORCEINLINE ~Goal() { free(this->text); }
 
	inline ~Goal() { free(this->text); }
 
};
 

	
 
#define FOR_ALL_GOALS_FROM(var, start) FOR_ALL_ITEMS_FROM(Goal, goal_index, var, start)
 
#define FOR_ALL_GOALS(var) FOR_ALL_GOALS_FROM(var, 0)
 

	
 
#endif /* GOAL_BASE_H */
src/ground_vehicle.hpp
Show inline comments
 
@@ -108,13 +108,13 @@ struct GroundVehicle : public Specialize
 
	}
 

	
 
	/**
 
	 * Calculates the total slope resistance for this vehicle.
 
	 * @return Slope resistance.
 
	 */
 
	FORCEINLINE int32 GetSlopeResistance() const
 
	inline int32 GetSlopeResistance() const
 
	{
 
		int32 incl = 0;
 

	
 
		for (const T *u = T::From(this); u != NULL; u = u->Next()) {
 
			if (HasBit(u->gv_flags, GVF_GOINGUP_BIT)) {
 
				incl += u->gcache.cached_slope_resistance;
 
@@ -129,13 +129,13 @@ struct GroundVehicle : public Specialize
 
	/**
 
	 * Updates vehicle's Z position and inclination.
 
	 * Used when the vehicle entered given tile.
 
	 * @pre The vehicle has to be at (or near to) a border of the tile,
 
	 *      directed towards tile centre
 
	 */
 
	FORCEINLINE void UpdateZPositionAndInclination()
 
	inline void UpdateZPositionAndInclination()
 
	{
 
		this->z_pos = GetSlopePixelZ(this->x_pos, this->y_pos);
 
		ClrBit(this->gv_flags, GVF_GOINGUP_BIT);
 
		ClrBit(this->gv_flags, GVF_GOINGDOWN_BIT);
 

	
 
		if (T::From(this)->TileMayHaveSlopedTrack()) {
 
@@ -154,13 +154,13 @@ struct GroundVehicle : public Specialize
 
	/**
 
	 * Updates vehicle's Z position.
 
	 * Inclination can't change in the middle of a tile.
 
	 * The faster code is used for trains and road vehicles unless they are
 
	 * reversing on a sloped tile.
 
	 */
 
	FORCEINLINE void UpdateZPosition()
 
	inline void UpdateZPosition()
 
	{
 
#if 0
 
		/* The following code does this: */
 

	
 
		if (HasBit(this->gv_flags, GVF_GOINGUP_BIT)) {
 
			switch (this->direction) {
 
@@ -226,13 +226,13 @@ struct GroundVehicle : public Specialize
 
	/**
 
	 * Checks if the vehicle is in a slope and sets the required flags in that case.
 
	 * @param new_tile True if the vehicle reached a new tile.
 
	 * @param turned Indicates if the vehicle has turned.
 
	 * @return Old height of the vehicle.
 
	 */
 
	FORCEINLINE byte UpdateInclination(bool new_tile, bool turned)
 
	inline byte UpdateInclination(bool new_tile, bool turned)
 
	{
 
		byte old_z = this->z_pos;
 

	
 
		if (new_tile) {
 
			this->UpdateZPositionAndInclination();
 
		} else {
 
@@ -243,105 +243,105 @@ struct GroundVehicle : public Specialize
 
		return old_z;
 
	}
 

	
 
	/**
 
	 * Set front engine state.
 
	 */
 
	FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, GVSF_FRONT); }
 
	inline void SetFrontEngine() { SetBit(this->subtype, GVSF_FRONT); }
 

	
 
	/**
 
	 * Remove the front engine state.
 
	 */
 
	FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, GVSF_FRONT); }
 
	inline void ClearFrontEngine() { ClrBit(this->subtype, GVSF_FRONT); }
 

	
 
	/**
 
	 * Set a vehicle to be an articulated part.
 
	 */
 
	FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, GVSF_ARTICULATED_PART); }
 
	inline void SetArticulatedPart() { SetBit(this->subtype, GVSF_ARTICULATED_PART); }
 

	
 
	/**
 
	 * Clear a vehicle from being an articulated part.
 
	 */
 
	FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, GVSF_ARTICULATED_PART); }
 
	inline void ClearArticulatedPart() { ClrBit(this->subtype, GVSF_ARTICULATED_PART); }
 

	
 
	/**
 
	 * Set a vehicle to be a wagon.
 
	 */
 
	FORCEINLINE void SetWagon() { SetBit(this->subtype, GVSF_WAGON); }
 
	inline void SetWagon() { SetBit(this->subtype, GVSF_WAGON); }
 

	
 
	/**
 
	 * Clear wagon property.
 
	 */
 
	FORCEINLINE void ClearWagon() { ClrBit(this->subtype, GVSF_WAGON); }
 
	inline void ClearWagon() { ClrBit(this->subtype, GVSF_WAGON); }
 

	
 
	/**
 
	 * Set engine status.
 
	 */
 
	FORCEINLINE void SetEngine() { SetBit(this->subtype, GVSF_ENGINE); }
 
	inline void SetEngine() { SetBit(this->subtype, GVSF_ENGINE); }
 

	
 
	/**
 
	 * Clear engine status.
 
	 */
 
	FORCEINLINE void ClearEngine() { ClrBit(this->subtype, GVSF_ENGINE); }
 
	inline void ClearEngine() { ClrBit(this->subtype, GVSF_ENGINE); }
 

	
 
	/**
 
	 * Set a vehicle as a free wagon.
 
	 */
 
	FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, GVSF_FREE_WAGON); }
 
	inline void SetFreeWagon() { SetBit(this->subtype, GVSF_FREE_WAGON); }
 

	
 
	/**
 
	 * Clear a vehicle from being a free wagon.
 
	 */
 
	FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, GVSF_FREE_WAGON); }
 
	inline void ClearFreeWagon() { ClrBit(this->subtype, GVSF_FREE_WAGON); }
 

	
 
	/**
 
	 * Set a vehicle as a multiheaded engine.
 
	 */
 
	FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, GVSF_MULTIHEADED); }
 
	inline void SetMultiheaded() { SetBit(this->subtype, GVSF_MULTIHEADED); }
 

	
 
	/**
 
	 * Clear multiheaded engine property.
 
	 */
 
	FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, GVSF_MULTIHEADED); }
 
	inline void ClearMultiheaded() { ClrBit(this->subtype, GVSF_MULTIHEADED); }
 

	
 
	/**
 
	 * Check if the vehicle is a free wagon (got no engine in front of it).
 
	 * @return Returns true if the vehicle is a free wagon.
 
	 */
 
	FORCEINLINE bool IsFreeWagon() const { return HasBit(this->subtype, GVSF_FREE_WAGON); }
 
	inline bool IsFreeWagon() const { return HasBit(this->subtype, GVSF_FREE_WAGON); }
 

	
 
	/**
 
	 * Check if a vehicle is an engine (can be first in a consist).
 
	 * @return Returns true if vehicle is an engine.
 
	 */
 
	FORCEINLINE bool IsEngine() const { return HasBit(this->subtype, GVSF_ENGINE); }
 
	inline bool IsEngine() const { return HasBit(this->subtype, GVSF_ENGINE); }
 

	
 
	/**
 
	 * Check if a vehicle is a wagon.
 
	 * @return Returns true if vehicle is a wagon.
 
	 */
 
	FORCEINLINE bool IsWagon() const { return HasBit(this->subtype, GVSF_WAGON); }
 
	inline bool IsWagon() const { return HasBit(this->subtype, GVSF_WAGON); }
 

	
 
	/**
 
	 * Check if the vehicle is a multiheaded engine.
 
	 * @return Returns true if the vehicle is a multiheaded engine.
 
	 */
 
	FORCEINLINE bool IsMultiheaded() const { return HasBit(this->subtype, GVSF_MULTIHEADED); }
 
	inline bool IsMultiheaded() const { return HasBit(this->subtype, GVSF_MULTIHEADED); }
 

	
 
	/**
 
	 * Tell if we are dealing with the rear end of a multiheaded engine.
 
	 * @return True if the engine is the rear part of a dualheaded engine.
 
	 */
 
	FORCEINLINE bool IsRearDualheaded() const { return this->IsMultiheaded() && !this->IsEngine(); }
 
	inline bool IsRearDualheaded() const { return this->IsMultiheaded() && !this->IsEngine(); }
 

	
 
	/**
 
	 * Update the GUI variant of the current speed of the vehicle.
 
	 * Also mark the widget dirty when that is needed, i.e. when
 
	 * the speed of this vehicle has changed.
 
	 */
 
	FORCEINLINE void SetLastSpeed()
 
	inline void SetLastSpeed()
 
	{
 
		if (this->cur_speed != this->gcache.last_speed) {
 
			SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
 
			this->gcache.last_speed = this->cur_speed;
 
		}
 
	}
 
@@ -357,13 +357,13 @@ protected:
 
	 * the distance to drive before moving a step on the map.
 
	 * @param accel     The acceleration we would like to give this vehicle.
 
	 * @param min_speed The minimum speed here, in vehicle specific units.
 
	 * @param max_speed The maximum speed here, in vehicle specific units.
 
	 * @return Distance to drive.
 
	 */
 
	FORCEINLINE uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
 
	inline uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
 
	{
 
		uint spd = this->subspeed + accel;
 
		this->subspeed = (byte)spd;
 

	
 
		/* When we are going faster than the maximum speed, reduce the speed
 
		 * somewhat gradually. But never lower than the maximum speed. */
src/house.h
Show inline comments
 
@@ -121,13 +121,13 @@ struct HouseSpec {
 
	byte processing_time;              ///< Periodic refresh multiplier
 
	byte minimum_life;                 ///< The minimum number of years this house will survive before the town rebuilds it
 
	uint32 watched_cargoes;            ///< Cargo types watched for acceptance.
 

	
 
	Money GetRemovalCost() const;
 

	
 
	static FORCEINLINE HouseSpec *Get(size_t house_id)
 
	static inline HouseSpec *Get(size_t house_id)
 
	{
 
		assert(house_id < HOUSE_MAX);
 
		extern HouseSpec _house_specs[];
 
		return &_house_specs[house_id];
 
	}
 
};
src/industry.h
Show inline comments
 
@@ -90,13 +90,13 @@ struct Industry : IndustryPool::PoolItem
 
	/**
 
	 * Get the industry of the given tile
 
	 * @param tile the tile to get the industry from
 
	 * @pre IsTileType(t, MP_INDUSTRY)
 
	 * @return the industry
 
	 */
 
	static FORCEINLINE Industry *GetByTile(TileIndex tile)
 
	static inline Industry *GetByTile(TileIndex tile)
 
	{
 
		return Industry::Get(GetIndustryIndex(tile));
 
	}
 

	
 
	static Industry *GetRandom();
 
	static void PostDestructor(size_t index);
src/misc/array.hpp
Show inline comments
 
@@ -27,52 +27,52 @@ protected:
 

	
 
	static const uint Tcapacity = B * N; ///< total max number of items
 

	
 
	SuperArray data; ///< array of arrays of items
 

	
 
	/** return first sub-array with free space for new item */
 
	FORCEINLINE SubArray& FirstFreeSubArray()
 
	inline SubArray& FirstFreeSubArray()
 
	{
 
		uint super_size = data.Length();
 
		if (super_size > 0) {
 
			SubArray& s = data[super_size - 1];
 
			if (!s.IsFull()) return s;
 
		}
 
		return *data.AppendC();
 
	}
 

	
 
public:
 
	/** implicit constructor */
 
	FORCEINLINE SmallArray() { }
 
	inline SmallArray() { }
 
	/** Clear (destroy) all items */
 
	FORCEINLINE void Clear() {data.Clear();}
 
	inline void Clear() {data.Clear();}
 
	/** Return actual number of items */
 
	FORCEINLINE uint Length() const
 
	inline uint Length() const
 
	{
 
		uint super_size = data.Length();
 
		if (super_size == 0) return 0;
 
		uint sub_size = data[super_size - 1].Length();
 
		return (super_size - 1) * B + sub_size;
 
	}
 
	/** return true if array is empty */
 
	FORCEINLINE bool IsEmpty() { return data.IsEmpty(); }
 
	inline bool IsEmpty() { return data.IsEmpty(); }
 
	/** return true if array is full */
 
	FORCEINLINE bool IsFull() { return data.IsFull() && data[N - 1].IsFull(); }
 
	inline bool IsFull() { return data.IsFull() && data[N - 1].IsFull(); }
 
	/** allocate but not construct new item */
 
	FORCEINLINE T *Append() { return FirstFreeSubArray().Append(); }
 
	inline T *Append() { return FirstFreeSubArray().Append(); }
 
	/** allocate and construct new item */
 
	FORCEINLINE T *AppendC() { return FirstFreeSubArray().AppendC(); }
 
	inline T *AppendC() { return FirstFreeSubArray().AppendC(); }
 
	/** indexed access (non-const) */
 
	FORCEINLINE T& operator [] (uint index)
 
	inline T& operator [] (uint index)
 
	{
 
		const SubArray& s = data[index / B];
 
		T& item = s[index % B];
 
		return item;
 
	}
 
	/** indexed access (const) */
 
	FORCEINLINE const T& operator [] (uint index) const
 
	inline const T& operator [] (uint index) const
 
	{
 
		const SubArray& s = data[index / B];
 
		const T& item = s[index % B];
 
		return item;
 
	}
 

	
src/misc/binaryheap.hpp
Show inline comments
 
@@ -82,13 +82,13 @@ protected:
 
	 *  is in order again.
 
	 *
 
	 * @param gap The position of the gap
 
	 * @param item The proposed item for filling the gap
 
	 * @return The (gap)position where the item fits
 
	 */
 
	FORCEINLINE uint HeapifyDown(uint gap, T *item)
 
	inline uint HeapifyDown(uint gap, T *item)
 
	{
 
		assert(gap != 0);
 

	
 
		/* The first child of the gap is at [parent * 2] */
 
		uint child = gap * 2;
 

	
 
@@ -118,13 +118,13 @@ protected:
 
	 *  is in order again.
 
	 *
 
	 * @param gap The position of the gap
 
	 * @param item The proposed item for filling the gap
 
	 * @return The (gap)position where the item fits
 
	 */
 
	FORCEINLINE uint HeapifyUp(uint gap, T *item)
 
	inline uint HeapifyUp(uint gap, T *item)
 
	{
 
		assert(gap != 0);
 

	
 
		uint parent;
 

	
 
		while (gap > 1) {
 
@@ -139,13 +139,13 @@ protected:
 
		}
 
		return gap;
 
	}
 

	
 
#if BINARYHEAP_CHECK
 
	/** Verify the heap consistency */
 
	FORCEINLINE void CheckConsistency()
 
	inline void CheckConsistency()
 
	{
 
		for (uint child = 2; child <= this->items; child++) {
 
			uint parent = child / 2;
 
			assert(!(*this->data[child] < *this->data[parent]));
 
		}
 
	}
 
@@ -154,57 +154,57 @@ protected:
 
public:
 
	/**
 
	 * Get the number of items stored in the priority queue.
 
	 *
 
	 *  @return The number of items in the queue
 
	 */
 
	FORCEINLINE uint Length() const { return this->items; }
 
	inline uint Length() const { return this->items; }
 

	
 
	/**
 
	 * Test if the priority queue is empty.
 
	 *
 
	 * @return True if empty
 
	 */
 
	FORCEINLINE bool IsEmpty() const { return this->items == 0; }
 
	inline bool IsEmpty() const { return this->items == 0; }
 

	
 
	/**
 
	 * Test if the priority queue is full.
 
	 *
 
	 * @return True if full.
 
	 */
 
	FORCEINLINE bool IsFull() const { return this->items >= this->capacity; }
 
	inline bool IsFull() const { return this->items >= this->capacity; }
 

	
 
	/**
 
	 * Get the smallest item in the binary tree.
 
	 *
 
	 * @return The smallest item, or throw assert if empty.
 
	 */
 
	FORCEINLINE T *Begin()
 
	inline T *Begin()
 
	{
 
		assert(!this->IsEmpty());
 
		return this->data[1];
 
	}
 

	
 
	/**
 
	 * Get the LAST item in the binary tree.
 
	 *
 
	 * @note The last item is not neccesary the biggest!
 
	 *
 
	 * @return The last item
 
	 */
 
	FORCEINLINE T *End()
 
	inline T *End()
 
	{
 
		return this->data[1 + this->items];
 
	}
 

	
 
	/**
 
	 * Insert new item into the priority queue, maintaining heap order.
 
	 *
 
	 * @param new_item The pointer to the new item
 
	 */
 
	FORCEINLINE void Include(T *new_item)
 
	inline void Include(T *new_item)
 
	{
 
		if (this->IsFull()) {
 
			assert(this->capacity < UINT_MAX / 2);
 

	
 
			this->capacity *= 2;
 
			this->data = ReallocT<T*>(this->data, this->capacity + 1);
 
@@ -219,13 +219,13 @@ public:
 
	/**
 
	 * Remove and return the smallest (and also first) item
 
	 *  from the priority queue.
 
	 *
 
	 * @return The pointer to the removed item
 
	 */
 
	FORCEINLINE T *Shift()
 
	inline T *Shift()
 
	{
 
		assert(!this->IsEmpty());
 

	
 
		T *first = this->Begin();
 

	
 
		this->items--;
 
@@ -241,13 +241,13 @@ public:
 

	
 
	/**
 
	 * Remove item at given index from the priority queue.
 
	 *
 
	 * @param index The position of the item in the heap
 
	 */
 
	FORCEINLINE void Remove(uint index)
 
	inline void Remove(uint index)
 
	{
 
		if (index < this->items) {
 
			assert(index != 0);
 
			this->items--;
 
			/* at position index we have a gap now */
 

	
 
@@ -269,13 +269,13 @@ public:
 
	 *  Matching is done by comparing adress of the
 
	 *  item.
 
	 *
 
	 * @param item The reference to the item
 
	 * @return The index of the item or zero if not found
 
	 */
 
	FORCEINLINE uint FindIndex(const T &item) const
 
	inline uint FindIndex(const T &item) const
 
	{
 
		if (this->IsEmpty()) return 0;
 
		for (T **ppI = this->data + 1, **ppLast = ppI + this->items; ppI <= ppLast; ppI++) {
 
			if (*ppI == &item) {
 
				return ppI - this->data;
 
			}
 
@@ -284,10 +284,10 @@ public:
 
	}
 

	
 
	/**
 
	 * Make the priority queue empty.
 
	 * All remaining items will remain untouched.
 
	 */
 
	FORCEINLINE void Clear() { this->items = 0; }
 
	inline void Clear() { this->items = 0; }
 
};
 

	
 
#endif /* BINARYHEAP_HPP */
src/misc/blob.hpp
Show inline comments
 
@@ -68,53 +68,53 @@ private:
 

	
 
public:
 
	static const size_t tail_reserve = 4; ///< four extra bytes will be always allocated and zeroed at the end
 
	static const size_t header_size = sizeof(BlobHeader);
 

	
 
	/** default constructor - initializes empty blob */
 
	FORCEINLINE ByteBlob() { InitEmpty(); }
 
	inline ByteBlob() { InitEmpty(); }
 

	
 
	/** copy constructor */
 
	FORCEINLINE ByteBlob(const ByteBlob &src)
 
	inline ByteBlob(const ByteBlob &src)
 
	{
 
		InitEmpty();
 
		AppendRaw(src);
 
	}
 

	
 
	/** move constructor - take ownership of blob data */
 
	FORCEINLINE ByteBlob(BlobHeader * const & src)
 
	inline ByteBlob(BlobHeader * const & src)
 
	{
 
		assert(src != NULL);
 
		header = src;
 
		*const_cast<BlobHeader**>(&src) = NULL;
 
	}
 

	
 
	/** destructor */
 
	FORCEINLINE ~ByteBlob()
 
	inline ~ByteBlob()
 
	{
 
		Free();
 
	}
 

	
 
protected:
 
	/** all allocation should happen here */
 
	static FORCEINLINE BlobHeader *RawAlloc(size_t num_bytes)
 
	static inline BlobHeader *RawAlloc(size_t num_bytes)
 
	{
 
		return (BlobHeader*)MallocT<byte>(num_bytes);
 
	}
 

	
 
	/**
 
	 * Return header pointer to the static BlobHeader with
 
	 * both items and capacity containing zero
 
	 */
 
	static FORCEINLINE BlobHeader *Zero()
 
	static inline BlobHeader *Zero()
 
	{
 
		return const_cast<BlobHeader *>(&ByteBlob::hdrEmpty[1]);
 
	}
 

	
 
	/** simple allocation policy - can be optimized later */
 
	static FORCEINLINE size_t AllocPolicy(size_t min_alloc)
 
	static inline size_t AllocPolicy(size_t min_alloc)
 
	{
 
		if (min_alloc < (1 << 9)) {
 
			if (min_alloc < (1 << 5)) return (1 << 5);
 
			return (min_alloc < (1 << 7)) ? (1 << 7) : (1 << 9);
 
		}
 
		if (min_alloc < (1 << 15)) {
 
@@ -127,130 +127,130 @@ protected:
 
		}
 
		min_alloc = (min_alloc | ((1 << 20) - 1)) + 1;
 
		return min_alloc;
 
	}
 

	
 
	/** all deallocations should happen here */
 
	static FORCEINLINE void RawFree(BlobHeader *p)
 
	static inline void RawFree(BlobHeader *p)
 
	{
 
		/* Just to silence an unsilencable GCC 4.4+ warning. */
 
		assert(p != ByteBlob::hdrEmpty);
 

	
 
		/* In case GCC warns about the following, see GCC's PR38509 why it is bogus. */
 
		free(p);
 
	}
 

	
 
	/** initialize the empty blob */
 
	FORCEINLINE void InitEmpty()
 
	inline void InitEmpty()
 
	{
 
		header = Zero();
 
	}
 

	
 
	/** initialize blob by attaching it to the given header followed by data */
 
	FORCEINLINE void Init(BlobHeader *src)
 
	inline void Init(BlobHeader *src)
 
	{
 
		header = &src[1];
 
	}
 

	
 
	/** blob header accessor - use it rather than using the pointer arithmetics directly - non-const version */
 
	FORCEINLINE BlobHeader& Hdr()
 
	inline BlobHeader& Hdr()
 
	{
 
		return *(header - 1);
 
	}
 

	
 
	/** blob header accessor - use it rather than using the pointer arithmetics directly - const version */
 
	FORCEINLINE const BlobHeader& Hdr() const
 
	inline const BlobHeader& Hdr() const
 
	{
 
		return *(header - 1);
 
	}
 

	
 
	/** return reference to the actual blob size - used when the size needs to be modified */
 
	FORCEINLINE size_t& LengthRef()
 
	inline size_t& LengthRef()
 
	{
 
		return Hdr().items;
 
	}
 

	
 
public:
 
	/** return true if blob doesn't contain valid data */
 
	FORCEINLINE bool IsEmpty() const
 
	inline bool IsEmpty() const
 
	{
 
		return Length() == 0;
 
	}
 

	
 
	/** return the number of valid data bytes in the blob */
 
	FORCEINLINE size_t Length() const
 
	inline size_t Length() const
 
	{
 
		return Hdr().items;
 
	}
 

	
 
	/** return the current blob capacity in bytes */
 
	FORCEINLINE size_t Capacity() const
 
	inline size_t Capacity() const
 
	{
 
		return Hdr().capacity;
 
	}
 

	
 
	/** return pointer to the first byte of data - non-const version */
 
	FORCEINLINE byte *Begin()
 
	inline byte *Begin()
 
	{
 
		return data;
 
	}
 

	
 
	/** return pointer to the first byte of data - const version */
 
	FORCEINLINE const byte *Begin() const
 
	inline const byte *Begin() const
 
	{
 
		return data;
 
	}
 

	
 
	/** invalidate blob's data - doesn't free buffer */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		LengthRef() = 0;
 
	}
 

	
 
	/** free the blob's memory */
 
	FORCEINLINE void Free()
 
	inline void Free()
 
	{
 
		if (Capacity() > 0) {
 
			RawFree(&Hdr());
 
			InitEmpty();
 
		}
 
	}
 

	
 
	/** append new bytes at the end of existing data bytes - reallocates if necessary */
 
	FORCEINLINE void AppendRaw(const void *p, size_t num_bytes)
 
	inline void AppendRaw(const void *p, size_t num_bytes)
 
	{
 
		assert(p != NULL);
 
		if (num_bytes > 0) {
 
			memcpy(Append(num_bytes), p, num_bytes);
 
		}
 
	}
 

	
 
	/** append bytes from given source blob to the end of existing data bytes - reallocates if necessary */
 
	FORCEINLINE void AppendRaw(const ByteBlob& src)
 
	inline void AppendRaw(const ByteBlob& src)
 
	{
 
		if (!src.IsEmpty()) {
 
			memcpy(Append(src.Length()), src.Begin(), src.Length());
 
		}
 
	}
 

	
 
	/**
 
	 * Reallocate if there is no free space for num_bytes bytes.
 
	 *  @return pointer to the new data to be added
 
	 */
 
	FORCEINLINE byte *Prepare(size_t num_bytes)
 
	inline byte *Prepare(size_t num_bytes)
 
	{
 
		size_t new_size = Length() + num_bytes;
 
		if (new_size > Capacity()) SmartAlloc(new_size);
 
		return data + Length();
 
	}
 

	
 
	/**
 
	 * Increase Length() by num_bytes.
 
	 *  @return pointer to the new data added
 
	 */
 
	FORCEINLINE byte *Append(size_t num_bytes)
 
	inline byte *Append(size_t num_bytes)
 
	{
 
		byte *pNewData = Prepare(num_bytes);
 
		LengthRef() += num_bytes;
 
		return pNewData;
 
	}
 

	
 
@@ -278,13 +278,13 @@ public:
 
			RawFree(&Hdr());
 
		}
 
		Init(tmp);
 
	}
 

	
 
	/** fixing the four bytes at the end of blob data - useful when blob is used to hold string */
 
	FORCEINLINE void FixTail() const
 
	inline void FixTail() const
 
	{
 
		if (Capacity() > 0) {
 
			byte *p = &data[Length()];
 
			for (uint i = 0; i < tail_reserve; i++) {
 
				p[i] = 0;
 
			}
 
@@ -314,93 +314,93 @@ public:
 
		OnTransfer(const OnTransfer& src) : header(src.header) {assert(src.header != NULL); *const_cast<typename base::BlobHeader**>(&src.header) = NULL;}
 
		OnTransfer(CBlobT& src) : header(src.header) {src.InitEmpty();}
 
		~OnTransfer() {assert(header == NULL);}
 
	};
 

	
 
	/** Default constructor - makes new Blob ready to accept any data */
 
	FORCEINLINE CBlobT()
 
	inline CBlobT()
 
		: base()
 
	{}
 

	
 
	/** Take ownership constructor */
 
	FORCEINLINE CBlobT(const OnTransfer& ot)
 
	inline CBlobT(const OnTransfer& ot)
 
		: base(ot.header)
 
	{}
 

	
 
	/** Destructor - ensures that allocated memory (if any) is freed */
 
	FORCEINLINE ~CBlobT()
 
	inline ~CBlobT()
 
	{
 
		Free();
 
	}
 

	
 
	/** Check the validity of item index (only in debug mode) */
 
	FORCEINLINE void CheckIdx(size_t index) const
 
	inline void CheckIdx(size_t index) const
 
	{
 
		assert(index < Size());
 
	}
 

	
 
	/** Return pointer to the first data item - non-const version */
 
	FORCEINLINE T *Data()
 
	inline T *Data()
 
	{
 
		return (T*)base::Begin();
 
	}
 

	
 
	/** Return pointer to the first data item - const version */
 
	FORCEINLINE const T *Data() const
 
	inline const T *Data() const
 
	{
 
		return (const T*)base::Begin();
 
	}
 

	
 
	/** Return pointer to the index-th data item - non-const version */
 
	FORCEINLINE T *Data(size_t index)
 
	inline T *Data(size_t index)
 
	{
 
		CheckIdx(index);
 
		return (Data() + index);
 
	}
 

	
 
	/** Return pointer to the index-th data item - const version */
 
	FORCEINLINE const T *Data(size_t index) const
 
	inline const T *Data(size_t index) const
 
	{
 
		CheckIdx(index);
 
		return (Data() + index);
 
	}
 

	
 
	/** Return number of items in the Blob */
 
	FORCEINLINE size_t Size() const
 
	inline size_t Size() const
 
	{
 
		return (base::Length() / type_size);
 
	}
 

	
 
	/** Return total number of items that can fit in the Blob without buffer reallocation */
 
	FORCEINLINE size_t MaxSize() const
 
	inline size_t MaxSize() const
 
	{
 
		return (base::Capacity() / type_size);
 
	}
 

	
 
	/** Return number of additional items that can fit in the Blob without buffer reallocation */
 
	FORCEINLINE size_t GetReserve() const
 
	inline size_t GetReserve() const
 
	{
 
		return ((base::Capacity() - base::Length()) / type_size);
 
	}
 

	
 
	/** Grow number of data items in Blob by given number - doesn't construct items */
 
	FORCEINLINE T *GrowSizeNC(size_t num_items)
 
	inline T *GrowSizeNC(size_t num_items)
 
	{
 
		return (T*)base::Append(num_items * type_size);
 
	}
 

	
 
	/**
 
	 * Ensures that given number of items can be added to the end of Blob. Returns pointer to the
 
	 *  first free (unused) item
 
	 */
 
	FORCEINLINE T *MakeFreeSpace(size_t num_items)
 
	inline T *MakeFreeSpace(size_t num_items)
 
	{
 
		return (T*)base::Prepare(num_items * type_size);
 
	}
 

	
 
	FORCEINLINE OnTransfer Transfer()
 
	inline OnTransfer Transfer()
 
	{
 
		return OnTransfer(*this);
 
	}
 
};
 

	
 

	
src/misc/countedptr.hpp
Show inline comments
 
@@ -32,70 +32,70 @@ public:
 
protected:
 
	/** here we hold our pointer to the target */
 
	Tcls *m_pT;
 

	
 
public:
 
	/** default (NULL) construct or construct from a raw pointer */
 
	FORCEINLINE CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) {AddRef();}
 
	inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) {AddRef();}
 

	
 
	/** copy constructor (invoked also when initializing from another smart ptr) */
 
	FORCEINLINE CCountedPtr(const CCountedPtr& src) : m_pT(src.m_pT) {AddRef();}
 
	inline CCountedPtr(const CCountedPtr& src) : m_pT(src.m_pT) {AddRef();}
 

	
 
	/** destructor releasing the reference */
 
	FORCEINLINE ~CCountedPtr() {Release();}
 
	inline ~CCountedPtr() {Release();}
 

	
 
protected:
 
	/** add one ref to the underlaying object */
 
	FORCEINLINE void AddRef() {if (m_pT != NULL) m_pT->AddRef();}
 
	inline void AddRef() {if (m_pT != NULL) m_pT->AddRef();}
 

	
 
public:
 
	/** release smart pointer (and decrement ref count) if not null */
 
	FORCEINLINE void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}}
 
	inline void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}}
 

	
 
	/** dereference of smart pointer - const way */
 
	FORCEINLINE const Tcls *operator -> () const {assert(m_pT != NULL); return m_pT;}
 
	inline const Tcls *operator -> () const {assert(m_pT != NULL); return m_pT;}
 

	
 
	/** dereference of smart pointer - non const way */
 
	FORCEINLINE Tcls *operator -> () {assert(m_pT != NULL); return m_pT;}
 
	inline Tcls *operator -> () {assert(m_pT != NULL); return m_pT;}
 

	
 
	/** raw pointer casting operator - const way */
 
	FORCEINLINE operator const Tcls*() const {assert(m_pT == NULL); return m_pT;}
 
	inline operator const Tcls*() const {assert(m_pT == NULL); return m_pT;}
 

	
 
	/** raw pointer casting operator - non-const way */
 
	FORCEINLINE operator Tcls*() {return m_pT;}
 
	inline operator Tcls*() {return m_pT;}
 

	
 
	/** operator & to support output arguments */
 
	FORCEINLINE Tcls** operator &() {assert(m_pT == NULL); return &m_pT;}
 
	inline Tcls** operator &() {assert(m_pT == NULL); return &m_pT;}
 

	
 
	/** assignment operator from raw ptr */
 
	FORCEINLINE CCountedPtr& operator = (Tcls *pT) {Assign(pT); return *this;}
 
	inline CCountedPtr& operator = (Tcls *pT) {Assign(pT); return *this;}
 

	
 
	/** assignment operator from another smart ptr */
 
	FORCEINLINE CCountedPtr& operator = (const CCountedPtr& src) {Assign(src.m_pT); return *this;}
 
	inline CCountedPtr& operator = (const CCountedPtr& src) {Assign(src.m_pT); return *this;}
 

	
 
	/** assignment operator helper */
 
	FORCEINLINE void Assign(Tcls *pT);
 
	inline void Assign(Tcls *pT);
 

	
 
	/** one way how to test for NULL value */
 
	FORCEINLINE bool IsNull() const {return m_pT == NULL;}
 
	inline bool IsNull() const {return m_pT == NULL;}
 

	
 
	/** another way how to test for NULL value */
 
	//FORCEINLINE bool operator == (const CCountedPtr& sp) const {return m_pT == sp.m_pT;}
 
	//inline bool operator == (const CCountedPtr& sp) const {return m_pT == sp.m_pT;}
 

	
 
	/** yet another way how to test for NULL value */
 
	//FORCEINLINE bool operator != (const CCountedPtr& sp) const {return m_pT != sp.m_pT;}
 
	//inline bool operator != (const CCountedPtr& sp) const {return m_pT != sp.m_pT;}
 

	
 
	/** assign pointer w/o incrementing ref count */
 
	FORCEINLINE void Attach(Tcls *pT) {Release(); m_pT = pT;}
 
	inline void Attach(Tcls *pT) {Release(); m_pT = pT;}
 

	
 
	/** detach pointer w/o decrementing ref count */
 
	FORCEINLINE Tcls *Detach() {Tcls *pT = m_pT; m_pT = NULL; return pT;}
 
	inline Tcls *Detach() {Tcls *pT = m_pT; m_pT = NULL; return pT;}
 
};
 

	
 
template <class Tcls_>
 
FORCEINLINE void CCountedPtr<Tcls_>::Assign(Tcls *pT)
 
inline void CCountedPtr<Tcls_>::Assign(Tcls *pT)
 
{
 
	/* if they are the same, we do nothing */
 
	if (pT != m_pT) {
 
		if (pT != NULL) pT->AddRef();        // AddRef new pointer if any
 
		Tcls *pTold = m_pT;                  // save original ptr
 
		m_pT = pT;                           // update m_pT to new value
src/misc/fixedsizearray.hpp
Show inline comments
 
@@ -38,19 +38,19 @@ protected:
 
	 * the only member of fixed size array is pointer to the block
 
	 *  of C array of items. Header can be found on the offset -sizeof(ArrayHeader).
 
	 */
 
	T *data;
 

	
 
	/** return reference to the array header (non-const) */
 
	FORCEINLINE ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
 
	inline ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
 
	/** return reference to the array header (const) */
 
	FORCEINLINE const ArrayHeader& Hdr() const { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
 
	inline const ArrayHeader& Hdr() const { return *(ArrayHeader*)(((byte*)data) - HeaderSize); }
 
	/** return reference to the block reference counter */
 
	FORCEINLINE uint& RefCnt() { return Hdr().reference_count; }
 
	inline uint& RefCnt() { return Hdr().reference_count; }
 
	/** return reference to number of used items */
 
	FORCEINLINE uint& SizeRef() { return Hdr().items; }
 
	inline uint& SizeRef() { return Hdr().items; }
 

	
 
public:
 
	/** Default constructor. Preallocate space for items and header, then initialize header. */
 
	FixedSizeArray()
 
	{
 
		/* Ensure the size won't overflow. */
 
@@ -80,35 +80,35 @@ public:
 
		/* free the memory block occupied by items */
 
		free(((byte*)data) - HeaderSize);
 
		data = NULL;
 
	}
 

	
 
	/** Clear (destroy) all items */
 
	FORCEINLINE void Clear()
 
	inline void Clear()
 
	{
 
		/* Walk through all allocated items backward and destroy them
 
		 * Note: this->Length() can be zero. In that case data[this->Length() - 1] is evaluated unsigned
 
		 *       on some compilers with some architectures. (e.g. gcc with x86) */
 
		for (T *pItem = this->data + this->Length() - 1; pItem >= this->data; pItem--) {
 
			pItem->~T();
 
		}
 
		/* number of items become zero */
 
		SizeRef() = 0;
 
	}
 

	
 
	/** return number of used items */
 
	FORCEINLINE uint Length() const { return Hdr().items; }
 
	inline uint Length() const { return Hdr().items; }
 
	/** return true if array is full */
 
	FORCEINLINE bool IsFull() const { return Length() >= C; }
 
	inline bool IsFull() const { return Length() >= C; }
 
	/** return true if array is empty */
 
	FORCEINLINE bool IsEmpty() const { return Length() <= 0; }
 
	inline bool IsEmpty() const { return Length() <= 0; }
 
	/** add (allocate), but don't construct item */
 
	FORCEINLINE T *Append() { assert(!IsFull()); return &data[SizeRef()++]; }
 
	inline T *Append() { assert(!IsFull()); return &data[SizeRef()++]; }
 
	/** add and construct item using default constructor */
 
	FORCEINLINE T *AppendC() { T *item = Append(); new(item)T; return item; }
 
	inline T *AppendC() { T *item = Append(); new(item)T; return item; }
 
	/** return item by index (non-const version) */
 
	FORCEINLINE T& operator [] (uint index) { assert(index < Length()); return data[index]; }
 
	inline T& operator [] (uint index) { assert(index < Length()); return data[index]; }
 
	/** return item by index (const version) */
 
	FORCEINLINE const T& operator [] (uint index) const { assert(index < Length()); return data[index]; }
 
	inline const T& operator [] (uint index) const { assert(index < Length()); return data[index]; }
 
};
 

	
 
#endif /* FIXEDSIZEARRAY_HPP */
src/misc/hashtable.hpp
Show inline comments
 
@@ -18,51 +18,51 @@ template <class Titem_>
 
struct CHashTableSlotT
 
{
 
	typedef typename Titem_::Key Key;          // make Titem_::Key a property of HashTable
 

	
 
	Titem_ *m_pFirst;
 

	
 
	FORCEINLINE CHashTableSlotT() : m_pFirst(NULL) {}
 
	inline CHashTableSlotT() : m_pFirst(NULL) {}
 

	
 
	/** hash table slot helper - clears the slot by simple forgetting its items */
 
	FORCEINLINE void Clear() {m_pFirst = NULL;}
 
	inline void Clear() {m_pFirst = NULL;}
 

	
 
	/** hash table slot helper - linear search for item with given key through the given blob - const version */
 
	FORCEINLINE const Titem_ *Find(const Key& key) const
 
	inline const Titem_ *Find(const Key& key) const
 
	{
 
		for (const Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) {
 
			if (pItem->GetKey() == key) {
 
				/* we have found the item, return it */
 
				return pItem;
 
			}
 
		}
 
		return NULL;
 
	}
 

	
 
	/** hash table slot helper - linear search for item with given key through the given blob - non-const version */
 
	FORCEINLINE Titem_ *Find(const Key& key)
 
	inline Titem_ *Find(const Key& key)
 
	{
 
		for (Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) {
 
			if (pItem->GetKey() == key) {
 
				/* we have found the item, return it */
 
				return pItem;
 
			}
 
		}
 
		return NULL;
 
	}
 

	
 
	/** hash table slot helper - add new item to the slot */
 
	FORCEINLINE void Attach(Titem_& new_item)
 
	inline void Attach(Titem_& new_item)
 
	{
 
		assert(new_item.GetHashNext() == NULL);
 
		new_item.SetHashNext(m_pFirst);
 
		m_pFirst = &new_item;
 
	}
 

	
 
	/** hash table slot helper - remove item from a slot */
 
	FORCEINLINE bool Detach(Titem_& item_to_remove)
 
	inline bool Detach(Titem_& item_to_remove)
 
	{
 
		if (m_pFirst == &item_to_remove) {
 
			m_pFirst = item_to_remove.GetHashNext();
 
			item_to_remove.SetHashNext(NULL);
 
			return true;
 
		}
 
@@ -78,13 +78,13 @@ struct CHashTableSlotT
 
		pItem->SetHashNext(item_to_remove.GetHashNext());
 
		item_to_remove.SetHashNext(NULL);
 
		return true;
 
	}
 

	
 
	/** hash table slot helper - remove and return item from a slot */
 
	FORCEINLINE Titem_ *Detach(const Key& key)
 
	inline Titem_ *Detach(const Key& key)
 
	{
 
		/* do we have any items? */
 
		if (m_pFirst == NULL) {
 
			return NULL;
 
		}
 
		/* is it our first item? */
 
@@ -147,38 +147,38 @@ protected:
 

	
 
	Slot  m_slots[Tcapacity]; // here we store our data (array of blobs)
 
	int   m_num_items;        // item counter
 

	
 
public:
 
	/* default constructor */
 
	FORCEINLINE CHashTableT() : m_num_items(0)
 
	inline CHashTableT() : m_num_items(0)
 
	{
 
	}
 

	
 
protected:
 
	/** static helper - return hash for the given key modulo number of slots */
 
	FORCEINLINE static int CalcHash(const Tkey& key)
 
	inline static int CalcHash(const Tkey& key)
 
	{
 
		int32 hash = key.CalcHash();
 
		if ((8 * Thash_bits) < 32) hash ^= hash >> (min(8 * Thash_bits, 31));
 
		if ((4 * Thash_bits) < 32) hash ^= hash >> (min(4 * Thash_bits, 31));
 
		if ((2 * Thash_bits) < 32) hash ^= hash >> (min(2 * Thash_bits, 31));
 
		if ((1 * Thash_bits) < 32) hash ^= hash >> (min(1 * Thash_bits, 31));
 
		hash &= (1 << Thash_bits) - 1;
 
		return hash;
 
	}
 

	
 
	/** static helper - return hash for the given item modulo number of slots */
 
	FORCEINLINE static int CalcHash(const Titem_& item) {return CalcHash(item.GetKey());}
 
	inline static int CalcHash(const Titem_& item) {return CalcHash(item.GetKey());}
 

	
 
public:
 
	/** item count */
 
	FORCEINLINE int Count() const {return m_num_items;}
 
	inline int Count() const {return m_num_items;}
 

	
 
	/** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */
 
	FORCEINLINE void Clear() {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
 
	inline void Clear() {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
 

	
 
	/** const item search */
 
	const Titem_ *Find(const Tkey& key) const
 
	{
 
		int hash = CalcHash(key);
 
		const Slot& slot = m_slots[hash];
src/misc/str.hpp
Show inline comments
 
@@ -21,75 +21,75 @@
 
/** Blob based case sensitive ANSI/UTF-8 string */
 
struct CStrA : public CBlobT<char>
 
{
 
	typedef CBlobT<char> base;                    ///< base class
 

	
 
	/** Create an empty CStrT */
 
	FORCEINLINE CStrA()
 
	inline CStrA()
 
	{
 
	}
 

	
 
	/** Copy constructor */
 
	FORCEINLINE CStrA(const CStrA &src) : base(src)
 
	inline CStrA(const CStrA &src) : base(src)
 
	{
 
		base::FixTail();
 
	}
 

	
 
	/** Take over ownership constructor */
 
	FORCEINLINE CStrA(const OnTransfer& ot)
 
	inline CStrA(const OnTransfer& ot)
 
		: base(ot)
 
	{
 
	}
 

	
 
	/** Grow the actual buffer and fix the trailing zero at the end. */
 
	FORCEINLINE char *GrowSizeNC(uint count)
 
	inline char *GrowSizeNC(uint count)
 
	{
 
		char *ret = base::GrowSizeNC(count);
 
		base::FixTail();
 
		return ret;
 
	}
 

	
 
	/** Append zero-ended C string. */
 
	FORCEINLINE void AppendStr(const char *str)
 
	inline void AppendStr(const char *str)
 
	{
 
		if (!StrEmpty(str)) {
 
			base::AppendRaw(str, strlen(str));
 
			base::FixTail();
 
		}
 
	}
 

	
 
	/** Append another CStrA. */
 
	FORCEINLINE void Append(const CStrA &src)
 
	inline void Append(const CStrA &src)
 
	{
 
		if (src.Length() > 0) {
 
			base::AppendRaw(src);
 
			base::FixTail();
 
		}
 
	}
 

	
 
	/** Assignment from C string. */
 
	FORCEINLINE CStrA &operator = (const char *src)
 
	inline CStrA &operator = (const char *src)
 
	{
 
		base::Clear();
 
		AppendStr(src);
 
		return *this;
 
	}
 

	
 
	/** Assignment from another CStrA. */
 
	FORCEINLINE CStrA &operator = (const CStrA &src)
 
	inline CStrA &operator = (const CStrA &src)
 
	{
 
		if (&src != this) {
 
			base::Clear();
 
			base::AppendRaw(src.Data(), src.Size());
 
			base::FixTail();
 
		}
 
		return *this;
 
	}
 

	
 
	/** Lower-than operator (to support stl collections) */
 
	FORCEINLINE bool operator < (const CStrA &other) const
 
	inline bool operator < (const CStrA &other) const
 
	{
 
		return strcmp(base::Data(), other.Data()) < 0;
 
	}
 

	
 
	/** Add formated string (like vsprintf) at the end of existing contents. */
 
	int AddFormatL(const char *format, va_list args)
src/newgrf.cpp
Show inline comments
 
@@ -204,13 +204,13 @@ protected:
 
	byte *data;
 
	byte *end;
 

	
 
public:
 
	ByteReader(byte *data, byte *end) : data(data), end(end) { }
 

	
 
	FORCEINLINE byte ReadByte()
 
	inline byte ReadByte()
 
	{
 
		if (data < end) return *(data)++;
 
		throw OTTDByteReaderSignal();
 
	}
 

	
 
	uint16 ReadWord()
 
@@ -258,28 +258,28 @@ public:
 
		}
 
		Skip(string_length);
 

	
 
		return string;
 
	}
 

	
 
	FORCEINLINE size_t Remaining() const
 
	inline size_t Remaining() const
 
	{
 
		return end - data;
 
	}
 

	
 
	FORCEINLINE bool HasData(size_t count = 1) const
 
	inline bool HasData(size_t count = 1) const
 
	{
 
		return data + count <= end;
 
	}
 

	
 
	FORCEINLINE byte *Data()
 
	inline byte *Data()
 
	{
 
		return data;
 
	}
 

	
 
	FORCEINLINE void Skip(size_t len)
 
	inline void Skip(size_t len)
 
	{
 
		data += len;
 
		/* It is valid to move the buffer to exactly the end of the data,
 
		 * as there may not be any more data read. */
 
		if (data > end) throw OTTDByteReaderSignal();
 
	}
src/newgrf_airport.h
Show inline comments
 
@@ -42,13 +42,13 @@ public:
 
	 * @param base_tile The basetile for all offsets.
 
	 */
 
	AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile) : TileIterator(base_tile + ToTileIndexDiff(att->ti)), att(att), base_tile(base_tile)
 
	{
 
	}
 

	
 
	FORCEINLINE TileIterator& operator ++()
 
	inline TileIterator& operator ++()
 
	{
 
		this->att++;
 
		if (this->att->ti.x == -0x80) {
 
			this->tile = INVALID_TILE;
 
		} else {
 
			this->tile = base_tile + ToTileIndexDiff(att->ti);
src/newgrf_config.h
Show inline comments
 
@@ -86,13 +86,13 @@ struct GRFIdentifier {
 
	/**
 
	 * Does the identification match the provided values?
 
	 * @param grfid  Expected grfid.
 
	 * @param md5sum Expected md5sum, may be \c NULL (in which case, do not check it).
 
	 * @return the object has the provided grfid and md5sum.
 
	 */
 
	FORCEINLINE bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
 
	inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
 
	{
 
		if (this->grfid != grfid) return false;
 
		if (md5sum == NULL) return true;
 
		return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
 
	}
 
};
src/newgrf_gui.cpp
Show inline comments
 
@@ -836,13 +836,13 @@ struct NewGRFWindow : public QueryString
 

	
 
	/**
 
	 * Pick the palette for the sprite of the grf to display.
 
	 * @param c grf to display.
 
	 * @return Palette for the sprite.
 
	 */
 
	FORCEINLINE PaletteID GetPalette(const GRFConfig *c) const
 
	inline PaletteID GetPalette(const GRFConfig *c) const
 
	{
 
		PaletteID pal;
 

	
 
		/* Pick a colour */
 
		switch (c->status) {
 
			case GCS_NOT_FOUND:
src/pathfinder/follow_track.hpp
Show inline comments
 
@@ -50,31 +50,31 @@ struct CFollowTrackT
 
	bool                m_is_station;    ///< last turn passed station
 
	int                 m_tiles_skipped; ///< number of skipped tunnel or station tiles
 
	ErrorCode           m_err;
 
	CPerformanceTimer  *m_pPerf;
 
	RailTypes           m_railtypes;
 

	
 
	FORCEINLINE CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
 
	inline CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
 
	{
 
		Init(v, railtype_override, pPerf);
 
	}
 

	
 
	FORCEINLINE CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
 
	inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
 
	{
 
		m_veh = NULL;
 
		Init(o, railtype_override, pPerf);
 
	}
 

	
 
	FORCEINLINE void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	inline void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	{
 
		assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
 
		m_veh = v;
 
		Init(v != NULL ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf);
 
	}
 

	
 
	FORCEINLINE void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
 
	{
 
		assert((!IsRoadTT() || m_veh != NULL) && (!IsRailTT() || railtype_override != INVALID_RAILTYPES));
 
		m_veh_owner = o;
 
		m_pPerf = pPerf;
 
		/* don't worry, all is inlined so compiler should remove unnecessary initializations */
 
		m_new_tile = INVALID_TILE;
 
@@ -83,22 +83,22 @@ struct CFollowTrackT
 
		m_is_station = m_is_bridge = m_is_tunnel = false;
 
		m_tiles_skipped = 0;
 
		m_err = EC_NONE;
 
		m_railtypes = railtype_override;
 
	}
 

	
 
	FORCEINLINE static TransportType TT() {return Ttr_type_;}
 
	FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
 
	FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
 
	FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
 
	FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
 
	FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
 
	FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
 
	inline static TransportType TT() {return Ttr_type_;}
 
	inline static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
 
	inline static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
 
	inline bool IsTram() {return IsRoadTT() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
 
	inline static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
 
	inline static bool Allow90degTurns() {return T90deg_turns_allowed_;}
 
	inline static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
 

	
 
	/** Tests if a tile is a road tile with a single tramtrack (tram can reverse) */
 
	FORCEINLINE DiagDirection GetSingleTramBit(TileIndex tile)
 
	inline DiagDirection GetSingleTramBit(TileIndex tile)
 
	{
 
		assert(IsTram()); // this function shouldn't be called in other cases
 

	
 
		if (IsNormalRoadTile(tile)) {
 
			RoadBits rb = GetRoadBits(tile, ROADTYPE_TRAM);
 
			switch (rb) {
 
@@ -186,13 +186,13 @@ struct CFollowTrackT
 
		}
 
		return true;
 
	}
 

	
 
protected:
 
	/** Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped */
 
	FORCEINLINE void FollowTileExit()
 
	inline void FollowTileExit()
 
	{
 
		m_is_station = m_is_bridge = m_is_tunnel = false;
 
		m_tiles_skipped = 0;
 

	
 
		/* extra handling for tunnels and bridges in our direction */
 
		if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
 
@@ -224,13 +224,13 @@ protected:
 
		} else {
 
			m_is_station = false;
 
		}
 
	}
 

	
 
	/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
 
	FORCEINLINE bool QueryNewTileTrackStatus()
 
	inline bool QueryNewTileTrackStatus()
 
	{
 
		CPerfStart perf(*m_pPerf);
 
		if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
 
			m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
 
		} else {
 
			m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() && m_veh != NULL ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0));
 
@@ -254,13 +254,13 @@ protected:
 
			}
 
		}
 
		return (m_new_td_bits != TRACKDIR_BIT_NONE);
 
	}
 

	
 
	/** return true if we can leave m_old_tile in m_exitdir */
 
	FORCEINLINE bool CanExitOldTile()
 
	inline bool CanExitOldTile()
 
	{
 
		/* road stop can be left at one direction only unless it's a drive-through stop */
 
		if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
 
			DiagDirection exitdir = GetRoadStopDir(m_old_tile);
 
			if (exitdir != m_exitdir) {
 
				m_err = EC_NO_WAY;
 
@@ -286,13 +286,13 @@ protected:
 
			}
 
		}
 
		return true;
 
	}
 

	
 
	/** return true if we can enter m_new_tile from m_exitdir */
 
	FORCEINLINE bool CanEnterNewTile()
 
	inline bool CanEnterNewTile()
 
	{
 
		if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
 
			/* road stop can be entered from one direction only unless it's a drive-through stop */
 
			DiagDirection exitdir = GetRoadStopDir(m_new_tile);
 
			if (ReverseDiagDir(exitdir) != m_exitdir) {
 
				m_err = EC_NO_WAY;
 
@@ -383,13 +383,13 @@ protected:
 
		}
 

	
 
		return true;
 
	}
 

	
 
	/** return true if we must reverse (in depots and single tram bits) */
 
	FORCEINLINE bool ForcedReverse()
 
	inline bool ForcedReverse()
 
	{
 
		/* rail and road depots cause reversing */
 
		if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
 
			DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
 
			if (exitdir != m_exitdir) {
 
				/* reverse */
 
@@ -414,13 +414,13 @@ protected:
 
		}
 

	
 
		return false;
 
	}
 

	
 
	/** return true if we successfully reversed at end of road/track */
 
	FORCEINLINE bool TryReverse()
 
	inline bool TryReverse()
 
	{
 
		if (IsRoadTT() && !IsTram()) {
 
			/* if we reached the end of road, we can reverse the RV and continue moving */
 
			m_exitdir = ReverseDiagDir(m_exitdir);
 
			/* new tile will be the same as old one */
 
			m_new_tile = m_old_tile;
src/pathfinder/npf/queue.h
Show inline comments
 
@@ -40,13 +40,13 @@ struct BinaryHeap {
 

	
 
	/**
 
	 * Get an element from the #elements.
 
	 * @param i Element to access (starts at offset \c 1).
 
	 * @return Value of the element.
 
	 */
 
	FORCEINLINE BinaryHeapNode &GetElement(uint i)
 
	inline BinaryHeapNode &GetElement(uint i)
 
	{
 
		assert(i > 0);
 
		return this->elements[(i - 1) >> BINARY_HEAP_BLOCKSIZE_BITS][(i - 1) & BINARY_HEAP_BLOCKSIZE_MASK];
 
	}
 

	
 
	uint max_size;
 
@@ -93,13 +93,13 @@ struct Hash {
 
	void Clear(bool free_values);
 
	void Delete(bool free_values);
 

	
 
	/**
 
	 * Gets the current size of the hash.
 
	 */
 
	FORCEINLINE uint GetSize() const
 
	inline uint GetSize() const
 
	{
 
		return this->size;
 
	}
 

	
 
protected:
 
#ifdef HASH_STATS
src/pathfinder/pf_performance_timer.hpp
Show inline comments
 
@@ -18,65 +18,65 @@ struct CPerformanceTimer
 
{
 
	int64    m_start;
 
	int64    m_acc;
 

	
 
	CPerformanceTimer() : m_start(0), m_acc(0) {}
 

	
 
	FORCEINLINE void Start()
 
	inline void Start()
 
	{
 
		m_start = QueryTime();
 
	}
 

	
 
	FORCEINLINE void Stop()
 
	inline void Stop()
 
	{
 
		m_acc += QueryTime() - m_start;
 
	}
 

	
 
	FORCEINLINE int Get(int64 coef)
 
	inline int Get(int64 coef)
 
	{
 
		return (int)(m_acc * coef / QueryFrequency());
 
	}
 

	
 
	FORCEINLINE int64 QueryTime()
 
	inline int64 QueryTime()
 
	{
 
		return ottd_rdtsc();
 
	}
 

	
 
	FORCEINLINE int64 QueryFrequency()
 
	inline int64 QueryFrequency()
 
	{
 
		return ((int64)2200 * 1000000);
 
	}
 
};
 

	
 
struct CPerfStartReal
 
{
 
	CPerformanceTimer *m_pperf;
 

	
 
	FORCEINLINE CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
 
	inline CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
 
	{
 
		if (m_pperf != NULL) m_pperf->Start();
 
	}
 

	
 
	FORCEINLINE ~CPerfStartReal()
 
	inline ~CPerfStartReal()
 
	{
 
		Stop();
 
	}
 

	
 
	FORCEINLINE void Stop()
 
	inline void Stop()
 
	{
 
		if (m_pperf != NULL) {
 
			m_pperf->Stop();
 
			m_pperf = NULL;
 
		}
 
	}
 
};
 

	
 
struct CPerfStartFake
 
{
 
	FORCEINLINE CPerfStartFake(CPerformanceTimer& perf) {}
 
	FORCEINLINE ~CPerfStartFake() {}
 
	FORCEINLINE void Stop() {}
 
	inline CPerfStartFake(CPerformanceTimer& perf) {}
 
	inline ~CPerfStartFake() {}
 
	inline void Stop() {}
 
};
 

	
 
typedef CPerfStartFake CPerfStart;
 

	
 
#endif /* PF_PERFORMANCE_TIMER_HPP */
src/pathfinder/yapf/nodelist.hpp
Show inline comments
 
@@ -59,105 +59,105 @@ public:
 
	/** destructor */
 
	~CNodeList_HashTableT()
 
	{
 
	}
 

	
 
	/** return number of open nodes */
 
	FORCEINLINE int OpenCount()
 
	inline int OpenCount()
 
	{
 
		return m_open.Count();
 
	}
 

	
 
	/** return number of closed nodes */
 
	FORCEINLINE int ClosedCount()
 
	inline int ClosedCount()
 
	{
 
		return m_closed.Count();
 
	}
 

	
 
	/** allocate new data item from m_arr */
 
	FORCEINLINE Titem_ *CreateNewNode()
 
	inline Titem_ *CreateNewNode()
 
	{
 
		if (m_new_node == NULL) m_new_node = m_arr.AppendC();
 
		return m_new_node;
 
	}
 

	
 
	/** Notify the nodelist that we don't want to discard the given node. */
 
	FORCEINLINE void FoundBestNode(Titem_& item)
 
	inline void FoundBestNode(Titem_& item)
 
	{
 
		/* for now it is enough to invalidate m_new_node if it is our given node */
 
		if (&item == m_new_node) {
 
			m_new_node = NULL;
 
		}
 
		/* TODO: do we need to store best nodes found in some extra list/array? Probably not now. */
 
	}
 

	
 
	/** insert given item as open node (into m_open and m_open_queue) */
 
	FORCEINLINE void InsertOpenNode(Titem_& item)
 
	inline void InsertOpenNode(Titem_& item)
 
	{
 
		assert(m_closed.Find(item.GetKey()) == NULL);
 
		m_open.Push(item);
 
		m_open_queue.Include(&item);
 
		if (&item == m_new_node) {
 
			m_new_node = NULL;
 
		}
 
	}
 

	
 
	/** return the best open node */
 
	FORCEINLINE Titem_ *GetBestOpenNode()
 
	inline Titem_ *GetBestOpenNode()
 
	{
 
		if (!m_open_queue.IsEmpty()) {
 
			return m_open_queue.Begin();
 
		}
 
		return NULL;
 
	}
 

	
 
	/** remove and return the best open node */
 
	FORCEINLINE Titem_ *PopBestOpenNode()
 
	inline Titem_ *PopBestOpenNode()
 
	{
 
		if (!m_open_queue.IsEmpty()) {
 
			Titem_ *item = m_open_queue.Shift();
 
			m_open.Pop(*item);
 
			return item;
 
		}
 
		return NULL;
 
	}
 

	
 
	/** return the open node specified by a key or NULL if not found */
 
	FORCEINLINE Titem_ *FindOpenNode(const Key& key)
 
	inline Titem_ *FindOpenNode(const Key& key)
 
	{
 
		Titem_ *item = m_open.Find(key);
 
		return item;
 
	}
 

	
 
	/** remove and return the open node specified by a key */
 
	FORCEINLINE Titem_& PopOpenNode(const Key& key)
 
	inline Titem_& PopOpenNode(const Key& key)
 
	{
 
		Titem_& item = m_open.Pop(key);
 
		uint idxPop = m_open_queue.FindIndex(item);
 
		m_open_queue.Remove(idxPop);
 
		return item;
 
	}
 

	
 
	/** close node */
 
	FORCEINLINE void InsertClosedNode(Titem_& item)
 
	inline void InsertClosedNode(Titem_& item)
 
	{
 
		assert(m_open.Find(item.GetKey()) == NULL);
 
		m_closed.Push(item);
 
	}
 

	
 
	/** return the closed node specified by a key or NULL if not found */
 
	FORCEINLINE Titem_ *FindClosedNode(const Key& key)
 
	inline Titem_ *FindClosedNode(const Key& key)
 
	{
 
		Titem_ *item = m_closed.Find(key);
 
		return item;
 
	}
 

	
 
	/** The number of items. */
 
	FORCEINLINE int TotalCount() {return m_arr.Length();}
 
	inline int TotalCount() {return m_arr.Length();}
 
	/** Get a particular item. */
 
	FORCEINLINE Titem_& ItemAt(int idx) {return m_arr[idx];}
 
	inline Titem_& ItemAt(int idx) {return m_arr[idx];}
 

	
 
	/** Helper for creating output of this array. */
 
	template <class D> void Dump(D &dmp) const
 
	{
 
		dmp.WriteStructT("m_arr", &m_arr);
 
	}
src/pathfinder/yapf/yapf.hpp
Show inline comments
 
@@ -15,13 +15,13 @@
 
#include "../../landscape.h"
 
#include "../pathfinder_func.h"
 
#include "../pf_performance_timer.hpp"
 
#include "yapf.h"
 

	
 
//#undef FORCEINLINE
 
//#define FORCEINLINE inline
 
//#define inline inline
 

	
 
#include "../../misc/blob.hpp"
 
#include "../../misc/str.hpp"
 
#include "../../misc/fixedsizearray.hpp"
 
#include "../../misc/array.hpp"
 
#include "../../misc/hashtable.hpp"
src/pathfinder/yapf/yapf_base.hpp
Show inline comments
 
@@ -34,17 +34,17 @@ extern int _total_pf_time_us;
 
 *  you need to declare only your node type. Look at test_yapf.h for an example.
 
 *
 
 *
 
 *  Requrements to your pathfinder class derived from CYapfBaseT:
 
 *  -------------------------------------------------------------
 
 *  Your pathfinder derived class needs to implement following methods:
 
 *    FORCEINLINE void PfSetStartupNodes()
 
 *    FORCEINLINE void PfFollowNode(Node& org)
 
 *    FORCEINLINE bool PfCalcCost(Node& n)
 
 *    FORCEINLINE bool PfCalcEstimate(Node& n)
 
 *    FORCEINLINE bool PfDetectDestination(Node& n)
 
 *    inline void PfSetStartupNodes()
 
 *    inline void PfFollowNode(Node& org)
 
 *    inline bool PfCalcCost(Node& n)
 
 *    inline bool PfCalcEstimate(Node& n)
 
 *    inline bool PfDetectDestination(Node& n)
 
 *
 
 *  For more details about those methods, look at the end of CYapfBaseT
 
 *  declaration. There are some examples. For another example look at
 
 *  test_yapf.h (part or unittest project).
 
 */
 
template <class Types>
 
@@ -77,13 +77,13 @@ public:
 

	
 
public:
 
	int                  m_num_steps;          ///< this is there for debugging purposes (hope it doesn't hurt)
 

	
 
public:
 
	/** default constructor */
 
	FORCEINLINE CYapfBaseT()
 
	inline CYapfBaseT()
 
		: m_pBestDestNode(NULL)
 
		, m_pBestIntermediateNode(NULL)
 
		, m_settings(&_settings_game.pf.yapf)
 
		, m_max_search_nodes(PfGetSettings().max_search_nodes)
 
		, m_veh(NULL)
 
		, m_stats_cost_calcs(0)
 
@@ -94,20 +94,20 @@ public:
 

	
 
	/** default destructor */
 
	~CYapfBaseT() {}
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** return current settings (can be custom - company based - but later) */
 
	FORCEINLINE const YAPFSettings& PfGetSettings() const
 
	inline const YAPFSettings& PfGetSettings() const
 
	{
 
		return *m_settings;
 
	}
 

	
 
	/**
 
	 * Main pathfinder routine:
 
@@ -179,29 +179,29 @@ public:
 
	}
 

	
 
	/**
 
	 * If path was found return the best node that has reached the destination. Otherwise
 
	 *  return the best visited node (which was nearest to the destination).
 
	 */
 
	FORCEINLINE Node *GetBestNode()
 
	inline Node *GetBestNode()
 
	{
 
		return (m_pBestDestNode != NULL) ? m_pBestDestNode : m_pBestIntermediateNode;
 
	}
 

	
 
	/**
 
	 * Calls NodeList::CreateNewNode() - allocates new node that can be filled and used
 
	 *  as argument for AddStartupNode() or AddNewNode()
 
	 */
 
	FORCEINLINE Node& CreateNewNode()
 
	inline Node& CreateNewNode()
 
	{
 
		Node& node = *m_nodes.CreateNewNode();
 
		return node;
 
	}
 

	
 
	/** Add new node (created by CreateNewNode and filled with data) into open list */
 
	FORCEINLINE void AddStartupNode(Node& n)
 
	inline void AddStartupNode(Node& n)
 
	{
 
		Yapf().PfNodeCacheFetch(n);
 
		/* insert the new node only if it is not there */
 
		if (m_nodes.FindOpenNode(n.m_key) == NULL) {
 
			m_nodes.InsertOpenNode(n);
 
		} else {
 
@@ -209,13 +209,13 @@ public:
 
			 *   probably the train is in the position that both its ends point to the same tile/exit-dir
 
			 *   very unlikely, but it happened */
 
		}
 
	}
 

	
 
	/** add multiple nodes - direct children of the given node */
 
	FORCEINLINE void AddMultipleNodes(Node *parent, const TrackFollower &tf)
 
	inline void AddMultipleNodes(Node *parent, const TrackFollower &tf)
 
	{
 
		bool is_choice = (KillFirstBit(tf.m_new_td_bits) != TRACKDIR_BIT_NONE);
 
		for (TrackdirBits rtds = tf.m_new_td_bits; rtds != TRACKDIR_BIT_NONE; rtds = KillFirstBit(rtds)) {
 
			Trackdir td = (Trackdir)FindFirstBit2x64(rtds);
 
			Node& n = Yapf().CreateNewNode();
 
			n.Set(parent, tf.m_new_tile, td, is_choice);
 
@@ -312,57 +312,57 @@ public:
 
	}
 

	
 
	/* methods that should be implemented at derived class Types::Tpf (derived from CYapfBaseT) */
 

	
 
#if 0
 
	/** Example: PfSetStartupNodes() - set source (origin) nodes */
 
	FORCEINLINE void PfSetStartupNodes()
 
	inline void PfSetStartupNodes()
 
	{
 
		/* example: */
 
		Node& n1 = *base::m_nodes.CreateNewNode();
 
		.
 
		. // setup node members here
 
		.
 
		base::m_nodes.InsertOpenNode(n1);
 
	}
 

	
 
	/** Example: PfFollowNode() - set following (child) nodes of the given node */
 
	FORCEINLINE void PfFollowNode(Node& org)
 
	inline void PfFollowNode(Node& org)
 
	{
 
		for (each follower of node org) {
 
			Node& n = *base::m_nodes.CreateNewNode();
 
			.
 
			. // setup node members here
 
			.
 
			n.m_parent   = &org; // set node's parent to allow back tracking
 
			AddNewNode(n);
 
		}
 
	}
 

	
 
	/** Example: PfCalcCost() - set path cost from origin to the given node */
 
	FORCEINLINE bool PfCalcCost(Node& n)
 
	inline bool PfCalcCost(Node& n)
 
	{
 
		/* evaluate last step cost */
 
		int cost = ...;
 
		/* set the node cost as sum of parent's cost and last step cost */
 
		n.m_cost = n.m_parent->m_cost + cost;
 
		return true; // true if node is valid follower (i.e. no obstacle was found)
 
	}
 

	
 
	/** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		/* evaluate the distance to our destination */
 
		int distance = ...;
 
		/* set estimate as sum of cost from origin + distance to the target */
 
		n.m_estimate = n.m_cost + distance;
 
		return true; // true if node is valid (i.e. not too far away :)
 
	}
 

	
 
	/** Example: PfDetectDestination() - return true if the given node is our destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
 
		return bDest;
 
	}
 
#endif
 
};
src/pathfinder/yapf/yapf_common.hpp
Show inline comments
 
@@ -23,13 +23,13 @@ public:
 

	
 
protected:
 
	TileIndex    m_orgTile;                       ///< origin tile
 
	TrackdirBits m_orgTrackdirs;                  ///< origin trackdir mask
 

	
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Set origin tile / trackdir mask */
 
@@ -67,13 +67,13 @@ protected:
 
	TileIndex   m_revTile;                        ///< second (reversed) origin tile
 
	Trackdir    m_revTd;                          ///< second (reversed) origin trackdir
 
	int         m_reverse_penalty;                ///< penalty to be added for using the reversed origin
 
	bool        m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently
 

	
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** set origin (tiles, trackdirs, etc.) */
 
@@ -101,13 +101,13 @@ public:
 
			n2.m_cost = m_reverse_penalty;
 
			Yapf().AddStartupNode(n2);
 
		}
 
	}
 

	
 
	/** return true if first two-way signal should be treated as dead end */
 
	FORCEINLINE bool TreatFirstRedTwoWaySignalAsEOL()
 
	inline bool TreatFirstRedTwoWaySignalAsEOL()
 
	{
 
		return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol;
 
	}
 
};
 

	
 
/** YAPF destination provider base class - used when destination is single tile / multiple trackdirs */
 
@@ -137,13 +137,13 @@ protected:
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
 
		return bDest;
 
	}
 

	
 
	/**
src/pathfinder/yapf/yapf_costbase.hpp
Show inline comments
 
@@ -17,13 +17,13 @@ struct CYapfCostBase {
 
	/**
 
	 * Does the given track direction on the given tile yeild an uphill penalty?
 
	 * @param tile The tile to check.
 
	 * @param td   The track direction to check.
 
	 * @return True if there's a slope, otherwise false.
 
	 */
 
	FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td)
 
	inline static bool stSlopeCost(TileIndex tile, Trackdir td)
 
	{
 
		if (IsDiagonalTrackdir(td)) {
 
			if (IsBridgeTile(tile)) {
 
				/* it is bridge ramp, check if we are entering the bridge */
 
				if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
 
				/* we are entering the bridge */
src/pathfinder/yapf/yapf_costcache.hpp
Show inline comments
 
@@ -27,22 +27,22 @@ public:
 
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
 

	
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used
 
	 */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	inline bool PfNodeCacheFetch(Node& n)
 
	{
 
		return false;
 
	}
 

	
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that.
 
	 */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	inline void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
 

	
 
/**
 
@@ -62,34 +62,34 @@ public:
 
	typedef SmallArray<CachedData> LocalCache;
 

	
 
protected:
 
	LocalCache      m_local_cache;
 

	
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used
 
	 */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	inline bool PfNodeCacheFetch(Node& n)
 
	{
 
		CacheKey key(n.GetKey());
 
		Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key));
 
		return false;
 
	}
 

	
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that.
 
	 */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	inline void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
 

	
 
/**
 
@@ -130,22 +130,22 @@ struct CSegmentCostCacheT
 
	typedef SmallArray<Tsegment> Heap;
 
	typedef typename Tsegment::Key Key;    ///< key to hash table
 

	
 
	HashTable    m_map;
 
	Heap         m_heap;
 

	
 
	FORCEINLINE CSegmentCostCacheT() {}
 
	inline CSegmentCostCacheT() {}
 

	
 
	/** flush (clear) the cache */
 
	FORCEINLINE void Flush()
 
	inline void Flush()
 
	{
 
		m_map.Clear();
 
		m_heap.Clear();
 
	}
 

	
 
	FORCEINLINE Tsegment& Get(Key& key, bool *found)
 
	inline Tsegment& Get(Key& key, bool *found)
 
	{
 
		Tsegment *item = m_map.Find(key);
 
		if (item == NULL) {
 
			*found = false;
 
			item = new (m_heap.Append()) Tsegment(key);
 
			m_map.Push(*item);
 
@@ -174,21 +174,21 @@ public:
 
	typedef typename CachedData::Key CacheKey;
 
	typedef CSegmentCostCacheT<CachedData> Cache;
 

	
 
protected:
 
	Cache&      m_global_cache;
 

	
 
	FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
 
	inline CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
 

	
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
	FORCEINLINE static Cache& stGetGlobalCache()
 
	inline static Cache& stGetGlobalCache()
 
	{
 
		static int last_rail_change_counter = 0;
 
		static Date last_date = 0;
 
		static Cache C;
 

	
 
		/* some statistics */
 
@@ -208,13 +208,13 @@ protected:
 

	
 
public:
 
	/**
 
	 * Called by YAPF to attach cached or local segment cost data to the given node.
 
	 *  @return true if globally cached data were used or false if local data was used
 
	 */
 
	FORCEINLINE bool PfNodeCacheFetch(Node& n)
 
	inline bool PfNodeCacheFetch(Node& n)
 
	{
 
		if (!Yapf().CanUseGlobalCache(n)) {
 
			return Tlocal::PfNodeCacheFetch(n);
 
		}
 
		CacheKey key(n.GetKey());
 
		bool found;
 
@@ -224,12 +224,12 @@ public:
 
	}
 

	
 
	/**
 
	 * Called by YAPF to flush the cached segment cost data back into cache storage.
 
	 *  Current cache implementation doesn't use that.
 
	 */
 
	FORCEINLINE void PfNodeCacheFlush(Node& n)
 
	inline void PfNodeCacheFlush(Node& n)
 
	{
 
	}
 
};
 

	
 
#endif /* YAPF_COSTCACHE_HPP */
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -93,20 +93,20 @@ protected:
 
	Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	FORCEINLINE int SlopeCost(TileIndex tile, Trackdir td)
 
	inline int SlopeCost(TileIndex tile, Trackdir td)
 
	{
 
		CPerfStart perf_cost(Yapf().m_perf_slope_cost);
 
		if (!stSlopeCost(tile, td)) return 0;
 
		return Yapf().PfGetSettings().rail_slope_penalty;
 
	}
 

	
 
	FORCEINLINE int CurveCost(Trackdir td1, Trackdir td2)
 
	inline int CurveCost(Trackdir td1, Trackdir td2)
 
	{
 
		assert(IsValidTrackdir(td1));
 
		assert(IsValidTrackdir(td2));
 
		int cost = 0;
 
		if (TrackFollower::Allow90degTurns()
 
				&& ((TrackdirToTrackdirBits(td2) & (TrackdirBits)TrackdirCrossesTrackdirs(td1)) != 0)) {
 
@@ -116,24 +116,24 @@ public:
 
			/* 45-deg curve penalty */
 
			cost += Yapf().PfGetSettings().rail_curve45_penalty;
 
		}
 
		return cost;
 
	}
 

	
 
	FORCEINLINE int SwitchCost(TileIndex tile1, TileIndex tile2, DiagDirection exitdir)
 
	inline int SwitchCost(TileIndex tile1, TileIndex tile2, DiagDirection exitdir)
 
	{
 
		if (IsPlainRailTile(tile1) && IsPlainRailTile(tile2)) {
 
			bool t1 = KillFirstBit(GetTrackBits(tile1) & DiagdirReachesTracks(ReverseDiagDir(exitdir))) != TRACK_BIT_NONE;
 
			bool t2 = KillFirstBit(GetTrackBits(tile2) & DiagdirReachesTracks(exitdir)) != TRACK_BIT_NONE;
 
			if (t1 && t2) return Yapf().PfGetSettings().rail_doubleslip_penalty;
 
		}
 
		return 0;
 
	}
 

	
 
	/** Return one tile cost (base cost + level crossing penalty). */
 
	FORCEINLINE int OneTileCost(TileIndex& tile, Trackdir trackdir)
 
	inline int OneTileCost(TileIndex& tile, Trackdir trackdir)
 
	{
 
		int cost = 0;
 
		/* set base cost */
 
		if (IsDiagonalTrackdir(trackdir)) {
 
			cost += YAPF_TILE_LENGTH;
 
			switch (GetTileType(tile)) {
 
@@ -152,23 +152,23 @@ public:
 
			cost = YAPF_TILE_CORNER_LENGTH;
 
		}
 
		return cost;
 
	}
 

	
 
	/** Check for a reserved station platform. */
 
	FORCEINLINE bool IsAnyStationTileReserved(TileIndex tile, Trackdir trackdir, int skipped)
 
	inline bool IsAnyStationTileReserved(TileIndex tile, Trackdir trackdir, int skipped)
 
	{
 
		TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir)));
 
		for (; skipped >= 0; skipped--, tile += diff) {
 
			if (HasStationReservation(tile)) return true;
 
		}
 
		return false;
 
	}
 

	
 
	/** The cost for reserved tiles, including skipped ones. */
 
	FORCEINLINE int ReservationCost(Node& n, TileIndex tile, Trackdir trackdir, int skipped)
 
	inline int ReservationCost(Node& n, TileIndex tile, Trackdir trackdir, int skipped)
 
	{
 
		if (n.m_num_signals_passed >= m_sig_look_ahead_costs.Size() / 2) return 0;
 
		if (!IsPbsSignal(n.m_last_signal_type)) return 0;
 

	
 
		if (IsRailStationTile(tile) && IsAnyStationTileReserved(tile, trackdir, skipped)) {
 
			return Yapf().PfGetSettings().rail_pbs_station_penalty * (skipped + 1);
 
@@ -248,13 +248,13 @@ public:
 
				}
 
			}
 
		}
 
		return cost;
 
	}
 

	
 
	FORCEINLINE int PlatformLengthPenalty(int platform_length)
 
	inline int PlatformLengthPenalty(int platform_length)
 
	{
 
		int cost = 0;
 
		const Train *v = Yapf().GetVehicle();
 
		assert(v != NULL);
 
		assert(v->type == VEH_TRAIN);
 
		assert(v->gcache.cached_total_length != 0);
 
@@ -267,23 +267,23 @@ public:
 
			cost += Yapf().PfGetSettings().rail_shorter_platform_penalty + Yapf().PfGetSettings().rail_shorter_platform_per_tile_penalty * missing_platform_length;
 
		}
 
		return cost;
 
	}
 

	
 
public:
 
	FORCEINLINE void SetMaxCost(int max_cost)
 
	inline void SetMaxCost(int max_cost)
 
	{
 
		m_max_cost = max_cost;
 
	}
 

	
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member
 
	 */
 
	FORCEINLINE bool PfCalcCost(Node &n, const TrackFollower *tf)
 
	inline bool PfCalcCost(Node &n, const TrackFollower *tf)
 
	{
 
		assert(!n.flags_u.flags_s.m_targed_seen);
 
		assert(tf->m_new_tile == n.m_key.m_tile);
 
		assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE);
 

	
 
		CPerfStart perf_cost(Yapf().m_perf_cost);
 
@@ -610,20 +610,20 @@ no_entry_cost: // jump here at the begin
 
		/* total node cost */
 
		n.m_cost = parent_cost + segment_entry_cost + segment_cost + extra_cost;
 

	
 
		return true;
 
	}
 

	
 
	FORCEINLINE bool CanUseGlobalCache(Node& n) const
 
	inline bool CanUseGlobalCache(Node& n) const
 
	{
 
		return !m_disable_cache
 
			&& (n.m_parent != NULL)
 
			&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size());
 
	}
 

	
 
	FORCEINLINE void ConnectNodeToCachedData(Node& n, CachedData& ci)
 
	inline void ConnectNodeToCachedData(Node& n, CachedData& ci)
 
	{
 
		n.m_segment = &ci;
 
		if (n.m_segment->m_cost < 0) {
 
			n.m_segment->m_last_tile = n.m_key.m_tile;
 
			n.m_segment->m_last_td = n.m_key.m_td;
 
		}
src/pathfinder/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -48,29 +48,29 @@ public:
 
	Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	inline bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		bool bDest = IsRailDepotTile(tile);
 
		return bDest;
 
	}
 

	
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate
 
	 */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
};
 

	
 
@@ -88,29 +88,29 @@ public:
 
	Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	inline bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		return IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
 
				IsWaitingPositionFree(Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
 
	}
 

	
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate.
 
	 */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
};
 

	
 
@@ -161,19 +161,19 @@ public:
 
				break;
 
		}
 
		CYapfDestinationRailBase::SetDestination(v);
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	inline bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		bool bDest;
 
		if (m_dest_station_id != INVALID_STATION) {
 
			bDest = HasStationTileRail(tile)
 
				&& (GetStationIndex(tile) == m_dest_station_id)
 
				&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
 
@@ -185,13 +185,13 @@ public:
 
	}
 

	
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate
 
	 */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
 
		static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
 
		if (PfDetectDestination(n)) {
 
			n.m_estimate = n.m_cost;
 
			return true;
src/pathfinder/yapf/yapf_node.hpp
Show inline comments
 
@@ -15,34 +15,34 @@
 
/** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */
 
struct CYapfNodeKeyExitDir {
 
	TileIndex      m_tile;
 
	Trackdir       m_td;
 
	DiagDirection  m_exitdir;
 

	
 
	FORCEINLINE void Set(TileIndex tile, Trackdir td)
 
	inline void Set(TileIndex tile, Trackdir td)
 
	{
 
		m_tile = tile;
 
		m_td = td;
 
		m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
 
	}
 

	
 
	FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);}
 
	FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
 
	inline int CalcHash() const {return m_exitdir | (m_tile << 2);}
 
	inline bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
 

	
 
	void Dump(DumpTarget &dmp) const
 
	{
 
		dmp.WriteTile("m_tile", m_tile);
 
		dmp.WriteEnumT("m_td", m_td);
 
		dmp.WriteEnumT("m_exitdir", m_exitdir);
 
	}
 
};
 

	
 
struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
 
{
 
	FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);}
 
	FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
 
	inline int CalcHash() const {return m_td | (m_tile << 4);}
 
	inline bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
 
};
 

	
 
/** Yapf Node base */
 
template <class Tkey_, class Tnode>
 
struct CYapfNodeT {
 
	typedef Tkey_ Key;
 
@@ -51,29 +51,29 @@ struct CYapfNodeT {
 
	Tkey_       m_key;
 
	Node       *m_hash_next;
 
	Node       *m_parent;
 
	int         m_cost;
 
	int         m_estimate;
 

	
 
	FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
 
	inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
 
	{
 
		m_key.Set(tile, td);
 
		m_hash_next = NULL;
 
		m_parent = parent;
 
		m_cost = 0;
 
		m_estimate = 0;
 
	}
 

	
 
	FORCEINLINE Node *GetHashNext() {return m_hash_next;}
 
	FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;}
 
	FORCEINLINE TileIndex GetTile() const {return m_key.m_tile;}
 
	FORCEINLINE Trackdir GetTrackdir() const {return m_key.m_td;}
 
	FORCEINLINE const Tkey_& GetKey() const {return m_key;}
 
	FORCEINLINE int GetCost() const {return m_cost;}
 
	FORCEINLINE int GetCostEstimate() const {return m_estimate;}
 
	FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
 
	inline Node *GetHashNext() {return m_hash_next;}
 
	inline void SetHashNext(Node *pNext) {m_hash_next = pNext;}
 
	inline TileIndex GetTile() const {return m_key.m_tile;}
 
	inline Trackdir GetTrackdir() const {return m_key.m_td;}
 
	inline const Tkey_& GetKey() const {return m_key;}
 
	inline int GetCost() const {return m_cost;}
 
	inline int GetCostEstimate() const {return m_estimate;}
 
	inline bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
 

	
 
	void Dump(DumpTarget &dmp) const
 
	{
 
		dmp.WriteStructT("m_key", &m_key);
 
		dmp.WriteStructT("m_parent", m_parent);
 
		dmp.WriteLine("m_cost = %d", m_cost);
src/pathfinder/yapf/yapf_node_rail.hpp
Show inline comments
 
@@ -14,45 +14,45 @@
 

	
 
/** key for cached segment cost for rail YAPF */
 
struct CYapfRailSegmentKey
 
{
 
	uint32    m_value;
 

	
 
	FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
 
	inline CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
 

	
 
	FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key)
 
	inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key)
 
	{
 
		Set(node_key);
 
	}
 

	
 
	FORCEINLINE void Set(const CYapfRailSegmentKey& src)
 
	inline void Set(const CYapfRailSegmentKey& src)
 
	{
 
		m_value = src.m_value;
 
	}
 

	
 
	FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key)
 
	inline void Set(const CYapfNodeKeyTrackDir& node_key)
 
	{
 
		m_value = (((int)node_key.m_tile) << 4) | node_key.m_td;
 
	}
 

	
 
	FORCEINLINE int32 CalcHash() const
 
	inline int32 CalcHash() const
 
	{
 
		return m_value;
 
	}
 

	
 
	FORCEINLINE TileIndex GetTile() const
 
	inline TileIndex GetTile() const
 
	{
 
		return (TileIndex)(m_value >> 4);
 
	}
 

	
 
	FORCEINLINE Trackdir GetTrackdir() const
 
	inline Trackdir GetTrackdir() const
 
	{
 
		return (Trackdir)(m_value & 0x0F);
 
	}
 

	
 
	FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const
 
	inline bool operator == (const CYapfRailSegmentKey& other) const
 
	{
 
		return m_value == other.m_value;
 
	}
 

	
 
	void Dump(DumpTarget &dmp) const
 
	{
 
@@ -141,39 +141,39 @@ struct CYapfRailSegment
 
	int                    m_cost;
 
	TileIndex              m_last_signal_tile;
 
	Trackdir               m_last_signal_td;
 
	EndSegmentReasonBits   m_end_segment_reason;
 
	CYapfRailSegment      *m_hash_next;
 

	
 
	FORCEINLINE CYapfRailSegment(const CYapfRailSegmentKey& key)
 
	inline CYapfRailSegment(const CYapfRailSegmentKey& key)
 
		: m_key(key)
 
		, m_last_tile(INVALID_TILE)
 
		, m_last_td(INVALID_TRACKDIR)
 
		, m_cost(-1)
 
		, m_last_signal_tile(INVALID_TILE)
 
		, m_last_signal_td(INVALID_TRACKDIR)
 
		, m_end_segment_reason(ESRB_NONE)
 
		, m_hash_next(NULL)
 
	{}
 

	
 
	FORCEINLINE const Key& GetKey() const
 
	inline const Key& GetKey() const
 
	{
 
		return m_key;
 
	}
 

	
 
	FORCEINLINE TileIndex GetTile() const
 
	inline TileIndex GetTile() const
 
	{
 
		return m_key.GetTile();
 
	}
 

	
 
	FORCEINLINE CYapfRailSegment *GetHashNext()
 
	inline CYapfRailSegment *GetHashNext()
 
	{
 
		return m_hash_next;
 
	}
 

	
 
	FORCEINLINE void SetHashNext(CYapfRailSegment *next)
 
	inline void SetHashNext(CYapfRailSegment *next)
 
	{
 
		m_hash_next = next;
 
	}
 

	
 
	void Dump(DumpTarget &dmp) const
 
	{
 
@@ -205,13 +205,13 @@ struct CYapfRailNodeT
 
			bool          m_last_signal_was_red : 1;
 
		} flags_s;
 
	} flags_u;
 
	SignalType        m_last_red_signal_type;
 
	SignalType        m_last_signal_type;
 

	
 
	FORCEINLINE void Set(CYapfRailNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
 
	inline void Set(CYapfRailNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
 
	{
 
		base::Set(parent, tile, td, is_choice);
 
		m_segment = NULL;
 
		if (parent == NULL) {
 
			m_num_signals_passed      = 0;
 
			flags_u.m_inherited_flags = 0;
 
@@ -233,25 +233,25 @@ struct CYapfRailNodeT
 
			m_last_red_signal_type    = parent->m_last_red_signal_type;
 
			m_last_signal_type        = parent->m_last_signal_type;
 
		}
 
		flags_u.flags_s.m_choice_seen |= is_choice;
 
	}
 

	
 
	FORCEINLINE TileIndex GetLastTile() const
 
	inline TileIndex GetLastTile() const
 
	{
 
		assert(m_segment != NULL);
 
		return m_segment->m_last_tile;
 
	}
 

	
 
	FORCEINLINE Trackdir GetLastTrackdir() const
 
	inline Trackdir GetLastTrackdir() const
 
	{
 
		assert(m_segment != NULL);
 
		return m_segment->m_last_td;
 
	}
 

	
 
	FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td)
 
	inline void SetLastTileTrackdir(TileIndex tile, Trackdir td)
 
	{
 
		assert(m_segment != NULL);
 
		m_segment->m_last_tile = tile;
 
		m_segment->m_last_td = td;
 
	}
 

	
src/pathfinder/yapf/yapf_rail.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ public:
 
	typedef typename Types::Tpf Tpf;                     ///< the pathfinder class (derived from THIS class)
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 

	
 
protected:
 
	/** to access inherited pathfinder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
private:
 
	TileIndex m_res_dest;         ///< The reservation target tile
 
@@ -194,13 +194,13 @@ public:
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 
	typedef typename Node::Key Key;                      ///< key to hash tables
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/**
 
@@ -214,13 +214,13 @@ public:
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
 
			Yapf().AddMultipleNodes(&old_node, F);
 
		}
 
	}
 

	
 
	/** return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	inline char TransportTypeChar() const
 
	{
 
		return 't';
 
	}
 

	
 
	static bool stFindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
 
	{
 
@@ -249,13 +249,13 @@ public:
 
		}
 
#endif
 

	
 
		return result1;
 
	}
 

	
 
	FORCEINLINE bool FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
 
	inline bool FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
 
	{
 
		/* set origin and destination nodes */
 
		Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
 
		Yapf().SetDestination(v);
 
		Yapf().SetMaxCost(max_penalty);
 

	
 
@@ -290,13 +290,13 @@ public:
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 
	typedef typename Node::Key Key;                      ///< key to hash tables
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/**
 
@@ -310,13 +310,13 @@ public:
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
 
			Yapf().AddMultipleNodes(&old_node, F);
 
		}
 
	}
 

	
 
	/** Return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	inline char TransportTypeChar() const
 
	{
 
		return 't';
 
	}
 

	
 
	static bool stFindNearestSafeTile(const Train *v, TileIndex t1, Trackdir td, bool override_railtype)
 
	{
 
@@ -373,13 +373,13 @@ public:
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 
	typedef typename Node::Key Key;                      ///< key to hash tables
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/**
 
@@ -393,13 +393,13 @@ public:
 
		if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
 
			Yapf().AddMultipleNodes(&old_node, F);
 
		}
 
	}
 

	
 
	/** return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	inline char TransportTypeChar() const
 
	{
 
		return 't';
 
	}
 

	
 
	static Trackdir stChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
 
	{
 
@@ -419,13 +419,13 @@ public:
 
		}
 
#endif
 

	
 
		return result1;
 
	}
 

	
 
	FORCEINLINE Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
 
	inline Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target)
 
	{
 
		if (target != NULL) target->tile = INVALID_TILE;
 

	
 
		/* set origin and destination nodes */
 
		PBSTileInfo origin = FollowTrainReservation(v);
 
		Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
 
@@ -477,13 +477,13 @@ public:
 
		}
 
#endif
 

	
 
		return result1;
 
	}
 

	
 
	FORCEINLINE bool CheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
 
	inline bool CheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
 
	{
 
		/* create pathfinder instance
 
		 * set origin and destination nodes */
 
		Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, false);
 
		Yapf().SetDestination(v);
 

	
src/pathfinder/yapf/yapf_road.cpp
Show inline comments
 
@@ -48,13 +48,13 @@ protected:
 
			return Yapf().PfGetSettings().road_slope_penalty;
 
		}
 
		return 0;
 
	}
 

	
 
	/** return one tile cost */
 
	FORCEINLINE int OneTileCost(TileIndex tile, Trackdir trackdir)
 
	inline int OneTileCost(TileIndex tile, Trackdir trackdir)
 
	{
 
		int cost = 0;
 
		/* set base cost */
 
		if (IsDiagonalTrackdir(trackdir)) {
 
			cost += YAPF_TILE_LENGTH;
 
			switch (GetTileType(tile)) {
 
@@ -97,13 +97,13 @@ protected:
 
public:
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member
 
	 */
 
	FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	inline bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	{
 
		int segment_cost = 0;
 
		uint tiles = 0;
 
		/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
 
		TileIndex tile = n.m_key.m_tile;
 
		Trackdir trackdir = n.m_key.m_td;
 
@@ -178,28 +178,28 @@ public:
 
	Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
 
		return bDest;
 
	}
 

	
 
	FORCEINLINE bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
 
	inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
 
	{
 
		return IsRoadDepotTile(tile);
 
	}
 

	
 
	/**
 
	 * Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate
 
	 */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	inline bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
};
 

	
 
@@ -242,18 +242,18 @@ protected:
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/** Called by YAPF to detect if node ends in the desired destination */
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	inline bool PfDetectDestination(Node& n)
 
	{
 
		return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
 
	}
 

	
 
	FORCEINLINE bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
 
	inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
 
	{
 
		if (m_dest_station != INVALID_STATION) {
 
			return IsTileType(tile, MP_STATION) &&
 
				GetStationIndex(tile) == m_dest_station &&
 
				(m_bus ? IsBusStop(tile) : IsTruckStop(tile)) &&
 
				(m_non_artic || IsDriveThroughStopTile(tile));
 
@@ -302,13 +302,13 @@ public:
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 
	typedef typename Node::Key Key;                      ///< key to hash tables
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 

	
 
@@ -323,24 +323,24 @@ public:
 
		if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
 
			Yapf().AddMultipleNodes(&old_node, F);
 
		}
 
	}
 

	
 
	/** return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	inline char TransportTypeChar() const
 
	{
 
		return 'r';
 
	}
 

	
 
	static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
 
	{
 
		Tpf pf;
 
		return pf.ChooseRoadTrack(v, tile, enterdir, path_found);
 
	}
 

	
 
	FORCEINLINE Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
 
	inline Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
 
	{
 
		/* Handle special case - when next tile is destination tile.
 
		 * However, when going to a station the (initial) destination
 
		 * tile might not be a station, but a junction, in which case
 
		 * this method forces the vehicle to jump in circles. */
 
		if (tile == v->dest_tile && !v->current_order.IsType(OT_GOTO_STATION)) {
 
@@ -381,13 +381,13 @@ public:
 
	static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile)
 
	{
 
		Tpf pf;
 
		return pf.DistanceToTile(v, tile);
 
	}
 

	
 
	FORCEINLINE uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
 
	inline uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
 
	{
 
		/* handle special case - when current tile is the destination tile */
 
		if (dst_tile == v->tile) {
 
			/* distance is zero in this case */
 
			return 0;
 
		}
 
@@ -411,13 +411,13 @@ public:
 
		}
 

	
 
		return dist;
 
	}
 

	
 
	/** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
 
	FORCEINLINE bool SetOriginFromVehiclePos(const RoadVehicle *v)
 
	inline bool SetOriginFromVehiclePos(const RoadVehicle *v)
 
	{
 
		/* set origin (tile, trackdir) */
 
		TileIndex src_tile = v->tile;
 
		Trackdir src_td = v->GetVehicleTrackdir();
 
		if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
 
			/* sometimes the roadveh is not on the road (it resides on non-existing track)
 
@@ -431,13 +431,13 @@ public:
 
	static bool stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
 
	{
 
		Tpf pf;
 
		return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile);
 
	}
 

	
 
	FORCEINLINE bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
 
	inline bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
 
	{
 
		/* set origin and destination nodes */
 
		Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
 

	
 
		/* find the best path */
 
		bool bFound = Yapf().FindPath(v);
src/pathfinder/yapf/yapf_ship.cpp
Show inline comments
 
@@ -24,13 +24,13 @@ public:
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
 
	typedef typename Node::Key Key;                      ///< key to hash tables
 

	
 
protected:
 
	/** to access inherited path finder */
 
	FORCEINLINE Tpf& Yapf()
 
	inline Tpf& Yapf()
 
	{
 
		return *static_cast<Tpf*>(this);
 
	}
 

	
 
public:
 
	/**
 
@@ -44,13 +44,13 @@ public:
 
		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
 
			Yapf().AddMultipleNodes(&old_node, F);
 
		}
 
	}
 

	
 
	/** return debug report character to identify the transportation type */
 
	FORCEINLINE char TransportTypeChar() const
 
	inline char TransportTypeChar() const
 
	{
 
		return 'w';
 
	}
 

	
 
	static Trackdir ChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found)
 
	{
 
@@ -120,13 +120,13 @@ protected:
 
public:
 
	/**
 
	 * Called by YAPF to calculate the cost from the origin to the given node.
 
	 *  Calculates only the cost of given node, adds it to the parent node cost
 
	 *  and stores the result into Node::m_cost member
 
	 */
 
	FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	inline bool PfCalcCost(Node& n, const TrackFollower *tf)
 
	{
 
		/* base tile cost depending on distance */
 
		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
 
		/* additional penalty for curves */
 
		if (n.m_parent != NULL && n.GetTrackdir() != NextTrackdir(n.m_parent->GetTrackdir())) {
 
			/* new trackdir does not match the next one when going straight */
src/roadstop_base.h
Show inline comments
 
@@ -43,22 +43,22 @@ struct RoadStop : RoadStopPool::PoolItem
 
		Entry() : length(0), occupied(0) {}
 

	
 
		/**
 
		 * Get the length of this drive through stop.
 
		 * @return the length in tile units.
 
		 */
 
		FORCEINLINE int GetLength() const
 
		inline int GetLength() const
 
		{
 
			return this->length;
 
		}
 

	
 
		/**
 
		 * Get the amount of occupied space in this drive through stop.
 
		 * @return the occupied space in tile units.
 
		 */
 
		FORCEINLINE int GetOccupied() const
 
		inline int GetOccupied() const
 
		{
 
			return this->occupied;
 
		}
 

	
 
		void Leave(const RoadVehicle *rv);
 
		void Enter(const RoadVehicle *rv);
 
@@ -68,73 +68,73 @@ struct RoadStop : RoadStopPool::PoolItem
 

	
 
	TileIndex       xy;     ///< Position on the map
 
	byte            status; ///< Current status of the Stop, @see RoadStopSatusFlag. Access using *Bay and *Busy functions.
 
	struct RoadStop *next;  ///< Next stop of the given type at this station
 

	
 
	/** Initializes a RoadStop */
 
	FORCEINLINE RoadStop(TileIndex tile = INVALID_TILE) :
 
	inline RoadStop(TileIndex tile = INVALID_TILE) :
 
		xy(tile),
 
		status((1 << RSSFB_BAY_COUNT) - 1)
 
	{ }
 

	
 
	~RoadStop();
 

	
 
	/**
 
	 * Checks whether there is a free bay in this road stop
 
	 * @return is at least one bay free?
 
	 */
 
	FORCEINLINE bool HasFreeBay() const
 
	inline bool HasFreeBay() const
 
	{
 
		return GB(this->status, 0, RSSFB_BAY_COUNT) != 0;
 
	}
 

	
 
	/**
 
	 * Checks whether the given bay is free in this road stop
 
	 * @param nr bay to check
 
	 * @return is given bay free?
 
	 */
 
	FORCEINLINE bool IsFreeBay(uint nr) const
 
	inline bool IsFreeBay(uint nr) const
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		return HasBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Checks whether the entrance of the road stop is occupied by a vehicle
 
	 * @return is entrance busy?
 
	 */
 
	FORCEINLINE bool IsEntranceBusy() const
 
	inline bool IsEntranceBusy() const
 
	{
 
		return HasBit(this->status, RSSFB_ENTRY_BUSY);
 
	}
 

	
 
	/**
 
	 * Makes an entrance occupied or free
 
	 * @param busy if true, marks busy; free otherwise
 
	 */
 
	FORCEINLINE void SetEntranceBusy(bool busy)
 
	inline void SetEntranceBusy(bool busy)
 
	{
 
		SB(this->status, RSSFB_ENTRY_BUSY, 1, busy);
 
	}
 

	
 
	/**
 
	 * Get the drive through road stop entry struct for the given direction.
 
	 * @param direction the direciton to get the entry for
 
	 * @return the entry
 
	 */
 
	FORCEINLINE const Entry *GetEntry(DiagDirection dir) const
 
	inline const Entry *GetEntry(DiagDirection dir) const
 
	{
 
		return HasBit((int)dir, 1) ? this->west : this->east;
 
	}
 

	
 
	/**
 
	 * Get the drive through road stop entry struct for the given direction.
 
	 * @param direction the direciton to get the entry for
 
	 * @return the entry
 
	 */
 
	FORCEINLINE Entry *GetEntry(DiagDirection dir)
 
	inline Entry *GetEntry(DiagDirection dir)
 
	{
 
		return HasBit((int)dir, 1) ? this->west : this->east;
 
	}
 

	
 
	void MakeDriveThrough();
 
	void ClearDriveThrough();
 
@@ -154,13 +154,13 @@ private:
 

	
 
	/**
 
	 * Allocates a bay
 
	 * @return the allocated bay number
 
	 * @pre this->HasFreeBay()
 
	 */
 
	FORCEINLINE uint AllocateBay()
 
	inline uint AllocateBay()
 
	{
 
		assert(this->HasFreeBay());
 

	
 
		/* Find the first free bay. If the bit is set, the bay is free. */
 
		uint bay_nr = 0;
 
		while (!HasBit(this->status, bay_nr)) bay_nr++;
 
@@ -170,23 +170,23 @@ private:
 
	}
 

	
 
	/**
 
	 * Allocates a bay in a drive-through road stop
 
	 * @param nr the number of the bay to allocate
 
	 */
 
	FORCEINLINE void AllocateDriveThroughBay(uint nr)
 
	inline void AllocateDriveThroughBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		ClrBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Frees the given bay
 
	 * @param nr the number of the bay to free
 
	 */
 
	FORCEINLINE void FreeBay(uint nr)
 
	inline void FreeBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		SetBit(this->status, nr);
 
	}
 
};
 

	
src/roadveh.h
Show inline comments
 
@@ -129,13 +129,13 @@ struct RoadVehicle FINAL : public Ground
 
protected: // These functions should not be called outside acceleration code.
 

	
 
	/**
 
	 * Allows to know the power value that this vehicle will use.
 
	 * @return Power value from the engine in HP, or zero if the vehicle is not powered.
 
	 */
 
	FORCEINLINE uint16 GetPower() const
 
	inline uint16 GetPower() const
 
	{
 
		/* Power is not added for articulated parts */
 
		if (!this->IsArticulatedPart()) {
 
			/* Road vehicle power is in units of 10 HP. */
 
			return 10 * GetVehicleProperty(this, PROP_ROADVEH_POWER, RoadVehInfo(this->engine_type)->power);
 
		}
 
@@ -143,22 +143,22 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Returns a value if this articulated part is powered.
 
	 * @return Zero, because road vehicles don't have powered parts.
 
	 */
 
	FORCEINLINE uint16 GetPoweredPartPower(const RoadVehicle *head) const
 
	inline uint16 GetPoweredPartPower(const RoadVehicle *head) const
 
	{
 
		return 0;
 
	}
 

	
 
	/**
 
	 * Allows to know the weight value that this vehicle will use.
 
	 * @return Weight value from the engine in tonnes.
 
	 */
 
	FORCEINLINE uint16 GetWeight() const
 
	inline uint16 GetWeight() const
 
	{
 
		uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count()) / 16;
 

	
 
		/* Vehicle weight is not added for articulated parts. */
 
		if (!this->IsArticulatedPart()) {
 
			/* Road vehicle weight is in units of 1/4 t. */
 
@@ -169,59 +169,59 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Allows to know the tractive effort value that this vehicle will use.
 
	 * @return Tractive effort value from the engine.
 
	 */
 
	FORCEINLINE byte GetTractiveEffort() const
 
	inline byte GetTractiveEffort() const
 
	{
 
		/* The tractive effort coefficient is in units of 1/256.  */
 
		return GetVehicleProperty(this, PROP_ROADVEH_TRACTIVE_EFFORT, RoadVehInfo(this->engine_type)->tractive_effort);
 
	}
 

	
 
	/**
 
	 * Gets the area used for calculating air drag.
 
	 * @return Area of the engine in m^2.
 
	 */
 
	FORCEINLINE byte GetAirDragArea() const
 
	inline byte GetAirDragArea() const
 
	{
 
		return 6;
 
	}
 

	
 
	/**
 
	 * Gets the air drag coefficient of this vehicle.
 
	 * @return Air drag value from the engine.
 
	 */
 
	FORCEINLINE byte GetAirDrag() const
 
	inline byte GetAirDrag() const
 
	{
 
		return RoadVehInfo(this->engine_type)->air_drag;
 
	}
 

	
 
	/**
 
	 * Checks the current acceleration status of this vehicle.
 
	 * @return Acceleration status.
 
	 */
 
	FORCEINLINE AccelStatus GetAccelerationStatus() const
 
	inline AccelStatus GetAccelerationStatus() const
 
	{
 
		return (this->vehstatus & VS_STOPPED) ? AS_BRAKE : AS_ACCEL;
 
	}
 

	
 
	/**
 
	 * Calculates the current speed of this vehicle.
 
	 * @return Current speed in km/h-ish.
 
	 */
 
	FORCEINLINE uint16 GetCurrentSpeed() const
 
	inline uint16 GetCurrentSpeed() const
 
	{
 
		return this->cur_speed / 2;
 
	}
 

	
 
	/**
 
	 * Returns the rolling friction coefficient of this vehicle.
 
	 * @return Rolling friction coefficient in [1e-4].
 
	 */
 
	FORCEINLINE uint32 GetRollingFriction() const
 
	inline uint32 GetRollingFriction() const
 
	{
 
		/* Trams have a slightly greater friction coefficient than trains.
 
		 * The rest of road vehicles have bigger values. */
 
		uint32 coeff = (this->roadtype == ROADTYPE_TRAM) ? 40 : 75;
 
		/* The friction coefficient increases with speed in a way that
 
		 * it doubles at 128 km/h, triples at 256 km/h and so on. */
 
@@ -229,40 +229,40 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Allows to know the acceleration type of a vehicle.
 
	 * @return Zero, road vehicles always use a normal acceleration method.
 
	 */
 
	FORCEINLINE int GetAccelerationType() const
 
	inline int GetAccelerationType() const
 
	{
 
		return 0;
 
	}
 

	
 
	/**
 
	 * Returns the slope steepness used by this vehicle.
 
	 * @return Slope steepness used by the vehicle.
 
	 */
 
	FORCEINLINE uint32 GetSlopeSteepness() const
 
	inline uint32 GetSlopeSteepness() const
 
	{
 
		return _settings_game.vehicle.roadveh_slope_steepness;
 
	}
 

	
 
	/**
 
	 * Gets the maximum speed allowed by the track for this vehicle.
 
	 * @return Since roads don't limit road vehicle speed, it returns always zero.
 
	 */
 
	FORCEINLINE uint16 GetMaxTrackSpeed() const
 
	inline uint16 GetMaxTrackSpeed() const
 
	{
 
		return 0;
 
	}
 

	
 
	/**
 
	 * Checks if the vehicle is at a tile that can be sloped.
 
	 * @return True if the tile can be sloped.
 
	 */
 
	FORCEINLINE bool TileMayHaveSlopedTrack() const
 
	inline bool TileMayHaveSlopedTrack() const
 
	{
 
		TrackStatus ts = GetTileTrackStatus(this->tile, TRANSPORT_ROAD, this->compatible_roadtypes);
 
		TrackBits trackbits = TrackStatusToTrackBits(ts);
 

	
 
		return trackbits == TRACK_BIT_X || trackbits == TRACK_BIT_Y;
 
	}
 
@@ -271,13 +271,13 @@ protected: // These functions should not
 
	 * Road vehicles have to use GetSlopePixelZ() to compute their height
 
	 * if they are reversing because in that case, their direction
 
	 * is not parallel with the road. It is safe to return \c true
 
	 * even if it is not reversing.
 
	 * @return are we (possibly) reversing?
 
	 */
 
	FORCEINLINE bool HasToUseGetSlopePixelZ()
 
	inline bool HasToUseGetSlopePixelZ()
 
	{
 
		const RoadVehicle *rv = this->First();
 

	
 
		/* Check if this vehicle is in the same direction as the road under.
 
		 * We already know it has either GVF_GOINGUP_BIT or GVF_GOINGDOWN_BIT set. */
 

	
src/roadveh_cmd.cpp
Show inline comments
 
@@ -413,13 +413,13 @@ void RoadVehicle::UpdateDeltaXY(Directio
 
}
 

	
 
/**
 
 * Calculates the maximum speed of the vehicle under its current conditions.
 
 * @return Maximum speed of the vehicle.
 
 */
 
FORCEINLINE int RoadVehicle::GetCurrentMaxSpeed() const
 
inline int RoadVehicle::GetCurrentMaxSpeed() const
 
{
 
	if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) return this->vcache.cached_max_speed;
 

	
 
	int max_speed = this->vcache.cached_max_speed;
 

	
 
	/* Limit speed to 50% while reversing, 75% in curves. */
src/saveload/saveload.cpp
Show inline comments
 
@@ -275,13 +275,13 @@ struct ReadBuffer {
 
	 * @param reader The filter to actually read data.
 
	 */
 
	ReadBuffer(LoadFilter *reader) : bufp(NULL), bufe(NULL), reader(reader), read(0)
 
	{
 
	}
 

	
 
	FORCEINLINE byte ReadByte()
 
	inline byte ReadByte()
 
	{
 
		if (this->bufp == this->bufe) {
 
			size_t len = this->reader->Read(this->buf, lengthof(this->buf));
 
			if (len == 0) SlErrorCorrupt("Unexpected end of chunk");
 

	
 
			this->read += len;
 
@@ -315,13 +315,13 @@ struct MemoryDumper {
 
	}
 

	
 
	/**
 
	 * Write a single byte into the dumper.
 
	 * @param b The byte to write.
 
	 */
 
	FORCEINLINE void WriteByte(byte b)
 
	inline void WriteByte(byte b)
 
	{
 
		/* Are we at the end of this chunk? */
 
		if (this->buf == this->bufe) {
 
			this->buf = CallocT<byte>(MEMORY_CHUNK_SIZE);
 
			*this->blocks.Append() = this->buf;
 
			this->bufe = this->buf + MEMORY_CHUNK_SIZE;
src/script/api/script_companymode.hpp
Show inline comments
 
@@ -16,16 +16,16 @@
 

	
 
/**
 
 * Class to switch the current company.
 
 * If you create an instance of this class, the company will be switched.
 
 *  The original company is stored and recovered from when ever the
 
 *  instance is destroyed.
 
 * All actions performed within the scope of this mode, will be executed
 
 *  on behalf of the company you switched to. This includes any costs
 
 *  attached to the action performed. If the company does not have the
 
 *  funds the action will be aborted. In other words, this is like the
 
 * All actions performed within the scope of this mode, will be executed
 
 *  on behalf of the company you switched to. This includes any costs
 
 *  attached to the action performed. If the company does not have the
 
 *  funds the action will be aborted. In other words, this is like the
 
 *  real player is executing the commands.
 
 * If the company is not valid during an action, the error
 
 *  ERR_PRECONDITION_INVALID_COMPANY will be returned. You can switch to
 
 *  invalid companies, or a company can become invalid (bankrupt) while you
 
 *  are switched to it.
 
 * @api game
src/smallmap_gui.cpp
Show inline comments
 
@@ -595,13 +595,13 @@ class SmallMapWindow : public Window {
 
	int32 subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
 
	int zoom;        ///< Zoom level. Bigger number means more zoom-out (further away).
 

	
 
	static const uint8 FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
 
	uint8 refresh; ///< refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks
 

	
 
	FORCEINLINE Point SmallmapRemapCoords(int x, int y) const
 
	inline Point SmallmapRemapCoords(int x, int y) const
 
	{
 
		Point pt;
 
		pt.x = (y - x) * 2;
 
		pt.y = y + x;
 
		return pt;
 
	}
 
@@ -609,13 +609,13 @@ class SmallMapWindow : public Window {
 
	/**
 
	 * Remap tile to location on this smallmap.
 
	 * @param tile_x X coordinate of the tile.
 
	 * @param tile_y Y coordinate of the tile.
 
	 * @return Position to draw on.
 
	 */
 
	FORCEINLINE Point RemapTile(int tile_x, int tile_y) const
 
	inline Point RemapTile(int tile_x, int tile_y) const
 
	{
 
		int x_offset = tile_x - this->scroll_x / (int)TILE_SIZE;
 
		int y_offset = tile_y - this->scroll_y / (int)TILE_SIZE;
 

	
 
		if (this->zoom == 1) return SmallmapRemapCoords(x_offset, y_offset);
 

	
 
@@ -633,13 +633,13 @@ class SmallMapWindow : public Window {
 
	 * @param py       Vertical coordinate of the pixel.
 
	 * @param sub[out] Pixel position at the tile (0..3).
 
	 * @param add_sub  Add current #subscroll to the position.
 
	 * @return Tile being displayed at the given position relative to #scroll_x and #scroll_y.
 
	 * @note The #subscroll offset is already accounted for.
 
	 */
 
	FORCEINLINE Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const
 
	inline Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const
 
	{
 
		if (add_sub) px += this->subscroll;  // Total horizontal offset.
 

	
 
		/* For each two rows down, add a x and a y tile, and
 
		 * For each four pixels to the right, move a tile to the right. */
 
		Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
src/station_base.h
Show inline comments
 
@@ -86,26 +86,26 @@ struct Airport : public TileArea {
 
	const AirportFTAClass *GetFTA() const
 
	{
 
		return this->GetSpec()->fsm;
 
	}
 

	
 
	/** Check if this airport has at least one hangar. */
 
	FORCEINLINE bool HasHangar() const
 
	inline bool HasHangar() const
 
	{
 
		return this->GetSpec()->nof_depots > 0;
 
	}
 

	
 
	/**
 
	 * Add the tileoffset to the base tile of this airport but rotate it first.
 
	 * The base tile is the northernmost tile of this airport. This function
 
	 * helps to make sure that getting the tile of a hangar works even for
 
	 * rotated airport layouts without requiring a rotated array of hangar tiles.
 
	 * @param tidc The tilediff to add to the airport tile.
 
	 * @return The tile of this airport plus the rotated offset.
 
	 */
 
	FORCEINLINE TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
 
	inline TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
 
	{
 
		const AirportSpec *as = this->GetSpec();
 
		switch (this->rotation) {
 
			case DIR_N: return this->tile + ToTileIndexDiff(tidc);
 

	
 
			case DIR_E: return this->tile + TileDiffXY(tidc.y, as->size_x - 1 - tidc.x);
 
@@ -121,13 +121,13 @@ struct Airport : public TileArea {
 
	/**
 
	 * Get the first tile of the given hangar.
 
	 * @param hangar_num The hangar to get the location of.
 
	 * @pre hangar_num < GetNumHangars().
 
	 * @return A tile with the given hangar.
 
	 */
 
	FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
 
	inline TileIndex GetHangarTile(uint hangar_num) const
 
	{
 
		const AirportSpec *as = this->GetSpec();
 
		for (uint i = 0; i < as->nof_depots; i++) {
 
			if (as->depot_table[i].hangar_num == hangar_num) {
 
				return this->GetRotatedTileFromOffset(as->depot_table[i].ti);
 
			}
 
@@ -138,33 +138,33 @@ struct Airport : public TileArea {
 
	/**
 
	 * Get the exit direction of the hangar at a specific tile.
 
	 * @param tile The tile to query.
 
	 * @pre IsHangarTile(tile).
 
	 * @return The exit direction of the hangar, taking airport rotation into account.
 
	 */
 
	FORCEINLINE Direction GetHangarExitDirection(TileIndex tile) const
 
	inline Direction GetHangarExitDirection(TileIndex tile) const
 
	{
 
		const AirportSpec *as = this->GetSpec();
 
		const HangarTileTable *htt = GetHangarDataByTile(tile);
 
		return ChangeDir(htt->dir, DirDifference(this->rotation, as->rotation[0]));
 
	}
 

	
 
	/**
 
	 * Get the hangar number of the hangar at a specific tile.
 
	 * @param tile The tile to query.
 
	 * @pre IsHangarTile(tile).
 
	 * @return The hangar number of the hangar at the given tile.
 
	 */
 
	FORCEINLINE uint GetHangarNum(TileIndex tile) const
 
	inline uint GetHangarNum(TileIndex tile) const
 
	{
 
		const HangarTileTable *htt = GetHangarDataByTile(tile);
 
		return htt->hangar_num;
 
	}
 

	
 
	/** Get the number of hangars on this airport. */
 
	FORCEINLINE uint GetNumHangars() const
 
	inline uint GetNumHangars() const
 
	{
 
		uint num = 0;
 
		uint counted = 0;
 
		const AirportSpec *as = this->GetSpec();
 
		for (uint i = 0; i < as->nof_depots; i++) {
 
			if (!HasBit(counted, as->depot_table[i].hangar_num)) {
 
@@ -179,13 +179,13 @@ private:
 
	/**
 
	 * Retrieve hangar information of a hangar at a given tile.
 
	 * @param tile %Tile containing the hangar.
 
	 * @return The requested hangar information.
 
	 * @pre The \a tile must be at a hangar tile at an airport.
 
	 */
 
	FORCEINLINE const HangarTileTable *GetHangarDataByTile(TileIndex tile) const
 
	inline const HangarTileTable *GetHangarDataByTile(TileIndex tile) const
 
	{
 
		const AirportSpec *as = this->GetSpec();
 
		for (uint i = 0; i < as->nof_depots; i++) {
 
			if (this->GetRotatedTileFromOffset(as->depot_table[i].ti) == tile) {
 
				return as->depot_table + i;
 
			}
 
@@ -242,18 +242,18 @@ public:
 
	void RecomputeIndustriesNear();
 
	static void RecomputeIndustriesNearForAll();
 

	
 
	uint GetCatchmentRadius() const;
 
	Rect GetCatchmentRect() const;
 

	
 
	/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
 
	/* virtual */ inline bool TileBelongsToRailStation(TileIndex tile) const
 
	{
 
		return IsRailStationTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	FORCEINLINE bool TileBelongsToAirport(TileIndex tile) const
 
	inline bool TileBelongsToAirport(TileIndex tile) const
 
	{
 
		return IsAirportTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	/* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
 

	
 
@@ -274,13 +274,13 @@ public:
 
	 */
 
	AirportTileIterator(const Station *st) : OrthogonalTileIterator(st->airport), st(st)
 
	{
 
		if (!st->TileBelongsToAirport(this->tile)) ++(*this);
 
	}
 

	
 
	FORCEINLINE TileIterator& operator ++()
 
	inline TileIterator& operator ++()
 
	{
 
		(*this).OrthogonalTileIterator::operator++();
 
		while (this->tile != INVALID_TILE && !st->TileBelongsToAirport(this->tile)) {
 
			(*this).OrthogonalTileIterator::operator++();
 
		}
 
		return *this;
src/stdafx.h
Show inline comments
 
@@ -118,13 +118,12 @@
 
	#define printf pspDebugScreenPrintf
 
#endif /* PSP */
 

	
 
/* Stuff for GCC */
 
#if defined(__GNUC__)
 
	#define NORETURN __attribute__ ((noreturn))
 
	#define FORCEINLINE inline
 
	#define CDECL
 
	#define __int64 long long
 
	#define GCC_PACK __attribute__((packed))
 
	/* Warn about functions using 'printf' format syntax. First argument determines which parameter
 
	 * is the format string, second argument is start of values passed to printf. */
 
	#define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
 
@@ -134,13 +133,12 @@
 
		#define FINAL
 
	#endif
 
#endif /* __GNUC__ */
 

	
 
#if defined(__WATCOMC__)
 
	#define NORETURN
 
	#define FORCEINLINE inline
 
	#define CDECL
 
	#define GCC_PACK
 
	#define WARN_FORMAT(string, args)
 
	#define FINAL
 
	#include <malloc.h>
 
#endif /* __WATCOMC__ */
 
@@ -182,14 +180,13 @@
 
	#pragma warning(disable: 6031)   // code analyzer: Return value ignored: 'ReadFile'
 
	#pragma warning(disable: 6255)   // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
 
	#pragma warning(disable: 6246)   // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
 

	
 
	#include <malloc.h> // alloca()
 
	#define NORETURN __declspec(noreturn)
 
	#define FORCEINLINE __forceinline
 
	#define inline _inline
 
	#define inline __forceinline
 

	
 
	#if !defined(WINCE)
 
		#define CDECL _cdecl
 
	#endif
 

	
 
	#define GCC_PACK
 
@@ -445,13 +442,13 @@ void NORETURN CDECL error(const char *st
 
#endif
 

	
 
/**
 
 * Version of the standard free that accepts const pointers.
 
 * @param ptr The data to free.
 
 */
 
static FORCEINLINE void free(const void *ptr)
 
static inline void free(const void *ptr)
 
{
 
	free(const_cast<void *>(ptr));
 
}
 

	
 
/**
 
 * The largest value that can be entered in a variable
src/subsidy_base.h
Show inline comments
 
@@ -30,24 +30,24 @@ struct Subsidy : SubsidyPool::PoolItem<&
 
	SourceID src;            ///< Index of source. Either TownID or IndustryID
 
	SourceID dst;            ///< Index of destination. Either TownID or IndustryID
 

	
 
	/**
 
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
 
	 */
 
	FORCEINLINE Subsidy() { }
 
	inline Subsidy() { }
 

	
 
	/**
 
	 * (Empty) destructor has to be defined else operator delete might be called with NULL parameter
 
	 */
 
	FORCEINLINE ~Subsidy() { }
 
	inline ~Subsidy() { }
 

	
 
	/**
 
	 * Tests whether this subsidy has been awarded to someone
 
	 * @return is this subsidy awarded?
 
	 */
 
	FORCEINLINE bool IsAwarded() const
 
	inline bool IsAwarded() const
 
	{
 
		return this->awarded != INVALID_COMPANY;
 
	}
 

	
 
	void AwardTo(CompanyID company);
 
};
src/tilearea_type.h
Show inline comments
 
@@ -82,13 +82,13 @@ public:
 
	}
 

	
 
	/**
 
	 * Get the tile we are currently at.
 
	 * @return The tile we are at, or INVALID_TILE when we're done.
 
	 */
 
	FORCEINLINE operator TileIndex () const
 
	inline operator TileIndex () const
 
	{
 
		return this->tile;
 
	}
 

	
 
	/**
 
	 * Move ourselves to the next tile in the rectange on the map.
 
@@ -117,13 +117,13 @@ public:
 
	{
 
	}
 

	
 
	/**
 
	 * Move ourselves to the next tile in the rectange on the map.
 
	 */
 
	FORCEINLINE TileIterator& operator ++()
 
	inline TileIterator& operator ++()
 
	{
 
		assert(this->tile != INVALID_TILE);
 

	
 
		if (--this->x > 0) {
 
			this->tile++;
 
		} else if (--this->y > 0) {
src/tilematrix_type.hpp
Show inline comments
 
@@ -134,13 +134,13 @@ public:
 
		uint y = TileY(tile) / N;
 

	
 
		return &this->data[y * this->area.w / N + x];
 
	}
 

	
 
	/** Array access operator, see #Get. */
 
	FORCEINLINE T &operator[](TileIndex tile)
 
	inline T &operator[](TileIndex tile)
 
	{
 
		return *this->Get(tile);
 
	}
 
};
 

	
 
#endif /* TILEMATRIX_TYPE_HPP */
src/town.h
Show inline comments
 
@@ -130,13 +130,13 @@ struct Town : TownPool::PoolItem<&_town_
 
		/* 3 is added (the noise of the lowest airport), so the  user can at least build a small airfield. */
 
		return (this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3;
 
	}
 

	
 
	void UpdateVirtCoord();
 

	
 
	static FORCEINLINE Town *GetByTile(TileIndex tile)
 
	static inline Town *GetByTile(TileIndex tile)
 
	{
 
		return Town::Get(GetTownIndex(tile));
 
	}
 

	
 
	static Town *GetRandom();
 
	static void PostDestructor(size_t index);
src/train.h
Show inline comments
 
@@ -125,25 +125,25 @@ struct Train FINAL : public GroundVehicl
 
	int GetCurrentMaxSpeed() const;
 

	
 
	/**
 
	 * Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
 
	 * @return Next vehicle in the consist.
 
	 */
 
	FORCEINLINE Train *GetNextUnit() const
 
	inline Train *GetNextUnit() const
 
	{
 
		Train *v = this->GetNextVehicle();
 
		if (v != NULL && v->IsRearDualheaded()) v = v->GetNextVehicle();
 

	
 
		return v;
 
	}
 

	
 
	/**
 
	 * Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
 
	 * @return Previous vehicle in the consist.
 
	 */
 
	FORCEINLINE Train *GetPrevUnit()
 
	inline Train *GetPrevUnit()
 
	{
 
		Train *v = this->GetPrevVehicle();
 
		if (v != NULL && v->IsRearDualheaded()) v = v->GetPrevVehicle();
 

	
 
		return v;
 
	}
 
@@ -164,13 +164,13 @@ struct Train FINAL : public GroundVehicl
 
protected: // These functions should not be called outside acceleration code.
 

	
 
	/**
 
	 * Allows to know the power value that this vehicle will use.
 
	 * @return Power value from the engine in HP, or zero if the vehicle is not powered.
 
	 */
 
	FORCEINLINE uint16 GetPower() const
 
	inline uint16 GetPower() const
 
	{
 
		/* Power is not added for articulated parts */
 
		if (!this->IsArticulatedPart() && HasPowerOnRail(this->railtype, GetRailType(this->tile))) {
 
			uint16 power = GetVehicleProperty(this, PROP_TRAIN_POWER, RailVehInfo(this->engine_type)->power);
 
			/* Halve power for multiheaded parts */
 
			if (this->IsMultiheaded()) power /= 2;
 
@@ -181,13 +181,13 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Returns a value if this articulated part is powered.
 
	 * @return Power value from the articulated part in HP, or zero if it is not powered.
 
	 */
 
	FORCEINLINE uint16 GetPoweredPartPower(const Train *head) const
 
	inline uint16 GetPoweredPartPower(const Train *head) const
 
	{
 
		/* For powered wagons the engine defines the type of engine (i.e. railtype) */
 
		if (HasBit(this->flags, VRF_POWEREDWAGON) && HasPowerOnRail(head->railtype, GetRailType(this->tile))) {
 
			return RailVehInfo(this->gcache.first_engine)->pow_wag_power;
 
		}
 

	
 
@@ -195,13 +195,13 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Allows to know the weight value that this vehicle will use.
 
	 * @return Weight value from the engine in tonnes.
 
	 */
 
	FORCEINLINE uint16 GetWeight() const
 
	inline uint16 GetWeight() const
 
	{
 
		uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count() * FreightWagonMult(this->cargo_type)) / 16;
 

	
 
		/* Vehicle weight is not added for articulated parts. */
 
		if (!this->IsArticulatedPart()) {
 
			weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
 
@@ -216,109 +216,109 @@ protected: // These functions should not
 
	}
 

	
 
	/**
 
	 * Allows to know the tractive effort value that this vehicle will use.
 
	 * @return Tractive effort value from the engine.
 
	 */
 
	FORCEINLINE byte GetTractiveEffort() const
 
	inline byte GetTractiveEffort() const
 
	{
 
		return GetVehicleProperty(this, PROP_TRAIN_TRACTIVE_EFFORT, RailVehInfo(this->engine_type)->tractive_effort);
 
	}
 

	
 
	/**
 
	 * Gets the area used for calculating air drag.
 
	 * @return Area of the engine in m^2.
 
	 */
 
	FORCEINLINE byte GetAirDragArea() const
 
	inline byte GetAirDragArea() const
 
	{
 
		/* Air drag is higher in tunnels due to the limited cross-section. */
 
		return (this->track == TRACK_BIT_WORMHOLE && this->vehstatus & VS_HIDDEN) ? 28 : 14;
 
	}
 

	
 
	/**
 
	 * Gets the air drag coefficient of this vehicle.
 
	 * @return Air drag value from the engine.
 
	 */
 
	FORCEINLINE byte GetAirDrag() const
 
	inline byte GetAirDrag() const
 
	{
 
		return RailVehInfo(this->engine_type)->air_drag;
 
	}
 

	
 
	/**
 
	 * Checks the current acceleration status of this vehicle.
 
	 * @return Acceleration status.
 
	 */
 
	FORCEINLINE AccelStatus GetAccelerationStatus() const
 
	inline AccelStatus GetAccelerationStatus() const
 
	{
 
		return (this->vehstatus & VS_STOPPED) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
 
	}
 

	
 
	/**
 
	 * Calculates the current speed of this vehicle.
 
	 * @return Current speed in km/h-ish.
 
	 */
 
	FORCEINLINE uint16 GetCurrentSpeed() const
 
	inline uint16 GetCurrentSpeed() const
 
	{
 
		return this->cur_speed;
 
	}
 

	
 
	/**
 
	 * Returns the rolling friction coefficient of this vehicle.
 
	 * @return Rolling friction coefficient in [1e-4].
 
	 */
 
	FORCEINLINE uint32 GetRollingFriction() const
 
	inline uint32 GetRollingFriction() const
 
	{
 
		/* Rolling friction for steel on steel is between 0.1% and 0.2%.
 
		 * The friction coefficient increases with speed in a way that
 
		 * it doubles at 512 km/h, triples at 1024 km/h and so on. */
 
		return 15 * (512 + this->GetCurrentSpeed()) / 512;
 
	}
 

	
 
	/**
 
	 * Allows to know the acceleration type of a vehicle.
 
	 * @return Acceleration type of the vehicle.
 
	 */
 
	FORCEINLINE int GetAccelerationType() const
 
	inline int GetAccelerationType() const
 
	{
 
		return GetRailTypeInfo(this->railtype)->acceleration_type;
 
	}
 

	
 
	/**
 
	 * Returns the slope steepness used by this vehicle.
 
	 * @return Slope steepness used by the vehicle.
 
	 */
 
	FORCEINLINE uint32 GetSlopeSteepness() const
 
	inline uint32 GetSlopeSteepness() const
 
	{
 
		return _settings_game.vehicle.train_slope_steepness;
 
	}
 

	
 
	/**
 
	 * Gets the maximum speed allowed by the track for this vehicle.
 
	 * @return Maximum speed allowed.
 
	 */
 
	FORCEINLINE uint16 GetMaxTrackSpeed() const
 
	inline uint16 GetMaxTrackSpeed() const
 
	{
 
		return GetRailTypeInfo(GetRailType(this->tile))->max_speed;
 
	}
 

	
 
	/**
 
	 * Checks if the vehicle is at a tile that can be sloped.
 
	 * @return True if the tile can be sloped.
 
	 */
 
	FORCEINLINE bool TileMayHaveSlopedTrack() const
 
	inline bool TileMayHaveSlopedTrack() const
 
	{
 
		/* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped. */
 
		return this->track == TRACK_BIT_X || this->track == TRACK_BIT_Y;
 
	}
 

	
 
	/**
 
	 * Trains can always use the faster algorithm because they
 
	 * have always the same direction as the track under them.
 
	 * @return false
 
	 */
 
	FORCEINLINE bool HasToUseGetSlopePixelZ()
 
	inline bool HasToUseGetSlopePixelZ()
 
	{
 
		return false;
 
	}
 
};
 

	
 
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
src/train_gui.cpp
Show inline comments
 
@@ -163,13 +163,13 @@ struct CargoSummaryItem {
 
	StringID subtype; ///< STR_EMPTY if none
 
	uint capacity;    ///< Amount that can be carried
 
	uint amount;      ///< Amount that is carried
 
	StationID source; ///< One of the source stations
 

	
 
	/** Used by CargoSummary::Find() and similiar functions */
 
	FORCEINLINE bool operator != (const CargoSummaryItem &other) const
 
	inline bool operator != (const CargoSummaryItem &other) const
 
	{
 
		return this->cargo != other.cargo || this->subtype != other.subtype;
 
	}
 
};
 

	
 
static const uint TRAIN_DETAILS_MIN_INDENT = 32; ///< Minimum indent level in the train details window
src/vehicle_base.h
Show inline comments
 
@@ -292,13 +292,13 @@ public:
 
	 * However, this method is slightly wrong in corners, as the leftover progress is not scaled correctly
 
	 * when changing movement direction. #GetAdvanceSpeed() and #GetAdvanceDistance() are better wrt. this.
 
	 *
 
	 * @param speed Direction-independent unscaled speed.
 
	 * @return speed scaled by movement direction. 256 units are required for each movement step.
 
	 */
 
	FORCEINLINE uint GetOldAdvanceSpeed(uint speed)
 
	inline uint GetOldAdvanceSpeed(uint speed)
 
	{
 
		return (this->direction & 1) ? speed : speed * 3 / 4;
 
	}
 

	
 
	/**
 
	 * Determines the effective vehicle movement speed.
 
@@ -309,25 +309,25 @@ public:
 
	 * However different amounts of "progress" are needed for moving a step in a specific direction.
 
	 * That way the leftover progress does not need any adaption when changing movement direction.
 
	 *
 
	 * @param speed Direction-independent unscaled speed.
 
	 * @return speed, scaled to match #GetAdvanceDistance().
 
	 */
 
	static FORCEINLINE uint GetAdvanceSpeed(uint speed)
 
	static inline uint GetAdvanceSpeed(uint speed)
 
	{
 
		return speed * 3 / 4;
 
	}
 

	
 
	/**
 
	 * Determines the vehicle "progress" needed for moving a step.
 
	 *
 
	 * Together with #GetAdvanceSpeed() this function is a replacement for #GetOldAdvanceSpeed().
 
	 *
 
	 * @return distance to drive for a movement step on the map.
 
	 */
 
	FORCEINLINE uint GetAdvanceDistance()
 
	inline uint GetAdvanceDistance()
 
	{
 
		return (this->direction & 1) ? 192 : 256;
 
	}
 

	
 
	/**
 
	 * Sets the expense type associated to this vehicle type
 
@@ -358,33 +358,33 @@ public:
 
	uint32 GetGRFID() const;
 

	
 
	/**
 
	 * Invalidates cached NewGRF variables
 
	 * @see InvalidateNewGRFCacheOfChain
 
	 */
 
	FORCEINLINE void InvalidateNewGRFCache()
 
	inline void InvalidateNewGRFCache()
 
	{
 
		this->grf_cache.cache_valid = 0;
 
	}
 

	
 
	/**
 
	 * Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
 
	 * @see InvalidateNewGRFCache
 
	 */
 
	FORCEINLINE void InvalidateNewGRFCacheOfChain()
 
	inline void InvalidateNewGRFCacheOfChain()
 
	{
 
		for (Vehicle *u = this; u != NULL; u = u->Next()) {
 
			u->InvalidateNewGRFCache();
 
		}
 
	}
 

	
 
	/**
 
	 * Check if the vehicle is a ground vehicle.
 
	 * @return True iff the vehicle is a train or a road vehicle.
 
	 */
 
	FORCEINLINE bool IsGroundVehicle() const
 
	inline bool IsGroundVehicle() const
 
	{
 
		return this->type == VEH_TRAIN || this->type == VEH_ROAD;
 
	}
 

	
 
	/**
 
	 * Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
 
@@ -736,97 +736,97 @@ public:
 
	void HandlePathfindingResult(bool path_found);
 

	
 
	/**
 
	 * Check if the vehicle is a front engine.
 
	 * @return Returns true if the vehicle is a front engine.
 
	 */
 
	FORCEINLINE bool IsFrontEngine() const
 
	inline bool IsFrontEngine() const
 
	{
 
		return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
 
	}
 

	
 
	/**
 
	 * Check if the vehicle is an articulated part of an engine.
 
	 * @return Returns true if the vehicle is an articulated part.
 
	 */
 
	FORCEINLINE bool IsArticulatedPart() const
 
	inline bool IsArticulatedPart() const
 
	{
 
		return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_ARTICULATED_PART);
 
	}
 

	
 
	/**
 
	 * Check if an engine has an articulated part.
 
	 * @return True if the engine has an articulated part.
 
	 */
 
	FORCEINLINE bool HasArticulatedPart() const
 
	inline bool HasArticulatedPart() const
 
	{
 
		return this->Next() != NULL && this->Next()->IsArticulatedPart();
 
	}
 

	
 
	/**
 
	 * Get the next part of an articulated engine.
 
	 * @return Next part of the articulated engine.
 
	 * @pre The vehicle is an articulated engine.
 
	 */
 
	FORCEINLINE Vehicle *GetNextArticulatedPart() const
 
	inline Vehicle *GetNextArticulatedPart() const
 
	{
 
		assert(this->HasArticulatedPart());
 
		return this->Next();
 
	}
 

	
 
	/**
 
	 * Get the first part of an articulated engine.
 
	 * @return First part of the engine.
 
	 */
 
	FORCEINLINE Vehicle *GetFirstEnginePart()
 
	inline Vehicle *GetFirstEnginePart()
 
	{
 
		Vehicle *v = this;
 
		while (v->IsArticulatedPart()) v = v->Previous();
 
		return v;
 
	}
 

	
 
	/**
 
	 * Get the first part of an articulated engine.
 
	 * @return First part of the engine.
 
	 */
 
	FORCEINLINE const Vehicle *GetFirstEnginePart() const
 
	inline const Vehicle *GetFirstEnginePart() const
 
	{
 
		const Vehicle *v = this;
 
		while (v->IsArticulatedPart()) v = v->Previous();
 
		return v;
 
	}
 

	
 
	/**
 
	 * Get the last part of an articulated engine.
 
	 * @return Last part of the engine.
 
	 */
 
	FORCEINLINE Vehicle *GetLastEnginePart()
 
	inline Vehicle *GetLastEnginePart()
 
	{
 
		Vehicle *v = this;
 
		while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
 
		return v;
 
	}
 

	
 
	/**
 
	 * Get the next real (non-articulated part) vehicle in the consist.
 
	 * @return Next vehicle in the consist.
 
	 */
 
	FORCEINLINE Vehicle *GetNextVehicle() const
 
	inline Vehicle *GetNextVehicle() const
 
	{
 
		const Vehicle *v = this;
 
		while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
 

	
 
		/* v now contains the last articulated part in the engine */
 
		return v->Next();
 
	}
 

	
 
	/**
 
	 * Get the previous real (non-articulated part) vehicle in the consist.
 
	 * @return Previous vehicle in the consist.
 
	 */
 
	FORCEINLINE Vehicle *GetPrevVehicle() const
 
	inline Vehicle *GetPrevVehicle() const
 
	{
 
		Vehicle *v = this->Previous();
 
		while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
 

	
 
		return v;
 
	}
 
@@ -855,144 +855,144 @@ struct SpecializedVehicle : public Vehic
 

	
 
	typedef SpecializedVehicle<T, Type> SpecializedVehicleBase; ///< Our type
 

	
 
	/**
 
	 * Set vehicle type correctly
 
	 */
 
	FORCEINLINE SpecializedVehicle<T, Type>() : Vehicle(Type) { }
 
	inline SpecializedVehicle<T, Type>() : Vehicle(Type) { }
 

	
 
	/**
 
	 * Get the first vehicle in the chain
 
	 * @return first vehicle in the chain
 
	 */
 
	FORCEINLINE T *First() const { return (T *)this->Vehicle::First(); }
 
	inline T *First() const { return (T *)this->Vehicle::First(); }
 

	
 
	/**
 
	 * Get the last vehicle in the chain
 
	 * @return last vehicle in the chain
 
	 */
 
	FORCEINLINE T *Last() { return (T *)this->Vehicle::Last(); }
 
	inline T *Last() { return (T *)this->Vehicle::Last(); }
 

	
 
	/**
 
	 * Get the last vehicle in the chain
 
	 * @return last vehicle in the chain
 
	 */
 
	FORCEINLINE const T *Last() const { return (const T *)this->Vehicle::Last(); }
 
	inline const T *Last() const { return (const T *)this->Vehicle::Last(); }
 

	
 
	/**
 
	 * Get next vehicle in the chain
 
	 * @return next vehicle in the chain
 
	 */
 
	FORCEINLINE T *Next() const { return (T *)this->Vehicle::Next(); }
 
	inline T *Next() const { return (T *)this->Vehicle::Next(); }
 

	
 
	/**
 
	 * Get previous vehicle in the chain
 
	 * @return previous vehicle in the chain
 
	 */
 
	FORCEINLINE T *Previous() const { return (T *)this->Vehicle::Previous(); }
 
	inline T *Previous() const { return (T *)this->Vehicle::Previous(); }
 

	
 
	/**
 
	 * Get the next part of an articulated engine.
 
	 * @return Next part of the articulated engine.
 
	 * @pre The vehicle is an articulated engine.
 
	 */
 
	FORCEINLINE T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
 
	inline T *GetNextArticulatedPart() { return (T *)this->Vehicle::GetNextArticulatedPart(); }
 

	
 
	/**
 
	 * Get the next part of an articulated engine.
 
	 * @return Next part of the articulated engine.
 
	 * @pre The vehicle is an articulated engine.
 
	 */
 
	FORCEINLINE T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
 
	inline T *GetNextArticulatedPart() const { return (T *)this->Vehicle::GetNextArticulatedPart(); }
 

	
 
	/**
 
	 * Get the first part of an articulated engine.
 
	 * @return First part of the engine.
 
	 */
 
	FORCEINLINE T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
 
	inline T *GetFirstEnginePart() { return (T *)this->Vehicle::GetFirstEnginePart(); }
 

	
 
	/**
 
	 * Get the first part of an articulated engine.
 
	 * @return First part of the engine.
 
	 */
 
	FORCEINLINE const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
 
	inline const T *GetFirstEnginePart() const { return (const T *)this->Vehicle::GetFirstEnginePart(); }
 

	
 
	/**
 
	 * Get the last part of an articulated engine.
 
	 * @return Last part of the engine.
 
	 */
 
	FORCEINLINE T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
 
	inline T *GetLastEnginePart() { return (T *)this->Vehicle::GetLastEnginePart(); }
 

	
 
	/**
 
	 * Get the next real (non-articulated part) vehicle in the consist.
 
	 * @return Next vehicle in the consist.
 
	 */
 
	FORCEINLINE T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
 
	inline T *GetNextVehicle() const { return (T *)this->Vehicle::GetNextVehicle(); }
 

	
 
	/**
 
	 * Get the previous real (non-articulated part) vehicle in the consist.
 
	 * @return Previous vehicle in the consist.
 
	 */
 
	FORCEINLINE T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
 
	inline T *GetPrevVehicle() const { return (T *)this->Vehicle::GetPrevVehicle(); }
 

	
 
	/**
 
	 * Tests whether given index is a valid index for vehicle of this type
 
	 * @param index tested index
 
	 * @return is this index valid index of T?
 
	 */
 
	static FORCEINLINE bool IsValidID(size_t index)
 
	static inline bool IsValidID(size_t index)
 
	{
 
		return Vehicle::IsValidID(index) && Vehicle::Get(index)->type == Type;
 
	}
 

	
 
	/**
 
	 * Gets vehicle with given index
 
	 * @return pointer to vehicle with given index casted to T *
 
	 */
 
	static FORCEINLINE T *Get(size_t index)
 
	static inline T *Get(size_t index)
 
	{
 
		return (T *)Vehicle::Get(index);
 
	}
 

	
 
	/**
 
	 * Returns vehicle if the index is a valid index for this vehicle type
 
	 * @return pointer to vehicle with given index if it's a vehicle of this type
 
	 */
 
	static FORCEINLINE T *GetIfValid(size_t index)
 
	static inline T *GetIfValid(size_t index)
 
	{
 
		return IsValidID(index) ? Get(index) : NULL;
 
	}
 

	
 
	/**
 
	 * Converts a Vehicle to SpecializedVehicle with type checking.
 
	 * @param v Vehicle pointer
 
	 * @return pointer to SpecializedVehicle
 
	 */
 
	static FORCEINLINE T *From(Vehicle *v)
 
	static inline T *From(Vehicle *v)
 
	{
 
		assert(v->type == Type);
 
		return (T *)v;
 
	}
 

	
 
	/**
 
	 * Converts a const Vehicle to const SpecializedVehicle with type checking.
 
	 * @param v Vehicle pointer
 
	 * @return pointer to SpecializedVehicle
 
	 */
 
	static FORCEINLINE const T *From(const Vehicle *v)
 
	static inline const T *From(const Vehicle *v)
 
	{
 
		assert(v->type == Type);
 
		return (const T *)v;
 
	}
 

	
 
	/**
 
	 * Update vehicle sprite- and position caches
 
	 * @param moved Was the vehicle moved?
 
	 * @param turned Did the vehicle direction change?
 
	 */
 
	FORCEINLINE void UpdateViewport(bool moved, bool turned)
 
	inline void UpdateViewport(bool moved, bool turned)
 
	{
 
		extern void VehicleMove(Vehicle *v, bool update_viewport);
 

	
 
		/* Explicitly choose method to call to prevent vtable dereference -
 
		 * it gives ~3% runtime improvements in games with many vehicles */
 
		if (turned) ((T *)this)->T::UpdateDeltaXY(this->direction);
src/vehicle_gui.cpp
Show inline comments
 
@@ -294,23 +294,23 @@ struct RefitOption {
 

	
 
	/**
 
	 * Inequality operator for #RefitOption.
 
	 * @param other Compare to this #RefitOption.
 
	 * @return True if both #RefitOption are different.
 
	 */
 
	FORCEINLINE bool operator != (const RefitOption &other) const
 
	inline bool operator != (const RefitOption &other) const
 
	{
 
		return other.cargo != this->cargo || other.value != this->value;
 
	}
 

	
 
	/**
 
	 * Equality operator for #RefitOption.
 
	 * @param other Compare to this #RefitOption.
 
	 * @return True if both #RefitOption are equal.
 
	 */
 
	FORCEINLINE bool operator == (const RefitOption &other) const
 
	inline bool operator == (const RefitOption &other) const
 
	{
 
		return other.cargo == this->cargo && other.value == this->value;
 
	}
 
};
 

	
 
typedef SmallVector<RefitOption, 32> SubtypeList; ///< List of refit subtypes associated to a cargo.
src/waypoint_base.h
Show inline comments
 
@@ -24,13 +24,13 @@ struct Waypoint FINAL : SpecializedStati
 
	 */
 
	Waypoint(TileIndex tile = INVALID_TILE) : SpecializedStation<Waypoint, true>(tile) { }
 
	~Waypoint();
 

	
 
	void UpdateVirtCoord();
 

	
 
	/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
 
	/* virtual */ inline bool TileBelongsToRailStation(TileIndex tile) const
 
	{
 
		return IsRailWaypointTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
 

	
 
@@ -47,24 +47,24 @@ struct Waypoint FINAL : SpecializedStati
 
	}
 

	
 
	/**
 
	 * Is this a single tile waypoint?
 
	 * @return true if it is.
 
	 */
 
	FORCEINLINE bool IsSingleTile() const
 
	inline bool IsSingleTile() const
 
	{
 
		return (this->facilities & FACIL_TRAIN) != 0 && this->train_station.w == 1 && this->train_station.h == 1;
 
	}
 

	
 
	/**
 
	 * Is the "type" of waypoint the same as the given waypoint,
 
	 * i.e. are both a rail waypoint or are both a buoy?
 
	 * @param wp The waypoint to compare to.
 
	 * @return true iff their types are equal.
 
	 */
 
	FORCEINLINE bool IsOfType(const Waypoint *wp) const
 
	inline bool IsOfType(const Waypoint *wp) const
 
	{
 
		return this->string_id == wp->string_id;
 
	}
 
};
 

	
 
/**
src/widget_type.h
Show inline comments
 
@@ -140,22 +140,22 @@ public:
 
	 * Set additional space (padding) around the widget.
 
	 * @param top    Amount of additional space above the widget.
 
	 * @param right  Amount of additional space right of the widget.
 
	 * @param bottom Amount of additional space below the widget.
 
	 * @param left   Amount of additional space left of the widget.
 
	 */
 
	FORCEINLINE void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
 
	inline void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
 
	{
 
		this->padding_top = top;
 
		this->padding_right = right;
 
		this->padding_bottom = bottom;
 
		this->padding_left = left;
 
	}
 

	
 
	FORCEINLINE uint GetHorizontalStepSize(SizingType sizing) const;
 
	FORCEINLINE uint GetVerticalStepSize(SizingType sizing) const;
 
	inline uint GetHorizontalStepSize(SizingType sizing) const;
 
	inline uint GetVerticalStepSize(SizingType sizing) const;
 

	
 
	virtual void Draw(const Window *w) = 0;
 
	virtual void SetDirty(const Window *w) const;
 

	
 
	WidgetType type;      ///< Type of the widget / nested widget.
 
	uint fill_x;          ///< Horizontal fill stepsize (from initial size, \c 0 means not resizable).
 
@@ -180,42 +180,42 @@ public:
 
	uint8 padding_top;    ///< Paddings added to the top of the widget. Managed by parent container widget.
 
	uint8 padding_right;  ///< Paddings added to the right of the widget. Managed by parent container widget.
 
	uint8 padding_bottom; ///< Paddings added to the bottom of the widget. Managed by parent container widget.
 
	uint8 padding_left;   ///< Paddings added to the left of the widget. Managed by parent container widget.
 

	
 
protected:
 
	FORCEINLINE void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
 
	inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
 
};
 

	
 
/**
 
 * Get the horizontal sizing step.
 
 * @param sizing Type of resize being performed.
 
 */
 
FORCEINLINE uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
 
inline uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
 
{
 
	return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
 
}
 

	
 
/**
 
 * Get the vertical sizing step.
 
 * @param sizing Type of resize being performed.
 
 */
 
FORCEINLINE uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
 
inline uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
 
{
 
	return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
 
}
 

	
 
/**
 
 * Store size and position.
 
 * @param sizing       Type of resizing to perform.
 
 * @param x            Horizontal offset of the widget relative to the left edge of the window.
 
 * @param y            Vertical offset of the widget relative to the top edge of the window.
 
 * @param given_width  Width allocated to the widget.
 
 * @param given_height Height allocated to the widget.
 
 */
 
FORCEINLINE void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
 
inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
 
{
 
	this->pos_x = x;
 
	this->pos_y = y;
 
	if (sizing == ST_SMALLEST) {
 
		this->smallest_x = given_width;
 
		this->smallest_y = given_height;
 
@@ -604,50 +604,50 @@ public:
 
	}
 

	
 
	/**
 
	 * Gets the number of elements in the list
 
	 * @return the number of elements
 
	 */
 
	FORCEINLINE uint16 GetCount() const
 
	inline uint16 GetCount() const
 
	{
 
		return this->count;
 
	}
 

	
 
	/**
 
	 * Gets the number of visible elements of the scrollbar
 
	 * @return the number of visible elements
 
	 */
 
	FORCEINLINE uint16 GetCapacity() const
 
	inline uint16 GetCapacity() const
 
	{
 
		return this->cap;
 
	}
 

	
 
	/**
 
	 * Gets the position of the first visible element in the list
 
	 * @return the position of the element
 
	 */
 
	FORCEINLINE uint16 GetPosition() const
 
	inline uint16 GetPosition() const
 
	{
 
		return this->pos;
 
	}
 

	
 
	/**
 
	 * Checks whether given current item is visible in the list
 
	 * @param item to check
 
	 * @return true iff the item is visible
 
	 */
 
	FORCEINLINE bool IsVisible(uint16 item) const
 
	inline bool IsVisible(uint16 item) const
 
	{
 
		return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
 
	}
 

	
 
	/**
 
	 * Is the scrollbar vertical or not?
 
	 * @return True iff the scrollbar is vertical.
 
	 */
 
	FORCEINLINE bool IsVertical() const
 
	inline bool IsVertical() const
 
	{
 
		return this->is_vertical;
 
	}
 

	
 
	/**
 
	 * Set the distance to scroll when using the buttons or the wheel.
 
@@ -786,13 +786,13 @@ private:
 
 * Return the biggest possible size of a nested widget.
 
 * @param base      Base size of the widget.
 
 * @param max_space Available space for the widget.
 
 * @param step      Stepsize of the widget.
 
 * @return Biggest possible size of the widget, assuming that \a base may only be incremented by \a step size steps.
 
 */
 
static FORCEINLINE uint ComputeMaxSize(uint base, uint max_space, uint step)
 
static inline uint ComputeMaxSize(uint base, uint max_space, uint step)
 
{
 
	if (base >= max_space || step == 0) return base;
 
	if (step == 1) return max_space;
 
	uint increment = max_space - base;
 
	increment -= increment % step;
 
	return base + increment;
src/window_gui.h
Show inline comments
 
@@ -260,23 +260,23 @@ public:
 
	/**
 
	 * Helper allocation function to disallow something.
 
	 * Don't allow arrays; arrays of Windows are pointless as you need
 
	 * to destruct them all at the same time too, which is kinda hard.
 
	 * @param size the amount of space not to allocate
 
	 */
 
	FORCEINLINE void *operator new[](size_t size)
 
	inline void *operator new[](size_t size)
 
	{
 
		NOT_REACHED();
 
	}
 

	
 
	/**
 
	 * Helper allocation function to disallow something.
 
	 * Don't free the window directly; it corrupts the linked list when iterating
 
	 * @param ptr the pointer not to free
 
	 */
 
	FORCEINLINE void operator delete(void *ptr)
 
	inline void operator delete(void *ptr)
 
	{
 
	}
 

	
 
	WindowFlags flags;          ///< Window flags
 
	WindowClass window_class;   ///< Window class
 
	WindowNumber window_number; ///< Window number within the window class
0 comments (0 inline, 0 general)