datamap object passed around while loading
[laserbrain_demo] / src / metascene.cc
index 21e9093..66e0027 100644 (file)
@@ -2,7 +2,6 @@
 #include <regex>
 #include "metascene.h"
 #include "scene.h"
-#include "datamap.h"
 #include "treestore.h"
 #include "logger.h"
 
@@ -20,7 +19,7 @@ struct MaterialEdit {
 
 static bool proc_node(MetaScene *mscn, struct ts_node *node);
 static bool proc_scenefile(MetaScene *mscn, struct ts_node *node);
-static bool proc_mtledit(MaterialEdit *med, struct ts_node *node, TextureSet *texset);
+static bool proc_mtledit(MetaScene *mscn, MaterialEdit *med, struct ts_node *node, TextureSet *texset);
 static void apply_mtledit(Scene *scn, const MaterialEdit &med);
 static void apply_mtledit(Material *mtl, const MaterialEdit &med);
 static struct ts_attr *attr_inscope(struct ts_node *node, const char *name);
@@ -94,7 +93,7 @@ static bool proc_node(MetaScene *mscn, struct ts_node *node)
                const char *match = ts_get_attr_str(node, "match");
                const char *replace = ts_get_attr_str(node, "replace");
                if(match && replace) {
-                       datamap_map(match, replace);
+                       mscn->datamap.map(match, replace);
                }
        }
 
@@ -118,7 +117,7 @@ static bool proc_scenefile(MetaScene *mscn, struct ts_node *node)
                struct ts_attr *adpath = attr_inscope(node, "datapath");
                if(adpath && adpath->val.type == TS_STRING) {
                        info_log("adding data path: %s\n", adpath->val.str);
-                       datamap_set_path(adpath->val.str);
+                       mscn->datamap.set_path(adpath->val.str);
                }
 
                // walkmesh
@@ -127,9 +126,9 @@ static bool proc_scenefile(MetaScene *mscn, struct ts_node *node)
                        sdat->walkmesh_regexp = std::string(awmesh->val.str);
                }
 
-               int namesz = datamap_lookup(fname, 0, 0);
+               int namesz = mscn->datamap.lookup(fname, 0, 0);
                char *namebuf = (char*)alloca(namesz + 1);
-               if(datamap_lookup(fname, namebuf, namesz + 1)) {
+               if(mscn->datamap.lookup(fname, namebuf, namesz + 1)) {
                        fname = namebuf;
                }
 
@@ -137,17 +136,20 @@ static bool proc_scenefile(MetaScene *mscn, struct ts_node *node)
                struct ts_node *child = node->child_list;
                while(child) {
                        MaterialEdit medit;
-                       if(proc_mtledit(&medit, child, mscn->texman)) {
+                       if(proc_mtledit(mscn, &medit, child, mscn->texman)) {
                                sdat->mtledit.push_back(medit);
                        }
                        child = child->next;
                }
 
                Scene *newscn = mscn->sceneman->get(fname);
-               /* NOTE: setting this after get() is not a race condition, because
+               /* NOTE: setting all these after get() is not a race condition, because
                 * scene_loaded() which uses this, will only run in our main loop during
                 * SceneSet::update() on the main thread.
                 */
+               newscn->datamap = mscn->datamap;
+               mscn->datamap.clear();
+
                newscn->metascn = mscn;
                mscn->scndata[newscn] = sdat;
        }
@@ -193,7 +195,7 @@ bool MetaScene::scene_loaded(Scene *newscn)
        return true;
 }
 
-static bool proc_mtledit(MaterialEdit *med, struct ts_node *node, TextureSet *texset)
+static bool proc_mtledit(MetaScene *mscn, MaterialEdit *med, struct ts_node *node, TextureSet *texset)
 {
        if(strcmp(node->name, "mtledit") != 0) {
                return false;
@@ -239,7 +241,7 @@ static bool proc_mtledit(MaterialEdit *med, struct ts_node *node, TextureSet *te
                                // remove
                                med->tex = 0;
                        } else {
-                               med->tex = texset->get_texture(afile->val.str, TEX_2D);
+                               med->tex = texset->get_texture(afile->val.str, TEX_2D, &mscn->datamap);
                        }
                }
                // TODO add more edit modes