mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
add time delta context to scene
This commit is contained in:
parent
8e8ac6c0be
commit
9bcaf87788
17
framework/common_components/src/mm/components/time_delta.hpp
Normal file
17
framework/common_components/src/mm/components/time_delta.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user