From 866d1439306d7736f571c003fa94814e57e1c43b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 7 Feb 2019 16:54:03 +0000 Subject: [PATCH] Move Pause Toggle into the GameAction framework --- src/openrct2-ui/windows/TopToolbar.cpp | 4 ++- src/openrct2/Game.cpp | 16 +-------- src/openrct2/Game.h | 3 +- .../actions/GameActionRegistration.cpp | 2 ++ src/openrct2/actions/PauseToggleAction.hpp | 35 +++++++++++++++++++ src/openrct2/network/Network.cpp | 10 ++++-- 6 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 src/openrct2/actions/PauseToggleAction.hpp diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 5e3c2d92f3..48280cd28b 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -337,7 +338,8 @@ static void window_top_toolbar_mouseup(rct_window* w, rct_widgetindex widgetInde case WIDX_PAUSE: if (network_get_mode() != NETWORK_MODE_CLIENT) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + auto pauseToggleAction = PauseToggleAction(); + GameActions::Execute(&pauseToggleAction); } break; case WIDX_ZOOM_OUT: diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index a65150bd1d..cfd351ae88 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -881,20 +881,6 @@ bool game_is_not_paused() return gGamePaused == 0; } -/** - * - * rct2: 0x00667C15 - */ -void game_pause_toggle( - [[maybe_unused]] int32_t* eax, int32_t* ebx, [[maybe_unused]] int32_t* ecx, [[maybe_unused]] int32_t* edx, - [[maybe_unused]] int32_t* esi, [[maybe_unused]] int32_t* edi, [[maybe_unused]] int32_t* ebp) -{ - if (*ebx & GAME_COMMAND_FLAG_APPLY) - pause_toggle(); - - *ebx = 0; -} - /** * * rct2: 0x0066DB5F @@ -1456,7 +1442,7 @@ void game_load_or_quit_no_save_prompt() GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { nullptr, nullptr, - game_pause_toggle, + nullptr, game_command_place_track, game_command_remove_track, game_load_or_quit, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index fff8defaa9..677969e457 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -20,7 +20,7 @@ enum GAME_COMMAND { GAME_COMMAND_SET_RIDE_APPEARANCE, // GA GAME_COMMAND_SET_LAND_HEIGHT, // GA - GAME_COMMAND_TOGGLE_PAUSE, + GAME_COMMAND_TOGGLE_PAUSE, // GA GAME_COMMAND_PLACE_TRACK, GAME_COMMAND_REMOVE_TRACK, GAME_COMMAND_LOAD_OR_QUIT, @@ -176,7 +176,6 @@ void game_log_multiplayer_command(int command, const int* eax, const int* ebx, c void game_load_or_quit_no_save_prompt(); void load_from_sv6(const char* path); void game_load_init(); -void game_pause_toggle(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void pause_toggle(); bool game_is_paused(); bool game_is_not_paused(); diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index 5367f678a8..996dbb9c37 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -20,6 +20,7 @@ #include "ParkSetLoanAction.hpp" #include "ParkSetNameAction.hpp" #include "ParkSetResearchFundingAction.hpp" +#include "PauseToggleAction.hpp" #include "PlaceParkEntranceAction.hpp" #include "PlacePeepSpawnAction.hpp" #include "RideCreateAction.hpp" @@ -73,5 +74,6 @@ namespace GameActions Register(); Register(); Register(); + Register(); } } // namespace GameActions diff --git a/src/openrct2/actions/PauseToggleAction.hpp b/src/openrct2/actions/PauseToggleAction.hpp new file mode 100644 index 0000000000..ced370e417 --- /dev/null +++ b/src/openrct2/actions/PauseToggleAction.hpp @@ -0,0 +1,35 @@ +/***************************************************************************** + * Copyright (c) 2014-2018 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "GameAction.h" + + +DEFINE_GAME_ACTION(PauseToggleAction, GAME_COMMAND_TOGGLE_PAUSE, GameActionResult) +{ +public: + PauseToggleAction(){} + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + GameActionResult::Ptr Query() const override + { + return std::make_unique(); + } + + GameActionResult::Ptr Execute() const override + { + pause_toggle(); + return std::make_unique(); + } +}; diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 852f90e517..3f8efa9b14 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -42,6 +42,7 @@ static int32_t _pickup_peep_old_x = LOCATION_NULL; # include "../ParkImporter.h" # include "../Version.h" # include "../actions/GameAction.h" +# include "../actions/PauseToggleAction.hpp" # include "../config/Config.h" # include "../core/Console.hpp" # include "../core/FileStream.hpp" @@ -622,7 +623,8 @@ bool Network::BeginServer(uint16_t port, const char* address) if (gConfigNetwork.pause_server_if_no_clients) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + auto pauseToggleAction = PauseToggleAction(); + GameActions::Execute(&pauseToggleAction); } return true; @@ -1986,7 +1988,8 @@ void Network::AddClient(std::unique_ptr&& socket) { if (gConfigNetwork.pause_server_if_no_clients && game_is_paused()) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + auto pauseToggleAction = PauseToggleAction(); + GameActions::Execute(&pauseToggleAction); } // Log connection info. @@ -2044,7 +2047,8 @@ void Network::RemoveClient(std::unique_ptr& connection) client_connection_list.remove(connection); if (gConfigNetwork.pause_server_if_no_clients && game_is_not_paused() && client_connection_list.size() == 0) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_TOGGLE_PAUSE, 0, 0); + auto pauseToggleAction = PauseToggleAction(); + GameActions::Execute(&pauseToggleAction); } Server_Send_PLAYERLIST(); }