From: Stephen Seo Date: Tue, 14 Mar 2023 10:19:47 +0000 (+0900) Subject: Use latest version of Rune stuff X-Git-Url: https://git.seodisparate.com/stephenseo/LD53?a=commitdiff_plain;h=9c32c31dcc6ad9ab0580fe7f88348c9af5c6b71a;p=RockPaperScissorsDuel Use latest version of Rune stuff Also impl. use of Game Over with explicit winner/loser. --- diff --git a/src/3d_renderer.cc b/src/3d_renderer.cc index d7ec4cc..4effd7f 100644 --- a/src/3d_renderer.cc +++ b/src/3d_renderer.cc @@ -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); diff --git a/src/3d_renderer.h b/src/3d_renderer.h index c47dc1f..848bcce 100644 --- a/src/3d_renderer.h +++ b/src/3d_renderer.h @@ -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; diff --git a/src/game_renderer.h b/src/game_renderer.h index 31197c5..a3d7752 100644 --- a/src/game_renderer.h +++ b/src/game_renderer.h @@ -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; diff --git a/src/main.cc b/src/main.cc index 99f31b0..fcf25e2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; } diff --git a/wasm_build/client.js b/wasm_build/client.js index 65ae04c..c2ea3c5 100644 --- a/wasm_build/client.js +++ b/wasm_build/client.js @@ -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]); } }, }); diff --git a/wasm_build/custom_shell.html b/wasm_build/custom_shell.html index 30846cf..7c621a6 100644 --- a/wasm_build/custom_shell.html +++ b/wasm_build/custom_shell.html @@ -28,7 +28,7 @@ - + diff --git a/wasm_build/logic.js b/wasm_build/logic.js index c123121..2588ed6 100644 --- a/wasm_build/logic.js +++ b/wasm_build/logic.js @@ -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;