From b5d636d5ef53d00f3a98d3ada4db37b2f548ff88 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 4 Jan 2023 19:44:44 +0900 Subject: [PATCH] Rename "Game" to "BasicRenderer" --- CMakeLists.txt | 2 +- src/{game.cc => basic_renderer.cc} | 46 ++++++++++++++++-------------- src/{game.h => basic_renderer.h} | 8 +++--- src/main.cc | 4 +-- wasm_build/Makefile | 4 +-- 5 files changed, 33 insertions(+), 31 deletions(-) rename src/{game.cc => basic_renderer.cc} (93%) rename src/{game.h => basic_renderer.h} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 520559e..6581efe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() set(RPSDuelNative_SOURCES src/main.cc - src/game.cc + src/basic_renderer.cc src/ems.cc src/helpers.cc ) diff --git a/src/game.cc b/src/basic_renderer.cc similarity index 93% rename from src/game.cc rename to src/basic_renderer.cc index 1aaaf02..34a30ed 100644 --- a/src/game.cc +++ b/src/basic_renderer.cc @@ -1,4 +1,4 @@ -#include "game.h" +#include "basic_renderer.h" // standard library includes #include @@ -12,7 +12,7 @@ #include "ems.h" #include "helpers.h" -Game::Game() +BasicRenderer::BasicRenderer() : spriteSheet(std::nullopt), status("Unknown status"), readyTimer(0.0F), resultsTimer(RESULTS_TIMER_MAX), scoreChangeTimer(SCORE_CHANGE_TIMER_MAX), requestTimer(REQUEST_TIMER_MAX), prevPos(0), cachedPos(0), @@ -28,11 +28,12 @@ Game::Game() opponentPicked[2] = 0; } -void Game::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, int pos, int matchup_idx) { +void BasicRenderer::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, int pos, int matchup_idx) { // TODO DEBUG // if (std::strcmp(playerOne, currentPlayer) == 0) { // std::clog << "update_state:\n" @@ -118,14 +119,14 @@ void Game::update_state(const char *playerOne, const char *playerTwo, } } -void Game::do_update() { +void BasicRenderer::do_update() { update_impl(); draw_impl(); } -void Game::screen_size_changed() { flags.set(13); } +void BasicRenderer::screen_size_changed() { flags.set(13); } -void Game::update_impl() { +void BasicRenderer::update_impl() { const float dt = GetFrameTime(); if (flags.test(13)) { @@ -399,7 +400,7 @@ void Game::update_impl() { } } -void Game::draw_impl() { +void BasicRenderer::draw_impl() { if (flags.test(2)) { BeginDrawing(); ClearBackground(BLACK); @@ -498,9 +499,9 @@ void Game::draw_impl() { EndDrawing(); } -void Game::draw_choice(const unsigned int idx, const char choice, - const bool using_triple, const float y, - const Color color) { +void BasicRenderer::draw_choice(const unsigned int idx, const char choice, + const bool using_triple, const float y, + const Color color) { if (!spriteSheet.has_value()) { return; } @@ -540,8 +541,8 @@ void Game::draw_choice(const unsigned int idx, const char choice, } } -void Game::draw_qm(const unsigned int idx, const bool using_triple, - const float y, const Color color) { +void BasicRenderer::draw_qm(const unsigned int idx, const bool using_triple, + const float y, const Color color) { if (!spriteSheet.has_value()) { return; } @@ -555,8 +556,9 @@ void Game::draw_qm(const unsigned int idx, const bool using_triple, {x, y, width, width}, {0.0F, 0.0F}, 0.0F, color); } -void Game::draw_helper_coord(float *x, float *width, const unsigned int idx, - const bool using_triple) { +void BasicRenderer::draw_helper_coord(float *x, float *width, + const unsigned int idx, + const bool using_triple) { if (x) { *x = 0.0F; *width = ICON_MAX_WIDTH; @@ -608,17 +610,17 @@ void Game::draw_helper_coord(float *x, float *width, const unsigned int idx, } } -bool Game::is_choices_set() const { +bool BasicRenderer::is_choices_set() const { return picked[0] != 0 && picked[1] != 0 && picked[2] != 0; } -bool Game::is_opponent_choices_set() const { +bool BasicRenderer::is_opponent_choices_set() const { return opponentPicked[0] != 0 && opponentPicked[1] != 0 && opponentPicked[2] != 0 && opponentPicked[0] != '?' && opponentPicked[1] != '?' && opponentPicked[2] != '?'; } -void Game::draw_score() const { +void BasicRenderer::draw_score() const { char buf[6]; if (isPlayerOne || flags.test(2)) { @@ -648,7 +650,7 @@ void Game::draw_score() const { } } -void Game::draw_reveal_choices(const char p[3], const float y) { +void BasicRenderer::draw_reveal_choices(const char p[3], const float y) { float ratio = 1.0F - resultsTimer / RESULTS_TIMER_MAX; char otherPicked = Helpers::isValidChoice(p[0]) ? p[0] : '?'; if (!flags.test(6)) { diff --git a/src/game.h b/src/basic_renderer.h similarity index 92% rename from src/game.h rename to src/basic_renderer.h index 9f89bb2..6735a2c 100644 --- a/src/game.h +++ b/src/basic_renderer.h @@ -1,5 +1,5 @@ -#ifndef ROCK_PAPER_SCISSORS_DUEL_GAME_H_ -#define ROCK_PAPER_SCISSORS_DUEL_GAME_H_ +#ifndef ROCK_PAPER_SCISSORS_DUEL_BASIC_RENDERER_H_ +#define ROCK_PAPER_SCISSORS_DUEL_BASIC_RENDERER_H_ // standard library includes #include @@ -12,9 +12,9 @@ // local includes #include "game_renderer.h" -class Game : public GameRenderer { +class BasicRenderer : public GameRenderer { public: - Game(); + BasicRenderer(); void update_state(const char *playerOne, const char *playerTwo, const char *currentPlayer, char first_first, diff --git a/src/main.cc b/src/main.cc index 5bfe8f1..506e0aa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -15,8 +15,8 @@ #include // local includes +#include "basic_renderer.h" #include "constants.h" -#include "game.h" #include "game_renderer.h" #ifdef __EMSCRIPTEN__ @@ -59,7 +59,7 @@ int main() { InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "RPSDuel_Native"); #endif - std::unique_ptr renderer = std::make_unique(); + std::unique_ptr renderer = std::make_unique(); #ifdef __EMSCRIPTEN__ global_game_ptr = renderer.get(); diff --git a/wasm_build/Makefile b/wasm_build/Makefile index 1871321..40ae8bc 100644 --- a/wasm_build/Makefile +++ b/wasm_build/Makefile @@ -7,13 +7,13 @@ endif SOURCES = \ ../src/main.cc \ ../src/ems.cc \ - ../src/game.cc \ + ../src/basic_renderer.cc \ ../src/helpers.cc HEADERS = \ ../src/constants.h \ ../src/ems.h \ - ../src/game.h \ + ../src/basic_renderer.h \ ../src/helpers.h \ ../src/game_renderer.h -- 2.49.0