+/*! \file
+ * \brief Metascene implementation
+ *
+ * Loading starts at `MetaScene::load`, which calls `ts_load` (libtreestore)
+ * to load the metascene description tree into memory. Then `proc_node` is
+ * called at the root to recursively process the tree. `scenefile` nodes are
+ * handed over to `proc_scenefile`, which will trigger scene loading for any
+ * nodes with a `file` attribute. Scene loading is handled by requesting the
+ * filename from the scene resource manager, which is of type [SceneSet](\ref SceneSet).
+ */
#include <assert.h>
#include <string>
#include <regex>
#include "treestore.h"
#include "logger.h"
#include "app.h"
+#include "dbg_gui.h"
#if defined(WIN32) || defined(__WIN32__)
#include <malloc.h>
static bool proc_node(MetaScene *mscn, struct ts_node *node);
static bool proc_scenefile(MetaScene *mscn, struct ts_node *node);
static bool proc_mtledit(MetaScene *mscn, MaterialEdit *med, struct ts_node *node);
+static bool proc_music(MetaScene *mscn, struct ts_node *node);
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);
MetaScene::MetaScene()
{
walk_mesh = 0;
+ music = 0;
}
MetaScene::~MetaScene()
{
delete walk_mesh;
+ delete music;
}
-
bool MetaScene::load(const char *fname)
{
struct ts_node *root = ts_load(fname);
void MetaScene::update(float dt)
{
+ bool expanded;
+ static char text[256];
+ if(debug_gui) {
+ ImGui::Begin("MetaScene nodes", 0, 0);
+ ImGui::Columns(2);
+
+ static bool once;
+ if(!once) {
+ float x = ImGui::GetColumnOffset(1);
+ ImGui::SetColumnOffset(1, x * 1.7);
+ once = true;
+ }
+ }
+
int nscn = scenes.size();
for(int i=0; i<nscn; i++) {
+
+ if(debug_gui) {
+ if(scenes[i]->name.empty()) {
+ sprintf(text, "scene %3d", i);
+ } else {
+ sprintf(text, "scene %3d: %s", i, scenes[i]->name.c_str());
+ }
+ expanded = parent_expanded = ImGui::TreeNode(text);
+ ImGui::NextColumn();
+ ImGui::NextColumn();
+ }
+
scenes[i]->update(dt);
+
+ if(debug_gui && expanded) {
+ ImGui::TreePop();
+ }
+ }
+
+ if(debug_gui) {
+ ImGui::Columns(1);
+ ImGui::End();
}
}
+// XXX not used, renderer draws
void MetaScene::draw() const
{
int nscn = scenes.size();
if(match && replace) {
mscn->datamap.map(match, replace);
}
+
+ } else if(strcmp(node->name, "music") == 0) {
+ return proc_music(mscn, node);
}
return true;
std::vector<MaterialEdit> mtledit;
};
+/*! Processes a `scenefile` node. And kicks off scene loading (if necessary) by
+ * calling `SceneSet::get`.
+ */
static bool proc_scenefile(MetaScene *mscn, struct ts_node *node)
{
const char *fname = ts_get_attr_str(node, "file");
fname = namebuf;
}
- // material edits
+ // material edits are kept in a list to be applied when the scene has been loaded
struct ts_node *child = node->child_list;
while(child) {
MaterialEdit medit;
}
}
+static bool proc_music(MetaScene *mscn, struct ts_node *node)
+{
+ const char *fname = ts_get_attr_str(node, "file");
+ if(fname) {
+ SceneData *sdat = new SceneData;
+ sdat->meta = mscn;
+
+ // datapath
+ struct ts_attr *adpath = attr_inscope(node, "datapath");
+ if(adpath && adpath->val.type == TS_STRING) {
+ mscn->datamap.set_path(adpath->val.str);
+ }
+
+ int namesz = mscn->datamap.lookup(fname, 0, 0);
+ char *namebuf = (char*)alloca(namesz + 1);
+ if(mscn->datamap.lookup(fname, namebuf, namesz + 1)) {
+ fname = namebuf;
+ }
+
+ OggVorbisStream *ovstream = new OggVorbisStream;
+ if(!ovstream->open(fname)) {
+ delete ovstream;
+ return false;
+ }
+
+ delete mscn->music;
+ mscn->music = ovstream;
+ }
+ return true;
+}
+
static void apply_mtledit(Material *mtl, const MaterialEdit &med)
{
// TODO more edit modes...