add time delta context to scene

This commit is contained in:
Green Sky 2021-01-17 16:16:16 +01:00
parent 8e8ac6c0be
commit 9bcaf87788
3 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,17 @@
#pragma once
namespace MM::Components {
// this is a context-variable / "component-singleton".
// it is used to retirve timing information about the tick.
// it is "read-only" for the systems and filled in by the service
// holding the scene.
struct TimeDelta {
float tickDelta = 1.f/60.f;
// this is optionally filled in
// it turned out, that sound playback needs the factor
float deltaFactor = 1.f;
};
}

View File

@ -10,6 +10,7 @@ target_include_directories(simple_scene PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src"
target_link_libraries(simple_scene
engine
common_components
)
if (BUILD_TESTING)

View File

@ -1,7 +1,6 @@
#include "./simple_scene.hpp"
#include "spdlog/fmt/bundled/core.h"
//#include "../systems_container.hpp"
#include <mm/components/time_delta.hpp>
#include <entt/entity/registry.hpp>
@ -61,6 +60,10 @@ void SimpleSceneService::sceneFixedUpdate(Engine&) {
size_t continuous_counter = 0;
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, delta_factor);
time_ctx.tickDelta = f_delta * delta_factor;
time_ctx.deltaFactor = delta_factor;
// TODO: this is just cancer
while (_accumulator >= static_cast<decltype(_accumulator)>(dt)){
_accumulator -= static_cast<decltype(_accumulator)>(dt);