port everything over to organizer

This commit is contained in:
2021-12-12 22:56:16 +01:00
parent edec5e51d3
commit edcecba2eb
25 changed files with 237 additions and 227 deletions

View File

@ -4,7 +4,7 @@ project(systems CXX)
add_subdirectory(simple_velocity)
if(NOT MM_HEADLESS)
#add_subdirectory(player_velocity)
#add_subdirectory(fast_sky_sun)
add_subdirectory(player_velocity)
add_subdirectory(fast_sky_sun)
endif()

View File

@ -11,6 +11,7 @@ target_include_directories(fast_sky_sun_system PUBLIC "${CMAKE_CURRENT_SOURCE_DI
target_link_libraries(fast_sky_sun_system
engine
fast_sky_render_task
common_components
)
if(EMSCRIPTEN)

View File

@ -2,6 +2,8 @@
#include <mm/services/scene_service_interface.hpp>
#include <mm/components/time_delta.hpp>
#include <entt/entity/registry.hpp>
#include <mm/opengl/render_tasks/fast_sky_render_task.hpp>
@ -10,10 +12,8 @@
namespace MM::Systems {
void FastSkySun(Scene& scene, float delta) {
auto& sky_ctx = scene.ctx<MM::OpenGL::RenderTasks::FastSkyContext>();
sky_ctx.time += delta * 0.2f;
void fast_sky_sun(MM::OpenGL::RenderTasks::FastSkyContext& sky_ctx, const MM::Components::TimeDelta& delta) {
sky_ctx.time += delta.tickDelta * 0.2f;
sky_ctx.fsun.y = glm::sin(sky_ctx.time * 0.01f);
sky_ctx.fsun.z = glm::cos(sky_ctx.time * 0.01f);

View File

@ -2,10 +2,18 @@
#include <mm/engine_fwd.hpp>
// fwd
namespace MM::OpenGL::RenderTasks {
struct FastSkyContext;
}
namespace MM::Components {
struct TimeDelta;
}
namespace MM::Systems {
// this system updates time and sun depending on time with the time delta
void FastSkySun(Scene& scene, float delta);
void fast_sky_sun(MM::OpenGL::RenderTasks::FastSkyContext& c, const MM::Components::TimeDelta& delta);
} // MM::Systems

View File

@ -2,34 +2,28 @@
#include <entt/entity/registry.hpp>
#include <mm/components/velocity2d.hpp>
#include <mm/services/input_service.hpp>
#include <tracy/Tracy.hpp>
namespace MM::Systems {
void PlayerVelocity2D(Scene& scene, float) {
ZoneScopedN("MM::Systems::PlayerVelocity2D");
MM::Engine* engine_ptr = scene.ctx<MM::Engine*>();
auto& input_ss = engine_ptr->getService<MM::Services::InputService>();
void player_velocity2d(entt::view<entt::exclude_t<>, MM::Input::PlayerID, MM::Components::Velocity2D> view, const MM::Engine* engine) {
ZoneScopedN("MM::Systems::PlayerVelocity2D");
scene.view<MM::Input::PlayerID, MM::Components::Velocity2D>().each(
[&input_ss](const MM::Input::PlayerID p_id, MM::Components::Velocity2D& v) {
//const float movement_speed = 8.f; // apply via post processing
auto& input_ss = engine->getService<MM::Services::InputService>();
auto vec_force = input_ss.getMoveForce(p_id);
view.each([&input_ss](const MM::Input::PlayerID p_id, MM::Components::Velocity2D& v) {
//const float movement_speed = 8.f; // apply via post processing
if (vec_force >= 0.01f) {
v.velocity = input_ss.getMoveVec(p_id);
v.velocity *= vec_force;
//v.velocity *= movement_speed;
} else {
v.velocity = {0.f, 0.f};
}
}
);
}
auto vec_force = input_ss.getMoveForce(p_id);
if (vec_force >= 0.01f) {
v.velocity = input_ss.getMoveVec(p_id);
//v.velocity *= vec_force;
} else {
v.velocity = {0.f, 0.f};
}
});
}
} // MM::Systems

View File

@ -1,13 +1,14 @@
#pragma once
//#include <mm/services/scene_service_interface.hpp>
#include <mm/engine_fwd.hpp>
#include <entt/entity/utility.hpp>
#include <mm/services/input_service.hpp>
#include <mm/components/velocity2d.hpp>
namespace MM::Systems {
// this system transforms the input from the input_ss into velocity
// uses Components::Velocity2D, PlayerID
void PlayerVelocity2D(Scene& scene, float delta);
// this system transforms the input from the input_service into velocity
void player_velocity2d(entt::view<entt::exclude_t<>, MM::Input::PlayerID, MM::Components::Velocity2D> view, const MM::Engine* engine);
} // MM::Systems

View File

@ -6,7 +6,7 @@ target_include_directories(player_velocity_test PRIVATE ".")
target_link_libraries(player_velocity_test
player_velocity_system
simple_scene
organizer_scene
gtest_main
)

View File

@ -3,9 +3,10 @@
#include <mm/engine.hpp>
#include <mm/services/sdl_service.hpp>
#include <mm/services/input_service.hpp>
#include <mm/services/simple_scene.hpp>
#include <mm/services/organizer_scene.hpp>
#include <entt/entity/registry.hpp>
#include <entt/entity/organizer.hpp>
#include <mm/systems/player_velocity2d_system.hpp>
@ -19,16 +20,21 @@ TEST(player_velocity, basic_run) {
engine.addService<MM::Services::InputService>();
ASSERT_TRUE(engine.enableService<MM::Services::InputService>());
engine.addService<MM::Services::SimpleSceneService>(delta);
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
engine.addService<MM::Services::OrganizerSceneService>(delta);
ASSERT_TRUE(engine.enableService<MM::Services::OrganizerSceneService>());
bool provide_ret = engine.provide<MM::Services::SceneServiceInterface, MM::Services::SimpleSceneService>();
bool provide_ret = engine.provide<MM::Services::SceneServiceInterface, MM::Services::OrganizerSceneService>();
ASSERT_TRUE(provide_ret);
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
// setup v system
MM::AddSystemToScene(scene, MM::Systems::PlayerVelocity2D);
auto& org = scene.set<entt::organizer>();
org.emplace<&MM::Systems::player_velocity2d>("player_velocity2d");
// HACK: instead you would switch to this scene
engine.getService<MM::Services::OrganizerSceneService>().updateOrganizerVertices(scene);
//auto [e, t, v] = scene.create<MM::Components::Transform, MM::Components::Velocity>();
//t.position = { 0.f, 0.f };