1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Remove game command callback

This commit is contained in:
duncanspumpkin
2019-06-20 19:50:55 +01:00
parent 6bd298b3a3
commit e99c51d23c
3 changed files with 2 additions and 105 deletions

View File

@@ -85,21 +85,6 @@ uint8_t gUnk141F568;
uint32_t gCurrentTicks;
uint32_t gCurrentRealTimeTicks;
// clang-format off
GAME_COMMAND_CALLBACK_POINTER * game_command_callback = nullptr;
static GAME_COMMAND_CALLBACK_POINTER * const game_command_callback_table[] = {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr
};
// clang-format on
int32_t game_command_playerid = -1;
rct_string_id gGameCommandErrorTitle;
@@ -109,27 +94,6 @@ rct_string_id gErrorStringId;
using namespace OpenRCT2;
int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback)
{
for (uint32_t i = 0; i < std::size(game_command_callback_table); i++)
{
if (game_command_callback_table[i] == callback)
{
return i;
}
}
return 0;
}
GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(uint32_t index)
{
if (index < std::size(game_command_callback_table))
{
return game_command_callback_table[index];
}
return nullptr;
}
void game_increase_game_speed()
{
gGameSpeed = std::min(gConfigGeneral.debugging_tools ? 5 : 4, gGameSpeed + 1);
@@ -413,16 +377,6 @@ int32_t game_do_command_p(
game_command_playerid = network_get_current_player_id();
}
// Log certain commands if we are in multiplayer and logging is enabled
bool serverLog = (network_get_mode() == NETWORK_MODE_SERVER) && gGameCommandNestLevel == 1
&& gConfigNetwork.log_server_actions;
bool clientLog = (network_get_mode() == NETWORK_MODE_CLIENT) && (flags & GAME_COMMAND_FLAG_NETWORKED)
&& gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions;
if (serverLog || clientLog)
{
game_log_multiplayer_command(command, eax, ebx, ecx, edx, edi, ebp);
}
*ebx &= ~GAME_COMMAND_FLAG_APPLY;
// Make sure the camera position won't change if the command skips setting them.
@@ -461,12 +415,11 @@ int32_t game_do_command_p(
&& gGameCommandNestLevel == 1) /* Send only top-level commands */
{
network_send_gamecmd(
*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, game_command_callback_get_index(game_command_callback));
*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, 0);
if (network_get_mode() == NETWORK_MODE_CLIENT)
{
// Client sent the command to the server, do not run it locally, just return. It will run when server
// sends it.
game_command_callback = nullptr;
// Decrement nest count
gGameCommandNestLevel--;
return cost;
@@ -489,21 +442,8 @@ int32_t game_do_command_p(
if (recordCommand && gGameCommandNestLevel == 1)
{
int32_t callback = game_command_callback_get_index(game_command_callback);
replayManager->AddGameCommand(
gCurrentTicks, *eax, original_ebx, *ecx, original_edx, original_esi, original_edi, original_ebp,
callback);
}
}
// Do the callback (required for multiplayer to work correctly), but only for top level commands
if (gGameCommandNestLevel == 1)
{
if (game_command_callback && !(flags & GAME_COMMAND_FLAG_GHOST))
{
game_command_callback(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp);
game_command_callback = nullptr;
gCurrentTicks, *eax, original_ebx, *ecx, original_edx, original_esi, original_edi, original_ebp, 0);
}
}
@@ -552,9 +492,6 @@ int32_t game_do_command_p(
// Decrement nest count
gGameCommandNestLevel--;
// Clear the game command callback to prevent the next command triggering it
game_command_callback = nullptr;
// Show error window
if (gGameCommandNestLevel == 0 && (flags & GAME_COMMAND_FLAG_APPLY) && gUnk141F568 == gUnk13CA740
&& !(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(flags & GAME_COMMAND_FLAG_NETWORKED)
@@ -566,34 +503,6 @@ int32_t game_do_command_p(
return MONEY32_UNDEFINED;
}
void game_log_multiplayer_command(int command, const int* eax, const int* ebx, const int* ecx, int* edx, int* edi, int* ebp)
{
// Get player name
const char* player_name = "localhost";
int player_index = network_get_player_index(game_command_playerid);
if (player_index != -1)
{
player_name = network_get_player_name(player_index);
}
char log_msg[256];
if (command == GAME_COMMAND_DEMOLISH_RIDE && (*ebp == 1 || *ebp == 0))
{ // ebp is 1 if command comes from ride window prompt, so we don't log "demolishing" ride previews
// Get ride name
Ride* ride = get_ride(*edx);
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
char* args[2] = {
(char*)player_name,
ride_name,
};
format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args);
network_append_server_log(log_msg);
}
}
void pause_toggle()
{
gGamePaused ^= GAME_PAUSED_NORMAL;

View File

@@ -130,12 +130,7 @@ enum
using GAME_COMMAND_POINTER = void(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
using GAME_COMMAND_CALLBACK_POINTER = void(
int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp);
extern GAME_COMMAND_CALLBACK_POINTER* game_command_callback;
int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback);
GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(uint32_t index);
extern int32_t game_command_playerid;
extern rct_string_id gGameCommandErrorTitle;
@@ -175,8 +170,6 @@ int32_t game_do_command(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int3
int32_t game_do_command_p(
uint32_t command, int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void game_log_multiplayer_command(int command, const int* eax, const int* ebx, const int* ecx, int* edx, int* edi, int* ebp);
void game_load_or_quit_no_save_prompt();
void load_from_sv6(const char* path);
void game_load_init();

View File

@@ -2145,11 +2145,6 @@ void Network::ProcessGameCommands()
}
else
{
if (GetPlayerID() == gc.playerid)
{
game_command_callback = game_command_callback_get_callback(gc.callback);
}
game_command_playerid = gc.playerid;
int32_t command = gc.esi;