# HG changeset patch # User celestar # Date 1167667641 0 # Node ID 6ce400c0a2f4e9d12af51f131441623a991c997e # Parent 3b40a41f90d23d636814ce5587b311f317dab72a (svn r7719) [cbh] - Codechange: KUDr and I have decided that our developemnt efforts went in the wrong direction, so revert all changes from 7686 onwards diff -r 3b40a41f90d2 -r 6ce400c0a2f4 bridge_cmd.c --- a/bridge_cmd.c Mon Jan 01 10:26:12 2007 +0000 +++ b/bridge_cmd.c Mon Jan 01 16:07:21 2007 +0000 @@ -1004,8 +1004,20 @@ } dir = GetBridgeRampDirection(tile); - if (v->direction == DiagDirToDir(ReverseDiagDir(dir))) { - /* leaving the bridge */ + if (DirToDiagDir(v->direction) == dir || + (IsTileType(tile, MP_RAILWAY_BRIDGE) && DirToDiagDir(v->direction) != ReverseDiagDir(dir))) { + switch (dir) { + default: NOT_REACHED(); + case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break; + case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break; + case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break; + case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break; + } + v->u.rail.track = 0x40; + CLRBIT(v->u.rail.flags, VRF_GOINGUP); + CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); + return 4; + } else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { v->tile = tile; if (v->u.rail.track == 0x40) { v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2); diff -r 3b40a41f90d2 -r 6ce400c0a2f4 openttd_vs80.vcproj --- a/openttd_vs80.vcproj Mon Jan 01 10:26:12 2007 +0000 +++ b/openttd_vs80.vcproj Mon Jan 01 16:07:21 2007 +0000 @@ -1784,14 +1784,6 @@ > - - - - diff -r 3b40a41f90d2 -r 6ce400c0a2f4 train_cmd.c --- a/train_cmd.c Mon Jan 01 10:26:12 2007 +0000 +++ b/train_cmd.c Mon Jan 01 16:07:21 2007 +0000 @@ -3014,36 +3014,6 @@ return NULL; } -/** Puts a train (logically) onto a bridge body. - * Sets the correct coordinates to traverse the bridge - * and aligns the vehicle with the bridge. The function - * assumes the train is on a bridge head about to enter - * the bridge. - */ -static void PutTrainOntoBridge(Vehicle *v, int x, int y) -{ - DiagDirection dir; - uint8 dxy; - assert(IsBridgeTile(v->tile)); - dir = GetBridgeRampDirection(v->tile); - v->u.rail.track = 0x40; - v->direction = DiagDirToDir(dir); - CLRBIT(v->u.rail.flags, VRF_GOINGUP); - CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); - - switch (dir) { - default: NOT_REACHED(); - case DIAGDIR_NE: dxy = 0xF8; break; - case DIAGDIR_SE: dxy = 0x80; break; - case DIAGDIR_SW: dxy = 0x08; break; - case DIAGDIR_NW: dxy = 0x8F; break; - } - SB(x, 0, 4, GB(dxy, 4, 4)); - SB(y, 0, 4, GB(dxy, 0, 4)); - v->x_pos = x; - v->y_pos = y; -} - static void TrainController(Vehicle *v, bool update_image) { Vehicle *prev; @@ -3072,10 +3042,7 @@ } else { /* is not inside depot */ - if (!TrainCheckIfLineEnds(v)) { - /* reversing */ - return; - } + if (!TrainCheckIfLineEnds(v)) return; r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); if (r & 0x8) { @@ -3093,26 +3060,15 @@ InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); } } - } else new_tile:{ + } else { /* A new tile is about to be entered. */ byte bits; - /* Determine what direction we're entering the new tile from */ dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile); enterdir = DirToDiagDir(dir); assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3); - /* We should not let the train that is leaving custom bridge head (entering bridge) - * to enter the tile that is under bridge. Enter the bridge wormhole instead. */ - if (IsBridgeTile(gp.old_tile) && GetBridgeRampDirection(gp.old_tile) == enterdir) { - /* train entering the bridge body */ - PutTrainOntoBridge(v, gp.x, gp.y); - UpdateTrainDeltaXY(v, v->direction); - if (update_image) v->cur_image = GetTrainImage(v, v->direction); - continue; - } - /* Get the status of the tracks in the new tile and mask * away the bits that aren't reachable. */ ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL) & _reachable_tracks[enterdir]; @@ -3208,17 +3164,7 @@ SetSpeedLimitOnBridge(v); - if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && ((VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4) != 0)) { - if (IsBridgeTile(gp.new_tile)) { - /* when on a bridge, v->tile points to one of the bridge heads. GetNewVehicleDirection will - * fail, because it expects the new and old tile (gp.{new|old}tile) to be adjacent to each - * other. So we set the old_tile here manually by using the current vehicle coordinates */ - gp.old_tile = TileVirtXY(v->x_pos, v->y_pos); - goto new_tile; /* We need the same code when entering from a bridge than from any other tile */ - } - - } else { - /* vehicle stays in the bridge/tunnel wormhole */ + if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4)) { v->x_pos = gp.x; v->y_pos = gp.y; VehiclePositionChanged(v); @@ -3459,11 +3405,11 @@ tile = v->tile; - if (IsTunnelTile(tile)) { - DiagDirection dir = GetTunnelDirection(tile); - if (v->direction == DiagDirToDir(dir)) return true; - } else if (IsBridgeTile(tile)) { - if (TrackdirToExitdir(GetVehicleTrackdir(v)) == GetBridgeRampDirection(tile)) return true; + if (IsTileType(tile, MP_TUNNEL) || IsTileType(tile, MP_RAILWAY_BRIDGE)) { + DiagDirection dir; + + dir = IsTunnelTile(tile) ? GetTunnelDirection(tile) : GetBridgeRampDirection(tile); + if (DiagDirToDir(dir) == v->direction) return true; } // depot? diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/blob.hpp --- a/yapf/blob.hpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/blob.hpp Mon Jan 01 16:07:21 2007 +0000 @@ -4,82 +4,75 @@ #define BLOB_HPP /** Type-safe version of memcpy(). -* @param d destination buffer -* @param s source buffer -* @param num_items number of items to be copied (!not number of bytes!) */ + * @param d destination buffer + * @param s source buffer + * @param num_items number of items to be copied (!not number of bytes!) */ template -FORCEINLINE void MemCpyT(Titem_* d, const Titem_* s, size_t num_items = 1) +FORCEINLINE void MemCpyT(Titem_* d, const Titem_* s, int num_items = 1) { memcpy(d, s, num_items * sizeof(Titem_)); } /** Base class for simple binary blobs. -* Item is byte. -* The word 'simple' means: -* - no configurable allocator type (always made from heap) -* - no smart deallocation - deallocation must be called from the same -* module (DLL) where the blob was allocated -* - no configurable allocation policy (how big blocks should be allocated) -* - no extra ownership policy (i.e. 'copy on write') when blob is copied -* - no thread synchronization at all -* -* Internal member layout: -* 1. The only class member is pointer to the first item (see union ptr_u). -* 2. Allocated block contains the blob header (see CHdr) followed by the raw byte data. -* Always, when it allocates memory the allocated size is: -* sizeof(CHdr) + -* 3. Two 'virtual' members (m_size and m_max_size) are stored in the CHdr at beginning -* of the alloated block. -* 4. The pointter (in ptr_u) posize_ts behind the header (to the first data byte). -* When memory block is allocated, the sizeof(CHdr) it added to it. -* 5. Benefits of this layout: -* - items are accessed in the simplest possible way - just dereferencing the pointer, -* which is good for performance (assuming that data are accessed most often). -* - sizeof(blob) is the same as the size of any other pointer -* 6. Drawbacks of this layout: -* - the fact, that pointer to the alocated block is adjusted by sizeof(CHdr) before -* it is stored can lead to several confusions: -* - it is not common pattern so the implementation code is bit harder to read -* - valgrind can generate warning that allocated block is lost (not accessible) -* */ + * Item is byte. + * The word 'simple' means: + * - no configurable allocator type (always made from heap) + * - no smart deallocation - deallocation must be called from the same + * module (DLL) where the blob was allocated + * - no configurable allocation policy (how big blocks should be allocated) + * - no extra ownership policy (i.e. 'copy on write') when blob is copied + * - no thread synchronization at all + * + * Internal member layout: + * 1. The only class member is pointer to the first item (see union ptr_u). + * 2. Allocated block contains the blob header (see CHdr) followed by the raw byte data. + * Always, when it allocates memory the allocated size is: + * sizeof(CHdr) + + * 3. Two 'virtual' members (m_size and m_max_size) are stored in the CHdr at beginning + * of the alloated block. + * 4. The pointer (in ptr_u) points behind the header (to the first data byte). + * When memory block is allocated, the sizeof(CHdr) it added to it. + * 5. Benefits of this layout: + * - items are accessed in the simplest possible way - just dereferencing the pointer, + * which is good for performance (assuming that data are accessed most often). + * - sizeof(blob) is the same as the size of any other pointer + * 6. Drawbacks of this layout: + * - the fact, that pointer to the alocated block is adjusted by sizeof(CHdr) before + * it is stored can lead to several confusions: + * - it is not common pattern so the implementation code is bit harder to read + * - valgrind can generate warning that allocated block is lost (not accessible) + * */ class CBlobBaseSimple { -public: - typedef ::ptrdiff_t size_t; protected: /** header of the allocated memory block */ struct CHdr { - size_t m_size; ///< actual blob size in bytes - size_t m_max_size; ///< maximum (allocated) size in bytes + int m_size; ///< actual blob size in bytes + int m_max_size; ///< maximum (allocated) size in bytes }; /** type used as class member */ union { - int8 *m_pData; ///< ptr to the first byte of data - wchar_t *m_pwData; ///< ptr to the first byte of data - CHdr *m_pHdr_1; ///< ptr just after the CHdr holding m_size and m_max_size + int8 *m_pData; ///< pointer to the first byte of data + CHdr *m_pHdr_1; ///< pointer just after the CHdr holding m_size and m_max_size } ptr_u; public: - static const size_t Ttail_reserve = 4; ///< four extra bytes will be always allocated and zeroed at the end + static const int Ttail_reserve = 4; ///< four extra bytes will be always allocated and zeroed at the end /** default constructor - initializes empty blob */ FORCEINLINE CBlobBaseSimple() { InitEmpty(); } - /** constructor - create blob with data */ - FORCEINLINE CBlobBaseSimple(const int8 *p, size_t num_bytes) { InitEmpty(); AppendRaw(p, num_bytes);} /** copy constructor */ FORCEINLINE CBlobBaseSimple(const CBlobBaseSimple& src) { InitEmpty(); AppendRaw(src); } - /** move constructor - take ownership of blob data */ - FORCEINLINE CBlobBaseSimple(CHdr * const & pHdr_1) {assert(pHdr_1 != NULL); ptr_u.m_pHdr_1 = pHdr_1; *(CHdr**)&pHdr_1 = NULL;} /** destructor */ FORCEINLINE ~CBlobBaseSimple() { Free(); } protected: /** initialize the empty blob by setting the ptr_u.m_pHdr_1 pointer to the static CHdr with - * both m_size and m_max_size containing zero */ + * both m_size and m_max_size containing zero */ FORCEINLINE void InitEmpty() { static CHdr hdrEmpty[] = {{0, 0}, {0, 0}}; ptr_u.m_pHdr_1 = &hdrEmpty[1]; } /** initialize blob by attaching it to the given header followed by data */ FORCEINLINE void Init(CHdr* hdr) { ptr_u.m_pHdr_1 = &hdr[1]; } @@ -88,22 +81,22 @@ /** blob header accessor - use it rather than using the pointer arithmetics directly - const version */ FORCEINLINE const CHdr& Hdr() const { return ptr_u.m_pHdr_1[-1]; } /** return reference to the actual blob size - used when the size needs to be modified */ - FORCEINLINE size_t& RawSizeRef() { return Hdr().m_size; }; + FORCEINLINE int& RawSizeRef() { return Hdr().m_size; }; public: /** return true if blob doesn't contain valid data */ FORCEINLINE bool IsEmpty() const { return RawSize() == 0; } /** return the number of valid data bytes in the blob */ - FORCEINLINE size_t RawSize() const { return Hdr().m_size; }; + FORCEINLINE int RawSize() const { return Hdr().m_size; }; /** return the current blob capacity in bytes */ - FORCEINLINE size_t MaxRawSize() const { return Hdr().m_max_size; }; + FORCEINLINE int MaxRawSize() const { return Hdr().m_max_size; }; /** return pointer to the first byte of data - non-const version */ FORCEINLINE int8* RawData() { return ptr_u.m_pData; } /** return pointer to the first byte of data - const version */ FORCEINLINE const int8* RawData() const { return ptr_u.m_pData; } #if 0 // reenable when needed /** return the 32 bit CRC of valid data in the blob */ - FORCEINLINE usize_t32 Crc32() const {return CCrc32::Calc(RawData(), RawSize());} + FORCEINLINE uint32 Crc32() const {return CCrc32::Calc(RawData(), RawSize());} #endif //0 /** invalidate blob's data - doesn't free buffer */ FORCEINLINE void Clear() { RawSizeRef() = 0; } @@ -117,7 +110,7 @@ FORCEINLINE void Swap(CBlobBaseSimple& src) { int8 *tmp = ptr_u.m_pData; ptr_u.m_pData = src.ptr_u.m_pData; src.ptr_u.m_pData = tmp; } /** append new bytes at the end of existing data bytes - reallocates if necessary */ - FORCEINLINE void AppendRaw(const int8 *p, size_t num_bytes) + FORCEINLINE void AppendRaw(int8 *p, int num_bytes) { assert(p != NULL); if (num_bytes > 0) { @@ -135,18 +128,19 @@ } /** Reallocate if there is no free space for num_bytes bytes. - * @return pointer to the new data to be added */ - FORCEINLINE int8* MakeRawFreeSpace(size_t num_bytes) + * @return pointer to the new data to be added */ + FORCEINLINE int8* MakeRawFreeSpace(int num_bytes) { assert(num_bytes >= 0); - size_t new_size = RawSize() + num_bytes; + int new_size = RawSize() + num_bytes; if (new_size > MaxRawSize()) SmartAlloc(new_size); + FixTail(); return ptr_u.m_pData + RawSize(); } /** Increase RawSize() by num_bytes. - * @return pointer to the new data added */ - FORCEINLINE int8* GrowRawSize(size_t num_bytes) + * @return pointer to the new data added */ + FORCEINLINE int8* GrowRawSize(int num_bytes) { int8* pNewData = MakeRawFreeSpace(num_bytes); RawSizeRef() += num_bytes; @@ -154,7 +148,7 @@ } /** Decrease RawSize() by num_bytes. */ - FORCEINLINE void ReduceRawSize(size_t num_bytes) + FORCEINLINE void ReduceRawSize(int num_bytes) { if (MaxRawSize() > 0 && num_bytes > 0) { assert(num_bytes <= RawSize()); @@ -163,14 +157,14 @@ } } /** reallocate blob data if needed */ - void SmartAlloc(size_t new_size) + void SmartAlloc(int new_size) { - size_t old_max_size = MaxRawSize(); + int old_max_size = MaxRawSize(); if (old_max_size >= new_size) return; // calculate minimum block size we need to allocate - size_t min_alloc_size = sizeof(CHdr) + new_size + Ttail_reserve; + int min_alloc_size = sizeof(CHdr) + new_size + Ttail_reserve; // ask allocation policy for some reasonable block size - size_t alloc_size = AllocPolicy(min_alloc_size); + int alloc_size = AllocPolicy(min_alloc_size); // allocate new block CHdr* pNewHdr = RawAlloc(alloc_size); // setup header @@ -186,7 +180,7 @@ RawFree(pOldHdr); } /** simple allocation policy - can be optimized later */ - FORCEINLINE static size_t AllocPolicy(size_t min_alloc) + FORCEINLINE static int AllocPolicy(int min_alloc) { if (min_alloc < (1 << 9)) { if (min_alloc < (1 << 5)) return (1 << 5); @@ -205,74 +199,58 @@ } /** all allocation should happen here */ - static FORCEINLINE CHdr* RawAlloc(size_t num_bytes) { return (CHdr*)malloc(num_bytes); } + static FORCEINLINE CHdr* RawAlloc(int num_bytes) { return (CHdr*)malloc(num_bytes); } /** all deallocations should happen here */ static FORCEINLINE void RawFree(CHdr* p) { free(p); } /** fixing the four bytes at the end of blob data - useful when blob is used to hold string */ - FORCEINLINE void FixTail() const + FORCEINLINE void FixTail() { if (MaxRawSize() > 0) { int8 *p = &ptr_u.m_pData[RawSize()]; - for (size_t i = 0; i < Ttail_reserve; i++) p[i] = 0; + for (int i = 0; i < Ttail_reserve; i++) p[i] = 0; } } }; /** Blob - simple dynamic Titem_ array. Titem_ (template argument) is a placeholder for any type. -* Titem_ can be any integral type, pointer, or structure. Using Blob instead of just plain C array -* simplifies the resource management in several ways: -* 1. When adding new item(s) it automatically grows capacity if needed. -* 2. When variable of type Blob comes out of scope it automatically frees the data buffer. -* 3. Takes care about the actual data size (number of used items). -* 4. Dynamically constructs only used items (as opposite of static array which constructs all items) */ + * Titem_ can be any integral type, pointer, or structure. Using Blob instead of just plain C array + * simplifies the resource management in several ways: + * 1. When adding new item(s) it automatically grows capacity if needed. + * 2. When variable of type Blob comes out of scope it automatically frees the data buffer. + * 3. Takes care about the actual data size (number of used items). + * 4. Dynamically constructs only used items (as opposite of static array which constructs all items) */ template -class CBlobT : public Tbase_ { +class CBlobT : public CBlobBaseSimple { // make template arguments public: public: typedef Titem_ Titem; typedef Tbase_ Tbase; - typedef typename Tbase::size_t size_t; - - static const size_t Titem_size = sizeof(Titem); - struct OnTransfer { - typename Tbase_::CHdr *m_pHdr_1; - OnTransfer(const OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); *(typename Tbase_::CHdr**)&src.m_pHdr_1 = NULL;} - OnTransfer(CBlobT& src) : m_pHdr_1(src.ptr_u.m_pHdr_1) {src.InitEmpty();} - ~OnTransfer() {assert(m_pHdr_1 == NULL);} - }; + static const int Titem_size = sizeof(Titem); /** Default constructor - makes new Blob ready to accept any data */ FORCEINLINE CBlobT() : Tbase() {} - /** Constructor - makes new Blob with data */ - FORCEINLINE CBlobT(const Titem_ *p, size_t num_items) : Tbase((int8*)p, num_items * Titem_size) {} /** Copy constructor - make new blob to become copy of the original (source) blob */ - FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((Tbase::RawSize() % Titem_size) == 0);} - /** Take ownership constructor */ - FORCEINLINE CBlobT(const OnTransfer& ot) : Tbase(ot.m_pHdr_1) {} + FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((RawSize() % Titem_size) == 0);} /** Destructor - ensures that allocated memory (if any) is freed */ FORCEINLINE ~CBlobT() { Free(); } /** Check the validity of item index (only in debug mode) */ - FORCEINLINE void CheckIdx(size_t idx) { assert(idx >= 0); assert(idx < Size()); } + FORCEINLINE void CheckIdx(int idx) { assert(idx >= 0); assert(idx < Size()); } /** Return pointer to the first data item - non-const version */ - FORCEINLINE Titem* Data() { return (Titem*)Tbase::RawData(); } + FORCEINLINE Titem* Data() { return (Titem*)RawData(); } /** Return pointer to the first data item - const version */ - FORCEINLINE const Titem* Data() const { return (const Titem*)Tbase::RawData(); } + FORCEINLINE const Titem* Data() const { return (const Titem*)RawData(); } /** Return pointer to the idx-th data item - non-const version */ - FORCEINLINE Titem* Data(size_t idx) { CheckIdx(idx); return (Data() + idx); } + FORCEINLINE Titem* Data(int idx) { CheckIdx(idx); return (Data() + idx); } /** Return pointer to the idx-th data item - const version */ - FORCEINLINE const Titem* Data(size_t idx) const { CheckIdx(idx); return (Data() + idx); } + FORCEINLINE const Titem* Data(int idx) const { CheckIdx(idx); return (Data() + idx); } /** Return number of items in the Blob */ - FORCEINLINE size_t Size() const { return (Tbase::RawSize() / Titem_size); } - /** Return total number of items that can fit in the Blob without buffer reallocation */ - FORCEINLINE size_t MaxSize() const { return (Tbase::MaxRawSize() / Titem_size); } - /** Return number of additional items that can fit in the Blob without buffer reallocation */ - FORCEINLINE size_t GetReserve() const { return ((Tbase::MaxRawSize() - Tbase::RawSize()) / Titem_size); } + FORCEINLINE int Size() const { return (RawSize() / Titem_size); } /** Free the memory occupied by Blob destroying all items */ FORCEINLINE void Free() { - assert((Tbase::RawSize() % Titem_size) == 0); - size_t old_size = Size(); + assert((RawSize() % Titem_size) == 0); + int old_size = Size(); if (old_size > 0) { // destroy removed items; Titem* pI_last_to_destroy = Data(0); @@ -281,25 +259,25 @@ Tbase::Free(); } /** Grow number of data items in Blob by given number - doesn't construct items */ - FORCEINLINE Titem* GrowSizeNC(size_t num_items) { return (Titem*)Tbase::GrowRawSize(num_items * Titem_size); } + FORCEINLINE Titem* GrowSizeNC(int num_items) { return (Titem*)GrowRawSize(num_items * Titem_size); } /** Grow number of data items in Blob by given number - constructs new items (using Titem_'s default constructor) */ - FORCEINLINE Titem* GrowSizeC(size_t num_items) + FORCEINLINE Titem* GrowSizeC(int num_items) { Titem* pI = GrowSizeNC(num_items); - for (size_t i = num_items; i > 0; i--, pI++) new (pI) Titem(); + for (int i = num_items; i > 0; i--, pI++) new (pI) Titem(); } /** Destroy given number of items and reduce the Blob's data size */ - FORCEINLINE void ReduceSize(size_t num_items) + FORCEINLINE void ReduceSize(int num_items) { - assert((Tbase::RawSize() % Titem_size) == 0); - size_t old_size = Size(); + assert((RawSize() % Titem_size) == 0); + int old_size = Size(); assert(num_items <= old_size); - size_t new_size = (num_items <= old_size) ? (old_size - num_items) : 0; + int new_size = (num_items <= old_size) ? (old_size - num_items) : 0; // destroy removed items; Titem* pI_last_to_destroy = Data(new_size); for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem(); // remove them - Tbase::ReduceRawSize(num_items * Titem_size); + ReduceRawSize(num_items * Titem_size); } /** Append one data item at the end (calls Titem_'s default constructor) */ FORCEINLINE Titem* AppendNew() @@ -316,7 +294,7 @@ return pNewItem; } /** Add given items (ptr + number of items) at the end of blob */ - FORCEINLINE Titem* Append(const Titem* pSrc, size_t num_items) + FORCEINLINE Titem* Append(const Titem* pSrc, int num_items) { Titem* pDst = GrowSizeNC(num_items); Titem* pDstOrg = pDst; @@ -325,7 +303,7 @@ return pDstOrg; } /** Remove item with the given index by replacing it by the last item and reducing the size by one */ - FORCEINLINE void RemoveBySwap(size_t idx) + FORCEINLINE void RemoveBySwap(int idx) { CheckIdx(idx); // destroy removed item @@ -345,14 +323,20 @@ // destroy the last item pLast->~Titem_(); // and reduce the raw blob size - Tbase::ReduceRawSize(Titem_size); + ReduceRawSize(Titem_size); } /** Ensures that given number of items can be added to the end of Blob. Returns pointer to the - * first free (unused) item */ - FORCEINLINE Titem* MakeFreeSpace(size_t num_items) { return (Titem*)Tbase::MakeRawFreeSpace(num_items * Titem_size); } - - FORCEINLINE OnTransfer Transfer() {return OnTransfer(*this);}; + * first free (unused) item */ + FORCEINLINE Titem* MakeFreeSpace(int num_items) { return (Titem*)MakeRawFreeSpace(num_items * Titem_size); } }; +// simple string implementation +struct CStrA : public CBlobT +{ + typedef CBlobT base; + CStrA(const char* str = NULL) {Append(str);} + FORCEINLINE CStrA(const CBlobBaseSimple& src) : base(src) {} + void Append(const char* str) {if (str != NULL && str[0] != '\0') base::Append(str, (int)strlen(str));} +}; #endif /* BLOB_HPP */ diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/follow_track.hpp --- a/yapf/follow_track.hpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/follow_track.hpp Mon Jan 01 16:07:21 2007 +0000 @@ -29,7 +29,6 @@ m_exitdir = INVALID_DIAGDIR; m_is_station = m_is_bridge = m_is_tunnel = false; m_tiles_skipped = 0; - m_intermediate_trackdir = INVALID_TRACKDIR; } FORCEINLINE static TransportType TT() {return Ttr_type_;} @@ -51,7 +50,7 @@ FollowTileExit(); if (!QueryNewTileTrackStatus()) return TryReverse(); m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir); - if (!Allow90degTurns() && m_tiles_skipped == 0) + if (!Allow90degTurns()) m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td); if (m_new_td_bits == TRACKDIR_BIT_NONE) return false; if (!CanEnterNewTile()) return false; @@ -88,7 +87,6 @@ uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile); m_tiles_skipped = bridge_length; m_is_bridge = true; - if (m_tiles_skipped > 0) m_intermediate_trackdir = DiagdirToDiagTrackdir(bridge_enterdir); return; } } diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/str.hpp --- a/yapf/str.hpp Mon Jan 01 10:26:12 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* $Id$ */ - -#ifndef STR_HPP -#define STR_HPP - -#include -#include - -#include "blob.hpp" -#include "strapi.hpp" - - -// simple string implementation -template -struct CStrT : public CBlobT -{ - typedef CBlobT base; - typedef CStrApiT Api; - typedef typename base::size_t size_t; - typedef typename base::OnTransfer OnTransfer; - - - FORCEINLINE CStrT(const Tchar* str = NULL) {AppendStr(str);} - FORCEINLINE CStrT(const Tchar* str, size_t num_chars) : base(str, num_chars) {base::FixTail();} - FORCEINLINE CStrT(const Tchar* str, const Tchar* end) : base(str, end - str) {base::FixTail();} - FORCEINLINE CStrT(const CBlobBaseSimple& src) : base(src) {base::FixTail();} - /** Take ownership constructor */ - FORCEINLINE CStrT(const OnTransfer& ot) : base(ot) {} - FORCEINLINE Tchar* GrowSizeNC(size_t count) {Tchar* ret = base::GrowSizeNC(count); base::FixTail(); return ret;} - FORCEINLINE void AppendStr(const Tchar* str) {if (str != NULL && str[0] != '\0') base::Append(str, (size_t)Api::StrLen(str)); base::FixTail();} - FORCEINLINE CStrT& operator = (const Tchar* src) {base::Clear(); Append(src); return *this;} - FORCEINLINE bool operator < (const CStrT &other) const {return (Api::StrCmp(base::Data(), other.Data()) < 0);} - - int FormatL(const Tchar *fmt, va_list args) - { - size_t addSize = Api::StrLen(fmt); - if (addSize < 16) addSize = 16; - addSize += addSize > 1; - int ret; - do { - Tchar *buf = MakeFreeSpace(addSize); - ret = Api::SPrintFL(buf, base::GetReserve(), fmt, args); - addSize *= 2; - } while(ret < 0 && (errno == ERANGE || errno == 0)); - if (ret > 0) { - GrowSizeNC(ret); - } else { -// int err = errno; - base::FixTail(); - } - return ret; - } - - int Format(const Tchar *format, ...) - { - va_list args; - va_start(args, format); - int ret = FormatL(format, args); - va_end(args); - return ret; - } - -}; - -typedef CStrT CStrA; -typedef CStrT CStrCiA; -typedef CStrT CStrW; -typedef CStrT CStrCiW; - -#endif /* STR_HPP */ diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/strapi.hpp --- a/yapf/strapi.hpp Mon Jan 01 10:26:12 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* $Id$ */ - -#ifndef STRAPI_HPP -#define STRAPI_HPP - -#include -#include - -#if !defined(_MSC_VER) -#define _stricmp strcmp -#define _wcsicmp wcscmp -#endif //!_MSC_VER - -/** String API mapper base - just mapping by character type, not by case sensitivity yet. - * Class template CStrApiBaseT declaration is general, but following inline method - * definitions are specialized by character type. Class is not used directly, but only - * as a base class for template class CStrApiT */ -template -class CStrApiBaseT -{ -public: - /** ::strlen wrapper */ - static size_t StrLen(const Tchar *s); - static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args); -}; - -/** ::strlen wrapper specialization for char */ -template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const char *s) -{ - return ::strlen(s); -} - -/** ::strlen wrapper specialization for wchar_t */ -template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const wchar_t *s) -{ - return ::wcslen(s); -} - -/** ::vsprintf wrapper specialization for char */ -template <> /*static*/ inline int CStrApiBaseT::SPrintFL(char *buf, size_t count, const char *fmt, va_list args) -{ -#if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above - return ::vsnprintf_s(buf, count, count - 1, fmt, args); -#else // ! VC 8.0 and above - return ::vsnprintf(buf, count, fmt, args); -#endif -} - -/** ::vsprintf wrapper specialization for wchar_t */ -template <> /*static*/ inline int CStrApiBaseT::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args) -{ -#if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above - return ::_vsnwprintf_s(buf, count, count - 1, fmt, args); -#else // ! VC 8.0 and above - return ::vswprintf(buf, count, fmt, args); -#endif -} - - - -template -class CStrApiT : public CStrApiBaseT -{ -public: - static int StrCmp(const Tchar *s1, const Tchar *s2); -}; - -template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) -{ - return ::strcmp(s1, s2); -} - -template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) -{ - return ::_stricmp(s1, s2); -} - -template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) -{ - return ::wcscmp(s1, s2); -} - -template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) -{ - return ::_wcsicmp(s1, s2); -} - -#endif /* STRAPI_HPP */ diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf.h --- a/yapf/yapf.h Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf.h Mon Jan 01 16:07:21 2007 +0000 @@ -98,7 +98,6 @@ bool m_is_bridge; ///< last turn passed bridge ramp bool m_is_station; ///< last turn passed station int m_tiles_skipped; ///< number of skipped tunnel or station tiles - Trackdir m_intermediate_trackdir; ///< when some bridge tiles are skipped, contains direction of the bridge } FollowTrack_t; /** Initializes FollowTrack_t structure */ diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf.hpp --- a/yapf/yapf.hpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf.hpp Mon Jan 01 16:07:21 2007 +0000 @@ -71,16 +71,12 @@ typedef CPerfStartFake CPerfStart; -#include "crc32.hpp" -#include "blob.hpp" -#include "str.hpp" - -const char* GetTrackdirName(Trackdir td); -CStrA GetTrackdirBitsName(TrackdirBits td_bits); //#undef FORCEINLINE //#define FORCEINLINE inline +#include "crc32.hpp" +#include "blob.hpp" #include "fixedsizearray.hpp" #include "array.hpp" #include "hashtable.hpp" diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf_common.cpp --- a/yapf/yapf_common.cpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf_common.cpp Mon Jan 01 16:07:21 2007 +0000 @@ -27,39 +27,3 @@ TRACKDIR_BIT_NONE , //14 TRACKDIR_BIT_NONE , //15 }; - -const char* GetTrackdirName(Trackdir td) -{ - static const char * const td_names[] = { - "INVALID_TRACKDIR", - "X_NE", - "Y_SE", - "UPPER_E", - "LOWER_E", - "LEFT_S", - "RIGHT_S", - "<6>", - "<7>", - "X_SW", - "Y_NW", - "UPPER_W", - "LOWER_W", - "LEFT_N", - "RIGHT_N", - "TRACKDIR_END" - }; - if (((int)td <= (int)TRACKDIR_END)) { - int idx = ((int8)td) + 1; - return td_names[idx]; - } - return ""; -} - -CStrA GetTrackdirBitsName(TrackdirBits td_bits) -{ - CStrA name; - for(int tdb = td_bits; tdb != 0; tdb = KillFirstBit2x64(tdb)) { - name.Format("%s%s", name.Size() > 0 ? "+" : "", GetTrackdirName((Trackdir)FindFirstBit2x64(tdb))); - } - return name.Transfer(); -} diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf_common.hpp --- a/yapf/yapf_common.hpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf_common.hpp Mon Jan 01 16:07:21 2007 +0000 @@ -50,24 +50,24 @@ typedef typename Node::Key Key; ///< key to hash tables protected: - TileIndex m_org_tile; ///< first origin tile - TrackdirBits m_org_td_bits; ///< first origin trackdirbits - TileIndex m_rev_tile; ///< second (reversed) origin tile - TrackdirBits m_rev_td_bits; ///< 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 + TileIndex m_orgTile; ///< first origin tile + Trackdir m_orgTd; ///< first origin trackdir + 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() {return *static_cast(this);} public: /// set origin (tiles, trackdirs, etc.) - void SetOrigin(TileIndex tile, TrackdirBits td_bits, TileIndex tiler = INVALID_TILE, TrackdirBits tdr_bits = INVALID_TRACKDIR_BIT, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true) + void SetOrigin(TileIndex tile, Trackdir td, TileIndex tiler = INVALID_TILE, Trackdir tdr = INVALID_TRACKDIR, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true) { - m_org_tile = tile; - m_org_td_bits = td_bits; - m_rev_tile = tiler; - m_rev_td_bits = tdr_bits; + m_orgTile = tile; + m_orgTd = td; + m_revTile = tiler; + m_revTd = tdr; m_reverse_penalty = reverse_penalty; m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol; } @@ -75,22 +75,16 @@ /// Called when YAPF needs to place origin nodes into open list void PfSetStartupNodes() { - if (m_org_tile != INVALID_TILE && m_org_td_bits != INVALID_TRACKDIR_BIT) { - for (TrackdirBits td_bits = m_org_td_bits; td_bits != TRACKDIR_BIT_NONE; td_bits = (TrackdirBits)KillFirstBit2x64(td_bits)) { - Node& n = Yapf().CreateNewNode(); - Trackdir td = (Trackdir)FindFirstBit2x64(td_bits); - n.Set(NULL, m_org_tile, td, false); - Yapf().AddStartupNode(n); - } + if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) { + Node& n1 = Yapf().CreateNewNode(); + n1.Set(NULL, m_orgTile, m_orgTd, false); + Yapf().AddStartupNode(n1); } - if (m_rev_tile != INVALID_TILE && m_rev_td_bits != INVALID_TRACKDIR_BIT) { - for (TrackdirBits td_bits = m_rev_td_bits; td_bits != TRACKDIR_BIT_NONE; td_bits = (TrackdirBits)KillFirstBit2x64(td_bits)) { - Node& n = Yapf().CreateNewNode(); - Trackdir td = (Trackdir)FindFirstBit2x64(td_bits); - n.Set(NULL, m_rev_tile, td, false); - n.m_cost = m_reverse_penalty; - Yapf().AddStartupNode(n); - } + if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) { + Node& n2 = Yapf().CreateNewNode(); + n2.Set(NULL, m_revTile, m_revTd, false); + n2.m_cost = m_reverse_penalty; + Yapf().AddStartupNode(n2); } } diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf_costrail.hpp --- a/yapf/yapf_costrail.hpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf_costrail.hpp Mon Jan 01 16:07:21 2007 +0000 @@ -189,58 +189,38 @@ Trackdir trackdir = n.m_key.m_td; TileType tile_type = GetTileType(tile); - DEBUG(yapf, 3, "PfCalcCost(Node:tile=%04X td=%s; Parent:tile=%04X td=%s)", tile, GetTrackdirName(trackdir), prev_tile, GetTrackdirName(prev_trackdir)); - RailType rail_type = GetTileRailType(tile, trackdir); // detect exit from bridge wormhole - Trackdir intermediate_trackdir = INVALID_TRACKDIR; if (IsBridgeTile(tile) && TrackdirToExitdir(ReverseTrackdir(trackdir)) == GetBridgeRampDirection(tile)) { // we are jumping over bridge (possible now with custom bridge heads) we must add the cost of skipped tiles - int skipped_tiles = DistanceManhattan(prev_tile, tile) - 1; - if (skipped_tiles > 0) { - segment_cost += skipped_tiles * YAPF_TILE_LENGTH; - DEBUG(yapf, 6, " Cost: skipped=%d", skipped_tiles * YAPF_TILE_LENGTH); - intermediate_trackdir = DiagdirToDiagTrackdir(ReverseDiagDir(GetBridgeRampDirection(tile))); - } + segment_cost += (DistanceManhattan(prev_tile, tile) - 1) * YAPF_TILE_LENGTH; } bool target_seen = Yapf().PfDetectDestination(tile, trackdir); while (true) { - int tile_cost = Yapf().OneTileCost(tile, trackdir); - int curve_cost; - if (intermediate_trackdir == INVALID_TRACKDIR) { - curve_cost = Yapf().CurveCost(prev_trackdir, trackdir); - } else { - curve_cost = Yapf().CurveCost(prev_trackdir, intermediate_trackdir) + Yapf().CurveCost(intermediate_trackdir, trackdir); - intermediate_trackdir = INVALID_TRACKDIR; - } - int slope_cost = Yapf().SlopeCost(tile, trackdir); - int signal_cost = Yapf().SignalCost(n, tile, trackdir); - DEBUG(yapf, 6, " Cost: tile=%d, curve=%d, slope=%d, signal=%d", tile_cost, curve_cost, slope_cost, signal_cost); - segment_cost += tile_cost + curve_cost + slope_cost + signal_cost; + segment_cost += Yapf().OneTileCost(tile, trackdir); + segment_cost += Yapf().CurveCost(prev_trackdir, trackdir); + segment_cost += Yapf().SlopeCost(tile, trackdir); + segment_cost += Yapf().SignalCost(n, tile, trackdir); if (n.m_segment->flags_u.flags_s.m_end_of_line) { - DEBUG(yapf, 4, " end: EOL (signal)"); break; } // finish if we have reached the destination if (target_seen) { - DEBUG(yapf, 4, " end: target_seen"); break; } // finish on first station tile - segment should end here to avoid target skipping // when cached segments are used if (tile_type == MP_STATION && prev_tile_type != MP_STATION) { - DEBUG(yapf, 4, " end: first station tile"); break; } // finish also on waypoint - same workaround as for first station tile if (tile_type == MP_RAILWAY && IsRailWaypoint(tile)) { - DEBUG(yapf, 4, " end: waypoint"); break; } @@ -249,15 +229,11 @@ if (!F.Follow(tile, trackdir)) { // we can't continue? // n.m_segment->flags_u.flags_s.m_end_of_line = true; - DEBUG(yapf, 4, " end: can't foolow (dead end?)"); break; } - if (F.m_is_bridge && F.m_tiles_skipped > 0) intermediate_trackdir = F.m_intermediate_trackdir; - DEBUG(yapf, 4, " next: tile=%04X td=%s", F.m_new_tile, GetTrackdirBitsName(F.m_new_td_bits).Data()); // if there are more trackdirs available & reachable, we are at the end of segment if (KillFirstBit2x64(F.m_new_td_bits) != 0) { - DEBUG(yapf, 4, " end: choice"); break; } @@ -266,23 +242,18 @@ { // end segment if train is about to enter simple loop with no junctions // so next time it should stop on the next if - if (segment_cost > s_max_segment_cost && IsTileType(F.m_new_tile, MP_RAILWAY)) { - DEBUG(yapf, 4, " end: loop fuse"); + if (segment_cost > s_max_segment_cost && IsTileType(F.m_new_tile, MP_RAILWAY)) break; - } // stop if train is on simple loop with no junctions - if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) { - DEBUG(yapf, 4, " end: loop detected"); + if (F.m_new_tile == n.m_key.m_tile && new_td == n.m_key.m_td) return false; - } } - // if rail type changes, finish segment (cached segment can't contain more rail types) + // if tail type changes, finish segment (cached segment can't contain more rail types) { RailType new_rail_type = GetTileRailType(F.m_new_tile, (Trackdir)FindFirstBit2x64(F.m_new_td_bits)); if (new_rail_type != rail_type) { - DEBUG(yapf, 4, " end: rail type changes"); break; } rail_type = new_rail_type; @@ -301,15 +272,12 @@ // reversing in depot penalty if (tile == prev_tile) { - int reverse_in_depot_cost = Yapf().PfGetSettings().rail_depot_reverse_penalty; - segment_cost += reverse_in_depot_cost; - DEBUG(yapf, 4, " end: reversing in depot (cost=%d)", reverse_in_depot_cost); + segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty; break; } // if we skipped some tunnel tiles, add their cost segment_cost += YAPF_TILE_LENGTH * F.m_tiles_skipped; - DEBUG(yapf, 6, " Cost: wormhole=%d", YAPF_TILE_LENGTH * F.m_tiles_skipped); // add penalty for skipped station tiles if (F.m_is_station) @@ -317,14 +285,10 @@ if (target_seen) { // it is our destination station uint platform_length = F.m_tiles_skipped + 1; - int platform_length_cost = PlatformLengthPenalty(platform_length); - segment_cost += platform_length_cost; - DEBUG(yapf, 6, " Cost: platform=%d", platform_length_cost); + segment_cost += PlatformLengthPenalty(platform_length); } else { // station is not our destination station, apply penalty for skipped platform tiles - int station_cost = Yapf().PfGetSettings().rail_station_penalty * F.m_tiles_skipped; - segment_cost += station_cost; - DEBUG(yapf, 6, " Cost: station=%d", station_cost); + segment_cost += Yapf().PfGetSettings().rail_station_penalty * F.m_tiles_skipped; } } @@ -338,7 +302,6 @@ // finish if we already exceeded the maximum cost if (m_max_cost > 0 && (parent_cost + first_tile_cost + segment_cost) > m_max_cost) { - DEBUG(yapf, 4, " abort: maximum cost reached"); return false; } @@ -346,12 +309,10 @@ // we just have done first tile first_tile_cost = segment_cost; segment_cost = 0; - DEBUG(yapf, 5, " TotalCost: first_tile=%d", first_tile_cost); // look if we can reuse existing (cached) segment cost if (n.m_segment->m_cost >= 0) { // reuse the cached segment cost - DEBUG(yapf, 4, " end: reusing the cached segment cost"); break; } } @@ -364,18 +325,15 @@ // we have just finished first tile first_tile_cost = segment_cost; segment_cost = 0; - DEBUG(yapf, 5, " TotalCost: first_tile=%d", first_tile_cost); } // do we have cached segment cost? if (n.m_segment->m_cost >= 0) { // reuse the cached segment cost segment_cost = n.m_segment->m_cost; - DEBUG(yapf, 5, " TotalCost: cached_segment=%d", segment_cost); } else { // save segment cost n.m_segment->m_cost = segment_cost; - DEBUG(yapf, 5, " TotalCost: segment=%d", segment_cost); // save end of segment back to the node n.SetLastTileTrackdir(tile, trackdir); @@ -394,12 +352,10 @@ } } } - DEBUG(yapf, 5, " TotalCost: extra=%d", extra_cost); // total node cost n.m_cost = parent_cost + first_tile_cost + segment_cost + extra_cost; - DEBUG(yapf, 3, " leaving: last_tile=%04X, last_td=%s, cost=%d", n.m_segment->m_last_tile, GetTrackdirName(n.m_segment->m_last_td), n.m_cost); - DEBUG(yapf, 3, " returning %s", n.m_segment->flags_u.flags_s.m_end_of_line ? "false" : "true"); + return !n.m_segment->flags_u.flags_s.m_end_of_line; } diff -r 3b40a41f90d2 -r 6ce400c0a2f4 yapf/yapf_rail.cpp --- a/yapf/yapf_rail.cpp Mon Jan 01 10:26:12 2007 +0000 +++ b/yapf/yapf_rail.cpp Mon Jan 01 16:07:21 2007 +0000 @@ -49,7 +49,7 @@ FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) { // set origin and destination nodes - Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), reverse_penalty, true); + Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true); Yapf().SetDestination(v); Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance); @@ -113,14 +113,7 @@ FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) { // set origin and destination nodes - if (v->tile == tile) { - // probably bridge head - trackdirs = (TrackdirBits)(GetTileTrackStatus(tile, TRANSPORT_RAIL) & TRACKDIR_BIT_MASK); - trackdirs &= DiagdirReachesTrackdirs(ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v))))); - Yapf().SetOrigin(tile, trackdirs, INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true); - } else { - Yapf().SetOrigin(v->tile, TrackdirToTrackdirBits(GetVehicleTrackdir(v)), INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true); - } + Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true); Yapf().SetDestination(v); // find the best path @@ -142,8 +135,8 @@ pNode = pNode->m_parent; } // return trackdir from the best origin node (one of start nodes) - Node& best_next_node = (v->tile == tile ? *pNode : *pPrev); - assert(v->tile == tile || best_next_node.GetTile() == tile); + Node& best_next_node = *pPrev; + assert(best_next_node.GetTile() == tile); next_trackdir = best_next_node.GetTrackdir(); } return next_trackdir; @@ -159,7 +152,7 @@ { // create pathfinder instance // set origin and destination nodes - Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), 1, false); + Yapf().SetOrigin(t1, td1, t2, td2, 1, false); Yapf().SetDestination(v); // find the best path