diff --git a/source/blood/src/actor.cpp b/source/blood/src/actor.cpp index b7cd59b95..464072dc9 100644 --- a/source/blood/src/actor.cpp +++ b/source/blood/src/actor.cpp @@ -4728,12 +4728,7 @@ void MoveDude(spritetype *pSprite) { GetZRange(pSprite, &ceilZ, &ceilHit, &floorZ, &floorHit, wd, CLIPMASK0, PARALLAXCLIP_CEILING|PARALLAXCLIP_FLOOR); if (pPlayer) - { - if (bVanilla) - playerResetInertia(pPlayer); - else - playerCorrectInertia(pPlayer, &oldpos); - } + playerCorrectInertia(pPlayer, &oldpos); switch (nLink) { case kMarkerLowStack: if (pPlayer == gView) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index cd9e9d01b..796d199a8 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "db.h" #include "blood.h" #include "choke.h" -#include "controls.h" #include "dude.h" #include "endgame.h" #include "eventq.h" @@ -100,7 +99,6 @@ void StartLevel(MapRecord* level) gFrameClock = 0; STAT_Update(0); EndLevel(); - gInput = {}; currentLevel = level; if (gGameOptions.nGameType == 0) @@ -125,7 +123,6 @@ void StartLevel(MapRecord* level) gHealthTemp[i] = xsprite[gPlayer[i].pSprite->extra].health; } } - bVanilla = false; memset(xsprite, 0, sizeof(xsprite)); memset(sprite, 0, kMaxSprites * sizeof(spritetype)); //drawLoadingScreen(); @@ -230,7 +227,7 @@ void StartLevel(MapRecord* level) PreloadCache(); InitMirrors(); trInit(); - if (!bVanilla && !gMe->packSlots[1].isActive) // if diving suit is not active, turn off reverb sound effect + if (!gMe->packSlots[1].isActive) // if diving suit is not active, turn off reverb sound effect sfxSetReverb(0); ambInit(); Net_ClearFifo(); @@ -340,7 +337,7 @@ void GameInterface::Ticker() thinktime.Unclock(); gFrameCount++; - gFrameClock += 4; + gFrameClock += kTicsPerFrame; if (gFrameClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. for (int i = 0; i < 8; i++) @@ -444,7 +441,7 @@ void GameInterface::app_init() gChoke.init(518, sub_84230); UpdateDacs(0, true); - enginecompatibility_mode = ENGINECOMPATIBILITY_19960925;//bVanilla; + enginecompatibility_mode = ENGINECOMPATIBILITY_19960925; } static void gameInit() diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index 433c9ddd1..203742226 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -88,7 +88,7 @@ struct GameInterface : ::GameInterface FString GetCoordString() override; ReservedSpace GetReservedScreenSpace(int viewsize) override; void UpdateSounds() override; - void GetInput(InputPacket* gInput, ControlInfo* const hidInput) override; + void GetInput(InputPacket* packet, ControlInfo* const hidInput) override; void Ticker() override; void DrawBackground() override; void Startup() override; @@ -99,6 +99,8 @@ struct GameInterface : ::GameInterface void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(int x, int y, int z, int a) override; void SetTileProps(int til, int surf, int vox, int shade) override; + fixed_t playerHorizMin() override { return IntToFixed(-80); } + fixed_t playerHorizMax() override { return IntToFixed(220); } GameStats getStats() override; }; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index a54d92bba..a2108ca33 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -23,63 +23,97 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "ns.h" // Must come before everything else! -#include "compat.h" #include "mmulti.h" -#include "gamecontrol.h" -#include "common_game.h" -#include "blood.h" -#include "controls.h" -#include "globals.h" -#include "levels.h" #include "view.h" -#include "d_event.h" #include "gamestate.h" -#include "sound.h" +#include "menu.h" BEGIN_BLD_NS -InputPacket gInput; -bool bSilentAim = false; +static const double gTurnSpeed = 92.; +static InputPacket gInput; +static double turnHeldTime; -int iTurnCount = 0; - -int32_t mouseyaxismode = -1; - -fixed_t gViewLook, gViewAngle; -float gViewAngleAdjust; -float gViewLookAdjust; -int gViewLookRecenter; - -void GetInputInternal(InputPacket &inputParm, ControlInfo* const hidInput) +enum { - int prevPauseState = paused; + MAXFVEL = 2048, + MAXSVEL = 2048, + MAXHORIZVEL = 128 +}; - static double lastInputTicks; - auto const currentHiTicks = I_msTimeF(); - double const elapsedInputTicks = currentHiTicks - lastInputTicks; +void UpdatePlayerSpriteAngle(PLAYER* pPlayer); - lastInputTicks = currentHiTicks; - - auto scaleAdjustmentToInterval = [=](double x) { return x * kTicsPerSec / (1000.0 / elapsedInputTicks); }; +//--------------------------------------------------------------------------- +// +// handles movement +// +//--------------------------------------------------------------------------- +static void processMovement(ControlInfo* const hidInput) +{ + double const scaleAdjust = InputScale(); + int const run = !!(gInput.actions & SB_RUN); + int const keyMove = (1 + run) << 10; InputPacket input = {}; - ApplyGlobalInput(inputParm, hidInput); - - bool mouseaim = !(inputParm.actions & SB_AIMMODE); - if (!mouseaim) inputParm.actions |= SB_CENTERVIEW; - - if (gPlayer[myconnectindex].nextWeapon == 0) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { + input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove))); + } + else + { + input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); } - if (inputParm.actions & (SB_LOOK_UP|SB_LOOK_DOWN)) - inputParm.actions |= SB_CENTERVIEW; + if (!(gInput.actions & SB_AIMMODE)) + { + input.q16horz += FloatToFixed(hidInput->mousey); + } + else + { + input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.); + } - int const run = !!(inputParm.actions & SB_RUN); - int const keyMove = (1 + run) << 10; + if (!in_mouseflip) + input.q16horz = -input.q16horz; - if (inputParm.fvel < keyMove && inputParm.fvel > -keyMove) + input.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); + input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove)); + input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove)); + + if (buttonMap.ButtonDown(gamefunc_Strafe)) + { + if (gInput.svel < keyMove && gInput.svel > -keyMove) + { + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) + input.svel += keyMove; + + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) + input.svel -= keyMove; + } + } + else + { + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) + { + turnHeldTime += scaleAdjust * kTicsPerFrame; + input.q16avel -= FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.)); + } + else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) + { + turnHeldTime += scaleAdjust * kTicsPerFrame; + input.q16avel += FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.)); + } + else + { + turnHeldTime = 0; + } + } + + if (run && turnHeldTime > 24.) + input.q16avel <<= 1; + + if (abs(gInput.fvel) < keyMove) { if (buttonMap.ButtonDown(gamefunc_Move_Forward)) input.fvel += keyMove; @@ -88,111 +122,47 @@ void GetInputInternal(InputPacket &inputParm, ControlInfo* const hidInput) input.fvel -= keyMove; } - if (inputParm.svel < keyMove && inputParm.svel > -keyMove) + if (abs(gInput.svel) < keyMove) { if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) input.svel += keyMove; + if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) input.svel -= keyMove; } - - char turnLeft = 0, turnRight = 0; - - if (buttonMap.ButtonDown(gamefunc_Strafe)) + if (!cl_syncinput && gamestate == GS_LEVEL) { - if (inputParm.svel < keyMove && inputParm.svel > -keyMove) + PLAYER* pPlayer = &gPlayer[myconnectindex]; + + // Perform unsynchronised angle/horizon if not dead. + if (gView->pXSprite->health != 0) { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - input.svel += keyMove; - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - input.svel -= keyMove; + applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0); + UpdatePlayerSpriteAngle(pPlayer); + sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust); } - } - else - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - turnLeft = 1; - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - turnRight = 1; + + playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); } - static int32_t turnHeldTime; - static int32_t lastInputClock; // MED - int32_t const elapsedTics = gFrameClock - lastInputClock; - - // Blood's q16mlook scaling is different from the other games, therefore use the below constant to attenuate - // the speed to match the other games. - float const mlookScale = 3.25f; - - lastInputClock = gFrameClock; - - if (turnLeft || turnRight) - turnHeldTime += elapsedTics; - else - turnHeldTime = 0; - - if (turnLeft) - input.q16avel -= FloatToFixed(scaleAdjustmentToInterval(ClipHigh(12 * turnHeldTime, gTurnSpeed)>>2)); - if (turnRight) - input.q16avel += FloatToFixed(scaleAdjustmentToInterval(ClipHigh(12 * turnHeldTime, gTurnSpeed)>>2)); - - if (run && turnHeldTime > 24) - input.q16avel <<= 1; - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - input.svel -= hidInput->mousex * 32.f; - input.svel -= scaleAdjustmentToInterval(hidInput->dyaw * keyMove); - } - else - { - input.q16avel += FloatToFixed(hidInput->mousex); - input.q16avel += FloatToFixed(scaleAdjustmentToInterval(hidInput->dyaw)); - } - - input.svel -= scaleAdjustmentToInterval(hidInput->dx * keyMove); - input.fvel -= scaleAdjustmentToInterval(hidInput->dz * keyMove); - - if (mouseaim) - input.q16horz += FloatToFixed(hidInput->mousey / mlookScale); - else - input.fvel -= hidInput->mousey * 64.f; - if (!in_mouseflip) - input.q16horz = -input.q16horz; - - input.q16horz -= FloatToFixed(scaleAdjustmentToInterval(hidInput->dpitch / mlookScale)); - - inputParm.fvel = clamp(inputParm.fvel + input.fvel, -2048, 2048); - inputParm.svel = clamp(inputParm.svel + input.svel, -2048, 2048); - inputParm.q16avel += input.q16avel; - inputParm.q16horz = clamp(inputParm.q16horz + input.q16horz, IntToFixed(-127) >> 2, IntToFixed(127) >> 2); - - if (gMe && gMe->pXSprite && gMe->pXSprite->health != 0 && !paused) - { - int upAngle = 289; - int downAngle = -347; - double lookStepUp = 4.0*upAngle/60.0; - double lookStepDown = -4.0*downAngle/60.0; - gViewAngle = (gViewAngle + input.q16avel + FloatToFixed(scaleAdjustmentToInterval(gViewAngleAdjust))) & 0x7ffffff; - if (gViewLookRecenter) - { - if (gViewLook < 0) - gViewLook = min(gViewLook+FloatToFixed(scaleAdjustmentToInterval(lookStepDown)), 0); - if (gViewLook > 0) - gViewLook = max(gViewLook-FloatToFixed(scaleAdjustmentToInterval(lookStepUp)), 0); - } - else - { - gViewLook = clamp(gViewLook+FloatToFixed(scaleAdjustmentToInterval(gViewLookAdjust)), IntToFixed(downAngle), IntToFixed(upAngle)); - } - gViewLook = clamp(gViewLook+(input.q16horz << 3), IntToFixed(downAngle), IntToFixed(upAngle)); - } + gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL); + gInput.svel = clamp(gInput.svel + input.svel, -MAXSVEL, MAXSVEL); + gInput.q16avel += input.q16avel; + gInput.q16horz = clamp(gInput.q16horz + input.q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); } void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { - GetInputInternal(gInput, hidInput); + if (paused || M_Active()) + { + gInput = {}; + return; + } + + ApplyGlobalInput(gInput, hidInput); + processMovement(hidInput); + if (packet) { *packet = gInput; diff --git a/source/blood/src/controls.h b/source/blood/src/controls.h deleted file mode 100644 index 6849e7ebc..000000000 --- a/source/blood/src/controls.h +++ /dev/null @@ -1,39 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010-2019 EDuke32 developers and contributors -Copyright (C) 2019 Nuke.YKT - -This file is part of NBlood. - -NBlood 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. - -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. -*/ -//------------------------------------------------------------------------- -#pragma once - -#include "packet.h" - -BEGIN_BLD_NS - -extern InputPacket gInput; -extern bool bSilentAim; - -extern fixed_t gViewLook, gViewAngle; -extern float gViewAngleAdjust; -extern float gViewLookAdjust; -extern int gViewLookRecenter; - -void ctrlGetInput(); - -END_BLD_NS diff --git a/source/blood/src/credits.cpp b/source/blood/src/credits.cpp index 868cba1fc..7e963f4d2 100644 --- a/source/blood/src/credits.cpp +++ b/source/blood/src/credits.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "SmackerDecoder.h" #include "common_game.h" #include "blood.h" -#include "controls.h" #include "globals.h" #include "sound.h" #include "view.h" diff --git a/source/blood/src/db.cpp b/source/blood/src/db.cpp index ae21bdca7..dc20962a9 100644 --- a/source/blood/src/db.cpp +++ b/source/blood/src/db.cpp @@ -162,7 +162,7 @@ void qinitspritelists(void) // Replace { headspritestat[i] = -1; } - int const nMaxSprites = bVanilla ? 4096 : kMaxSprites; + int const nMaxSprites = kMaxSprites; for (short i = 0; i < nMaxSprites; i++) { sprite[i].sectnum = -1; @@ -285,8 +285,7 @@ unsigned short dbInsertXSprite(int nSprite) ThrowError("Out of free XSprites"); } memset(&xsprite[nXSprite], 0, sizeof(XSPRITE)); - if (!bVanilla) - memset(&gSpriteHit[nXSprite], 0, sizeof(SPRITEHIT)); + memset(&gSpriteHit[nXSprite], 0, sizeof(SPRITEHIT)); xsprite[nXSprite].reference = nSprite; sprite[nSprite].extra = nXSprite; return nXSprite; diff --git a/source/blood/src/globals.cpp b/source/blood/src/globals.cpp index c517b7a51..14eebbde3 100644 --- a/source/blood/src/globals.cpp +++ b/source/blood/src/globals.cpp @@ -32,14 +32,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -bool bVanilla = false; int gFrameClock; int gFrameCount; static const char *_module; static int _line; -int32_t gTurnSpeed = 92; int32_t gDetail = 4; bool gNoClip; bool gInfiniteAmmo; diff --git a/source/blood/src/globals.h b/source/blood/src/globals.h index 5b784e21f..c69935c1b 100644 --- a/source/blood/src/globals.h +++ b/source/blood/src/globals.h @@ -32,11 +32,9 @@ BEGIN_BLD_NS extern int gFrameClock; extern int gFrameCount; -extern bool bVanilla; #define MAXPLAYERNAME 16 -extern int32_t gTurnSpeed; extern int32_t gDetail; extern bool gNoClip; extern bool gInfiniteAmmo; diff --git a/source/blood/src/hudsprites.cpp b/source/blood/src/hudsprites.cpp index 384b2b7f0..8010583a3 100644 --- a/source/blood/src/hudsprites.cpp +++ b/source/blood/src/hudsprites.cpp @@ -96,14 +96,17 @@ static void viewBurnTime(int gScale) } -void hudDraw(PLAYER *gView, int nSectnum, int defaultHoriz, double bobx, double boby, double zDelta, int basepal, int smoothratio) +void hudDraw(PLAYER *gView, VIEW *pView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio) { if (gViewPos == 0) { - DrawCrosshair(kCrosshairTile, gView->pXSprite->health >> 4, 0, defaultHoriz - 100, 2); + double look_anghalf = getHalfLookAng(pView->q16look_ang, gView->q16look_ang, cl_syncinput, smoothratio); + double looking_arc = fabs(look_anghalf) / 4.5; - double cX = 160; - double cY = 220; + DrawCrosshair(kCrosshairTile, gView->pXSprite->health >> 4, -look_anghalf, 0, 2); + + double cX = 160 - look_anghalf; + double cY = 220 + looking_arc; if (cl_weaponsway) { cX += (bobx / 256.); diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 7f627bd58..d7670bec2 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -498,7 +498,7 @@ bool GameInterface::LoadGame(FSaveGameNode* node) InitSectorFX(); viewInitializePrediction(); PreloadCache(); - if (!bVanilla && !gMe->packSlots[1].isActive) // if diving suit is not active, turn off reverb sound effect + if (!gMe->packSlots[1].isActive) // if diving suit is not active, turn off reverb sound effect sfxSetReverb(0); ambInit(); for (int i = 0; i < gNetPlayers; i++) @@ -506,7 +506,6 @@ bool GameInterface::LoadGame(FSaveGameNode* node) viewSetErrorMessage(""); Net_ClearFifo(); paused = 0; - bVanilla = false; #ifdef USE_OPENGL @@ -645,8 +644,6 @@ void MyLoadSave::Load(void) Read(&gMapRev, sizeof(gMapRev)); Read(&gSongId, sizeof(gSkyCount)); Read(&gFogMode, sizeof(gFogMode)); - Read(&gViewAngle, sizeof(gViewAngle)); - Read(&gViewLook, sizeof(gViewLook)); #ifdef NOONE_EXTENSIONS Read(&gModernMap, sizeof(gModernMap)); #endif @@ -734,8 +731,6 @@ void MyLoadSave::Save(void) Write(&gMapRev, sizeof(gMapRev)); Write(&gSongId, sizeof(gSkyCount)); Write(&gFogMode, sizeof(gFogMode)); - Write(&gViewAngle, sizeof(gViewAngle)); - Write(&gViewLook, sizeof(gViewLook)); #ifdef NOONE_EXTENSIONS Write(&gModernMap, sizeof(gModernMap)); #endif diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index 6a3e9b442..3b539d1d0 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -90,6 +90,16 @@ inline int Cos(int ang) return costable[ang & 2047]; } +inline double Sinf(double ang) +{ + return (1 << 30) * sin(BANG2RAD * ang); +} + +inline double Cosf(double ang) +{ + return (1 << 30) * sin(BANG2RAD * (ang + 512.)); +} + inline int SinScale16(int ang) { return FixedToInt(costable[(ang - 512) & 2047]); diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index 4349e9bab..40176f6ca 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -1482,17 +1482,22 @@ void trPlayerCtrlSetScreenEffect(XSPRITE* pXSource, PLAYER* pPlayer) { } -void trPlayerCtrlSetLookAngle(XSPRITE* pXSource, PLAYER* pPlayer) { - - const int upAngle = 289; - const int downAngle = -347; - const double lookStepUp = 4.0 * upAngle / 60.0; - const double lookStepDown = -4.0 * downAngle / 60.0; - +void trPlayerCtrlSetLookAngle(XSPRITE* pXSource, PLAYER* pPlayer) +{ int look = pXSource->data2 << 5; - if (look > 0) pPlayer->q16look = min(mulscale8(FloatToFixed(lookStepUp), look), FloatToFixed(upAngle)); - else if (look < 0) pPlayer->q16look = -max(mulscale8(FloatToFixed(lookStepDown), abs(look)), FloatToFixed(downAngle)); - else pPlayer->q16look = 0; + + if (abs(look) > 0) + { + if (pPlayer->q16horiz != IntToFixed(100)) + { + // move q16horiz back to 100 + pPlayer->q16horiz += IntToFixed(25) - (pPlayer->q16horiz >> 2); + } + } + else + { + pPlayer->q16horiz = IntToFixed(100); + } } diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index f1b1d75ae..a12b4fe07 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -56,9 +56,7 @@ static int osdcmd_warptocoords(CCmdFuncPtr parm) if (parm->numparms == 5) { - // fix me, I'm broken. pPlayer->q16horiz = gView->q16horiz = IntToFixed(atoi(parm->parms[4])); - gViewAngle = FloatToFixed(atan2(atoi(parm->parms[4]), 100) * (1024. / pi::pi())); } viewBackupView(pPlayer->nPlayer); diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index bee04f7fc..6ebadac23 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -31,7 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "actor.h" #include "blood.h" #include "callback.h" -#include "controls.h" #include "eventq.h" #include "fx.h" #include "gib.h" @@ -722,9 +721,8 @@ void playerStart(int nPlayer, int bNewLevel) pPlayer->pXSprite->health = pDudeInfo->startHealth<<4; pPlayer->pSprite->cstat &= (unsigned short)~32768; pPlayer->bloodlust = 0; - pPlayer->q16horiz = 0; + pPlayer->q16horiz = IntToFixed(100); pPlayer->q16slopehoriz = 0; - pPlayer->q16look = 0; pPlayer->slope = 0; pPlayer->fraggerId = -1; pPlayer->underwaterTime = 1200; @@ -807,8 +805,6 @@ void playerStart(int nPlayer, int bNewLevel) if (pPlayer == gMe) { viewInitializePrediction(); - gViewLook = pPlayer->q16look; - gViewAngle = pPlayer->q16ang; } if (IsUnderwaterSector(pSprite->sectnum)) { @@ -1307,6 +1303,32 @@ int ActionScan(PLAYER *pPlayer, int *a2, int *a3) return -1; } +//--------------------------------------------------------------------------- +// +// Player's sprite angle function, called in ProcessInput() or from gi->GetInput() as required. +// +//--------------------------------------------------------------------------- + +void UpdatePlayerSpriteAngle(PLAYER *pPlayer) +{ + spritetype *pSprite = pPlayer->pSprite; + + pPlayer->q16ang = (pPlayer->q16ang + IntToFixed(pSprite->ang - pPlayer->angold)) & 0x7FFFFFF; + pPlayer->angold = pSprite->ang = FixedToInt(pPlayer->q16ang); +} + +//--------------------------------------------------------------------------- +// +// Unsynchronised input helpers. +// +//--------------------------------------------------------------------------- + +static void resetinputhelpers(PLAYER* pPlayer) +{ + pPlayer->horizAdjust = 0; + pPlayer->angAdjust = 0; +} + void ProcessInput(PLAYER *pPlayer) { enum @@ -1317,19 +1339,14 @@ void ProcessInput(PLAYER *pPlayer) Item_JumpBoots = 3 }; + resetinputhelpers(pPlayer); + spritetype *pSprite = pPlayer->pSprite; XSPRITE *pXSprite = pPlayer->pXSprite; int nSprite = pPlayer->nSprite; POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; InputPacket *pInput = &pPlayer->input; - if (pPlayer == gMe && numplayers == 1) - { - gViewAngleAdjust = 0.f; - gViewLookRecenter = false; - gViewLookAdjust = 0.f; - } - pPlayer->isRunning = !!(pInput->actions & SB_RUN); if ((pInput->actions & SB_BUTTON_MASK) || pInput->fvel || pInput->svel || pInput->q16avel) pPlayer->restTime = 0; @@ -1341,17 +1358,13 @@ void ProcessInput(PLAYER *pPlayer) char bSeqStat = playerSeqPlaying(pPlayer, 16); if (pPlayer->fraggerId != -1) { - pPlayer->angold = pSprite->ang = getangle(sprite[pPlayer->fraggerId].x - pSprite->x, sprite[pPlayer->fraggerId].y - pSprite->y); - pPlayer->q16ang = IntToFixed(pSprite->ang); + fixed_t fraggerAng = gethiq16angle(sprite[pPlayer->fraggerId].x - pSprite->x, sprite[pPlayer->fraggerId].y - pSprite->y); + pPlayer->angold = pSprite->ang = FixedToInt(fraggerAng); + playerAddAngle(&pPlayer->q16ang, &pPlayer->angAdjust, FixedToFloat(getincangleq16(pPlayer->q16ang, fraggerAng))); } pPlayer->deathTime += 4; if (!bSeqStat) - { - if (bVanilla) - pPlayer->q16horiz = IntToFixed(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime*8, 1024))>>15), 120)); - else - pPlayer->q16horiz = mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime*8, 1024))>>15), IntToFixed(120)); - } + playerAddHoriz(&pPlayer->q16horiz, &pPlayer->horizAdjust, FixedToFloat(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime<<3, 1024))>>15), gi->playerHorizMax()) - pPlayer->q16horiz)); if (pPlayer->curWeapon) pInput->setNewWeapon(pPlayer->curWeapon); if (pInput->actions & SB_OPEN) @@ -1430,30 +1443,13 @@ void ProcessInput(PLAYER *pPlayer) yvel[nSprite] -= mulscale30(strafe, x); } } - if (pInput->q16avel) - pPlayer->q16ang = (pPlayer->q16ang+pInput->q16avel)&0x7ffffff; - if (pInput->actions & SB_TURNAROUND) + + if (cl_syncinput) { - if (!pPlayer->spin) - pPlayer->spin = -1024; - pInput->actions &= ~SB_TURNAROUND; + applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, pInput->q16avel, &pInput->actions, 1, pPlayer->posture != 0); + UpdatePlayerSpriteAngle(pPlayer); } - if (pPlayer->spin < 0) - { - int speed; - if (pPlayer->posture == 1) - speed = 64; - else - speed = 128; - pPlayer->spin = min(pPlayer->spin+speed, 0); - pPlayer->q16ang += IntToFixed(speed); - if (pPlayer == gMe && numplayers == 1) - gViewAngleAdjust += float(speed); - } - if (pPlayer == gMe && numplayers == 1) - gViewAngleAdjust += float(pSprite->ang - pPlayer->angold); - pPlayer->q16ang = (pPlayer->q16ang+IntToFixed(pSprite->ang-pPlayer->angold))&0x7ffffff; - pPlayer->angold = pSprite->ang = FixedToInt(pPlayer->q16ang); + if (!(pInput->actions & SB_JUMP)) pPlayer->cantJump = 0; @@ -1559,69 +1555,12 @@ void ProcessInput(PLAYER *pPlayer) } pInput->actions &= ~SB_OPEN; } - if (bVanilla) + + if (cl_syncinput) { - if ((pInput->actions & SB_CENTERVIEW) && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN))) - { - if (pPlayer->q16look < 0) - pPlayer->q16look = min(pPlayer->q16look+IntToFixed(4), 0); - if (pPlayer->q16look > 0) - pPlayer->q16look = max(pPlayer->q16look-IntToFixed(4), 0); - if (!pPlayer->q16look) - pInput->actions &= ~SB_CENTERVIEW; - } - else - { - if (pInput->actions & (SB_LOOK_UP|SB_AIM_UP)) - pPlayer->q16look = min(pPlayer->q16look+IntToFixed(4), IntToFixed(60)); - if (pInput->actions & (SB_LOOK_DOWN|SB_AIM_DOWN)) - pPlayer->q16look = max(pPlayer->q16look-IntToFixed(4), IntToFixed(-60)); - } - pPlayer->q16look = clamp(pPlayer->q16look+pInput->q16horz, IntToFixed(-60), IntToFixed(60)); - if (pPlayer->q16look > 0) - pPlayer->q16horiz = IntToFixed(mulscale30(120, Sin(FixedToInt(pPlayer->q16look)<<3))); - else if (pPlayer->q16look < 0) - pPlayer->q16horiz = IntToFixed(mulscale30(180, Sin(FixedToInt(pPlayer->q16look)<<3))); - else - pPlayer->q16horiz = 0; - } - else - { - int upAngle = 289; - int downAngle = -347; - double lookStepUp = 4.0*upAngle/60.0; - double lookStepDown = -4.0*downAngle/60.0; - if ((pInput->actions & SB_CENTERVIEW) && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN))) - { - if (pPlayer->q16look < 0) - pPlayer->q16look = min(pPlayer->q16look+FloatToFixed(lookStepDown), 0); - if (pPlayer->q16look > 0) - pPlayer->q16look = max(pPlayer->q16look-FloatToFixed(lookStepUp), 0); - if (!pPlayer->q16look) - pInput->actions &= ~SB_CENTERVIEW; - } - else - { - if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) - pPlayer->q16look = min(pPlayer->q16look+FloatToFixed(lookStepUp), IntToFixed(upAngle)); - if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) - pPlayer->q16look = max(pPlayer->q16look-FloatToFixed(lookStepDown), IntToFixed(downAngle)); - } - if (pPlayer == gMe && numplayers == 1) - { - if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) - { - gViewLookAdjust += float(lookStepUp); - } - if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) - { - gViewLookAdjust -= float(lookStepDown); - } - gViewLookRecenter = ((pInput->actions & SB_CENTERVIEW) && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN))); - } - pPlayer->q16look = clamp(pPlayer->q16look+(pInput->q16horz<<3), IntToFixed(downAngle), IntToFixed(upAngle)); - pPlayer->q16horiz = FloatToFixed(100.f*tanf(FixedToFloat(pPlayer->q16look)*fPI/1024.f)); + sethorizon(&pPlayer->q16horiz, pInput->q16horz, &pInput->actions, 1); } + int nSector = pSprite->sectnum; int florhit = gSpriteHit[pSprite->extra].florhit & 0xc000; char va; @@ -1648,7 +1587,7 @@ void ProcessInput(PLAYER *pPlayer) if (klabs(pPlayer->q16slopehoriz) < 4) pPlayer->q16slopehoriz = 0; } - pPlayer->slope = (-FixedToInt(pPlayer->q16horiz))<<7; + pPlayer->slope = -(pPlayer->q16horiz - IntToFixed(100)) >> 9; if (pInput->actions & SB_INVPREV) { pInput->actions&= ~SB_INVPREV; diff --git a/source/blood/src/player.h b/source/blood/src/player.h index 908766a40..d9d558788 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "common_game.h" #include "compat.h" #include "globals.h" -#include "controls.h" #include "db.h" #include "dude.h" #include "levels.h" @@ -109,9 +108,8 @@ struct PLAYER int zViewVel; int zWeapon; int zWeaponVel; - fixed_t q16look; - int q16horiz; // horiz - int q16slopehoriz; // horizoff + fixed_t q16horiz; // horiz + fixed_t q16slopehoriz; // horizoff int slope; bool isUnderwater; bool hasKey[8]; @@ -156,7 +154,7 @@ struct PLAYER int restTime; int kickPower; int laughCount; - int spin; // turning around + fixed_t spin; // turning around bool godMode; bool fallScream; bool cantJump; @@ -186,6 +184,12 @@ struct PLAYER int player_par; int nWaterPal; POSTURE pPosture[kModeMax][kPostureMax]; + fixed_t q16look_ang; + fixed_t q16rotscrnang; + + // Input helper variables. + double horizAdjust, angAdjust; + fixed_t horizTarget, angTarget; }; struct PROFILE diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index 718621aaf..a3925808b 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -58,7 +58,6 @@ static VIEW predictFifo[256]; void viewInitializePrediction(void) { predict.at30 = gMe->q16ang; - predict.at20 = gMe->q16look; predict.at24 = gMe->q16horiz; predict.at28 = gMe->q16slopehoriz; predict.at2c = gMe->slope; @@ -93,11 +92,6 @@ void viewInitializePrediction(void) predict.at40 = gMe->zWeapon; predict.at44 = gMe->zWeaponVel; predictOld = predict; - if (numplayers != 1) - { - gViewAngle = predict.at30; - gViewLook = predict.at20; - } } void viewUpdatePrediction(InputPacket *pInput) @@ -110,11 +104,6 @@ void viewUpdatePrediction(InputPacket *pInput) gMe->pSprite->cstat = bakCstat; //predictFifo[gPredictTail&255] = predict; //gPredictTail++; - if (numplayers != 1) - { - gViewAngle = predict.at30; - gViewLook = predict.at20; - } } static void sub_158B4(PLAYER *pPlayer) @@ -127,13 +116,6 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) { POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][predict.at48]; - if (numplayers > 1 && gPrediction) - { - gViewAngleAdjust = 0.f; - gViewLookRecenter = false; - gViewLookAdjust = 0.f; - } - predict.at70 = !!(gMe->input.actions & SB_RUN); predict.at71 = !!(gMe->input.actions & SB_JUMP); if (predict.at48 == 1) @@ -202,8 +184,6 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) predict.at4c = min(predict.at4c+speed, 0); predict.at30 += IntToFixed(speed); - if (numplayers > 1 && gPrediction) - gViewAngleAdjust += float(speed); } if (!predict.at71) @@ -231,8 +211,8 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) predict.at48 = 2; break; } -#if 0 - if (predict.at6e && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown) + + if (predict.at6e && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN))) { if (predict.at20 < 0) predict.at20 = min(predict.at20+IntToFixed(4), 0); @@ -243,54 +223,19 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) } else { - if (pInput->syncFlags.lookUp) + if (pInput->actions & SB_LOOK_UP) predict.at20 = min(predict.at20+IntToFixed(4), IntToFixed(60)); - if (pInput->syncFlags.lookDown) + if (pInput->actions & SB_LOOK_DOWN) predict.at20 = max(predict.at20-IntToFixed(4), IntToFixed(-60)); } - predict.at20 = clamp(predict.at20+pInput->q16mlook, IntToFixed(-60), IntToFixed(60)); + predict.at20 = clamp(predict.at20+pInput->q16horz, IntToFixed(-60), IntToFixed(60)); if (predict.at20 > 0) - predict.at24 = mulscale30(IntToFixed(120), Sin(FixedToInt(predict.at20<<3))); + predict.at24 = FloatToFixed(fmulscale30(120., Sinf(FixedToFloat(predict.at20) * 8.))); else if (predict.at20 < 0) - predict.at24 = mulscale30(IntToFixed(180), Sin(FixedToInt(predict.at20<<3))); + predict.at24 = FloatToFixed(fmulscale30(180., Sinf(FixedToFloat(predict.at20) * 8.))); else predict.at24 = 0; -#endif - int upAngle = 289; - int downAngle = -347; - double lookStepUp = 4.0*upAngle/60.0; - double lookStepDown = -4.0*downAngle/60.0; - if (predict.at6e && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN))) - { - if (predict.at20 < 0) - predict.at20 = min(predict.at20+FloatToFixed(lookStepDown), 0); - if (predict.at20 > 0) - predict.at20 = max(predict.at20-FloatToFixed(lookStepUp), 0); - if (predict.at20 == 0) - predict.at6e = 0; - } - else - { - if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) - predict.at20 = min(predict.at20+FloatToFixed(lookStepUp), IntToFixed(upAngle)); - if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) - predict.at20 = max(predict.at20-FloatToFixed(lookStepDown), IntToFixed(downAngle)); - } - if (numplayers > 1 && gPrediction) - { - if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) - { - gViewLookAdjust += float(lookStepUp); - } - if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) - { - gViewLookAdjust -= float(lookStepDown); - } - gViewLookRecenter = predict.at6e && !(pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN)); - } - predict.at20 = clamp(predict.at20+(pInput->q16horz<<3), IntToFixed(downAngle), IntToFixed(upAngle)); - predict.at24 = FloatToFixed(100.f*tanf(FixedToFloat(predict.at20)*fPI/1024.f)); int nSector = predict.at68; int florhit = predict.at75.florhit & 0xc000; @@ -318,7 +263,7 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) if (klabs(predict.at28) < 4) predict.at28 = 0; } - predict.at2c = (-FixedToInt(predict.at24))<<7; + predict.at2c = -(predict.at24 - IntToFixed(100)) >> 9; } void fakePlayerProcess(PLAYER *pPlayer, InputPacket *pInput) @@ -706,12 +651,6 @@ void fakeActProcessSprites(void) void viewCorrectPrediction(void) { #if 0 - if (numplayers == 1) - { - gViewLook = gMe->q16look; - gViewAngle = gMe->q16ang; - return; - } spritetype *pSprite = gMe->pSprite; VIEW *pView = &predictFifo[(gNetFifoTail-1)&255]; if (gMe->q16ang != pView->at30 || pView->at24 != gMe->q16horiz || pView->at50 != pSprite->x || pView->at54 != pSprite->y || pView->at58 != pSprite->z) diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index cc3080621..be7c50bb3 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -74,8 +74,6 @@ INTERPOLATE gInterpolation[kMaxInterpolations]; int gScreenTilt; - - FFont *gFont[kFontNum]; void FontSet(int id, int tile, int space) @@ -118,6 +116,8 @@ void viewBackupView(int nPlayer) pView->atc = pPlayer->bobWidth; pView->at18 = pPlayer->swayHeight; pView->at1c = pPlayer->swayWidth; + pView->q16look_ang = pPlayer->q16look_ang; + pView->q16rotscrnang = pPlayer->q16rotscrnang; } void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos) @@ -586,7 +586,6 @@ static void DrawMap(spritetype* pSprite) void viewDrawScreen(bool sceneonly) { int nPalette = 0; - int defaultHoriz = r_horizcenter ? 100 : 90; if (TestBitString(gotpic, 2342)) { @@ -594,10 +593,6 @@ void viewDrawScreen(bool sceneonly) ClearBitString(gotpic, 2342); } - -#ifdef USE_OPENGL - polymostcenterhoriz = defaultHoriz; -#endif if (!paused && (!M_Active() || gGameOptions.nGameType != 0)) { gInterpolate = I_GetTimeFrac() * MaxSmoothRatio; @@ -636,60 +631,64 @@ void viewDrawScreen(bool sceneonly) int v1 = xs_CRoundToInt(double(viewingrange) * tan(r_fov * (PI / 360.))); renderSetAspect(v1, yxaspect); - int cX = gView->pSprite->x; - int cY = gView->pSprite->y; - int cZ = gView->zView; - double zDelta = gView->zWeapon - gView->zView - (12 << 8); - fixed_t cA = gView->q16ang; - fixed_t q16horiz = gView->q16horiz; - fixed_t q16slopehoriz = gView->q16slopehoriz; - int v74 = gView->bobWidth; - int v8c = gView->bobHeight; - double v4c = gView->swayWidth; - double v48 = gView->swayHeight; + + int cX, cY, cZ, v74, v8c; + fixed_t cA, q16horiz, q16slopehoriz, q16rotscrnang; + double zDelta, v4c, v48; int nSectnum = gView->pSprite->sectnum; - if (cl_interpolate) + if (numplayers > 1 && gView == gMe && gPrediction && gMe->pXSprite->health > 0) { - if (numplayers > 1 && gView == gMe && gPrediction && gMe->pXSprite->health > 0) + nSectnum = predict.at68; + cX = interpolate(predictOld.at50, predict.at50, gInterpolate); + cY = interpolate(predictOld.at54, predict.at54, gInterpolate); + cZ = interpolate(predictOld.at38, predict.at38, gInterpolate); + zDelta = finterpolate(predictOld.at34, predict.at34, gInterpolate); + q16slopehoriz = interpolate(predictOld.at28, predict.at28, gInterpolate); + v74 = interpolate(predictOld.atc, predict.atc, gInterpolate); + v8c = interpolate(predictOld.at8, predict.at8, gInterpolate); + v4c = finterpolate(predictOld.at1c, predict.at1c, gInterpolate); + v48 = finterpolate(predictOld.at18, predict.at18, gInterpolate); + + if (!cl_syncinput) { - nSectnum = predict.at68; - cX = interpolate(predictOld.at50, predict.at50, gInterpolate); - cY = interpolate(predictOld.at54, predict.at54, gInterpolate); - cZ = interpolate(predictOld.at38, predict.at38, gInterpolate); - zDelta = finterpolate(predictOld.at34, predict.at34, gInterpolate); - cA = interpolateangfix16(predictOld.at30, predict.at30, gInterpolate); - q16horiz = interpolate(predictOld.at24, predict.at24, gInterpolate); - q16slopehoriz = interpolate(predictOld.at28, predict.at28, gInterpolate); - v74 = interpolate(predictOld.atc, predict.atc, gInterpolate); - v8c = interpolate(predictOld.at8, predict.at8, gInterpolate); - v4c = finterpolate(predictOld.at1c, predict.at1c, gInterpolate); - v48 = finterpolate(predictOld.at18, predict.at18, gInterpolate); + cA = predict.at30 + predict.q16look_ang; + q16horiz = predict.at24; + q16rotscrnang = predict.q16rotscrnang; } else { - VIEW* pView = &gPrevView[gViewIndex]; - cX = interpolate(pView->at50, cX, gInterpolate); - cY = interpolate(pView->at54, cY, gInterpolate); - cZ = interpolate(pView->at38, cZ, gInterpolate); - zDelta = finterpolate(pView->at34, zDelta, gInterpolate); - cA = interpolateangfix16(pView->at30, cA, gInterpolate); - q16horiz = interpolate(pView->at24, q16horiz, gInterpolate); - q16slopehoriz = interpolate(pView->at28, q16slopehoriz, gInterpolate); - v74 = interpolate(pView->atc, v74, gInterpolate); - v8c = interpolate(pView->at8, v8c, gInterpolate); - v4c = finterpolate(pView->at1c, v4c, gInterpolate); - v48 = finterpolate(pView->at18, v48, gInterpolate); + cA = interpolateangfix16(predictOld.at30 + predictOld.q16look_ang, predict.at30 + predict.q16look_ang, gInterpolate); + q16horiz = interpolate(predictOld.at24, predict.at24, gInterpolate); + q16rotscrnang = interpolateangfix16(predictOld.q16rotscrnang, predict.q16rotscrnang, gInterpolate); } } - if (!cl_syncinput && gView == gMe && (numplayers <= 1 || gPrediction) && gView->pXSprite->health != 0 && !VanillaMode()) + else { - int upAngle = 289; - int downAngle = -347; - fixed_t q16look; - cA = gViewAngle; - q16look = gViewLook; - q16horiz = FloatToFixed(100.f * tanf(FixedToFloat(q16look) * fPI / 1024.f)); + VIEW* pView = &gPrevView[gViewIndex]; + cX = interpolate(pView->at50, gView->pSprite->x, gInterpolate); + cY = interpolate(pView->at54, gView->pSprite->y, gInterpolate); + cZ = interpolate(pView->at38, gView->zView, gInterpolate); + zDelta = finterpolate(pView->at34, gView->zWeapon - gView->zView - (12 << 8), gInterpolate); + q16slopehoriz = interpolate(pView->at28, gView->q16slopehoriz, gInterpolate); + v74 = interpolate(pView->atc, gView->bobWidth, gInterpolate); + v8c = interpolate(pView->at8, gView->bobHeight, gInterpolate); + v4c = finterpolate(pView->at1c, gView->swayWidth, gInterpolate); + v48 = finterpolate(pView->at18, gView->swayHeight, gInterpolate); + + if (!cl_syncinput) + { + cA = gView->q16ang + gView->q16look_ang; + q16horiz = gView->q16horiz; + q16rotscrnang = gView->q16rotscrnang; + } + else + { + cA = interpolateangfix16(pView->at30 + pView->q16look_ang, gView->q16ang + gView->q16look_ang, gInterpolate); + q16horiz = interpolate(pView->at24, gView->q16horiz, gInterpolate); + q16rotscrnang = interpolateangfix16(pView->q16rotscrnang, gView->q16rotscrnang, gInterpolate); + } } + viewUpdateShake(); q16horiz += IntToFixed(shakeHoriz); cA += IntToFixed(shakeAngle); @@ -734,7 +733,7 @@ void viewDrawScreen(bool sceneonly) //int tiltcs, tiltdim; uint8_t v4 = powerupCheck(gView, kPwUpCrystalBall) > 0; #ifdef USE_OPENGL - renderSetRollAngle(0); + renderSetRollAngle(FixedToFloat(q16rotscrnang)); #endif if (v78 || bDelirium) { @@ -811,8 +810,8 @@ void viewDrawScreen(bool sceneonly) for (int i = 0; i < 16; i++) ror_status[i] = TestBitString(gotpic, 4080 + i); yax_preparedrawrooms(); - DrawMirrors(vd8, vd4, vd0, IntToFixed(v50), IntToFixed(v54 + defaultHoriz), gInterpolate, -1); - drawrooms(vd8, vd4, vd0, v50, v54 + defaultHoriz, vcc); + DrawMirrors(vd8, vd4, vd0, IntToFixed(v50), IntToFixed(v54), gInterpolate, -1); + drawrooms(vd8, vd4, vd0, v50, v54, vcc); yax_drawrooms(viewProcessSprites, vcc, 0, gInterpolate); bool do_ror_hack = false; for (int i = 0; i < 16; i++) @@ -880,13 +879,13 @@ void viewDrawScreen(bool sceneonly) { cZ = vfc + (gLowerLink[nSectnum] >= 0 ? 0 : (8 << 8)); } - q16horiz = ClipRange(q16horiz, IntToFixed(-200), IntToFixed(200)); + q16horiz = ClipRange(q16horiz, gi->playerHorizMin(), gi->playerHorizMax()); RORHACK: int ror_status[16]; for (int i = 0; i < 16; i++) ror_status[i] = TestBitString(gotpic, 4080 + i); fixed_t deliriumPitchI = interpolate(IntToFixed(deliriumPitchO), IntToFixed(deliriumPitch), gInterpolate); - DrawMirrors(cX, cY, cZ, cA, q16horiz + IntToFixed(defaultHoriz) + deliriumPitchI, gInterpolate, gViewIndex); + DrawMirrors(cX, cY, cZ, cA, q16horiz + deliriumPitchI, gInterpolate, gViewIndex); int bakCstat = gView->pSprite->cstat; if (gViewPos == 0) { @@ -897,7 +896,7 @@ void viewDrawScreen(bool sceneonly) gView->pSprite->cstat |= 514; } - renderDrawRoomsQ16(cX, cY, cZ, cA, q16horiz + IntToFixed(defaultHoriz) + deliriumPitchI, nSectnum); + renderDrawRoomsQ16(cX, cY, cZ, cA, q16horiz + deliriumPitchI, nSectnum); viewProcessSprites(cX, cY, cZ, FixedToInt(cA), gInterpolate); bool do_ror_hack = false; for (int i = 0; i < 16; i++) @@ -955,7 +954,7 @@ void viewDrawScreen(bool sceneonly) int v8 = byte_1CE5C2 > 0 && (sector[tmpSect].ceilingstat & 1); if (gWeather.at12d8 > 0 || v8) { - gWeather.Draw(cX, cY, cZ, cA, q16horiz + defaultHoriz + deliriumPitch, gWeather.at12d8); + gWeather.Draw(cX, cY, cZ, cA, q16horiz + deliriumPitch, gWeather.at12d8); if (v8) { gWeather.at12d8 = ClipRange(delta * 8 + gWeather.at12d8, 0, 4095); @@ -966,7 +965,7 @@ void viewDrawScreen(bool sceneonly) } } #endif - hudDraw(gView, nSectnum, defaultHoriz, v4c, v48, zDelta, basepal, (int)gInterpolate); + hudDraw(gView, &gPrevView[gViewIndex], nSectnum, v4c, v48, zDelta, basepal, gInterpolate); } UpdateDacs(0, true); // keep the view palette active only for the actual 3D view and its overlays. if (automapMode != am_off) diff --git a/source/blood/src/view.h b/source/blood/src/view.h index 656f0db07..48de4fd9c 100644 --- a/source/blood/src/view.h +++ b/source/blood/src/view.h @@ -25,7 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "build.h" #include "palette.h" #include "common_game.h" -#include "controls.h" #include "messages.h" #include "player.h" @@ -67,6 +66,8 @@ struct VIEW { char at72; // underwater short at73; // sprite flags SPRITEHIT at75; + fixed_t q16look_ang; + fixed_t q16rotscrnang; }; extern VIEW gPrevView[kMaxPlayers]; @@ -141,7 +142,7 @@ extern LOCATION gPrevSpriteLoc[kMaxSprites]; extern int gLastPal; extern double gInterpolate; -void hudDraw(PLAYER* gView, int nSectnum, int defaultHoriz, double bobx, double boby, double zDelta, int basepal, int smoothratio); +void hudDraw(PLAYER* gView, VIEW *pView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio); void viewInitializePrediction(void); void viewUpdatePrediction(InputPacket *pInput); void viewCorrectPrediction(void); diff --git a/source/build/include/build.h b/source/build/include/build.h index 637869aa6..54363c84b 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -678,11 +678,6 @@ int32_t ksqrt(uint32_t num); int32_t getangle(int32_t xvect, int32_t yvect); fixed_t gethiq16angle(int32_t xvect, int32_t yvect); -static FORCE_INLINE fixed_t getq16angle(int32_t xvect, int32_t yvect) -{ - return IntToFixed(getangle(xvect, yvect)); -} - static FORCE_INLINE constexpr uint32_t uhypsq(int32_t const dx, int32_t const dy) { return (uint32_t)dx*dx + (uint32_t)dy*dy; diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index 41c151db6..22b8e912f 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -45,8 +45,6 @@ enum { extern float curpolygonoffset; -extern int32_t polymostcenterhoriz; - extern int16_t globalpicnum; #define POLYMOST_CHOOSE_FOG_PAL(fogpal, pal) \ diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index e80f081a3..6aa23f294 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -45,7 +45,6 @@ int32_t r_rortexture = 0; int32_t r_rortexturerange = 0; int32_t r_rorphase = 0; int32_t mdtims, omdtims; -int32_t polymostcenterhoriz = 100; float fcosglobalang, fsinglobalang; float fxdim, fydim, fydimen, fviewingrange; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index bdc40a126..fd3054376 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2485,7 +2485,7 @@ void polymost_drawrooms() ghalfy = (float)(ydimen>>1); grhalfxdown10 = 1.f/(ghalfx*1024.f); ghoriz = FixedToFloat(qglobalhoriz); - ghorizcorrect = FixedToFloat((100-polymostcenterhoriz)*divscale16(xdimenscale, viewingrange)); + ghorizcorrect = FixedToFloat(divscale16(xdimenscale, viewingrange)); GLInterface.SetShadeInterpolate(hw_shadeinterpolate); @@ -2885,7 +2885,7 @@ void polymost_prepareMirror(int32_t dax, int32_t day, int32_t daz, fixed_t daang ghalfy = (float)(ydimen>>1); grhalfxdown10 = 1.f/(ghalfx*1024.f); ghoriz = FixedToFloat(qglobalhoriz); - ghorizcorrect = FixedToFloat((100-polymostcenterhoriz)*divscale16(xdimenscale, viewingrange)); + ghorizcorrect = FixedToFloat(divscale16(xdimenscale, viewingrange)); resizeglcheck(); if (r_yshearing) { diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index b0f9aba90..cf89415e5 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1446,3 +1446,274 @@ void LoadDefinitions() } +//--------------------------------------------------------------------------- +// +// code fron gameexec/conrun +// +//--------------------------------------------------------------------------- + +int getincangle(int a, int na) +{ + a &= 2047; + na &= 2047; + + if(abs(a-na) < 1024) + return (na-a); + else + { + if(na > 1024) na -= 2048; + if(a > 1024) a -= 2048; + + na -= 2048; + a -= 2048; + return (na-a); + } +} + +fixed_t getincangleq16(fixed_t a, fixed_t na) +{ + a &= 0x7FFFFFF; + na &= 0x7FFFFFF; + + if(abs(a-na) < IntToFixed(1024)) + return (na-a); + else + { + if(na > IntToFixed(1024)) na -= IntToFixed(2048); + if(a > IntToFixed(1024)) a -= IntToFixed(2048); + + na -= IntToFixed(2048); + a -= IntToFixed(2048); + return (na-a); + } +} + +//--------------------------------------------------------------------------- +// +// Player's horizon function, called from game's ticker or from gi->GetInput() as required. +// +//--------------------------------------------------------------------------- + +void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust) +{ + // Calculate adjustment as true pitch (Fixed point math really sucks...) + double horizAngle = atan2(*q16horiz - IntToFixed(100), IntToFixed(128)) * (512. / pi::pi()); + + if (q16horz) + { + *actions &= ~SB_CENTERVIEW; + horizAngle = clamp(horizAngle + FixedToFloat(q16horz), -180, 180); + } + + // this is the locked type + if (*actions & (SB_AIM_UP|SB_AIM_DOWN)) + { + *actions &= ~SB_CENTERVIEW; + double const amount = 250. / GameTicRate; + + if (*actions & SB_AIM_DOWN) + horizAngle -= scaleAdjust * amount; + + if (*actions & SB_AIM_UP) + horizAngle += scaleAdjust * amount; + } + + // this is the unlocked type + if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN)) + { + *actions |= SB_CENTERVIEW; + double const amount = 500. / GameTicRate; + + if (*actions & SB_LOOK_DOWN) + horizAngle -= scaleAdjust * amount; + + if (*actions & SB_LOOK_UP) + horizAngle += scaleAdjust * amount; + } + + // convert back to Build's horizon + *q16horiz = IntToFixed(100) + xs_CRoundToInt(IntToFixed(128) * tan(horizAngle * (pi::pi() / 512.))); + + // return to center if conditions met. + if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) + { + if (*q16horiz < FloatToFixed(99.75) || *q16horiz > FloatToFixed(100.25)) + { + // move *q16horiz back to 100 + *q16horiz += xs_CRoundToInt(scaleAdjust * (((1000. / GameTicRate) * FRACUNIT) - (*q16horiz * (10. / GameTicRate)))); + } + else + { + // not looking anymore because *q16horiz is back at 100 + *q16horiz = IntToFixed(100); + *actions &= ~SB_CENTERVIEW; + } + } + + // clamp before returning + *q16horiz = clamp(*q16horiz, gi->playerHorizMin(), gi->playerHorizMax()); +} + +//--------------------------------------------------------------------------- +// +// Player's angle function, called from game's ticker or from gi->GetInput() as required. +// +//--------------------------------------------------------------------------- + +void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching) +{ + // return q16rotscrnang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384) + *q16rotscrnang -= xs_CRoundToInt(scaleAdjust * (*q16rotscrnang * (15. / GameTicRate))); + if (abs(*q16rotscrnang) < (FRACUNIT >> 2)) *q16rotscrnang = 0; + + // return q16look_ang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384) + *q16look_ang -= xs_CRoundToInt(scaleAdjust * (*q16look_ang * (7.5 / GameTicRate))); + if (abs(*q16look_ang) < (FRACUNIT >> 2)) *q16look_ang = 0; + + if (*actions & SB_LOOK_LEFT) + { + // start looking left + *q16look_ang -= FloatToFixed(scaleAdjust * (4560. / GameTicRate)); + *q16rotscrnang += FloatToFixed(scaleAdjust * (720. / GameTicRate)); + } + + if (*actions & SB_LOOK_RIGHT) + { + // start looking right + *q16look_ang += FloatToFixed(scaleAdjust * (4560. / GameTicRate)); + *q16rotscrnang -= FloatToFixed(scaleAdjust * (720. / GameTicRate)); + } + + if (*actions & SB_TURNAROUND) + { + if (*spin == 0) + { + // currently not spinning, so start a spin + *spin = IntToFixed(-1024); + } + *actions &= ~SB_TURNAROUND; + } + + if (*spin < 0) + { + // return spin to 0 + fixed_t add = FloatToFixed(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate)); + *spin += add; + if (*spin > 0) + { + // Don't overshoot our target. With variable factor this is possible. + add -= *spin; + *spin = 0; + } + *q16ang += add; + } + + if (q16avel) + { + // add player's input + *q16ang = (*q16ang + q16avel) & 0x7FFFFFF; + } +} + +//--------------------------------------------------------------------------- +// +// Player's ticrate helper functions. +// +//--------------------------------------------------------------------------- + +void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment) +{ + if (!cl_syncinput) + { + *helper += adjustment; + } + else + { + *q16ang = (*q16ang + FloatToFixed(adjustment)) & 0x7FFFFFF; + } +} + +void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment) +{ + if (!cl_syncinput) + { + // Add slight offset if adjustment is coming in as absolute 0. + if (adjustment == 0) adjustment += (1. / (FRACUNIT >> 1)); + + *helper = *q16ang + getincangleq16(*q16ang, FloatToFixed(adjustment)); + } + else + { + *q16ang = FloatToFixed(adjustment); + } +} + +void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment) +{ + if (!cl_syncinput) + { + *helper += adjustment; + } + else + { + *q16horiz += FloatToFixed(adjustment); + } +} + +void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment) +{ + if (!cl_syncinput) + { + // Add slight offset if adjustment is coming in as absolute 0. + if (adjustment == 0) adjustment += (1. / (FRACUNIT >> 1)); + + *helper = FloatToFixed(adjustment); + } + else + { + *q16horiz = FloatToFixed(adjustment); + } +} + +//--------------------------------------------------------------------------- +// +// Player's ticrate helper processor. +// +//--------------------------------------------------------------------------- + +void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, fixed_t* q16horiz, double* horizAdjust, fixed_t* horizTarget, double const scaleAdjust) +{ + // Process angle amendments from the game's ticker. + if (*angTarget) + { + fixed_t angDelta = getincangleq16(*q16ang, *angTarget); + *q16ang = (*q16ang + xs_CRoundToInt(scaleAdjust * angDelta)); + + if (abs(*q16ang - *angTarget) < FRACUNIT) + { + *q16ang = *angTarget; + *angTarget = 0; + } + } + else if (*angAdjust) + { + *q16ang = (*q16ang + FloatToFixed(scaleAdjust * *angAdjust)) & 0x7FFFFFF; + } + + // Process horizon amendments from the game's ticker. + if (*horizTarget) + { + fixed_t horizDelta = *horizTarget - *q16horiz; + *q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta); + + if (abs(*q16horiz - *horizTarget) < FRACUNIT) + { + *q16horiz = *horizTarget; + *horizTarget = 0; + } + } + else if (*horizAdjust) + { + *q16horiz += FloatToFixed(scaleAdjust * *horizAdjust); + } +} diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 9632dd40e..fc92a6f1b 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -11,6 +11,7 @@ #include "stats.h" #include "i_time.h" #include "palentry.h" +#include "pragmas.h" extern FString currentGame; extern FString LumpFilter; @@ -63,6 +64,17 @@ void DeferedStartGame(MapRecord* map, int skill); void ChangeLevel(MapRecord* map, int skill); void CompleteLevel(MapRecord* map); +int getincangle(int c, int n); +fixed_t getincangleq16(fixed_t c, fixed_t n); + +void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust); +void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching); +void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment); +void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment); +void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment); +void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment); +void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, fixed_t* q16horiz, double* horizAdjust, fixed_t* horizTarget, double const scaleAdjust); + struct UserConfig { FString gamegrp; @@ -224,3 +236,13 @@ extern int chatmodeon; extern bool sendPause; extern int lastTic; +//--------------------------------------------------------------------------- +// +// Return half player's q16look_ang directly or interpolated as required. +// +//--------------------------------------------------------------------------- + +inline double getHalfLookAng(fixed_t const oq16look_ang, fixed_t const q16look_ang, bool interpolate, double smoothratio) +{ + return (!interpolate ? q16look_ang : oq16look_ang + fmulscale16(q16look_ang - oq16look_ang, smoothratio)) * (0.5 / FRACUNIT); +} diff --git a/source/core/gamecvars.cpp b/source/core/gamecvars.cpp index a8951b08a..c7c4548f7 100644 --- a/source/core/gamecvars.cpp +++ b/source/core/gamecvars.cpp @@ -207,8 +207,6 @@ CUSTOM_CVARD(Int, r_fov, 90, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "change the field o else if (self > 140) self = 140; } -CVARD(Bool, r_horizcenter, false, CVAR_ARCHIVE, "enable/disable centered horizon line") // only present in Blood. - CVARD(Bool, in_mousemode, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "toggles vertical mouse view") CVAR(Bool, silentmouseaimtoggle, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index ae8dc6ccc..bcc11b94d 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -71,7 +71,6 @@ EXTERN_CVAR(Bool, am_nameontop) EXTERN_CVAR(Int, r_fov) -EXTERN_CVAR(Bool, r_horizcenter) EXTERN_CVAR(Int, r_drawweapon) EXTERN_CVAR(Int, r_showfps) EXTERN_CVAR(Int, r_showfpsperiod) diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 91aa9e9af..e4d442be0 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -108,6 +108,8 @@ struct GameInterface virtual void LevelCompleted(MapRecord* map, int skill) {} virtual bool DrawAutomapPlayer(int x, int y, int z, int a) { return false; } virtual void SetTileProps(int tile, int surf, int vox, int shade) {} + virtual fixed_t playerHorizMin() { return IntToFixed(-99); } + virtual fixed_t playerHorizMax() { return IntToFixed(299); } virtual FString statFPS() { diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 18827e30a..8cd209610 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -50,10 +50,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -extern short bPlayerPan; -extern short bLockPan; - - static MapRecord* NextMap; void uploadCinemaPalettes(); @@ -339,7 +335,6 @@ void GameInterface::Ticker() } else if (EndLevel == 0) { - nPlayerDAng += localInput.q16avel; inita &= kAngleMask; for (int i = 0; i < 4; i++) @@ -421,34 +416,24 @@ void GameInterface::Ticker() } } - if (localInput.actions & SB_CENTERVIEW) - { - bLockPan = false; - bPlayerPan = false; - //PlayerList[nLocalPlayer].q16horiz = IntToFixed(92); - nDestVertPan[nLocalPlayer] = IntToFixed(92); - } - if (localInput.actions & SB_TURNAROUND) - { - // todo - } - - sPlayerInput[nLocalPlayer].xVel = lPlayerXVel; sPlayerInput[nLocalPlayer].yVel = lPlayerYVel; // make weapon selection persist until it gets used up. sPlayerInput[nLocalPlayer].buttons = lLocalCodes; int weap = sPlayerInput[nLocalPlayer].getNewWeapon(); - sPlayerInput[nLocalPlayer].actions = localInput.actions; if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap); sPlayerInput[nLocalPlayer].nTarget = besttarget; + auto oldactions = sPlayerInput[nLocalPlayer].actions; + sPlayerInput[nLocalPlayer].actions = localInput.actions; + if (oldactions & SB_CENTERVIEW) sPlayerInput[nLocalPlayer].actions |= SB_CENTERVIEW; + + sPlayerInput[nLocalPlayer].nAngle = localInput.q16avel; + sPlayerInput[nLocalPlayer].pan = localInput.q16horz; + Ra[nLocalPlayer].nTarget = besttarget; lLocalCodes = 0; - nPlayerDAng = 0; - - sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz; leveltime++; if (leveltime == 2) gameaction = ga_autosave; // let the game run for 1 frame before saving. @@ -525,7 +510,6 @@ void GameInterface::app_init() TileFiles.SetBackup(); - InitView(); InitFX(); seq_LoadSequences(); InitStatus(); diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index d4a5113ba..113f9d764 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -260,7 +260,8 @@ struct GameInterface : ::GameInterface void LevelCompleted(MapRecord *map, int skill) override; void NextLevel(MapRecord *map, int skill) override; bool DrawAutomapPlayer(int x, int y, int z, int a) override; - + fixed_t playerHorizMin() override { return IntToFixed(-50); } + fixed_t playerHorizMax() override { return IntToFixed(250); } ::GameStats getStats() override; }; diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index dd73b7ab3..0ba7359fe 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -102,8 +102,13 @@ void GameInterface::Render() DrawClock(); } - DrawView(calc_smoothratio()); + double const smoothratio = calc_smoothratio(); + double const look_anghalf = getHalfLookAng(PlayerList[nLocalPlayer].oq16look_ang, PlayerList[nLocalPlayer].q16look_ang, cl_syncinput, smoothratio); + + DrawView(smoothratio); DrawStatusBar(); + DrawCrosshair(MAXTILES, PlayerList[nLocalPlayer].nHealth >> 3, -look_anghalf, 0, 1); + if (paused && !M_Active()) { auto tex = GStrings("TXTB_PAUSED"); diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 00789f297..c6afa4fb8 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -739,7 +739,7 @@ loc_flag: // loc_27266: case kWeaponSword: { - nHeight += (92 - FixedToInt(sPlayerInput[nPlayer].horizon)) << 6; + nHeight += (IntToFixed(100) - PlayerList[nLocalPlayer].q16horiz) >> 10; theZ += nHeight; @@ -844,7 +844,7 @@ loc_flag: } case kWeaponPistol: { - int var_50 = (FixedToInt(sPlayerInput[nPlayer].horizon) - 92) << 2; + int var_50 = (PlayerList[nLocalPlayer].q16horiz - IntToFixed(100)) >> 14; nHeight -= var_50; if (sPlayerInput[nPlayer].nTarget >= 0 && cl_autoaim) @@ -859,7 +859,7 @@ loc_flag: case kWeaponGrenade: { - ThrowGrenade(nPlayer, ebp, ebx, nHeight - 2560, FixedToInt(sPlayerInput[nPlayer].horizon) - 92); + ThrowGrenade(nPlayer, ebp, ebx, nHeight - 2560, FixedToInt(PlayerList[nLocalPlayer].q16horiz) - 100); break; } case kWeaponStaff: @@ -985,6 +985,12 @@ void DrawWeapons(double smooth) nShade = sprite[PlayerList[nLocalPlayer].nSprite].shade; } + double const look_anghalf = getHalfLookAng(PlayerList[nLocalPlayer].oq16look_ang, PlayerList[nLocalPlayer].q16look_ang, cl_syncinput, smooth); + double const looking_arc = fabs(look_anghalf) / 4.5; + + xOffset -= look_anghalf; + yOffset += looking_arc; + seq_DrawGunSequence(var_28, PlayerList[nLocalPlayer].field_3FOUR, xOffset, yOffset, nShade, nPal); if (nWeapon != kWeaponM60) diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index ed9c7a40b..cc5f1e090 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -194,7 +194,6 @@ void InitLevel(int level) // todo: use a map record totalmoves = 0; GrabPalette(); ResetMoveFifo(); - nPlayerDAng = 0; lPlayerXVel = 0; lPlayerYVel = 0; movefifopos = movefifoend; diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index 0e2af7cf3..d8a99829f 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -17,20 +17,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //------------------------------------------------------------------------- #include "ns.h" #include "ps_input.h" -#include "engine.h" #include "exhumed.h" #include "player.h" -#include "aistuff.h" #include "status.h" #include "view.h" -#include "gamecontrol.h" -#include -#include "v_video.h" +#include "menu.h" BEGIN_PS_NS -extern short bPlayerPan; -extern short bLockPan; +static int turn; +static int counter; short nInputStack = 0; @@ -98,64 +94,40 @@ void CheckKeys2() } -static void PlayerInterruptKeys(bool after, ControlInfo* const hidInput) +static void processMovement(ControlInfo* const hidInput) { - static double lastInputTicks; - auto const currentHiTicks = I_msTimeF(); - double const elapsedInputTicks = currentHiTicks - lastInputTicks; - - lastInputTicks = currentHiTicks; - - auto scaleAdjustmentToInterval = [=](double x) { return x * (120 / 4) / (1000.0 / elapsedInputTicks); }; - - if (paused) - return; - - InputPacket tempinput{}; - fixed_t input_angle = 0; - - if (!after) - { - localInput = {}; - ApplyGlobalInput(localInput, hidInput); - if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN; - } - - if (PlayerList[nLocalPlayer].nHealth == 0) - { - lPlayerYVel = 0; - lPlayerXVel = 0; - nPlayerDAng = 0; - return; - } - // JBF: Run key behaviour is selectable int const playerRunning = !!(localInput.actions & SB_RUN); int const turnAmount = playerRunning ? 12 : 8; int const keyMove = playerRunning ? 12 : 6; + bool const mouseaim = !(localInput.actions & SB_AIMMODE); + double const scaleAdjust = InputScale(); + InputPacket tempinput {}; if (buttonMap.ButtonDown(gamefunc_Strafe)) { - tempinput.svel -= hidInput->mousex * 4.f; - tempinput.svel -= hidInput->dyaw * keyMove; + tempinput.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove))); } else { - input_angle += FloatToFixed(hidInput->mousex + scaleAdjustmentToInterval(hidInput->dyaw)); + tempinput.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); } - bool mouseaim = !(localInput.actions & SB_AIMMODE); - if (mouseaim) + { tempinput.q16horz += FloatToFixed(hidInput->mousey); + } else - tempinput.fvel -= hidInput->mousey * 8.f; + { + tempinput.fvel -= xs_CRoundToInt(hidInput->mousey * 8.); + } - if (!in_mouseflip) tempinput.q16horz = -tempinput.q16horz; + if (!in_mouseflip) + tempinput.q16horz = -tempinput.q16horz; - tempinput.q16horz -= FloatToFixed(scaleAdjustmentToInterval(hidInput->dpitch)); - tempinput.svel -= hidInput->dx * keyMove; - tempinput.fvel -= hidInput->dz * keyMove; + tempinput.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); + tempinput.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove)); + tempinput.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove)); if (buttonMap.ButtonDown(gamefunc_Strafe)) { @@ -167,9 +139,6 @@ static void PlayerInterruptKeys(bool after, ControlInfo* const hidInput) } else { - static int turn = 0; - static int counter = 0; - // normal, non strafing movement if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turn -= 2; @@ -200,7 +169,7 @@ static void PlayerInterruptKeys(bool after, ControlInfo* const hidInput) } //if ((counter++) % 4 == 0) // what was this for??? - input_angle += FloatToFixed(scaleAdjustmentToInterval(turn * 2)); + tempinput.q16avel += FloatToFixed(scaleAdjust * (turn * 2)); } @@ -218,81 +187,48 @@ static void PlayerInterruptKeys(bool after, ControlInfo* const hidInput) localInput.fvel = clamp(localInput.fvel + tempinput.fvel, -12, 12); localInput.svel = clamp(localInput.svel + tempinput.svel, -12, 12); - localInput.q16avel += input_angle; + localInput.q16avel += tempinput.q16avel; + localInput.q16horz += tempinput.q16horz; - if (!nFreeze) + if (!cl_syncinput) { - PlayerList[nLocalPlayer].q16angle = (PlayerList[nLocalPlayer].q16angle + input_angle) & 0x7FFFFFF; + Player* pPlayer = &PlayerList[nLocalPlayer]; - // A horiz diff of 128 equal 45 degrees, - // so we convert horiz to 1024 angle units - - float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - IntToFixed(92), IntToFixed(128)) * (512.f / fPI) + FixedToFloat(tempinput.q16horz), -255.f, 255.f); - auto newq16horiz = IntToFixed(92) + xs_CRoundToInt(IntToFixed(128) * tanf(horizAngle * (fPI / 512.f))); - if (PlayerList[nLocalPlayer].q16horiz != newq16horiz) + if (!nFreeze) { - bLockPan = true; - PlayerList[nLocalPlayer].q16horiz = newq16horiz; - nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz; + applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, tempinput.q16avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080); + sethorizon(&pPlayer->q16horiz, tempinput.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); + UpdatePlayerSpriteAngle(pPlayer); } - // Look/aim up/down functions. - if (localInput.actions & (SB_LOOK_UP|SB_AIM_UP)) - { - bLockPan |= (localInput.actions & SB_LOOK_UP); - if (PlayerList[nLocalPlayer].q16horiz < IntToFixed(180)) { - PlayerList[nLocalPlayer].q16horiz += FloatToFixed(scaleAdjustmentToInterval(4)); - } - - bPlayerPan = true; - nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz; - } - else if (localInput.actions & (SB_LOOK_DOWN|SB_AIM_DOWN)) - { - bLockPan |= (localInput.actions & SB_LOOK_DOWN); - if (PlayerList[nLocalPlayer].q16horiz > IntToFixed(4)) { - PlayerList[nLocalPlayer].q16horiz -= FloatToFixed(scaleAdjustmentToInterval(4)); - } - - bPlayerPan = true; - nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz; - } + playerProcessHelpers(&pPlayer->q16angle, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); } - - // loc_1C048: - if (totalvel[nLocalPlayer] > 20) { - bPlayerPan = false; - } - if (nFreeze) return; - - // loc_1C05E - fixed_t dVertPan = nDestVertPan[nLocalPlayer] - PlayerList[nLocalPlayer].q16horiz; - if (dVertPan != 0 && !bLockPan) - { - int val = dVertPan / 4; - if (abs(val) >= 4) - { - if (val >= 4) - PlayerList[nLocalPlayer].q16horiz += IntToFixed(4); - else if (val <= -4) - PlayerList[nLocalPlayer].q16horiz -= IntToFixed(4); - } - else if (abs(dVertPan) >= FRACUNIT) - PlayerList[nLocalPlayer].q16horiz += dVertPan / 2.0f; - else - { - if (mouseaim) bLockPan = true; - PlayerList[nLocalPlayer].q16horiz = nDestVertPan[nLocalPlayer]; - } - } - else bLockPan = mouseaim; - PlayerList[nLocalPlayer].q16horiz = clamp(PlayerList[nLocalPlayer].q16horiz, 0, IntToFixed(184)); } void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { - PlayerInterruptKeys(packet == nullptr, hidInput); + if (paused || M_Active()) + { + localInput = {}; + return; + } + + if (PlayerList[nLocalPlayer].nHealth == 0) + { + lPlayerYVel = 0; + lPlayerXVel = 0; + return; + } + + if (packet != nullptr) + { + localInput = {}; + ApplyGlobalInput(localInput, hidInput); + if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN; + } + + processMovement(hidInput); if (packet) *packet = localInput; } diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index f13651971..26cd14d6f 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -51,10 +51,7 @@ struct PlayerSave int lPlayerXVel = 0; int lPlayerYVel = 0; -fixed_t nPlayerDAng = 0; short obobangle = 0, bobangle = 0; -short bPlayerPan = 0; -short bLockPan = 0; static actionSeq ActionSeq[] = { {18, 0}, {0, 0}, {9, 0}, {27, 0}, {63, 0}, @@ -338,6 +335,10 @@ void RestartPlayer(short nPlayer) } PlayerList[nPlayer].opos = sprite[nSprite].pos; + PlayerList[nPlayer].oq16angle = PlayerList[nPlayer].q16angle; + PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz; + PlayerList[nPlayer].oq16look_ang = PlayerList[nPlayer].q16look_ang = 0; + PlayerList[nPlayer].oq16rotscrnang = PlayerList[nPlayer].q16rotscrnang = 0; nPlayerFloorSprite[nPlayer] = floorspr; @@ -437,8 +438,7 @@ void RestartPlayer(short nPlayer) nYDamage[nPlayer] = 0; nXDamage[nPlayer] = 0; - PlayerList[nPlayer].q16horiz = IntToFixed(92); - nDestVertPan[nPlayer] = IntToFixed(92); + PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz = IntToFixed(100); nBreathTimer[nPlayer] = 90; nTauntTimer[nPlayer] = RandomSize(3) + 3; @@ -455,13 +455,9 @@ void RestartPlayer(short nPlayer) if (nPlayer == nLocalPlayer) { nLocalSpr = nSprite; - nPlayerDAng = 0; SetMagicFrame(); RestoreGreenPal(); - - bPlayerPan = 0; - bLockPan = 0; } sprintf(playerNames[nPlayer], "JOE%d", nPlayer); @@ -539,7 +535,7 @@ void StartDeathSeq(int nPlayer, int nVal) StopFiringWeapon(nPlayer); - PlayerList[nPlayer].q16horiz = IntToFixed(92); + PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz = IntToFixed(100); oeyelevel[nPlayer] = eyelevel[nPlayer] = -14080; nPlayerInvisible[nPlayer] = 0; dVertPan[nPlayer] = 15; @@ -704,6 +700,11 @@ static void pickupMessage(int no) } } +void UpdatePlayerSpriteAngle(Player* pPlayer) +{ + sprite[pPlayer->nSprite].ang = FixedToInt(pPlayer->q16angle); +} + void FuncPlayer(int a, int nDamage, int nRun) { int var_48 = 0; @@ -725,6 +726,10 @@ void FuncPlayer(int a, int nDamage, int nRun) short nSprite2; PlayerList[nPlayer].opos = sprite[nPlayerSprite].pos; + PlayerList[nPlayer].oq16angle = PlayerList[nPlayer].q16angle; + PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz; + PlayerList[nPlayer].oq16look_ang = PlayerList[nPlayer].q16look_ang; + PlayerList[nPlayer].oq16rotscrnang = PlayerList[nPlayer].q16rotscrnang; oeyelevel[nPlayer] = eyelevel[nPlayer]; switch (nMessage) @@ -938,7 +943,12 @@ void FuncPlayer(int a, int nDamage, int nRun) } // loc_1A494: - sprite[nPlayerSprite].ang = FixedToInt(PlayerList[nPlayer].q16angle); + if (cl_syncinput) + { + Player* pPlayer = &PlayerList[nPlayer]; + applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions, 1, eyelevel[nLocalPlayer] > -14080); + UpdatePlayerSpriteAngle(pPlayer); + } // sprite[nPlayerSprite].zvel is modified within Gravity() short zVel = sprite[nPlayerSprite].zvel; @@ -1033,10 +1043,13 @@ void FuncPlayer(int a, int nDamage, int nRun) { if (nTotalPlayers <= 1) { - PlayerList[nPlayer].q16angle = IntToFixed(GetAngleToSprite(nPlayerSprite, nSpiritSprite) & kAngleMask); - sprite[nPlayerSprite].ang = FixedToInt(PlayerList[nPlayer].q16angle); + auto ang = GetAngleToSprite(nPlayerSprite, nSpiritSprite) & kAngleMask; + playerSetAngle(&PlayerList[nPlayer].q16angle, &PlayerList[nPlayer].angTarget, ang); + PlayerList[nPlayer].oq16angle = PlayerList[nPlayer].q16angle; + sprite[nPlayerSprite].ang = ang; - PlayerList[nPlayer].q16horiz = IntToFixed(92); + playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 100); + PlayerList[nPlayer].oq16horiz = PlayerList[nPlayer].q16horiz; lPlayerXVel = 0; lPlayerYVel = 0; @@ -1045,8 +1058,6 @@ void FuncPlayer(int a, int nDamage, int nRun) sprite[nPlayerSprite].yvel = 0; sprite[nPlayerSprite].zvel = 0; - nPlayerDAng = 0; - if (nFreeze < 1) { nFreeze = 1; @@ -1054,15 +1065,15 @@ void FuncPlayer(int a, int nDamage, int nRun) StopLocalSound(); InitSpiritHead(); - nDestVertPan[nPlayer] = IntToFixed(92); + playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 100); if (currentLevel->levelNumber == 11) { - nDestVertPan[nPlayer] += IntToFixed(46); + playerAddHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizAdjust, 46); } else { - nDestVertPan[nPlayer] += IntToFixed(11); + playerAddHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizAdjust, 11); } } } @@ -1090,8 +1101,8 @@ void FuncPlayer(int a, int nDamage, int nRun) zVelB = -zVelB; } - if (zVelB > 512 && !bLockPan) { - nDestVertPan[nPlayer] = IntToFixed(92); + if (zVelB > 512 && PlayerList[nPlayer].q16angle != IntToFixed(100) && !(sPlayerInput[nPlayer].actions & (SB_AIM_UP|SB_AIM_DOWN))) { + sPlayerInput[nPlayer].actions |= SB_CENTERVIEW; } } @@ -1190,21 +1201,6 @@ void FuncPlayer(int a, int nDamage, int nRun) } loc_1AB8E: - if (!bPlayerPan && !bLockPan) - { - fixed_t nPanVal = IntToFixed(spr_z - sprite[nPlayerSprite].z) / 32 + IntToFixed(92); - - if (nPanVal < 0) { - nPanVal = 0; - } - else if (nPanVal > IntToFixed(183)) - { - nPanVal = IntToFixed(183); - } - - nDestVertPan[nPlayer] = nPanVal; - } - playerX -= sprite[nPlayerSprite].x; playerY -= sprite[nPlayerSprite].y; @@ -2673,6 +2669,12 @@ loc_1BD2E: PlayerList[nPlayer].nAction = nActionB; PlayerList[nPlayer].field_2 = 0; } + + if (cl_syncinput) + { + Player* pPlayer = &PlayerList[nPlayer]; + sethorizon(&pPlayer->q16horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions, 1); + } } else // else, player's health is less than 0 { @@ -2791,19 +2793,20 @@ loc_1BD2E: } else { - if (PlayerList[nPlayer].q16horiz < IntToFixed(92)) + if (PlayerList[nPlayer].q16horiz < IntToFixed(100)) { - PlayerList[nPlayer].q16horiz = IntToFixed(91); + playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, 100); eyelevel[nPlayer] -= (dVertPan[nPlayer] << 8); } else { - PlayerList[nPlayer].q16horiz += IntToFixed(dVertPan[nPlayer]); - if (PlayerList[nPlayer].q16horiz >= IntToFixed(200)) + playerAddHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizAdjust, dVertPan[nPlayer]); + + if (PlayerList[nPlayer].q16horiz > gi->playerHorizMax()) { - PlayerList[nPlayer].q16horiz = IntToFixed(199); + playerSetHoriz(&PlayerList[nPlayer].q16horiz, &PlayerList[nPlayer].horizTarget, gi->playerHorizMax()); } - else if (PlayerList[nPlayer].q16horiz <= IntToFixed(92)) + else if (PlayerList[nPlayer].q16horiz <= IntToFixed(100)) { if (!(SectFlag[sprite[nPlayerSprite].sectnum] & kSectUnderwater)) { @@ -2842,11 +2845,8 @@ loc_1BD2E: static SavegameHelper sgh("player", SV(lPlayerXVel), SV(lPlayerYVel), - SV(nPlayerDAng), SV(obobangle), SV(bobangle), - SV(bPlayerPan), - SV(bLockPan), SV(nStandHeight), SV(PlayerCount), SV(nNetStartSprites), diff --git a/source/exhumed/src/player.h b/source/exhumed/src/player.h index 7c1989572..40293001a 100644 --- a/source/exhumed/src/player.h +++ b/source/exhumed/src/player.h @@ -43,7 +43,6 @@ extern int nLocalPlayer; extern int lPlayerXVel; extern int lPlayerYVel; -extern fixed_t nPlayerDAng; struct Player { @@ -70,8 +69,13 @@ struct Player short field_3C; short nRun; - fixed_t q16angle; - fixed_t q16horiz; + fixed_t oq16angle, q16angle; + fixed_t oq16horiz, q16horiz; + fixed_t oq16look_ang, q16look_ang; + fixed_t oq16rotscrnang, q16rotscrnang; + fixed_t spin; + fixed_t angTarget, horizTarget; + double angAdjust, horizAdjust; vec3_t opos; }; @@ -122,6 +126,7 @@ short GetPlayerFromSprite(short nSprite); void SetPlayerMummified(int nPlayer, int bIsMummified); int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount); void ShootStaff(int nPlayer); +void UpdatePlayerSpriteAngle(Player* pPlayer); END_PS_NS diff --git a/source/exhumed/src/ps_input.h b/source/exhumed/src/ps_input.h index 564fc7359..9ecc7f9f8 100644 --- a/source/exhumed/src/ps_input.h +++ b/source/exhumed/src/ps_input.h @@ -38,7 +38,8 @@ struct PlayerInput int yVel; uint16_t buttons; short nTarget; - fixed_t horizon; + fixed_t nAngle; + fixed_t pan; int8_t nItem; ESyncBits actions; diff --git a/source/exhumed/src/ramses.cpp b/source/exhumed/src/ramses.cpp index 0e5ec0e04..f3a2f2647 100644 --- a/source/exhumed/src/ramses.cpp +++ b/source/exhumed/src/ramses.cpp @@ -209,7 +209,7 @@ void DoSpiritHead() { static short dimSectCount = 0; - PlayerList[0].q16horiz += (nDestVertPan[0] - PlayerList[0].q16horiz) / 4; + PlayerList[0].q16horiz += PlayerList[0].q16horiz / 4; TileFiles.InvalidateTile(kTileRamsesWorkTile); int totalclock = leveltime * 4; diff --git a/source/exhumed/src/sequence.cpp b/source/exhumed/src/sequence.cpp index 64914b19b..5c795ed23 100644 --- a/source/exhumed/src/sequence.cpp +++ b/source/exhumed/src/sequence.cpp @@ -376,7 +376,7 @@ void seq_DrawPilotLightSeq(double xOffset, double yOffset) double x = ChunkXpos[nFrameBase] + (160 + xOffset); double y = ChunkYpos[nFrameBase] + (100 + yOffset); - hud_drawsprite(x, y, 65536, fmod(-2 * FixedToFloat(nPlayerDAng), kAngleMask + 1), nTile, 0, 0, 1); + hud_drawsprite(x, y, 65536, fmod(-2 * FixedToFloat(PlayerList[nLocalPlayer].q16angle), kAngleMask + 1), nTile, 0, 0, 1); nFrameBase++; } } diff --git a/source/exhumed/src/status.cpp b/source/exhumed/src/status.cpp index 7bed57d37..dde120f70 100644 --- a/source/exhumed/src/status.cpp +++ b/source/exhumed/src/status.cpp @@ -1002,7 +1002,6 @@ void DrawStatusBar() } DExhumedStatusBar sbar; sbar.Draw(); - DrawCrosshair(MAXTILES, PlayerList[nLocalPlayer].nHealth >> 3, 0, 0, 1); } diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index d47302a17..a5702401f 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -36,7 +36,6 @@ short bSubTitles = true; int zbob; -fixed_t nDestVertPan[kMaxPlayers] = { 0 }; short dVertPan[kMaxPlayers]; int nCamerax; int nCameray; @@ -120,11 +119,6 @@ void viewRestoreInterpolations(void) //Stick at end of drawscreen for (; i>=0; i--) *curipos[i] = bakipos[i]; } -void InitView() -{ - polymostcenterhoriz = 92; -} - // NOTE - not to be confused with Ken's analyzesprites() static void analyzesprites() { @@ -243,6 +237,9 @@ void DrawView(double smoothRatio, bool sceneonly) short nSector; fixed_t nAngle; fixed_t pan; + fixed_t q16rotscrnang; + + fixed_t dang = IntToFixed(1024); zbob = Sin(2 * bobangle) >> 3; @@ -282,13 +279,32 @@ void DrawView(double smoothRatio, bool sceneonly) + interpolate16(oeyelevel[nLocalPlayer], eyelevel[nLocalPlayer], smoothRatio); nSector = nPlayerViewSect[nLocalPlayer]; updatesector(playerX, playerY, &nSector); - nAngle = PlayerList[nLocalPlayer].q16angle; + + if (!cl_syncinput) + { + nAngle = PlayerList[nLocalPlayer].q16angle + PlayerList[nLocalPlayer].q16look_ang; + q16rotscrnang = PlayerList[nLocalPlayer].q16rotscrnang; + } + else + { + fixed_t oang, ang; + + oang = PlayerList[nLocalPlayer].oq16angle + PlayerList[nLocalPlayer].oq16look_ang; + ang = PlayerList[nLocalPlayer].q16angle + PlayerList[nLocalPlayer].q16look_ang; + nAngle = oang + xs_CRoundToInt(fmulscale16(((ang + dang - oang) & 0x7FFFFFF) - dang, smoothRatio)); + + oang = PlayerList[nLocalPlayer].oq16rotscrnang + PlayerList[nLocalPlayer].oq16rotscrnang; + ang = PlayerList[nLocalPlayer].q16rotscrnang + PlayerList[nLocalPlayer].q16rotscrnang; + q16rotscrnang = oang + xs_CRoundToInt(fmulscale16(((ang + dang - oang) & 0x7FFFFFF) - dang, smoothRatio)); + } if (!bCamera) { sprite[nPlayerSprite].cstat |= CSTAT_SPRITE_INVISIBLE; sprite[nDoppleSprite[nLocalPlayer]].cstat |= CSTAT_SPRITE_INVISIBLE; } + + renderSetRollAngle(FixedToFloat(q16rotscrnang)); } nCameraa = nAngle; @@ -297,7 +313,7 @@ void DrawView(double smoothRatio, bool sceneonly) { if (nSnakeCam >= 0 && !sceneonly) { - pan = IntToFixed(92); + pan = IntToFixed(100); viewz = playerZ; } else @@ -305,7 +321,14 @@ void DrawView(double smoothRatio, bool sceneonly) viewz = playerZ + nQuake[nLocalPlayer]; int floorZ = sector[sprite[nPlayerSprite].sectnum].floorz; - pan = PlayerList[nLocalPlayer].q16horiz; + if (!cl_syncinput) + { + pan = PlayerList[nLocalPlayer].q16horiz; + } + else + { + pan = PlayerList[nLocalPlayer].oq16horiz + xs_CRoundToInt(fmulscale16(PlayerList[nLocalPlayer].q16horiz - PlayerList[nLocalPlayer].oq16horiz, smoothRatio)); + } if (viewz > floorZ) viewz = floorZ; @@ -321,7 +344,7 @@ void DrawView(double smoothRatio, bool sceneonly) -2000 * Sin(inita), 4, 0, 0, CLIPMASK1); - pan = IntToFixed(92); + pan = IntToFixed(100); viewz = playerZ; } @@ -502,7 +525,6 @@ static SavegameHelper sgh("view", SV(viewz), SV(enemy), SV(nEnemyPal), - SA(nDestVertPan), SA(dVertPan), SA(nQuake), SV(g_interpolationCnt), diff --git a/source/exhumed/src/view.h b/source/exhumed/src/view.h index 7343a51cd..c537bd99a 100644 --- a/source/exhumed/src/view.h +++ b/source/exhumed/src/view.h @@ -27,7 +27,6 @@ extern short bSubTitles; extern short besttarget; extern short bCamera; -void InitView(); void DrawStatusBar(); void DrawView(double smoothRatio, bool sceneonly = false); void ResetView(); @@ -40,7 +39,6 @@ void viewDoInterpolations(int smoothRatio); void viewUpdateInterpolations(void); void viewRestoreInterpolations(void); -extern fixed_t nDestVertPan[]; extern short dVertPan[]; extern short nQuake[]; extern int nCamerax; diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index e8426b306..03d9c44b1 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -468,7 +468,7 @@ void moveplayers(void) //Players if (p->actorsqu >= 0) { - playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2); + playerAddAngle(&p->q16ang, &p->angAdjust, getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2); } if (s->extra > 0) @@ -491,7 +491,7 @@ void moveplayers(void) //Players if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS) { - playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1); + playerAddAngle(&p->q16ang, &p->angAdjust, getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1); } } s->ang = p->getang(); @@ -748,7 +748,7 @@ void movecrane(int i, int crane) s->owner = -2; ps[p].on_crane = i; S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].i); - playerSetAngle(&ps[p], s->ang + 1024); + playerSetAngle(&ps[p].q16ang, &ps[p].angTarget, s->ang + 1024); } else { @@ -2674,7 +2674,7 @@ void handle_se00(int i, int LASERLINE) { if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1) { - playerAddAngle(&ps[p], l * q); + playerAddAngle(&ps[p].q16ang, &ps[p].angAdjust, l * q); ps[p].posz += zchange; @@ -2866,7 +2866,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].bobposx += m; ps[p].bobposy += x; - playerAddAngle(&ps[p], q); + playerAddAngle(&ps[p].q16ang, &ps[p].angAdjust, q); if (numplayers > 1) { @@ -4667,31 +4667,6 @@ void handle_se130(int i, int countmax, int EXPLOSION2) } } - -//--------------------------------------------------------------------------- -// -// code fron gameexec/conrun -// -//--------------------------------------------------------------------------- - -int getincangle(int a,int na) -{ - a &= 2047; - na &= 2047; - - if(abs(a-na) < 1024) - return (na-a); - else - { - if(na > 1024) na -= 2048; - if(a > 1024) a -= 2048; - - na -= 2048; - a -= 2048; - return (na-a); - } -} - //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 04ccab479..f13d10cf3 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1852,8 +1852,8 @@ void moveweapons_d(void) if (s->picnum == SPIT) { - playerAddHoriz(&ps[p], 32); - ps[p].return_to_center = 8; + playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); + sync[p].actions |= SB_CENTERVIEW; if (ps[p].loogcnt == 0) { diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index f55e8b22d..79f60ecf0 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1399,8 +1399,8 @@ void moveweapons_r(void) guts_r(s, RABBITJIBC, 2, myconnectindex); } - playerAddHoriz(&ps[p], 32); - ps[p].return_to_center = 8; + playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); + sync[p].actions |= SB_CENTERVIEW; if (ps[p].loogcnt == 0) { diff --git a/source/games/duke/src/conlabeldef.h b/source/games/duke/src/conlabeldef.h index a842c4cee..a103d21b3 100644 --- a/source/games/duke/src/conlabeldef.h +++ b/source/games/duke/src/conlabeldef.h @@ -261,7 +261,6 @@ LABELS playerlabels[]= { "pals", PLAYER_PALS, LABEL_HASPARM2, 3 }, { "max_actors_killed", PLAYER_MAX_ACTORS_KILLED, 0, 0 }, { "actors_killed", PLAYER_ACTORS_KILLED, 0, 0 }, - { "return_to_center", PLAYER_RETURN_TO_CENTER, 0, 0 }, { "", -1, 0, 0 } // END OF LIST diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 8a857584c..eae5f08e3 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -109,7 +109,7 @@ void footprints(int snum); int makepainsounds(int snum, int type); void playerCrouch(int snum); void playerJump(int snum, int fz, int cz); -void applylook(int snum, double factor, fixed_t adjustment); +void processq16avel(player_struct* p, fixed_t* q16avel); void checklook(int snum, ESyncBits actions); void playerCenterView(int snum); void playerLookUp(int snum, ESyncBits actions); @@ -165,7 +165,6 @@ void execute(int s, int p, int d); void makeitfall(int s); int furthestangle(int snum, int angDiv); void getglobalz(int s); -int getincangle(int c, int n); void OnEvent(int id, int pnum = -1, int snum = -1, int dist = -1); short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, short s_ow, signed char s_ss); @@ -230,7 +229,6 @@ int playercolor2lookup(int color); void PlayerColorChanged(void); void apply_seasick(player_struct* p, double scalefactor); void calcviewpitch(player_struct* p, double factor); -void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment); bool movementBlocked(int snum); void loadcons(); void recordoldspritepos(); @@ -250,9 +248,4 @@ void resetinputhelpers(player_struct* p); void checkhardlanding(player_struct* p); void playerweaponsway(player_struct* p, spritetype* s); -void playerAddAngle(player_struct* p, int ang); -void playerSetAngle(player_struct* p, int ang); -void playerAddHoriz(player_struct* p, int horiz); -void playerSetHoriz(player_struct* p, int horiz); - END_DUKE_NS diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 999a09524..696b5d5bd 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -300,7 +300,7 @@ void drawoverlays(double smoothratio) if (ps[myconnectindex].newowner == -1 && ud.camerasprite == -1) { - DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -getHalfLookAng(screenpeek, cl_syncinput, smoothratio), 0, isRR() ? 0.5 : 1); + DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -getHalfLookAng(pp->oq16look_ang, pp->q16look_ang, cl_syncinput, smoothratio), 0, isRR() ? 0.5 : 1); } if (paused == 2) diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 1487a0d51..73e08e7e3 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -84,7 +84,7 @@ void fakebubbaspawn(int g_i, int g_p); void tearitup(int sect); void destroyit(int g_i); void mamaspawn(int g_i); -void forceplayerangle(struct player_struct* p); +void forceplayerangle(int snum); bool killthesprite = false; @@ -330,7 +330,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; case PLAYER_HORIZ: - if (bSet) playerSetHoriz(&ps[iPlayer], lValue); + if (bSet) playerSetHoriz(&ps[iPlayer].q16horiz, &ps[iPlayer].horizTarget, lValue); else SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horiz), sActor, sPlayer); break; @@ -452,7 +452,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; case PLAYER_ANG: - if (bSet) playerSetAngle(&ps[iPlayer], lValue); + if (bSet) playerSetAngle(&ps[iPlayer].q16ang, &ps[iPlayer].angTarget, lValue); else SetGameVarID((int)lVar2, ps[iPlayer].getang(), sActor, sPlayer); break; @@ -909,11 +909,6 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl else SetGameVarID((int)lVar2, ps[iPlayer].actors_killed, sActor, sPlayer); break; - case PLAYER_RETURN_TO_CENTER: - if (bSet) ps[iPlayer].return_to_center = lValue; - else SetGameVarID((int)lVar2, ps[iPlayer].return_to_center, sActor, sPlayer); - break; - default: if (!bSet) SetGameVarID((int)lVar2, 0, sActor, sPlayer); break; @@ -2461,14 +2456,14 @@ int ParseState::parse(void) break; case concmd_slapplayer: insptr++; - forceplayerangle(&ps[g_p]); + forceplayerangle(g_p); ps[g_p].posxv -= sintable[(ps[g_p].getang() + 512) & 2047] << 7; ps[g_p].posyv -= sintable[ps[g_p].getang() & 2047] << 7; return 0; case concmd_wackplayer: insptr++; if (!isRR()) - forceplayerangle(&ps[g_p]); + forceplayerangle(g_p); else { ps[g_p].posxv -= sintable[(ps[g_p].getang() + 512) & 2047] << 10; diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 028ae3dc3..2f5a95958 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -49,7 +49,9 @@ void GameInterface::Ticker() // Make copies so that the originals do not have to be modified. for (int i = 0; i < MAXPLAYERS; i++) { + auto oldactions = sync[i].actions; sync[i] = playercmds[i].ucmd; + if (oldactions & SB_CENTERVIEW) sync[i].actions |= SB_CENTERVIEW; } if (rtsplaying > 0) rtsplaying--; diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 506a9e49d..1424a9c1f 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -289,7 +289,7 @@ void displayweapon_d(int snum, double smoothratio) o = 0; horiz16th = get16thOfHoriz(snum, cl_syncinput, smoothratio); - look_anghalf = getHalfLookAng(snum, cl_syncinput, smoothratio); + look_anghalf = getHalfLookAng(p->oq16look_ang, p->q16look_ang, cl_syncinput, smoothratio); looking_arc = fabs(look_anghalf) / 4.5; weapon_sway = p->oweapon_sway + fmulscale16(p->weapon_sway - p->oweapon_sway, smoothratio); kickback_pic = p->okickback_pic + fmulscale16(*kb - p->okickback_pic, smoothratio); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 9c973ee76..9a89e0bbd 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -124,7 +124,7 @@ void displayweapon_r(int snum, double smoothratio) o = 0; - look_anghalf = getHalfLookAng(snum, cl_syncinput, smoothratio); + look_anghalf = getHalfLookAng(p->oq16look_ang, p->q16look_ang, cl_syncinput, smoothratio); looking_arc = fabs(look_anghalf) / 4.5; weapon_sway = p->oweapon_sway + fmulscale16((p->weapon_sway - p->oweapon_sway), smoothratio); TiltStatus = !cl_syncinput ? p->TiltStatus : p->oTiltStatus + fmulscale16((p->TiltStatus - p->oTiltStatus), smoothratio); diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index c6d7e428d..85d778fcc 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -202,13 +202,7 @@ inline void backupplayer(player_struct* p) backupview(p); } -// the weapon display code uses these. -inline double getHalfLookAng(int snum, bool interpolate, double smoothratio) -{ - struct player_struct *p = &ps[snum]; - return (!interpolate ? p->q16look_ang : p->oq16look_ang + fmulscale16(p->q16look_ang - p->oq16look_ang, smoothratio)) * (0.5 / FRACUNIT); -} - +// the weapon display code uses this. inline double get16thOfHoriz(int snum, bool interpolate, double smoothratio) { struct player_struct *p = &ps[snum]; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 0df2701f9..9dd2d17c7 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -67,7 +67,7 @@ void hud_input(int snum) i = p->aim_mode; p->aim_mode = !PlayerInput(snum, SB_AIMMODE); if (p->aim_mode < i) - p->return_to_center = 9; + sync[snum].actions |= SB_CENTERVIEW; // Backup weapon here as hud_input() is the first function where any one of the weapon variables can change. backupweapon(p); @@ -477,13 +477,13 @@ void hud_input(int snum) } } - if (PlayerInput(snum, SB_TURNAROUND) && p->one_eighty_count == 0) + if (PlayerInput(snum, SB_TURNAROUND) && p->one_eighty_count == 0 && p->on_crane < 0) { SetGameVarID(g_iReturnVarID, 0, -1, snum); OnEvent(EVENT_TURNAROUND, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + if (GetGameVarID(g_iReturnVarID, -1, snum) != 0) { - p->one_eighty_count = -IntToFixed(1024); + sync[snum].actions &= ~SB_TURNAROUND; } } } @@ -884,15 +884,13 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) loc.actions |= SB_JUMP; if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - loc.actions |= SB_AIM_UP; + p->vehicle_backwards = true; if (loc.actions & SB_RUN) loc.actions |= SB_CROUCH; } - if (turnl) - loc.actions |= SB_AIM_DOWN; - if (turnr) - loc.actions |= SB_LOOK_LEFT; + if (turnl) p->vehicle_turnl = true; + if (turnr) p->vehicle_turnr = true; double turnvel; @@ -965,7 +963,7 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) loc.q16avel = input.q16avel = 0; } - if (p->newowner == -1 && p->return_to_center <= 0) + if (p->newowner == -1 && !(sync[playerNum].actions & SB_CENTERVIEW)) { loc.q16horz = clamp(loc.q16horz + input.q16horz, IntToFixed(-MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); } @@ -1022,10 +1020,16 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) if (!cl_syncinput) { - // Do these in the same order as the old code. - calcviewpitch(p, scaleAdjust); - applylook(myconnectindex, scaleAdjust, input.q16avel); - sethorizon(myconnectindex, loc.actions, scaleAdjust, input.q16horz); + if (p->dead_flag == 0) + { + // Do these in the same order as the old code. + calcviewpitch(p, scaleAdjust); + processq16avel(p, &input.q16avel); + applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &sync[myconnectindex].actions, scaleAdjust, p->crouch_toggle || sync[myconnectindex].actions & SB_CROUCH); + sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust); + } + + playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust); } } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 843375871..3741ea8bc 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -157,14 +157,15 @@ void quickkill(struct player_struct* p) // //--------------------------------------------------------------------------- -void forceplayerangle(struct player_struct* p) +void forceplayerangle(int snum) { + player_struct* p = &ps[snum]; int n; n = 128 - (krand() & 255); - playerAddHoriz(p, 64); - p->return_to_center = 9; + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64); + sync[snum].actions |= SB_CENTERVIEW; p->setlookang(n >> 1); p->setrotscrnang(n >> 1); } @@ -405,8 +406,8 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli if (p->knee_incs > 0) { p->knee_incs++; - playerAddHoriz(p, -48); - p->return_to_center = 9; + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48); + sync[snum].actions |= SB_CENTERVIEW; if (p->knee_incs > 15) { p->knee_incs = 0; @@ -762,7 +763,7 @@ void playerJump(int snum, int fz, int cz) void apply_seasick(player_struct* p, double factor) { - if (isRRRA() && p->SeaSick) + if (isRRRA() && p->SeaSick && p->dead_flag == 0) { if (p->SeaSick < 250) { @@ -786,63 +787,17 @@ void apply_seasick(player_struct* p, double factor) // //--------------------------------------------------------------------------- -void applylook(int snum, double factor, fixed_t adjustment) +void processq16avel(player_struct* p, fixed_t* q16avel) { - auto p = &ps[snum]; - fixed_t q16avel; - - if (p->dead_flag == 0) - { - p->addrotscrnang(factor * -0.5 * FixedToFloat(p->q16rotscrnang)); - if (abs(p->q16rotscrnang) < FRACUNIT) p->q16rotscrnang = 0; - - p->addlookang(factor * -0.25 * FixedToFloat(p->q16look_ang)); - if (abs(p->q16look_ang) < FRACUNIT) p->q16look_ang = 0; - - if (p->lookLeft) - { - p->addlookang(factor * -152); - p->addrotscrnang(factor * 24); - } - - if (p->lookRight) - { - p->addlookang(factor * 152); - p->addrotscrnang(factor * -24); - } - - if (p->one_eighty_count < 0 && p->on_crane < 0) - { - fixed_t add = FloatToFixed(factor * 128); - p->one_eighty_count += add; - if (p->one_eighty_count > 0) - { - // Don't overshoot our target. With variable factor this is possible. - add -= p->one_eighty_count; - p->one_eighty_count = 0; - } - p->q16ang += add; - } - apply_seasick(p, factor); - } - - // Add angAdjust if input is unsynchronised. - if (!cl_syncinput) - { - p->q16ang += FloatToFixed(factor * p->angAdjust); - } - // Taken from processinput() for use with applying look while cl_syncinput is 0. if (p->psectlotag == ST_2_UNDERWATER) { - q16avel = (adjustment - (adjustment >> 3)) * sgn(TICSPERFRAME); + *q16avel = (*q16avel - (*q16avel >> 3)) * sgn(TICSPERFRAME); } else { - q16avel = adjustment * sgn(TICSPERFRAME); + *q16avel = *q16avel * sgn(TICSPERFRAME); } - - p->q16ang = (p->q16ang + q16avel) & 0x7FFFFFF; } //--------------------------------------------------------------------------- @@ -920,7 +875,6 @@ void resetinputhelpers(player_struct* p) { p->horizAdjust = 0; p->angAdjust = 0; - p->pitchAdjust = 0; } //--------------------------------------------------------------------------- @@ -933,7 +887,7 @@ void checkhardlanding(player_struct* p) { if (p->hard_landing > 0) { - playerAddHoriz(p, -(p->hard_landing << 4)); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -(p->hard_landing << 4)); p->hard_landing--; } } @@ -972,15 +926,13 @@ void checklook(int snum, ESyncBits actions) { auto p = &ps[snum]; - p->lookLeft = false; - p->lookRight = false; if ((actions & SB_LOOK_LEFT) && !p->OnMotorcycle) { SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_LOOKLEFT, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) { - p->lookLeft = true; + actions &= ~SB_LOOK_LEFT; } } @@ -988,9 +940,9 @@ void checklook(int snum, ESyncBits actions) { SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_LOOKRIGHT, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) { - p->lookRight = true; + actions &= ~SB_LOOK_RIGHT; } } backuplook(p); @@ -1002,43 +954,6 @@ void checklook(int snum, ESyncBits actions) // //--------------------------------------------------------------------------- -void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment) -{ - auto p = &ps[snum]; - - // Calculate adjustment as true pitch (Fixed point math really sucks...) - double horizAngle = clamp(atan2(p->q16horiz - IntToFixed(100), IntToFixed(128)) * (512. / pi::pi()) + (factor * p->pitchAdjust) + (adjustment / 65536.), -180, 180); - - if (p->return_to_center > 0 && (actions & (SB_LOOK_UP | SB_LOOK_DOWN)) == 0) // only snap back if no relevant button is pressed. - { - p->return_to_center += -factor * (p->return_to_center / 2); - horizAngle += -factor * (horizAngle / 2); - - if (horizAngle > -0.5 && horizAngle < 0.5) - { - horizAngle = 0.; - p->return_to_center = 0.; - } - } - - // Convert back to Build's horizon. - p->q16horiz = IntToFixed(100) + xs_CRoundToInt(IntToFixed(128) * tan(horizAngle * (pi::pi() / 512.))); - - // Add horizAdjust if input is unsynchronised. - if (!cl_syncinput) - { - p->q16horiz += xs_CRoundToInt(factor * (p->horizAdjust * 65536.)); - } - - p->q16horiz = clamp(p->q16horiz, IntToFixed(HORIZ_MIN), IntToFixed(HORIZ_MAX)); -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void playerCenterView(int snum) { auto p = &ps[snum]; @@ -1046,7 +961,11 @@ void playerCenterView(int snum) OnEvent(EVENT_RETURNTOCENTER, p->i, snum, -1); if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) { - p->return_to_center = 9; + sync[snum].actions |= SB_CENTERVIEW; + } + else + { + sync[snum].actions &= ~SB_CENTERVIEW; } } @@ -1057,8 +976,11 @@ void playerLookUp(int snum, ESyncBits actions) OnEvent(EVENT_LOOKUP, p->i, snum, -1); if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) { - p->return_to_center = 9; - p->pitchAdjust += (actions & SB_RUN) ? 12 : 24; + sync[snum].actions |= SB_CENTERVIEW; + } + else + { + sync[snum].actions &= ~SB_LOOK_UP; } } @@ -1069,8 +991,11 @@ void playerLookDown(int snum, ESyncBits actions) OnEvent(EVENT_LOOKDOWN, p->i, snum, -1); if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) { - p->return_to_center = 9; - p->pitchAdjust -= (actions & SB_RUN) ? 12 : 24; + sync[snum].actions |= SB_CENTERVIEW; + } + else + { + sync[snum].actions &= ~SB_LOOK_DOWN; } } @@ -1079,9 +1004,9 @@ void playerAimUp(int snum, ESyncBits actions) auto p = &ps[snum]; SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_AIMUP, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) { - p->pitchAdjust += (actions & SB_RUN) ? 6 : 12; + sync[snum].actions &= ~SB_AIM_UP; } } @@ -1090,63 +1015,9 @@ void playerAimDown(int snum, ESyncBits actions) auto p = &ps[snum]; SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_AIMDOWN, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) { - p->pitchAdjust -= (actions & SB_RUN) ? 6 : 12; - } -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void playerAddAngle(player_struct* p, int ang) -{ - if (!cl_syncinput) - { - p->angAdjust += ang; - } - else - { - p->addang(ang); - } -} - -void playerSetAngle(player_struct* p, int ang) -{ - if (!cl_syncinput) - { - p->angAdjust += -1. * ((p->q16ang / 65536.) - ang); - } - else - { - p->setang(ang); - } -} - -void playerAddHoriz(player_struct* p, int horiz) -{ - if (!cl_syncinput) - { - p->horizAdjust += horiz; - } - else - { - p->addhoriz(horiz); - } -} - -void playerSetHoriz(player_struct* p, int horiz) -{ - if (!cl_syncinput) - { - p->horizAdjust += -1. * ((p->q16horiz / 65536.) - horiz); - } - else - { - p->sethoriz(horiz); + sync[snum].actions &= ~SB_AIM_DOWN; } } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 97d4a8e4f..1142ffb6a 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2846,7 +2846,8 @@ void processinput_d(int snum) //ENGINE calculates angvel for you // may still be needed later for demo recording - applylook(snum, 1, sb_avel); + processq16avel(p, &sb_avel); + applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH); } if (p->spritebridge == 0) @@ -3078,7 +3079,7 @@ HORIZONLY: if (cl_syncinput) { - sethorizon(snum, actions, 1, PlayerHorizon(snum)); + sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1); } checkhardlanding(p); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 3cf212da0..e6c885e19 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1611,29 +1611,29 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (!S_CheckActorSoundPlaying(pi, 189) && !S_CheckActorSoundPlaying(pi, 187)) S_PlayActorSound(187, pi); } - if (actions & SB_AIM_UP) + if (p->vehicle_backwards) { var6c = 1; - actions &= ~SB_AIM_UP; + p->vehicle_backwards = false; } else var6c = 0; - if (actions & SB_AIM_DOWN) + if (p->vehicle_turnl) { var70 = 1; var74 = 1; - actions &= ~SB_AIM_DOWN; + p->vehicle_turnl = false; } else { var70 = 0; var74 = 0; } - if (actions & SB_LOOK_LEFT) + if (p->vehicle_turnr) { var78 = 1; var7c = 1; - actions &= ~SB_LOOK_LEFT; + p->vehicle_turnr = false; } else { @@ -1717,9 +1717,10 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->moto_drink--; } } + + int horiz = 0; if (p->TurbCount) { - int horiz; if (p->TurbCount <= 1) { horiz = 100; @@ -1733,7 +1734,6 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - playerSetHoriz(p, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -1743,7 +1743,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + horiz = 100 + p->VBumpNow / 3; } else if (p->VBumpTarget < p->VBumpNow) { @@ -1753,13 +1753,18 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + horiz = 100 + p->VBumpNow / 3; } else { p->VBumpTarget = 0; p->moto_bump_fast = 0; } + if (horiz != 0) + { + playerAddHoriz(&p->q16horiz, &p->horizAdjust, horiz - FixedToFloat(p->q16horiz)); + } + if (p->MotoSpeed >= 20 && p->on_ground == 1 && (var74 || var7c)) { short var8c, var90, var94, var98; @@ -1812,7 +1817,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) ang = var98 >> 7; } } - playerSetAngle(p, (var90 - ang) & 2047); + playerAddAngle(&p->q16ang, &p->angAdjust, FixedToFloat(getincangleq16(p->q16ang, IntToFixed(var90 - ang)))); } else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil)) { @@ -1914,17 +1919,17 @@ static void onBoat(int snum, ESyncBits &actions) } else varb0 = 0; - if (actions & SB_AIM_UP) + if (p->vehicle_backwards) { varb4 = 1; - actions &= ~SB_AIM_UP; + p->vehicle_backwards = false; } else varb4 = 0; - if (actions & SB_AIM_DOWN) + if (p->vehicle_turnl) { varb8 = 1; varbc = 1; - actions &= ~SB_AIM_DOWN; + p->vehicle_turnl = false; if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pi); } @@ -1933,11 +1938,11 @@ static void onBoat(int snum, ESyncBits &actions) varb8 = 0; varbc = 0; } - if (actions & SB_LOOK_LEFT) + if (p->vehicle_turnr) { varc0 = 1; varc4 = 1; - actions &= ~SB_LOOK_LEFT; + p->vehicle_turnr = false; if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pi); } @@ -2041,9 +2046,10 @@ static void onBoat(int snum, ESyncBits &actions) p->moto_drink--; } } + + int horiz = 0; if (p->TurbCount) { - int horiz; if (p->TurbCount <= 1) { horiz = 100; @@ -2057,7 +2063,6 @@ static void onBoat(int snum, ESyncBits &actions) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - playerSetHoriz(p, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -2067,7 +2072,7 @@ static void onBoat(int snum, ESyncBits &actions) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + horiz = 100 + p->VBumpNow / 3; } else if (p->VBumpTarget < p->VBumpNow) { @@ -2077,13 +2082,18 @@ static void onBoat(int snum, ESyncBits &actions) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + horiz = 100 + p->VBumpNow / 3; } else { p->VBumpTarget = 0; p->moto_bump_fast = 0; } + if (horiz != 0) + { + playerAddHoriz(&p->q16horiz, &p->horizAdjust, horiz - FixedToFloat(p->q16horiz)); + } + if (p->MotoSpeed > 0 && p->on_ground == 1 && (varbc || varc4)) { short vard4, vard8, vardc, vare0; @@ -2111,7 +2121,7 @@ static void onBoat(int snum, ESyncBits &actions) p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4); ang = vare0 >> 6; } - playerSetAngle(p, (vard8 - ang) & 2047); + playerAddAngle(&p->q16ang, &p->angAdjust, FixedToFloat(getincangleq16(p->q16ang, IntToFixed(vard8 - ang)))); } if (p->NotOnWater) if (p->MotoSpeed > 50) @@ -2455,7 +2465,7 @@ void onMotorcycleMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 1); break; } - playerAddAngle(p, ang); + playerAddAngle(&p->q16ang, &p->angAdjust, ang); if (var10c >= 441 && var10c <= 581) { var104 = (p->MotoSpeed * p->MotoSpeed) >> 8; @@ -2522,7 +2532,7 @@ void onBoatMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 2); break; } - playerAddAngle(p, ang); + playerAddAngle(&p->q16ang, &p->angAdjust, ang); if (var118 >= 441 && var118 <= 581) { p->MotoSpeed = ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 2; @@ -3056,7 +3066,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case RIFLEGUN_WEAPON: p->kickback_pic++; - playerAddHoriz(p, 1); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 1); p->recoil++; if (p->kickback_pic <= 12) @@ -3146,11 +3156,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) } if (p->kickback_pic == 2) { - playerAddAngle(p, 16); + playerAddAngle(&p->q16ang, &p->angAdjust, 16); } else if (p->kickback_pic == 4) { - playerAddAngle(p, -16); + playerAddAngle(&p->q16ang, &p->angAdjust, -16); } if (p->kickback_pic > 4) p->kickback_pic = 1; @@ -3176,11 +3186,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) } if (p->kickback_pic == 2) { - playerAddAngle(p, 4); + playerAddAngle(&p->q16ang, &p->angAdjust, 4); } else if (p->kickback_pic == 4) { - playerAddAngle(p, -4); + playerAddAngle(&p->q16ang, &p->angAdjust, -4); } if (p->kickback_pic > 4) p->kickback_pic = 1; @@ -3228,7 +3238,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->posxv -= sintable[(p->getang() + 512) & 2047] << 4; p->posyv -= sintable[p->getang() & 2047] << 4; - playerAddHoriz(p, 20); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 20); p->recoil += 20; } if (p->kickback_pic > 20) @@ -3736,7 +3746,9 @@ void processinput_r(int snum) //ENGINE calculates angvel for you // may still be needed later for demo recording - applylook(snum, 1, sb_avel); + processq16avel(p, &sb_avel); + applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH); + apply_seasick(p, 1); } if (p->spritebridge == 0) @@ -4086,12 +4098,12 @@ HORIZONLY: if (!d) d = 1; p->recoil -= d; - playerAddHoriz(p, -d); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -d); } if (cl_syncinput) { - sethorizon(snum, actions, 1, PlayerHorizon(snum)); + sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1); } checkhardlanding(p); diff --git a/source/games/duke/src/prediction.cpp b/source/games/duke/src/prediction.cpp index 8bddff24a..0a777b6c6 100644 --- a/source/games/duke/src/prediction.cpp +++ b/source/games/duke/src/prediction.cpp @@ -62,7 +62,6 @@ void resetmys() myjumpingtoggle = ps[myconnectindex].jumping_toggle; myonground = ps[myconnectindex].on_ground; myhardlanding = ps[myconnectindex].hard_landing; - myreturntocenter = ps[myconnectindex].return_to_center; } #if 0 // todo: fix this when networking works again @@ -90,7 +89,6 @@ void fakedomovethingscorrect(void) myjumpingtoggle = p->jumping_toggle; myonground = p->on_ground; myhardlanding = p->hard_landing; - myreturntocenter = p->return_to_center; fakemovefifoplc = movefifoplc; while (fakemovefifoplc < movefifoend[myconnectindex]) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index a5b3de4c0..0e6066c7c 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -119,7 +119,7 @@ void resetplayerstats(int snum) p->bobcounter = 0; p->on_ground = 0; p->player_par = 0; - p->return_to_center = 9; + sync[snum].actions |= SB_CENTERVIEW; p->airleft = 15*26; p->rapid_fire_hold = 0; p->toggle_key_flag = 0; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 219283e94..f0de68fc0 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -229,7 +229,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("walking_snd_toggle", w.walking_snd_toggle) ("palookup", w.palookup) ("hard_landing", w.hard_landing) - ("return_to_center", w.return_to_center) ("max_secret_rooms", w.max_secret_rooms) ("secret_rooms", w.secret_rooms) ("max_actors_killed", w.max_actors_killed) @@ -299,9 +298,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, w.ohard_landing = w.hard_landing; w.horizAdjust = 0; w.angAdjust = 0; - w.pitchAdjust = 0; - w.lookLeft = false; - w.lookRight = false; } return arc; } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 1cf7ef5d9..3e4cd1e40 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -169,7 +169,6 @@ struct player_struct unsigned char toggle_key_flag, knuckle_incs; // ,select_dir; unsigned char walking_snd_toggle, palookup; - double return_to_center; bool quick_kick_msg; int max_secret_rooms, secret_rooms, max_actors_killed, actors_killed; @@ -204,12 +203,13 @@ struct player_struct uint8_t hurt_delay2, nocheat; uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround; uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud; + bool vehicle_turnl, vehicle_turnr, vehicle_backwards; int8_t crouch_toggle; // input stuff. - double horizAdjust, angAdjust, pitchAdjust; - bool lookLeft, lookRight; + double horizAdjust, angAdjust; + fixed_t horizTarget, angTarget; // Access helpers for the widened angle and horizon fields. diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 43e68c6aa..6b00d52ec 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1262,7 +1262,7 @@ void DrawCrosshair(PLAYERp pp) if (!(CameraTestMode) && !TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE)) { USERp u = User[pp->PlayerSprite]; - ::DrawCrosshair(2326, u->Health, 0, 0, 2, shadeToLight(10)); + ::DrawCrosshair(2326, u->Health, -getHalfLookAng(pp->oq16look_ang, pp->q16look_ang, cl_syncinput, smoothratio), 0, 2, shadeToLight(10)); } } @@ -1283,7 +1283,7 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fixed_t sp = &sprite[i]; ang = getangle(*tx - sp->x, *ty - sp->y); - ang_test = GetDeltaAngle(sp->ang, ang) < sp->lotag; + ang_test = getincangle(ang, sp->ang) < sp->lotag; FAFcansee_test = (FAFcansee(sp->x, sp->y, sp->z, sp->sectnum, *tx, *ty, *tz, pp->cursectnum) || @@ -1611,7 +1611,7 @@ drawscreen(PLAYERp pp, double smoothratio) { extern bool CameraTestMode; int tx, ty, tz; - fixed_t tq16horiz, tq16ang; + fixed_t tq16horiz, tq16ang, tq16rotscrnang; short tsectnum; short i,j; int bob_amt = 0; @@ -1654,16 +1654,23 @@ drawscreen(PLAYERp pp, double smoothratio) // This isn't needed for the turret as it was fixable, but moving sector objects are problematic. if (cl_syncinput || pp != Player+myconnectindex || (!cl_syncinput && pp->sop && !TEST(pp->Flags2, PF2_INPUT_CAN_TURN_TURRET))) { - tq16ang = camerapp->oq16ang + xs_CRoundToInt(fmulscale16(NORM_Q16ANGLE(camerapp->q16ang + IntToFixed(1024) - camerapp->oq16ang) - IntToFixed(1024), smoothratio)); + fixed_t dang = IntToFixed(1024); + fixed_t oang = camerapp->oq16ang + camerapp->oq16look_ang; + fixed_t ang = camerapp->q16ang + camerapp->q16look_ang; + tq16ang = oang + xs_CRoundToInt(fmulscale16(NORM_Q16ANGLE(ang + dang - oang) - dang, smoothratio)); tq16horiz = camerapp->oq16horiz + xs_CRoundToInt(fmulscale16(camerapp->q16horiz - camerapp->oq16horiz, smoothratio)); + tq16rotscrnang = camerapp->oq16rotscrnang + xs_CRoundToInt(fmulscale16(NORM_Q16ANGLE(camerapp->q16rotscrnang + dang - camerapp->oq16rotscrnang) - dang, smoothratio)); } else { - tq16ang = pp->q16ang; + tq16ang = pp->q16ang + pp->q16look_ang; tq16horiz = pp->q16horiz; + tq16rotscrnang = pp->q16rotscrnang; } tsectnum = camerapp->cursectnum; + renderSetRollAngle(FixedToFloat(tq16rotscrnang)); + COVERupdatesector(tx, ty, &tsectnum); if (tsectnum >= 0) diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 77f2ddda1..195912890 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -622,6 +622,7 @@ void GameInterface::Ticker(void) auto pp = Player + i; pp->lastinput = pp->input; pp->input = playercmds[i].ucmd; + if (pp->lastinput.actions & SB_CENTERVIEW) pp->input.actions |= SB_CENTERVIEW; } domovethings(); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 4c1241e3c..e297550c7 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -355,13 +355,13 @@ int StdRandomRange(int range); #define SQ(val) ((val) * (val)) #define KENFACING_PLAYER(pp,sp) (sintable[NORM_ANGLE(sp->ang+512)]*(pp->posy-sp->y) >= sintable[NORM_ANGLE(sp-ang)]*(pp->posx-sp->x)) -#define FACING_PLAYER(pp,sp) (abs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < 512) -#define PLAYER_FACING(pp,sp) (abs(GetDeltaAngle(FixedToInt((pp)->q16ang), NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < 320) -#define FACING(sp1,sp2) (abs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < 512) +#define FACING_PLAYER(pp,sp) (abs(getincangle(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y), (sp)->ang)) < 512) +#define PLAYER_FACING(pp,sp) (abs(getincangle(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy), FixedToInt((pp)->q16ang))) < 320) +#define FACING(sp1,sp2) (abs(getincangle(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y), (sp2)->ang)) < 512) -#define FACING_PLAYER_RANGE(pp,sp,range) (abs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < (range)) -#define PLAYER_FACING_RANGE(pp,sp,range) (abs(GetDeltaAngle(FixedToInt((pp)->q16ang), NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < (range)) -#define FACING_RANGE(sp1,sp2,range) (abs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < (range)) +#define FACING_PLAYER_RANGE(pp,sp,range) (abs(getincangle(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y), (sp)->ang)) < (range)) +#define PLAYER_FACING_RANGE(pp,sp,range) (abs(getincangle(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy), FixedToInt((pp)->q16ang))) < (range)) +#define FACING_RANGE(sp1,sp2,range) (abs(getincangle(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y), (sp2)->ang)) < (range)) // two vectors // can determin direction @@ -832,6 +832,7 @@ struct PLAYERstruct int oposx, oposy, oposz; fixed_t oq16horiz, oq16ang; + fixed_t oq16look_ang, oq16rotscrnang; // holds last valid move position short lv_sectnum; @@ -882,6 +883,7 @@ struct PLAYERstruct // variables that do not fit into sprite structure int hvel,tilt,tilt_dest; fixed_t q16horiz, q16horizbase, q16horizoff, q16ang; + fixed_t q16look_ang, q16rotscrnang; short recoil_amt; short recoil_speed; short recoil_ndx; @@ -1007,13 +1009,9 @@ struct PLAYERstruct char WpnReloadState; - // Input helper variables and setters. - double horizAdjust, angAdjust, pitchAdjust; + // Input helper variables. + double horizAdjust, angAdjust; fixed_t horizTarget, angTarget; - void addang(int v) { q16ang = (q16ang + IntToFixed(v)) & 0x7FFFFFF; } - void setang(int v) { q16ang = IntToFixed(v); } - void addhoriz(int v) { q16horiz += (IntToFixed(v)); } - void sethoriz(int v) { q16horiz = IntToFixed(v); } }; extern PLAYER Player[MAX_SW_PLAYERS_REG+1]; @@ -1029,8 +1027,6 @@ enum PF_JUMPING = (BIT(2)), PF_FALLING = (BIT(3)), PF_LOCK_CRAWL = (BIT(4)), - PF_LOCK_HORIZ = (BIT(5)), - PF_LOOKING = (BIT(6)), PF_PLAYER_MOVED = (BIT(7)), PF_PLAYER_RIDING = (BIT(8)), PF_AUTO_AIM = (BIT(9)), @@ -1044,7 +1040,6 @@ enum PF_DIVING = (BIT(17)), PF_DIVING_IN_LAVA = (BIT(18)), PF_TWO_UZI = (BIT(19)), - PF_TURN_180 = (BIT(21)), PF_DEAD_HEAD = (BIT(22)), // are your a dead head PF_HEAD_CONTROL = (BIT(23)), // have control of turning when a head? PF_CLIP_CHEAT = (BIT(24)), // cheat for wall clipping @@ -1846,8 +1841,6 @@ extern SECTOR_OBJECT SectorObject[MAX_SECTOR_OBJECTS]; ANIMATOR NullAnimator; int Distance(int x1, int y1, int x2, int y2); -short GetDeltaAngle(short, short); -fixed_t GetDeltaQ16Angle(fixed_t, fixed_t); int SetActorRotation(short SpriteNum,int,int); int NewStateGroup(short SpriteNum, STATEp SpriteGroup[]); diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index f4c6fb594..9034e77a6 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -291,43 +291,11 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool DoPlayerHorizon(pp, q16horz, scaleAdjust); } - if (pp->horizTarget) - { - fixed_t horizDelta = pp->horizTarget - pp->q16horiz; - pp->q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta); - - if (abs(pp->q16horiz - pp->horizTarget) < FRACUNIT) - { - pp->q16horiz = pp->horizTarget; - pp->horizTarget = 0; - } - } - else if (pp->horizAdjust) - { - pp->q16horiz += FloatToFixed(scaleAdjust * pp->horizAdjust); - } - if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL)) { DoPlayerTurn(pp, q16avel, scaleAdjust); } - if (pp->angTarget) - { - fixed_t angDelta = GetDeltaQ16Angle(pp->angTarget, pp->q16ang); - pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * angDelta)); - - if (abs(pp->q16ang - pp->angTarget) < FRACUNIT) - { - pp->q16ang = pp->angTarget; - pp->angTarget = 0; - } - } - else if (pp->angAdjust) - { - pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF; - } - if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE)) { DoPlayerTurnVehicle(pp, q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz)); @@ -337,6 +305,8 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool { DoPlayerTurnTurret(pp, q16avel); } + + playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust); } loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL); diff --git a/source/sw/src/jsector.cpp b/source/sw/src/jsector.cpp index eb4dcf09d..5d123b4d6 100644 --- a/source/sw/src/jsector.cpp +++ b/source/sw/src/jsector.cpp @@ -653,7 +653,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz) SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta)); // TAG6 = Turn radius - if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp)) + if (klabs(getincangle(sp->ang, SP_TAG5(sp))) >= SP_TAG6(sp)) { SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta)); RESET_BOOL3(sp); // Reverse turn @@ -666,7 +666,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz) SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta)); // TAG6 = Turn radius - if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp)) + if (klabs(getincangle(sp->ang, SP_TAG5(sp))) >= SP_TAG6(sp)) { SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta)); SET_BOOL3(sp); // Reverse turn diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index f9fbf3b61..aa80a0419 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -6921,13 +6921,16 @@ pDisplaySprites(PLAYERp pp, double smoothratio) short ang; int flags; + double look_anghalf = getHalfLookAng(pp->oq16look_ang, pp->q16look_ang, cl_syncinput, smoothratio); + double looking_arc = fabs(look_anghalf) / 4.5; + TRAVERSE(&pp->PanelSpriteList, psp, next) { ang = psp->rotate_ang; shade = 0; flags = 0; - x = psp->ox + fmulscale16(psp->x - psp->ox, smoothratio); - y = psp->oy + fmulscale16(psp->y - psp->oy, smoothratio); + x = (psp->ox + fmulscale16(psp->x - psp->ox, smoothratio)) - look_anghalf; + y = (psp->oy + fmulscale16(psp->y - psp->oy, smoothratio)) + looking_arc; // initilize pal here - jack with it below pal = psp->pal; diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 52e429a0d..24234708e 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -120,12 +120,6 @@ char PlayerGravity = PLAYER_JUMP_GRAV; extern bool DebugOperate; -enum -{ - TURN_SHIFT = 2, - HORIZ_SPEED = 16 -}; - //unsigned char synctics, lastsynctics; int ChopTics; @@ -1065,6 +1059,18 @@ STATEp sg_PlayerNinjaFly[] = ///////////////////////////////////////////////////////////////////////////// +//--------------------------------------------------------------------------- +// +// Unsynchronised input helper. +// +//--------------------------------------------------------------------------- + +static void resetinputhelpers(PLAYERp pp) +{ + pp->horizAdjust = 0; + pp->angAdjust = 0; +} + void DoPlayerSpriteThrow(PLAYERp pp) { @@ -1124,45 +1130,6 @@ void pSetVisNorm(PANEL_SPRITEp psp) // SetVisNorm(); } -short -GetDeltaAngle(short ang1, short ang2) -{ - // Look at the smaller angle if > 1024 (180 degrees) - if (labs(ang1 - ang2) > 1024) - { - if (ang1 <= 1024) - ang1 += 2048; - - if (ang2 <= 1024) - ang2 += 2048; - } - - //if (ang1 - ang2 == -1024) - // return(1024); - - return ang1 - ang2; - -} - -fixed_t -GetDeltaQ16Angle(fixed_t ang1, fixed_t ang2) -{ - // Look at the smaller angle if > 1024 (180 degrees) - if (abs(ang1 - ang2) > IntToFixed(1024)) - { - if (ang1 <= IntToFixed(1024)) - ang1 += IntToFixed(2048); - - if (ang2 <= IntToFixed(1024)) - ang2 += IntToFixed(2048); - } - - //if (ang1 - ang2 == -IntToFixed(1024)) - // return(IntToFixed(1024)); - - return ang1 - ang2; -} - TARGET_SORT TargetSort[MAX_TARGET_SORT]; unsigned TargetSortCount; @@ -1240,7 +1207,7 @@ DoPickTarget(SPRITEp sp, uint32_t max_delta_ang, int skip_targets) // Get the angle difference // delta_ang = labs(FixedToInt(pp->q16ang) - angle2); - delta_ang = labs(GetDeltaAngle(sp->ang, angle2)); + delta_ang = labs(getincangle(angle2, sp->ang)); // If delta_ang not in the range skip this one if (delta_ang > (int)max_delta_ang) @@ -1544,78 +1511,22 @@ DoPlayerCrawlHeight(PLAYERp pp) pp->posz = pp->posz - (DIV4(diff) + DIV8(diff)); } +void +UpdatePlayerSpriteAngle(PLAYERp pp) +{ + sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); + + if (!Prediction && pp->PlayerUnderSprite >= 0) + { + sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); + } +} + void DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust) { - if (!TEST(pp->Flags, PF_TURN_180)) - { - if (pp->input.actions & SB_TURNAROUND) - { - if (pp->KeyPressBits & SB_TURNAROUND) - { - fixed_t delta_ang; - - pp->KeyPressBits &= ~SB_TURNAROUND; - - pp->turn180_target = pp->q16ang + IntToFixed(1024); - - // make the first turn in the clockwise direction - // the rest will follow - delta_ang = labs(GetDeltaQ16Angle(pp->turn180_target, pp->q16ang)) >> TURN_SHIFT; - pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; - - SET(pp->Flags, PF_TURN_180); - } - } - else - { - pp->KeyPressBits |= SB_TURNAROUND; - } - } - - if (TEST(pp->Flags, PF_TURN_180)) - { - fixed_t delta_ang; - - delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang) >> TURN_SHIFT; - pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; - - sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); - - if (!Prediction && pp->PlayerUnderSprite >= 0) - { - sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); - } - - // get new delta to see how close we are - delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang); - - if (labs(delta_ang) < (IntToFixed(3) << TURN_SHIFT)) - { - pp->q16ang = pp->turn180_target; - RESET(pp->Flags, PF_TURN_180); - } - else - { - return; - } - } - - if (q16avel != 0) - { - pp->q16ang = (pp->q16ang + q16avel) & 0x7FFFFFF; - - // update players sprite angle - // NOTE: It's also updated in UpdatePlayerSprite, but needs to be - // here to cover - // all cases. - sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); - - if (!Prediction && pp->PlayerUnderSprite >= 0) - { - sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); - } - } + applylook(&pp->q16ang, &pp->q16look_ang, &pp->q16rotscrnang, &pp->turn180_target, q16avel, &pp->input.actions, scaleAdjust, pp->input.actions & (SB_CROUCH|SB_CROUCH_LOCK)); + UpdatePlayerSpriteAngle(pp); } #if 0 @@ -1723,7 +1634,7 @@ DoPlayerTurnTurret(PLAYERp pp, fixed_t q16avel) if (sop->limit_ang_center >= 0) { - diff = GetDeltaQ16Angle(new_ang, IntToFixed(sop->limit_ang_center)); + diff = getincangleq16(IntToFixed(sop->limit_ang_center), new_ang); if (labs(diff) >= IntToFixed(sop->limit_ang_delta)) { @@ -1824,70 +1735,8 @@ DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust) if (cl_slopetilting) PlayerAutoLook(pp, scaleAdjust); - if (q16horz) - { - pp->q16horizbase += q16horz; - SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); - } - - // this is the locked type - if (pp->input.actions & (SB_AIM_UP|SB_AIM_DOWN)) - { - // set looking because player is manually looking. - SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); - - // adjust q16horiz negative - if (pp->input.actions & SB_AIM_DOWN) - pp->q16horizbase -= FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); - - // adjust q16horiz positive - if (pp->input.actions & SB_AIM_UP) - pp->q16horizbase += FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); - } - - // this is the unlocked type - if (pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN|SB_CENTERVIEW)) - { - RESET(pp->Flags, PF_LOCK_HORIZ); - SET(pp->Flags, PF_LOOKING); - - // adjust q16horiz negative - if (pp->input.actions & SB_LOOK_DOWN) - pp->q16horizbase -= FloatToFixed(scaleAdjust * HORIZ_SPEED); - - // adjust q16horiz positive - if (pp->input.actions & SB_LOOK_UP) - pp->q16horizbase += FloatToFixed(scaleAdjust * HORIZ_SPEED); - - if (pp->input.actions & SB_CENTERVIEW) - pp->q16horizoff = 0; - } - - if (!TEST(pp->Flags, PF_LOCK_HORIZ)) - { - if (!(pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN))) - { - // not pressing the q16horiz keys - if (pp->q16horizbase != IntToFixed(100)) - { - // move q16horiz back to 100 - for (int i = 1; i; i--) - { - // this formula does not work for q16horiz = 101-103 - pp->q16horizbase += xs_CRoundToInt(scaleAdjust * (IntToFixed(25) - (pp->q16horizbase >> 2))); - } - } - else - { - // not looking anymore because q16horiz is back at 100 - RESET(pp->Flags, PF_LOOKING); - } - } - } - - // bound the base - pp->q16horizbase = max(pp->q16horizbase, IntToFixed(PLAYER_HORIZ_MIN)); - pp->q16horizbase = min(pp->q16horizbase, IntToFixed(PLAYER_HORIZ_MAX)); + // apply default horizon from backend + sethorizon(&pp->q16horizbase, q16horz, &pp->input.actions, scaleAdjust); // bound adjust q16horizoff if (pp->q16horizbase + pp->q16horizoff < IntToFixed(PLAYER_HORIZ_MIN)) @@ -3449,10 +3298,9 @@ DoPlayerFall(PLAYERp pp) } else if (pp->jump_speed > 1300) { - if (TEST(pp->Flags, PF_LOCK_HORIZ)) + if (!(pp->input.actions & SB_CENTERVIEW)) { - RESET(pp->Flags, PF_LOCK_HORIZ); - SET(pp->Flags, PF_LOOKING); + pp->input.actions |= SB_CENTERVIEW; } } @@ -3821,7 +3669,7 @@ DoPlayerClimb(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - playerSetAngle(pp, pp->LadderAngle); + playerSetAngle(&pp->q16ang, &pp->angTarget, pp->LadderAngle); } } } @@ -4280,7 +4128,7 @@ PlayerOnLadder(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - playerSetAngle(pp, pp->LadderAngle); + playerSetAngle(&pp->q16ang, &pp->angTarget, pp->LadderAngle); return true; } @@ -5519,7 +5367,7 @@ DoPlayerBeginOperate(PLAYERp pp) pp->sop = pp->sop_control = sop; sop->controller = pp->SpriteP; - playerSetAngle(pp, sop->ang); + playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -5606,7 +5454,7 @@ DoPlayerBeginRemoteOperate(PLAYERp pp, SECTOR_OBJECTp sop) save_sectnum = pp->cursectnum; - playerSetAngle(pp, sop->ang); + playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -6180,7 +6028,7 @@ DoPlayerBeginDie(PLAYERp pp) // Get rid of all panel spells that are currently working KillAllPanelInv(pp); - SET(pp->Flags, PF_LOCK_HORIZ); + pp->input.actions &= ~SB_CENTERVIEW; pp->friction = PLAYER_RUN_FRICTION; pp->slide_xvect = pp->slide_yvect = 0; @@ -6291,12 +6139,12 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed) { if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT) { - playerAddHoriz(pp, -speed); + playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, -speed); } if ((IntToFixed(target) - pp->q16horiz) > FRACUNIT) { - playerAddHoriz(pp, speed); + playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, speed); } } @@ -6393,7 +6241,7 @@ void DoPlayerDeathFollowKiller(PLAYERp pp) if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum)) { - playerAddAngle(pp, GetDeltaQ16Angle(gethiq16angle(kp->x - pp->posx, kp->y - pp->posy), pp->q16ang) / (double)(FRACUNIT << 4)); + playerAddAngle(&pp->q16ang, &pp->angAdjust, getincangleq16(pp->q16ang, gethiq16angle(kp->x - pp->posx, kp->y - pp->posy)) / (double)(FRACUNIT << 4)); } } } @@ -6443,9 +6291,9 @@ void DoPlayerDeathCheckKeys(PLAYERp pp) RESET(pp->Flags, PF_WEAPON_DOWN|PF_WEAPON_RETRACT); RESET(pp->Flags, PF_DEAD); - RESET(pp->Flags, PF_LOCK_HORIZ); RESET(sp->cstat, CSTAT_SPRITE_YCENTER); SET(sp->cstat, CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); + pp->input.actions |= SB_CENTERVIEW; sp->xrepeat = PLAYER_NINJA_XREPEAT; sp->yrepeat = PLAYER_NINJA_YREPEAT; @@ -6585,7 +6433,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp) wall_ang = NORM_ANGLE(hsp->ang); - dang = GetDeltaAngle(u->slide_ang, wall_ang); + dang = getincangle(wall_ang, u->slide_ang); u->slide_ang = NORM_ANGLE(wall_ang + 1024 - dang); SpawnShrap(pp->PlayerSprite, -1); @@ -6602,7 +6450,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp) nw = wall[w].point2; wall_ang = NORM_ANGLE(getangle(wall[nw].x - wall[w].x, wall[nw].y - wall[w].y)-512); - dang = GetDeltaAngle(u->slide_ang, wall_ang); + dang = getincangle(wall_ang, u->slide_ang); u->slide_ang = NORM_ANGLE(wall_ang + 1024 - dang); SpawnShrap(pp->PlayerSprite, -1); @@ -7124,6 +6972,8 @@ MoveSkipSavePos(void) pp->oq16ang = pp->q16ang; pp->oq16horiz = pp->q16horiz; pp->obob_z = pp->bob_z; + pp->oq16look_ang = pp->q16look_ang; + pp->oq16rotscrnang = pp->q16rotscrnang; } // save off stats for skip4 @@ -7431,7 +7281,7 @@ domovethings(void) // auto tracking mode for single player multi-game if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) { - playerSetAngle(&Player[screenpeek], FixedToFloat(gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy))); + playerSetAngle(&Player[screenpeek].q16ang, &Player[screenpeek].angTarget, FixedToFloat(gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy))); } if (!TEST(pp->Flags, PF_DEAD)) @@ -7779,85 +7629,6 @@ void CheckFootPrints(PLAYERp pp) } } -//--------------------------------------------------------------------------- -// -// Unsynchronised input helpers. -// -//--------------------------------------------------------------------------- - -void resetinputhelpers(PLAYERp pp) -{ - pp->horizAdjust = 0; - pp->angAdjust = 0; - pp->pitchAdjust = 0; -} - -void playerAddAngle(PLAYERp pp, double ang) -{ - if (!cl_syncinput) - { - pp->angAdjust += ang; - } - else - { - pp->addang(ang); - } -} - -void playerSetAngle(PLAYERp pp, double ang) -{ - if (!cl_syncinput) - { - // Cancel out any angle adjustments as we're setting angle now. - pp->angAdjust = 0; - - // Add slight offset if input angle is coming in as absolute 0. - if (ang == 0) - { - ang += 0.1; - } - - pp->angTarget = pp->q16ang + GetDeltaQ16Angle(FloatToFixed(ang), pp->q16ang); - } - else - { - pp->setang(ang); - } -} - -void playerAddHoriz(PLAYERp pp, double horiz) -{ - if (!cl_syncinput) - { - pp->horizAdjust += horiz; - } - else - { - pp->addhoriz(horiz); - } -} - -void playerSetHoriz(PLAYERp pp, double horiz) -{ - if (!cl_syncinput) - { - // Cancel out any horizon adjustments as we're setting horizon now. - pp->horizAdjust = 0; - - // Add slight offset if input horizon is coming in as absolute 0. - if (horiz == 0) - { - horiz += 0.1; - } - - pp->horizTarget = FloatToFixed(horiz); - } - else - { - pp->sethoriz(horiz); - } -} - //--------------------------------------------------------------------------- // // diff --git a/source/sw/src/player.h b/source/sw/src/player.h index 527b50742..9f3ca775b 100644 --- a/source/sw/src/player.h +++ b/source/sw/src/player.h @@ -144,12 +144,6 @@ void PlaySOsound(short sectnum,short sound_num); void DoSpawnTeleporterEffectPlace(SPRITEp sp); void FindMainSector(SECTOR_OBJECTp sop); -void resetinputhelpers(PLAYERp pp); -void playerAddAngle(PLAYERp pp, double ang); -void playerSetAngle(PLAYERp pp, double ang); -void playerAddHoriz(PLAYERp pp, double horiz); -void playerSetHoriz(PLAYERp pp, double horiz); - END_SW_NS #endif diff --git a/source/sw/src/sprite.cpp b/source/sw/src/sprite.cpp index cf3dd6a8e..1f7795f64 100644 --- a/source/sw/src/sprite.cpp +++ b/source/sw/src/sprite.cpp @@ -108,7 +108,6 @@ int MissileZrange(short SpriteNum); #define ACTIVE_CHECK_TIME (3*120) /* -short GetDeltaAngle(short ang1, short ang2); short GetRotation(short sn); int StateControl(int16_t SpriteNum); void PreCacheRange(short, short); diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 76e0fa8eb..b36178bf2 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -931,7 +931,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) sop->clipbox_vdist[sop->clipbox_num] = ksqrt(SQ(sop->xmid - sp->x) + SQ(sop->ymid - sp->y)); ang2 = getangle(sp->x - sop->xmid, sp->y - sop->ymid); - sop->clipbox_ang[sop->clipbox_num] = GetDeltaAngle(sop->ang, ang2); + sop->clipbox_ang[sop->clipbox_num] = getincangle(ang2, sop->ang); sop->clipbox_num++; KillSprite(sp_num); @@ -1678,7 +1678,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny) // New angle is formed by taking last known angle and // adjusting by the delta angle - playerAddAngle(pp, GetDeltaQ16Angle(pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng), pp->q16ang)); + playerAddAngle(&pp->q16ang, &pp->angAdjust, FixedToFloat(getincangleq16(pp->q16ang, pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng)))); UpdatePlayerSprite(pp); } @@ -1891,7 +1891,7 @@ PlayerPart: setspritez(sop->sp_num[i], (vec3_t *)sp); } - u->oangdiff += GetDeltaAngle(sp->ang, oldang); + u->oangdiff += getincangle(oldang, sp->ang); if (TEST(sp->extra, SPRX_BLADE)) { @@ -2384,7 +2384,7 @@ MoveSectorObjects(SECTOR_OBJECTp sop, short locktics) DoTrack(sop, locktics, &nx, &ny); // get delta to target angle - delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang); + delta_ang = getincangle(sop->ang, sop->ang_tgt); sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> sop->turn_speed)); delta_ang = delta_ang >> sop->turn_speed; @@ -2896,7 +2896,7 @@ void TornadoSpin(SECTOR_OBJECTp sop) short locktics = synctics; // get delta to target angle - delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang); + delta_ang = getincangle(sop->ang, sop->ang_tgt); sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> sop->turn_speed)); delta_ang = delta_ang >> sop->turn_speed; @@ -3026,7 +3026,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop) sop->ang_tgt = getangle(u->tgt_sp->x - sop->xmid, u->tgt_sp->y - sop->ymid); // get delta to target angle - delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang); + delta_ang = getincangle(sop->ang, sop->ang_tgt); //sop->ang += delta_ang >> 4; sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> 3)); @@ -3034,7 +3034,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop) if (sop->limit_ang_center >= 0) { - diff = GetDeltaAngle(sop->ang, sop->limit_ang_center); + diff = getincangle(sop->limit_ang_center, sop->ang); if (labs(diff) >= sop->limit_ang_delta) { diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index 85378c970..e516181fe 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -8312,7 +8312,7 @@ MissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int16_t d // move to correct angle ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y); - delta_ang = GetDeltaAngle(sp->ang, ang2tgt); + delta_ang = getincangle(ang2tgt, sp->ang); if (labs(delta_ang) > 32) { @@ -8386,7 +8386,7 @@ ComboMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int1 // move to correct angle ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y); - delta_ang = GetDeltaAngle(sp->ang, ang2tgt); + delta_ang = getincangle(ang2tgt, sp->ang); if (labs(delta_ang) > 32) { @@ -18951,7 +18951,7 @@ InitTurretMgun(SECTOR_OBJECTp sop) daang = 512; if ((hitinfo.sprite = WeaponAutoAimHitscan(sp, &daz, &daang, false)) != -1) { - delta = labs(GetDeltaAngle(daang, sp->ang)); + delta = labs(getincangle(sp->ang, daang)); if (delta > 128) { // don't shoot if greater than 128 diff --git a/wadsrc/static/engine/menudef.txt b/wadsrc/static/engine/menudef.txt index 121a229b2..4222c893a 100644 --- a/wadsrc/static/engine/menudef.txt +++ b/wadsrc/static/engine/menudef.txt @@ -498,10 +498,7 @@ OptionMenu "ActionControlsMenu"// protected StaticText "" Control "$CNTRLMNU_TURNLEFT" , "+turn_left" Control "$CNTRLMNU_TURNRIGHT" , "+turn_right" - ifnotgame(Exhumed) - { - Control "$CNTRLMNU_TURN180" , "turnaround" - } + Control "$CNTRLMNU_TURN180" , "turnaround" StaticText "" Control "$CNTRLMNU_JUMP" , "+jump" @@ -520,11 +517,8 @@ OptionMenu "ActionControlsMenu"// protected Control "$CNTRLMNU_AIMDOWN" , "+aim_down" Control "$CNTRLMNU_LOOKUP" , "+look_up" Control "$CNTRLMNU_LOOKDOWN" , "+look_down" - ifgame(Duke, Nam, WW2GI, Redneck, RedneckRides) - { - Control "$CNTRLMNU_LOOKLEFT" , "+look_left" - Control "$CNTRLMNU_LOOKRIGHT" , "+look_right" - } + Control "$CNTRLMNU_LOOKLEFT" , "+look_left" + Control "$CNTRLMNU_LOOKRIGHT" , "+look_right" Control "$CNTRLMNU_CENTERVIEW" , "centerview" StaticText ""