yapf_node.hpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef YAPF_NODE_HPP
00013 #define YAPF_NODE_HPP
00014 
00016 struct CYapfNodeKeyExitDir {
00017   TileIndex      m_tile;
00018   Trackdir       m_td;
00019   DiagDirection  m_exitdir;
00020 
00021   FORCEINLINE void Set(TileIndex tile, Trackdir td)
00022   {
00023     m_tile = tile;
00024     m_td = td;
00025     m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
00026   }
00027 
00028   FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);}
00029   FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
00030 
00031   void Dump(DumpTarget &dmp) const
00032   {
00033     dmp.WriteTile("m_tile", m_tile);
00034     dmp.WriteEnumT("m_td", m_td);
00035     dmp.WriteEnumT("m_exitdir", m_exitdir);
00036   }
00037 };
00038 
00039 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
00040 {
00041   FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);}
00042   FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
00043 };
00044 
00046 template <class Tkey_, class Tnode>
00047 struct CYapfNodeT {
00048   typedef Tkey_ Key;
00049   typedef Tnode Node;
00050 
00051   Tkey_       m_key;
00052   Node       *m_hash_next;
00053   Node       *m_parent;
00054   int         m_cost;
00055   int         m_estimate;
00056 
00057   FORCEINLINE void Set(Node *parent, bool is_choice)
00058   {
00059     m_hash_next = NULL;
00060     m_parent = parent;
00061     m_cost = 0;
00062     m_estimate = 0;
00063   }
00064 
00065   FORCEINLINE Node *GetHashNext() {return m_hash_next;}
00066   FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;}
00067   FORCEINLINE const Tkey_& GetKey() const {return m_key;}
00068   FORCEINLINE int GetCost() const {return m_cost;}
00069   FORCEINLINE int GetCostEstimate() const {return m_estimate;}
00070   FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
00071 
00072   void Dump(DumpTarget &dmp) const
00073   {
00074     dmp.WriteStructT("m_key", &m_key);
00075     dmp.WriteStructT("m_parent", m_parent);
00076     dmp.WriteLine("m_cost = %d", m_cost);
00077     dmp.WriteLine("m_estimate = %d", m_estimate);
00078   }
00079 };
00080 
00082 template <class Tkey_, class Tnode>
00083 struct CYapfNodeTrackT : public CYapfNodeT<Tkey_, Tnode>
00084 {
00085   typedef CYapfNodeT<Tkey_, Tnode> Base;
00086   typedef Tnode                    Node;
00087 
00088   FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
00089   {
00090     Base::Set(parent, is_choice);
00091     this->m_key.Set(tile, td);
00092   }
00093 
00094   FORCEINLINE TileIndex GetTile() const { return this->m_key.m_tile; }
00095   FORCEINLINE Trackdir GetTrackdir() const { return this->m_key.m_td; }
00096 };
00097 
00098 #endif /* YAPF_NODE_HPP */

Generated on Fri Jun 3 05:18:56 2011 for OpenTTD by  doxygen 1.6.1