Some progress

This commit is contained in:
SimoZ64
2025-05-22 00:30:33 +02:00
parent 8fa341bf72
commit 722a0e98c0
14 changed files with 317 additions and 178 deletions

View File

@@ -1,15 +1,13 @@
#include <Core.hpp>
#include <EmuThread.hpp>
#include <KaizenGui.hpp>
EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, RenderWidget &renderWidget,
SettingsWindow &settings) noexcept :
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {}
SettingsWindow &settings, KaizenGui& kaizenGui) noexcept :
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {
void EmuThread::start() noexcept {
thread = std::thread([this]() {
thread = std::thread([&]() {
isRunning = true;
core->parallel.Init(renderWidget.wsiPlatform, renderWidget.windowInfo,
core->cpu->GetMem().GetRDRAMPtr());
auto lastSample = std::chrono::high_resolution_clock::now();
auto avgFps = 16.667;
@@ -19,32 +17,60 @@ void EmuThread::start() noexcept {
fps = 1000.0 / avgFps;
while (!interruptionRequested) {
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
if (core->render) {
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi);
}
const auto endFrameTime = std::chrono::high_resolution_clock::now();
using namespace std::chrono_literals;
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
avgFps += frameTimeMs;
sampledFps++;
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
if(!started) {
const auto startFrameTime = std::chrono::high_resolution_clock::now();
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi, kaizenGui, false);
const auto endFrameTime = std::chrono::high_resolution_clock::now();
using namespace std::chrono_literals;
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
avgFps += frameTimeMs;
sampledFps++;
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
}
continue;
}
if(started) {
started = false;
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
if (core->render) {
core->parallel.UpdateScreen(core->cpu->GetMem().mmio.vi, kaizenGui);
}
const auto endFrameTime = std::chrono::high_resolution_clock::now();
using namespace std::chrono_literals;
const auto frameTimeMs = std::chrono::duration<double>(endFrameTime - startFrameTime) / 1ms;
avgFps += frameTimeMs;
sampledFps++;
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
}
}
SetRender(false);
@@ -53,6 +79,8 @@ void EmuThread::start() noexcept {
});
}
void EmuThread::start() noexcept { started = true; }
void EmuThread::TogglePause() const noexcept {
core->TogglePause();
Util::RPC::GetInstance().Update(core->pause ? Util::RPC::Paused : Util::RPC::GetInstance().GetState(),