From b3c27a177e4787bf9341973039e73c1403e1b230 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:48:18 +1100 Subject: [PATCH] - Consolidate each game's `gi-GetInput()` into a unified function. * Eliminates a lot of boilerplate. * Consolidation of input accumulation buffers discretely used in each game. * Allows privatisation of `PlayerAngles::CameraAngles`. --- source/core/gameinput.cpp | 52 +++++++++++++++++- source/core/gameinput.h | 15 +++-- source/core/gamestruct.h | 9 ++- source/core/inputstate.cpp | 2 +- source/core/mainloop.cpp | 5 +- source/games/blood/all.cpp | 1 - source/games/blood/src/blood.h | 3 +- source/games/blood/src/controls.cpp | 85 ----------------------------- source/games/duke/src/duke3d.h | 5 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/input.cpp | 44 +-------------- source/games/exhumed/src/exhumed.h | 3 +- source/games/exhumed/src/input.cpp | 51 ----------------- source/games/sw/src/draw.cpp | 4 +- source/games/sw/src/game.cpp | 3 - source/games/sw/src/game.h | 6 +- source/games/sw/src/input.cpp | 49 ----------------- source/games/sw/src/network.h | 1 - source/games/sw/src/save.cpp | 1 - 19 files changed, 82 insertions(+), 259 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 709370f7b..60dde8ba4 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- +#include "menu.h" +#include "gamestate.h" #include "gameinput.h" //--------------------------------------------------------------------------- @@ -49,6 +51,7 @@ static constexpr double PITCH_HORIZOFFSPEED = 4.375; static constexpr DAngle PITCH_CNTRSINEOFFSET = DAngle90 / 8.; static constexpr DAngle PITCH_HORIZOFFCLIMB = DAngle::fromDeg(-38.); static constexpr DAngle PITCH_HORIZOFFPUSH = DAngle::fromDeg(0.4476); +static InputPacket inputBuffer{}; //--------------------------------------------------------------------------- @@ -110,9 +113,11 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { // set up variables. + const bool allowstrafe = isDukeEngine() ? true : inputOpts.first; + const double turnscale = inputOpts.second; const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); const float scaleAdjustf = float(scaleAdjust); @@ -146,8 +151,8 @@ void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, I currInput->svel += strafing * keymove * allowstrafe; // process RR's drunk state. - if (isRR() && drink_amt >= 66 && drink_amt <= 87) - currInput->svel += drink_amt & 1 ? -currInput->fvel : currInput->fvel; + if (isRR() && inputOpts.first) + currInput->svel += inputOpts.first & 1 ? -currInput->fvel : currInput->fvel; // add collected input to game's local input accumulation packet. inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -(float)keymove, (float)keymove); @@ -157,6 +162,47 @@ void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, I } +//--------------------------------------------------------------------------- +// +// Processes input and returns a packet if provided. +// +//--------------------------------------------------------------------------- + +void clearLocalInputBuffer() +{ + inputBuffer = {}; +} + +void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet) +{ + if (paused || M_Active() || gamestate != GS_LEVEL || !plrAngles || !plrAngles->pActor) + { + clearLocalInputBuffer(); + return; + } + + const auto inputOpts = gi->GetInputOptions(); + InputPacket input{}; + HIDInput hidInput{}; + getHidInput(&hidInput); + ApplyGlobalInput(&hidInput, &inputBuffer); + gi->GetInput(&hidInput, &inputBuffer, &input, !SyncInput() ? scaleAdjust : 1., inputOpts); + + // Directly update the camera angles if we're unsynchronised. + if (!SyncInput()) + { + plrAngles->CameraAngles.Yaw += DAngle::fromDeg(input.avel); + plrAngles->CameraAngles.Pitch += DAngle::fromDeg(input.horz); + } + + if (packet) + { + *packet = inputBuffer; + clearLocalInputBuffer(); + } +} + + //--------------------------------------------------------------------------- // // Adjust player's pitch by way of keyboard input. diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 3205f6c34..1ab5674b1 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -8,13 +8,11 @@ struct PlayerAngles // Player viewing angles, separate from the camera. DRotator PrevViewAngles, ViewAngles; - // Player camera angles, not for direct manipulation within the playsim. - DRotator CameraAngles; - // Holder of current yaw spin state for the 180 degree turn. DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); + friend void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet); // Prototypes. void doPitchKeys(InputPacket* const input); @@ -34,6 +32,10 @@ struct PlayerAngles } // Render angle functions. + const DRotator& getCameraAngles() + { + return CameraAngles; + } DRotator getRenderAngles(const double interpfrac) { // Get angles and return with clamped off pitch. @@ -71,8 +73,8 @@ struct PlayerAngles } private: - // Private data which should never be accessed publically. - DRotator PrevLerpAngles; + // Private data which should never be accessed publicly. + DRotator PrevLerpAngles, CameraAngles; DCoreActor* pActor; }; @@ -83,4 +85,5 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); +void clearLocalInputBuffer(); +void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet = nullptr); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 9f1e3cb9c..5d01278fc 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -17,6 +17,10 @@ struct sectortype; struct tspritetype; class DCoreActor; struct MapRecord; +struct PlayerAngles; + +using InputOptions = std::pair; +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts); struct GameStats { @@ -69,7 +73,6 @@ struct GameInterface virtual void LoadTextureInfo(TilesetBuildInfo& info) {} virtual void SetupSpecialTextures(TilesetBuildInfo&) {} virtual void loadPalette(); - virtual void clearlocalinputstate() {} virtual void UpdateScreenSize() {} virtual void FreeLevelData(); virtual void FreeGameData() {} @@ -88,7 +91,8 @@ struct GameInterface virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} virtual void ExitFromMenu() { throw CExitEvent(0); } - virtual void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) {} + virtual void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); } + virtual InputOptions GetInputOptions() { return std::make_pair(true, 1.); } virtual void UpdateSounds() {} virtual void ErrorCleanup() {} virtual void Startup() {} @@ -105,6 +109,7 @@ struct GameInterface virtual DAngle playerPitchMin() { return DAngle::fromDeg(57.375); } virtual DAngle playerPitchMax() { return DAngle::fromDeg(-57.375); } virtual DCoreActor* getConsoleActor() = 0; + virtual PlayerAngles* getConsoleAngles() = 0; virtual void ToggleThirdPerson() { } virtual void SwitchCoopView() { Printf("Unsupported command\n"); } virtual void ToggleShowWeapon() { Printf("Unsupported command\n"); } diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 211edc07c..e514c9260 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -142,7 +142,7 @@ void InputState::ClearAllInput() { ActionsToSend = 0; crouch_toggle = false; - gi->clearlocalinputstate(); // also clear game local input state. + clearLocalInputBuffer(); // also clear game local input state. } else if (gamestate == GS_LEVEL && crouch_toggle) { diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 7267adae5..6f7681280 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -91,6 +91,7 @@ #include "i_interface.h" #include "texinfo.h" #include "texturemanager.h" +#include "gameinput.h" CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -136,7 +137,7 @@ void G_BuildTiccmd(ticcmd_t* cmd) } cmd->ucmd = {}; I_GetEvent(); - gi->GetInput(!SyncInput() ? inputScale : 1., &cmd->ucmd); + getInput(inputScale, gi->getConsoleAngles(), &cmd->ucmd); cmd->consistency = consistency[myconnectindex][(maketic / ticdup) % BACKUPTICS]; } @@ -614,7 +615,7 @@ void TryRunTics (void) if (!SyncInput()) { I_GetEvent(); - gi->GetInput(!SyncInput() ? inputScale : 1.); + getInput(inputScale, gi->getConsoleAngles()); } return; } diff --git a/source/games/blood/all.cpp b/source/games/blood/all.cpp index 9d5a25080..614475060 100644 --- a/source/games/blood/all.cpp +++ b/source/games/blood/all.cpp @@ -30,7 +30,6 @@ #include "src/blood.cpp" #include "src/callback.cpp" #include "src/choke.cpp" -#include "src/controls.cpp" #include "src/db.cpp" #include "src/dude.cpp" #include "src/endgame.cpp" diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index b3b381854..797eb61e9 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -111,7 +111,6 @@ struct GameInterface : public ::GameInterface void app_init() override; void SerializeGameState(FSerializer& arc) override; void loadPalette() override; - void clearlocalinputstate() override; bool GenerateSavePic() override; void FreeLevelData() override; void FreeGameData() override; @@ -120,7 +119,6 @@ struct GameInterface : public ::GameInterface void MenuClosed() override; bool CanSave() override; void UpdateSounds() override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Ticker() override; void DrawBackground() override; void Startup() override; @@ -133,6 +131,7 @@ struct GameInterface : public ::GameInterface DAngle playerPitchMin() override { return DAngle::fromDeg(54.575); } DAngle playerPitchMax() override { return DAngle::fromDeg(-43.15); } DCoreActor* getConsoleActor() override { return gPlayer[myconnectindex].actor; } + PlayerAngles* getConsoleAngles() override { return &gPlayer[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index ea1ed63ea..e69de29bb 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -1,85 +0,0 @@ -#pragma once -//------------------------------------------------------------------------- -/* -Copyright (C) 2020 Christoph Oelckers & Mitchell Richters - -This file is part of Raze. - -Raze is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "ns.h" // Must come before everything else! - -#include "blood.h" -#include "gamestate.h" -#include "inputstate.h" -#include "gamestruct.h" -#include "razemenu.h" - -BEGIN_BLD_NS - -static InputPacket gInput; - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) -{ - if (paused || M_Active()) - { - gInput = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - PLAYER* pPlayer = &gPlayer[myconnectindex]; - InputPacket input{}; - - ApplyGlobalInput(&hidInput, &gInput); - processMovement(&hidInput, &gInput, &input, scaleAdjust); - - // Perform unsynchronised angle/horizon if not dead. - if (!SyncInput() && gamestate == GS_LEVEL) - { - pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = gInput; - gInput = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - gInput = {}; -} - -END_BLD_NS diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index a85ada872..446e5c6bb 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -27,7 +27,6 @@ struct GameInterface : public ::GameInterface void app_init() override; void loadPalette() override; void SetupSpecialTextures(TilesetBuildInfo& info) override; - void clearlocalinputstate() override; bool GenerateSavePic() override; void PlayHudSound() override; GameStats getStats() override; @@ -40,7 +39,8 @@ struct GameInterface : public ::GameInterface void SerializeGameState(FSerializer& arc) override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; + void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) override; + InputOptions GetInputOptions() override { return std::make_pair(ps[myconnectindex].drink_amt >= 66 && ps[myconnectindex].drink_amt <= 87, 1.); } void UpdateSounds() override; void Startup() override; void DrawBackground() override; @@ -53,6 +53,7 @@ struct GameInterface : public ::GameInterface void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DCoreActor* getConsoleActor() override { return ps[myconnectindex].GetActor(); } + PlayerAngles* getConsoleAngles() override { return &ps[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index fe6dd8159..2a655b1d7 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -419,7 +419,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, double j = clamp(czoom * act->spr.scale.Y + abs(pp.truefz - act->getOffsetZ()) * REPEAT_SCALE, (1. / 3.), 2.); auto const vec = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); - auto const daang = -(pp.Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); + auto const daang = -(pp.Angles.getCameraAngles().Yaw - cang).Normalized360().Degrees(); DrawTexture(twod, tileGetTexture(i), vec.X, vec.Y, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true, DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j, DTA_ScaleY, j, TAG_DONE); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 8136d78e6..91a06ccc2 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -44,9 +44,6 @@ EXTERN_CVAR(Float, m_yaw) BEGIN_DUKE_NS -// State timer counters. -static InputPacket loc; // input accumulation buffer. - //--------------------------------------------------------------------------- // // handles all HUD related input, i.e. inventory item selection and activation plus weapon selection. @@ -748,53 +745,18 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // //--------------------------------------------------------------------------- -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) +void GameInterface::GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { - if (paused || gamestate != GS_LEVEL) - { - loc = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - auto const p = &ps[myconnectindex]; - InputPacket input{}; - - ApplyGlobalInput(&hidInput, &loc); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - processVehicleInput(p, &hidInput, &loc, &input, scaleAdjust); + processVehicleInput(p, hidInput, inputBuffer, currInput, scaleAdjust); } else { - processMovement(&hidInput, &loc, &input, scaleAdjust, p->drink_amt); + processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); } - - if (!SyncInput() && p->GetActor()->spr.extra > 0) - { - p->Angles.CameraAngles.Yaw += p->adjustavel(input.avel); - p->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = loc; - loc = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - loc = {}; } diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 8c0269eea..519c98561 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -212,7 +212,6 @@ struct GameInterface : public ::GameInterface const char* Name() override { return "Exhumed"; } void app_init() override; void SetupSpecialTextures(TilesetBuildInfo& info) override; - void clearlocalinputstate() override; void loadPalette() override; bool GenerateSavePic() override; void MenuOpened() override; @@ -226,7 +225,6 @@ struct GameInterface : public ::GameInterface void DrawBackground() override; void Render() override; //void DrawWeapons() override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Startup() override; const char* GenericCheat(int player, int cheat) override; void NewGame(MapRecord *map, int skill, bool) override; @@ -236,6 +234,7 @@ struct GameInterface : public ::GameInterface DAngle playerPitchMin() override { return DAngle::fromDeg(49.5); } DAngle playerPitchMax() override { return DAngle::fromDeg(-49.5); } DCoreActor* getConsoleActor() override { return PlayerList[nLocalPlayer].pActor; } + PlayerAngles* getConsoleAngles() override { return &PlayerList[nLocalPlayer].Angles; } void ToggleThirdPerson() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 600d3feaa..7c82e0d69 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -25,8 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -static InputPacket localInput; - //--------------------------------------------------------------------------- // // @@ -39,53 +37,4 @@ void ClearSpaceBar(int nPlayer) buttonMap.ClearButton(gamefunc_Open); } - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) -{ - if (paused || M_Active()) - { - localInput = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - ApplyGlobalInput(&hidInput, &localInput); - - Player* pPlayer = &PlayerList[nLocalPlayer]; - InputPacket input {}; - - processMovement(&hidInput, &localInput, &input, scaleAdjust); - - if (!SyncInput() && gamestate == GS_LEVEL) - { - pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = localInput; - localInput = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - localInput = {}; -} - END_PS_NS diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 7d0ca917e..734ce4def 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -803,7 +803,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub } tsp->pos = pos; - tsp->Angles.Yaw = pp->Angles.CameraAngles.Yaw; + tsp->Angles.Yaw = pp->Angles.getCameraAngles().Yaw; //continue; } else @@ -1445,7 +1445,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, if (spnum >= 0) { - const auto daang = -(pp->Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); + const auto daang = -(pp->Angles.getCameraAngles().Yaw - cang).Normalized360().Degrees(); auto vect = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); // This repeat scale is correct. diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 138270295..724659674 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -502,9 +502,6 @@ void InitRunLevel(void) // send packets with player info InitNetPlayerOptions(); - // Initialize Game part of network code - InitNetVars(); - if (currentLevel) { PlaySong(currentLevel->music, currentLevel->cdSongId); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 68cb35b62..119a90ff3 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1587,8 +1587,6 @@ void SyncStatMessage(void); // sync.c int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c void ScreenCaptureKeys(void); // draw.c -void computergetinput(int snum,InputPacket *syn); // jplayer.c - void SetupMirrorTiles(void); // rooms.c bool FAF_Sector(sectortype* sect); // rooms.c double GetZadjustment(sectortype* sect,short hitag); // rooms.c @@ -1858,7 +1856,6 @@ struct GameInterface : public ::GameInterface void LoadTextureInfo(TilesetBuildInfo& info) override; void SetupSpecialTextures(TilesetBuildInfo& info) override; void loadPalette() override; - void clearlocalinputstate() override; void FreeLevelData() override; bool GenerateSavePic() override; void MenuSound(EMenuSounds snd) override; @@ -1869,7 +1866,7 @@ struct GameInterface : public ::GameInterface void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } void UpdateSounds() override; void ErrorCleanup() override; - void GetInput(const double scaleAdjust, InputPacket* input = nullptr) override; + InputOptions GetInputOptions() override { return std::make_pair(!Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); } void DrawBackground(void) override; void Ticker(void) override; void Render() override; @@ -1882,6 +1879,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord *map, int skill, bool) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DCoreActor* getConsoleActor() override { return Player[myconnectindex].actor; } + PlayerAngles* getConsoleAngles() override { return &Player[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double smoothRatio) override; diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index 47d36e972..fd2948d38 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -34,19 +34,12 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -static InputPacket loc; - //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- -void InitNetVars(void) -{ - loc = {}; -} - void InitTimingVars(void) { PlayClock = 0; @@ -157,46 +150,4 @@ void processWeapon(PLAYER* const pp) } } -void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) -{ - PLAYER* pp = &Player[myconnectindex]; - - if (paused || M_Active() || pp->actor == nullptr) - { - loc = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - InputPacket input {}; - - ApplyGlobalInput(&hidInput, &loc); - processMovement(&hidInput, &loc, &input, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); - - if (!SyncInput()) - { - pp->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pp->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = loc; - loc = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - loc = {}; -} - END_SW_NS diff --git a/source/games/sw/src/network.h b/source/games/sw/src/network.h index 08df66605..55f4aa91e 100644 --- a/source/games/sw/src/network.h +++ b/source/games/sw/src/network.h @@ -74,7 +74,6 @@ struct gNET extern gNET gNet; void UpdateInputs(void); -void InitNetVars(void); void InitTimingVars(void); void InitNetPlayerOptions(void); inline void SW_SendMessage(short, const char*) {} diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index d1b87182c..d85487d5b 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -1160,7 +1160,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) InitTimingVars(); PlayClock = SavePlayClock; defineSky(nullptr, pskybits_override, nullptr, 0, parallaxyscale_override / 8192.f); - InitNetVars(); screenpeek = myconnectindex;