port to EnTT v3.10.0

This commit is contained in:
Green Sky 2022-03-25 19:17:01 +01:00 committed by Erik Scholz
parent e0f503728d
commit 4dd5a69dee
25 changed files with 143 additions and 163 deletions

View File

@ -85,8 +85,8 @@ private:
bool entityHasComponent(Registry& registry, EntityType& entity, ComponentTypeID type_id) bool entityHasComponent(Registry& registry, EntityType& entity, ComponentTypeID type_id)
{ {
ComponentTypeID type[] = { type_id }; const auto storage_it = registry.storage(type_id);
return registry.runtime_view(std::cbegin(type), std::cend(type)).contains(entity); return storage_it != registry.storage().end() && storage_it->second.contains(entity);
} }
public: public:
@ -243,7 +243,16 @@ public:
} }
}); });
} else { } else {
auto view = registry.runtime_view(comp_list.begin(), comp_list.end()); entt::basic_runtime_view<entt::basic_sparse_set<EntityType>> view{};
for (const auto type : comp_list) {
auto storage_it = registry.storage(type);
if (storage_it != registry.storage().end()) {
view.iterate(registry.storage(type)->second);
}
}
// TODO: add support for exclude
ImGui::Text("%lu Entities Matching:", view.size_hint()); ImGui::Text("%lu Entities Matching:", view.size_hint());
if (ImGui::BeginChild("entity list")) { if (ImGui::BeginChild("entity list")) {
@ -297,7 +306,8 @@ public:
// MIT License // MIT License
// Copyright (c) 2020 Erik Scholz, Gnik Droy // Copyright (c) 2019-2022 Erik Scholz
// Copyright (c) 2020 Gnik Droy
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal

View File

@ -16,20 +16,20 @@ void Camera3D(MM::Scene& scene) {
ImGui::Indent(); ImGui::Indent();
auto* camera = scene.try_ctx<MM::OpenGL::Camera3D>(); if (!scene.ctx().contains<MM::OpenGL::Camera3D>()) {
if (!camera) {
ImGui::TextUnformatted("NO CAMERA!"); ImGui::TextUnformatted("NO CAMERA!");
return; return;
} }
auto& camera = scene.ctx().at<MM::OpenGL::Camera3D>();
static bool follow_entity = false; static bool follow_entity = false;
static MM::Entity tracking = entt::null; static MM::Entity tracking = entt::null;
ImGui::InputFloat("screenRatio", &camera->screenRatio); ImGui::InputFloat("screenRatio", &camera.screenRatio);
ImGui::InputFloat("nearPlane", &camera->nearPlane); ImGui::InputFloat("nearPlane", &camera.nearPlane);
ImGui::InputFloat("farPlane", &camera->farPlane); ImGui::InputFloat("farPlane", &camera.farPlane);
if (camera->ortho) { if (camera.ortho) {
ImGui::TextUnformatted("orthographic mode"); ImGui::TextUnformatted("orthographic mode");
ImGui::Checkbox("follow entity", &follow_entity); ImGui::Checkbox("follow entity", &follow_entity);
@ -39,39 +39,39 @@ void Camera3D(MM::Scene& scene) {
MM::ImGuiWidgets::Entity(tracking, scene); MM::ImGuiWidgets::Entity(tracking, scene);
if (scene.valid(tracking)) { if (scene.valid(tracking)) {
if (scene.all_of<MM::Components::Position2D>(tracking)) { if (scene.all_of<MM::Components::Position2D>(tracking)) {
camera->translation = {scene.get<MM::Components::Position2D>(tracking).pos, 0.f}; camera.translation = {scene.get<MM::Components::Position2D>(tracking).pos, 0.f};
} else if (scene.all_of<MM::Components::Position3D>(tracking)) { // "3d" fallback } else if (scene.all_of<MM::Components::Position3D>(tracking)) { // "3d" fallback
camera->translation = scene.get<MM::Components::Position3D>(tracking).pos; camera.translation = scene.get<MM::Components::Position3D>(tracking).pos;
} else { } else {
ImGui::TextUnformatted("error: Entity has neither Position2D nor Position3D"); ImGui::TextUnformatted("error: Entity has neither Position2D nor Position3D");
} }
} }
} else { } else {
ImGui::DragFloat2("translation", &camera->translation.x, 0.1f); ImGui::DragFloat2("translation", &camera.translation.x, 0.1f);
} }
ImGui::DragFloat("h_vp_size", &camera->horizontalViewPortSize, 0.1f); ImGui::DragFloat("h_vp_size", &camera.horizontalViewPortSize, 0.1f);
// TODO: aspect ratio // TODO: aspect ratio
// TODO: check for change // TODO: check for change
camera->setOrthographic(); camera.setOrthographic();
} else { // perspective } else { // perspective
ImGui::TextUnformatted("perspective mode"); ImGui::TextUnformatted("perspective mode");
ImGui::DragFloat3("translation", &camera->translation.x, 0.1f); ImGui::DragFloat3("translation", &camera.translation.x, 0.1f);
ImGui::SliderFloat("fov", &camera->fov, 0.1f, glm::pi<float>()); ImGui::SliderFloat("fov", &camera.fov, 0.1f, glm::pi<float>());
ImGui::SliderFloat("yaw", &camera->yaw, 0.0f, 2*glm::pi<float>()); ImGui::SliderFloat("yaw", &camera.yaw, 0.0f, 2*glm::pi<float>());
ImGui::SliderFloat("pitch", &camera->pitch, -glm::pi<float>()/2, glm::pi<float>()/2); ImGui::SliderFloat("pitch", &camera.pitch, -glm::pi<float>()/2, glm::pi<float>()/2);
ImGui::InputFloat3("up", &camera->up.x); ImGui::InputFloat3("up", &camera.up.x);
camera->setPerspective(); camera.setPerspective();
} }
camera->updateView(); camera.updateView();
ImGui::Unindent(); ImGui::Unindent();
} }

View File

@ -71,14 +71,13 @@ namespace MM::Services {
}; };
menu_bar.menu_tree["Scene"]["TimeCtx"] = [this](Engine& e) { menu_bar.menu_tree["Scene"]["TimeCtx"] = [this](Engine& e) {
MM::Components::TimeDelta* td_ptr = nullptr; bool have_ctx = false;
if (auto* ssi_ptr = e.tryService<MM::Services::SceneServiceInterface>()) { if (auto* ssi_ptr = e.tryService<MM::Services::SceneServiceInterface>()) {
auto& scene = ssi_ptr->getScene(); have_ctx = ssi_ptr->getScene().ctx().contains<MM::Components::TimeDelta>();
td_ptr = scene.try_ctx<MM::Components::TimeDelta>();
} }
ImGui::MenuItem("TimeDelta Context", NULL, &_show_time_delta_ctx, td_ptr); ImGui::MenuItem("TimeDelta Context", NULL, &_show_time_delta_ctx, have_ctx);
}; };
// add task // add task
@ -157,10 +156,13 @@ namespace MM::Services {
if (_show_time_delta_ctx) { if (_show_time_delta_ctx) {
if (ImGui::Begin("Scene TimeDelta Context", &_show_time_delta_ctx)) { if (ImGui::Begin("Scene TimeDelta Context", &_show_time_delta_ctx)) {
auto* td_ptr = scene.try_ctx<MM::Components::TimeDelta>(); if (scene.ctx().contains<MM::Components::TimeDelta>()) {
ImGui::Value("tickDelta", td_ptr->tickDelta); auto& td = scene.ctx().at<MM::Components::TimeDelta>();
ImGui::SliderFloat("deltaFactor", &td_ptr->deltaFactor, 0.f, 10.f, "%.5f", ImGuiSliderFlags_Logarithmic); ImGui::Value("tickDelta", td.tickDelta);
ImGui::SliderFloat("deltaFactor", &td.deltaFactor, 0.f, 10.f, "%.5f", ImGuiSliderFlags_Logarithmic);
} else {
ImGui::TextUnformatted("No TimeDelta");
}
} }
ImGui::End(); ImGui::End();
} }

View File

@ -27,9 +27,6 @@
namespace MM::OpenGL::RenderTasks { namespace MM::OpenGL::RenderTasks {
BatchedSpriteSheet::BatchedSpriteSheet(Engine& engine) { BatchedSpriteSheet::BatchedSpriteSheet(Engine& engine) {
default_cam.setOrthographic();
default_cam.updateView();
float vertices[] = { float vertices[] = {
-0.5f, 0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f, -0.5f,
@ -70,6 +67,10 @@ void BatchedSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
auto& scene = ssi->getScene(); auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
struct sp_data { struct sp_data {
SpriteSheet sp; SpriteSheet sp;
struct instance_data { struct instance_data {
@ -116,12 +117,9 @@ void BatchedSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER); _vertexBuffer->bind(GL_ARRAY_BUFFER);
_vao->bind(); _vao->bind();
auto* cam = scene.try_ctx<Camera3D>(); auto& cam = scene.ctx().at<Camera3D>();
if (!cam) {
cam = &default_cam;
}
auto vp = cam->getViewProjection(); auto vp = cam.getViewProjection();
_shader->setUniformMat4f("_VP", vp); _shader->setUniformMat4f("_VP", vp);
for (auto& sp_ent : batch_map) { for (auto& sp_ent : batch_map) {

View File

@ -37,8 +37,6 @@ namespace MM::OpenGL::RenderTasks {
public: public:
glm::vec4 default_color {1.f, 1.f, 1.f, 1.f}; glm::vec4 default_color {1.f, 1.f, 1.f, 1.f};
OpenGL::Camera3D default_cam;
BatchedSpriteSheet(Engine& engine); BatchedSpriteSheet(Engine& engine);
~BatchedSpriteSheet(void); ~BatchedSpriteSheet(void);

View File

@ -47,7 +47,6 @@ FastSky::FastSky(MM::Engine& engine) {
_vertexBuffer->unbind(GL_ARRAY_BUFFER); _vertexBuffer->unbind(GL_ARRAY_BUFFER);
_vao->unbind(); _vao->unbind();
} }
FastSky::~FastSky(void) { FastSky::~FastSky(void) {
@ -56,6 +55,17 @@ FastSky::~FastSky(void) {
void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) { void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
ZoneScopedN("MM::OpenGL::RenderTasks::FastSky::render"); ZoneScopedN("MM::OpenGL::RenderTasks::FastSky::render");
auto* ssi = engine.tryService<MM::Services::SceneServiceInterface>();
if (ssi == nullptr) {
return; // nothing to draw
}
auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
rs.targets[target_fbo]->bind(MM::OpenGL::FrameBufferObject::W); rs.targets[target_fbo]->bind(MM::OpenGL::FrameBufferObject::W);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -67,9 +77,8 @@ void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER); _vertexBuffer->bind(GL_ARRAY_BUFFER);
_vao->bind(); _vao->bind();
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
{ {
auto& cam = scene.ctx<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().at<MM::OpenGL::Camera3D>();
MM::OpenGL::Camera3D tmp_cam = cam; MM::OpenGL::Camera3D tmp_cam = cam;
// create cam with y up, bc shader says so // create cam with y up, bc shader says so
tmp_cam.up = {0, 1, 0}; tmp_cam.up = {0, 1, 0};
@ -80,9 +89,13 @@ void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
} }
{ {
auto* ctx_ptr = scene.try_ctx<FastSkyContext>(); //auto* ctx_ptr = scene.try_ctx<FastSkyContext>();
if (!ctx_ptr) { //if (!ctx_ptr) {
ctx_ptr = &_default_context; //ctx_ptr = &_default_context;
//}
auto* ctx_ptr = &_default_context;
if (scene.ctx().contains<FastSkyContext>()) {
ctx_ptr = &scene.ctx().at<FastSkyContext>();
} }
_shader->setUniform1f("time", ctx_ptr->time); _shader->setUniform1f("time", ctx_ptr->time);

View File

@ -22,9 +22,6 @@
namespace MM::OpenGL::RenderTasks { namespace MM::OpenGL::RenderTasks {
SimpleRect::SimpleRect(Engine& engine) { SimpleRect::SimpleRect(Engine& engine) {
default_cam.setOrthographic();
default_cam.updateView();
float vertices[] = { float vertices[] = {
-0.5f, 0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f, -0.5f,
@ -63,6 +60,10 @@ void SimpleRect::render(Services::OpenGLRenderer& rs, Engine& engine) {
auto& scene = ssi->getScene(); auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
rs.targets[target_fbo]->bind(FrameBufferObject::RW); rs.targets[target_fbo]->bind(FrameBufferObject::RW);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -71,12 +72,8 @@ void SimpleRect::render(Services::OpenGLRenderer& rs, Engine& engine) {
_shader->bind(); _shader->bind();
_vao->bind(); _vao->bind();
Camera3D* cam = scene.try_ctx<Camera3D>(); Camera3D& cam = scene.ctx().at<Camera3D>();
if (!cam) { auto vp = cam.getViewProjection();
cam = &default_cam;
}
auto vp = cam->getViewProjection();
scene.view<const Components::Transform4x4>().each([this, &scene, &vp](entt::entity e, const auto& t) { scene.view<const Components::Transform4x4>().each([this, &scene, &vp](entt::entity e, const auto& t) {
_shader->setUniformMat4f("_WVP", vp * t.trans); _shader->setUniformMat4f("_WVP", vp * t.trans);

View File

@ -5,7 +5,6 @@
#include <mm/opengl/camera_3d.hpp> #include <mm/opengl/camera_3d.hpp>
//#include <glm/fwd.hpp>
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
// fwd // fwd
@ -26,8 +25,6 @@ namespace MM::OpenGL::RenderTasks {
public: public:
glm::vec4 default_color {1,1,1,1}; glm::vec4 default_color {1,1,1,1};
Camera3D default_cam;
SimpleRect(Engine& engine); SimpleRect(Engine& engine);
~SimpleRect(void); ~SimpleRect(void);

View File

@ -28,9 +28,6 @@
namespace MM::OpenGL::RenderTasks { namespace MM::OpenGL::RenderTasks {
SimpleSprite::SimpleSprite(Engine& engine) { SimpleSprite::SimpleSprite(Engine& engine) {
default_cam.setOrthographic();
default_cam.updateView();
float vertices[] = { float vertices[] = {
-0.5f, 0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f, -0.5f,
@ -69,6 +66,10 @@ void SimpleSprite::render(Services::OpenGLRenderer& rs, Engine& engine) {
auto& scene = ssi->getScene(); auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
rs.targets[target_fbo]->bind(FrameBufferObject::W); rs.targets[target_fbo]->bind(FrameBufferObject::W);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -79,12 +80,8 @@ void SimpleSprite::render(Services::OpenGLRenderer& rs, Engine& engine) {
_vao->bind(); _vao->bind();
auto* cam = scene.try_ctx<Camera3D>(); Camera3D& cam = scene.ctx().at<Camera3D>();
if (!cam) { auto vp = cam.getViewProjection();
cam = &default_cam;
}
auto vp = cam->getViewProjection();
scene.view<const Components::Transform4x4, Components::OpenGL::Texture>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& tex) { scene.view<const Components::Transform4x4, Components::OpenGL::Texture>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& tex) {
assert(tex.tex); // debug assert(tex.tex); // debug

View File

@ -26,8 +26,6 @@ namespace MM::OpenGL::RenderTasks {
public: public:
glm::vec4 default_color {1,1,1,1}; glm::vec4 default_color {1,1,1,1};
Camera3D default_cam;
SimpleSprite(Engine& engine); SimpleSprite(Engine& engine);
~SimpleSprite(void); ~SimpleSprite(void);

View File

@ -30,9 +30,6 @@
namespace MM::OpenGL::RenderTasks { namespace MM::OpenGL::RenderTasks {
SimpleSpriteSheet::SimpleSpriteSheet(Engine& engine) { SimpleSpriteSheet::SimpleSpriteSheet(Engine& engine) {
default_cam.setOrthographic();
default_cam.updateView();
float vertices[] = { float vertices[] = {
-0.5f, 0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f, -0.5f,
@ -56,11 +53,6 @@ SimpleSpriteSheet::SimpleSpriteSheet(Engine& engine) {
setupShaderFiles(); setupShaderFiles();
_shader = Shader::createF(engine, vertexPath, fragmentPath); _shader = Shader::createF(engine, vertexPath, fragmentPath);
assert(_shader != nullptr); assert(_shader != nullptr);
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
if (!scene.try_ctx<Camera3D>()) {
LOG_SSSR("warn: scene has no Camera!");
}
} }
SimpleSpriteSheet::~SimpleSpriteSheet(void) { SimpleSpriteSheet::~SimpleSpriteSheet(void) {
@ -76,6 +68,10 @@ void SimpleSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
auto& scene = ssi->getScene(); auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
rs.targets[target_fbo]->bind(FrameBufferObject::W); rs.targets[target_fbo]->bind(FrameBufferObject::W);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -85,12 +81,8 @@ void SimpleSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER); _vertexBuffer->bind(GL_ARRAY_BUFFER);
_vao->bind(); _vao->bind();
auto* cam = scene.try_ctx<Camera3D>(); Camera3D& cam = scene.ctx().at<Camera3D>();
if (!cam) { auto vp = cam.getViewProjection();
cam = &default_cam;
}
auto vp = cam->getViewProjection();
scene.view<const Components::Transform4x4, SpriteSheetRenderable>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& spr) { scene.view<const Components::Transform4x4, SpriteSheetRenderable>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& spr) {
assert(spr.sp.tex); // debug assert(spr.sp.tex); // debug

View File

@ -26,8 +26,6 @@ namespace MM::OpenGL::RenderTasks {
public: public:
glm::vec4 default_color {1.f, 1.f, 1.f, 1.f}; glm::vec4 default_color {1.f, 1.f, 1.f, 1.f};
Camera3D default_cam;
SimpleSpriteSheet(Engine& engine); SimpleSpriteSheet(Engine& engine);
~SimpleSpriteSheet(void); ~SimpleSpriteSheet(void);

View File

@ -75,6 +75,17 @@ Tilemap::~Tilemap(void) {
void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) { void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
ZoneScopedN("MM::OpenGL::Renderers::TilemapRenderer::render"); ZoneScopedN("MM::OpenGL::Renderers::TilemapRenderer::render");
auto* ssi = engine.tryService<MM::Services::SceneServiceInterface>();
if (ssi == nullptr) {
return; // nothing to draw
}
auto& scene = ssi->getScene();
if (!scene.ctx().contains<Camera3D>()) {
return; // nothing to draw
}
rs.targets[target_fbo]->bind(MM::OpenGL::FrameBufferObject::W); rs.targets[target_fbo]->bind(MM::OpenGL::FrameBufferObject::W);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -85,17 +96,13 @@ void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER); _vertexBuffer->bind(GL_ARRAY_BUFFER);
_vao->bind(); _vao->bind();
MM::OpenGL::Camera3D& cam = scene.ctx().at<MM::OpenGL::Camera3D>();
auto& scene = engine.tryService<Services::SceneServiceInterface>()->getScene();
MM::OpenGL::Camera3D& cam = scene.ctx<MM::OpenGL::Camera3D>();
auto vp = cam.getViewProjection(); auto vp = cam.getViewProjection();
_shader->setUniform3f("_ambient_color", ambient_color); _shader->setUniform3f("_ambient_color", ambient_color);
scene.view<MM::Components::Transform4x4, OpenGL::TilemapRenderable>() scene.view<MM::Components::Transform4x4, OpenGL::TilemapRenderable>()
.each([&](auto, MM::Components::Transform4x4& t, OpenGL::TilemapRenderable& tilemap) { .each([&](auto, MM::Components::Transform4x4& t, OpenGL::TilemapRenderable& tilemap) {
//_shader->setUniformMat4f("_WVP", vp * t.getTransform4(tilemap.z + 500.f));
_shader->setUniformMat4f("_WVP", vp * t.trans); _shader->setUniformMat4f("_WVP", vp * t.trans);
// for each sprite layer // for each sprite layer

View File

@ -68,7 +68,7 @@ TEST(batched_spritesheet_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
auto& cam = scene.set<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.horizontalViewPortSize = 5; cam.horizontalViewPortSize = 5;
cam.setOrthographic(); cam.setOrthographic();
cam.updateView(); cam.updateView();
@ -87,8 +87,8 @@ TEST(batched_spritesheet_render_task, it) {
// setup systems // setup systems
scene.set<float>(0.f); // accu scene.ctx().emplace<float>(0.f); // accu
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&update_spritesheet_animation>("update_spritesheet_animation"); org.emplace<&update_spritesheet_animation>("update_spritesheet_animation");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -129,9 +129,12 @@ TEST(blur_render_task, it) {
scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.setOrthographic();
cam.updateView();
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching"); org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -42,18 +42,18 @@ TEST(fast_sky_render_task, it) {
rs.addRenderTask<MM::OpenGL::RenderTasks::FastSky>(engine); rs.addRenderTask<MM::OpenGL::RenderTasks::FastSky>(engine);
// setup systems // setup systems
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&MM::Systems::fast_sky_sun>("fast_sky_sun"); org.emplace<&MM::Systems::fast_sky_sun>("fast_sky_sun");
// HACK: instead you would switch to this scene // HACK: instead you would switch to this scene
engine.getService<MM::Services::OrganizerSceneService>().updateOrganizerVertices(scene); engine.getService<MM::Services::OrganizerSceneService>().updateOrganizerVertices(scene);
auto& cam = scene.set<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.setPerspective(); cam.setPerspective();
cam.updateView(); cam.updateView();
scene.set<MM::OpenGL::RenderTasks::FastSkyContext>(); scene.ctx().emplace<MM::OpenGL::RenderTasks::FastSkyContext>();
engine.run(); engine.run();
} }

View File

@ -119,46 +119,6 @@ static void setup_fbos(MM::Engine& engine) {
const float render_scale = 1.f; const float render_scale = 1.f;
#if 0
rs.targets["clear_opaque"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("albedo"_hs), GL_COLOR_ATTACHMENT0)
.attachTexture(rm_t.get("opaque_depth"_hs), GL_DEPTH_ATTACHMENT)
.setResize(true)
.finish();
assert(rs.targets["clear_opaque"]);
rs.targets["clear_opaque_normal"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("normal"_hs), GL_COLOR_ATTACHMENT0)
.setResize(true)
.finish();
assert(rs.targets["clear_opaque"]);
rs.targets["opaque"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("albedo"_hs), GL_COLOR_ATTACHMENT0)
.attachTexture(rm_t.get("normal"_hs), GL_COLOR_ATTACHMENT1)
.attachTexture(rm_t.get("opaque_depth"_hs), GL_DEPTH_ATTACHMENT)
.setResize(true)
.finish();
assert(rs.targets["opaque"]);
rs.targets["tmp_read"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("normal"_hs), GL_COLOR_ATTACHMENT0)
.setResize(false)
.finish();
assert(rs.targets["tmp_read"]);
rs.targets["depth_read"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("opaque_depth"_hs), GL_DEPTH_ATTACHMENT)
.setResize(false)
.finish();
assert(rs.targets["depth_read"]);
rs.targets["deferred_shading"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("hdr_color"_hs), GL_COLOR_ATTACHMENT0)
.setResize(true)
.finish();
assert(rs.targets["deferred_shading"]);
#endif
rs.targets["game_view"] = MM::OpenGL::FBOBuilder::start() rs.targets["game_view"] = MM::OpenGL::FBOBuilder::start()
.attachTexture(rm_t.get("hdr_color"_hs), GL_COLOR_ATTACHMENT0) .attachTexture(rm_t.get("hdr_color"_hs), GL_COLOR_ATTACHMENT0)
.attachTexture(rm_t.get("depth"_hs), GL_DEPTH_ATTACHMENT) .attachTexture(rm_t.get("depth"_hs), GL_DEPTH_ATTACHMENT)
@ -230,9 +190,12 @@ TEST(hdr_bloom_pipeline, it) {
scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.setOrthographic();
cam.updateView();
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching"); org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -62,8 +62,12 @@ TEST(simple_rect_render_task, it) {
scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.setOrthographic();
cam.updateView();
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching"); org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -65,9 +65,12 @@ TEST(simple_sprite_render_task, it) {
scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched scene.on_update<MM::Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); // in this example only rotation is touched
auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.setOrthographic();
cam.updateView();
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching"); org.emplace<MM::Systems::simple_rotational_velocity_patching>("simple_rotational_velocity_patching");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -64,7 +64,7 @@ TEST(simple_spritesheet_render_task, it) {
auto& rs = engine.addService<MM::Services::OpenGLRenderer>(); auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>()); ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
auto& cam = scene.set<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.horizontalViewPortSize = 5; cam.horizontalViewPortSize = 5;
cam.setOrthographic(); cam.setOrthographic();
cam.updateView(); cam.updateView();
@ -82,8 +82,8 @@ TEST(simple_spritesheet_render_task, it) {
scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Scale2D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
// setup systems // setup systems
scene.set<float>(0.f); // accu scene.ctx().emplace<float>(0.f); // accu
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&update_spritesheet_animation>("update_spritesheet_animation"); org.emplace<&update_spritesheet_animation>("update_spritesheet_animation");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");

View File

@ -39,7 +39,7 @@ TEST(tilemap_render_task_test, it) {
ASSERT_TRUE(provide_ret); ASSERT_TRUE(provide_ret);
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene(); auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
auto& cam = scene.set<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.translation = {2.f, -2.f, 0.f}; cam.translation = {2.f, -2.f, 0.f};
cam.horizontalViewPortSize = 20.f; cam.horizontalViewPortSize = 20.f;
cam.setOrthographic(); cam.setOrthographic();
@ -63,7 +63,7 @@ TEST(tilemap_render_task_test, it) {
scene.on_update<MM::Components::Position2D_ZOffset>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Position2D_ZOffset>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
scene.on_update<MM::Components::Position3D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>(); scene.on_update<MM::Components::Position3D>().connect<&entt::registry::emplace_or_replace<MM::Components::DirtyTransformTag>>();
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d"); org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate"); org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");
org.emplace<MM::Systems::transform_clear_dirty>("transform_clear_dirty"); org.emplace<MM::Systems::transform_clear_dirty>("transform_clear_dirty");

View File

@ -52,7 +52,7 @@ bool OrganizerSceneService::enable(Engine& engine, std::vector<UpdateStrategies:
// default scene // default scene
if (!_scene) { if (!_scene) {
_scene = std::make_unique<Scene>(); _scene = std::make_unique<Scene>();
_scene->set<MM::Engine&>(engine); _scene->ctx().emplace<MM::Engine&>(engine);
updateOrganizerVertices(*_scene); updateOrganizerVertices(*_scene);
} }
@ -74,14 +74,14 @@ void OrganizerSceneService::sceneFixedUpdate(Engine&) {
size_t continuous_counter = 0; size_t continuous_counter = 0;
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor); auto& time_ctx = _scene->ctx().emplace<MM::Components::TimeDelta>(f_delta, initial_delta_factor);
time_ctx.tickDelta = f_delta * time_ctx.deltaFactor; time_ctx.tickDelta = f_delta * time_ctx.deltaFactor;
while (_accumulator >= f_delta){ while (_accumulator >= f_delta){
_accumulator -= f_delta; _accumulator -= f_delta;
continuous_counter++; continuous_counter++;
for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) { for (auto&& v : _scene->ctx().at<std::vector<entt::organizer::vertex>>()) {
v.callback()(v.data(), *_scene); v.callback()(v.data(), *_scene);
} }
@ -97,8 +97,8 @@ void OrganizerSceneService::changeSceneFixedUpdate(Engine& engine) {
if (_next_scene) { if (_next_scene) {
LOG_OSS("changing scene..."); LOG_OSS("changing scene...");
_scene = std::move(_next_scene); _scene = std::move(_next_scene);
if (!_scene->try_ctx<MM::Engine>()) { if (!_scene->ctx().contains<MM::Engine>()) {
_scene->set<MM::Engine&>(engine); // make engine accessible from scene _scene->ctx().emplace<MM::Engine&>(engine); // make engine accessible from scene
} }
updateOrganizerVertices(*_scene); updateOrganizerVertices(*_scene);
} }
@ -119,14 +119,14 @@ void OrganizerSceneService::changeSceneNow(std::unique_ptr<Scene>&& new_scene) {
} }
void OrganizerSceneService::updateOrganizerVertices(Scene& scene) { void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
scene.ctx_or_set<std::vector<entt::organizer::vertex>>() = scene.ctx().emplace<std::vector<entt::organizer::vertex>>() =
scene.ctx_or_set<entt::organizer>().graph(); scene.ctx().emplace<entt::organizer>().graph();
if (!scene.try_ctx<MM::Components::TimeDelta>()) { if (!scene.ctx().contains<MM::Components::TimeDelta>()) {
scene.set<MM::Components::TimeDelta>(); scene.ctx().emplace<MM::Components::TimeDelta>();
} }
SPDLOG_DEBUG("graph:\n{}", scene.ctx<std::vector<entt::organizer::vertex>>()); SPDLOG_DEBUG("graph:\n{}", scene.ctx().at<std::vector<entt::organizer::vertex>>());
} }
void OrganizerSceneService::resetTime(void) { void OrganizerSceneService::resetTime(void) {

View File

@ -120,11 +120,11 @@ void create_mm_logo(MM::Engine& engine, MM::Services::ScreenDirector::Screen& sc
auto new_scene = std::make_unique<MM::Scene>(); auto new_scene = std::make_unique<MM::Scene>();
auto& scene = *new_scene; auto& scene = *new_scene;
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
scene.set<MM::Engine&>(_engine); // alias scene.ctx().emplace<MM::Engine&>(_engine); // alias
scene.set<Components::screen_timer>(0.f, screen_duration, next_screen); scene.ctx().emplace<Components::screen_timer>(0.f, screen_duration, next_screen);
org.emplace<Systems::screen_timer_system>("screen_timer_system"); org.emplace<Systems::screen_timer_system>("screen_timer_system");
@ -135,7 +135,7 @@ void create_mm_logo(MM::Engine& engine, MM::Services::ScreenDirector::Screen& sc
org.emplace<MM::Systems::transform3d_scale2d>("transform3d_scale2d"); org.emplace<MM::Systems::transform3d_scale2d>("transform3d_scale2d");
//org.emplace<MM::Systems::transform_clear_dirty>("transform_clear_dirty"); //org.emplace<MM::Systems::transform_clear_dirty>("transform_clear_dirty");
auto& cam = scene.set<MM::OpenGL::Camera3D>(); auto& cam = scene.ctx().emplace<MM::OpenGL::Camera3D>();
cam.horizontalViewPortSize = 89.f; cam.horizontalViewPortSize = 89.f;
cam.setOrthographic(); cam.setOrthographic();
cam.updateView(); cam.updateView();

View File

@ -29,7 +29,7 @@ TEST(player_velocity, basic_run) {
auto& scene = engine.getService<MM::Services::SceneServiceInterface>().getScene(); auto& scene = engine.getService<MM::Services::SceneServiceInterface>().getScene();
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&MM::Systems::player_velocity2d>("player_velocity2d"); org.emplace<&MM::Systems::player_velocity2d>("player_velocity2d");
// HACK: instead you would switch to this scene // HACK: instead you would switch to this scene

View File

@ -11,13 +11,13 @@ TEST(simple_velocity_2d, basic_run) {
MM::Scene scene; MM::Scene scene;
// setup v system // setup v system
auto& org = scene.set<entt::organizer>(); auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&MM::Systems::simple_positional_velocity>("simple_positional_velocity"); org.emplace<&MM::Systems::simple_positional_velocity>("simple_positional_velocity");
org.emplace<&MM::Systems::simple_rotational_velocity>("simple_rotational_velocity"); org.emplace<&MM::Systems::simple_rotational_velocity>("simple_rotational_velocity");
auto graph = org.graph(); auto graph = org.graph();
// setup delta // setup delta
auto& time_ctx = scene.ctx_or_set<MM::Components::TimeDelta>(1.f/60.f, 1.f); auto& time_ctx = scene.ctx().emplace<MM::Components::TimeDelta>(1.f/60.f, 1.f);
time_ctx.tickDelta = 1.f/60.f * time_ctx.deltaFactor; time_ctx.tickDelta = 1.f/60.f * time_ctx.deltaFactor;
// setup test entity // setup test entity