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. 17
      src/main.cpp

@ -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

@ -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<float, std::chrono::milliseconds::period>(currentTime - lastCycleTime).count();
if (dt > cycleDelay)
{
lastCycleTime = currentTime;
auto t = cycle_stats.time_start();
chip8.Cycle();
cycle_stats.sample_time(t);
}
auto ut = update_stats.time_start();
display.update(chip8);

Loading…
Cancel
Save