From 688fa2e778614b114166b939fac57d2507b294f7 Mon Sep 17 00:00:00 2001 From: nukeykt Date: Sat, 9 Nov 2019 01:55:26 +0900 Subject: [PATCH] Interpolate bob angle --- source/exhumed/src/exhumed.cpp | 2 ++ source/exhumed/src/gun.cpp | 11 ++++++----- source/exhumed/src/gun.h | 2 +- source/exhumed/src/player.cpp | 2 +- source/exhumed/src/player.h | 2 +- source/exhumed/src/view.cpp | 2 +- source/exhumed/src/view.h | 7 +++++++ 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index de15a041f..45c1ad89b 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -2082,6 +2082,8 @@ static void GameMove(void) // YELLOW SECTION MoveThings(); + obobangle = bobangle; + if (totalvel[nLocalPlayer] == 0) { bobangle = 0; diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 0f4a75ce9..302d8429d 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -662,7 +662,7 @@ loc_flag: } if (nPlayer == nLocalPlayer) { - bobangle = 512; + obobangle = bobangle = 512; } if (nWeapon == kWeaponFlamer && (!(nSectFlag & kSectUnderwater))) @@ -911,7 +911,7 @@ loc_flag: } } -void DrawWeapons() +void DrawWeapons(int smooth) { if (bCamera) { return; @@ -947,18 +947,19 @@ void DrawWeapons() int nVal = totalvel[nLocalPlayer] >> 1; // CHECKME - not & 0x7FF? - int yOffset = (nVal * (sintable[bobangle & 0x3FF] >> 8)) >> 9; + int nBobAngle = angle_interpolate16(obobangle, bobangle, smooth); + int yOffset = (nVal * (sintable[nBobAngle & 0x3FF] >> 8)) >> 9; int xOffset = 0; if (var_34 == 1) { - xOffset = ((Sin(bobangle + 512) >> 8) * nVal) >> 8; + xOffset = ((Sin(nBobAngle + 512) >> 8) * nVal) >> 8; } else { xOffset = 0; - bobangle = 512; + obobangle = bobangle = 512; } if (nWeapon == 3 && var_34 == 1) { diff --git a/source/exhumed/src/gun.h b/source/exhumed/src/gun.h index ecb2982fe..6e132b771 100644 --- a/source/exhumed/src/gun.h +++ b/source/exhumed/src/gun.h @@ -45,6 +45,6 @@ void StopFiringWeapon(short nPlayer); void FireWeapon(short nPlayer); void CheckClip(short nPlayer); void MoveWeapons(short nPlayer); -void DrawWeapons(); +void DrawWeapons(int smooth); #endif diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index f417cf09a..8bf2ce4a0 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -47,7 +47,7 @@ struct PlayerSave fix16_t lPlayerXVel = 0; fix16_t lPlayerYVel = 0; fix16_t nPlayerDAng = 0; -short bobangle = 0; +short obobangle = 0, bobangle = 0; short bPlayerPan = 0; short bLockPan = 0; diff --git a/source/exhumed/src/player.h b/source/exhumed/src/player.h index 99e866cb2..eaf242ee9 100644 --- a/source/exhumed/src/player.h +++ b/source/exhumed/src/player.h @@ -86,7 +86,7 @@ extern short nPlayerScore[]; extern short nPlayerClip[]; -extern short bobangle; +extern short obobangle, bobangle; extern int totalvel[]; extern int16_t eyelevel[], oeyelevel[]; diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index ca91b5f86..c55cd54af 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -574,7 +574,7 @@ void DrawView(int smoothRatio) { if (nSnakeCam < 0) { - DrawWeapons(); + DrawWeapons(smoothRatio); DrawStatus(); } else diff --git a/source/exhumed/src/view.h b/source/exhumed/src/view.h index de007b34b..68aeec61d 100644 --- a/source/exhumed/src/view.h +++ b/source/exhumed/src/view.h @@ -2,6 +2,8 @@ #ifndef __view_h__ #define __view_h__ +#include "build.h" + extern short bSubTitles; extern short nViewTop; extern short bClip; @@ -39,4 +41,9 @@ extern short bTouchFloor; extern short nChunkTotal; +static inline int angle_interpolate16(int a, int b, int smooth) +{ + return a + mulscale16(((b+1024-a)&2047)-1024, smooth); +} + #endif