Skip to content
Snippets Groups Projects
Commit 92c37613 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add custom timer class

parent 6f64a0fd
No related branches found
No related tags found
No related merge requests found
...@@ -41,5 +41,5 @@ if [ -x "$(command -v mangohud)" ]; then ...@@ -41,5 +41,5 @@ if [ -x "$(command -v mangohud)" ]; then
fi fi
pushd demo pushd demo
$EXE ../build/demo/FgglDemo > /tmp/fggl.log 2>&1 & $EXE ../build/demo/FgglDemo
popd popd
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <fggl/ecs/ecs.hpp> #include <fggl/ecs/ecs.hpp>
#include <fggl/debug/debug.h> #include <fggl/debug/debug.h>
#include <fggl/data/storage.hpp> #include <fggl/data/storage.hpp>
#include <fggl/util/chrono.hpp>
#include <imgui.h> #include <imgui.h>
...@@ -254,20 +255,29 @@ int main(int argc, char* argv[]) { ...@@ -254,20 +255,29 @@ int main(int argc, char* argv[]) {
fggl::gfx::Input& input = fggl::gfx::Input::instance(); fggl::gfx::Input& input = fggl::gfx::Input::instance();
bool joystickWindow = true; bool joystickWindow = true;
bool gamepadWindow = true; bool gamepadWindow = true;
float time = 0.0f; fggl::util::Timer time;
float dt = 16.0f; time.frequency( glfwGetTimerFrequency() );
time.setup( glfwGetTimerValue() );
while( !win.closeRequested() ) { while( !win.closeRequested() ) {
//
// Setup setup
//
time.tick( glfwGetTimerValue() );
input.frame(); input.frame();
glfwModule->context.pollEvents(); glfwModule->context.pollEvents();
debug.frameStart(); debug.frameStart();
//
// update step // update step
time += dt; //
process_camera(win, ecs, input, camEnt); process_camera(win, ecs, input, camEnt);
if ( cam_mode == cam_arcball ) { if ( cam_mode == cam_arcball ) {
if ( input.mouseDown( fggl::gfx::MOUSE_2 ) ) { if ( input.mouseDown( fggl::gfx::MOUSE_2 ) ) {
...@@ -375,6 +385,8 @@ int main(int argc, char* argv[]) { ...@@ -375,6 +385,8 @@ int main(int argc, char* argv[]) {
} }
ImGui::End(); ImGui::End();
debug.showDemo();
/* float amount = glm::radians( time / 2048.0f * 360.0f ); /* float amount = glm::radians( time / 2048.0f * 360.0f );
auto spinners = ecs.getEntityWith<fggl::math::Transform>(); auto spinners = ecs.getEntityWith<fggl::math::Transform>();
for ( auto entity : spinners ) { for ( auto entity : spinners ) {
...@@ -382,12 +394,14 @@ int main(int argc, char* argv[]) { ...@@ -382,12 +394,14 @@ int main(int argc, char* argv[]) {
transform->euler(glm::vec3(0.0f, amount, 0.0f)); transform->euler(glm::vec3(0.0f, amount, 0.0f));
}*/ }*/
//
// render step // render step
//
win.activate(); win.activate();
glModule->ogl.clear(); glModule->ogl.clear();
// model rendering system // model rendering system
fggl::gfx::renderMeshes(glModule, ecs, dt); fggl::gfx::renderMeshes(glModule, ecs, time.delta());
debug.draw(); debug.draw();
// swap the windows - frame rendering over // swap the windows - frame rendering over
......
#ifndef FGGL_UTIL_CHRONO_H
#define FGGL_UTIL_CHRONO_H
namespace fggl::util {
class Timer {
public:
inline void frequency(long freq) {
m_freq = freq;
}
inline void setup(long epoch) {
m_first = epoch;
m_last = m_first;
m_curr = m_first;
}
inline void tick(long time) {
m_last = m_curr;
m_curr = time;
}
inline float delta() const {
return (m_curr - m_last) / m_freq;
}
private:
float m_freq;
float m_first;
float m_last;
float m_curr;
};
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment