mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-05 03:33:27 +01:00
remove simple scene and disable most stuff that used it. TODO: replace with organizer
This commit is contained in:
parent
b0e065e2ef
commit
0ad504e5d4
@ -9,17 +9,16 @@ add_subdirectory(std_utils)
|
||||
add_subdirectory(random)
|
||||
add_subdirectory(screen_director)
|
||||
add_subdirectory(filesystem)
|
||||
add_subdirectory(simple_scene)
|
||||
add_subdirectory(organizer_scene)
|
||||
|
||||
if(NOT MM_HEADLESS)
|
||||
add_subdirectory(sdl_service)
|
||||
add_subdirectory(simple_sdl_renderer)
|
||||
add_subdirectory(opengl_primitives)
|
||||
add_subdirectory(opengl_renderer)
|
||||
add_subdirectory(imgui)
|
||||
add_subdirectory(input)
|
||||
#add_subdirectory(opengl_renderer)
|
||||
#add_subdirectory(imgui)
|
||||
#add_subdirectory(input)
|
||||
add_subdirectory(sound)
|
||||
add_subdirectory(tilemap)
|
||||
#add_subdirectory(tilemap)
|
||||
endif()
|
||||
|
||||
|
@ -15,7 +15,6 @@ add_library(engine
|
||||
src/mm/update_strategies/sequential_strategy.cpp
|
||||
|
||||
src/mm/services/scene_service_interface.hpp
|
||||
src/mm/services/scene_service_interface.cpp
|
||||
|
||||
src/mm/services/net_channeled_interface.hpp
|
||||
)
|
||||
|
@ -1,27 +0,0 @@
|
||||
#include "./scene_service_interface.hpp"
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
namespace MM {
|
||||
|
||||
struct DefaultSystemsContainer {
|
||||
// list of callables, expecting a Scene (ecs) and a step size (delta)
|
||||
std::vector<std::function<void(Scene&, float)>> systems;
|
||||
};
|
||||
|
||||
void AddSystemToScene(::MM::Scene& scene, ::MM::System fn) {
|
||||
auto& sc = scene.ctx_or_set<DefaultSystemsContainer>();
|
||||
sc.systems.emplace_back(std::move(fn));
|
||||
}
|
||||
|
||||
void EachSystemInScene(::MM::Scene& scene, std::function<void(::MM::Scene&, ::MM::System&)> fn) {
|
||||
auto* sc = scene.try_ctx<DefaultSystemsContainer>();
|
||||
if (sc != nullptr) {
|
||||
for (auto& system : sc->systems) {
|
||||
fn(scene, system);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // MM
|
||||
|
@ -10,14 +10,6 @@ namespace MM {
|
||||
using Scene = entt::basic_registry<::MM::Entity>;
|
||||
using System = std::function<void(::MM::Scene&, float)>;
|
||||
|
||||
// opaque way to add a System to a Scene
|
||||
[[deprecated("use organizer")]]
|
||||
void AddSystemToScene(::MM::Scene& scene, ::MM::System fn);
|
||||
|
||||
// opaque way to iterate over the Systems
|
||||
[[deprecated("use organizer")]]
|
||||
void EachSystemInScene(::MM::Scene& scene, std::function<void(::MM::Scene&, ::MM::System&)> fn);
|
||||
|
||||
} // MM
|
||||
|
||||
namespace MM::Services {
|
||||
@ -34,12 +26,6 @@ namespace MM::Services {
|
||||
// dont use, except for when you know what you are doing!
|
||||
// be carefull of that one (lol)
|
||||
virtual void changeSceneNow(std::unique_ptr<::MM::Scene>&& new_scene) = 0;
|
||||
|
||||
// adds a System to current Scene.
|
||||
// default impl. will use getScene() !
|
||||
virtual void addSystemToScene(::MM::System fn) {
|
||||
::MM::AddSystemToScene(getScene(), std::move(fn));
|
||||
}
|
||||
};
|
||||
|
||||
} // MM::Services
|
||||
|
@ -1,7 +1,5 @@
|
||||
add_executable(opengl_renderer_s_test ./opengl_renderer_s_test.cpp)
|
||||
|
||||
target_include_directories(opengl_renderer_s_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(opengl_renderer_s_test
|
||||
opengl_renderer_s
|
||||
gtest_main
|
||||
@ -13,8 +11,6 @@ add_test(NAME opengl_renderer_s_test COMMAND opengl_renderer_s_test)
|
||||
|
||||
add_executable(imgui_render_task_test imgui_render_task_test.cpp)
|
||||
|
||||
target_include_directories(imgui_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(imgui_render_task_test
|
||||
opengl_renderer_s
|
||||
imgui_service
|
||||
@ -28,11 +24,9 @@ add_test(NAME imgui_render_task_test COMMAND imgui_render_task_test)
|
||||
|
||||
add_executable(simple_rect_render_task_test simple_rect_render_task_test.cpp)
|
||||
|
||||
target_include_directories(simple_rect_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_rect_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
simple_rect_render_task
|
||||
|
||||
simple_velocity_system
|
||||
@ -46,11 +40,9 @@ add_test(NAME simple_rect_render_task_test COMMAND simple_rect_render_task_test)
|
||||
|
||||
add_executable(simple_sprite_render_task_test simple_sprite_render_task_test.cpp)
|
||||
|
||||
target_include_directories(simple_sprite_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_sprite_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
simple_sprite_render_task
|
||||
|
||||
simple_velocity_system
|
||||
@ -64,11 +56,9 @@ add_test(NAME simple_sprite_render_task_test COMMAND simple_sprite_render_task_t
|
||||
|
||||
add_executable(simple_spritesheet_render_task_test simple_spritesheet_render_task_test.cpp)
|
||||
|
||||
target_include_directories(simple_spritesheet_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_spritesheet_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
simple_spritesheet_render_task
|
||||
|
||||
#simple_velocity_system
|
||||
@ -82,11 +72,9 @@ add_test(NAME simple_spritesheet_render_task_test COMMAND simple_spritesheet_ren
|
||||
|
||||
add_executable(batched_spritesheet_render_task_test batched_spritesheet_render_task_test.cpp)
|
||||
|
||||
target_include_directories(batched_spritesheet_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(batched_spritesheet_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
batched_spritesheet_render_task
|
||||
|
||||
#simple_velocity_system
|
||||
@ -100,11 +88,9 @@ add_test(NAME batched_spritesheet_render_task_test COMMAND batched_spritesheet_r
|
||||
|
||||
add_executable(blur_render_task_test blur_render_task_test.cpp)
|
||||
|
||||
target_include_directories(blur_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(blur_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
simple_rect_render_task
|
||||
blur_render_task
|
||||
copy_to_fb_render_task
|
||||
@ -123,11 +109,9 @@ add_test(NAME blur_render_task_test COMMAND blur_render_task_test)
|
||||
|
||||
add_executable(tilemap_render_task_test tilemap_render_task_test.cpp)
|
||||
|
||||
target_include_directories(tilemap_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(tilemap_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
imgui_service
|
||||
tilemap_render_task
|
||||
|
||||
@ -140,11 +124,9 @@ add_test(NAME tilemap_render_task_test COMMAND tilemap_render_task_test)
|
||||
|
||||
add_executable(fast_sky_render_task_test fast_sky_render_task_test.cpp)
|
||||
|
||||
target_include_directories(fast_sky_render_task_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(fast_sky_render_task_test
|
||||
opengl_renderer_s
|
||||
simple_scene
|
||||
organizer_scene
|
||||
#imgui_service
|
||||
fast_sky_render_task
|
||||
fast_sky_sun_system
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "entt/entity/fwd.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
#include <mm/services/filesystem.hpp>
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/simple_scene.hpp>
|
||||
#include <mm/services/organizer_scene.hpp>
|
||||
#include <mm/services/opengl_renderer.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
@ -28,10 +29,10 @@ TEST(simple_rect_render_task, it) {
|
||||
|
||||
sdl_ss.createGLWindow("simple_rect_render_task_test", 1280, 720);
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
engine.addService<MM::Services::OrganizerSceneService>();
|
||||
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();
|
||||
|
||||
@ -44,7 +45,9 @@ TEST(simple_rect_render_task, it) {
|
||||
rs.addRenderTask<MM::OpenGL::RenderTasks::SimpleRect>(engine);
|
||||
|
||||
// setup v system
|
||||
MM::AddSystemToScene(scene, MM::Systems::SimpleVelocity);
|
||||
auto& org = scene.set<entt::organizer>();
|
||||
|
||||
//MM::AddSystemToScene(scene, MM::Systems::SimpleVelocity);
|
||||
|
||||
std::mt19937 mt(42);
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(simple_scene CXX)
|
||||
|
||||
add_library(simple_scene
|
||||
src/mm/services/simple_scene.hpp
|
||||
src/mm/services/simple_scene.cpp
|
||||
)
|
||||
|
||||
target_include_directories(simple_scene PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
|
||||
target_link_libraries(simple_scene
|
||||
engine
|
||||
common_components
|
||||
)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
@ -1,109 +0,0 @@
|
||||
#include "./simple_scene.hpp"
|
||||
|
||||
#include <mm/components/time_delta.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
#include <mm/logger.hpp>
|
||||
#define LOG_SSS(x) LOG("SimpleSceneService", x)
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
bool SimpleSceneService::enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) {
|
||||
// add tasks
|
||||
task_array.push_back(
|
||||
UpdateStrategies::TaskInfo{"SimpleSceneService::scene_tick"}
|
||||
.fn([this](Engine& e) { sceneFixedUpdate(e); })
|
||||
);
|
||||
task_array.push_back(
|
||||
UpdateStrategies::TaskInfo{"SimpleSceneService::scene_change"}
|
||||
.succeed("SimpleSceneService::scene_tick")
|
||||
.fn([this](Engine& e) { changeSceneFixedUpdate(e); })
|
||||
);
|
||||
|
||||
// default scene
|
||||
if (!_scene) {
|
||||
_scene = std::make_unique<Scene>();
|
||||
_scene->set<MM::Engine*>(&engine);
|
||||
}
|
||||
|
||||
resetTime();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SimpleSceneService::disable(Engine&) {
|
||||
}
|
||||
|
||||
void SimpleSceneService::sceneFixedUpdate(Engine&) {
|
||||
ZoneScoped;
|
||||
|
||||
auto newNow = clock::now();
|
||||
auto deltaTime = std::chrono::duration_cast<std::chrono::nanoseconds>(newNow - _last_time);
|
||||
_last_time = newNow;
|
||||
_accumulator += deltaTime.count();
|
||||
const double dt = f_delta * 1'000'000'000.0;
|
||||
|
||||
size_t continuous_counter = 0;
|
||||
|
||||
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor);
|
||||
time_ctx.tickDelta = f_delta * time_ctx.deltaFactor;
|
||||
|
||||
// TODO: this is just cancer
|
||||
while (_accumulator >= static_cast<decltype(_accumulator)>(dt)){
|
||||
_accumulator -= static_cast<decltype(_accumulator)>(dt);
|
||||
continuous_counter++;
|
||||
|
||||
::MM::EachSystemInScene(*_scene, [&](::MM::Scene& s, ::MM::System& fn) {
|
||||
fn(s, time_ctx.tickDelta);
|
||||
});
|
||||
|
||||
TracyPlot("MM::Services::SimpleSceneService::_scene.alive", (int64_t)_scene->alive());
|
||||
}
|
||||
|
||||
if (continuous_counter > 2) {
|
||||
LOG_SSS(fmt::format("had {} contiguous scene ticks!", continuous_counter));
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleSceneService::changeSceneFixedUpdate(Engine& engine) {
|
||||
if (_next_scene) {
|
||||
LOG_SSS("changing scene...");
|
||||
_scene = std::move(_next_scene);
|
||||
_scene->set<MM::Engine*>(&engine); // make engine accessible from scene
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleSceneService::changeScene(std::unique_ptr<Scene>&& new_scene) {
|
||||
if (_next_scene) {
|
||||
LOG_SSS("warn: already next scene enqueued! overwriting...");
|
||||
}
|
||||
|
||||
_next_scene = std::move(new_scene);
|
||||
|
||||
//// ensure there are systems
|
||||
//if (!_next_scene->try_ctx<MM::simple_scene::SystemsContainer>()) {
|
||||
//_next_scene->set<MM::simple_scene::SystemsContainer>();
|
||||
//}
|
||||
}
|
||||
|
||||
void SimpleSceneService::changeSceneNow(std::unique_ptr<Scene>&& new_scene) {
|
||||
_scene = std::move(new_scene);
|
||||
//_scene->set<MM::Engine*>(&engine); // make engine accessible from scene
|
||||
|
||||
//// ensure there are systems
|
||||
//if (!_scene->try_ctx<MM::simple_scene::SystemsContainer>()) {
|
||||
//_scene->set<MM::simple_scene::SystemsContainer>();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
void SimpleSceneService::resetTime(void) {
|
||||
_last_time = clock::now();
|
||||
_accumulator = 0;
|
||||
}
|
||||
|
||||
} // MM::Services
|
||||
|
@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mm/services/scene_service_interface.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
// provides an implementation for SceneServiceInterface
|
||||
class SimpleSceneService : public SceneServiceInterface {
|
||||
private:
|
||||
std::unique_ptr<Scene> _scene;
|
||||
std::unique_ptr<Scene> _next_scene; // enqueued next scene
|
||||
|
||||
using clock = std::chrono::high_resolution_clock;
|
||||
long long int _accumulator = 0;
|
||||
std::chrono::time_point<clock> _last_time;
|
||||
|
||||
public:
|
||||
const float f_delta;
|
||||
|
||||
float initial_delta_factor = 1.f;
|
||||
|
||||
public:
|
||||
explicit SimpleSceneService(const float update_delta = 1.f/60.f) : f_delta(update_delta) {}
|
||||
|
||||
const char* name(void) override { return "SimpleSceneService"; }
|
||||
|
||||
bool enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) override;
|
||||
void disable(Engine& engine) override;
|
||||
|
||||
private:
|
||||
void sceneFixedUpdate(Engine& engine);
|
||||
void changeSceneFixedUpdate(Engine& engine);
|
||||
|
||||
public:
|
||||
Scene& getScene(void) override { return *_scene; }
|
||||
|
||||
void changeScene(std::unique_ptr<Scene>&& new_scene) override;
|
||||
|
||||
// be carefull of that one
|
||||
void changeSceneNow(std::unique_ptr<Scene>&& new_scene) override;
|
||||
|
||||
void resetTime(void);
|
||||
};
|
||||
|
||||
} // MM::Services
|
||||
|
@ -1,14 +0,0 @@
|
||||
add_executable(simple_scene_test
|
||||
ss_test.cpp
|
||||
)
|
||||
|
||||
target_include_directories(simple_scene_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_scene_test
|
||||
engine
|
||||
simple_scene
|
||||
gtest_main
|
||||
)
|
||||
|
||||
add_test(NAME simple_scene_test COMMAND simple_scene_test)
|
||||
|
@ -1,72 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/engine.hpp>
|
||||
#include <mm/services/simple_scene.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
TEST(simple_scene, add_en_dis) {
|
||||
MM::Engine engine;
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
|
||||
{
|
||||
auto* sss = engine.tryService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_NE(sss, nullptr);
|
||||
|
||||
auto& s = sss->getScene();
|
||||
auto e = s.create();
|
||||
ASSERT_TRUE(s.valid(e));
|
||||
}
|
||||
|
||||
engine.disableService<MM::Services::SimpleSceneService>();
|
||||
}
|
||||
|
||||
TEST(simple_scene, add_en_dis_provide) {
|
||||
MM::Engine engine;
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
engine.provide<MM::Services::SceneServiceInterface, MM::Services::SimpleSceneService>();
|
||||
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
|
||||
{
|
||||
auto* ssi = engine.tryService<MM::Services::SceneServiceInterface>();
|
||||
ASSERT_NE(ssi, nullptr);
|
||||
|
||||
auto& s = ssi->getScene();
|
||||
auto e = s.create();
|
||||
ASSERT_TRUE(s.valid(e));
|
||||
}
|
||||
|
||||
engine.disableService<MM::Services::SimpleSceneService>();
|
||||
}
|
||||
|
||||
TEST(simple_scene, change_scene) {
|
||||
MM::Engine engine;
|
||||
|
||||
engine.addService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SimpleSceneService>());
|
||||
|
||||
{
|
||||
auto* sss = engine.tryService<MM::Services::SimpleSceneService>();
|
||||
ASSERT_NE(sss, nullptr);
|
||||
|
||||
auto e = sss->getScene().create();
|
||||
ASSERT_TRUE(sss->getScene().valid(e));
|
||||
|
||||
sss->changeScene(std::make_unique<MM::Scene>());
|
||||
|
||||
ASSERT_TRUE(sss->getScene().valid(e));
|
||||
|
||||
//engine.fixedUpdate();
|
||||
engine.getUpdateStrategy().addDeferred([](MM::Engine& eng) {eng.stop();});
|
||||
engine.run();
|
||||
|
||||
ASSERT_FALSE(sss->getScene().valid(e));
|
||||
}
|
||||
|
||||
engine.disableService<MM::Services::SimpleSceneService>();
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.2)
|
||||
project(screens CXX)
|
||||
|
||||
if(NOT MM_HEADLESS)
|
||||
add_subdirectory(mm_logo)
|
||||
#add_subdirectory(mm_logo)
|
||||
endif()
|
||||
|
||||
|
@ -15,7 +15,7 @@ target_link_libraries(mm_logo_screen
|
||||
glm
|
||||
engine
|
||||
screen_director
|
||||
simple_scene
|
||||
organizer_scene
|
||||
|
||||
opengl_renderer_s
|
||||
simple_sprite_render_task
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
#include <mm/services/simple_scene.hpp>
|
||||
#include <mm/services/organizer_scene.hpp>
|
||||
#include <mm/services/opengl_renderer.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
@ -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()
|
||||
|
||||
|
@ -4,12 +4,13 @@
|
||||
|
||||
#include <mm/components/velocity2d.hpp>
|
||||
#include <mm/components/transform2d.hpp>
|
||||
#include <mm/components/time_delta.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) {
|
||||
inline void simple_velocity(entt::view<entt::exclude_t<>, Components::Transform2D, const Components::Velocity2D> view, const Components::TimeDelta& td) {
|
||||
view.each([delta = td.tickDelta](auto, auto& t, auto& v) {
|
||||
t.position += v.velocity * delta;
|
||||
t.rotation += v.rotation * delta;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ target_include_directories(simple_velocity_test PRIVATE ".")
|
||||
|
||||
target_link_libraries(simple_velocity_test
|
||||
simple_velocity_system
|
||||
simple_scene
|
||||
gtest_main
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <mm/engine_fwd.hpp>
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/entity/organizer.hpp>
|
||||
|
||||
#include <mm/systems/simple_velocity_system2d.hpp>
|
||||
|
||||
@ -10,8 +11,15 @@ TEST(simple_velocity_2d, basic_run) {
|
||||
MM::Scene scene;
|
||||
|
||||
// setup v system
|
||||
MM::AddSystemToScene(scene, MM::Systems::SimpleVelocity);
|
||||
auto& org = scene.set<entt::organizer>();
|
||||
org.emplace<&MM::Systems::simple_velocity>("simple_velocity");
|
||||
auto graph = org.graph();
|
||||
|
||||
// setup delta
|
||||
auto& time_ctx = scene.ctx_or_set<MM::Components::TimeDelta>(1.f/60.f, 1.f);
|
||||
time_ctx.tickDelta = 1.f/60.f * time_ctx.deltaFactor;
|
||||
|
||||
// setup test entity
|
||||
auto e = scene.create();
|
||||
auto& t = scene.emplace<MM::Components::Transform2D>(e);
|
||||
auto& v = scene.emplace<MM::Components::Velocity2D>(e);
|
||||
@ -21,9 +29,10 @@ TEST(simple_velocity_2d, basic_run) {
|
||||
v.velocity = { 1.f, 1.f };
|
||||
v.rotation = 0.f;
|
||||
|
||||
::MM::EachSystemInScene(scene, [&](::MM::Scene& s, ::MM::System& fn) {
|
||||
fn(s, 1.f/60.f);
|
||||
});
|
||||
// run all systems
|
||||
for (auto&& vert : graph) {
|
||||
vert.callback()(vert.data(), scene);
|
||||
}
|
||||
|
||||
ASSERT_EQ(t.position.x, 1.f * 1.f/60.f);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user