Dragonfly 4.20
A text-based game engine
WorldManager.h
1///
2/// The game world manager
3///
4
5#ifndef __WORLD_MANAGER_H__
6#define __WORLD_MANAGER_H__
7
8#include "Box.h"
9#include "Circle.h"
10#include "Line.h"
11#include "Manager.h"
12#include "ObjectList.h"
13#include "Vector.h"
14#include "SceneGraph.h"
15
16// Two-letter acronym for easier access to manager.
17#define WM df::WorldManager::getInstance()
18
19namespace df {
20
21class WorldManager : public Manager {
22
23 private:
24 WorldManager(); ///< Private since a singleton.
25 WorldManager (WorldManager const&); ///< Don't allow copy.
26 void operator=(WorldManager const&); ///< Don't allow assignment.
27 SceneGraph m_scene_graph; ///< Storage for all Objects, game and view.
28 ObjectList m_deletions; ///< List of all Objects to delete.
29 Object *m_p_view_following; ///< Object view is following.
30 Box m_boundary; ///< World boundary.
31 Box m_view; ///< Player view of game world.
32 Vector m_view_slack; ///< "Slack" for view following.
33
34 public:
35 /// Get the one and only instance of the WorldManager.
37
38 /// Startup game world (initialize everything to empty).
39 /// Return 0.
40 int startUp() override;
41
42 /// Shutdown game world (delete all game world Objects).
43 void shutDown() override;
44
45 /// Accept all user-defined events (returns true).
46 /// Return false for other engine events.
47 bool isValid(std::string event_type) const override;
48
49 /// Add Object to world.
50 /// Return 0 if ok, else -1.
52
53 /// Remove Object from world.
54 /// Return 0 if ok, else -1.
56
57 /// Return list of all Objects in world.
58 /// If inactive is true, include inactive Objects.
59 ObjectList getAllObjects(bool inactive=false) const;
60
61 /// Indicate Object is to be deleted at end of current game loop.
62 /// Return 0 if ok, else -1.
64
65 /// Indicate Objects in list are to be deleted at end of current game loop.
66 /// Return 0 if ok, else -1.
68
69 /// Update world.
70 /// Update positions of Objects based on their velocities.
71 /// Lastly, delete Objects marked for deletion.
72 void update();
73
74 /// Draw all Objects in view.
75 /// Draw bottom up, from 0 to MAX_ALTITUDE.
76 void draw();
77
78 /// Move Object.
79 /// If collision with solid, send collision events.
80 /// If no collision with solid, move ok.
81 /// If all collided objects soft, move ok.
82 /// If Object is spectral, move ok.
83 /// If move ok, move.
84 /// If moved, adjust view if following this Object.
85 /// If moved from inside world boundary to outside, generate EventOut.
86 /// Return 0 if moved, else -1 if collision with solid.
87 int moveObject(Object *p_o, Vector where);
88
89 /// Return list of Objects collided with at position 'where'.
90 /// Collisions only with solid Objects.
91 /// Does not consider if p_o is solid or not.
93
94 /// Return Object with indicated id.
95 /// NULL if Object is not found.
96 Object *objectWithId(int id) const;
97
98 /// Return list of Objects matching type.
99 /// List is empty if none found.
100 ObjectList objectsOfType(std::string type);
101
102 /// Return list of all Objects at position 'where'.
103 /// Does include bounding boxes. Return empty list if none found.
105
106 /// Return list of all Objects in Box.
107 /// Does include bounding boxes. Return empty list if none found.
109
110 /// Return a list of all Objects on line from point1 to point2.
111 /// Does include bounding boxes. Return empty list if none found.
113
114 /// Return a list of all Objects in circle.
115 /// Does include bounding boxes. Return empty list if none found.
117
118 // Return all solid Objects. Empty list if none.
119 ObjectList solidObjects() const;
120
121 /// Get game world boundary.
123
124 /// Set game world boundary.
125 void setBoundary(Box new_boundary);
126
127 /// Get player view of game world.
128 Box getView() const;
129
130 /// Set player view of game world.
131 void setView(Box new_view);
132
133 /// Get player "slack" for view following.
134 /// Units are in fraction of view (0-1).
136
137 /// Set player "slack" for view following.
138 /// Units are in fraction of view (0-1).
139 void setViewSlack(Vector new_slack);
140
141 /// Set view to center screen on Object.
142 /// Set to NULL to stop following.
143 /// If Object not legit, return -1 else return 0.
144 int setViewFollowing(Object *p_new_view_following);
145
146 /// Get Object view is following (NULL if none).
148
149 /// Set view to center screen on position view_pos.
150 /// View edge will not go beyond world boundary.
151 void setViewPosition(Vector view_pos);
152
153 /// Return reference to SceneGraph.
155};
156
157} // end of namespace df
158#endif // __WORLD_MANAGER_H__
Definition: Box.h:16
Definition: Circle.h:12
Definition: Line.h:12
Definition: Manager.h:24
Definition: ObjectList.h:15
Definition: Object.h:57
Definition: SceneGraph.h:41
Definition: Vector.h:12
Definition: WorldManager.h:21
Box m_view
Player view of game world.
Definition: WorldManager.h:31
Box getView() const
Get player view of game world.
int markForDelete(Object *p_o)
Indicate Object is to be deleted at end of current game loop.
void setBoundary(Box new_boundary)
Set game world boundary.
void operator=(WorldManager const &)
Don't allow assignment.
int insertObject(Object *p_o)
Add Object to world.
void setViewSlack(Vector new_slack)
Set player "slack" for view following.
void setView(Box new_view)
Set player view of game world.
SceneGraph & getSceneGraph() const
Return reference to SceneGraph.
Object * m_p_view_following
Object view is following.
Definition: WorldManager.h:29
SceneGraph m_scene_graph
Storage for all Objects, game and view.
Definition: WorldManager.h:27
ObjectList objectsAtPosition(Vector where) const
Return list of all Objects at position 'where'.
void update()
Update world.
ObjectList getCollisions(Object *p_o, Vector where) const
Return list of Objects collided with at position 'where'.
WorldManager(WorldManager const &)
Don't allow copy.
WorldManager()
Private since a singleton.
ObjectList m_deletions
List of all Objects to delete.
Definition: WorldManager.h:28
void shutDown() override
Shutdown game world (delete all game world Objects).
int removeObject(Object *p_o)
Remove Object from world.
Object * getViewFollowing() const
Get Object view is following (NULL if none).
Object * objectWithId(int id) const
Return Object with indicated id.
int markForDelete(ObjectList obj_list)
Indicate Objects in list are to be deleted at end of current game loop.
ObjectList objectsOnLine(Line line) const
Return a list of all Objects on line from point1 to point2.
void draw()
Draw all Objects in view.
int moveObject(Object *p_o, Vector where)
Move Object.
Box getBoundary() const
Get game world boundary.
bool isValid(std::string event_type) const override
Accept all user-defined events (returns true).
ObjectList objectsInBox(Box box) const
Return list of all Objects in Box.
int setViewFollowing(Object *p_new_view_following)
Set view to center screen on Object.
ObjectList objectsOfType(std::string type)
Return list of Objects matching type.
ObjectList getAllObjects(bool inactive=false) const
Return list of all Objects in world.
int startUp() override
Startup game world (initialize everything to empty).
static WorldManager & getInstance()
Get the one and only instance of the WorldManager.
void setViewPosition(Vector view_pos)
Set view to center screen on position view_pos.
Vector m_view_slack
"Slack" for view following.
Definition: WorldManager.h:32
Vector getViewSlack() const
Get player "slack" for view following.
Box m_boundary
World boundary.
Definition: WorldManager.h:30
ObjectList objectsInCircle(Circle circle) const
Return a list of all Objects in circle.
An animation for a sprite.
Definition: Animation.h:15