Roguelike
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gameobject.h
Go to the documentation of this file.
1 #ifndef ROGUELIKE_BASE_GAMEOBJECT_H_
2 #define ROGUELIKE_BASE_GAMEOBJECT_H_
3 
4 // Inheritance
5 #include <ugdk/action/entity.h>
6 
7 // External Dependencies
8 #include <set>
9 #include <string>
10 #include <ugdk/portable/tr1.h>
11 #include FROM_TR1(functional)
12 #include <list> // template class
13 #include <ugdk/math/vector2D.h> // needed for dimensions_
14 
15 // Internal Dependencies
17 
18 // Forward Declarations
19 #include "game/base.h"
20 #include "game/component.h"
21 
22 // Defines
23 #define FORALL_UPDATEABLE_COMPONENTS(action) \
24  action( graphic, Graphic)
25 
26 #define FORALL_COMPONENTS(action) \
27  action( controller, Controller) \
28  action( vision, Vision) \
29  action( damageable, Damageable) \
30  action( energy, Energy) \
31  action( shape, Shape) \
32  action( graphic, Graphic) \
33  action( sound, Sound)
34 
35 
36 #define FULL_TYPE(type) component::type*
37 
38 #define INI_FULLTYPE_ARG_DECLARATION(compo,type) FULL_TYPE(type) compo##_component,
39 
40 #define GETTER_DECLARATION(compo,type) \
41  FULL_TYPE(type) compo##_component() { return compo##_component_; } \
42  const FULL_TYPE(type) compo##_component() const { return compo##_component_; }
43 
44 #define SETTER_DECLARATION(compo,type) \
45  void set_##compo##_component(FULL_TYPE(type) compo##_component) { compo##_component_ = compo##_component; }
46 
47 #define ATTRIBUTES_DECLARATION(compo,type) FULL_TYPE(type) compo##_component_;
48 
49 
50 namespace game {
51 namespace base {
52 
53 class GameObject : public ugdk::action::Entity {
54  typedef ugdk::action::Entity super;
55  public:
56  GameObject();
57  ~GameObject();
58 
59  void Initialize(
61  const std::tr1::function<void (void)>& die = std::tr1::function<void (void)>()
62  );
63 
64  void Update(double dt);
65 
68 
69  void Die();
70  bool dead() const { return to_be_removed_; }
71 
72  void OnSceneAdd(ugdk::action::Scene* scene);
73 
74  private:
75  FORALL_COMPONENTS(ATTRIBUTES_DECLARATION) // note lack of ";"
76 
77  std::tr1::function<void (void)> die_;
78 };
79 
80 } // namespace base
81 } // namespace game
82 
83 #endif // ROGUELIKE_BASE_GAMEOBJECT_H_
void Initialize(FORALL_COMPONENTS(INI_FULLTYPE_ARG_DECLARATION) const std::tr1::function< void(void)> &die=std::tr1::function< void(void)>())
Definition: gameobject.h:53
#define GETTER_DECLARATION(compo, type)
Definition: gameobject.h:40
#define SETTER_DECLARATION(compo, type)
Definition: gameobject.h:44
Definition: aim.cc:15
void OnSceneAdd(ugdk::action::Scene *scene)
#define INI_FULLTYPE_ARG_DECLARATION(compo, type)
Definition: gameobject.h:38
void Update(double dt)
#define ATTRIBUTES_DECLARATION(compo, type)
Definition: gameobject.h:47
bool dead() const
Definition: gameobject.h:70
FORALL_COMPONENTS(GETTER_DECLARATION) FORALL_COMPONENTS(SETTER_DECLARATION) void Die()