Merge branch 'save_ext' into tracerestrict-sx

Conflicts:
	src/pathfinder/yapf/yapf_costrail.hpp
pull/3/head
Jonathan G Rennison 9 years ago
commit a48652ac6f

@ -29,6 +29,7 @@ set_default() {
strip="" strip=""
lipo="" lipo=""
awk="awk" awk="awk"
pkg_config="pkg-config"
os="DETECT" os="DETECT"
endian="AUTO" endian="AUTO"
cpu_type="DETECT" cpu_type="DETECT"
@ -105,6 +106,7 @@ set_default() {
strip strip
lipo lipo
awk awk
pkg_config
os os
endian endian
cpu_type cpu_type
@ -213,6 +215,8 @@ detect_params() {
--windres=*) windres="$optarg";; --windres=*) windres="$optarg";;
--awk) prev_p="awk";; --awk) prev_p="awk";;
--awk=*) awk="$optarg";; --awk=*) awk="$optarg";;
--pkg-config) prev_p="pkg_config";;
--pkg-config=*) pkg_config="$optarg";;
--strip) prev_p="strip";; --strip) prev_p="strip";;
--strip=*) strip="$optarg";; --strip=*) strip="$optarg";;
--lipo) prev_p="lipo";; --lipo) prev_p="lipo";;
@ -1938,9 +1942,26 @@ check_compiler() {
log 2 " exit code $ret" log 2 " exit code $ret"
if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
log 1 "checking $1... $compiler not found" if [ -z "$5" ]; then
log 1 "I couldn't detect any $6 binary for $3" log 1 "checking $1... $compiler not found"
exit 1 log 1 "I couldn't detect any $6 binary for $3"
exit 1
else
compiler="$3-$5"
fi
machine=`eval $compiler $9 2>/dev/null`
ret=$?
eval "$2=\"$compiler\""
log 2 "executing $compiler $9"
log 2 " returned $machine"
log 2 " exit code $ret"
if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
log 1 "checking $1... $compiler not found"
log 1 "I couldn't detect any $5 binary for $3"
exit 1
fi
fi fi
if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
@ -2736,7 +2757,7 @@ detect_pkg_config() {
log 2 "detecting $2" log 2 "detecting $2"
if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
pkg_config_call="pkg-config $2" pkg_config_call="$pkg_config $2"
else else
pkg_config_call="$1" pkg_config_call="$1"
fi fi
@ -2758,7 +2779,7 @@ detect_pkg_config() {
# It was forced, so it should be found. # It was forced, so it should be found.
if [ "$1" != "1" ]; then if [ "$1" != "1" ]; then
log 1 "configure: error: pkg-config $2 couldn't be found" log 1 "configure: error: $pkg_config $2 couldn't be found"
log 1 "configure: error: you supplied '$1', but it seems invalid" log 1 "configure: error: you supplied '$1', but it seems invalid"
exit 1 exit 1
fi fi
@ -3588,6 +3609,7 @@ showhelp() {
echo " --windres=WINDRES the windres to use [HOST-windres]" echo " --windres=WINDRES the windres to use [HOST-windres]"
echo " --strip=STRIP the strip to use [HOST-strip]" echo " --strip=STRIP the strip to use [HOST-strip]"
echo " --awk=AWK the awk to use in configure [awk]" echo " --awk=AWK the awk to use in configure [awk]"
echo " --pkg-config=PKG-CONFIG the pkg-config to use in configure [pkg-config]"
echo " --lipo=LIPO the lipo to use (OSX ONLY) [HOST-lipo]" echo " --lipo=LIPO the lipo to use (OSX ONLY) [HOST-lipo]"
echo " --os=OS the OS we are compiling for [DETECT]" echo " --os=OS the OS we are compiling for [DETECT]"
echo " DETECT/UNIX/OSX/FREEBSD/DRAGONFLY/OPENBSD/" echo " DETECT/UNIX/OSX/FREEBSD/DRAGONFLY/OPENBSD/"

@ -1390,7 +1390,7 @@ STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT :Ropné rafineri
STR_CONFIG_SETTING_SNOWLINE_HEIGHT :Výška sněhové čáry: {STRING} STR_CONFIG_SETTING_SNOWLINE_HEIGHT :Výška sněhové čáry: {STRING}
STR_CONFIG_SETTING_SNOWLINE_HEIGHT_HELPTEXT :Určuje o jaké výšky se vyskytuje sníh u subarktického klimatu. Sníh rovněž ovlivňuje vytváření průmyslu a požadavky na růst měst STR_CONFIG_SETTING_SNOWLINE_HEIGHT_HELPTEXT :Určuje o jaké výšky se vyskytuje sníh u subarktického klimatu. Sníh rovněž ovlivňuje vytváření průmyslu a požadavky na růst měst
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN :Členitost krajiny: {STRING} STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN :Členitost krajiny: {STRING}
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT :(Pouze TerraGenesis) Zvol množství hor: Rovinatý terén má méně hor, které jsou však rozlehlejší. Členitý terén má mnoho hor, u kterých se může zdát, že se upakují STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT :(Pouze TerraGenesis) Zvol množství hor: Rovinatý terén má méně hor, které jsou však rozlehlejší. Členitý terén má mnoho hor, u kterých se může zdát, že se opakují
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH :velmi rovná STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH :velmi rovná
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH :rovná STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH :rovná
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH :členitá STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH :členitá

@ -1143,7 +1143,7 @@ STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN :Maximale beginl
STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximale bedrag een bedrijf kan lenen (zonder rekening te houden met de inflatie) STR_CONFIG_SETTING_MAXIMUM_INITIAL_LOAN_HELPTEXT :Maximale bedrag een bedrijf kan lenen (zonder rekening te houden met de inflatie)
STR_CONFIG_SETTING_INTEREST_RATE :Rente van lening: {STRING} STR_CONFIG_SETTING_INTEREST_RATE :Rente van lening: {STRING}
STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :Percentage rente op lening; bepaald ook het inflatiecijfer wanneer ingeschakeld STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :Percentage rente op lening; bepaald ook het inflatiecijfer wanneer ingeschakeld
STR_CONFIG_SETTING_RUNNING_COSTS :Brandstofkosten: {STRING} STR_CONFIG_SETTING_RUNNING_COSTS :Onderhoudskosten: {STRING}
STR_CONFIG_SETTING_RUNNING_COSTS_HELPTEXT :Het niveau van onderhoud en bedrijfskosten van voertuigen en infrastuctuur STR_CONFIG_SETTING_RUNNING_COSTS_HELPTEXT :Het niveau van onderhoud en bedrijfskosten van voertuigen en infrastuctuur
STR_CONFIG_SETTING_CONSTRUCTION_SPEED :Bouwsnelheid: {STRING} STR_CONFIG_SETTING_CONSTRUCTION_SPEED :Bouwsnelheid: {STRING}
STR_CONFIG_SETTING_CONSTRUCTION_SPEED_HELPTEXT :Beperk de hoeveelheid bouwactiviteiten voor computerspeler STR_CONFIG_SETTING_CONSTRUCTION_SPEED_HELPTEXT :Beperk de hoeveelheid bouwactiviteiten voor computerspeler
@ -3184,16 +3184,16 @@ STR_FINANCES_EXPENDITURE_INCOME_TITLE :{WHITE}Uitgaven
STR_FINANCES_YEAR :{WHITE}{NUM} STR_FINANCES_YEAR :{WHITE}{NUM}
STR_FINANCES_SECTION_CONSTRUCTION :{GOLD}Bouwkosten STR_FINANCES_SECTION_CONSTRUCTION :{GOLD}Bouwkosten
STR_FINANCES_SECTION_NEW_VEHICLES :{GOLD}Nieuwe voertuigen STR_FINANCES_SECTION_NEW_VEHICLES :{GOLD}Nieuwe voertuigen
STR_FINANCES_SECTION_TRAIN_RUNNING_COSTS :{GOLD}Treinbrandstofkosten STR_FINANCES_SECTION_TRAIN_RUNNING_COSTS :{GOLD}Treinonderhoudskosten
STR_FINANCES_SECTION_ROAD_VEHICLE_RUNNING_COSTS :{GOLD}Wegvoertuigbrandstofkosten STR_FINANCES_SECTION_ROAD_VEHICLE_RUNNING_COSTS :{GOLD}Wegvoertuigbrandstofkosten
STR_FINANCES_SECTION_AIRCRAFT_RUNNING_COSTS :{GOLD}Vliegtuigbrandstofkosten STR_FINANCES_SECTION_AIRCRAFT_RUNNING_COSTS :{GOLD}Vliegtuigonderhoudskosten
STR_FINANCES_SECTION_SHIP_RUNNING_COSTS :{GOLD}Schipbrandstofkosten STR_FINANCES_SECTION_SHIP_RUNNING_COSTS :{GOLD}Schiponderhoudskosten
STR_FINANCES_SECTION_PROPERTY_MAINTENANCE :{GOLD}Eigendomsonderhoud STR_FINANCES_SECTION_PROPERTY_MAINTENANCE :{GOLD}Eigendomsonderhoud
STR_FINANCES_SECTION_TRAIN_INCOME :{GOLD}Treininkomsten STR_FINANCES_SECTION_TRAIN_INCOME :{GOLD}Treininkomsten
STR_FINANCES_SECTION_ROAD_VEHICLE_INCOME :{GOLD}Wegvoertuiginkomsten STR_FINANCES_SECTION_ROAD_VEHICLE_INCOME :{GOLD}Wegvoertuiginkomsten
STR_FINANCES_SECTION_AIRCRAFT_INCOME :{GOLD}Vliegtuiginkomsten STR_FINANCES_SECTION_AIRCRAFT_INCOME :{GOLD}Vliegtuiginkomsten
STR_FINANCES_SECTION_SHIP_INCOME :{GOLD}Schipinkomsten STR_FINANCES_SECTION_SHIP_INCOME :{GOLD}Schipinkomsten
STR_FINANCES_SECTION_LOAN_INTEREST :{GOLD}Rente van lening STR_FINANCES_SECTION_LOAN_INTEREST :{GOLD} De rente van de lening
STR_FINANCES_SECTION_OTHER :{GOLD}Overig STR_FINANCES_SECTION_OTHER :{GOLD}Overig
STR_FINANCES_NEGATIVE_INCOME :{BLACK}-{CURRENCY_LONG} STR_FINANCES_NEGATIVE_INCOME :{BLACK}-{CURRENCY_LONG}
STR_FINANCES_POSITIVE_INCOME :{BLACK}+{CURRENCY_LONG} STR_FINANCES_POSITIVE_INCOME :{BLACK}+{CURRENCY_LONG}
@ -3598,12 +3598,12 @@ STR_VEHICLE_VIEW_SHIP_REFIT_TOOLTIP :{BLACK}Bouw sch
STR_VEHICLE_VIEW_AIRCRAFT_REFIT_TOOLTIP :{BLACK}Bouw vliegtuig om voor een ander goederentype STR_VEHICLE_VIEW_AIRCRAFT_REFIT_TOOLTIP :{BLACK}Bouw vliegtuig om voor een ander goederentype
STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP :{BLACK}Keer trein om STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP :{BLACK}Keer trein om
STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP :{BLACK}Dwing het wegvoertuig om om te draaien STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP :{BLACK}Dwing het wegvoertuig te keren.
STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP :{BLACK}Toon orders van trein. Ctrl+klik toont het tijdschema van de trein STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP :{BLACK}Toon orders van de trein. Ctrl+klik toont het tijdschema van de trein
STR_VEHICLE_VIEW_ROAD_VEHICLE_ORDERS_TOOLTIP :{BLACK}Toon orders van wegvoertuig. Ctrl+klik toont tijdschema van het voertuig STR_VEHICLE_VIEW_ROAD_VEHICLE_ORDERS_TOOLTIP :{BLACK}Toon orders van het wegvoertuig. Ctrl+klik toont tijdschema van het voertuig
STR_VEHICLE_VIEW_SHIP_ORDERS_TOOLTIP :{BLACK}Toon orders van schip. Ctrl+klik toont tijdschema van het schip STR_VEHICLE_VIEW_SHIP_ORDERS_TOOLTIP :{BLACK}Toon orders van het schip. Ctrl+klik toont tijdschema van het schip
STR_VEHICLE_VIEW_AIRCRAFT_ORDERS_TOOLTIP :{BLACK}Toon orders van vliegtuig. Ctrl+klik toont het tijdschema van het vliegtuig STR_VEHICLE_VIEW_AIRCRAFT_ORDERS_TOOLTIP :{BLACK}Toon orders van het vliegtuig. Ctrl+klik toont het tijdschema van het vliegtuig
STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP :{BLACK}Toon details van trein STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP :{BLACK}Toon details van trein
STR_VEHICLE_VIEW_ROAD_VEHICLE_SHOW_DETAILS_TOOLTIP :{BLACK}Toon details van wegvoertuig STR_VEHICLE_VIEW_ROAD_VEHICLE_SHOW_DETAILS_TOOLTIP :{BLACK}Toon details van wegvoertuig
@ -4153,9 +4153,9 @@ STR_ERROR_MAXIMUM_PERMITTED_LOAN :{WHITE}... maxi
STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY :{WHITE}Kan geen geld meer lenen... STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY :{WHITE}Kan geen geld meer lenen...
STR_ERROR_LOAN_ALREADY_REPAYED :{WHITE}... geen lening om af te betalen STR_ERROR_LOAN_ALREADY_REPAYED :{WHITE}... geen lening om af te betalen
STR_ERROR_CURRENCY_REQUIRED :{WHITE}... {CURRENCY_LONG} benodigd STR_ERROR_CURRENCY_REQUIRED :{WHITE}... {CURRENCY_LONG} benodigd
STR_ERROR_CAN_T_REPAY_LOAN :{WHITE}Kan geen lening afbetalen... STR_ERROR_CAN_T_REPAY_LOAN :{WHITE}Kan de lening niet afbetalen..
STR_ERROR_INSUFFICIENT_FUNDS :{WHITE}Kan geen geld weggeven dat van de bank geleend is... STR_ERROR_INSUFFICIENT_FUNDS :{WHITE}Kan geen geld weggeven dat van de bank geleend is...
STR_ERROR_CAN_T_BUY_COMPANY :{WHITE}Kan bedrijf niet kopen... STR_ERROR_CAN_T_BUY_COMPANY :{WHITE}Kan het bedrijf niet kopen...
STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS :{WHITE}Kan bedrijfshoofdkantoor niet bouwen... STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS :{WHITE}Kan bedrijfshoofdkantoor niet bouwen...
STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS :{WHITE}Kan geen 25% aandeel in dit bedrijf kopen... STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS :{WHITE}Kan geen 25% aandeel in dit bedrijf kopen...
STR_ERROR_CAN_T_SELL_25_SHARE_IN :{WHITE}Kan geen 25% aandeel in dit bedrijf verkopen... STR_ERROR_CAN_T_SELL_25_SHARE_IN :{WHITE}Kan geen 25% aandeel in dit bedrijf verkopen...

@ -3848,7 +3848,7 @@ STR_ORDER_NO_LOAD :(Ingen lastning
STR_ORDER_UNLOAD :(Lasta av och lasta gods) STR_ORDER_UNLOAD :(Lasta av och lasta gods)
STR_ORDER_UNLOAD_FULL_LOAD :(Lasta av och vänta på full last) STR_ORDER_UNLOAD_FULL_LOAD :(Lasta av och vänta på full last)
STR_ORDER_UNLOAD_FULL_LOAD_ANY :(Lasta av och vänta på någon full last) STR_ORDER_UNLOAD_FULL_LOAD_ANY :(Lasta av och vänta på någon full last)
STR_ORDER_UNLOAD_NO_LOAD :(Ladda av och lämna tom) STR_ORDER_UNLOAD_NO_LOAD :(Lasta av och lämna tom)
STR_ORDER_TRANSFER :(Överför och lasta gods) STR_ORDER_TRANSFER :(Överför och lasta gods)
STR_ORDER_TRANSFER_FULL_LOAD :(Överför och vänta på full last) STR_ORDER_TRANSFER_FULL_LOAD :(Överför och vänta på full last)
STR_ORDER_TRANSFER_FULL_LOAD_ANY :(Överför och vänta på full last av någon godstyp) STR_ORDER_TRANSFER_FULL_LOAD_ANY :(Överför och vänta på full last av någon godstyp)

@ -34,7 +34,7 @@ protected:
{ {
uint super_size = data.Length(); uint super_size = data.Length();
if (super_size > 0) { if (super_size > 0) {
SubArray& s = data[super_size - 1]; SubArray &s = data[super_size - 1];
if (!s.IsFull()) return s; if (!s.IsFull()) return s;
} }
return *data.AppendC(); return *data.AppendC();
@ -42,9 +42,16 @@ protected:
public: public:
/** implicit constructor */ /** implicit constructor */
inline SmallArray() { } inline SmallArray()
{
}
/** Clear (destroy) all items */ /** Clear (destroy) all items */
inline void Clear() {data.Clear();} inline void Clear()
{
data.Clear();
}
/** Return actual number of items */ /** Return actual number of items */
inline uint Length() const inline uint Length() const
{ {
@ -54,25 +61,41 @@ public:
return (super_size - 1) * B + sub_size; return (super_size - 1) * B + sub_size;
} }
/** return true if array is empty */ /** return true if array is empty */
inline bool IsEmpty() { return data.IsEmpty(); } inline bool IsEmpty()
{
return data.IsEmpty();
}
/** return true if array is full */ /** return true if array is full */
inline 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 */ /** allocate but not construct new item */
inline T *Append() { return FirstFreeSubArray().Append(); } inline T *Append()
{
return FirstFreeSubArray().Append();
}
/** allocate and construct new item */ /** allocate and construct new item */
inline T *AppendC() { return FirstFreeSubArray().AppendC(); } inline T *AppendC()
{
return FirstFreeSubArray().AppendC();
}
/** indexed access (non-const) */ /** indexed access (non-const) */
inline T& operator [] (uint index) inline T& operator[](uint index)
{ {
const SubArray& s = data[index / B]; const SubArray &s = data[index / B];
T& item = s[index % B]; T &item = s[index % B];
return item; return item;
} }
/** indexed access (const) */ /** indexed access (const) */
inline const T& operator [] (uint index) const inline const T& operator[](uint index) const
{ {
const SubArray& s = data[index / B]; const SubArray &s = data[index / B];
const T& item = s[index % B]; const T &item = s[index % B];
return item; return item;
} }
@ -87,7 +110,7 @@ public:
dmp.WriteLine("num_items = %d", num_items); dmp.WriteLine("num_items = %d", num_items);
CStrA name; CStrA name;
for (uint i = 0; i < num_items; i++) { for (uint i = 0; i < num_items; i++) {
const T& item = (*this)[i]; const T &item = (*this)[i];
name.Format("item[%d]", i); name.Format("item[%d]", i);
dmp.WriteStructT(name.Data(), &item); dmp.WriteStructT(name.Data(), &item);
} }

@ -157,21 +157,30 @@ public:
* *
* @return The number of items in the queue * @return The number of items in the queue
*/ */
inline uint Length() const { return this->items; } inline uint Length() const
{
return this->items;
}
/** /**
* Test if the priority queue is empty. * Test if the priority queue is empty.
* *
* @return True if empty * @return True if empty
*/ */
inline bool IsEmpty() const { return this->items == 0; } inline bool IsEmpty() const
{
return this->items == 0;
}
/** /**
* Test if the priority queue is full. * Test if the priority queue is full.
* *
* @return True if full. * @return True if full.
*/ */
inline 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. * Get the smallest item in the binary tree.
@ -287,7 +296,10 @@ public:
* Make the priority queue empty. * Make the priority queue empty.
* All remaining items will remain untouched. * All remaining items will remain untouched.
*/ */
inline void Clear() { this->items = 0; } inline void Clear()
{
this->items = 0;
}
}; };
#endif /* BINARYHEAP_HPP */ #endif /* BINARYHEAP_HPP */

@ -71,7 +71,10 @@ public:
static const size_t header_size = sizeof(BlobHeader); static const size_t header_size = sizeof(BlobHeader);
/** default constructor - initializes empty blob */ /** default constructor - initializes empty blob */
inline ByteBlob() { InitEmpty(); } inline ByteBlob()
{
InitEmpty();
}
/** copy constructor */ /** copy constructor */
inline ByteBlob(const ByteBlob &src) inline ByteBlob(const ByteBlob &src)
@ -311,9 +314,22 @@ public:
struct OnTransfer { struct OnTransfer {
typename base::BlobHeader *header; typename base::BlobHeader *header;
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(const OnTransfer& src) : header(src.header)
~OnTransfer() {assert(header == NULL);} {
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 */ /** Default constructor - makes new Blob ready to accept any data */

@ -35,60 +35,118 @@ protected:
public: public:
/** default (NULL) construct or construct from a raw pointer */ /** default (NULL) construct or construct from a raw pointer */
inline 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) */ /** copy constructor (invoked also when initializing from another smart ptr) */
inline 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 */ /** destructor releasing the reference */
inline ~CCountedPtr() {Release();} inline ~CCountedPtr()
{
Release();
}
protected: protected:
/** add one ref to the underlaying object */ /** add one ref to the underlaying object */
inline void AddRef() {if (m_pT != NULL) m_pT->AddRef();} inline void AddRef()
{
if (m_pT != NULL) m_pT->AddRef();
}
public: public:
/** release smart pointer (and decrement ref count) if not null */ /** release smart pointer (and decrement ref count) if not null */
inline 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 */ /** dereference of smart pointer - const way */
inline 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 */ /** dereference of smart pointer - non const way */
inline 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 */ /** raw pointer casting operator - const way */
inline 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 */ /** raw pointer casting operator - non-const way */
inline operator Tcls*() {return m_pT;} inline operator Tcls*()
{
return m_pT;
}
/** operator & to support output arguments */ /** operator & to support output arguments */
inline Tcls** operator &() {assert(m_pT == NULL); return &m_pT;} inline Tcls** operator&()
{
assert(m_pT == NULL);
return &m_pT;
}
/** assignment operator from raw ptr */ /** assignment operator from raw ptr */
inline CCountedPtr& operator = (Tcls *pT) {Assign(pT); return *this;} inline CCountedPtr& operator=(Tcls *pT)
{
Assign(pT);
return *this;
}
/** assignment operator from another smart ptr */ /** assignment operator from another smart ptr */
inline 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 */ /** assignment operator helper */
inline void Assign(Tcls *pT); inline void Assign(Tcls *pT);
/** one way how to test for NULL value */ /** one way how to test for NULL value */
inline bool IsNull() const {return m_pT == NULL;} inline bool IsNull() const
{
return m_pT == NULL;
}
/** another way how to test for NULL value */ /** another way how to test for NULL value */
//inline 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 */ /** yet another way how to test for NULL value */
//inline 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 */ /** assign pointer w/o incrementing ref count */
inline void Attach(Tcls *pT) {Release(); m_pT = pT;} inline void Attach(Tcls *pT)
{
Release();
m_pT = pT;
}
/** detach pointer w/o decrementing ref count */ /** detach pointer w/o decrementing ref count */
inline 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_> template <class Tcls_>
@ -136,7 +194,6 @@ template <class T> struct AdaptT {
} }
}; };
/** /**
* Simple counted object. Use it as base of your struct/class if you want to use * Simple counted object. Use it as base of your struct/class if you want to use
* basic reference counting. Your struct/class will destroy and free itself when * basic reference counting. Your struct/class will destroy and free itself when
@ -161,7 +218,4 @@ struct SimpleCountedObject {
virtual void FinalRelease() {}; virtual void FinalRelease() {};
}; };
#endif /* COUNTEDPTR_HPP */ #endif /* COUNTEDPTR_HPP */

@ -111,7 +111,7 @@ struct DumpTarget {
m_ptr = src.m_ptr; m_ptr = src.m_ptr;
} }
bool operator < (const KnownStructKey &other) const bool operator<(const KnownStructKey &other) const
{ {
if ((size_t)m_ptr < (size_t)other.m_ptr) return true; if ((size_t)m_ptr < (size_t)other.m_ptr) return true;
if ((size_t)m_ptr > (size_t)other.m_ptr) return false; if ((size_t)m_ptr > (size_t)other.m_ptr) return false;

@ -41,13 +41,28 @@ protected:
T *data; T *data;
/** return reference to the array header (non-const) */ /** return reference to the array header (non-const) */
inline ArrayHeader& Hdr() { return *(ArrayHeader*)(((byte*)data) - HeaderSize); } inline ArrayHeader& Hdr()
{
return *(ArrayHeader*)(((byte*)data) - HeaderSize);
}
/** return reference to the array header (const) */ /** return reference to the array header (const) */
inline 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 */ /** return reference to the block reference counter */
inline uint& RefCnt() { return Hdr().reference_count; } inline uint& RefCnt()
{
return Hdr().reference_count;
}
/** return reference to number of used items */ /** return reference to number of used items */
inline uint& SizeRef() { return Hdr().items; } inline uint& SizeRef()
{
return Hdr().items;
}
public: public:
/** Default constructor. Preallocate space for items and header, then initialize header. */ /** Default constructor. Preallocate space for items and header, then initialize header. */
@ -63,7 +78,7 @@ public:
} }
/** Copy constructor. Preallocate space for items and header, then initialize header. */ /** Copy constructor. Preallocate space for items and header, then initialize header. */
FixedSizeArray(const FixedSizeArray<T, C>& src) FixedSizeArray(const FixedSizeArray<T, C> &src)
{ {
/* share block (header + items) with the source array */ /* share block (header + items) with the source array */
data = src.data; data = src.data;
@ -96,19 +111,50 @@ public:
} }
/** return number of used items */ /** return number of used items */
inline uint Length() const { return Hdr().items; } inline uint Length() const
{
return Hdr().items;
}
/** return true if array is full */ /** return true if array is full */
inline bool IsFull() const { return Length() >= C; } inline bool IsFull() const
{
return Length() >= C;
}
/** return true if array is empty */ /** return true if array is empty */
inline bool IsEmpty() const { return Length() <= 0; } inline bool IsEmpty() const
{
return Length() <= 0;
}
/** add (allocate), but don't construct item */ /** add (allocate), but don't construct item */
inline T *Append() { assert(!IsFull()); return &data[SizeRef()++]; } inline T *Append()
{
assert(!IsFull());
return &data[SizeRef()++];
}
/** add and construct item using default constructor */ /** add and construct item using default constructor */
inline 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) */ /** return item by index (non-const version) */
inline 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) */ /** return item by index (const version) */
inline 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 */ #endif /* FIXEDSIZEARRAY_HPP */

@ -24,10 +24,13 @@ struct CHashTableSlotT
inline CHashTableSlotT() : m_pFirst(NULL) {} inline CHashTableSlotT() : m_pFirst(NULL) {}
/** hash table slot helper - clears the slot by simple forgetting its items */ /** hash table slot helper - clears the slot by simple forgetting its items */
inline 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 */ /** hash table slot helper - linear search for item with given key through the given blob - const version */
inline 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()) { for (const Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) {
if (pItem->GetKey() == key) { if (pItem->GetKey() == key) {
@ -39,7 +42,7 @@ struct CHashTableSlotT
} }
/** hash table slot helper - linear search for item with given key through the given blob - non-const version */ /** hash table slot helper - linear search for item with given key through the given blob - non-const version */
inline Titem_ *Find(const Key& key) inline Titem_ *Find(const Key &key)
{ {
for (Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) { for (Titem_ *pItem = m_pFirst; pItem != NULL; pItem = pItem->GetHashNext()) {
if (pItem->GetKey() == key) { if (pItem->GetKey() == key) {
@ -51,7 +54,7 @@ struct CHashTableSlotT
} }
/** hash table slot helper - add new item to the slot */ /** hash table slot helper - add new item to the slot */
inline void Attach(Titem_& new_item) inline void Attach(Titem_ &new_item)
{ {
assert(new_item.GetHashNext() == NULL); assert(new_item.GetHashNext() == NULL);
new_item.SetHashNext(m_pFirst); new_item.SetHashNext(m_pFirst);
@ -59,7 +62,7 @@ struct CHashTableSlotT
} }
/** hash table slot helper - remove item from a slot */ /** hash table slot helper - remove item from a slot */
inline bool Detach(Titem_& item_to_remove) inline bool Detach(Titem_ &item_to_remove)
{ {
if (m_pFirst == &item_to_remove) { if (m_pFirst == &item_to_remove) {
m_pFirst = item_to_remove.GetHashNext(); m_pFirst = item_to_remove.GetHashNext();
@ -81,7 +84,7 @@ struct CHashTableSlotT
} }
/** hash table slot helper - remove and return item from a slot */ /** hash table slot helper - remove and return item from a slot */
inline Titem_ *Detach(const Key& key) inline Titem_ *Detach(const Key &key)
{ {
/* do we have any items? */ /* do we have any items? */
if (m_pFirst == NULL) { if (m_pFirst == NULL) {
@ -89,7 +92,7 @@ struct CHashTableSlotT
} }
/* is it our first item? */ /* is it our first item? */
if (m_pFirst->GetKey() == key) { if (m_pFirst->GetKey() == key) {
Titem_& ret_item = *m_pFirst; Titem_ &ret_item = *m_pFirst;
m_pFirst = m_pFirst->GetHashNext(); m_pFirst = m_pFirst->GetHashNext();
ret_item.SetHashNext(NULL); ret_item.SetHashNext(NULL);
return &ret_item; return &ret_item;
@ -128,7 +131,7 @@ struct CHashTableSlotT
* - public method that calculates key's hash: * - public method that calculates key's hash:
* int CalcHash() const; * int CalcHash() const;
* - public 'equality' operator to compare the key with another one * - public 'equality' operator to compare the key with another one
* bool operator == (const Key& other) const; * bool operator==(const Key &other) const;
*/ */
template <class Titem_, int Thash_bits_> template <class Titem_, int Thash_bits_>
class CHashTableT { class CHashTableT {
@ -156,7 +159,7 @@ public:
protected: protected:
/** static helper - return hash for the given key modulo number of slots */ /** static helper - return hash for the given key modulo number of slots */
inline static int CalcHash(const Tkey& key) inline static int CalcHash(const Tkey &key)
{ {
int32 hash = key.CalcHash(); int32 hash = key.CalcHash();
if ((8 * Thash_bits) < 32) hash ^= hash >> (min(8 * Thash_bits, 31)); if ((8 * Thash_bits) < 32) hash ^= hash >> (min(8 * Thash_bits, 31));
@ -168,38 +171,47 @@ protected:
} }
/** static helper - return hash for the given item modulo number of slots */ /** static helper - return hash for the given item modulo number of slots */
inline static int CalcHash(const Titem_& item) {return CalcHash(item.GetKey());} inline static int CalcHash(const Titem_ &item)
{
return CalcHash(item.GetKey());
}
public: public:
/** item count */ /** item count */
inline int Count() const {return m_num_items;} inline int Count() const
{
return m_num_items;
}
/** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */ /** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */
inline 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 item search */
const Titem_ *Find(const Tkey& key) const const Titem_ *Find(const Tkey &key) const
{ {
int hash = CalcHash(key); int hash = CalcHash(key);
const Slot& slot = m_slots[hash]; const Slot &slot = m_slots[hash];
const Titem_ *item = slot.Find(key); const Titem_ *item = slot.Find(key);
return item; return item;
} }
/** non-const item search */ /** non-const item search */
Titem_ *Find(const Tkey& key) Titem_ *Find(const Tkey &key)
{ {
int hash = CalcHash(key); int hash = CalcHash(key);
Slot& slot = m_slots[hash]; Slot &slot = m_slots[hash];
Titem_ *item = slot.Find(key); Titem_ *item = slot.Find(key);
return item; return item;
} }
/** non-const item search & optional removal (if found) */ /** non-const item search & optional removal (if found) */
Titem_ *TryPop(const Tkey& key) Titem_ *TryPop(const Tkey &key)
{ {
int hash = CalcHash(key); int hash = CalcHash(key);
Slot& slot = m_slots[hash]; Slot &slot = m_slots[hash];
Titem_ *item = slot.Detach(key); Titem_ *item = slot.Detach(key);
if (item != NULL) { if (item != NULL) {
m_num_items--; m_num_items--;
@ -208,7 +220,7 @@ public:
} }
/** non-const item search & removal */ /** non-const item search & removal */
Titem_& Pop(const Tkey& key) Titem_& Pop(const Tkey &key)
{ {
Titem_ *item = TryPop(key); Titem_ *item = TryPop(key);
assert(item != NULL); assert(item != NULL);
@ -216,11 +228,11 @@ public:
} }
/** non-const item search & optional removal (if found) */ /** non-const item search & optional removal (if found) */
bool TryPop(Titem_& item) bool TryPop(Titem_ &item)
{ {
const Tkey& key = item.GetKey(); const Tkey &key = item.GetKey();
int hash = CalcHash(key); int hash = CalcHash(key);
Slot& slot = m_slots[hash]; Slot &slot = m_slots[hash];
bool ret = slot.Detach(item); bool ret = slot.Detach(item);
if (ret) { if (ret) {
m_num_items--; m_num_items--;
@ -229,17 +241,17 @@ public:
} }
/** non-const item search & removal */ /** non-const item search & removal */
void Pop(Titem_& item) void Pop(Titem_ &item)
{ {
bool ret = TryPop(item); bool ret = TryPop(item);
assert(ret); assert(ret);
} }
/** add one item - copy it from the given item */ /** add one item - copy it from the given item */
void Push(Titem_& new_item) void Push(Titem_ &new_item)
{ {
int hash = CalcHash(new_item); int hash = CalcHash(new_item);
Slot& slot = m_slots[hash]; Slot &slot = m_slots[hash];
assert(slot.Find(new_item.GetKey()) == NULL); assert(slot.Find(new_item.GetKey()) == NULL);
slot.Attach(new_item); slot.Attach(new_item);
m_num_items++; m_num_items++;

@ -35,7 +35,7 @@ struct CStrA : public CBlobT<char>
} }
/** Take over ownership constructor */ /** Take over ownership constructor */
inline CStrA(const OnTransfer& ot) inline CStrA(const OnTransfer &ot)
: base(ot) : base(ot)
{ {
} }
@ -67,7 +67,7 @@ struct CStrA : public CBlobT<char>
} }
/** Assignment from C string. */ /** Assignment from C string. */
inline CStrA &operator = (const char *src) inline CStrA &operator=(const char *src)
{ {
base::Clear(); base::Clear();
AppendStr(src); AppendStr(src);
@ -75,7 +75,7 @@ struct CStrA : public CBlobT<char>
} }
/** Assignment from another CStrA. */ /** Assignment from another CStrA. */
inline CStrA &operator = (const CStrA &src) inline CStrA &operator=(const CStrA &src)
{ {
if (&src != this) { if (&src != this) {
base::Clear(); base::Clear();
@ -86,7 +86,7 @@ struct CStrA : public CBlobT<char>
} }
/** Lower-than operator (to support stl collections) */ /** Lower-than operator (to support stl collections) */
inline bool operator < (const CStrA &other) const inline bool operator<(const CStrA &other) const
{ {
return strcmp(base::Data(), other.Data()) < 0; return strcmp(base::Data(), other.Data()) < 0;
} }

@ -24,34 +24,23 @@
template <class Titem_, int Thash_bits_open_, int Thash_bits_closed_> template <class Titem_, int Thash_bits_open_, int Thash_bits_closed_>
class CNodeList_HashTableT { class CNodeList_HashTableT {
public: public:
/** make Titem_ visible from outside of class */ typedef Titem_ Titem; ///< Make #Titem_ visible from outside of class.
typedef Titem_ Titem; typedef typename Titem_::Key Key; ///< Make Titem_::Key a property of #HashTable.
/** make Titem_::Key a property of HashTable */ typedef SmallArray<Titem_, 65536, 256> CItemArray; ///< Type that we will use as item container.
typedef typename Titem_::Key Key; typedef CHashTableT<Titem_, Thash_bits_open_ > COpenList; ///< How pointers to open nodes will be stored.
/** type that we will use as item container */ typedef CHashTableT<Titem_, Thash_bits_closed_> CClosedList; ///< How pointers to closed nodes will be stored.
typedef SmallArray<Titem_, 65536, 256> CItemArray; typedef CBinaryHeapT<Titem_> CPriorityQueue; ///< How the priority queue will be managed.
/** how pointers to open nodes will be stored */
typedef CHashTableT<Titem_, Thash_bits_open_ > COpenList;
/** how pointers to closed nodes will be stored */
typedef CHashTableT<Titem_, Thash_bits_closed_> CClosedList;
/** how the priority queue will be managed */
typedef CBinaryHeapT<Titem_> CPriorityQueue;
protected: protected:
/** here we store full item data (Titem_) */ CItemArray m_arr; ///< Here we store full item data (Titem_).
CItemArray m_arr; COpenList m_open; ///< Hash table of pointers to open item data.
/** hash table of pointers to open item data */ CClosedList m_closed; ///< Hash table of pointers to closed item data.
COpenList m_open; CPriorityQueue m_open_queue; ///< Priority queue of pointers to open item data.
/** hash table of pointers to closed item data */ Titem *m_new_node; ///< New open node under construction.
CClosedList m_closed;
/** priority queue of pointers to open item data */
CPriorityQueue m_open_queue;
/** new open node under construction */
Titem *m_new_node;
public: public:
/** default constructor */ /** default constructor */
CNodeList_HashTableT() CNodeList_HashTableT() : m_open_queue(2048)
: m_open_queue(2048)
{ {
m_new_node = NULL; m_new_node = NULL;
} }
@ -81,7 +70,7 @@ public:
} }
/** Notify the nodelist that we don't want to discard the given node. */ /** Notify the nodelist that we don't want to discard the given node. */
inline 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 */ /* for now it is enough to invalidate m_new_node if it is our given node */
if (&item == m_new_node) { if (&item == m_new_node) {
@ -91,7 +80,7 @@ public:
} }
/** insert given item as open node (into m_open and m_open_queue) */ /** insert given item as open node (into m_open and m_open_queue) */
inline void InsertOpenNode(Titem_& item) inline void InsertOpenNode(Titem_ &item)
{ {
assert(m_closed.Find(item.GetKey()) == NULL); assert(m_closed.Find(item.GetKey()) == NULL);
m_open.Push(item); m_open.Push(item);
@ -122,39 +111,46 @@ public:
} }
/** return the open node specified by a key or NULL if not found */ /** return the open node specified by a key or NULL if not found */
inline Titem_ *FindOpenNode(const Key& key) inline Titem_ *FindOpenNode(const Key &key)
{ {
Titem_ *item = m_open.Find(key); Titem_ *item = m_open.Find(key);
return item; return item;
} }
/** remove and return the open node specified by a key */ /** remove and return the open node specified by a key */
inline Titem_& PopOpenNode(const Key& key) inline Titem_& PopOpenNode(const Key &key)
{ {
Titem_& item = m_open.Pop(key); Titem_ &item = m_open.Pop(key);
uint idxPop = m_open_queue.FindIndex(item); uint idxPop = m_open_queue.FindIndex(item);
m_open_queue.Remove(idxPop); m_open_queue.Remove(idxPop);
return item; return item;
} }
/** close node */ /** close node */
inline void InsertClosedNode(Titem_& item) inline void InsertClosedNode(Titem_ &item)
{ {
assert(m_open.Find(item.GetKey()) == NULL); assert(m_open.Find(item.GetKey()) == NULL);
m_closed.Push(item); m_closed.Push(item);
} }
/** return the closed node specified by a key or NULL if not found */ /** return the closed node specified by a key or NULL if not found */
inline Titem_ *FindClosedNode(const Key& key) inline Titem_ *FindClosedNode(const Key &key)
{ {
Titem_ *item = m_closed.Find(key); Titem_ *item = m_closed.Find(key);
return item; return item;
} }
/** The number of items. */ /** The number of items. */
inline int TotalCount() {return m_arr.Length();} inline int TotalCount()
{
return m_arr.Length();
}
/** Get a particular item. */ /** Get a particular item. */
inline Titem_& ItemAt(int idx) {return m_arr[idx];} inline Titem_& ItemAt(int idx)
{
return m_arr[idx];
}
/** Helper for creating output of this array. */ /** Helper for creating output of this array. */
template <class D> void Dump(D &dmp) const template <class D> void Dump(D &dmp) const

@ -38,10 +38,10 @@ extern int _total_pf_time_us;
* -------------------------------------------------------------- * --------------------------------------------------------------
* Your pathfinder derived class needs to implement following methods: * Your pathfinder derived class needs to implement following methods:
* inline void PfSetStartupNodes() * inline void PfSetStartupNodes()
* inline void PfFollowNode(Node& org) * inline void PfFollowNode(Node &org)
* inline bool PfCalcCost(Node& n) * inline bool PfCalcCost(Node &n)
* inline bool PfCalcEstimate(Node& n) * inline bool PfCalcEstimate(Node &n)
* inline bool PfDetectDestination(Node& n) * inline bool PfDetectDestination(Node &n)
* *
* For more details about those methods, look at the end of CYapfBaseT * For more details about those methods, look at the end of CYapfBaseT
* declaration. There are some examples. For another example look at * declaration. There are some examples. For another example look at
@ -99,7 +99,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -193,12 +193,12 @@ public:
*/ */
inline Node& CreateNewNode() inline Node& CreateNewNode()
{ {
Node& node = *m_nodes.CreateNewNode(); Node &node = *m_nodes.CreateNewNode();
return node; return node;
} }
/** Add new node (created by CreateNewNode and filled with data) into open list */ /** Add new node (created by CreateNewNode and filled with data) into open list */
inline void AddStartupNode(Node& n) inline void AddStartupNode(Node &n)
{ {
Yapf().PfNodeCacheFetch(n); Yapf().PfNodeCacheFetch(n);
/* insert the new node only if it is not there */ /* insert the new node only if it is not there */
@ -217,7 +217,7 @@ public:
bool is_choice = (KillFirstBit(tf.m_new_td_bits) != TRACKDIR_BIT_NONE); 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)) { for (TrackdirBits rtds = tf.m_new_td_bits; rtds != TRACKDIR_BIT_NONE; rtds = KillFirstBit(rtds)) {
Trackdir td = (Trackdir)FindFirstBit2x64(rtds); Trackdir td = (Trackdir)FindFirstBit2x64(rtds);
Node& n = Yapf().CreateNewNode(); Node &n = Yapf().CreateNewNode();
n.Set(parent, tf.m_new_tile, td, is_choice); n.Set(parent, tf.m_new_tile, td, is_choice);
Yapf().AddNewNode(n, tf); Yapf().AddNewNode(n, tf);
} }
@ -333,7 +333,7 @@ public:
inline void PfSetStartupNodes() inline void PfSetStartupNodes()
{ {
/* example: */ /* example: */
Node& n1 = *base::m_nodes.CreateNewNode(); Node &n1 = *base::m_nodes.CreateNewNode();
. .
. // setup node members here . // setup node members here
. .
@ -341,10 +341,10 @@ public:
} }
/** Example: PfFollowNode() - set following (child) nodes of the given node */ /** Example: PfFollowNode() - set following (child) nodes of the given node */
inline void PfFollowNode(Node& org) inline void PfFollowNode(Node &org)
{ {
for (each follower of node org) { for (each follower of node org) {
Node& n = *base::m_nodes.CreateNewNode(); Node &n = *base::m_nodes.CreateNewNode();
. .
. // setup node members here . // setup node members here
. .
@ -354,7 +354,7 @@ public:
} }
/** Example: PfCalcCost() - set path cost from origin to the given node */ /** Example: PfCalcCost() - set path cost from origin to the given node */
inline bool PfCalcCost(Node& n) inline bool PfCalcCost(Node &n)
{ {
/* evaluate last step cost */ /* evaluate last step cost */
int cost = ...; int cost = ...;
@ -364,7 +364,7 @@ public:
} }
/** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */ /** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */
inline bool PfCalcEstimate(Node& n) inline bool PfCalcEstimate(Node &n)
{ {
/* evaluate the distance to our destination */ /* evaluate the distance to our destination */
int distance = ...; int distance = ...;
@ -374,7 +374,7 @@ public:
} }
/** Example: PfDetectDestination() - return true if the given node is our destination */ /** Example: PfDetectDestination() - return true if the given node is our destination */
inline 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); bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
return bDest; return bDest;

@ -28,7 +28,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -45,7 +45,7 @@ public:
bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE); bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE);
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) { for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) {
Trackdir td = (Trackdir)FindFirstBit2x64(tdb); Trackdir td = (Trackdir)FindFirstBit2x64(tdb);
Node& n1 = Yapf().CreateNewNode(); Node &n1 = Yapf().CreateNewNode();
n1.Set(NULL, m_orgTile, td, is_choice); n1.Set(NULL, m_orgTile, td, is_choice);
Yapf().AddStartupNode(n1); Yapf().AddStartupNode(n1);
} }
@ -72,7 +72,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -91,12 +91,12 @@ public:
void PfSetStartupNodes() void PfSetStartupNodes()
{ {
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) { if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
Node& n1 = Yapf().CreateNewNode(); Node &n1 = Yapf().CreateNewNode();
n1.Set(NULL, m_orgTile, m_orgTd, false); n1.Set(NULL, m_orgTile, m_orgTd, false);
Yapf().AddStartupNode(n1); Yapf().AddStartupNode(n1);
} }
if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) { if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) {
Node& n2 = Yapf().CreateNewNode(); Node &n2 = Yapf().CreateNewNode();
n2.Set(NULL, m_revTile, m_revTd, false); n2.Set(NULL, m_revTile, m_revTd, false);
n2.m_cost = m_reverse_penalty; n2.m_cost = m_reverse_penalty;
Yapf().AddStartupNode(n2); Yapf().AddStartupNode(n2);
@ -135,12 +135,12 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline 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); bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
return bDest; return bDest;
@ -150,7 +150,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate
*/ */
inline 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_x_offs[] = {-1, 0, 1, 0};
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1}; static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};

@ -30,7 +30,7 @@ public:
* Called by YAPF to attach cached or local segment cost data to the given node. * 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 * @return true if globally cached data were used or false if local data was used
*/ */
inline bool PfNodeCacheFetch(Node& n) inline bool PfNodeCacheFetch(Node &n)
{ {
return false; return false;
} }
@ -39,7 +39,7 @@ public:
* Called by YAPF to flush the cached segment cost data back into cache storage. * Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. * Current cache implementation doesn't use that.
*/ */
inline void PfNodeCacheFlush(Node& n) inline void PfNodeCacheFlush(Node &n)
{ {
} }
}; };
@ -67,7 +67,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -75,7 +75,7 @@ public:
* Called by YAPF to attach cached or local segment cost data to the given node. * 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 * @return true if globally cached data were used or false if local data was used
*/ */
inline bool PfNodeCacheFetch(Node& n) inline bool PfNodeCacheFetch(Node &n)
{ {
CacheKey key(n.GetKey()); CacheKey key(n.GetKey());
Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key)); Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key));
@ -86,7 +86,7 @@ public:
* Called by YAPF to flush the cached segment cost data back into cache storage. * Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. * Current cache implementation doesn't use that.
*/ */
inline void PfNodeCacheFlush(Node& n) inline void PfNodeCacheFlush(Node &n)
{ {
} }
}; };
@ -121,9 +121,7 @@ struct CSegmentCostCacheBase
* Look at CYapfRailSegment (yapf_node_rail.hpp) for the segment example * Look at CYapfRailSegment (yapf_node_rail.hpp) for the segment example
*/ */
template <class Tsegment> template <class Tsegment>
struct CSegmentCostCacheT struct CSegmentCostCacheT : public CSegmentCostCacheBase {
: public CSegmentCostCacheBase
{
static const int C_HASH_BITS = 14; static const int C_HASH_BITS = 14;
typedef CHashTableT<Tsegment, C_HASH_BITS> HashTable; typedef CHashTableT<Tsegment, C_HASH_BITS> HashTable;
@ -142,7 +140,7 @@ struct CSegmentCostCacheT
m_heap.Clear(); m_heap.Clear();
} }
inline Tsegment& Get(Key& key, bool *found) inline Tsegment& Get(Key &key, bool *found)
{ {
Tsegment *item = m_map.Find(key); Tsegment *item = m_map.Find(key);
if (item == NULL) { if (item == NULL) {
@ -162,9 +160,7 @@ struct CSegmentCostCacheT
* segment cost caching services for your Nodes. * segment cost caching services for your Nodes.
*/ */
template <class Types> template <class Types>
class CYapfSegmentCostCacheGlobalT class CYapfSegmentCostCacheGlobalT : public CYapfSegmentCostCacheLocalT<Types> {
: public CYapfSegmentCostCacheLocalT<Types>
{
public: public:
typedef CYapfSegmentCostCacheLocalT<Types> Tlocal; typedef CYapfSegmentCostCacheLocalT<Types> Tlocal;
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
@ -175,14 +171,14 @@ public:
typedef CSegmentCostCacheT<CachedData> Cache; typedef CSegmentCostCacheT<CachedData> Cache;
protected: protected:
Cache& m_global_cache; Cache &m_global_cache;
inline CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {}; inline CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
inline static Cache& stGetGlobalCache() inline static Cache& stGetGlobalCache()
@ -211,14 +207,14 @@ public:
* Called by YAPF to attach cached or local segment cost data to the given node. * 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 * @return true if globally cached data were used or false if local data was used
*/ */
inline bool PfNodeCacheFetch(Node& n) inline bool PfNodeCacheFetch(Node &n)
{ {
if (!Yapf().CanUseGlobalCache(n)) { if (!Yapf().CanUseGlobalCache(n)) {
return Tlocal::PfNodeCacheFetch(n); return Tlocal::PfNodeCacheFetch(n);
} }
CacheKey key(n.GetKey()); CacheKey key(n.GetKey());
bool found; bool found;
CachedData& item = m_global_cache.Get(key, &found); CachedData &item = m_global_cache.Get(key, &found);
Yapf().ConnectNodeToCachedData(n, item); Yapf().ConnectNodeToCachedData(n, item);
return found; return found;
} }
@ -227,7 +223,7 @@ public:
* Called by YAPF to flush the cached segment cost data back into cache storage. * Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. * Current cache implementation doesn't use that.
*/ */
inline void PfNodeCacheFlush(Node& n) inline void PfNodeCacheFlush(Node &n)
{ {
} }
}; };

@ -16,9 +16,7 @@
#include "../../tracerestrict.h" #include "../../tracerestrict.h"
template <class Types> template <class Types>
class CYapfCostRailT class CYapfCostRailT : public CYapfCostBase {
: public CYapfCostBase
{
public: public:
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
typedef typename Types::TrackFollower TrackFollower; typedef typename Types::TrackFollower TrackFollower;
@ -75,10 +73,7 @@ protected:
static const int s_max_segment_cost = 10000; static const int s_max_segment_cost = 10000;
CYapfCostRailT() CYapfCostRailT() : m_max_cost(0), m_disable_cache(false), m_stopped_on_first_two_way_signal(false)
: m_max_cost(0)
, m_disable_cache(false)
, m_stopped_on_first_two_way_signal(false)
{ {
/* pre-compute look-ahead penalties into array */ /* pre-compute look-ahead penalties into array */
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0; int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0;
@ -93,7 +88,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -131,7 +126,7 @@ public:
} }
/** Return one tile cost (base cost + level crossing penalty). */ /** Return one tile cost (base cost + level crossing penalty). */
inline int OneTileCost(TileIndex& tile, Trackdir trackdir) inline int OneTileCost(TileIndex &tile, Trackdir trackdir)
{ {
int cost = 0; int cost = 0;
/* set base cost */ /* set base cost */
@ -166,7 +161,7 @@ public:
} }
/** The cost for reserved tiles, including skipped ones. */ /** The cost for reserved tiles, including skipped ones. */
inline 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 (n.m_num_signals_passed >= m_sig_look_ahead_costs.Size() / 2) return 0;
if (!IsPbsSignal(n.m_last_signal_type)) return 0; if (!IsPbsSignal(n.m_last_signal_type)) return 0;
@ -281,7 +276,7 @@ private:
} }
public: public:
int SignalCost(Node& n, TileIndex tile, Trackdir trackdir) int SignalCost(Node &n, TileIndex tile, Trackdir trackdir)
{ {
int cost = 0; int cost = 0;
/* if there is one-way signal in the opposite direction, then it is not our way */ /* if there is one-way signal in the opposite direction, then it is not our way */
@ -729,14 +724,14 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
return true; return true;
} }
inline bool CanUseGlobalCache(Node& n) const inline bool CanUseGlobalCache(Node &n) const
{ {
return !m_disable_cache return !m_disable_cache
&& (n.m_parent != NULL) && (n.m_parent != NULL)
&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size()); && (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size());
} }
inline void ConnectNodeToCachedData(Node& n, CachedData& ci) inline void ConnectNodeToCachedData(Node &n, CachedData &ci)
{ {
n.m_segment = &ci; n.m_segment = &ci;
if (n.m_segment->m_cost < 0) { if (n.m_segment->m_cost < 0) {

@ -12,8 +12,7 @@
#ifndef YAPF_DESTRAIL_HPP #ifndef YAPF_DESTRAIL_HPP
#define YAPF_DESTRAIL_HPP #define YAPF_DESTRAIL_HPP
class CYapfDestinationRailBase class CYapfDestinationRailBase {
{
protected: protected:
RailTypes m_compatible_railtypes; RailTypes m_compatible_railtypes;
@ -36,9 +35,7 @@ public:
}; };
template <class Types> template <class Types>
class CYapfDestinationAnyDepotRailT class CYapfDestinationAnyDepotRailT : public CYapfDestinationRailBase {
: public CYapfDestinationRailBase
{
public: public:
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
typedef typename Types::NodeList::Titem Node; ///< this will be our node type typedef typename Types::NodeList::Titem Node; ///< this will be our node type
@ -47,11 +44,11 @@ public:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node& n) inline bool PfDetectDestination(Node &n)
{ {
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir()); return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
} }
@ -67,7 +64,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate
*/ */
inline bool PfCalcEstimate(Node& n) inline bool PfCalcEstimate(Node &n)
{ {
n.m_estimate = n.m_cost; n.m_estimate = n.m_cost;
return true; return true;
@ -75,9 +72,7 @@ public:
}; };
template <class Types> template <class Types>
class CYapfDestinationAnySafeTileRailT class CYapfDestinationAnySafeTileRailT : public CYapfDestinationRailBase {
: public CYapfDestinationRailBase
{
public: public:
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
typedef typename Types::NodeList::Titem Node; ///< this will be our node type typedef typename Types::NodeList::Titem Node; ///< this will be our node type
@ -87,11 +82,11 @@ public:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node& n) inline bool PfDetectDestination(Node &n)
{ {
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir()); return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
} }
@ -107,7 +102,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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. * adds it to the actual cost from origin and stores the sum to the Node::m_estimate.
*/ */
inline bool PfCalcEstimate(Node& n) inline bool PfCalcEstimate(Node &n)
{ {
n.m_estimate = n.m_cost; n.m_estimate = n.m_cost;
return true; return true;
@ -115,9 +110,7 @@ public:
}; };
template <class Types> template <class Types>
class CYapfDestinationTileOrStationRailT class CYapfDestinationTileOrStationRailT : public CYapfDestinationRailBase {
: public CYapfDestinationRailBase
{
public: public:
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
typedef typename Types::NodeList::Titem Node; ///< this will be our node type typedef typename Types::NodeList::Titem Node; ///< this will be our node type
@ -131,7 +124,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -164,7 +157,7 @@ public:
} }
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node& n) inline bool PfDetectDestination(Node &n)
{ {
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir()); return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
} }
@ -188,7 +181,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate
*/ */
inline 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_x_offs[] = {-1, 0, 1, 0};
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1}; static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};

@ -25,8 +25,15 @@ struct CYapfNodeKeyExitDir {
m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td); m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
} }
inline int CalcHash() const {return m_exitdir | (m_tile << 2);} inline int CalcHash() const
inline bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);} {
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 void Dump(DumpTarget &dmp) const
{ {
@ -38,8 +45,15 @@ struct CYapfNodeKeyExitDir {
struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
{ {
inline int CalcHash() const {return m_td | (m_tile << 4);} inline int CalcHash() const
inline bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);} {
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 */ /** Yapf Node base */
@ -63,14 +77,45 @@ struct CYapfNodeT {
m_estimate = 0; m_estimate = 0;
} }
inline Node *GetHashNext() {return m_hash_next;} inline Node *GetHashNext()
inline void SetHashNext(Node *pNext) {m_hash_next = pNext;} {
inline TileIndex GetTile() const {return m_key.m_tile;} return m_hash_next;
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 void SetHashNext(Node *pNext)
inline int GetCostEstimate() const {return m_estimate;} {
inline bool operator < (const Node& other) const {return m_estimate < other.m_estimate;} 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 void Dump(DumpTarget &dmp) const
{ {

@ -17,19 +17,19 @@ struct CYapfRailSegmentKey
{ {
uint32 m_value; uint32 m_value;
inline CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {} inline CYapfRailSegmentKey(const CYapfRailSegmentKey &src) : m_value(src.m_value) {}
inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key) inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir &node_key)
{ {
Set(node_key); Set(node_key);
} }
inline void Set(const CYapfRailSegmentKey& src) inline void Set(const CYapfRailSegmentKey &src)
{ {
m_value = src.m_value; m_value = src.m_value;
} }
inline 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; m_value = (((int)node_key.m_tile) << 4) | node_key.m_td;
} }
@ -49,7 +49,7 @@ struct CYapfRailSegmentKey
return (Trackdir)(m_value & 0x0F); return (Trackdir)(m_value & 0x0F);
} }
inline bool operator == (const CYapfRailSegmentKey& other) const inline bool operator==(const CYapfRailSegmentKey &other) const
{ {
return m_value == other.m_value; return m_value == other.m_value;
} }
@ -75,7 +75,7 @@ struct CYapfRailSegment
EndSegmentReasonBits m_end_segment_reason; EndSegmentReasonBits m_end_segment_reason;
CYapfRailSegment *m_hash_next; CYapfRailSegment *m_hash_next;
inline CYapfRailSegment(const CYapfRailSegmentKey& key) inline CYapfRailSegment(const CYapfRailSegmentKey &key)
: m_key(key) : m_key(key)
, m_last_tile(INVALID_TILE) , m_last_tile(INVALID_TILE)
, m_last_td(INVALID_TRACKDIR) , m_last_td(INVALID_TRACKDIR)

@ -14,13 +14,11 @@
/** Yapf Node for road YAPF */ /** Yapf Node for road YAPF */
template <class Tkey_> template <class Tkey_>
struct CYapfRoadNodeT struct CYapfRoadNodeT : CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > {
: CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> >
{
typedef CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > base; typedef CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > base;
TileIndex m_segment_last_tile; TileIndex m_segment_last_tile;
Trackdir m_segment_last_td; Trackdir m_segment_last_td;
void Set(CYapfRoadNodeT *parent, TileIndex tile, Trackdir td, bool is_choice) void Set(CYapfRoadNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
{ {

@ -14,11 +14,7 @@
/** Yapf Node for ships */ /** Yapf Node for ships */
template <class Tkey_> template <class Tkey_>
struct CYapfShipNodeT struct CYapfShipNodeT : CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> > { };
: CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> >
{
};
/* now define two major node types (that differ by key type) */ /* now define two major node types (that differ by key type) */
typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir; typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir;
@ -28,5 +24,4 @@ typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 10, 12> CShipNodeListExitDir; typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 10, 12> CShipNodeListExitDir;
typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 10, 12> CShipNodeListTrackDir; typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 10, 12> CShipNodeListTrackDir;
#endif /* YAPF_NODE_SHIP_HPP */ #endif /* YAPF_NODE_SHIP_HPP */

@ -48,7 +48,7 @@ protected:
/** to access inherited pathfinder */ /** to access inherited pathfinder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
private: private:
@ -200,7 +200,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -209,7 +209,7 @@ public:
* reachable trackdir on the new tile creates new node, initializes it * reachable trackdir on the new tile creates new node, initializes it
* and adds it to the open list by calling Yapf().AddNewNode(n) * and adds it to the open list by calling Yapf().AddNewNode(n)
*/ */
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) { if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
@ -296,7 +296,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -305,7 +305,7 @@ public:
* reachable trackdir on the new tile creates new node, initializes it * reachable trackdir on the new tile creates new node, initializes it
* and adds it to the open list by calling Yapf().AddNewNode(n) * and adds it to the open list by calling Yapf().AddNewNode(n)
*/ */
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes()); TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) { if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
@ -379,7 +379,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -388,7 +388,7 @@ public:
* reachable trackdir on the new tile creates new node, initializes it * reachable trackdir on the new tile creates new node, initializes it
* and adds it to the open list by calling Yapf().AddNewNode(n) * and adds it to the open list by calling Yapf().AddNewNode(n)
*/ */
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) { if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
@ -453,7 +453,7 @@ public:
this->FindSafePositionOnNode(pPrev); this->FindSafePositionOnNode(pPrev);
} }
/* return trackdir from the best origin node (one of start nodes) */ /* return trackdir from the best origin node (one of start nodes) */
Node& best_next_node = *pPrev; Node &best_next_node = *pPrev;
next_trackdir = best_next_node.GetTrackdir(); next_trackdir = best_next_node.GetTrackdir();
if (reserve_track && path_found) this->TryReservePath(target, pNode->GetLastTile()); if (reserve_track && path_found) this->TryReservePath(target, pNode->GetLastTile());
@ -502,7 +502,7 @@ public:
} }
/* check if it was reversed origin */ /* check if it was reversed origin */
Node& best_org_node = *pNode; Node &best_org_node = *pNode;
bool reversed = (best_org_node.m_cost != 0); bool reversed = (best_org_node.m_cost != 0);
return reversed; return reversed;
} }

@ -30,7 +30,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir) int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
@ -102,7 +102,7 @@ public:
* Calculates only the cost of given node, adds it to the parent node cost * Calculates only the cost of given node, adds it to the parent node cost
* and stores the result into Node::m_cost member * and stores the result into Node::m_cost member
*/ */
inline bool PfCalcCost(Node& n, const TrackFollower *tf) inline bool PfCalcCost(Node &n, const TrackFollower *tf)
{ {
int segment_cost = 0; int segment_cost = 0;
uint tiles = 0; uint tiles = 0;
@ -179,11 +179,11 @@ public:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node& n) inline bool PfDetectDestination(Node &n)
{ {
bool bDest = IsRoadDepotTile(n.m_segment_last_tile); bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
return bDest; return bDest;
@ -198,7 +198,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate
*/ */
inline bool PfCalcEstimate(Node& n) inline bool PfCalcEstimate(Node &n)
{ {
n.m_estimate = n.m_cost; n.m_estimate = n.m_cost;
return true; return true;
@ -242,12 +242,12 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
/** Called by YAPF to detect if node ends in the desired destination */ /** Called by YAPF to detect if node ends in the desired destination */
inline bool PfDetectDestination(Node& n) inline bool PfDetectDestination(Node &n)
{ {
return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td); return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
} }
@ -268,7 +268,7 @@ public:
* Called by YAPF to calculate cost estimate. Calculates distance to the destination * 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 * adds it to the actual cost from origin and stores the sum to the Node::m_estimate
*/ */
inline 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_x_offs[] = {-1, 0, 1, 0};
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1}; static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
@ -309,7 +309,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -319,7 +319,7 @@ public:
* reachable trackdir on the new tile creates new node, initializes it * reachable trackdir on the new tile creates new node, initializes it
* and adds it to the open list by calling Yapf().AddNewNode(n) * and adds it to the open list by calling Yapf().AddNewNode(n)
*/ */
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) { if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
@ -373,7 +373,7 @@ public:
pNode = pNode->m_parent; pNode = pNode->m_parent;
} }
/* return trackdir from the best origin node (one of start nodes) */ /* return trackdir from the best origin node (one of start nodes) */
Node& best_next_node = *pNode; Node &best_next_node = *pNode;
assert(best_next_node.GetTile() == tile); assert(best_next_node.GetTile() == tile);
next_trackdir = best_next_node.GetTrackdir(); next_trackdir = best_next_node.GetTrackdir();
} }

@ -31,7 +31,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
inline Tpf& Yapf() inline Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -40,7 +40,7 @@ public:
* reachable trackdir on the new tile creates new node, initializes it * reachable trackdir on the new tile creates new node, initializes it
* and adds it to the open list by calling Yapf().AddNewNode(n) * and adds it to the open list by calling Yapf().AddNewNode(n)
*/ */
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) { if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
@ -97,7 +97,7 @@ public:
pNode = pNode->m_parent; pNode = pNode->m_parent;
} }
/* return trackdir from the best next node (direct child of origin) */ /* return trackdir from the best next node (direct child of origin) */
Node& best_next_node = *pPrevNode; Node &best_next_node = *pPrevNode;
assert(best_next_node.GetTile() == tile); assert(best_next_node.GetTile() == tile);
next_trackdir = best_next_node.GetTrackdir(); next_trackdir = best_next_node.GetTrackdir();
} }
@ -155,7 +155,7 @@ protected:
/** to access inherited path finder */ /** to access inherited path finder */
Tpf& Yapf() Tpf& Yapf()
{ {
return *static_cast<Tpf*>(this); return *static_cast<Tpf *>(this);
} }
public: public:
@ -164,7 +164,7 @@ public:
* Calculates only the cost of given node, adds it to the parent node cost * Calculates only the cost of given node, adds it to the parent node cost
* and stores the result into Node::m_cost member * and stores the result into Node::m_cost member
*/ */
inline bool PfCalcCost(Node& n, const TrackFollower *tf) inline bool PfCalcCost(Node &n, const TrackFollower *tf)
{ {
/* base tile cost depending on distance */ /* base tile cost depending on distance */
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH; int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;

@ -76,6 +76,8 @@ enum SlxiSubChunkFlags {
XSCF_IGNORABLE_VERSION = 1 << 1, ///< the loader is free to ignore this without aborting the load if the version is greater than the maximum that can be loaded XSCF_IGNORABLE_VERSION = 1 << 1, ///< the loader is free to ignore this without aborting the load if the version is greater than the maximum that can be loaded
XSCF_EXTRA_DATA_PRESENT = 1 << 2, ///< extra data field is present, extra data in some sub-chunk/feature specific format, not used for anything yet XSCF_EXTRA_DATA_PRESENT = 1 << 2, ///< extra data field is present, extra data in some sub-chunk/feature specific format, not used for anything yet
XSCF_CHUNK_ID_LIST_PRESENT = 1 << 3, ///< chunk ID list field is present, list of chunks which this sub-chunk/feature adds to the save game, this can be used to discard the chunks if the feature is unknown XSCF_CHUNK_ID_LIST_PRESENT = 1 << 3, ///< chunk ID list field is present, list of chunks which this sub-chunk/feature adds to the save game, this can be used to discard the chunks if the feature is unknown
XSCF_IGNORABLE_ALL = XSCF_IGNORABLE_UNKNOWN | XSCF_IGNORABLE_VERSION, ///< all "ignorable" flags
}; };
DECLARE_ENUM_AS_BIT_SET(SlxiSubChunkFlags) DECLARE_ENUM_AS_BIT_SET(SlxiSubChunkFlags)

@ -2469,8 +2469,6 @@ static inline void ClearSaveLoadState()
delete _sl.lf; delete _sl.lf;
_sl.lf = NULL; _sl.lf = NULL;
SlXvSetCurrentState();
} }
/** /**
@ -2782,6 +2780,8 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
GamelogStopAction(); GamelogStopAction();
} }
SlXvSetCurrentState();
return SL_OK; return SL_OK;
} }
@ -2841,6 +2841,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
return SL_REINIT; return SL_REINIT;
} }
GamelogStopAction(); GamelogStopAction();
SlXvSetCurrentState();
return SL_OK; return SL_OK;
} }

Loading…
Cancel
Save