KUDr@3900: /* $Id$ */ KUDr@3900: celestar@6447: /** @file yapf_node_rail.hpp */ celestar@6447: KUDr@3900: #ifndef YAPF_NODE_RAIL_HPP KUDr@3900: #define YAPF_NODE_RAIL_HPP KUDr@3900: KUDr@3900: /** key for cached segment cost for rail YAPF */ KUDr@3900: struct CYapfRailSegmentKey KUDr@3900: { KUDr@3900: uint32 m_value; KUDr@3900: KUDr@3900: FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {} KUDr@3900: FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyExitDir& node_key) {Set(node_key);} KUDr@3900: KUDr@3900: FORCEINLINE void Set(const CYapfRailSegmentKey& src) {m_value = src.m_value;} KUDr@3900: FORCEINLINE void Set(const CYapfNodeKeyExitDir& node_key) {m_value = (((int)node_key.m_tile) << 2) | node_key.m_exitdir;} KUDr@3900: KUDr@3900: FORCEINLINE int32 CalcHash() const {return m_value;} KUDr@3900: FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 2);} KUDr@3900: FORCEINLINE DiagDirection GetExitDir() const {return (DiagDirection)(m_value & 3);} KUDr@3900: FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;} KUDr@3900: }; KUDr@3900: KUDr@3900: /** cached segment cost for rail YAPF */ KUDr@3900: struct CYapfRailSegment KUDr@3900: { KUDr@3900: typedef CYapfRailSegmentKey Key; KUDr@3900: KUDr@3900: CYapfRailSegmentKey m_key; KUDr@3900: TileIndex m_last_tile; KUDr@3900: Trackdir m_last_td; KUDr@3900: int m_cost; KUDr@3900: TileIndex m_last_signal_tile; KUDr@3900: Trackdir m_last_signal_td; KUDr@3900: CYapfRailSegment* m_hash_next; KUDr@3900: union { KUDr@3900: byte m_flags; KUDr@3900: struct { KUDr@3900: bool m_end_of_line : 1; KUDr@3900: } flags_s; KUDr@3900: } flags_u; KUDr@3900: byte m_reserve[3]; KUDr@3900: KUDr@3900: FORCEINLINE CYapfRailSegment(const CYapfRailSegmentKey& key) KUDr@3900: : m_key(key) KUDr@3900: , m_last_tile(INVALID_TILE) KUDr@3900: , m_last_td(INVALID_TRACKDIR) KUDr@3900: , m_cost(-1) KUDr@3900: , m_last_signal_tile(INVALID_TILE) KUDr@3900: , m_last_signal_td(INVALID_TRACKDIR) KUDr@3900: , m_hash_next(NULL) KUDr@3900: { KUDr@3900: flags_u.m_flags = 0; KUDr@3900: } KUDr@3900: KUDr@3900: FORCEINLINE const Key& GetKey() const {return m_key;} KUDr@3900: FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();} KUDr@3900: FORCEINLINE DiagDirection GetExitDir() const {return m_key.GetExitDir();} KUDr@3900: FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;} KUDr@3900: FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;} KUDr@3900: }; KUDr@3900: KUDr@3900: /** Yapf Node for rail YAPF */ KUDr@3900: template KUDr@3900: struct CYapfRailNodeT KUDr@3900: : CYapfNodeT > KUDr@3900: { KUDr@3900: typedef CYapfNodeT > base; KUDr@3900: typedef CYapfRailSegment CachedData; KUDr@3900: KUDr@3900: CYapfRailSegment *m_segment; KUDr@3900: uint16 m_num_signals_passed; KUDr@3900: union { KUDr@3978: uint32 m_inherited_flags; KUDr@3900: struct { KUDr@3900: bool m_targed_seen : 1; KUDr@3978: bool m_choice_seen : 1; KUDr@3900: bool m_last_signal_was_red : 1; KUDr@3900: } flags_s; KUDr@3900: } flags_u; KUDr@3900: SignalType m_last_red_signal_type; KUDr@3900: KUDr@3978: FORCEINLINE void Set(CYapfRailNodeT* parent, TileIndex tile, Trackdir td, bool is_choice) KUDr@3900: { KUDr@3978: base::Set(parent, tile, td, is_choice); KUDr@3900: m_segment = NULL; KUDr@3900: if (parent == NULL) { KUDr@3900: m_num_signals_passed = 0; KUDr@3900: flags_u.m_inherited_flags = 0; KUDr@3900: m_last_red_signal_type = SIGTYPE_NORMAL; KUDr@3900: } else { KUDr@3900: m_num_signals_passed = parent->m_num_signals_passed; KUDr@3900: flags_u.m_inherited_flags = parent->flags_u.m_inherited_flags; KUDr@3900: m_last_red_signal_type = parent->m_last_red_signal_type; KUDr@3900: } KUDr@3978: flags_u.flags_s.m_choice_seen |= is_choice; KUDr@3900: } KUDr@3900: KUDr@3900: FORCEINLINE TileIndex GetLastTile() const {assert(m_segment != NULL); return m_segment->m_last_tile;} KUDr@3900: FORCEINLINE Trackdir GetLastTrackdir() const {assert(m_segment != NULL); return m_segment->m_last_td;} KUDr@3900: FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td) {assert(m_segment != NULL); m_segment->m_last_tile = tile; m_segment->m_last_td = td;} KUDr@3900: }; KUDr@3900: KUDr@3900: // now define two major node types (that differ by key type) KUDr@3900: typedef CYapfRailNodeT CYapfRailNodeExitDir; KUDr@3900: typedef CYapfRailNodeT CYapfRailNodeTrackDir; KUDr@3900: KUDr@3900: // Default NodeList types KUDr@3900: typedef CNodeList_HashTableT CRailNodeListExitDir; KUDr@3900: typedef CNodeList_HashTableT CRailNodeListTrackDir; KUDr@3900: KUDr@3900: KUDr@3900: KUDr@3900: #endif /* YAPF_NODE_RAIL_HPP */