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)
{
ComponentTypeID type[] = { type_id };
return registry.runtime_view(std::cbegin(type), std::cend(type)).contains(entity);
const auto storage_it = registry.storage(type_id);
return storage_it != registry.storage().end() && storage_it->second.contains(entity);
}
public:
@ -243,7 +243,16 @@ public:
}
});
} 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());
if (ImGui::BeginChild("entity list")) {
@ -297,7 +306,8 @@ public:
// 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
// of this software and associated documentation files (the "Software"), to deal

View File

@ -16,20 +16,20 @@ void Camera3D(MM::Scene& scene) {
ImGui::Indent();
auto* camera = scene.try_ctx<MM::OpenGL::Camera3D>();
if (!camera) {
if (!scene.ctx().contains<MM::OpenGL::Camera3D>()) {
ImGui::TextUnformatted("NO CAMERA!");
return;
}
auto& camera = scene.ctx().at<MM::OpenGL::Camera3D>();
static bool follow_entity = false;
static MM::Entity tracking = entt::null;
ImGui::InputFloat("screenRatio", &camera->screenRatio);
ImGui::InputFloat("nearPlane", &camera->nearPlane);
ImGui::InputFloat("farPlane", &camera->farPlane);
ImGui::InputFloat("screenRatio", &camera.screenRatio);
ImGui::InputFloat("nearPlane", &camera.nearPlane);
ImGui::InputFloat("farPlane", &camera.farPlane);
if (camera->ortho) {
if (camera.ortho) {
ImGui::TextUnformatted("orthographic mode");
ImGui::Checkbox("follow entity", &follow_entity);
@ -39,39 +39,39 @@ void Camera3D(MM::Scene& scene) {
MM::ImGuiWidgets::Entity(tracking, scene);
if (scene.valid(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
camera->translation = scene.get<MM::Components::Position3D>(tracking).pos;
camera.translation = scene.get<MM::Components::Position3D>(tracking).pos;
} else {
ImGui::TextUnformatted("error: Entity has neither Position2D nor Position3D");
}
}
} 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: check for change
camera->setOrthographic();
camera.setOrthographic();
} else { // perspective
ImGui::TextUnformatted("perspective mode");
ImGui::DragFloat3("translation", &camera->translation.x, 0.1f);
ImGui::SliderFloat("fov", &camera->fov, 0.1f, glm::pi<float>());
ImGui::DragFloat3("translation", &camera.translation.x, 0.1f);
ImGui::SliderFloat("fov", &camera.fov, 0.1f, 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("yaw", &camera.yaw, 0.0f, 2*glm::pi<float>());
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();
}

View File

@ -71,14 +71,13 @@ namespace MM::Services {
};
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>()) {
auto& scene = ssi_ptr->getScene();
td_ptr = scene.try_ctx<MM::Components::TimeDelta>();
have_ctx = ssi_ptr->getScene().ctx().contains<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
@ -157,10 +156,13 @@ namespace MM::Services {
if (_show_time_delta_ctx) {
if (ImGui::Begin("Scene TimeDelta Context", &_show_time_delta_ctx)) {
auto* td_ptr = scene.try_ctx<MM::Components::TimeDelta>();
ImGui::Value("tickDelta", td_ptr->tickDelta);
ImGui::SliderFloat("deltaFactor", &td_ptr->deltaFactor, 0.f, 10.f, "%.5f", ImGuiSliderFlags_Logarithmic);
if (scene.ctx().contains<MM::Components::TimeDelta>()) {
auto& td = scene.ctx().at<MM::Components::TimeDelta>();
ImGui::Value("tickDelta", td.tickDelta);
ImGui::SliderFloat("deltaFactor", &td.deltaFactor, 0.f, 10.f, "%.5f", ImGuiSliderFlags_Logarithmic);
} else {
ImGui::TextUnformatted("No TimeDelta");
}
}
ImGui::End();
}

View File

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

View File

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

View File

@ -47,7 +47,6 @@ FastSky::FastSky(MM::Engine& engine) {
_vertexBuffer->unbind(GL_ARRAY_BUFFER);
_vao->unbind();
}
FastSky::~FastSky(void) {
@ -56,6 +55,17 @@ FastSky::~FastSky(void) {
void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
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);
glEnable(GL_DEPTH_TEST);
@ -67,9 +77,8 @@ void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER);
_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;
// create cam with y up, bc shader says so
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>();
if (!ctx_ptr) {
ctx_ptr = &_default_context;
//auto* ctx_ptr = scene.try_ctx<FastSkyContext>();
//if (!ctx_ptr) {
//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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -75,6 +75,17 @@ Tilemap::~Tilemap(void) {
void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
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);
glEnable(GL_DEPTH_TEST);
@ -85,17 +96,13 @@ void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
_vertexBuffer->bind(GL_ARRAY_BUFFER);
_vao->bind();
auto& scene = engine.tryService<Services::SceneServiceInterface>()->getScene();
MM::OpenGL::Camera3D& cam = scene.ctx<MM::OpenGL::Camera3D>();
MM::OpenGL::Camera3D& cam = scene.ctx().at<MM::OpenGL::Camera3D>();
auto vp = cam.getViewProjection();
_shader->setUniform3f("_ambient_color", ambient_color);
scene.view<MM::Components::Transform4x4, OpenGL::TilemapRenderable>()
.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);
// for each sprite layer

View File

@ -68,7 +68,7 @@ TEST(batched_spritesheet_render_task, it) {
auto& rs = engine.addService<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.setOrthographic();
cam.updateView();
@ -87,8 +87,8 @@ TEST(batched_spritesheet_render_task, it) {
// setup systems
scene.set<float>(0.f); // accu
auto& org = scene.set<entt::organizer>();
scene.ctx().emplace<float>(0.f); // accu
auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&update_spritesheet_animation>("update_spritesheet_animation");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
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::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
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::position3d_from_2d>("position3d_from_2d");
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);
// 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");
// HACK: instead you would switch to this 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.updateView();
scene.set<MM::OpenGL::RenderTasks::FastSkyContext>();
scene.ctx().emplace<MM::OpenGL::RenderTasks::FastSkyContext>();
engine.run();
}

View File

@ -119,46 +119,6 @@ static void setup_fbos(MM::Engine& engine) {
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()
.attachTexture(rm_t.get("hdr_color"_hs), GL_COLOR_ATTACHMENT0)
.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::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
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::position3d_from_2d>("position3d_from_2d");
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::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
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::position3d_from_2d>("position3d_from_2d");
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::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
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::position3d_from_2d>("position3d_from_2d");
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>();
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.setOrthographic();
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>>();
// setup systems
scene.set<float>(0.f); // accu
auto& org = scene.set<entt::organizer>();
scene.ctx().emplace<float>(0.f); // accu
auto& org = scene.ctx().emplace<entt::organizer>();
org.emplace<&update_spritesheet_animation>("update_spritesheet_animation");
org.emplace<MM::Systems::position3d_from_2d>("position3d_from_2d");
org.emplace<MM::Systems::transform3d_translate>("transform3d_translate");
@ -103,7 +103,7 @@ TEST(simple_spritesheet_render_task, it) {
auto e = scene.create();
auto& p = scene.emplace<MM::Components::Position2D>(e);
p.pos.x = -1.f;
// zoffset is created by event
auto& s = scene.emplace<MM::Components::Scale2D>(e);

View File

@ -39,7 +39,7 @@ TEST(tilemap_render_task_test, it) {
ASSERT_TRUE(provide_ret);
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.horizontalViewPortSize = 20.f;
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::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::transform3d_translate>("transform3d_translate");
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
if (!_scene) {
_scene = std::make_unique<Scene>();
_scene->set<MM::Engine&>(engine);
_scene->ctx().emplace<MM::Engine&>(engine);
updateOrganizerVertices(*_scene);
}
@ -74,14 +74,14 @@ void OrganizerSceneService::sceneFixedUpdate(Engine&) {
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;
while (_accumulator >= f_delta){
_accumulator -= f_delta;
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);
}
@ -97,8 +97,8 @@ void OrganizerSceneService::changeSceneFixedUpdate(Engine& engine) {
if (_next_scene) {
LOG_OSS("changing scene...");
_scene = std::move(_next_scene);
if (!_scene->try_ctx<MM::Engine>()) {
_scene->set<MM::Engine&>(engine); // make engine accessible from scene
if (!_scene->ctx().contains<MM::Engine>()) {
_scene->ctx().emplace<MM::Engine&>(engine); // make engine accessible from scene
}
updateOrganizerVertices(*_scene);
}
@ -119,14 +119,14 @@ void OrganizerSceneService::changeSceneNow(std::unique_ptr<Scene>&& new_scene) {
}
void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
scene.ctx_or_set<std::vector<entt::organizer::vertex>>() =
scene.ctx_or_set<entt::organizer>().graph();
scene.ctx().emplace<std::vector<entt::organizer::vertex>>() =
scene.ctx().emplace<entt::organizer>().graph();
if (!scene.try_ctx<MM::Components::TimeDelta>()) {
scene.set<MM::Components::TimeDelta>();
if (!scene.ctx().contains<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) {

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& 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");
@ -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::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.setOrthographic();
cam.updateView();

View File

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

View File

@ -11,13 +11,13 @@ TEST(simple_velocity_2d, basic_run) {
MM::Scene scene;
// 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_rotational_velocity>("simple_rotational_velocity");
auto graph = org.graph();
// 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;
// setup test entity