From d63a6baa5d9948e39cce8444486f67be1383c93b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 18:02:27 +0200 Subject: [PATCH] - removed the 'caller' parameter from the CCMD dispatcher. This can never be anything but players[consoleplayer].mo, so there is no need to pass it through the interface. --- src/console/c_cmds.cpp | 5 ++--- src/console/c_dispatch.cpp | 18 +++++++++--------- src/console/c_dispatch.h | 18 +++++++++--------- src/g_dumpinfo.cpp | 2 +- src/g_game.cpp | 25 +++++++++++++------------ 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/console/c_cmds.cpp b/src/console/c_cmds.cpp index 0c3ee4bc1d..b768b0d20a 100644 --- a/src/console/c_cmds.cpp +++ b/src/console/c_cmds.cpp @@ -354,14 +354,13 @@ CCMD (hxvisit) CCMD (changemap) { - if (who == NULL || !usergame) + if (!players[consoleplayer].mo || !usergame) { Printf ("Use the map command when not in a game.\n"); return; } - AActor* user = (AActor*)who; - if (!players[user->player - players].settings_controller && netgame) + if (!players[consoleplayer].settings_controller && netgame) { Printf ("Only setting controllers can change the map.\n"); return; diff --git a/src/console/c_dispatch.cpp b/src/console/c_dispatch.cpp index 3315db25b6..86d3837b15 100644 --- a/src/console/c_dispatch.cpp +++ b/src/console/c_dispatch.cpp @@ -123,7 +123,7 @@ public: if (Text.IsNotEmpty() && Command != nullptr) { FCommandLine args(Text); - Command->Run(args, players[consoleplayer].mo, 0); + Command->Run(args, 0); } return true; } @@ -298,7 +298,7 @@ void C_DoCommand (const char *cmd, int keynum) ) { FCommandLine args (beg); - com->Run (args, players[consoleplayer].mo, keynum); + com->Run (args, keynum); } else { @@ -525,12 +525,12 @@ FConsoleCommand::~FConsoleCommand () delete[] m_Name; } -void FConsoleCommand::Run (FCommandLine &argv, void *who, int key) +void FConsoleCommand::Run(FCommandLine &argv, int key) { - m_RunFunc (argv, who, key); + m_RunFunc (argv, key); } -void FUnsafeConsoleCommand::Run (FCommandLine &args, void *instigator, int key) +void FUnsafeConsoleCommand::Run(FCommandLine &args, int key) { if (UnsafeExecutionContext) { @@ -538,7 +538,7 @@ void FUnsafeConsoleCommand::Run (FCommandLine &args, void *instigator, int key) return; } - FConsoleCommand::Run (args, instigator, key); + FConsoleCommand::Run (args, key); } FConsoleAlias::FConsoleAlias (const char *name, const char *command, bool noSave) @@ -948,7 +948,7 @@ bool FConsoleAlias::IsAlias () return true; } -void FConsoleAlias::Run (FCommandLine &args, void *who, int key) +void FConsoleAlias::Run (FCommandLine &args, int key) { if (bRunning) { @@ -1011,10 +1011,10 @@ void FConsoleAlias::SafeDelete () } } -void FUnsafeConsoleAlias::Run (FCommandLine &args, void *instigator, int key) +void FUnsafeConsoleAlias::Run (FCommandLine &args, int key) { UnsafeExecutionScope scope; - FConsoleAlias::Run(args, instigator, key); + FConsoleAlias::Run(args, key); } void FExecList::AddCommand(const char *cmd, const char *file) diff --git a/src/console/c_dispatch.h b/src/console/c_dispatch.h index ee40da2c77..bd3e4da0e8 100644 --- a/src/console/c_dispatch.h +++ b/src/console/c_dispatch.h @@ -86,7 +86,7 @@ void C_ClearAliases (); FString BuildString (int argc, FString *argv); class AActor; -typedef void (*CCmdRun) (FCommandLine &argv, void *instigator, int key); +typedef void (*CCmdRun) (FCommandLine &argv, int key); class FConsoleCommand { @@ -96,7 +96,7 @@ public: virtual bool IsAlias (); void PrintCommand(); - virtual void Run (FCommandLine &args, void *instigator, int key); + virtual void Run (FCommandLine &args, int key); static FConsoleCommand* FindByName (const char* name); FConsoleCommand *m_Next, **m_Prev; @@ -113,9 +113,9 @@ protected: }; #define CCMD(n) \ - void Cmd_##n (FCommandLine &, void *, int key); \ + void Cmd_##n (FCommandLine &, int key); \ FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \ - void Cmd_##n (FCommandLine &argv, void *who, int key) + void Cmd_##n (FCommandLine &argv, int key) class FUnsafeConsoleCommand : public FConsoleCommand { @@ -125,13 +125,13 @@ public: { } - virtual void Run (FCommandLine &args, void *instigator, int key) override; + virtual void Run (FCommandLine &args, int key) override; }; #define UNSAFE_CCMD(n) \ - static void Cmd_##n (FCommandLine &, void *, int key); \ + static void Cmd_##n (FCommandLine &, int key); \ static FUnsafeConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \ - void Cmd_##n (FCommandLine &argv, void *who, int key) + void Cmd_##n (FCommandLine &argv, int key) const int KEY_DBLCLICKED = 0x8000; @@ -140,7 +140,7 @@ class FConsoleAlias : public FConsoleCommand public: FConsoleAlias (const char *name, const char *command, bool noSave); ~FConsoleAlias (); - void Run (FCommandLine &args, void *instigator, int key); + void Run (FCommandLine &args, int key); bool IsAlias (); void PrintAlias (); void Archive (FConfigFile *f); @@ -161,7 +161,7 @@ public: { } - virtual void Run (FCommandLine &args, void *instigator, int key) override; + virtual void Run (FCommandLine &args, int key) override; }; diff --git a/src/g_dumpinfo.cpp b/src/g_dumpinfo.cpp index 7c82682dd9..1200debba2 100644 --- a/src/g_dumpinfo.cpp +++ b/src/g_dumpinfo.cpp @@ -121,7 +121,7 @@ CCMD (countdecals) CCMD (spray) { - if (who == NULL || argv.argc() < 2) + if (players[consoleplayer].mo == NULL || argv.argc() < 2) { Printf ("Usage: spray \n"); return; diff --git a/src/g_game.cpp b/src/g_game.cpp index 719420b030..06fb928e87 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -423,11 +423,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, DisplayNameTag, DisplayNameTag) CCMD (invnext) { - if (who != NULL) + if (players[consoleplayer].mo != nullptr) { IFVM(PlayerPawn, InvNext) { - VMValue param = who; + VMValue param = players[consoleplayer].mo; VMCall(func, ¶m, 1, nullptr, 0); } } @@ -435,11 +435,11 @@ CCMD (invnext) CCMD(invprev) { - if (who != NULL) + if (players[consoleplayer].mo != nullptr) { IFVM(PlayerPawn, InvPrev) { - VMValue param = who; + VMValue param = players[consoleplayer].mo; VMCall(func, ¶m, 1, nullptr, 0); } } @@ -470,9 +470,9 @@ CCMD(invquery) CCMD (use) { - if (argv.argc() > 1 && who != NULL) + if (argv.argc() > 1 && players[consoleplayer].mo != NULL) { - SendItemUse = ((AActor*)who)->FindInventory(argv[1]); + SendItemUse = players[consoleplayer].mo->FindInventory(argv[1]); } } @@ -493,19 +493,19 @@ CCMD (weapdrop) CCMD (drop) { - if (argv.argc() > 1 && who != NULL) + if (argv.argc() > 1 && players[consoleplayer].mo != NULL) { - SendItemDrop = ((AActor*)who)->FindInventory(argv[1]); + SendItemDrop = players[consoleplayer].mo->FindInventory(argv[1]); SendItemDropAmount = argv.argc() > 2 ? atoi(argv[2]) : -1; } } CCMD (useflechette) { - if (who == nullptr) return; - IFVIRTUALPTRNAME(((AActor*)who), NAME_PlayerPawn, GetFlechetteItem) + if (players[consoleplayer].mo == nullptr) return; + IFVIRTUALPTRNAME(players[consoleplayer].mo, NAME_PlayerPawn, GetFlechetteItem) { - VMValue params[] = { who }; + VMValue params[] = { players[consoleplayer].mo }; AActor *cls; VMReturn ret((void**)&cls); VMCall(func, params, 1, &ret, 1); @@ -516,7 +516,8 @@ CCMD (useflechette) CCMD (select) { - auto user = ((AActor*)who); + if (!players[consoleplayer].mo) return; + auto user = players[consoleplayer].mo; if (argv.argc() > 1) { auto item = user->FindInventory(argv[1]);