4 #include "blob_exhibit.h"
7 static Exhibit *create_exhibit(const char *type);
9 ExhibitManager::ExhibitManager()
13 ExhibitManager::~ExhibitManager()
18 void ExhibitManager::clear()
20 int num = (int)items.size();
21 for(int i=0; i<num; i++) {
27 void ExhibitManager::add(Exhibit *ex)
29 std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
30 if(it == items.end()) {
35 bool ExhibitManager::remove(Exhibit *ex)
37 std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
38 if(it != items.end()) {
45 bool ExhibitManager::load(MetaScene *mscn, const char *fname)
47 struct ts_node *root = ts_load(fname);
48 if(!root || strcmp(root->name, "exhibits") != 0) {
50 error_log("failed to load exhibits\n");
54 struct ts_node *iter = root->child_list;
56 struct ts_node *node = iter;
59 if(strcmp(node->name, "item") == 0) {
62 const char *amatch = ts_get_attr_str(node, "match_node");
63 if(!amatch || !(snode = mscn->match_node(amatch))) {
64 error_log("ExhibitManager::load: regexp \"%s\" didn't match any nodes\n",
65 amatch ? amatch : "");
70 const char *atype = ts_get_attr_str(node, "type");
71 if(!atype || !(ex = create_exhibit(atype))) {
72 error_log("failed to create exhibit of type: %s\n", atype);
76 const char *desc = ts_get_attr_str(node, "description");
77 const char *voice = ts_get_attr_str(node, "voiceover");
82 exd.text = std::string(desc);
85 exd.voice = new OggVorbisStream;
86 if(!exd.voice->open(voice)) {
87 error_log("failed to open voiceover: %s\n", voice);
92 ex->data.push_back(exd);
104 ExSelection ExhibitManager::select(const Ray &ray) const
110 sel.validmask = EXSEL_RAY;
115 ExSelection ExhibitManager::select(const Sphere &sph) const
121 sel.validmask = EXSEL_SPHERE;
126 void ExhibitManager::update(float dt)
128 int num = items.size();
129 for(int i=0; i<num; i++) {
130 // if the exhibit is not part of a scene graph, first call its
131 // node's update function (otherwise it'll have been called recursively earlier)
132 if(!items[i]->node->get_parent()) {
133 items[i]->node->update(dt);
135 items[i]->update(dt);
139 void ExhibitManager::draw() const
141 int num = items.size();
142 for(int i=0; i<num; i++) {
143 items[i]->pre_draw();
145 items[i]->post_draw();
149 static Exhibit *create_exhibit(const char *type)
151 if(strcmp(type, "static") == 0) {
152 debug_log("creating static exhibit\n");
154 } else if(strcmp(type, "blobs") == 0) {
155 debug_log("creating blobs exhibit\n");
156 return new BlobExhibit;
158 error_log("unknown exhibit type: %s\n", type);