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-11-03 11:19:01 +03:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "Timer.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
class Time final {
|
|
|
|
private:
|
2021-11-03 11:19:01 +03:00
|
|
|
std::map<std::string, Timer> _timers;
|
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
// 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-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-11-03 11:19:01 +03:00
|
|
|
|
|
|
|
static void startTimer(const std::string& timerName);
|
|
|
|
static void stopTimer(const std::string& timerName);
|
|
|
|
|
|
|
|
[[nodiscard]] static double elapsedTimerMilliseconds(const std::string& timerName);
|
|
|
|
[[nodiscard]] static double elapsedTimerSeconds(const std::string& timerName);
|
|
|
|
|
|
|
|
[[nodiscard]] static std::map<std::string, Timer> const & timers() { return _instance->_timers; }
|
2021-10-17 19:38:16 +03:00
|
|
|
};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
#endif //INC_3DZAVR_TIME_H
|