Implement FPS counting

This commit is contained in:
SimoneN64
2024-12-25 21:28:34 +01:00
parent 92a10d41ad
commit 7d18f2386a
2 changed files with 8 additions and 2 deletions

View File

@@ -3,7 +3,6 @@
#include <backend/RomHelpers.hpp> #include <backend/RomHelpers.hpp>
#include <cassert> #include <cassert>
#include <core/Interpreter.hpp> #include <core/Interpreter.hpp>
#include <core/registers/Cop0.hpp>
#include <core/registers/Registers.hpp> #include <core/registers/Registers.hpp>
#include <unarr.h> #include <unarr.h>
@@ -115,7 +114,7 @@ std::vector<u8> Mem::OpenArchive(const std::string &path, size_t &sizeAdjusted)
auto filename = ar_entry_get_name(archive); auto filename = ar_entry_get_name(archive);
auto extension = fs::path(filename).extension(); auto extension = fs::path(filename).extension();
if (std::ranges::any_of(rom_exts, [&](const auto& x) { return extension == x; })) { if (std::ranges::any_of(rom_exts, [&](const auto &x) { return extension == x; })) {
const auto size = ar_entry_get_size(archive); const auto size = ar_entry_get_size(archive);
sizeAdjusted = Util::NextPow2(size); sizeAdjusted = Util::NextPow2(size);
buf.resize(sizeAdjusted); buf.resize(sizeAdjusted);
@@ -283,6 +282,7 @@ u32 Mem::Read(Registers &regs, const u32 paddr) {
return 0; return 0;
default: default:
Util::panic("Unimplemented 32-bit read at address {:08X} (PC = {:016X})", paddr, (u64)regs.pc); Util::panic("Unimplemented 32-bit read at address {:08X} (PC = {:016X})", paddr, (u64)regs.pc);
return 0;
} }
} }
@@ -313,6 +313,7 @@ u64 Mem::Read(Registers &regs, const u32 paddr) {
return 0; return 0;
default: default:
Util::panic("Unimplemented 32-bit read at address {:08X} (PC = {:016X})", paddr, (u64)regs.pc); Util::panic("Unimplemented 32-bit read at address {:08X} (PC = {:016X})", paddr, (u64)regs.pc);
return 0;
} }
} }

View File

@@ -12,6 +12,7 @@ void EmuThread::run() noexcept {
auto lastSample = std::chrono::high_resolution_clock::now(); auto lastSample = std::chrono::high_resolution_clock::now();
auto avgFps = 16.667; auto avgFps = 16.667;
auto sampledFps = 0; auto sampledFps = 0;
static bool oneSecondPassed = false;
fps.setText(fmt::format("{:.2f} FPS", 1000.0 / avgFps).c_str()); fps.setText(fmt::format("{:.2f} FPS", 1000.0 / avgFps).c_str());
@@ -34,6 +35,10 @@ void EmuThread::run() noexcept {
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s; if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) { elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime; lastSample = endFrameTime;
avgFps /= sampledFps; avgFps /= sampledFps;
sampledFps = 0; sampledFps = 0;