coeng
annotate 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 |
rev | line source |
---|---|
nuclear@0 | 1 #ifndef COMP_H_ |
nuclear@0 | 2 #define COMP_H_ |
nuclear@0 | 3 |
nuclear@1 | 4 #include <string> |
nuclear@0 | 5 |
nuclear@6 | 6 #ifdef NDEBUG |
nuclear@6 | 7 #define COCAST(type, x) ((type*)x) |
nuclear@6 | 8 #else |
nuclear@6 | 9 #define COCAST(type, x) dynamic_cast<type*>(x) |
nuclear@6 | 10 #endif |
nuclear@6 | 11 |
nuclear@6 | 12 class GObject; |
nuclear@1 | 13 |
nuclear@0 | 14 class Component { |
nuclear@1 | 15 protected: |
nuclear@2 | 16 const char *name; |
nuclear@6 | 17 GObject *gobj; |
nuclear@6 | 18 |
nuclear@6 | 19 /* attach/detach to a particular GObject. |
nuclear@6 | 20 * This is only called from GObject::add_component and |
nuclear@6 | 21 * GObject::remove_component respectively |
nuclear@6 | 22 */ |
nuclear@6 | 23 virtual void attach(GObject *gobj); |
nuclear@6 | 24 virtual void detach(); |
nuclear@6 | 25 |
nuclear@6 | 26 /* Returns an array of component names which depend on this and |
nuclear@6 | 27 * must not be updated first if both exist in the same object. |
nuclear@6 | 28 * Terminated by a null pointer. |
nuclear@6 | 29 */ |
nuclear@6 | 30 virtual const char **update_before() const; |
nuclear@1 | 31 |
nuclear@0 | 32 public: |
nuclear@2 | 33 Component(); |
nuclear@2 | 34 virtual ~Component(); |
nuclear@1 | 35 |
nuclear@1 | 36 const char *get_name() const; |
nuclear@1 | 37 |
nuclear@6 | 38 virtual void update(float dt); |
nuclear@6 | 39 virtual void draw() const; |
nuclear@1 | 40 |
nuclear@6 | 41 friend class GObject; |
nuclear@1 | 42 }; |
nuclear@1 | 43 |
nuclear@2 | 44 void register_component(const char *name, Component *(*cons_func)()); |
nuclear@2 | 45 Component *create_component(const char *name); |
nuclear@0 | 46 |
nuclear@0 | 47 #endif // COMP_H_ |