nuclear@4: #include nuclear@2: #include nuclear@2: #include nuclear@2: #include "comp.h" nuclear@2: nuclear@4: static std::map *early_comp_cons; nuclear@2: static std::map comp_cons; nuclear@2: nuclear@2: Component::Component() nuclear@2: { nuclear@2: name = "unknown"; nuclear@2: gobj = 0; nuclear@2: } nuclear@2: nuclear@2: Component::~Component() nuclear@2: { nuclear@2: } nuclear@2: nuclear@6: void Component::attach(GObject *gobj) nuclear@6: { nuclear@6: this->gobj = gobj; nuclear@6: } nuclear@6: nuclear@6: void Component::detach() nuclear@6: { nuclear@6: gobj = 0; nuclear@6: } nuclear@6: nuclear@6: const char **Component::update_before() const nuclear@6: { nuclear@6: static const char *before[] = { 0 }; nuclear@6: return before; nuclear@6: } nuclear@6: nuclear@2: const char *Component::get_name() const nuclear@2: { nuclear@2: return name; nuclear@2: } nuclear@2: nuclear@8: GObject *Component::get_object() const nuclear@8: { nuclear@8: return gobj; nuclear@8: } nuclear@8: nuclear@6: void Component::update(float dt) nuclear@2: { nuclear@2: } nuclear@2: nuclear@6: void Component::draw() const nuclear@2: { nuclear@2: } nuclear@2: nuclear@2: void register_component(const char *name, Component *(*cons_func)()) nuclear@2: { nuclear@4: if(!early_comp_cons) { nuclear@4: early_comp_cons = new std::map; nuclear@4: } nuclear@4: nuclear@4: if(!(*early_comp_cons)[name]) { nuclear@3: printf("register component: %s\n", name); nuclear@4: (*early_comp_cons)[name] = cons_func; nuclear@3: } nuclear@2: } nuclear@2: nuclear@2: Component *create_component(const char *name) nuclear@2: { nuclear@4: if(early_comp_cons) { nuclear@4: comp_cons = std::move(*early_comp_cons); nuclear@4: delete early_comp_cons; nuclear@4: early_comp_cons = 0; nuclear@4: } nuclear@4: nuclear@2: Component *(*cons)() = comp_cons[name]; nuclear@2: if(cons) { nuclear@2: return cons(); nuclear@2: } nuclear@2: return 0; nuclear@2: }