From 12644286068e0d06948bcebb31ba768046f77f1e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 18 May 2026 12:13:02 -0400 Subject: [PATCH] Turns out the 'performance problem' is just me setting the framerate. Weird thing though is setting that also changes how SFML updates the textures when doing texture.update(). Need to investigate why. --- Makefile | 4 ++-- src/main.cpp | 23 +++++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index b1ad697..ceebef9 100644 --- a/Makefile +++ b/Makefile @@ -15,13 +15,13 @@ debug_build: meson compile -j 4 -C builddir run: build - ./builddir/b8rk.exe 1 1 ./roms/test_opcode.ch8 + ./builddir/b8rk.exe 1 1 ./roms/tetris.ch8 debug: build gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe debug_run: build - gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/b8rk.exe 1 1 ./roms/test_opcode.ch8 + gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/b8rk.exe 1 1 ./roms/tetris.ch8 clean: meson compile --clean -C builddir diff --git a/src/main.cpp b/src/main.cpp index 03777d8..ecdc702 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,7 @@ struct Display { void update(Chip8& vm) { handle_inputs(vm); - texture.update((uint8_t *)(vm.video)); + texture.update((uint8_t *)(vm.video), {64, 32}, {0,0}); } void render() { @@ -70,7 +70,6 @@ struct Display { } }; - int main(int argc, char* argv[]) { if(argc != 4) { fmt::print("ERROR!"); @@ -78,18 +77,17 @@ int main(int argc, char* argv[]) { } int videoScale = std::stoi(argv[1]); - int cycleDelay = std::stoi(argv[2]); + int framerate = std::stoi(argv[2]); std::string romFilename{argv[3]}; Chip8 chip8; chip8.LoadROM(romFilename); int videoPitch = sizeof(chip8.video[0]) * VIDEO_WIDTH; - auto lastCycleTime = std::chrono::high_resolution_clock::now(); sf::RenderWindow window{sf::VideoMode({1280, 720}), "Chip8 Emulator"}; - window.setFramerateLimit(60); - window.setVerticalSyncEnabled(true); + window.setFramerateLimit(framerate); + window.setVerticalSyncEnabled(false); Display display{window, {0, 0}, {1000, 1000}}; Stats cycle_stats; @@ -97,16 +95,9 @@ int main(int argc, char* argv[]) { Stats update_stats; while (display.active()) { - auto currentTime = std::chrono::high_resolution_clock::now(); - float dt = std::chrono::duration(currentTime - lastCycleTime).count(); - - if (dt > cycleDelay) - { - lastCycleTime = currentTime; - auto t = cycle_stats.time_start(); - chip8.Cycle(); - cycle_stats.sample_time(t); - } + auto t = cycle_stats.time_start(); + chip8.Cycle(); + cycle_stats.sample_time(t); auto ut = update_stats.time_start(); display.update(chip8);