5 #include "blob_exhibit.h"
8 static Exhibit *create_exhibit(const char *type);
10 ExhibitManager::ExhibitManager()
14 ExhibitManager::~ExhibitManager()
19 void ExhibitManager::clear()
21 int num = (int)items.size();
22 for(int i=0; i<num; i++) {
28 void ExhibitManager::add(Exhibit *ex)
30 std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
31 if(it == items.end()) {
36 bool ExhibitManager::remove(Exhibit *ex)
38 std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
39 if(it != items.end()) {
46 bool ExhibitManager::load(MetaScene *mscn, const char *fname)
48 struct ts_node *root = ts_load(fname);
49 if(!root || strcmp(root->name, "exhibits") != 0) {
51 error_log("failed to load exhibits\n");
55 struct ts_node *iter = root->child_list;
57 struct ts_node *node = iter;
60 if(strcmp(node->name, "item") == 0) {
63 const char *amatch = ts_get_attr_str(node, "match_node");
64 if(!amatch || !(snode = mscn->match_node(amatch))) {
65 error_log("ExhibitManager::load: regexp \"%s\" didn't match any nodes\n",
66 amatch ? amatch : "");
71 const char *atype = ts_get_attr_str(node, "type");
72 if(!atype || !(ex = create_exhibit(atype))) {
73 error_log("failed to create exhibit of type: %s\n", atype);
77 const char *desc = ts_get_attr_str(node, "description");
78 const char *voice = ts_get_attr_str(node, "voiceover");
83 exd.text = std::string(desc);
86 exd.voice = new OggVorbisStream;
87 if(!exd.voice->open(voice)) {
88 error_log("failed to open voiceover: %s\n", voice);
93 ex->data.push_back(exd);
105 ExSelection ExhibitManager::select(const Ray &ray) const
108 nearest.dist = FLT_MAX;
110 int nitems = items.size();
111 for(int i=0; i<nitems; i++) {
112 ExSelection sel = items[i]->select(ray);
113 if(sel && sel.dist < nearest.dist) {
121 ExSelection ExhibitManager::select(const Sphere &sph) const
127 sel.validmask = EXSEL_SPHERE;
132 void ExhibitManager::update(float dt)
134 int num = items.size();
135 for(int i=0; i<num; i++) {
136 // if the exhibit is not part of a scene graph, first call its
137 // node's update function (otherwise it'll have been called recursively earlier)
138 if(!items[i]->node->get_parent()) {
139 items[i]->node->update(dt);
141 items[i]->update(dt);
145 void ExhibitManager::draw() const
147 int num = items.size();
148 for(int i=0; i<num; i++) {
149 items[i]->pre_draw();
151 items[i]->post_draw();
155 static Exhibit *create_exhibit(const char *type)
157 if(strcmp(type, "static") == 0) {
158 debug_log("creating static exhibit\n");
160 } else if(strcmp(type, "blobs") == 0) {
161 debug_log("creating blobs exhibit\n");
162 return new BlobExhibit;
164 error_log("unknown exhibit type: %s\n", type);