From cc718ee511748af3ada7e78a69061c15b5bc3b91 Mon Sep 17 00:00:00 2001 From: dr20ervin Date: Wed, 27 May 2026 00:18:54 +0300 Subject: [PATCH] Refactor global variable declarations and usage --- include/main.h | 16 ++++++++-------- src/game.cpp | 5 +++-- src/main.cpp | 11 ++++++++++- src/menu.cpp | 5 +++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/main.h b/include/main.h index c4d6ef7..d80130a 100644 --- a/include/main.h +++ b/include/main.h @@ -7,15 +7,15 @@ #include #include - // Global colors -Color Green = Color{ 38, 185, 154, 255 }; -Color Dark_Green = Color{ 20, 160, 133, 255 }; -Color Light_Green = Color{ 129, 204, 184, 255 }; -Color Yellow = Color{ 243, 213, 91, 255 }; +extern Color Green; +extern Color Dark_Green; +extern Color Light_Green; +extern Color Yellow; -// DevLog buffering & function prototype -std::vector logHistory; -std::mutex logMutex; +// DevLog buffering & global variables +extern std::vector logHistory; +extern std::mutex logMutex; +extern bool isConsoleVisible; void CustomLogCallback(int logLevel, const char* text, va_list args); diff --git a/src/game.cpp b/src/game.cpp index 62ad13c..3fab1fb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,4 +1,5 @@ #include "game.h" +#include "main.h" // Paddle implementation bool Paddle::Update() { @@ -321,7 +322,7 @@ void DrawGameOverState(const GameContext& ctx, int screenWidth, int screenHeight if (ctx.isMultiplayer) { if (ctx.score.player_score > ctx.score.player2_score) { winnerText = "PLAYER 1 WINS!"; - winnerColor = Color{ 38, 185, 154, 255 }; + winnerColor = Green; } else if (ctx.score.player2_score > ctx.score.player_score) { winnerText = "PLAYER 2 WINS!"; @@ -333,7 +334,7 @@ void DrawGameOverState(const GameContext& ctx, int screenWidth, int screenHeight else { if (ctx.score.player_score > ctx.score.cpu_score) { winnerText = "YOU WIN!"; - winnerColor = Color{ 38, 185, 154, 255 }; + winnerColor = Green; } else if (ctx.score.cpu_score > ctx.score.player_score) { winnerText = "CPU WINS!"; diff --git a/src/main.cpp b/src/main.cpp index 724a890..63ecadb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,13 +3,22 @@ #include "menu.h" #include "resource.h" +// Define global variables +Color Green = Color{ 38, 185, 154, 255 }; +Color Dark_Green = Color{ 20, 160, 133, 255 }; +Color Light_Green = Color{ 129, 204, 184, 255 }; +Color Yellow = Color{ 243, 213, 91, 255 }; + +std::vector logHistory; +std::mutex logMutex; +bool isConsoleVisible = false; + #ifdef _WIN32 #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") extern "C" { int __stdcall AllocConsole(); int __stdcall FreeConsole(); } -bool isConsoleVisible = false; #endif int main() { diff --git a/src/menu.cpp b/src/menu.cpp index 7e7b32d..4d30512 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -1,4 +1,5 @@ #include "menu.h" +#include "main.h" int Menu::Update() { // Menu navigation @@ -219,7 +220,7 @@ void DrawLobbyState(const GameContext& ctx, int screenWidth, int screenHeight) { DrawText("Press 'W' to toggle ready", p1X, p1Y + 75, 18, GRAY); if (ctx.p1Ready) { - DrawRectangle(p1X, p1Y + 115, 220, 50, GREEN); + DrawRectangle(p1X, p1Y + 115, 220, 50, Green); DrawText("READY", p1X + 110 - MeasureText("READY", 20)/2, p1Y + 130, 20, BLACK); } else { DrawRectangle(p1X, p1Y + 115, 220, 50, RED); @@ -234,7 +235,7 @@ void DrawLobbyState(const GameContext& ctx, int screenWidth, int screenHeight) { DrawText("Press 'UP' to toggle ready", p2X, p2Y + 75, 18, GRAY); if (ctx.p2Ready) { - DrawRectangle(p2X, p2Y + 115, 220, 50, GREEN); + DrawRectangle(p2X, p2Y + 115, 220, 50, Green); DrawText("READY", p2X + 110 - MeasureText("READY", 20)/2, p2Y + 130, 20, BLACK); } else { DrawRectangle(p2X, p2Y + 115, 220, 50, RED);