2020-08-26 00:38:01 -07:00
|
|
|
#pragma once
|
2022-10-01 13:29:51 -07:00
|
|
|
#include <blah_common.h>
|
2020-08-26 00:38:01 -07:00
|
|
|
|
|
|
|
namespace Blah
|
|
|
|
{
|
2022-02-10 01:13:20 -08:00
|
|
|
namespace Time
|
2020-08-26 00:38:01 -07:00
|
|
|
{
|
2021-02-06 00:13:50 -08:00
|
|
|
// ticks per second (microseconds, in this case)
|
2022-02-10 01:13:20 -08:00
|
|
|
constexpr u64 ticks_per_second = 1000000;
|
2021-02-06 00:13:50 -08:00
|
|
|
|
2022-02-11 16:07:07 -08:00
|
|
|
// uptime, in ticks, at the start of the current frame
|
2022-02-10 01:13:20 -08:00
|
|
|
extern u64 ticks;
|
2020-08-26 00:38:01 -07:00
|
|
|
|
2022-02-11 16:07:07 -08:00
|
|
|
// uptime, in seconds, at the start of the current frame
|
2022-02-10 01:13:20 -08:00
|
|
|
extern double seconds;
|
2021-02-06 00:13:50 -08:00
|
|
|
|
2022-02-11 15:20:07 -08:00
|
|
|
// delta time from last frame
|
|
|
|
extern float delta;
|
|
|
|
|
2021-02-06 00:13:50 -08:00
|
|
|
// previous frame uptime, in ticks
|
2022-02-10 01:13:20 -08:00
|
|
|
extern u64 previous_ticks;
|
2020-08-26 00:38:01 -07:00
|
|
|
|
|
|
|
// previous frame uptime, in seconds
|
2022-02-10 01:13:20 -08:00
|
|
|
extern double previous_seconds;
|
2020-08-26 00:38:01 -07:00
|
|
|
|
|
|
|
// time the application should pause for
|
2022-02-10 01:13:20 -08:00
|
|
|
extern float pause_timer;
|
2020-08-26 00:38:01 -07:00
|
|
|
|
2022-02-11 16:07:07 -08:00
|
|
|
// uptime, in ticks. polls the Platform for an immediate value, unlike the cached `Time::ticks` value
|
|
|
|
u64 get_ticks();
|
|
|
|
|
2020-08-27 19:43:47 -07:00
|
|
|
// pauses the entire application for the given time
|
2022-02-10 01:13:20 -08:00
|
|
|
void pause_for(float duration);
|
2020-08-26 00:38:01 -07:00
|
|
|
|
2020-08-27 19:43:47 -07:00
|
|
|
// returns true on the given time interval
|
2022-02-10 01:13:20 -08:00
|
|
|
bool on_interval(double time, float delta, float interval, float offset);
|
2020-08-27 19:43:47 -07:00
|
|
|
|
|
|
|
// returns true on the given time interval
|
2022-02-10 01:13:20 -08:00
|
|
|
bool on_interval(float delta, float interval, float offset);
|
2020-08-27 19:43:47 -07:00
|
|
|
|
|
|
|
// returns true on the given time interval
|
2022-02-10 01:13:20 -08:00
|
|
|
bool on_interval(float interval, float offset = 0);
|
2020-08-26 00:38:01 -07:00
|
|
|
|
2020-08-27 19:43:47 -07:00
|
|
|
// returns true when the given timestamp is passed
|
2022-02-10 01:13:20 -08:00
|
|
|
bool on_time(double time, double timestamp);
|
2020-08-26 00:38:01 -07:00
|
|
|
|
2020-08-27 19:43:47 -07:00
|
|
|
// returns true between time intervals
|
2022-02-10 01:13:20 -08:00
|
|
|
bool between_interval(double time, float interval, float offset);
|
2020-08-27 19:43:47 -07:00
|
|
|
|
|
|
|
// returns true between time intervals
|
2022-02-10 01:13:20 -08:00
|
|
|
bool between_interval(float interval, float offset = 0);
|
2020-08-26 00:38:01 -07:00
|
|
|
};
|
2021-05-09 17:23:02 -07:00
|
|
|
|
|
|
|
class Stopwatch
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Stopwatch();
|
|
|
|
void reset();
|
2021-12-12 20:41:23 -08:00
|
|
|
u64 microseconds() const;
|
|
|
|
u64 milliseconds() const;
|
2021-05-09 17:23:02 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
u64 start_time;
|
|
|
|
};
|
2020-08-26 00:38:01 -07:00
|
|
|
}
|