Dragonfly 4.20
A text-based game engine
Manager.h
1///
2/// The base manager
3///
4
5#ifndef __MANAGER_H__
6#define __MANAGER_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Event.h"
13#include "Object.h"
14#include "ObjectList.h"
15
16namespace df {
17
18const int MAX_EVENTS = 100; ///< Max number of different events.
19
20#ifndef DF_REGISTER_INTEREST
21#define DF_REGISTER_INTEREST // registerInterest() defined.
22#endif
23
24class Manager {
25
26 private:
27 std::string m_type; ///< Manager type identifier.
28 int m_event_count; ///< Number of events.
29 std::string m_event_name[MAX_EVENTS]; ///< List of events.
30 ObjectList m_obj_list[MAX_EVENTS]; ///< Objects interested in event.
31 bool m_is_started; ///< True if startUp() succeeded
32
33 /// Check if event is handled by this Manager.
34 /// If handled, return true else false.
35 /// (Base Manager always returns false.)
36 virtual bool isValid(std::string event_type) const;
37
38 protected:
39 /// Set type identifier of Manager.
40 void setType(std::string new_type);
41
42 public:
43 Manager();
44 virtual ~Manager();
45
46 /// Get type identifier of Manager.
47 std::string getType() const;
48
49 /// Startup Manager.
50 /// Return 0 if ok, else negative number.
51 virtual int startUp();
52
53 /// Shutdown Manager.
54 virtual void shutDown();
55
56 /// Return status of is_started (true when startUp() was successful).
57 bool isStarted() const;
58
59 /// Send event to all interested Objects.
60 /// Return count of number of events sent.
61 int onEvent(const Event *p_event) const;
62
63 /// Indicate interest in event.
64 /// Return 0 if ok, else -1.
65 /// (Note, doesn't check to see if Object is already registered.)
66 int registerInterest(Object *p_o, std::string event_type);
67
68 /// Indicate no more interest in event.
69 /// Return 0 if ok, else -1.
70 int unregisterInterest(Object *p_o, std::string event_type);
71
72};
73
74} // end of namespace df
75#endif // __MANAGER_H__
Definition: Event.h:15
Definition: Manager.h:24
ObjectList m_obj_list[MAX_EVENTS]
Objects interested in event.
Definition: Manager.h:30
int onEvent(const Event *p_event) const
Send event to all interested Objects.
virtual void shutDown()
Shutdown Manager.
std::string getType() const
Get type identifier of Manager.
std::string m_event_name[MAX_EVENTS]
List of events.
Definition: Manager.h:29
int unregisterInterest(Object *p_o, std::string event_type)
Indicate no more interest in event.
virtual bool isValid(std::string event_type) const
Check if event is handled by this Manager.
int m_event_count
Number of events.
Definition: Manager.h:28
int registerInterest(Object *p_o, std::string event_type)
Indicate interest in event.
bool m_is_started
True if startUp() succeeded.
Definition: Manager.h:31
virtual int startUp()
Startup Manager.
void setType(std::string new_type)
Set type identifier of Manager.
std::string m_type
Manager type identifier.
Definition: Manager.h:27
bool isStarted() const
Return status of is_started (true when startUp() was successful).
Definition: ObjectList.h:15
Definition: Object.h:57
An animation for a sprite.
Definition: Animation.h:15
const int MAX_EVENTS
Max number of different events.
Definition: Manager.h:18