summaryrefslogtreecommitdiff
path: root/src/objects
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-10-03 19:08:44 -0400
committerAndrew Opalach <andrew@akon.city> 2024-10-04 14:19:40 -0400
commit0bf9b26b87075448d49482fe4411739af765d872 (patch)
treee3f0e3312a92e5250fa72b410adb370734deca04 /src/objects
parentacd44bb898996ff4e36b39b10e870e40bcaf2634 (diff)
downloadmauri-0bf9b26b87075448d49482fe4411739af765d872.tar.gz
mauri-0bf9b26b87075448d49482fe4411739af765d872.tar.bz2
mauri-0bf9b26b87075448d49482fe4411739af765d872.zip
Update codebase
Bring up-to-date with my other projects. Wallpaper engine behavior is mostly unchanged. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/objects')
-rw-r--r--src/objects/effect.cc42
-rw-r--r--src/objects/effect.h5
-rw-r--r--src/objects/material.cc19
-rw-r--r--src/objects/material.h10
-rw-r--r--src/objects/model.cc25
-rw-r--r--src/objects/model.h4
-rw-r--r--src/objects/object.cc91
-rw-r--r--src/objects/object.h16
-rw-r--r--src/objects/pass.cc77
-rw-r--r--src/objects/pass.h26
-rw-r--r--src/objects/scene.cc43
-rw-r--r--src/objects/scene.h7
12 files changed, 216 insertions, 149 deletions
diff --git a/src/objects/effect.cc b/src/objects/effect.cc
index 5542ccc..92f7dda 100644
--- a/src/objects/effect.cc
+++ b/src/objects/effect.cc
@@ -1,48 +1,58 @@
-#include "pass.h"
#include "effect.h"
+#include "pass.h"
using namespace Mauri;
-Effect::Effect(Parser &pr, const json &root)
+auto Effect::parse(Parser &pr, const json &root) -> Effect *
{
+ Effect *effect = new Effect();
+
Asset *asset = asset_manager()->get_file(root["file"]);
- if (asset->type == ASSET_VOID) return;
+ if (asset->type == ASSET_VOID) parse_fail(effect);
- const json &file = json::parse(asset->as_string());
- if (file.is_discarded()) return;
+ const json &file = json::parse(asset->as_string(), nullptr, false);
+ if (file.is_discarded()) parse_fail(effect);
- pr.map_value<u32>(root, "id", &this->id, 0);
- pr.map_value<bool>(root, "visible", &this->visible, true);
- pr.map_value<std::string>(file, "name", &this->name, "");
+ pr.map_value<u32>(root, "id", &effect->id, 0);
+ pr.map_value<bool>(root, "visible", &effect->visible, true);
+ pr.map_value<std::string>(file, "name", &effect->name, "");
if (root.contains("passes"))
{
for (const json &pass0 : root["passes"])
{
- this->passes0.emplace_back(new Pass(pr, pass0, EFFECT0_PASS));
+ Pass *pass = Pass::parse(pr, pass0, EFFECT0_PASS);
+ if (pass) effect->passes0.emplace_back(pass);
}
}
+ if (effect->passes0.size() == 0) parse_fail(effect);
+
if (file.contains("passes"))
{
for (const json &pass1 : file["passes"])
{
- this->passes1.emplace_back(new Pass(pr, pass1, EFFECT1_PASS));
+ Pass *pass = Pass::parse(pr, pass1, EFFECT1_PASS);
+ if (pass) effect->passes1.emplace_back(pass);
}
}
+ if (effect->passes1.size() == 0) parse_fail(effect);
+
if (file.contains("fbos"))
{
for (const json &fbo : file["fbos"])
{
- this->fbos.emplace_back(EffectBuffer{fbo["name"], fbo.contains("scale") ? (f32)fbo["scale"] : 1.f });
+ effect->fbos.emplace_back(EffectBuffer{fbo["name"], fbo.contains("scale") ? (f32)fbo["scale"] : 1.f });
}
}
+
+ return effect;
}
auto Effect::load(Engine *engine, Object *object, bool last) -> void
{
- this->buffer_id = str_format("_%i_%i", object->id, this->id);
+ this->buffer_id = "_" + std::to_string(object->id) + "_" + std::to_string(this->id);
for (const EffectBuffer &fbo : this->fbos)
{
@@ -82,14 +92,14 @@ auto Effect::draw(Engine *engine) -> void
{
if (!this->visible) return;
-#if FRAME_STEP
- std::cout << this->name << ":\n";
+#ifdef FRAME_STEP
+ al_printf("%s\n", this->name.c_str());
#endif
for (RenderPass *pass : this->passes)
{
-#if FRAME_STEP
- if (pass->shader) std::cout << "\t" << pass->shader->origin()->name << "\n";
+#ifdef FRAME_STEP
+ if (pass->shader) al_printf("\t%s\n", pass->shader->origin()->name.c_str());
#endif
pass->draw(engine);
}
diff --git a/src/objects/effect.h b/src/objects/effect.h
index cb53a04..710fc51 100644
--- a/src/objects/effect.h
+++ b/src/objects/effect.h
@@ -3,7 +3,6 @@
#include "../json.h"
#include "../engine.h"
-#include "../texture.h"
namespace Mauri
{
@@ -20,7 +19,7 @@ class RenderPass;
class Effect
{
public:
- Effect(Parser &pr, const json &root);
+ Effect() = default;
~Effect();
u32 id;
@@ -32,6 +31,8 @@ class Effect
std::vector<RenderPass *> passes;
+ static auto parse(Parser &pr, const json &root) -> Effect *;
+
auto load(Engine *engine, Object *object, bool last) -> void;
auto draw(Engine *engine) -> void;
diff --git a/src/objects/material.cc b/src/objects/material.cc
index b17a102..e3e3e02 100644
--- a/src/objects/material.cc
+++ b/src/objects/material.cc
@@ -1,23 +1,28 @@
-#include "pass.h"
#include "material.h"
+#include "pass.h"
using namespace Mauri;
-Material::Material(Parser &pr, const std::string &path)
+auto Material::parse(Parser &pr, const std::string &path) -> Material *
{
+ Material *material = new Material();
+
Asset *asset = asset_manager()->get_file(path);
- if (asset->type == ASSET_VOID) return;
+ if (asset->type == ASSET_VOID) parse_fail(material);
- const json &root = json::parse(asset->as_string());
- if (root.is_discarded()) return;
+ const json &root = json::parse(asset->as_string(), nullptr, false);
+ if (root.is_discarded()) parse_fail(material);
if (root.contains("passes"))
{
- for (const json &pass : root["passes"])
+ for (const json &pass0 : root["passes"])
{
- this->passes0.push_back(new Pass(pr, pass, MATERIAL_PASS));
+ Pass *pass = Pass::parse(pr, pass0, MATERIAL_PASS);
+ if (pass) material->passes0.push_back(pass);
}
}
+
+ return material;
}
auto Material::load(Engine *engine, Object *object, MaterialType type, Pass *pass) -> void
diff --git a/src/objects/material.h b/src/objects/material.h
index cfea216..a0edca7 100644
--- a/src/objects/material.h
+++ b/src/objects/material.h
@@ -7,16 +7,22 @@
namespace Mauri
{
-enum MaterialType { MATERIAL_MODEL, MATERIAL_EFFECT };
+enum MaterialType
+{
+ MATERIAL_MODEL = 0,
+ MATERIAL_EFFECT
+};
class Pass;
class Material
{
public:
- Material(Parser &pr, const std::string &path);
+ Material() = default;
~Material();
+ static auto parse(Parser &pr, const std::string &path) -> Material *;
+
std::vector<Pass *> passes0;
auto load(Engine *engine, Object *object, MaterialType type, Pass *pass) -> void;
diff --git a/src/objects/model.cc b/src/objects/model.cc
index b916ec7..830bdaf 100644
--- a/src/objects/model.cc
+++ b/src/objects/model.cc
@@ -2,22 +2,27 @@
using namespace Mauri;
-Model::Model(Parser &pr, const std::string &path)
+auto Model::parse(Parser &pr, const std::string &path) -> Model *
{
+ Model *model = new Model();
+
Asset *asset = asset_manager()->get_file(path);
- if (asset->type == ASSET_VOID) return;
+ if (asset->type == ASSET_VOID) parse_fail(model);
+
+ const json &root = json::parse(asset->as_string(), nullptr, false);
+ if (root.is_discarded()) parse_fail(model);
- const json &root = json::parse(asset->as_string());
- if (root.is_discarded()) return;
+ pr.map_value<bool>(root, "autosize", &model->autosize, false);
+ pr.map_value<bool>(root, "fullscreen", &model->fullscreen, false);
+ pr.map_value<bool>(root, "passthrough", &model->passthrough, false);
- pr.map_value<bool>(root, "autosize", &this->autosize, false);
- pr.map_value<bool>(root, "fullscreen", &this->fullscreen, false);
- pr.map_value<bool>(root, "passthrough", &this->passthrough, false);
+ pr.map_value<f32>(root, "width", &model->width, 0.f);
+ pr.map_value<f32>(root, "height", &model->height, 0.f);
- pr.map_value<f32>(root, "width", &this->width, 0.f);
- pr.map_value<f32>(root, "height", &this->height, 0.f);
+ if (root.contains("material")) model->material = Material::parse(pr, root["material"]);
+ if (!model->material) parse_fail(model);
- if (root.contains("material")) this->material = new Material(pr, root["material"]);
+ return model;
}
auto Model::load(Engine *engine, Object *object) -> void
diff --git a/src/objects/model.h b/src/objects/model.h
index f6b532a..d000bd7 100644
--- a/src/objects/model.h
+++ b/src/objects/model.h
@@ -9,7 +9,7 @@ namespace Mauri
class Model
{
public:
- Model(Parser &pr, const std::string &path);
+ Model() = default;
~Model();
bool autosize = true;
@@ -19,6 +19,8 @@ class Model
f32 width;
f32 height;
+ static auto parse(Parser &pr, const std::string &path) -> Model *;
+
auto load(Engine *engine, Object *object) -> void;
private:
diff --git a/src/objects/object.cc b/src/objects/object.cc
index ac64a25..d648b63 100644
--- a/src/objects/object.cc
+++ b/src/objects/object.cc
@@ -1,21 +1,21 @@
-#include "../context.h"
-
-#include "pass.h"
-#include "scene.h"
#include "object.h"
+#include "scene.h"
+#include "pass.h"
using namespace Mauri;
-Object::Object(Parser &pr, const json &root)
+auto Object::parse(Parser &pr, const json &root) -> Object *
{
- pr.map_value<u32>(root, "id", &this->id, 0);
- pr.map_value<std::string>(root, "name", &this->name, "");
+ Object *object = new Object();
+
+ pr.map_value<u32>(root, "id", &object->id, 0);
+ pr.map_value<std::string>(root, "name", &object->name, "");
if (root.contains("dependencies"))
{
for (const json &id : root["dependencies"])
{
- this->deps.push_back(id);
+ object->deps.push_back(id);
}
}
@@ -23,11 +23,11 @@ Object::Object(Parser &pr, const json &root)
// object or are repeated. This could be handled be sorting objects
// on the scene in order of deps but I'm not sure if that would
// break other things.
- auto it = this->deps.begin();
- while (it != this->deps.end())
+ auto it = object->deps.begin();
+ while (it != object->deps.end())
{
- bool remove = ((u32)(*it) == id);
- for (auto rt = this->deps.begin(); rt != this->deps.end(); ++rt)
+ bool remove = ((u32)(*it) == object->id);
+ for (auto rt = object->deps.begin(); rt != object->deps.end(); ++rt)
{
if (rt != it && *rt == *it)
{
@@ -35,44 +35,48 @@ Object::Object(Parser &pr, const json &root)
break;
}
}
- if (remove) this->deps.erase(it);
+ if (remove) object->deps.erase(it);
else it++;
}
- pr.map_value<bool>(root, "visible", &this->visible, true);
- pr.map_value<vec3>(root, "angles", &this->angles, vec3(0.f));
- pr.map_value<vec2>(root, "size", &this->size, vec2(0.f));
- pr.map_value<vec3>(root, "scale", &this->scale, vec3(0.f));
- pr.map_value<vec3>(root, "origin", &this->origin, vec3(0.f));
- if (this->origin[2] != 0.f)
+ pr.map_value<bool>(root, "visible", &object->visible, true);
+ pr.map_value<vec3>(root, "angles", &object->angles, vec3(0.f));
+ pr.map_value<vec2>(root, "size", &object->size, vec2(0.f));
+ pr.map_value<vec3>(root, "scale", &object->scale, vec3(1.f));
+ pr.map_value<vec3>(root, "origin", &object->origin, vec3(0.f));
+ if (object->origin[2] != 0.f)
{
warn("non 0 origin[2]");
- this->origin[2] = 0.f;
+ object->origin[2] = 0.f;
}
- pr.map_value<vec3>(root, "color", &this->color, vec3(0.f));
- pr.map_value<f32>(root, "alpha", &this->alpha, 1.f);
- pr.map_value<s32>(root, "colorBlendMode", &this->color_blend_mode, 0);
+ pr.map_value<vec3>(root, "color", &object->color, vec3(0.f));
+ pr.map_value<f32>(root, "alpha", &object->alpha, 1.f);
+ pr.map_value<s32>(root, "colorBlendMode", &object->color_blend_mode, 0);
- this->color4 = vec4{this->color[0], this->color[1], this->color[2], this->alpha};
+ object->color4 = vec4{object->color[0], object->color[1], object->color[2], object->alpha};
if (root.contains("image"))
{
const json &image = root["image"];
- if (image.is_string()) this->model = new Model(pr, image);
+ if (image.is_string()) object->model = Model::parse(pr, image);
+ if (!object->model) parse_fail(object);
}
if (root.contains("config"))
{
- pr.map_value<bool>(root["config"], "passthrough", &this->passthrough, false);
+ pr.map_value<bool>(root["config"], "passthrough", &object->passthrough, false);
}
if (root.contains("effects"))
{
for (const json &effect : root["effects"])
{
- this->effects.emplace_back(new Effect(pr, effect));
+ Effect *eff = Effect::parse(pr, effect);
+ if (eff) object->effects.emplace_back(eff);
}
}
+
+ return object;
}
auto Object::load(Engine *engine) -> void
@@ -110,8 +114,9 @@ auto Object::load(Engine *engine) -> void
if (this->size[1] == 0.f) this->size[1] = engine->scene->height;
}
- this->buffer_a = str_format("_rt_imageLayerComposite_%i_a", this->id);
- this->buffer_b = str_format("_rt_imageLayerComposite_%i_b", this->id);
+ const std::string buffer_name = "_rt_imageLayerComposite_" + std::to_string(this->id) + "_";
+ this->buffer_a = buffer_name + "a";
+ this->buffer_b = buffer_name + "b";
engine->create_framebuffer(this->buffer_a, this->size[0], this->size[1], 1.f);
engine->create_framebuffer(this->buffer_b, this->size[0], this->size[1], 1.f);
@@ -151,23 +156,7 @@ auto Object::load(Engine *engine) -> void
blend_pass.combos.push_back(Combo("BLENDMODE", this->color_blend_mode));
blend_pass.combos.push_back(Combo("TRANSFORM", 1));
- RenderPass *pass = new RenderPass(engine, &blend_pass);
- this->effects.back()->passes.emplace_back(pass);
-
- /*
- blend_pass.combine = true;
-
- blend_pass.target = "";
- blend_pass.textures[1] = "";
- blend_pass.shader = "minimal";
-
- blend_pass.combos.clear();
-
- pass = new RenderPass(engine, &blend_pass);
- //pass->mat = &engine->default_mat;
- //pass->render_object = engine->default_object;
- this->effects.back()->passes.emplace_back(pass);
- */
+ this->effects.back()->passes.emplace_back(new RenderPass(engine, &blend_pass));
}
this->loaded = true;
@@ -183,7 +172,7 @@ auto Object::create_objects(Engine *engine, Texture *texture) -> void
{
// Something about positioning is wrong, affects most gifs.
}
- if (this->passthrough)
+ if (this->passthrough && !this->fullscreen)
{
this->model_model = this->combine_model;
this->model_model = glm::rotate(this->model_model, this->angles[0], vec3{1.f, 0.f, 0.f});
@@ -204,16 +193,16 @@ auto Object::create_objects(Engine *engine, Texture *texture) -> void
auto Object::draw_internal(Engine *engine) -> void
{
-#if FRAME_STEP
- std::cout << this->name << " (model):\n";
+#ifdef FRAME_STEP
+ al_printf("%s (model):\n", this->name.c_str());
#endif
this->buffer_switch = true;
for (RenderPass *pass : this->passes)
{
-#if FRAME_STEP
- std::cout << "\t" << pass->shader->origin()->name << "\n";;
+#ifdef FRAME_STEP
+ al_printf("\t%s\n", pass->shader->origin()->name.c_str());
#endif
pass->draw(engine);
}
diff --git a/src/objects/object.h b/src/objects/object.h
index a171fae..9c9f60c 100644
--- a/src/objects/object.h
+++ b/src/objects/object.h
@@ -7,13 +7,21 @@
namespace Mauri
{
-enum ObjectAlignment { CENTER };
-enum BlendMode { TRANSLUCENT, NORMAL };
+enum ObjectAlignment
+{
+ CENTER = 0
+};
+
+enum BlendMode
+{
+ TRANSLUCENT = 0,
+ NORMAL
+};
class Object
{
public:
- Object(Parser &pr, const json &root);
+ Object() = default;
~Object();
u32 id;
@@ -42,6 +50,8 @@ class Object
RenderObject *model_object = nullptr;
RenderObject *combine_object = nullptr;
+ static auto parse(Parser &pr, const json &root) -> Object *;
+
auto get_target_buffer() const -> const std::string &;
auto get_texture_buffer() const -> const std::string &;
diff --git a/src/objects/pass.cc b/src/objects/pass.cc
index 49533e1..04e23d5 100644
--- a/src/objects/pass.cc
+++ b/src/objects/pass.cc
@@ -1,38 +1,37 @@
-#include <thread>
-
#include "../gl.h"
-#include "../context.h"
-#include "scene.h"
#include "pass.h"
using namespace Mauri;
-Pass::Pass(Parser &pr, const json &root, PassStage stage)
+auto Pass::parse(Parser &pr, const json &root, PassStage stage) -> Pass *
{
+ Pass *pass = new Pass();
+
switch (stage)
{
case EFFECT0_PASS:
break;
case EFFECT1_PASS:
{
- if (root.contains("material")) this->material = new Material(pr, root["material"]);
+ if (root.contains("material")) pass->material = Material::parse(pr, root["material"]);
+ if (!pass->material) parse_fail(pass);
if (root.contains("command"))
{
const json command = root["command"];
- if (command == "copy") this->command = COPY;
+ if (command == "copy") pass->command = COPY;
}
- if (root.contains("target")) this->target = root["target"];
- if (root.contains("source")) this->source = root["source"];
+ if (root.contains("target")) pass->target = root["target"];
+ if (root.contains("source")) pass->source = root["source"];
- this->binds[0] = "previous";
+ pass->binds[0] = "previous";
if (root.contains("bind"))
{
for (const json &bind : root["bind"])
{
- this->binds[bind["index"]] = bind["name"];
+ pass->binds[bind["index"]] = bind["name"];
}
}
@@ -40,7 +39,10 @@ Pass::Pass(Parser &pr, const json &root, PassStage stage)
}
case MATERIAL_ONLY_PASS:
case MATERIAL_PASS:
- this->shader = root["shader"];
+ pass->shader = root["shader"];
+ if (pass->shader == "genericimage4") {
+ pass->shader = "genericimage2";
+ }
break;
}
@@ -51,7 +53,7 @@ Pass::Pass(Parser &pr, const json &root, PassStage stage)
{
UniformOverride *uniform = new UniformOverride{vec4(0.f), value.key()};
pr.map_value<vec4>(uniforms, value.key(), &uniform->value, vec4(0.f));
- this->uniforms.push_back(uniform);
+ pass->uniforms.push_back(uniform);
}
}
@@ -60,7 +62,7 @@ Pass::Pass(Parser &pr, const json &root, PassStage stage)
const json textures = root["textures"];
for (u32 i = 0; i < textures.size(); i++)
{
- if (textures[i].is_string()) this->textures[i] = textures[i];
+ if (textures[i].is_string()) pass->textures[i] = textures[i];
}
}
@@ -68,9 +70,11 @@ Pass::Pass(Parser &pr, const json &root, PassStage stage)
{
for (const auto &combo : root["combos"].items())
{
- this->combos.emplace_back(Combo(combo.key(), combo.value()));
+ pass->combos.emplace_back(Combo(combo.key(), combo.value()));
}
}
+
+ return pass;
}
auto Pass::load(Engine *engine, PassStage stage, Pass *pass) -> void
@@ -169,7 +173,7 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
pass->combos.push_back(Combo(this->shader->origin()->texture_combos[i], !pass->textures[i].empty()));
}
- if (!this->shader->origin()->textures[i].empty() && pass->textures[i].empty())
+ if (pass->textures[i].empty() && !this->shader->origin()->textures[i].empty())
{
pass->textures[i] = this->shader->origin()->textures[i];
}
@@ -193,9 +197,12 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
}
}
- if (i == 0 && this->textures[0] && this->model)
+ if (this->model && i == 0 && this->textures[0])
{
- if (this->textures[0]->is_gif()) pass->combos.push_back(Combo("SPRITESHEET", 1));
+ if (this->textures[0]->is_gif())
+ {
+ pass->combos.push_back(Combo("SPRITESHEET", 1));
+ }
this->object->create_objects(engine, this->textures[0]);
objects_created = true;
}
@@ -267,41 +274,41 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
}
}
-#if _DEBUG_
+#ifdef _DEBUG_
debug("PASS (%s)", this->command == COPY ? "copy" : "draw");
- debug(" object: %s (passthrough: %i, fullscreen %i)", this->object->name.c_str(),
+ debug(" object: %s (passthrough: %d, fullscreen %d)", this->object->name.c_str(),
this->object->passthrough, this->object->fullscreen);
- //debug(" visible: %i", );
- debug(" shader: %s", this->shader->origin()->name.c_str());
- debug(" target: %s", pass->target.c_str());
- debug(" textures (%i):", this->shader->origin()->texture_count);
+ debug(" visible: %d", this->object->visible);
+ debug(" shader: %s", this->shader->origin()->name.c_str());
+ debug(" target: %s", pass->target.c_str());
+ debug(" textures (%u):", this->shader->origin()->texture_count);
for (u32 i = 0; i < this->shader->origin()->texture_count; i++)
{
switch (this->texture_types[i])
{
case STATIC:
- if (pass->textures[i].empty() && !this->shader->textures[i].empty())
+ if (pass->textures[i].empty() && !this->shader->origin()->textures[i].empty())
{
- debug(" %s (DEFAULT)", this->shader->textures[i].c_str());
+ debug(" [%u] %s (DEFAULT)", i, this->shader->origin()->textures[i].c_str());
}
else
{
- debug(" %s", pass->textures[i].c_str());
+ debug(" [%u] %s", i, pass->textures[i].c_str());
}
break;
case PREVIOUS:
- debug(" previous");
+ debug(" [%u] previous", i);
break;
}
}
- debug(" uniforms (%li)", this->shader->uniforms.size());
+ debug(" uniforms (%u)", this->shader->uniforms.size());
for (Uniform *uniform : this->shader->uniforms)
{
- debug(" %s %s %s", uniform_type_to_string(uniform->type).c_str(),
+ debug(" %s %s %s", uniform_type_to_string(uniform->type).c_str(),
uniform->uname.c_str(), glm::to_string(*uniform->value).c_str());
}
- debug(" model: %i", this->model);
- debug(" combine: %i", this->combine);
+ debug(" model: %d", this->model);
+ debug(" combine: %d", this->combine);
#endif
}
@@ -341,10 +348,10 @@ auto RenderPass::draw(Engine *engine) -> void
this->render_object->draw();
-#if FRAME_STEP
- adjusted_target->buffer->blit(0, context()->width, context()->height);
+#ifdef FRAME_STEP
+ adjusted_target->buffer->blit(0, context()->width(), context()->height());
context()->swap_buffers();
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ aki_thread_sleep(AKI_TS_FROM_USEC(1000000));
#endif
break;
}
diff --git a/src/objects/pass.h b/src/objects/pass.h
index a2b3124..5012ed5 100644
--- a/src/objects/pass.h
+++ b/src/objects/pass.h
@@ -8,10 +8,25 @@
namespace Mauri
{
-enum PassStage { EFFECT0_PASS, EFFECT1_PASS, MATERIAL_PASS, MATERIAL_ONLY_PASS };
-enum PassCommand { DRAW, COPY };
+enum PassStage
+{
+ EFFECT0_PASS = 0,
+ EFFECT1_PASS,
+ MATERIAL_PASS,
+ MATERIAL_ONLY_PASS
+};
+
+enum PassCommand
+{
+ DRAW = 0,
+ COPY
+};
-enum TextureType { STATIC, PREVIOUS };
+enum TextureType
+{
+ STATIC = 0,
+ PREVIOUS
+};
struct UniformOverride
{
@@ -22,8 +37,7 @@ struct UniformOverride
class Pass
{
public:
- Pass() {}
- Pass(Parser &pr, const json &root, PassStage stage);
+ Pass() = default;
~Pass();
bool intermediate;
@@ -47,6 +61,8 @@ class Pass
std::vector<UniformOverride *> uniforms;
std::vector<Combo> combos;
+ static auto parse(Parser &pr, const json &root, PassStage stage) -> Pass *;
+
auto load(Engine *engine, PassStage stage, Pass *pass) -> void;
private:
diff --git a/src/objects/scene.cc b/src/objects/scene.cc
index 06412f5..b7d1192 100644
--- a/src/objects/scene.cc
+++ b/src/objects/scene.cc
@@ -2,37 +2,48 @@
using namespace Mauri;
-Scene::Scene(const std::string &path)
+auto Scene::parse(const std::string &path) -> Scene *
{
+ Scene *scene = new Scene();
+
Asset *asset = asset_manager()->get_file(path);
- if (asset->type == ASSET_VOID) return;
+ if (asset->type == ASSET_VOID) parse_fail(scene);
- const json &root = json::parse(asset->as_string());
- if (root.is_discarded()) return;
+ const json &root = json::parse(asset->as_string(), nullptr, false);
+ if (root.is_discarded()) parse_fail(scene);
- Parser &pr = this->parser;
+ Parser &pr = scene->parser;
const json &camera = root["camera"];
- pr.map_value<vec3>(camera, "center", &this->cam.center, vec3(0.f));
- pr.map_value<vec3>(camera, "eye", &this->cam.eye, vec3(0.f));
- pr.map_value<vec3>(camera, "up", &this->cam.up, vec3(0.f));
+ pr.map_value<vec3>(camera, "center", &scene->cam.center, vec3(0.f));
+ pr.map_value<vec3>(camera, "eye", &scene->cam.eye, vec3(0.f));
+ pr.map_value<vec3>(camera, "up", &scene->cam.up, vec3(0.f));
const json &general = root["general"];
- pr.map_value<bool>(general, "clearenabled", &this->clear_enabled, true);
- pr.map_value<vec4>(general, "clearcolor", &this->clear_color, vec4(1.f));
- pr.map_value<f32>(general, "nearz", &this->nearz, -1.f);
- pr.map_value<f32>(general, "farz", &this->farz, 1.f);
+ pr.map_value<bool>(general, "clearenabled", &scene->clear_enabled, true);
+ pr.map_value<vec4>(general, "clearcolor", &scene->clear_color, vec4(1.f));
+ pr.map_value<f32>(general, "nearz", &scene->nearz, -1.f);
+ pr.map_value<f32>(general, "farz", &scene->farz, 1.f);
const json &ortho = general["orthogonalprojection"];
- pr.map_value<s32>(ortho, "width", &this->width, 0);
- pr.map_value<s32>(ortho, "height", &this->height, 0);
+ pr.map_value<s32>(ortho, "width", &scene->width, 0);
+ pr.map_value<s32>(ortho, "height", &scene->height, 0);
for (const json &object : root["objects"])
{
if (!object.contains("image") || object["image"].is_null()) continue;
- //if (object["name"] == "ICUE") continue;
- this->objects.emplace_back(new Object(pr, object));
+ if (object["name"] == "ICUE") continue;
+ Object *obj = Object::parse(scene->parser, object);
+ if (obj) scene->objects.emplace_back(obj);
}
+
+ return scene;
+}
+
+auto Scene::offset_camera(s32 x, s32 y) -> void
+{
+ this->cam.offset[0] = x;
+ this->cam.offset[1] = y;
}
auto Scene::get_object_by_id(u32 id) -> Object *
diff --git a/src/objects/scene.h b/src/objects/scene.h
index 7b3d07a..2472fda 100644
--- a/src/objects/scene.h
+++ b/src/objects/scene.h
@@ -11,12 +11,13 @@ struct Camera
vec3 center;
vec3 eye;
vec3 up;
+ vec2 offset = vec2(0.f);
};
class Scene
{
public:
- Scene(const std::string &path);
+ Scene() = default;
~Scene();
Parser parser;
@@ -32,6 +33,10 @@ class Scene
bool clear_enabled;
vec4 clear_color;
+ static auto parse(const std::string &path) -> Scene *;
+
+ auto offset_camera(s32 x, s32 y) -> void;
+
auto get_object_by_id(u32 id) -> Object *;
auto load(Engine *engine) -> void;