coeng
annotate src/comp.cc @ 9:49fdb15f1100
added makefile rule to download and unpack the obj file
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Feb 2015 05:23:09 +0200 |
parents | 2f872a179914 |
children |
rev | line source |
---|---|
nuclear@4 | 1 #include <stdio.h> |
nuclear@2 | 2 #include <map> |
nuclear@2 | 3 #include <string> |
nuclear@2 | 4 #include "comp.h" |
nuclear@2 | 5 |
nuclear@4 | 6 static std::map<std::string, Component *(*)()> *early_comp_cons; |
nuclear@2 | 7 static std::map<std::string, Component *(*)()> comp_cons; |
nuclear@2 | 8 |
nuclear@2 | 9 Component::Component() |
nuclear@2 | 10 { |
nuclear@2 | 11 name = "unknown"; |
nuclear@2 | 12 gobj = 0; |
nuclear@2 | 13 } |
nuclear@2 | 14 |
nuclear@2 | 15 Component::~Component() |
nuclear@2 | 16 { |
nuclear@2 | 17 } |
nuclear@2 | 18 |
nuclear@6 | 19 void Component::attach(GObject *gobj) |
nuclear@6 | 20 { |
nuclear@6 | 21 this->gobj = gobj; |
nuclear@6 | 22 } |
nuclear@6 | 23 |
nuclear@6 | 24 void Component::detach() |
nuclear@6 | 25 { |
nuclear@6 | 26 gobj = 0; |
nuclear@6 | 27 } |
nuclear@6 | 28 |
nuclear@6 | 29 const char **Component::update_before() const |
nuclear@6 | 30 { |
nuclear@6 | 31 static const char *before[] = { 0 }; |
nuclear@6 | 32 return before; |
nuclear@6 | 33 } |
nuclear@6 | 34 |
nuclear@2 | 35 const char *Component::get_name() const |
nuclear@2 | 36 { |
nuclear@2 | 37 return name; |
nuclear@2 | 38 } |
nuclear@2 | 39 |
nuclear@8 | 40 GObject *Component::get_object() const |
nuclear@8 | 41 { |
nuclear@8 | 42 return gobj; |
nuclear@8 | 43 } |
nuclear@8 | 44 |
nuclear@6 | 45 void Component::update(float dt) |
nuclear@2 | 46 { |
nuclear@2 | 47 } |
nuclear@2 | 48 |
nuclear@6 | 49 void Component::draw() const |
nuclear@2 | 50 { |
nuclear@2 | 51 } |
nuclear@2 | 52 |
nuclear@2 | 53 void register_component(const char *name, Component *(*cons_func)()) |
nuclear@2 | 54 { |
nuclear@4 | 55 if(!early_comp_cons) { |
nuclear@4 | 56 early_comp_cons = new std::map<std::string, Component *(*)()>; |
nuclear@4 | 57 } |
nuclear@4 | 58 |
nuclear@4 | 59 if(!(*early_comp_cons)[name]) { |
nuclear@3 | 60 printf("register component: %s\n", name); |
nuclear@4 | 61 (*early_comp_cons)[name] = cons_func; |
nuclear@3 | 62 } |
nuclear@2 | 63 } |
nuclear@2 | 64 |
nuclear@2 | 65 Component *create_component(const char *name) |
nuclear@2 | 66 { |
nuclear@4 | 67 if(early_comp_cons) { |
nuclear@4 | 68 comp_cons = std::move(*early_comp_cons); |
nuclear@4 | 69 delete early_comp_cons; |
nuclear@4 | 70 early_comp_cons = 0; |
nuclear@4 | 71 } |
nuclear@4 | 72 |
nuclear@2 | 73 Component *(*cons)() = comp_cons[name]; |
nuclear@2 | 74 if(cons) { |
nuclear@2 | 75 return cons(); |
nuclear@2 | 76 } |
nuclear@2 | 77 return 0; |
nuclear@2 | 78 } |