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