X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fmetascene.cc;h=65c9d666ec48320eeb9fc3c3dae0634951aaf419;hp=b92e31ff8820775fee430ea7d66757d95cd5ac95;hb=84f1549d8146ac54574256ae0243747199e51151;hpb=7dc732cd42c88fa16accdbc606f10bcd6815d478 diff --git a/src/metascene.cc b/src/metascene.cc index b92e31f..65c9d66 100644 --- a/src/metascene.cc +++ b/src/metascene.cc @@ -11,14 +11,28 @@ #include #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) { @@ -27,20 +41,37 @@ bool load_scene(Scene *scn, const char *fname) 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; iupdate(dt); + } +} + +void MetaScene::draw() const +{ + int nscn = scenes.size(); + for(int i=0; idraw(); + } +} + +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; @@ -48,7 +79,7 @@ static bool proc_node(Scene *scn, struct ts_node *node) // 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"); @@ -61,7 +92,7 @@ static bool proc_node(Scene *scn, struct ts_node *node) 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) { @@ -85,7 +116,7 @@ static bool proc_scenefile(Scene *scn, struct ts_node *node) 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; } @@ -100,10 +131,10 @@ static bool proc_scenefile(Scene *scn, struct ts_node *node) for(int i=0; imeshes[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 } } @@ -118,8 +149,7 @@ static bool proc_scenefile(Scene *scn, struct ts_node *node) 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