mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-19 03:06:37 +02:00
initial import, >900commits predate this
This commit is contained in:
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user