more precise timing

renamed Time::elapsed -> Time::seconds, change type to double
updated game to store ticks (microseconds) instead of milliseconds for better update precision
This commit is contained in:
Noel Berry
2021-02-06 00:13:50 -08:00
parent 2c2d668927
commit ac58379de8
13 changed files with 101 additions and 87 deletions

View File

@ -5,14 +5,20 @@ namespace Blah
{
struct Time
{
// uptime, in milliseconds
static uint64_t milliseconds;
// ticks per second (microseconds, in this case)
static constexpr uint64_t ticks_per_second = 1000000;
// uptime, in ticks
static uint64_t ticks;
// uptime, in seconds
static float elapsed;
static double seconds;
// previous frame uptime, in ticks
static uint64_t previous_ticks;
// previous frame uptime, in seconds
static float previous_elapsed;
static double previous_seconds;
// delta time from last frame
static float delta;
@ -21,10 +27,10 @@ namespace Blah
static float pause_timer;
// pauses the entire application for the given time
static void pause_for(float time);
static void pause_for(float duration);
// returns true on the given time interval
static bool on_interval(float time, float delta, float interval, float offset);
static bool on_interval(double time, float delta, float interval, float offset);
// returns true on the given time interval
static bool on_interval(float delta, float interval, float offset);
@ -33,10 +39,10 @@ namespace Blah
static bool on_interval(float interval, float offset = 0);
// returns true when the given timestamp is passed
static bool on_time(float time, float timestamp);
static bool on_time(double time, double timestamp);
// returns true between time intervals
static bool between_interval(float time, float interval, float offset);
static bool between_interval(double time, float interval, float offset);
// returns true between time intervals
static bool between_interval(float interval, float offset = 0);

View File

@ -61,9 +61,9 @@ namespace Blah
int m_last_value_i = 0;
bool m_pressed = false;
bool m_released = false;
float m_last_press_time = -1;
float m_last_release_time = -1;
float m_repeat_press_time = -1;
double m_last_press_time = -1;
double m_last_release_time = -1;
double m_repeat_press_time = -1;
public:
VirtualAxis& add_keys(Key negative, Key positive);

View File

@ -61,9 +61,9 @@ namespace Blah
bool m_down = false;
bool m_pressed = false;
bool m_released = false;
float m_last_press_time = -1;
float m_last_release_time = -1;
float m_repeat_press_time = -1;
double m_last_press_time = -1;
double m_last_release_time = -1;
double m_repeat_press_time = -1;
public:
VirtualButton& add_key(Key key);

View File

@ -70,9 +70,9 @@ namespace Blah
bool m_released = false;
float m_i_deadzone;
float m_last_press_time = -1;
float m_last_release_time = -1;
float m_repeat_press_time = -1;
double m_last_press_time = -1;
double m_last_release_time = -1;
double m_repeat_press_time = -1;
public:
VirtualStick();