#pragma once #include #include #include "CCallbackHandler.h" #include "CScriptObject.h" using CClock = std::chrono::high_resolution_clock; using CTimePoint = std::chrono::time_point; #define TIME_EXPR(a) std::chrono::time_point_cast(a) class CTime : public CScriptObject { public: void Init(); bool V_ScriptInit(std::shared_ptr state, sol::table table) override; void NewTick(); void EndTick(); CTimePoint GetCurrent() const; unsigned int GetFPS() const; unsigned int GetPrevFPS() const; void ResetDeltaTime(double resetValue = 0.0); float GetDeltaTime() const; double GetDeltaTimePrecise() const; CCallbackHandler OnNewTick; CCallbackHandler OnEndTick; private: CTimePoint m_LastTick; CTimePoint m_NextTick; CTimePoint m_CurrentTick; CTimePoint m_LastFpsCheck; unsigned int m_MaxFps = 0; double m_WaitTime = 0.0f; double m_DeltaTime = 0.0f; unsigned int m_PrevFPS = 0; unsigned int m_FPS = 0; };