| 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 | { |
no test coverage detected