1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Added in frame timestep, should be used in some way with scalers to generate rates

This commit is contained in:
Gordon McCann 2022-06-15 01:01:00 -04:00
parent e1b56dd1c3
commit ad98d7dc49
15 changed files with 55 additions and 10 deletions

View File

@ -39,7 +39,7 @@ namespace Navigator {
void SPSInputLayer::OnDetach() {} void SPSInputLayer::OnDetach() {}
void SPSInputLayer::OnUpdate() {} void SPSInputLayer::OnUpdate(Timestep& step) {}
void SPSInputLayer::OnEvent(Event& event) {} void SPSInputLayer::OnEvent(Event& event) {}

View File

@ -27,7 +27,7 @@ namespace Navigator {
virtual void OnAttach() override; virtual void OnAttach() override;
virtual void OnDetach() override; virtual void OnDetach() override;
virtual void OnUpdate() override; virtual void OnUpdate(Timestep& step) override;
virtual void OnEvent(Event& event) override; //If you want to respond to events virtual void OnEvent(Event& event) override; //If you want to respond to events
virtual void OnImGuiRender() override; //"Main" function virtual void OnImGuiRender() override; //"Main" function

View File

@ -11,6 +11,7 @@
#include "Application.h" #include "Application.h"
#include "Navigator/Renderer/RenderCommand.h" #include "Navigator/Renderer/RenderCommand.h"
#include "Navigator/Editor/EditorLayer.h" #include "Navigator/Editor/EditorLayer.h"
#include "Timestep.h"
namespace Navigator { namespace Navigator {
@ -77,13 +78,22 @@ namespace Navigator {
void Application::Run() void Application::Run()
{ {
NAV_PROFILE_FUNCTION(); NAV_PROFILE_FUNCTION();
float lastFrameTime = 0;
float time;
Timestep step;
while(m_runFlag) while(m_runFlag)
{ {
RenderCommand::SetClearColor(m_bckgnd_color); RenderCommand::SetClearColor(m_bckgnd_color);
RenderCommand::Clear(); RenderCommand::Clear();
time = RenderCommand::GetFrameTime();
step.SetTime(time - lastFrameTime);
lastFrameTime = time;
for(auto layer : m_stack) for(auto layer : m_stack)
layer->OnUpdate(); layer->OnUpdate(step);
m_imgui_layer->Begin(); m_imgui_layer->Begin();
for(auto layer : m_stack) for(auto layer : m_stack)

View File

@ -9,6 +9,7 @@
#include "NavCore.h" #include "NavCore.h"
#include "Navigator/Events/Event.h" #include "Navigator/Events/Event.h"
#include "Timestep.h"
namespace Navigator { namespace Navigator {
@ -21,7 +22,7 @@ namespace Navigator {
virtual void OnAttach() {} virtual void OnAttach() {}
virtual void OnDetach() {} virtual void OnDetach() {}
virtual void OnImGuiRender() {} virtual void OnImGuiRender() {}
virtual void OnUpdate() {} virtual void OnUpdate(Timestep& step) {}
virtual void OnEvent(Event& event) {} virtual void OnEvent(Event& event) {}
inline const std::string& GetName() { return m_name; } inline const std::string& GetName() { return m_name; }

View File

@ -0,0 +1,25 @@
#ifndef TIMESTEP_H
#define TIMESTEP_H
namespace Navigator {
class Timestep
{
public:
Timestep(float time=0.0f) :
m_time(time)
{
}
void SetTime(float time) { m_time = time; }
operator float() { return m_time; }
float GetElapsedSeconds() const { return m_time; }
float GetElapsedMilliseconds() const { return m_time * 1000.0f; }
private:
float m_time;
};
}
#endif

View File

@ -38,7 +38,7 @@ namespace Navigator {
{ {
} }
void EditorLayer::OnUpdate() void EditorLayer::OnUpdate(Timestep& step)
{ {
} }

View File

@ -33,7 +33,7 @@ namespace Navigator {
virtual void OnAttach() override; virtual void OnAttach() override;
virtual void OnDetach() override; virtual void OnDetach() override;
virtual void OnImGuiRender() override; virtual void OnImGuiRender() override;
virtual void OnUpdate() override; virtual void OnUpdate(Timestep& step) override;
virtual void OnEvent(Event& event) override; virtual void OnEvent(Event& event) override;

View File

@ -87,7 +87,7 @@ namespace Navigator {
m_physStack.PushStage(stage); m_physStack.PushStage(stage);
} }
void PhysicsLayer::OnUpdate() {} void PhysicsLayer::OnUpdate(Timestep& step) {}
/*Threaded functions*/ /*Threaded functions*/

View File

@ -31,7 +31,7 @@ namespace Navigator {
virtual ~PhysicsLayer(); virtual ~PhysicsLayer();
virtual void OnAttach() override; virtual void OnAttach() override;
virtual void OnUpdate() override; virtual void OnUpdate(Timestep& step) override;
virtual void OnDetach() override; virtual void OnDetach() override;
virtual void OnImGuiRender() override {}; virtual void OnImGuiRender() override {};
virtual void OnEvent(Event& event) override; virtual void OnEvent(Event& event) override;

View File

@ -18,6 +18,7 @@ namespace Navigator {
public: public:
inline static void SetClearColor(const glm::vec4& color_array) { s_api->SetClearColor(color_array); } inline static void SetClearColor(const glm::vec4& color_array) { s_api->SetClearColor(color_array); }
inline static void Clear() { s_api->Clear(); } inline static void Clear() { s_api->Clear(); }
inline static float GetFrameTime() { return s_api->GetFrameTime(); }
private: private:
static RendererAPI* s_api; static RendererAPI* s_api;

View File

@ -24,6 +24,7 @@ namespace Navigator {
virtual void Clear() = 0; virtual void Clear() = 0;
virtual void SetClearColor(const glm::vec4& color) = 0; virtual void SetClearColor(const glm::vec4& color) = 0;
virtual float GetFrameTime() = 0;
inline static API GetAPI() { return s_api; } inline static API GetAPI() { return s_api; }

View File

@ -314,7 +314,7 @@ namespace Navigator {
} }
//Tell to write, then poll actions //Tell to write, then poll actions
void TestServerLayer::OnUpdate() void TestServerLayer::OnUpdate(Timestep& step)
{ {
m_connection->Start(); m_connection->Start();
m_context.poll(); m_context.poll();

View File

@ -66,7 +66,7 @@ namespace Navigator {
virtual void OnAttach() override; virtual void OnAttach() override;
virtual void OnDetach() override; virtual void OnDetach() override;
virtual void OnUpdate() override; virtual void OnUpdate(Timestep& step) override;
private: private:
asio::io_context m_context; asio::io_context m_context;

View File

@ -8,6 +8,7 @@
#include "OpenGLRendererAPI.h" #include "OpenGLRendererAPI.h"
#include "glad/glad.h" #include "glad/glad.h"
#include "GLFW/glfw3.h"
namespace Navigator { namespace Navigator {
@ -20,4 +21,9 @@ namespace Navigator {
{ {
glClearColor(color_array[0], color_array[1], color_array[2], color_array[3]); glClearColor(color_array[0], color_array[1], color_array[2], color_array[3]);
} }
float OpenGLRendererAPI::GetFrameTime()
{
return (float)glfwGetTime();
}
} }

View File

@ -18,6 +18,7 @@ namespace Navigator {
public: public:
virtual void Clear() override; virtual void Clear() override;
virtual void SetClearColor(const glm::vec4& color_array) override; virtual void SetClearColor(const glm::vec4& color_array) override;
virtual float GetFrameTime() override;
}; };
} }