change scene engine from pointer to reference

This commit is contained in:
Green Sky 2022-02-08 21:06:22 +01:00
parent a8b3b25e7d
commit a2b056f385
4 changed files with 9 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#include "./organizer_scene.hpp"
#include "mm/engine.hpp"
#include <mm/components/time_delta.hpp>
@ -51,7 +52,7 @@ bool OrganizerSceneService::enable(Engine& engine, std::vector<UpdateStrategies:
// default scene
if (!_scene) {
_scene = std::make_unique<Scene>();
_scene->set<MM::Engine*>(&engine);
_scene->set<MM::Engine&>(engine);
updateOrganizerVertices(*_scene);
}
@ -98,7 +99,9 @@ void OrganizerSceneService::changeSceneFixedUpdate(Engine& engine) {
if (_next_scene) {
LOG_OSS("changing scene...");
_scene = std::move(_next_scene);
_scene->set<MM::Engine*>(&engine); // make engine accessible from scene
if (!_scene->try_ctx<MM::Engine>()) {
_scene->set<MM::Engine&>(engine); // make engine accessible from scene
}
updateOrganizerVertices(*_scene);
}
}

View File

@ -6,10 +6,10 @@
namespace MM::Systems {
void player_velocity2d(entt::view<entt::get_t<const MM::Input::PlayerID, MM::Components::Velocity2DPositionIntent>> view, const MM::Engine* engine) {
void player_velocity2d(entt::view<entt::get_t<const MM::Input::PlayerID, MM::Components::Velocity2DPositionIntent>> view, MM::Engine& engine) {
ZoneScopedN("MM::Systems::PlayerVelocity2D");
auto& input_ss = engine->getService<MM::Services::InputService>();
auto& input_ss = engine.getService<MM::Services::InputService>();
view.each([&input_ss](const MM::Input::PlayerID p_id, MM::Components::Velocity2DPositionIntent& v) {
v.intent = input_ss.getMoveVec(p_id);

View File

@ -7,7 +7,7 @@
namespace MM::Systems {
// this system transforms the input from the input_service into velocity intent
void player_velocity2d(entt::view<entt::get_t<const MM::Input::PlayerID, MM::Components::Velocity2DPositionIntent>> view, const MM::Engine* engine);
void player_velocity2d(entt::view<entt::get_t<const MM::Input::PlayerID, MM::Components::Velocity2DPositionIntent>> view, MM::Engine& engine);
} // MM::Systems

View File

@ -26,7 +26,7 @@ TEST(player_velocity, basic_run) {
bool provide_ret = engine.provide<MM::Services::SceneServiceInterface, MM::Services::OrganizerSceneService>();
ASSERT_TRUE(provide_ret);
auto& scene = engine.tryService<MM::Services::SceneServiceInterface>()->getScene();
auto& scene = engine.getService<MM::Services::SceneServiceInterface>().getScene();
// setup v system
auto& org = scene.set<entt::organizer>();