2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 11.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_TIME_H
|
|
|
|
#define ENGINE_TIME_H
|
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
#include <chrono>
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
class Time final {
|
|
|
|
private:
|
|
|
|
// High precision time
|
|
|
|
std::chrono::high_resolution_clock::time_point _start = std::chrono::high_resolution_clock::now();
|
|
|
|
std::chrono::high_resolution_clock::time_point _last = _start;
|
|
|
|
|
|
|
|
// FPS counter
|
|
|
|
std::chrono::high_resolution_clock::time_point _fpsStart{};
|
|
|
|
std::chrono::milliseconds _fpsCountTime = std::chrono::milliseconds(1000);
|
|
|
|
int _fpsCounter = 0;
|
|
|
|
double _lastFps = 0;
|
|
|
|
|
|
|
|
// Compatibility
|
|
|
|
double _time = 0;
|
|
|
|
double _deltaTime = 0;
|
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
static Time *_instance;
|
2021-10-29 23:44:37 +03:00
|
|
|
static bool _validInstance;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
Time() = default;
|
|
|
|
|
|
|
|
public:
|
2021-10-31 11:39:08 +03:00
|
|
|
Time(const Time &) = delete;
|
|
|
|
|
|
|
|
Time &operator=(Time &) = delete;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
static int fps();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static double time();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static double deltaTime();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void update();
|
|
|
|
|
|
|
|
static void init();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void free();
|
|
|
|
};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
#endif //INC_3DZAVR_TIME_H
|