MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / computeFPS

Method computeFPS

testbed/src/TestbedApplication.cpp:565–597  ·  view source on GitHub ↗

Compute the FPS

Source from the content-addressed store, hash-verified

563
564// Compute the FPS
565void TestbedApplication::computeFPS() {
566
567 // Note : By default the nanogui library is using glfwWaitEvents() to process
568 // events and sleep to target a framerate of 50 ms (using a thread
569 // sleeping). However, for games we prefer to use glfwPollEvents()
570 // instead and remove the update. Therefore the file common.cpp of the
571 // nanogui library has been modified to have a faster framerate
572
573 mNbFrames++;
574
575 // Get the number of seconds since start
576 mCurrentTime = glfwGetTime();
577
578 // Calculate time passed
579 mFrameTime = mCurrentTime - mPreviousTime;
580 double timeInterval = (mCurrentTime - mLastTimeComputedFPS) * 1000.0;
581
582 // Update the FPS counter each second
583 if(timeInterval > 1000) {
584
585 // calculate the number of frames per second
586 mFPS = static_cast<double>(mNbFrames) / timeInterval;
587 mFPS *= 1000.0;
588
589 // Reset frame count
590 mNbFrames = 0;
591
592 mLastTimeComputedFPS = mCurrentTime;
593 }
594
595 // Set time
596 mPreviousTime = mCurrentTime;
597}
598
599void TestbedApplication::keyboard_event(int key, int scancode, int action, int modifiers) {
600

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected