nuclear@0: #ifndef COMP_H_ nuclear@0: #define COMP_H_ nuclear@0: nuclear@1: #include nuclear@0: nuclear@6: #ifdef NDEBUG nuclear@6: #define COCAST(type, x) ((type*)x) nuclear@6: #else nuclear@6: #define COCAST(type, x) dynamic_cast(x) nuclear@6: #endif nuclear@6: nuclear@8: // for the second arg of the various gobj_co_whatever() functions nuclear@8: #define COGET_NOFAIL true nuclear@8: #define COGET_FAIL false nuclear@8: nuclear@6: class GObject; nuclear@1: nuclear@0: class Component { nuclear@1: protected: nuclear@2: const char *name; nuclear@6: GObject *gobj; nuclear@6: nuclear@6: /* attach/detach to a particular GObject. nuclear@6: * This is only called from GObject::add_component and nuclear@6: * GObject::remove_component respectively nuclear@6: */ nuclear@6: virtual void attach(GObject *gobj); nuclear@6: virtual void detach(); nuclear@6: nuclear@6: /* Returns an array of component names which depend on this and nuclear@6: * must not be updated first if both exist in the same object. nuclear@6: * Terminated by a null pointer. nuclear@6: */ nuclear@6: virtual const char **update_before() const; nuclear@1: nuclear@0: public: nuclear@2: Component(); nuclear@2: virtual ~Component(); nuclear@1: nuclear@1: const char *get_name() const; nuclear@8: GObject *get_object() const; nuclear@1: nuclear@6: virtual void update(float dt); nuclear@6: virtual void draw() const; nuclear@1: nuclear@6: friend class GObject; nuclear@1: }; nuclear@1: nuclear@2: void register_component(const char *name, Component *(*cons_func)()); nuclear@2: Component *create_component(const char *name); nuclear@0: nuclear@0: #endif // COMP_H_