Added Time
This commit is contained in:
11
TSE_Core/src/interfaces/ITimeInterface.hpp
Normal file
11
TSE_Core/src/interfaces/ITimeInterface.hpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class ITimeInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual float GetTotalEllapsedTime() = 0;
|
||||||
|
virtual ~ITimeInterface() = default;
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "IWindow.hpp"
|
#include "IWindow.hpp"
|
||||||
#include "Debug.hpp"
|
#include "Debug.hpp"
|
||||||
#include "LuaStateHandler.hpp"
|
#include "LuaStateHandler.hpp"
|
||||||
|
#include "Time.hpp"
|
||||||
|
|
||||||
TSE::IWindow* TSE::IWindow::lastWindow = nullptr;
|
TSE::IWindow* TSE::IWindow::lastWindow = nullptr;
|
||||||
|
|
||||||
@@ -10,6 +11,11 @@ bool TSE::IWindow::BaseInit() const
|
|||||||
Debug::Init();
|
Debug::Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TSE::IWindow::BaseUpdate() const
|
||||||
|
{
|
||||||
|
Time::Update();
|
||||||
|
}
|
||||||
|
|
||||||
TSE::IWindow::~IWindow()
|
TSE::IWindow::~IWindow()
|
||||||
{
|
{
|
||||||
Debug::Close();
|
Debug::Close();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace TSE
|
|||||||
virtual bool ShouldClose() const = 0;
|
virtual bool ShouldClose() const = 0;
|
||||||
|
|
||||||
bool BaseInit() const;
|
bool BaseInit() const;
|
||||||
|
void BaseUpdate() const;
|
||||||
~IWindow();
|
~IWindow();
|
||||||
};
|
};
|
||||||
} // namespace TSE
|
} // namespace TSE
|
||||||
|
|||||||
38
TSE_Core/src/utils/Time.cpp
Normal file
38
TSE_Core/src/utils/Time.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include "Time.hpp"
|
||||||
|
|
||||||
|
TSE::ITimeInterface* TSE::Time::timeInterface = nullptr;
|
||||||
|
float TSE::Time::DeltaTime = 0;
|
||||||
|
float TSE::Time::LastFrameTime = 0;
|
||||||
|
float TSE::Time::CurrentTime = 0;
|
||||||
|
|
||||||
|
void TSE::Time::Init(ITimeInterface *time)
|
||||||
|
{
|
||||||
|
Time::timeInterface = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Time::Destroy()
|
||||||
|
{
|
||||||
|
delete(timeInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Time::deltaTime()
|
||||||
|
{
|
||||||
|
return DeltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Time::currentTime()
|
||||||
|
{
|
||||||
|
return CurrentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
float TSE::Time::lastFrameTime()
|
||||||
|
{
|
||||||
|
return LastFrameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSE::Time::Update()
|
||||||
|
{
|
||||||
|
LastFrameTime = CurrentTime;
|
||||||
|
CurrentTime = timeInterface->GetTotalEllapsedTime();
|
||||||
|
DeltaTime = CurrentTime - LastFrameTime;
|
||||||
|
}
|
||||||
23
TSE_Core/src/utils/Time.hpp
Normal file
23
TSE_Core/src/utils/Time.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "interfaces/ITimeInterface.hpp"
|
||||||
|
|
||||||
|
namespace TSE
|
||||||
|
{
|
||||||
|
class Time
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static ITimeInterface* timeInterface;
|
||||||
|
static float LastFrameTime;
|
||||||
|
static float DeltaTime;
|
||||||
|
static float CurrentTime;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void Init(ITimeInterface* time);
|
||||||
|
static void Destroy();
|
||||||
|
static float deltaTime();
|
||||||
|
static float currentTime();
|
||||||
|
static float lastFrameTime();
|
||||||
|
static void Update();
|
||||||
|
};
|
||||||
|
} // namespace TSE
|
||||||
8
TSE_GlfwImpl/src/TimeInterfaceGlfw.cpp
Normal file
8
TSE_GlfwImpl/src/TimeInterfaceGlfw.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "TimeInterfaceGlfw.hpp"
|
||||||
|
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
float TSE::GLFW::TimeInterfaceGlfw::GetTotalEllapsedTime()
|
||||||
|
{
|
||||||
|
return (float)glfwGetTime();
|
||||||
|
}
|
||||||
12
TSE_GlfwImpl/src/TimeInterfaceGlfw.hpp
Normal file
12
TSE_GlfwImpl/src/TimeInterfaceGlfw.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "interfaces/ITimeInterface.hpp"
|
||||||
|
|
||||||
|
namespace TSE::GLFW
|
||||||
|
{
|
||||||
|
class TimeInterfaceGlfw : public ITimeInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float GetTotalEllapsedTime() override;
|
||||||
|
};
|
||||||
|
} // namespace TSE::GLFW
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "WindowGlfw.hpp"
|
#include "WindowGlfw.hpp"
|
||||||
|
#include "utils/Time.hpp"
|
||||||
|
#include "TimeInterfaceGlfw.hpp"
|
||||||
#include "Debug.hpp"
|
#include "Debug.hpp"
|
||||||
|
|
||||||
TSE::GLFW::WindowGlfw::WindowGlfw(string _title, int _width, int _height, IRenderingBackend* backend)
|
TSE::GLFW::WindowGlfw::WindowGlfw(string _title, int _width, int _height, IRenderingBackend* backend)
|
||||||
@@ -36,6 +38,8 @@ bool TSE::GLFW::WindowGlfw::Init()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Time::Init(new TimeInterfaceGlfw());
|
||||||
|
|
||||||
renderingBackend->InitPreWindow();
|
renderingBackend->InitPreWindow();
|
||||||
glfwWindowHint(GLFW_FOCUSED, true);
|
glfwWindowHint(GLFW_FOCUSED, true);
|
||||||
|
|
||||||
@@ -118,6 +122,7 @@ void TSE::GLFW::WindowGlfw::Clear() const
|
|||||||
|
|
||||||
void TSE::GLFW::WindowGlfw::Update() const
|
void TSE::GLFW::WindowGlfw::Update() const
|
||||||
{
|
{
|
||||||
|
BaseUpdate();
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
renderingBackend->onUpdate();
|
renderingBackend->onUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user