#include <alloca.h>
#endif
-static bool proc_node(Scene *scn, struct ts_node *node);
-static bool proc_scenefile(Scene *scn, struct ts_node *node);
+static bool proc_node(MetaScene *mscn, struct ts_node *node);
+static bool proc_scenefile(MetaScene *mscn, struct ts_node *node);
static bool proc_mtledit(Scene *scn, struct ts_node *node);
static struct ts_attr *attr_inscope(struct ts_node *node, const char *name);
static void print_scene_graph(SceneNode *n, int level);
-bool load_scene(Scene *scn, const char *fname)
+
+MetaScene::MetaScene(SceneSet *sman, TextureSet *tman)
+{
+ sceneman = sman;
+ texman = tman;
+ walk_mesh = 0;
+}
+
+MetaScene::~MetaScene()
+{
+ delete walk_mesh;
+}
+
+
+bool MetaScene::load(const char *fname)
{
struct ts_node *root = ts_load(fname);
if(!root || strcmp(root->name, "scene") != 0) {
return false;
}
- bool res = proc_node(scn, root);
+ bool res = proc_node(this, root);
ts_free_tree(root);
- info_log("loaded scene: %s\n", fname);
+ /*info_log("loaded scene: %s\n", fname);
info_log("scene graph:\n");
print_scene_graph(scn->nodes, 0);
+ */
return res;
}
-static bool proc_node(Scene *scn, struct ts_node *node)
+void MetaScene::update(float dt)
+{
+ int nscn = scenes.size();
+ for(int i=0; i<nscn; i++) {
+ scenes[i]->update(dt);
+ }
+}
+
+void MetaScene::draw() const
+{
+ int nscn = scenes.size();
+ for(int i=0; i<nscn; i++) {
+ scenes[i]->draw();
+ }
+}
+
+static bool proc_node(MetaScene *mscn, struct ts_node *node)
{
struct ts_node *c = node->child_list;
while(c) {
- if(!proc_node(scn, c)) {
+ if(!proc_node(mscn, c)) {
return false;
}
c = c->next;
// do this last to allow other contents of the node to do their thing
if(strcmp(node->name, "scenefile") == 0) {
- return proc_scenefile(scn, node);
+ return proc_scenefile(mscn, node);
} else if(strcmp(node->name, "remap") == 0) {
const char *match = ts_get_attr_str(node, "match");
return true;
}
-static bool proc_scenefile(Scene *scn, struct ts_node *node)
+static bool proc_scenefile(MetaScene *mscn, struct ts_node *node)
{
const char *fname = ts_get_attr_str(node, "file");
if(fname) {
fname = namebuf;
}
- Scene *newscn = new Scene(scn->texset);
+ Scene *newscn = new Scene(mscn->texman);
if(!(newscn->load(fname, SCNLOAD_FLIPTEX))) { // TODO unhardcode FLIPTEX
return false;
}
for(int i=0; i<nmeshes; i++) {
Mesh *m = wscn->meshes[i];
- if(newscn->walk_mesh) {
- newscn->walk_mesh->append(*m);
+ if(mscn->walk_mesh) {
+ mscn->walk_mesh->append(*m);
} else {
- newscn->walk_mesh = m;
+ mscn->walk_mesh = m;
wscn->remove_mesh(m); // to save it from destruction
}
}
child = child->next;
}
- scn->merge(newscn);
- delete newscn;
+ mscn->scenes.push_back(newscn);
}
//datamap_reset(); // TODO this should be push/pop instead of hard reset