mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-19 11:16:37 +02:00
initial import, >900commits predate this
This commit is contained in:
10
systems/CMakeLists.txt
Normal file
10
systems/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(systems CXX)
|
||||
|
||||
add_subdirectory(simple_velocity)
|
||||
|
||||
if(NOT MM_HEADLESS)
|
||||
add_subdirectory(player_velocity)
|
||||
add_subdirectory(fast_sky_sun)
|
||||
endif()
|
||||
|
20
systems/fast_sky_sun/CMakeLists.txt
Normal file
20
systems/fast_sky_sun/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(fast_sky_sun_system CXX)
|
||||
|
||||
add_library(fast_sky_sun_system
|
||||
src/mm/systems/fast_sky_sun_system.hpp
|
||||
src/mm/systems/fast_sky_sun_system.cpp
|
||||
)
|
||||
|
||||
target_include_directories(fast_sky_sun_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
target_link_libraries(fast_sky_sun_system
|
||||
engine
|
||||
fast_sky_render_task
|
||||
)
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set_target_properties(fast_sky_sun_system PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
|
||||
set_target_properties(fast_sky_sun_system PROPERTIES LINK_FLAGS "-s USE_SDL=2")
|
||||
endif()
|
||||
|
23
systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.cpp
Normal file
23
systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "./fast_sky_sun_system.hpp"
|
||||
|
||||
#include <mm/services/scene_service_interface.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include <mm/opengl/render_tasks/fast_sky_render_task.hpp>
|
||||
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
||||
namespace MM::Systems {
|
||||
|
||||
void FastSkySun(Scene& scene, float delta) {
|
||||
auto& sky_ctx = scene.ctx<MM::OpenGL::RenderTasks::FastSkyContext>();
|
||||
|
||||
sky_ctx.time += delta * 0.2f;
|
||||
|
||||
sky_ctx.fsun.y = glm::sin(sky_ctx.time * 0.01f);
|
||||
sky_ctx.fsun.z = glm::cos(sky_ctx.time * 0.01f);
|
||||
}
|
||||
|
||||
} // MM::Systems
|
||||
|
11
systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.hpp
Normal file
11
systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <mm/engine_fwd.hpp>
|
||||
|
||||
namespace MM::Systems {
|
||||
|
||||
// this system updates time and sun depending on time with the time delta
|
||||
void FastSkySun(Scene& scene, float delta);
|
||||
|
||||
} // MM::Systems
|
||||
|
28
systems/player_velocity/CMakeLists.txt
Normal file
28
systems/player_velocity/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(player_velocity_system CXX)
|
||||
|
||||
add_library(player_velocity_system
|
||||
src/mm/systems/player_velocity2d_system.hpp
|
||||
src/mm/systems/player_velocity2d_system.cpp
|
||||
)
|
||||
|
||||
target_include_directories(player_velocity_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
target_link_libraries(player_velocity_system
|
||||
entt
|
||||
glm
|
||||
engine
|
||||
common_components
|
||||
input_service
|
||||
)
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set_target_properties(player_velocity_system PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
|
||||
set_target_properties(player_velocity_system PROPERTIES LINK_FLAGS "-s USE_SDL=2")
|
||||
endif()
|
||||
|
||||
if (BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
@ -0,0 +1,35 @@
|
||||
#include "./player_velocity2d_system.hpp"
|
||||
|
||||
#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>();
|
||||
|
||||
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 vec_force = input_ss.getMoveForce(p_id);
|
||||
|
||||
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};
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
//#include <mm/services/scene_service_interface.hpp>
|
||||
#include <mm/engine_fwd.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);
|
||||
|
||||
} // MM::Systems
|
||||
|
14
systems/player_velocity/test/CMakeLists.txt
Normal file
14
systems/player_velocity/test/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
add_executable(player_velocity_test
|
||||
player_velocity_test.cpp
|
||||
)
|
||||
|
||||
target_include_directories(player_velocity_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(player_velocity_test
|
||||
player_velocity_system
|
||||
simple_scene
|
||||
gtest_main
|
||||
)
|
||||
|
||||
add_test(NAME player_velocity_test COMMAND player_velocity_test)
|
||||
|
45
systems/player_velocity/test/player_velocity_test.cpp
Normal file
45
systems/player_velocity/test/player_velocity_test.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/input_service.hpp>
|
||||
#include <mm/services/simple_scene.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include <mm/systems/player_velocity2d_system.hpp>
|
||||
|
||||
TEST(player_velocity, basic_run) {
|
||||
float delta = 1/60.f;
|
||||
MM::Engine engine(delta);
|
||||
|
||||
engine.addService<MM::Services::SDLService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
|
||||
|
||||
engine.addService<MM::Services::InputService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::InputService>());
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
|
||||
bool provide_ret = engine.provide<MM::Services::SceneServiceInterface, MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(provide_ret);
|
||||
|
||||
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
|
||||
|
||||
// setup v system
|
||||
MM::AddSystemToScene(scene, MM::Systems::PlayerVelocity2D);
|
||||
|
||||
//auto [e, t, v] = scene.create<MM::Components::Transform, MM::Components::Velocity>();
|
||||
//t.position = { 0.f, 0.f };
|
||||
//t.rotation = 0.f;
|
||||
|
||||
//v.velocity = { 1.f, 1.f };
|
||||
//v.rotation = 0.f;
|
||||
|
||||
engine.fixedUpdate();
|
||||
|
||||
//ASSERT_EQ(t.position.x, 1.f * delta);
|
||||
// TODO: TEST
|
||||
}
|
||||
|
26
systems/simple_velocity/CMakeLists.txt
Normal file
26
systems/simple_velocity/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(simple_velocity_system CXX)
|
||||
|
||||
set(HPP_FILES
|
||||
src/mm/systems/simple_velocity_system2d.hpp
|
||||
)
|
||||
|
||||
set(CPP_FILES
|
||||
)
|
||||
|
||||
add_library(simple_velocity_system ${CPP_FILES} ${HPP_FILES})
|
||||
|
||||
target_include_directories(simple_velocity_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
target_link_libraries(simple_velocity_system
|
||||
entt
|
||||
glm
|
||||
engine
|
||||
common_components
|
||||
)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <mm/components/velocity2d.hpp>
|
||||
#include <mm/components/transform2d.hpp>
|
||||
|
||||
#include <mm/services/scene_service_interface.hpp>
|
||||
|
||||
namespace MM::Systems {
|
||||
inline void SimpleVelocity(Scene& scene, float delta) {
|
||||
scene.view<MM::Components::Transform2D, MM::Components::Velocity2D>().each([delta](auto, auto& t, auto& v) {
|
||||
t.position += v.velocity * delta;
|
||||
t.rotation += v.rotation * delta;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
14
systems/simple_velocity/test/CMakeLists.txt
Normal file
14
systems/simple_velocity/test/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
add_executable(simple_velocity_test
|
||||
simple_velocity_test.cpp
|
||||
)
|
||||
|
||||
target_include_directories(simple_velocity_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_velocity_test
|
||||
simple_velocity_system
|
||||
simple_scene
|
||||
gtest_main
|
||||
)
|
||||
|
||||
add_test(NAME simple_velocity_test COMMAND simple_velocity_test)
|
||||
|
38
systems/simple_velocity/test/simple_velocity_test.cpp
Normal file
38
systems/simple_velocity/test/simple_velocity_test.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <mm/services/simple_scene.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include <mm/systems/simple_velocity_system2d.hpp>
|
||||
|
||||
TEST(simple_velocity_2d, basic_run) {
|
||||
float delta = 1/60.f;
|
||||
MM::Engine engine(delta);
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
|
||||
bool provide_ret = engine.provide<MM::Services::SceneServiceInterface, MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(provide_ret);
|
||||
|
||||
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
|
||||
|
||||
// setup v system
|
||||
MM::AddSystemToScene(scene, MM::Systems::SimpleVelocity);
|
||||
|
||||
auto e = scene.create();
|
||||
auto& t = scene.emplace<MM::Components::Transform2D>(e);
|
||||
auto& v = scene.emplace<MM::Components::Velocity2D>(e);
|
||||
t.position = { 0.f, 0.f };
|
||||
t.rotation = 0.f;
|
||||
|
||||
v.velocity = { 1.f, 1.f };
|
||||
v.rotation = 0.f;
|
||||
|
||||
engine.fixedUpdate();
|
||||
|
||||
ASSERT_EQ(t.position.x, 1.f * delta);
|
||||
}
|
||||
|
Reference in New Issue
Block a user