feat: move fps and deltatime calculations in core engine
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
|
||||
#include "engine/scene/scene.h"
|
||||
#include "engine/window/event.hpp"
|
||||
#include "engine/time/timestep.h"
|
||||
|
||||
#include "engine/export.h"
|
||||
|
||||
namespace Core {
|
||||
@ -11,7 +13,7 @@ namespace Core {
|
||||
virtual ~IApplication() = default;
|
||||
|
||||
virtual void OnInit(std::shared_ptr<Scene> scene) {};
|
||||
virtual void OnUpdate() {};
|
||||
virtual void OnUpdate(Timestep dt) {};
|
||||
virtual void OnShutdown() {};
|
||||
|
||||
virtual void OnEvent(const Event& event) {};
|
||||
|
||||
@ -30,6 +30,7 @@ private:
|
||||
std::shared_ptr<Window> m_window;
|
||||
std::unique_ptr<Renderer> m_renderer;
|
||||
std::shared_ptr<Scene> m_scene;
|
||||
uint64_t m_elapsed;
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
|
||||
22
engine/include/engine/time/timestep.h
Normal file
22
engine/include/engine/time/timestep.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef TIME_TIMESTEP_H_
|
||||
#define TIME_TIMESTEP_H_
|
||||
|
||||
namespace Core {
|
||||
class Timestep {
|
||||
public:
|
||||
Timestep(float time = 0.0f)
|
||||
: m_time(time) {}
|
||||
|
||||
[[nodiscard]] float GetSeconds() const { return m_time; }
|
||||
[[nodiscard]] float GetMilliseconds() const { return m_time * 1000.f; }
|
||||
|
||||
operator float() const { return m_time; }
|
||||
public:
|
||||
static Timestep FromMilliseconds(float milliseconds) { return Timestep(milliseconds * 0.001f); }
|
||||
static Timestep FromSeconds(float seconds) { return Timestep(seconds); }
|
||||
private:
|
||||
float m_time;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TIME_TIMESTEP_H_
|
||||
Reference in New Issue
Block a user