make it single threaded for now...

Hmm don't quite get it

idfk
This commit is contained in:
irisz64
2025-05-26 15:05:05 +02:00
parent 2152a73cce
commit 67c761d34b
9 changed files with 56 additions and 67 deletions

View File

@@ -6,46 +6,39 @@ EmuThread::EmuThread(const std::shared_ptr<n64::Core> &core, double &fps, Render
SettingsWindow &settings) noexcept :
renderWidget(renderWidget), core(core), settings(settings), fps(fps) {}
void EmuThread::start() noexcept {
thread = std::thread([&]() {
isRunning = true;
void EmuThread::run() noexcept {
isRunning = true;
auto lastSample = std::chrono::high_resolution_clock::now();
auto avgFps = 16.667;
auto sampledFps = 0;
static bool oneSecondPassed = false;
fps = 1000.0 / avgFps;
while (!interruptionRequested) {
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
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;
}
auto lastSample = std::chrono::high_resolution_clock::now();
auto avgFps = 16.667;
auto sampledFps = 0;
static bool oneSecondPassed = false;
fps = 1000.0 / avgFps;
const auto startFrameTime = std::chrono::high_resolution_clock::now();
if (!core->pause) {
core->Run(settings.getVolumeL(), settings.getVolumeR());
}
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;
return;
}
SetRender(false);
Stop();
isRunning = false;
});
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;
fps = 1000.0 / avgFps;
}
}
void EmuThread::TogglePause() const noexcept {
@@ -55,8 +48,6 @@ void EmuThread::TogglePause() const noexcept {
core->cpu->GetMem().mmio.si.pif.movie.GetFilename());
}
void EmuThread::SetRender(const bool v) const noexcept { core->render = v; }
void EmuThread::Reset() const noexcept {
core->pause = true;
core->Stop();