|
|
@@ -10,9 +10,10 @@
|
|
|
|
|
|
#include <json/json.h>
|
|
|
|
|
|
+#include "game/graphics/manager.hpp"
|
|
|
#include "game/graphics/material.hpp"
|
|
|
#include "game/graphics/object.hpp"
|
|
|
-#include "game/util/flyweight.hpp"
|
|
|
+#include "game/util/identity.hpp"
|
|
|
#include "vector/vector.hpp"
|
|
|
|
|
|
namespace engine {
|
|
|
@@ -24,27 +25,31 @@ namespace engine {
|
|
|
return json.isNull() ? backup : to_vec2(json);
|
|
|
}
|
|
|
|
|
|
- flyweight<graphics::shader_program> to_program(Json::Value const & json) {
|
|
|
- using graphics::shader_program;
|
|
|
+ identity<graphics::shader_program> to_program(Json::Value const & json,
|
|
|
+ graphics::manager const & mgr) {
|
|
|
if (json.empty()) {
|
|
|
- return shader_program::create("data/shaders/BlankShader.fragment.glsl",
|
|
|
- "data/shaders/BlankShader.vertex.glsl");
|
|
|
+ return mgr.get("data/shaders/BlankShader.fragment.glsl",
|
|
|
+ "data/shaders/BlankShader.vertex.glsl");
|
|
|
}
|
|
|
- return shader_program::create(json["fragmentShader"].asString(),
|
|
|
- json["vertexShader"].asString());
|
|
|
+ return mgr.get(json["fragmentShader"].asString(),
|
|
|
+ json["vertexShader"].asString());
|
|
|
}
|
|
|
|
|
|
- flyweight<graphics::material> to_material(Json::Value const & json) {
|
|
|
- auto & prog = to_program(json["shaderProgram"]).actual();
|
|
|
- return graphics::material::create(prog, json["texture"]["file"].asString(),
|
|
|
- json["texture"]["uniform"].asString());
|
|
|
+ identity<graphics::material> to_material(Json::Value const & json,
|
|
|
+ graphics::manager const & mgr) {
|
|
|
+ return mgr.get(to_program(json["shaderProgram"], mgr),
|
|
|
+ json["texture"]["file"].asString(),
|
|
|
+ json["texture"]["uniform"].asString());
|
|
|
}
|
|
|
|
|
|
- graphics::object to_object(Json::Value const & json) {
|
|
|
- flyweight<graphics::material> mat = to_material(json["material"]);
|
|
|
+ graphics::object to_object(Json::Value const & json,
|
|
|
+ graphics::manager const & mgr) {
|
|
|
+ identity<graphics::material> mat = to_material(json["material"], mgr);
|
|
|
auto frame_size = to_vec2(json["frameSize"], make_vector(1.f, 1.f));
|
|
|
- math::dim2::rectangle pos = {to_vec2(json["position"]),
|
|
|
- mat.actual().size() * frame_size};
|
|
|
- return {pos, pos, mat, {{{0, 0}}, frame_size}};
|
|
|
+ auto origin = to_vec2(json["position"]);
|
|
|
+ return mgr.create_object(mat, origin, frame_size);
|
|
|
+ // math::dim2::rectangle pos = {to_vec2(json["position"]),
|
|
|
+ // mat.actual().size() * frame_size};
|
|
|
+ // return {pos, pos, mat, {{{0, 0}}, frame_size}};
|
|
|
}
|
|
|
}
|