]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Use latest version of Rune stuff
authorStephen Seo <seo.disparate@gmail.com>
Tue, 14 Mar 2023 10:19:47 +0000 (19:19 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 14 Mar 2023 10:19:47 +0000 (19:19 +0900)
Also impl. use of Game Over with explicit winner/loser.

src/3d_renderer.cc
src/3d_renderer.h
src/game_renderer.h
src/main.cc
wasm_build/client.js
wasm_build/custom_shell.html
wasm_build/logic.js

index d7ec4cc06c5dd064255a1a75cd9f4a9d2a26f4b5..4effd7f0065d965b09a375b7198d2bdb2fdedb1e 100644 (file)
@@ -119,14 +119,12 @@ Renderer3D::~Renderer3D() {
   UnloadModel(scissors_model);
 }
 
-void Renderer3D::update_state(const char *playerOne, const char *playerTwo,
-                              const char *currentPlayer, char first_first,
-                              char first_second, char first_third,
-                              char second_first, char second_second,
-                              char second_third, bool first_ready,
-                              bool second_ready, bool first_matchup_done,
-                              bool second_matchup_done, int pos, int prev_pos,
-                              bool gameover_called, bool matchup_started) {
+void Renderer3D::update_state(
+    const char *playerOne, const char *playerTwo, const char *currentPlayer,
+    char first_first, char first_second, char first_third, char second_first,
+    char second_second, char second_third, bool first_ready, bool second_ready,
+    bool first_matchup_done, bool second_matchup_done, int pos, int prev_pos,
+    bool gameover_called, bool matchup_started, const char *currentName) {
   if (std::strcmp(playerOne, currentPlayer) == 0) {
     flags.set(2);
     flags.reset(3);
@@ -138,6 +136,14 @@ void Renderer3D::update_state(const char *playerOne, const char *playerTwo,
     flags.set(3);
   }
 
+  // DEBUG
+  //if (flags.test(2)) {
+  //  std::cout << "Player one str is \"" << playerOne << "\"" << std::endl;
+  //} else {
+  //  std::cout << "Player two str is \"" << playerTwo << "\"" << std::endl;
+  //}
+  //std::cout << "Name is \"" << currentName << std::endl;
+
   flags.set(9, first_ready);
   flags.set(10, second_ready);
   flags.set(13, matchup_started);
index c47dc1f345bd3587fd2b63513f700f4750923f40..848bcce2d0ceba5f0550195db343f9045dc03b82 100644 (file)
@@ -32,7 +32,8 @@ class Renderer3D : public GameRenderer {
                     char second_second, char second_third, bool first_ready,
                     bool second_ready, bool first_matchup_done,
                     bool second_matchup_done, int pos, int prev_pos,
-                    bool gameover_called, bool matchup_started) override;
+                    bool gameover_called, bool matchup_started,
+                    const char *currentName) override;
 
   void do_update() override;
 
index 31197c50dbd2b0b524cd411cb5d70884192d2a03..a3d7752b8972344e89e88a0f34d742f60db8763b 100644 (file)
@@ -13,7 +13,8 @@ class GameRenderer {
                             char second_third, bool first_ready,
                             bool second_ready, bool first_matchup_done,
                             bool second_matchup_done, int pos, int prev_pos,
-                            bool gameover_called, bool matchup_started) = 0;
+                            bool gameover_called, bool matchup_started,
+                            const char *currentName) = 0;
 
   virtual void do_update() = 0;
 
index 99f31b08eba4a28acb389e4c991a79b93ff03f19..fcf25e2560ee932fe97a719a51f3d533530f7c20 100644 (file)
@@ -30,13 +30,13 @@ int EMSCRIPTEN_KEEPALIVE game_visual_update(
     char first_first, char first_second, char first_third, char second_first,
     char second_second, char second_third, bool first_ready, bool second_ready,
     bool first_matchup_done, bool second_matchup_done, int pos, int prev_pos,
-    bool gameover_called, bool matchup_started) {
+    bool gameover_called, bool matchup_started, const char *currentName) {
   ((GameRenderer *)global_game_ptr)
       ->update_state(playerOne, playerTwo, currentPlayer, first_first,
                      first_second, first_third, second_first, second_second,
                      second_third, first_ready, second_ready,
                      first_matchup_done, second_matchup_done, pos, prev_pos,
-                     gameover_called, matchup_started);
+                     gameover_called, matchup_started, currentName);
   return 0;
 }
 
index 65ae04c559d3b2b35033ff81defda6d0ee98fb58..c2ea3c5a50bc4d12f535bda25fed02255dc259fc 100644 (file)
@@ -1,6 +1,6 @@
 function do_rune_init() {
 Rune.initClient({
-    visualUpdate: ({ newGame, yourPlayerId}) => {
+    visualUpdate: ({ newGame, yourPlayerId, players}) => {
         const { player1, player2, first_choices, second_choices, ready, matchup_done, pos, prev_pos, gameover, gameover_called, matchup_started } = newGame;
 
         function is_choices_filled(choices) {
@@ -12,6 +12,11 @@ Rune.initClient({
             return true;
         }
 
+        let current_name = "spectator";
+        if (yourPlayerId !== undefined) {
+            current_name = players[yourPlayerId].displayName;
+        }
+
         if (is_choices_filled(first_choices) && is_choices_filled(second_choices)) {
             Module.ccall('game_visual_update',
                 'number',
@@ -20,7 +25,8 @@ Rune.initClient({
                     'number', 'number', 'number',
                     'boolean', 'boolean',
                     'boolean', 'boolean',
-                    'number', 'number', 'boolean', 'boolean'],
+                    'number', 'number', 'boolean', 'boolean',
+                    'string'],
                 [player1, player2,
                     yourPlayerId === undefined ? 'undefined' : yourPlayerId,
                     first_choices[0].charCodeAt(0),
@@ -31,7 +37,8 @@ Rune.initClient({
                     second_choices[2].charCodeAt(0),
                     ready[0], ready[1],
                     matchup_done[0], matchup_done[1],
-                    pos, prev_pos, gameover_called, matchup_started]);
+                    pos, prev_pos, gameover_called, matchup_started,
+                    current_name]);
         } else {
             Module.ccall('game_visual_update',
                 'number',
@@ -40,7 +47,8 @@ Rune.initClient({
                     'number', 'number', 'number',
                     'boolean', 'boolean',
                     'boolean', 'boolean',
-                    'number', 'number', 'boolean', 'boolean'],
+                    'number', 'number', 'boolean', 'boolean',
+                    'string'],
                 [player1, player2,
                     yourPlayerId === undefined ? 'undefined' : yourPlayerId,
                     '?'.charCodeAt(0),
@@ -51,7 +59,8 @@ Rune.initClient({
                     '?'.charCodeAt(0),
                     ready[0], ready[1],
                     matchup_done[0], matchup_done[1],
-                    pos, prev_pos, gameover_called, matchup_started]);
+                    pos, prev_pos, gameover_called, matchup_started,
+                    current_name]);
         }
     },
 });
index 30846cf2b181ddac2f4308bca6738ad36407722e..7c621a678d488955557046b4dd1deaca8167350b 100644 (file)
@@ -28,7 +28,7 @@
     </style>
   </head>
   <body>
-    <script src="https://cdn.jsdelivr.net/npm/rune-games-sdk@3/multiplayer.js"></script>
+    <script src="https://cdn.jsdelivr.net/npm/rune-games-sdk@4/multiplayer.js"></script>
     <script src="logic.js" defer></script>
     <script src="client.js" defer></script>
     <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
index c123121028df4add773c047fa2ff48e62f93f653..2588ed6fb4ec3da1328a01572b7c1d8bed81ad7e 100644 (file)
@@ -141,7 +141,14 @@ Rune.initLogic({
                 game.matchup_started = false;
                 if (game.gameover) {
                     game.gameover_called = true;
-                    Rune.gameOver();
+                    let p1_status = game.pos > 0 ? "WON" : "LOST";
+                    let p2_status = game.pos < 0 ? "WON" : "LOST";
+                    Rune.gameOver({
+                        players: {
+                            [game.player1]: p1_status,
+                            [game.player2]: p2_status,
+                        }
+                    });
                 }
 
                 game.ready[0] = false;