Planeshift
celgraph.h
Go to the documentation of this file.
1 /* Crystal Space Entity Layer
2  Copyright (C) 2006 by Jorrit Tyberghein
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public
15  License along with this library; if not, write to the Free
16  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #ifndef __CEL_TOOLS_CELGRAPH__
20 #define __CEL_TOOLS_CELGRAPH__
21 
22 #include "csutil/csobject.h"
23 #include "csutil/util.h"
24 #include "csutil/hash.h"
25 #include "csutil/redblacktree.h"
26 #include "csutil/weakrefarr.h"
27 #include "csutil/stringarray.h"
28 #include "csutil/eventhandlers.h"
29 #include "iutil/comp.h"
30 #include "iutil/eventh.h"
31 #include "iutil/eventq.h"
32 #include "ivaria/conin.h"
33 #include "ivaria/conout.h"
34 
35 #include "tools/celgraph.h"
36 
37 #include <stdio.h>
38 #include <string.h>
39 
43 class celEdge : public scfImplementation1<
44  celEdge, iCelEdge>
45 {
46  private:
47  csRef<iCelNode> successor;
48  bool state;
49  float weight;
50 
51  public:
52  celEdge ();
53  virtual ~celEdge ();
54  virtual void SetState (bool open);
55  virtual void SetSuccessor (iCelNode* node);
56  virtual bool GetState ();
57  virtual iCelNode* GetSuccessor ();
58  virtual float GetWeight () const;
59  virtual void SetWeight (float weight);
60 };
61 
62 class celNode : public scfImplementation1<
63  celNode, iCelNode>
64 {
65  private:
66  csRefArray<iCelEdge> edges;
67  csRef<iMapNode> map_node;
68  csRef<iCelNode> parent;
69  float heuristic;
70  float cost;
71  csString name;
72 
73  public:
74  celNode ();
75  virtual ~celNode ();
76  virtual size_t AddSuccessor (iCelNode* node, bool state);
77  virtual void SetMapNode (iMapNode* node);
78  virtual void SetParent (iCelNode* par);
79  virtual void SetName (const char* n);
80  virtual void Heuristic (float cost, iCelNode* goal);
81  virtual iMapNode* GetMapNode ();
82  virtual csVector3 GetPosition ();
83  virtual const char* GetName ();
84  virtual iCelNode* GetParent () {return parent;}
85  virtual csArray<iCelNode*> GetSuccessors ();
86  virtual csArray<iCelNode*> GetAllSuccessors ();
87  virtual float GetHeuristic () {return heuristic;};
88  virtual float GetCost () {return cost;};
89  virtual size_t GetEdgeCount ()
90  { return edges.GetSize(); }
91  virtual iCelEdge* GetEdge (size_t idx)
92  { return edges.Get(idx); }
93  virtual void RemoveEdge (size_t idx);
94  virtual size_t AddSuccessor (iCelNode* node, bool state, float weight);
95  virtual csRefArray<iCelEdge>* GetEdges ();
96 };
97 
103 celPath, csObject, iCelPath, iComponent>
104 {
105  private:
106  iObjectRegistry* object_reg;
107  size_t cur_node;
108  csRefArray<iMapNode> nodes;
109 
110  public:
111  celPath (iBase* parent);
112  virtual ~celPath ();
113  virtual iObject* QueryObject () { return this; }
114  virtual void AddNode (iMapNode* node);
115  virtual void InsertNode (size_t pos, iMapNode* node);
116  virtual iMapNode* Next ();
117  virtual iMapNode* Previous ();
118  virtual iMapNode* Current ();
119  virtual csVector3 CurrentPosition ();
120  virtual iSector* CurrentSector ();
121  virtual bool HasNext ();
122  virtual bool HasPrevious ();
123  virtual void Restart ();
124  virtual void Clear ();
125  virtual bool Initialize (iObjectRegistry* object_reg);
126  virtual iMapNode* GetFirst ();
127  virtual iMapNode* GetLast ();
128  virtual void Invert ();
129  virtual size_t GetNodeCount ()
130  { return nodes.GetSize(); }
131 };
132 
137  celGraph, csObject, iCelGraph, iComponent>
138 {
139 private:
140  iObjectRegistry* object_reg;
141  csRefArray <iCelNode> nodes;
142 
143 public:
144  celGraph (iBase* parent);
145  virtual ~celGraph ();
146  virtual iObject* QueryObject () { return this; }
147  virtual bool Initialize (iObjectRegistry* object_reg);
148  virtual iCelNode* CreateNode (const char *name, csVector3 &pos);
149  virtual size_t AddNode (iCelNode* node);
150  virtual void AddEdge (iCelNode* from, iCelNode* to, bool state);
151  virtual bool AddEdgeByNames (const char* from, const char* to, bool state);
152  virtual iCelNode* GetClosest (csVector3 position);
153  virtual bool ShortestPath (iCelNode* from, iCelNode* goal, iCelPath* path);
154  virtual iCelNode* RandomPath (iCelNode* from, int distance, iCelPath* path);
155  virtual size_t GetNodeCount ()
156  { return nodes.GetSize(); }
157  virtual iCelNode* GetNode (size_t idx)
158  { return nodes.Get(idx); }
159  virtual void RemoveNode (size_t idx);
160  virtual void RemoveEdge (iCelNode* from, size_t idx);
161  virtual size_t AddEdge (iCelNode* from, iCelNode* to, bool state, float weight);
162  virtual iCelNode* CreateEmptyNode (size_t& index);
163  virtual bool ShortestPath2 (iCelNode* from, iCelNode* goal, iCelPath* path);
164 };
165 
166 #endif //__CEL_TOOLS_CELGRAPH__
167 
virtual iCelNode * GetParent()
Definition: celgraph.h:84
const char * GetName(int id)
This is a mapnode Graph for CEL.
Definition: celgraph.h:136
virtual size_t GetEdgeCount()
Definition: celgraph.h:89
virtual float GetWeight() const
This is a mapnode Graph for CEL.
Definition: celgraph.h:43
virtual float GetHeuristic()
Definition: celgraph.h:87
virtual float GetCost()
Definition: celgraph.h:88
virtual bool GetState()
virtual iObject * QueryObject()
Definition: celgraph.h:113
virtual size_t GetNodeCount()
Definition: celgraph.h:155
void void Initialize(iObjectRegistry *object_reg)
virtual void SetWeight(float weight)
virtual void SetState(bool open)
virtual iCelNode * GetSuccessor()
virtual iCelNode * GetNode(size_t idx)
Definition: celgraph.h:157
virtual iCelEdge * GetEdge(size_t idx)
Definition: celgraph.h:91
virtual void SetSuccessor(iCelNode *node)
This is a mapnode Path for CEL.
Definition: celgraph.h:102
virtual size_t GetNodeCount()
Definition: celgraph.h:129
virtual ~celEdge()
virtual iObject * QueryObject()
Definition: celgraph.h:146