Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PFQueue.h
Go to the documentation of this file.
1 // Copyright (C) 2004,2005 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef PFQUEUE_H
22 #define PFQUEUE_H
23 
24 #include <algorithm>
25 
26 #include "../CD_LIB/CDGrid.h"
27 
28 #include "PFConsts.h"
29 
30 namespace OpenSkyNet {
31  namespace PF {
33  class Queue {
34  struct QueueNode {
35  Utils::uint64 _pathDirs;
36  CD::DIRECTION _initPathDir;
38  QueueNode(const Math::Point<Utils::uint>& bin_=Math::Point<Utils::uint>()) : _pathDirs(CD::NONE), _initPathDir(CD::NONE), _bin(bin_) {}
39  };
40 
41  static const Utils::uint64 _maxPathDirs;
42  std::list<QueueNode> _q;
43  std::list<QueueNode>::iterator _front;
44  std::list<QueueNode>::iterator _back;
45  Utils::HashTableUIntKeys<bool> _visitedBins;
46  bool _deletedRightPaths;
47  bool _deletedLeftPaths;
48  bool _deletedUpPaths;
49  bool _deletedDownPaths;
50  bool _deletedForwardPaths;
51  bool _deletedBackwardPaths;
52  public:
53  Queue() : _visitedBins(OpenSkyNet::Utils::INITIAL_TABLE_SIZE,false) {}
54 
55  void init(const Math::Point<Utils::uint>& bin_);
56 
57  inline bool isEmpty() const { return (!(_q.size() > 1)); }
58 
59  inline bool enqueue(CD::DIRECTION dir_, const Math::Point<Utils::uint>& bin_) {
60  if ((!_visitedBins[Utils::getCompositeKey(bin_)]) && (_front->_pathDirs < _maxPathDirs)) {
61  _q.push_back(*_front);
62  _back = _q.end();
63  --_back;
64  _back->_pathDirs = _back->_pathDirs*10+dir_;
65  if (_back->_pathDirs < 10)
66  _back->_initPathDir = static_cast<CD::DIRECTION>(_back->_pathDirs);
67  _back->_bin = bin_;
68  _visitedBins.add(Utils::getCompositeKey(bin_)) = true;
69  return true;
70  }
71  return false;
72  }
73 
75  _q.pop_front();
76  _front = _q.begin();
77  bin_ = _front->_bin;
78  return (static_cast<CD::DIRECTION>(_front->_pathDirs - (_front->_pathDirs/10)*10));
79  }
80 
82 
83  std::vector<CD::DIRECTION> returnFrontPathDirsAsVector() const;
84 
85  inline bool getCurrBin(Math::Point<Utils::uint>& bin_) const {
86  if (!_q.size()) return false;
87  bin_ = _front->_bin;
88  return true;
89  }
90 
91  inline void setVisitedBin(const Math::Point<Utils::uint>& bin_, bool isVisited_) {
92  _visitedBins.add(Utils::getCompositeKey(bin_)) = isVisited_;
93  }
94  };
95  }
96 }
97 
98 #endif //PFQUEUE_H
void init(const Math::Point< Utils::uint > &bin_)
Definition: PFQueue.cpp:17
bool getCurrBin(Math::Point< Utils::uint > &bin_) const
Definition: PFQueue.h:85
bool isEmpty() const
Definition: PFQueue.h:57
User editable constants to finetune the pathfinder's capabilities.
const uint INITIAL_TABLE_SIZE
Definition: UHash.h:34
void deletePathDirsStartingWith(CD::DIRECTION dir_)
Definition: PFQueue.cpp:35
CD::DIRECTION dequeue(Math::Point< Utils::uint > &bin_)
Definition: PFQueue.h:74
Utils::uint getCompositeKey(const Math::Point< Utils::uint > &bin_)
Definition: CDGrid.h:41
DIRECTION
Definition: CDGrid.h:61
std::vector< CD::DIRECTION > returnFrontPathDirsAsVector() const
Definition: PFQueue.cpp:80
unsigned long long uint64
Definition: UTypes.h:43
void setVisitedBin(const Math::Point< Utils::uint > &bin_, bool isVisited_)
Definition: PFQueue.h:91
Definition: PFQueue.h:33
void add(const uint &key_, const T &value_)
Definition: UHash.h:185
Definition: CDGrid.h:61
bool enqueue(CD::DIRECTION dir_, const Math::Point< Utils::uint > &bin_)
Definition: PFQueue.h:59
Queue()
Definition: PFQueue.h:53