]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Cache "pos" value in Game class
authorStephen Seo <seo.disparate@gmail.com>
Mon, 2 Jan 2023 05:30:02 +0000 (14:30 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 2 Jan 2023 05:30:02 +0000 (14:30 +0900)
src/game.cc
src/game.h

index 40476490c3bc7509be4cc41cf90af7f044a8b186..438c9c5c1a68537ad9414eb8a6145a1b31bf9954 100644 (file)
@@ -6,7 +6,7 @@
 // third party includes
 #include <raylib.h>
 
-Game::Game() : status("Unknown status") {}
+Game::Game() : status("Unknown status"), prevPos(0), cachedPos(0) {}
 
 void Game::update_state(const char *playerOne, const char *playerTwo,
                         const char *currentPlayer, char first_first,
@@ -29,6 +29,11 @@ void Game::update_state(const char *playerOne, const char *playerTwo,
   } else {
     status = "unknown player";
   }
+
+  if (cachedPos != pos) {
+    prevPos = cachedPos;
+    cachedPos = pos;
+  }
 }
 
 void Game::do_update() {
index 1e7451ccfe1395b1eaff955be38d089ef390c2c4..969b3ce37eed5fac32bca3b053b9b70b246fe010 100644 (file)
@@ -22,6 +22,8 @@ private:
   std::string playerOne;
   std::string playerTwo;
   std::string status;
+  int prevPos;
+  int cachedPos;
   bool isPlayerOne;
 
 };