static Ray last_pick_ray;
+static bool post_scene_init_pending = true;
+
bool app_init(int argc, char **argv)
{
return true;
}
+static void post_scene_init()
+{
+ exman->load(mscn, "data/exhibits");
+}
+
void app_cleanup()
{
if(mscn->music) {
texman.update();
sceneman.update();
+ if(post_scene_init_pending && !sceneman.pending()) {
+ post_scene_init_pending = false;
+ post_scene_init();
+ }
+
mscn->update(dt);
exman->update(dt);
exui_update(dt);
T get(const char *name) const;
+ int pending() const;
+ void wait() const;
+
void add_loaded_callback(LoadedCallbackFunc func, void *cls = 0);
bool remove_loaded_callback(LoadedCallbackFunc func);
};
T res = create();
data[name] = res;
- resman_lookup(rman, name, res);
+ resman_add(rman, name, res);
return res;
}
template <typename T>
+int DataSet<T>::pending() const
+{
+ return resman_pending(rman);
+}
+
+template <typename T>
+void DataSet<T>::wait() const
+{
+ resman_waitall(rman);
+}
+
+template <typename T>
void DataSet<T>::add_loaded_callback(LoadedCallbackFunc func, void *cls)
{
std::pair<LoadedCallbackFunc, void*> cb;
bool ExhibitManager::load(MetaScene *mscn, const char *fname)
{
+ info_log("ExhibitManager::load(%s)\n", fname);
+
struct ts_node *root = ts_load(fname);
if(!root || strcmp(root->name, "exhibits") != 0) {
ts_free_tree(root);
const char *voice = ts_get_attr_str(node, "voiceover");
if(desc || voice) {
ExData exd;
+ exd.type = EXDATA_INFO;
if(desc) {
char *fixed_desc = new char[strlen(desc) + 1];
#include <regex>
#include "metascene.h"
#include "scene.h"
+#include "objmesh.h"
#include "treestore.h"
#include "logger.h"
#include "app.h"
{
walk_mesh = 0;
music = 0;
+ mirrors = 0;
}
MetaScene::~MetaScene()
{
delete walk_mesh;
delete music;
+
+ while(mirrors) {
+ FlatMirror *m = mirrors;
+ mirrors = mirrors->next;
+ delete m;
+ }
}
bool MetaScene::load(const char *fname)
// XXX not used, renderer draws
void MetaScene::draw() const
{
+ error_log("Don't call MetaScene::draw, use the Renderer\n");
int nscn = scenes.size();
for(int i=0; i<nscn; i++) {
scenes[i]->draw();
return scn;
}
+int MetaScene::calc_mirror_planes()
+{
+ int num_mirrors = 0;
+ while(mirrors) {
+ FlatMirror *m = mirrors;
+ mirrors = mirrors->next;
+ delete m;
+ }
+ mirrors = 0;
+ objmirror.clear();
+
+ int numscn = scenes.size();
+ for(int i=0; i<numscn; i++) {
+ Scene *scn = scenes[i];
+
+ int numobj = scn->objects.size();
+ for(int j=0; j<numobj; j++) {
+ Object *obj = scn->objects[j];
+
+ if(obj->mtl.flat_mirror && obj->get_type() == OBJ_MESH) {
+ const Mesh *mesh = ((ObjMesh*)obj)->mesh;
+ if(!mesh) continue;
+
+ // assume the object is actually flat, so grab the first triangle and make a plane
+ Triangle face = Triangle(0, (const Vec3*)mesh->get_attrib_data(MESH_ATTR_VERTEX),
+ mesh->get_index_data());
+ face.calc_normal();
+
+ FlatMirror *mir = new FlatMirror;
+ mir->plane.pt = face.v[0];
+ mir->plane.normal = face.normal;
+ mir->reflect = obj->mtl.reflect;
+
+ // check to see if we have found this mirror plane already
+ bool found = false;
+ FlatMirror *node = mirrors;
+ while(node) {
+ if(fabs(dot(mir->plane.normal, node->plane.normal)) < 1e-4 &&
+ fabs(dot(mir->plane.normal, normalize(mir->plane.pt - node->plane.pt))) < 1e-4) {
+ found = true;
+ break;
+ }
+ }
+
+ if(!found) {
+ mir->next = mirrors;
+ mirrors = mir;
+
+ objmirror[obj] = mir; // associate with object
+ ++num_mirrors;
+ } else {
+ delete mir;
+ }
+ }
+ }
+ }
+
+ return num_mirrors;
+}
+
static bool proc_node(MetaScene *mscn, struct ts_node *node)
{
struct ts_node *c = node->child_list;
#ifndef METASCENE_H_
#define METASCENE_H_
+#include <vector>
#include <map>
#include "scene.h"
#include "mesh.h"
+#include "geom.h"
#include "audio/ovstream.h"
#include "datamap.h"
+
+struct FlatMirror {
+ Plane plane;
+ float reflect;
+ //std::vector<Object*> objects;
+
+ FlatMirror *next;
+};
+
+
class MetaScene {
public:
DataMap datamap;
std::map<Scene*, void*> scndata;
+ FlatMirror *mirrors;
+ int num_mirrors;
+ std::map<Object*, FlatMirror*> objmirror;
+
AudioStream *music;
MetaScene();
std::list<SceneNode*> match_nodes(const char *qstr) const;
Scene *extract_nodes(const char *qstr);
+
+ int calc_mirror_planes();
};
#endif // METASCENE_H_
TextureSet *texset;
void *loader_data;
- explicit Scene();
+ Scene();
~Scene();
Scene(const Scene &rhs) = delete;
Texture *res = create();
data[fname] = res;
res->create_default(type);
- resman_lookup(rman, fname, res);
+ resman_add(rman, fname, res);
return res;
}