Little optimization where I don't render if there was a colision. This is because chip-8 attempts to draw to detect colision, and then 'undoes' it, so no point in rendering that.

master
Zed A. Shaw 15 hours ago
parent 1264428606
commit 37a22f9966
  1. 5
      src/chip8.cpp
  2. 1
      src/chip8.hpp
  3. 2
      src/main.cpp

@ -288,8 +288,10 @@ void Chip8::OP_Dxyn() {
uint8_t yPos = registers[Vy] % VIDEO_HEIGHT; uint8_t yPos = registers[Vy] % VIDEO_HEIGHT;
registers[0xF] = 0; registers[0xF] = 0;
for(size_t row = 0; row < height; ++row) { for(size_t row = 0; row < height; ++row) {
uint8_t spriteByte = memory[index + row]; uint8_t spriteByte = memory[index + row];
for(size_t col = 0; col < 8; ++col) { for(size_t col = 0; col < 8; ++col) {
uint8_t spritePixel = spriteByte & (0x80u >> col); uint8_t spritePixel = spriteByte & (0x80u >> col);
uint32_t* screenPixel = &video[(yPos + row) * VIDEO_WIDTH + (xPos + col)]; uint32_t* screenPixel = &video[(yPos + row) * VIDEO_WIDTH + (xPos + col)];
@ -305,6 +307,9 @@ void Chip8::OP_Dxyn() {
} }
} }
} }
// don't bother rendering collision tests
needs_render = !registers[0xF];
} }
void Chip8::OP_Ex9E() { void Chip8::OP_Ex9E() {

@ -45,6 +45,7 @@ class Chip8 {
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E 0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F 0xF0, 0x80, 0xF0, 0x80, 0x80 // F
}; };
bool needs_render = true;
std::default_random_engine randGen; std::default_random_engine randGen;
std::uniform_int_distribution<uint8_t> randByte; std::uniform_int_distribution<uint8_t> randByte;

@ -99,6 +99,7 @@ int main(int argc, char* argv[]) {
chip8.Cycle(); chip8.Cycle();
cycle_stats.sample_time(t); cycle_stats.sample_time(t);
if(chip8.needs_render) {
auto ut = update_stats.time_start(); auto ut = update_stats.time_start();
display.update(chip8); display.update(chip8);
update_stats.sample_time(ut); update_stats.sample_time(ut);
@ -107,6 +108,7 @@ int main(int argc, char* argv[]) {
display.render(); display.render();
render_stats.sample_time(rt); render_stats.sample_time(rt);
} }
}
cycle_stats.dump("CYCLE TIMES"); cycle_stats.dump("CYCLE TIMES");
update_stats.dump("UPDATE TIMES"); update_stats.dump("UPDATE TIMES");

Loading…
Cancel
Save