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:
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