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;
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;
_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 while is just cancer
while (_accumulator >= static_cast<decltype(_accumulator)>(dt)){
_accumulator -= static_cast<decltype(_accumulator)>(dt);
while (_accumulator >= f_delta){
_accumulator -= f_delta;
continuous_counter++;
for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) {
@ -133,7 +131,7 @@ void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
void OrganizerSceneService::resetTime(void) {
_last_time = clock::now();
_accumulator = 0;
_accumulator = 0.0;
}
} // MM::Services

View File

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