From 00ecea47aae68b747d3bb3c3800e8828cccaf423 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Aug 2020 20:44:37 +0200 Subject: [PATCH] - use CCMDs for input in Blood where appropriate. --- source/blood/src/blood.cpp | 27 +--- source/blood/src/blood.h | 25 +-- source/blood/src/controls.cpp | 148 +++++++----------- source/blood/src/misc.h | 1 + source/blood/src/view.h | 1 - .../static/filter/blood/engine/defbinds.txt | 12 +- .../static/filter/blood/engine/leftbinds.txt | 12 +- .../static/filter/blood/engine/origbinds.txt | 12 +- 8 files changed, 82 insertions(+), 156 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index b256dfcb4..51c45ae3f 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -752,7 +752,7 @@ void ClockStrobe() void ReadAllRFS(); static const char* actions[] = { - "Move_Forward", + "Move_Forward", "Move_Backward", "Turn_Left", "Turn_Right", @@ -771,43 +771,19 @@ static const char* actions[] = { "Strafe_Right", "Aim_Up", "Aim_Down", - "Weapon_1", - "Weapon_2", - "Weapon_3", - "Weapon_4", - "Weapon_5", - "Weapon_6", - "Weapon_7", - "Weapon_8", - "Weapon_9", - "Weapon_10", - "Inventory", - "Inventory_Left", - "Inventory_Right", - "Nightvision", - "MedKit", - "TurnAround", "SendMessage", "Map", "Shrink_Screen", "Enlarge_Screen", - "Center_View", - "Holster_Weapon", "Show_Opponents_Weapon", "Map_Follow_Mode", "See_Coop_View", "Mouse_Aiming", "Toggle_Crosshair", - "Next_Weapon", - "Previous_Weapon", "Dpad_Select", "Dpad_Aiming", "Third_Person_View", "Toggle_Crouch", - "CrystalBall", - "ProximityBombs", - "RemoteBombs", - "Jetpack" }; static void app_init() @@ -863,6 +839,7 @@ static void app_init() Printf("Initializing sound system\n"); sndInit(); registerosdcommands(); + registerinputcommands(); gChoke.sub_83ff0(518, sub_84230); if (bAddUserMap) diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index cb4bc5c6b..b71eec3a8 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -50,43 +50,19 @@ enum GameFunction_t gamefunc_Strafe_Right, gamefunc_Aim_Up, gamefunc_Aim_Down, - gamefunc_Weapon_1, - gamefunc_Weapon_2, - gamefunc_Weapon_3, - gamefunc_Weapon_4, - gamefunc_Weapon_5, - gamefunc_Weapon_6, - gamefunc_Weapon_7, - gamefunc_Weapon_8, - gamefunc_Weapon_9, - gamefunc_Weapon_10, - gamefunc_Inventory, - gamefunc_Inventory_Left, - gamefunc_Inventory_Right, - gamefunc_BeastVision, //Nightvision - gamefunc_MedKit, - gamefunc_TurnAround, gamefunc_SendMessage, gamefunc_Map, gamefunc_Shrink_Screen, gamefunc_Enlarge_Screen, - gamefunc_Center_View, - gamefunc_Holster_Weapon, gamefunc_Show_Opponents_Weapon, gamefunc_Map_Follow_Mode, gamefunc_See_Coop_View, gamefunc_Mouse_Aiming, gamefunc_Toggle_Crosshair, - gamefunc_Next_Weapon, - gamefunc_Previous_Weapon, gamefunc_Dpad_Select, gamefunc_Dpad_Aiming, gamefunc_Third_Person_View, gamefunc_Toggle_Crouch, - gamefunc_CrystalBall, - gamefunc_ProximityBombs, - gamefunc_RemoteBombs, - gamefunc_JumpBoots, NUM_ACTIONS }; @@ -149,6 +125,7 @@ struct GameInterface : ::GameInterface void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override; void QuitToTitle() override; FString GetCoordString() override; + void clearlocalinputstate() override; GameStats getStats() override; }; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 43dcff19f..83e99ae4d 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -43,6 +43,9 @@ GINPUT gInput, gNetInput; bool bSilentAim = false; int iTurnCount = 0; +static int WeaponToSend; +static KEYFLAGS BitsToSend; +static USEFLAGS UsesToSend; void ctrlInit(void) { @@ -116,6 +119,14 @@ void ctrlGetInput(void) if (gQuitRequest) gInput.keyFlags.quit = 1; + gInput.keyFlags.word |= BitsToSend.word; + gInput.useFlags.byte |= UsesToSend.byte; + gInput.newWeapon = WeaponToSend; + + BitsToSend.word = 0; + UsesToSend.byte = 0; + WeaponToSend = 0; + if (buttonMap.ButtonDown(gamefunc_Map)) { buttonMap.ClearButton(gamefunc_Map); @@ -179,17 +190,6 @@ void ctrlGetInput(void) if (gPlayer[myconnectindex].nextWeapon == 0) { - if (buttonMap.ButtonPressed(gamefunc_Next_Weapon)) - { - buttonMap.ClearButton(gamefunc_Next_Weapon); - gInput.keyFlags.nextWeapon = 1; - } - - if (buttonMap.ButtonPressed(gamefunc_Previous_Weapon)) - { - buttonMap.ClearButton(gamefunc_Previous_Weapon); - gInput.keyFlags.prevWeapon = 1; - } } if (buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon)) @@ -227,83 +227,6 @@ void ctrlGetInput(void) gInput.buttonFlags.lookDown |= buttonMap.ButtonDown(gamefunc_Aim_Down); } - if (buttonMap.ButtonDown(gamefunc_Center_View)) - { - buttonMap.ClearButton(gamefunc_Center_View); - gInput.keyFlags.lookCenter = 1; - } - - gInput.keyFlags.spin180 |= buttonMap.ButtonDown(gamefunc_TurnAround); - - if (buttonMap.ButtonDown(gamefunc_Inventory_Left)) - { - buttonMap.ClearButton(gamefunc_Inventory_Left); - gInput.keyFlags.prevItem = 1; - } - - if (buttonMap.ButtonDown(gamefunc_Inventory_Right)) - { - buttonMap.ClearButton(gamefunc_Inventory_Right); - gInput.keyFlags.nextItem = 1; - } - - if (buttonMap.ButtonDown(gamefunc_Inventory)) - { - buttonMap.ClearButton(gamefunc_Inventory); - gInput.keyFlags.useItem = 1; - } - - if (buttonMap.ButtonDown(gamefunc_BeastVision)) - { - buttonMap.ClearButton(gamefunc_BeastVision); - gInput.useFlags.useBeastVision = 1; - } - - if (buttonMap.ButtonDown(gamefunc_CrystalBall)) - { - buttonMap.ClearButton(gamefunc_CrystalBall); - gInput.useFlags.useCrystalBall = 1; - } - - if (buttonMap.ButtonDown(gamefunc_JumpBoots)) - { - buttonMap.ClearButton(gamefunc_JumpBoots); - gInput.useFlags.useJumpBoots = 1; - } - - if (buttonMap.ButtonDown(gamefunc_MedKit)) - { - buttonMap.ClearButton(gamefunc_MedKit); - gInput.useFlags.useMedKit = 1; - } - - for (int i = 0; i < 10; i++) - { - if (buttonMap.ButtonDown(gamefunc_Weapon_1 + i)) - { - buttonMap.ClearButton(gamefunc_Weapon_1 + i); - gInput.newWeapon = 1 + i; - } - } - - if (buttonMap.ButtonDown(gamefunc_ProximityBombs)) - { - buttonMap.ClearButton(gamefunc_ProximityBombs); - gInput.newWeapon = 11; - } - - if (buttonMap.ButtonDown(gamefunc_RemoteBombs)) - { - buttonMap.ClearButton(gamefunc_RemoteBombs); - gInput.newWeapon = 12; - } - - if (buttonMap.ButtonDown(gamefunc_Holster_Weapon)) - { - buttonMap.ClearButton(gamefunc_Holster_Weapon); - gInput.keyFlags.holsterWeapon = 1; - } - int const run = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const run2 = false; // What??? buttonMap.ButtonDown(gamefunc_Run); int const keyMove = (1 + run) << 10; @@ -429,4 +352,53 @@ void ctrlGetInput(void) } } +//--------------------------------------------------------------------------- +// +// CCMD based input. The basics are from Randi's ZDuke but this uses dynamic +// registration to only have the commands active when this game module runs. +// +//--------------------------------------------------------------------------- + +static int ccmd_slot(CCmdFuncPtr parm) +{ + if (parm->numparms != 1) return CCMD_SHOWHELP; + + auto slot = atoi(parm->parms[0]); + if (slot >= 1 && slot <= 10) + { + WeaponToSend = slot; + return CCMD_OK; + } + return CCMD_SHOWHELP; +} + +void registerinputcommands() +{ + C_RegisterFunction("slot", "slot : select a weapon from the given slot (1-10)", ccmd_slot); + C_RegisterFunction("weapprev", nullptr, [](CCmdFuncPtr)->int { if (gPlayer[myconnectindex].nextWeapon == 0) BitsToSend.prevWeapon = 1; return CCMD_OK; }); + C_RegisterFunction("weapnext", nullptr, [](CCmdFuncPtr)->int { if (gPlayer[myconnectindex].nextWeapon == 0) BitsToSend.nextWeapon = 1; return CCMD_OK; }); + C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend.pause = 1; return CCMD_OK; }); + C_RegisterFunction("proximitybombs", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 11; return CCMD_OK; }); + C_RegisterFunction("remotebombs", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 12; return CCMD_OK; }); + C_RegisterFunction("jumpboots", nullptr, [](CCmdFuncPtr)->int { UsesToSend.useJumpBoots = 1; return CCMD_OK; }); + C_RegisterFunction("medkit", nullptr, [](CCmdFuncPtr)->int { UsesToSend.useMedKit = 1; return CCMD_OK; }); + C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend.lookCenter = 1; return CCMD_OK; }); + C_RegisterFunction("holsterweapon", nullptr, [](CCmdFuncPtr)->int { BitsToSend.holsterWeapon = 1; return CCMD_OK; }); + C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { BitsToSend.prevItem = 1; return CCMD_OK; }); + C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { BitsToSend.nextItem = 1; return CCMD_OK; }); + C_RegisterFunction("crystalball", nullptr, [](CCmdFuncPtr)->int { UsesToSend.useCrystalBall = 1; return CCMD_OK; }); + C_RegisterFunction("beastvision", nullptr, [](CCmdFuncPtr)->int { UsesToSend.useBeastVision = 1; return CCMD_OK; }); + C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { BitsToSend.spin180 = 1; return CCMD_OK; }); + C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useItem = 1; return CCMD_OK; }); +} + +// This is called from ImputState::ClearAllInput and resets all static state being used here. +void GameInterface::clearlocalinputstate() +{ + WeaponToSend = 0; + BitsToSend.word = 0; + UsesToSend.byte = 0; +} + + END_BLD_NS diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index 52e012013..2d2cf061b 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -42,6 +42,7 @@ void sub_5571C(char mode); void sub_557C4(int x, int y, int interpolation); void DrawMirrors(int x, int y, int z, fix16_t a, fix16_t horiz, int smooth, int viewPlayer); int32_t registerosdcommands(void); +void registerinputcommands(void); int qanimateoffs(int a1, int a2); int32_t qgetpalookup(int32_t a1, int32_t a2); void HookReplaceFunctions(); diff --git a/source/blood/src/view.h b/source/blood/src/view.h index 695a64aaa..78e2f0eb0 100644 --- a/source/blood/src/view.h +++ b/source/blood/src/view.h @@ -165,7 +165,6 @@ void viewInit(void); void viewResizeView(int size); void UpdateFrame(void); void viewDrawInterface(ClockTicks arg); -tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect); void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t smooth); void CalcOtherPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, int zm); void CalcPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, int zm); diff --git a/wadsrc/static/filter/blood/engine/defbinds.txt b/wadsrc/static/filter/blood/engine/defbinds.txt index 0713276f9..c8b1c3a1b 100644 --- a/wadsrc/static/filter/blood/engine/defbinds.txt +++ b/wadsrc/static/filter/blood/engine/defbinds.txt @@ -1,11 +1,11 @@ U "+Mouse_Aiming" I "+Toggle_Crosshair" Scroll "+Holster_Weapon" -B "+BeastVision" -C "+CrystalBall" -P "+ProximityBombs" -R "+RemoteBombs" +B "BeastVision" +C "CrystalBall" +P "ProximityBombs" +R "RemoteBombs" X "+Alt_Fire" -J "+Jetpack" -M "+MedKit" +J "jumpboots" +M "MedKit" Mouse2 "+Alt_Fire" diff --git a/wadsrc/static/filter/blood/engine/leftbinds.txt b/wadsrc/static/filter/blood/engine/leftbinds.txt index 6bd24ae48..bc13285ed 100644 --- a/wadsrc/static/filter/blood/engine/leftbinds.txt +++ b/wadsrc/static/filter/blood/engine/leftbinds.txt @@ -1,9 +1,9 @@ // W "+Show_Opponents_Weapon" -B "+BeastVision" -C "+CrystalBall" -P "+ProximityBombs" -R "+RemoteBombs" +B "BeastVision" +C "CrystalBall" +P "ProximityBombs" +R "RemoteBombs" X "+Alt_Fire" -J "+Jetpack" -M "+MedKit" +J "jumpboots" +M "MedKit" diff --git a/wadsrc/static/filter/blood/engine/origbinds.txt b/wadsrc/static/filter/blood/engine/origbinds.txt index 29c8ef5d5..ef059205f 100644 --- a/wadsrc/static/filter/blood/engine/origbinds.txt +++ b/wadsrc/static/filter/blood/engine/origbinds.txt @@ -1,10 +1,10 @@ // X "+Alt_Fire" W "+Show_Opponents_Weapon" -B "+BeastVision" -C "+CrystalBall" -J "+JetPack" -M "+MedKit" -P "+ProximityBombs" -R "+RemoteBombs" +B "BeastVision" +C "CrystalBall" +J "jumpboots" +M "MedKit" +P "ProximityBombs" +R "RemoteBombs" Mouse2 "+Alt_Fire"