blah/include/blah_time.h

65 lines
1.6 KiB
C
Raw Permalink Normal View History

2020-08-26 15:38:01 +08:00
#pragma once
#include <blah_common.h>
2020-08-26 15:38:01 +08:00
namespace Blah
{
namespace Time
2020-08-26 15:38:01 +08:00
{
// ticks per second (microseconds, in this case)
constexpr u64 ticks_per_second = 1000000;
// uptime, in ticks, at the start of the current frame
extern u64 ticks;
2020-08-26 15:38:01 +08:00
// uptime, in seconds, at the start of the current frame
extern double seconds;
// delta time from last frame
extern float delta;
// previous frame uptime, in ticks
extern u64 previous_ticks;
2020-08-26 15:38:01 +08:00
// previous frame uptime, in seconds
extern double previous_seconds;
2020-08-26 15:38:01 +08:00
// time the application should pause for
extern float pause_timer;
2020-08-26 15:38:01 +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
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
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
bool on_interval(float delta, float interval, float offset);
2020-08-28 10:43:47 +08:00
// returns true on the given time interval
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
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
bool between_interval(double time, float interval, float offset);
2020-08-28 10:43:47 +08:00
// returns true between time intervals
bool between_interval(float interval, float offset = 0);
2020-08-26 15:38:01 +08:00
};
class Stopwatch
{
public:
Stopwatch();
void reset();
u64 microseconds() const;
u64 milliseconds() const;
private:
u64 start_time;
};
2020-08-26 15:38:01 +08:00
}