X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fexman.cc;h=28f3700c80aad471881484467e282ce2a7bdb686;hp=e0ededc9c07165cf358efb8b636291dfe2b4050c;hb=b75b6703809abf0dc02f2e557ba73e9efbefa4d1;hpb=bfceaade5df3177a3e213fe20bc3811b2f78ac98 diff --git a/src/exman.cc b/src/exman.cc index e0ededc..28f3700 100644 --- a/src/exman.cc +++ b/src/exman.cc @@ -1,6 +1,8 @@ +#include #include "exman.h" #include "exhibit.h" #include "blob_exhibit.h" +#include "treestore.h" static Exhibit *create_exhibit(const char *type); @@ -10,6 +12,11 @@ ExhibitManager::ExhibitManager() ExhibitManager::~ExhibitManager() { + clear(); +} + +void ExhibitManager::clear() +{ int num = (int)items.size(); for(int i=0; i::iterator it = std::find(items.begin(), items.end(), ex); + if(it == items.end()) { + items.push_back(ex); + } +} + +bool ExhibitManager::remove(Exhibit *ex) +{ + std::vector::iterator it = std::find(items.begin(), items.end(), ex); + if(it != items.end()) { + items.erase(it); + return true; + } + return false; +} + +bool ExhibitManager::load(MetaScene *mscn, const char *fname) { struct ts_node *root = ts_load(fname); if(!root || strcmp(root->name, "exhibits") != 0) { @@ -26,17 +51,74 @@ bool ExhibitManager::load(const MetaScene *mscn, const char *fname) return false; } + struct ts_node *iter = root->child_list; + while(iter) { + struct ts_node *node = iter; + iter = iter->next; + + if(strcmp(node->name, "item") == 0) { + SceneNode *snode; + + const char *amatch = ts_get_attr_str(node, "match_node"); + if(!amatch || !(snode = mscn->match_node(amatch))) { + error_log("ExhibitManager::load: regexp \"%s\" didn't match any nodes\n", + amatch ? amatch : ""); + continue; + } + + Exhibit *ex; + const char *atype = ts_get_attr_str(node, "type"); + if(!atype || !(ex = create_exhibit(atype))) { + error_log("failed to create exhibit of type: %s\n", atype); + continue; + } + + ex->set_node(snode); + items.push_back(ex); + } + } + ts_free_tree(root); return true; } +ExSelection ExhibitManager::select(const Ray &ray) const +{ + return ExSelection(); // TODO +} + +ExSelection ExhibitManager::select(const Sphere &sph) const +{ + return ExSelection(); // TODO +} + +void ExhibitManager::update(float dt) +{ + int num = items.size(); + for(int i=0; iupdate(dt); + } +} + +void ExhibitManager::draw() const +{ + int num = items.size(); + for(int i=0; ipre_draw(); + items[i]->draw(); + items[i]->post_draw(); + } +} static Exhibit *create_exhibit(const char *type) { if(strcmp(type, "static") == 0) { + debug_log("creating static exhibit\n"); return new Exhibit; } else if(strcmp(type, "blobs") == 0) { + debug_log("creating blobs exhibit\n"); return new BlobExhibit; } + error_log("unknown exhibit type: %s\n", type); return 0; }