mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-05 03:33:27 +01:00
make timer cleaner
This commit is contained in:
parent
a2b056f385
commit
bfe09374bb
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user