From abe178fa1de2415a577e6f65ce83d8dab0e2cc66 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Tue, 1 Mar 2016 07:41:15 +0100 Subject: [PATCH] Working on new gui for testbed application --- testbed/src/Gui.cpp | 24 +++++++-------- testbed/src/Gui.h | 4 +-- testbed/src/TestbedApplication.cpp | 47 ++++++++++++------------------ testbed/src/TestbedApplication.h | 14 ++++----- 4 files changed, 39 insertions(+), 50 deletions(-) diff --git a/testbed/src/Gui.cpp b/testbed/src/Gui.cpp index 2387dfc8..4e50a7ce 100644 --- a/testbed/src/Gui.cpp +++ b/testbed/src/Gui.cpp @@ -79,22 +79,22 @@ void Gui::init() { // Update the GUI void Gui::update() { - double currentTime = glfwGetTime(); - if ((currentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) { - mTimeSinceLastProfilingDisplay = currentTime; + // Update Profiling GUI every seconds + if ((mApp->mCurrentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) { + mTimeSinceLastProfilingDisplay = mApp->mCurrentTime; mCachedFPS = mApp->mFPS; - mCachedUpdateTime = mApp->mUpdateTime; - mCachedPhysicsUpdateTime = mApp->mPhysicsUpdateTime; + mCachedUpdateTime = mApp->mFrameTime; + mCachedPhysicsUpdateTime = mApp->mPhysicsTime; } // Framerate (FPS) mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0)); - // Update time - mUpdateTimeLabel->setCaption(std::string("Update time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1)); + // Frame time + mFrameTimeLabel->setCaption(std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1)); - // Update time - mUpdatePhysicsTimeLabel->setCaption("Update physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1)); + // Physics time + mPhysicsTimeLabel->setCaption("Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1)); } @@ -400,7 +400,7 @@ void Gui::createSettingsPanel() { CheckBox* checkboxVSync = new CheckBox(mRenderingPanel, "V-Sync"); checkboxVSync->setChecked(mApp->mIsVSyncEnabled); checkboxVSync->setCallback([&](bool value) { - mApp->mIsVSyncEnabled = value; + mApp->enableVSync(value); }); // Enabled/Disable Shadows @@ -426,10 +426,10 @@ void Gui::createProfilingPanel() { mFPSLabel = new Label(profilingPanel, std::string("FPS : ") + floatToString(mCachedFPS, 0),"sans-bold"); // Update time - mUpdateTimeLabel = new Label(profilingPanel, std::string("Update time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1),"sans-bold"); + mFrameTimeLabel = new Label(profilingPanel, std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1),"sans-bold"); // Update time - mUpdatePhysicsTimeLabel = new Label(profilingPanel, "Update physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1),"sans-bold"); + mPhysicsTimeLabel = new Label(profilingPanel, "Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1),"sans-bold"); profilingPanel->setVisible(true); } diff --git a/testbed/src/Gui.h b/testbed/src/Gui.h index 26fc5bcc..5a63d610 100644 --- a/testbed/src/Gui.h +++ b/testbed/src/Gui.h @@ -68,8 +68,8 @@ class Gui { // Profiling panel Label* mFPSLabel; - Label* mUpdateTimeLabel; - Label* mUpdatePhysicsTimeLabel; + Label* mFrameTimeLabel; + Label* mPhysicsTimeLabel; std::vector mCheckboxesScenes; diff --git a/testbed/src/TestbedApplication.cpp b/testbed/src/TestbedApplication.cpp index eca42a78..cb970844 100644 --- a/testbed/src/TestbedApplication.cpp +++ b/testbed/src/TestbedApplication.cpp @@ -51,7 +51,7 @@ const float TestbedApplication::SCROLL_SENSITIVITY = 0.02f; TestbedApplication::TestbedApplication(bool isFullscreen) : Screen(Vector2i(1280, 760), "Testbed ReactPhysics3D", true, isFullscreen), mIsInitialized(false), mFPS(0), mNbFrames(0), mPreviousTime(0), - mUpdateTime(0), mPhysicsUpdateTime(0), mGui(this) { + mLastTimeComputedFPS(0), mFrameTime(0), mPhysicsTime(0), mGui(this) { mCurrentScene = NULL; mIsMultisamplingActive = true; @@ -61,10 +61,12 @@ TestbedApplication::TestbedApplication(bool isFullscreen) mSinglePhysicsStepDone = false; mWindowToFramebufferRatio = Vector2(1, 1); mIsShadowMappingEnabled = true; - mIsVSyncEnabled = true; + mIsVSyncEnabled = false; mIsContactPointsDisplayed = false; init(); + + resizeEvent(Vector2i(0, 0)); } // Destructor @@ -72,12 +74,6 @@ TestbedApplication::~TestbedApplication() { // Destroy all the scenes destroyScenes(); - - // Destroy the window - //glfwDestroyWindow(mWindow); - - // Terminate GLFW - //glfwTerminate(); } // Initialize the viewer @@ -184,7 +180,7 @@ void TestbedApplication::update() { } // Compute the physics update time - mPhysicsUpdateTime = glfwGetTime() - currentTime; + mPhysicsTime = glfwGetTime() - currentTime; // Compute the interpolation factor float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep); @@ -205,8 +201,6 @@ void TestbedApplication::update() { void TestbedApplication::drawContents() { - resizeEvent(Vector2i(0, 0)); - update(); int bufferWidth, bufferHeight; @@ -219,16 +213,13 @@ void TestbedApplication::drawContents() { // Render the scene mCurrentScene->render(); - // Display the GUI - //Gui::getInstance().render(); - - // Compute the current framerate - computeFPS(); - mGui.update(); // Check the OpenGL errors checkOpenGLErrors(); + + // Compute the current framerate + computeFPS(); } /// Window resize event handler @@ -251,12 +242,6 @@ bool TestbedApplication::resizeEvent(const Vector2i& size) { return true; } -// Set the dimension of the camera viewport -void TestbedApplication::reshape() { - - -} - // Change the current scene void TestbedApplication::switchScene(Scene* newScene) { @@ -271,6 +256,8 @@ void TestbedApplication::switchScene(Scene* newScene) { // Reset the scene mCurrentScene->reset(); + + resizeEvent(Vector2i(0, 0)); } // Check the OpenGL errors @@ -310,22 +297,24 @@ void TestbedApplication::computeFPS() { mCurrentTime = glfwGetTime(); // Calculate time passed - mUpdateTime = mCurrentTime - mPreviousTime; - double timeInterval = mUpdateTime * 1000.0; + mFrameTime = mCurrentTime - mPreviousTime; + double timeInterval = (mCurrentTime - mLastTimeComputedFPS) * 1000.0; // Update the FPS counter each second - if(timeInterval > 0.0001) { + if(timeInterval > 1000) { // calculate the number of frames per second mFPS = static_cast(mNbFrames) / timeInterval; mFPS *= 1000.0; - // Set time - mPreviousTime = mCurrentTime; - // Reset frame count mNbFrames = 0; + + mLastTimeComputedFPS = mCurrentTime; } + + // Set time + mPreviousTime = mCurrentTime; } // GLFW error callback method diff --git a/testbed/src/TestbedApplication.h b/testbed/src/TestbedApplication.h index dec37de3..29bdc545 100644 --- a/testbed/src/TestbedApplication.h +++ b/testbed/src/TestbedApplication.h @@ -80,11 +80,14 @@ class TestbedApplication : public Screen { /// Previous time for fps computation (in seconds) double mPreviousTime; + /// Last time the FPS have been computed + double mLastTimeComputedFPS; + /// Update time (in seconds) - double mUpdateTime; + double mFrameTime; /// Physics update time (in seconds) - double mPhysicsUpdateTime; + double mPhysicsTime; /// True if multisampling is active bool mIsMultisamplingActive; @@ -126,9 +129,6 @@ class TestbedApplication : public Screen { /// Update the simulation by taking a single physics step void updateSinglePhysicsStep(); - /// Called when the windows is reshaped - void reshape(); - /// Check the OpenGL errors static void checkOpenGLErrorsInternal(const char* file, int line); @@ -275,13 +275,13 @@ inline void TestbedApplication::displayContactPoints(bool display) { // Enable/Disable Vertical synchronization inline void TestbedApplication::enableVSync(bool enable) { - mIsVSyncEnabled = enable; + /*mIsVSyncEnabled = enable; if (mIsVSyncEnabled) { glfwSwapInterval(1); } else { glfwSwapInterval(0); - } + }*/ } #endif