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.

master
Zed A. Shaw 15 hours ago
parent 2fc7fbb788
commit 1264428606
  1. 4
      Makefile
  2. 23
      src/main.cpp

@ -15,13 +15,13 @@ debug_build:
meson compile -j 4 -C builddir meson compile -j 4 -C builddir
run: build run: build
./builddir/b8rk.exe 1 1 ./roms/test_opcode.ch8 ./builddir/b8rk.exe 1 1 ./roms/tetris.ch8
debug: build debug: build
gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe
debug_run: build 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: clean:
meson compile --clean -C builddir meson compile --clean -C builddir

@ -56,7 +56,7 @@ struct Display {
void update(Chip8& vm) { void update(Chip8& vm) {
handle_inputs(vm); handle_inputs(vm);
texture.update((uint8_t *)(vm.video)); texture.update((uint8_t *)(vm.video), {64, 32}, {0,0});
} }
void render() { void render() {
@ -70,7 +70,6 @@ struct Display {
} }
}; };
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if(argc != 4) { if(argc != 4) {
fmt::print("ERROR!"); fmt::print("ERROR!");
@ -78,18 +77,17 @@ int main(int argc, char* argv[]) {
} }
int videoScale = std::stoi(argv[1]); int videoScale = std::stoi(argv[1]);
int cycleDelay = std::stoi(argv[2]); int framerate = std::stoi(argv[2]);
std::string romFilename{argv[3]}; std::string romFilename{argv[3]};
Chip8 chip8; Chip8 chip8;
chip8.LoadROM(romFilename); chip8.LoadROM(romFilename);
int videoPitch = sizeof(chip8.video[0]) * VIDEO_WIDTH; 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"}; sf::RenderWindow window{sf::VideoMode({1280, 720}), "Chip8 Emulator"};
window.setFramerateLimit(60); window.setFramerateLimit(framerate);
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(false);
Display display{window, {0, 0}, {1000, 1000}}; Display display{window, {0, 0}, {1000, 1000}};
Stats cycle_stats; Stats cycle_stats;
@ -97,16 +95,9 @@ int main(int argc, char* argv[]) {
Stats update_stats; Stats update_stats;
while (display.active()) { while (display.active()) {
auto currentTime = std::chrono::high_resolution_clock::now(); auto t = cycle_stats.time_start();
float dt = std::chrono::duration<float, std::chrono::milliseconds::period>(currentTime - lastCycleTime).count(); chip8.Cycle();
cycle_stats.sample_time(t);
if (dt > cycleDelay)
{
lastCycleTime = currentTime;
auto t = cycle_stats.time_start();
chip8.Cycle();
cycle_stats.sample_time(t);
}
auto ut = update_stats.time_start(); auto ut = update_stats.time_start();
display.update(chip8); display.update(chip8);

Loading…
Cancel
Save