Dragonfly 4.20
A text-based game engine
SceneGraph.h
1///
2/// A scene graph
3///
4
5#ifndef __SCENE_GRAPH_H__
6#define __SCENE_GRAPH_H__
7
8// Uncomment exactly one of the below.
9//#define SG_SIMP // simple scene graph (no Quadtree, no Grid)
10//#define SG_QUAD // Quadtree scene graph
11#define SG_GRID // Grid scene graph
12
13// System includes.
14#include <map>
15
16// Engine includes.
17#ifdef SG_GRID
18#include "Grid.h"
19#endif
20#include "Object.h"
21#include "ObjectList.h"
22#ifdef SG_QUAD
23#include "QuadtreeNode.h"
24#endif
25
26// Check exactly one of SG_SIMP, SG_QUAD, SG_GRID is defined.
27#if !defined(SG_SIMP) && !defined(SG_QUAD) && !defined(SG_GRID)
28#pragma message "Must #define exactly one of: SG_SIMPLE, SG_QUAD, SG_GRID"
29#elif defined(SG_SIMP) && (defined(SG_QUAD) || defined(SG_GRID))
30#pragma message "Must #define exactly one of: SG_SIMPLE, SG_QUAD, SG_GRID"
31#elif defined(SG_QUAD) && (defined(SG_SIMP) || defined(SG_GRID))
32#pragma message "Must #define exactly one of: SG_SIMPLE, SG_QUAD, SG_GRID"
33#elif defined(SG_GRID) && (defined(SG_SIMP) || defined(SG_QUAD))
34#pragma message "Must #define exactly one of: SG_SIMPLE, SG_QUAD, SG_GRID"
35#endif
36
37namespace df {
38
39const int MAX_ALTITUDE = 4;
40
42
43 private:
44 ObjectList m_active_objects; ///< All active Objects.
45 ObjectList m_solid_objects; ///< Solid Objects.
46 ObjectList m_visible_objects[MAX_ALTITUDE+1]; ///< Visible Objects.
47 ObjectList m_inactive_objects; ///< All inactive Objects.
48 std::map<std::string, ObjectList> m_type; ///< Map of type:Object
49#ifdef SG_GRID
50 Grid m_grid; ///< Grid for collision detection.
51#endif
52#ifdef SG_QUAD
53 QuadtreeNode *m_p_qt; ///< Quadtree for collision detection.
54#endif
55
56 public:
57 SceneGraph();
59
60 /// Insert Object into SceneGraph.
61 /// Return 0 if ok, else -1.
63
64 /// Remove Object from SceneGraph.
65 /// Return 0 if ok, else -1.
67
68 /// Return all active Objects. Empty list if none.
70
71 /// Return all active, solid Objects. Empty list if none.
73
74 /// Return all active, visible Objects at altitude. Empty list if none.
75 ObjectList visibleObjects(int altitude) const;
76
77 /// Return list of Objects matching type.
78 /// List is empty if none found.
79 ObjectList objectsOfType(std::string type);
80
81 /// Return all inactive Objects. Empty list if none.
83
84 /// Re-position Object in SceneGraph to new altitude.
85 /// Return 0 if ok, else -1.
86 int updateAltitude(Object *p_o, int new_alt);
87
88 /// Re-position Object in SceneGraph to new solidness.
89 /// Return 0 if ok, else -1.
90 int updateSolidness(Object *p_o, Solidness new_solidness);
91
92 /// Re-position Object in SceneGraph to new visibility.
93 /// Return 0 if ok, else -1.
94 int updateVisible(Object *p_vo, bool new_visible);
95
96 /// Re-position Object in SceneGraph to new activeness.
97 /// Return 0 if ok, else -1.
98 int updateActive(Object *p_o, bool new_active);
99
100 /// Set position of Object in SceneGraph.
101 /// Return 0 if ok, else -1.
102 int updatePosition(Object *p_o, Vector new_position);
103
104 /// Re-position Object in SceneGraph to new type.
105 /// Return 0 if ok, else -1.
106 int updateType(Object *p_o, std::string new_type);
107
108 /// Return list of solid Objects collided with at position 'where'.
109 /// Does not consider if p_o is solid or not.
111
112#ifdef SG_GRID
113 /// Get Grid.
115#endif
116
117#ifdef SG_QUAD
118 /// Get Quadtree.
119 QuadtreeNode *getQuadtree() const;
120#endif
121
122 /// Startup Scenegraph (create Grid).
123 /// Return 0 if ok, else -1.
124 int startUp();
125
126 /// Shutdown Scenegraph (delete Quadtree, clear Grid).
127 void shutDown();
128};
129
130} // end of namespace df
131#endif // __SCENE_GRAPH_H__
Definition: Grid.h:22
Definition: ObjectList.h:15
Definition: Object.h:57
Definition: QuadtreeNode.h:16
Definition: SceneGraph.h:41
int updateType(Object *p_o, std::string new_type)
Re-position Object in SceneGraph to new type.
ObjectList visibleObjects(int altitude) const
Return all active, visible Objects at altitude. Empty list if none.
ObjectList m_visible_objects[MAX_ALTITUDE+1]
Visible Objects.
Definition: SceneGraph.h:46
void shutDown()
Shutdown Scenegraph (delete Quadtree, clear Grid).
int startUp()
Startup Scenegraph (create Grid).
int updateSolidness(Object *p_o, Solidness new_solidness)
Re-position Object in SceneGraph to new solidness.
ObjectList activeObjects() const
Return all active Objects. Empty list if none.
ObjectList solidObjects() const
Return all active, solid Objects. Empty list if none.
Grid m_grid
Grid for collision detection.
Definition: SceneGraph.h:50
int insertObject(Object *p_o)
Insert Object into SceneGraph.
ObjectList m_inactive_objects
All inactive Objects.
Definition: SceneGraph.h:47
ObjectList m_solid_objects
Solid Objects.
Definition: SceneGraph.h:45
Grid * getGrid()
Get Grid.
int removeObject(Object *p_o)
Remove Object from SceneGraph.
ObjectList getCollisions(Object *p_o, Vector where) const
Return list of solid Objects collided with at position 'where'.
ObjectList m_active_objects
All active Objects.
Definition: SceneGraph.h:44
ObjectList objectsOfType(std::string type)
Return list of Objects matching type.
int updateActive(Object *p_o, bool new_active)
Re-position Object in SceneGraph to new activeness.
int updatePosition(Object *p_o, Vector new_position)
Set position of Object in SceneGraph.
int updateVisible(Object *p_vo, bool new_visible)
Re-position Object in SceneGraph to new visibility.
std::map< std::string, ObjectList > m_type
Map of type:Object.
Definition: SceneGraph.h:48
int updateAltitude(Object *p_o, int new_alt)
Re-position Object in SceneGraph to new altitude.
ObjectList inactiveObjects() const
Return all inactive Objects. Empty list if none.
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15
Solidness
Types of solidness of Object.
Definition: Object.h:26