Skip to content

Commit

Permalink
perf: add condition for updating the screen for slight GPU performanc…
Browse files Browse the repository at this point in the history
…e improvement
  • Loading branch information
Natan822 committed Sep 24, 2024
1 parent 62b27db commit f3a9308
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Chip8Emulator/src/Chip8.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Chip8.h"
#include <fstream>

bool screenUpdate = true;

Chip8::Chip8()
: randGen(std::chrono::system_clock::now().time_since_epoch().count())
{
Expand Down Expand Up @@ -331,6 +333,8 @@ void Chip8::OP_CXNN() {
}

void Chip8::OP_DXYN() {
screenUpdate = true;

uint8_t Vx = (opcode & 0x0F00u) >> 8u;
uint8_t Vy = (opcode & 0x00F0u) >> 4u;
uint8_t height = opcode & 0xFu;
Expand Down
2 changes: 2 additions & 0 deletions Chip8Emulator/src/Chip8.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const unsigned int FONTSET_SIZE = 80;
const unsigned int VIDEO_WIDTH = 64;
const unsigned int VIDEO_HEIGHT = 32;

extern bool screenUpdate;

class Chip8
{

Expand Down
6 changes: 5 additions & 1 deletion Chip8Emulator/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ int main(int argc, char* argv[]) {
{
lastCycleTime = currentCycleTime;
chip8.Cycle();
update(chip8.video, videoPitch);
if (screenUpdate)
{
update(chip8.video, videoPitch);
screenUpdate = false;
}
}
}
shutdown();
Expand Down

0 comments on commit f3a9308

Please sign in to comment.