segon commit

This commit is contained in:
2026-04-05 21:34:38 +02:00
parent d168ed59f9
commit 20ad7d778f
502 changed files with 178145 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#include "utils/delta_timer.hpp"
DeltaTimer::DeltaTimer() noexcept
: last_counter_(SDL_GetPerformanceCounter()),
perf_freq_(static_cast<double>(SDL_GetPerformanceFrequency())),
time_scale_(1.0F) {
}
auto DeltaTimer::tick() noexcept -> float {
const Uint64 NOW = SDL_GetPerformanceCounter();
const Uint64 DIFF = (NOW > last_counter_) ? (NOW - last_counter_) : 0;
last_counter_ = NOW;
const double SECONDS = static_cast<double>(DIFF) / perf_freq_;
return static_cast<float>(SECONDS * static_cast<double>(time_scale_));
}
auto DeltaTimer::peek() const noexcept -> float {
const Uint64 NOW = SDL_GetPerformanceCounter();
const Uint64 DIFF = (NOW > last_counter_) ? (NOW - last_counter_) : 0;
const double SECONDS = static_cast<double>(DIFF) / perf_freq_;
return static_cast<float>(SECONDS * static_cast<double>(time_scale_));
}
void DeltaTimer::reset(Uint64 counter) noexcept {
if (counter == 0) {
last_counter_ = SDL_GetPerformanceCounter();
} else {
last_counter_ = counter;
}
}
void DeltaTimer::setTimeScale(float scale) noexcept {
time_scale_ = std::max(scale, 0.0F);
}
auto DeltaTimer::getTimeScale() const noexcept -> float {
return time_scale_;
}