coeng

view src/comp.h @ 6:2f872a179914

first component test: - prs, xform, physics components with dependencies - topological sort of components to update them in the correct order - debug visualization component todo: remove draw() from components, doesn't make sense
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Feb 2015 07:27:12 +0200
parents 4a1c9597f4d3
children 8cce82794f90
line source
1 #ifndef COMP_H_
2 #define COMP_H_
4 #include <string>
6 #ifdef NDEBUG
7 #define COCAST(type, x) ((type*)x)
8 #else
9 #define COCAST(type, x) dynamic_cast<type*>(x)
10 #endif
12 class GObject;
14 class Component {
15 protected:
16 const char *name;
17 GObject *gobj;
19 /* attach/detach to a particular GObject.
20 * This is only called from GObject::add_component and
21 * GObject::remove_component respectively
22 */
23 virtual void attach(GObject *gobj);
24 virtual void detach();
26 /* Returns an array of component names which depend on this and
27 * must not be updated first if both exist in the same object.
28 * Terminated by a null pointer.
29 */
30 virtual const char **update_before() const;
32 public:
33 Component();
34 virtual ~Component();
36 const char *get_name() const;
38 virtual void update(float dt);
39 virtual void draw() const;
41 friend class GObject;
42 };
44 void register_component(const char *name, Component *(*cons_func)());
45 Component *create_component(const char *name);
47 #endif // COMP_H_