MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / drawFps

Function drawFps

TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp:546–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544 }
545
546 void drawFps(s32 windowWidth)
547 {
548 const u32 windowFlags = ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoSavedSettings;
549 static f64 _fpsAve = 0.0;
550
551 // Calculate the window size.
552 ImFont* fpsFont = s_versionFont;
553 ImVec2 size = fpsFont->CalcTextSizeA(fpsFont->FontSize, 1024.0f, 0.0f, "FPS: 99999");
554 f32 width = size.x + 8.0f;
555 f32 height = size.y + 8.0f;
556
557 // Get the raw delta time.
558 const f64 dt = TFE_System::getDeltaTimeRaw();
559 // Adjust the exponential average based on the frame time - this is because the standard of deviation is much higher as frame times get really small.
560 const f64 expAve = dt >= 1.0 / 144.0 ? 0.95 : 0.999;
561 // Compute the current fps from the delta time.
562 const f64 curFps = 1.0f / dt;
563 // Compute the exponential average based on the curFPS and the running average.
564 const f64 aveFps = _fpsAve != 0.0 ? curFps * (1.0 - expAve) + _fpsAve * expAve : curFps;
565 _fpsAve = aveFps;
566
567 ImGui::PushFont(fpsFont);
568 ImGui::SetNextWindowSize(ImVec2(width, height));
569 ImGui::SetNextWindowPos(ImVec2(windowWidth - width, 0.0f));
570 ImGui::Begin("##FPS", nullptr, windowFlags);
571 ImGui::Text("FPS: %d", s32(aveFps + 0.5));
572 ImGui::End();
573 ImGui::PopFont();
574 }
575
576 void setCurrentGame(IGame* game)
577 {

Callers 2

updateFunction · 0.85
drawFunction · 0.85

Calls 3

getDeltaTimeRawFunction · 0.85
ImVec2Function · 0.85
CalcTextSizeAMethod · 0.80

Tested by

no test coverage detected