Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
time_keeper.h
1 #pragma once
2 
3 #ifdef __DREAMCAST__
4  #include <cstdint>
5 #else
6  #include <chrono>
7 #endif
8 
9 #include "generic/managed.h"
10 
11 namespace smlt {
12 
13 class TimeKeeper:
14  public RefCounted<TimeKeeper> {
15 
16 public:
17  TimeKeeper(const float fixed_step);
18 
19  bool init() override;
20  void clean_up() override;
21 
22  void update();
23 
24  static uint64_t now_in_us();
25 
26  float delta_time() const { return delta_time_; }
27  float fixed_step() const { return fixed_step_; }
28  float fixed_step_remainder() const;
29  float total_elapsed_seconds() const { return total_time_; }
30 
31  bool use_fixed_step();
32 
33  void restart() {
34  total_time_ = delta_time_ = accumulator_ = 0.0f;
35  }
36 
37 private:
38  uint64_t last_update_;
39 
40  float accumulator_ = 0.0f;
41  float total_time_ = 0.0f;
42  float delta_time_ = 0.0f;
43  float fixed_step_ = 0.0f;
44 };
45 
46 }
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::TimeKeeper
Definition: time_keeper.h:14