make timer cleaner

This commit is contained in:
Green Sky 2022-02-09 11:23:23 +01:00
parent a2b056f385
commit bfe09374bb
2 changed files with 5 additions and 7 deletions

View File

@ -68,19 +68,17 @@ void OrganizerSceneService::sceneFixedUpdate(Engine&) {
ZoneScoped; ZoneScoped;
auto newNow = clock::now(); auto newNow = clock::now();
auto deltaTime = std::chrono::duration_cast<std::chrono::nanoseconds>(newNow - _last_time); std::chrono::duration<double, std::ratio<1, 1>> deltaTime = newNow - _last_time;
_last_time = newNow; _last_time = newNow;
_accumulator += deltaTime.count(); _accumulator += deltaTime.count();
const double dt = f_delta * 1'000'000'000.0;
size_t continuous_counter = 0; size_t continuous_counter = 0;
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor); auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor);
time_ctx.tickDelta = f_delta * time_ctx.deltaFactor; time_ctx.tickDelta = f_delta * time_ctx.deltaFactor;
// TODO: this while is just cancer while (_accumulator >= f_delta){
while (_accumulator >= static_cast<decltype(_accumulator)>(dt)){ _accumulator -= f_delta;
_accumulator -= static_cast<decltype(_accumulator)>(dt);
continuous_counter++; continuous_counter++;
for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) { for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) {
@ -133,7 +131,7 @@ void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
void OrganizerSceneService::resetTime(void) { void OrganizerSceneService::resetTime(void) {
_last_time = clock::now(); _last_time = clock::now();
_accumulator = 0; _accumulator = 0.0;
} }
} // MM::Services } // MM::Services

View File

@ -14,7 +14,7 @@ namespace MM::Services {
std::unique_ptr<Scene> _next_scene; // enqueued next scene std::unique_ptr<Scene> _next_scene; // enqueued next scene
using clock = std::chrono::high_resolution_clock; using clock = std::chrono::high_resolution_clock;
long long int _accumulator = 0; double _accumulator = 0.0;
std::chrono::time_point<clock> _last_time; std::chrono::time_point<clock> _last_time;
public: public: