diff --git a/build.sh b/build.sh index e2bb12556828240558c4d2f84e76ce68c945ca58..d6d7f386e26b2babb71058e02a447380715ca13c 100755 --- a/build.sh +++ b/build.sh @@ -41,5 +41,5 @@ if [ -x "$(command -v mangohud)" ]; then fi pushd demo -$EXE ../build/demo/FgglDemo > /tmp/fggl.log 2>&1 & +$EXE ../build/demo/FgglDemo popd diff --git a/demo/main.cpp b/demo/main.cpp index 962435002529102aa2b5e7ffbebe585e3cb9d572..25aa1c385be68fc7ec23d801170b0b428b5644e0 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -14,6 +14,7 @@ #include <fggl/ecs/ecs.hpp> #include <fggl/debug/debug.h> #include <fggl/data/storage.hpp> +#include <fggl/util/chrono.hpp> #include <imgui.h> @@ -254,20 +255,29 @@ int main(int argc, char* argv[]) { fggl::gfx::Input& input = fggl::gfx::Input::instance(); + bool joystickWindow = true; bool gamepadWindow = true; - float time = 0.0f; - float dt = 16.0f; + fggl::util::Timer time; + time.frequency( glfwGetTimerFrequency() ); + time.setup( glfwGetTimerValue() ); + while( !win.closeRequested() ) { + + // + // Setup setup + // + time.tick( glfwGetTimerValue() ); + input.frame(); glfwModule->context.pollEvents(); debug.frameStart(); + // // update step - time += dt; - + // process_camera(win, ecs, input, camEnt); if ( cam_mode == cam_arcball ) { if ( input.mouseDown( fggl::gfx::MOUSE_2 ) ) { @@ -375,6 +385,8 @@ int main(int argc, char* argv[]) { } ImGui::End(); + debug.showDemo(); + /* float amount = glm::radians( time / 2048.0f * 360.0f ); auto spinners = ecs.getEntityWith<fggl::math::Transform>(); for ( auto entity : spinners ) { @@ -382,12 +394,14 @@ int main(int argc, char* argv[]) { transform->euler(glm::vec3(0.0f, amount, 0.0f)); }*/ + // // render step + // win.activate(); glModule->ogl.clear(); // model rendering system - fggl::gfx::renderMeshes(glModule, ecs, dt); + fggl::gfx::renderMeshes(glModule, ecs, time.delta()); debug.draw(); // swap the windows - frame rendering over diff --git a/fggl/util/chrono.hpp b/fggl/util/chrono.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bba16710ba73109bdcb292e2b044569b775b3f26 --- /dev/null +++ b/fggl/util/chrono.hpp @@ -0,0 +1,35 @@ +#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