From 1504e19cf894fd00a434d17f9cc4d2bbc1725f87 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 26 Nov 2020 19:15:49 +1100 Subject: [PATCH] - Exhumed: Add sprite interpolation to `analyzesprites()`. --- source/exhumed/src/exhumed.cpp | 17 +++++++++++++++++ source/exhumed/src/view.cpp | 21 ++++++++++++++++++--- source/exhumed/src/view.h | 6 ++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index f905fd4e9..227370089 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -174,6 +174,8 @@ int nTimeLimit; int bVanilla = 0; +Loc oldLocs[MAXSPRITES]; + void DebugOut(const char *fmt, ...) { #ifdef _DEBUG @@ -260,10 +262,25 @@ double calc_smoothratio() return I_GetTimeFrac() * MaxSmoothRatio; } +static void recordoldspritepos() +{ + for (int i = 0; i < MAXSPRITES; i++) + { + auto* spr = &sprite[i]; + Loc* oldLoc = &oldLocs[i]; + oldLoc->x = spr->x; + oldLoc->y = spr->y; + oldLoc->z = spr->z; + oldLoc->ang = spr->ang; + } +} + void GameMove(void) { FixPalette(); + recordoldspritepos(); + if (currentLevel->levelNumber == kMap20) { if (lCountDown <= 0) diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index b6eb814fd..0ebf22225 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -121,8 +121,24 @@ void viewRestoreInterpolations(void) //Stick at end of drawscreen } // NOTE - not to be confused with Ken's analyzesprites() -static void analyzesprites() +static void analyzesprites(double const smoothratio) { + tspritetype *pTSprite; + + for (int i = 0; i < spritesortcnt; i++) { + pTSprite = &tsprite[i]; + + if (pTSprite->owner != -1) + { + // interpolate sprite position + Loc* oldLoc = &oldLocs[pTSprite->owner]; + pTSprite->x = oldLoc->x + MulScale(pTSprite->x - oldLoc->x, smoothratio, 16); + pTSprite->y = oldLoc->y + MulScale(pTSprite->y - oldLoc->y, smoothratio, 16); + pTSprite->z = oldLoc->z + MulScale(pTSprite->z - oldLoc->z, smoothratio, 16); + pTSprite->ang = oldLoc->ang + MulScale(((pTSprite->ang - oldLoc->ang + 1024) & 0x7FF) - 1024, smoothratio, 16); + } + } + short nPlayerSprite = PlayerList[nLocalPlayer].nSprite; int var_38 = 20; @@ -142,7 +158,6 @@ static void analyzesprites() int nAngle = (2048 - pPlayerSprite->ang) & kAngleMask; int nTSprite; - tspritetype *pTSprite; // int var_20 = var_24; @@ -398,7 +413,7 @@ void DrawView(double smoothRatio, bool sceneonly) } renderDrawRoomsQ16(nCamerax, nCameray, viewz, nCameraa.asq16(), nCamerapan.asq16(), nSector); - analyzesprites(); + analyzesprites(smoothRatio); renderDrawMasks(); if (HavePLURemap()) diff --git a/source/exhumed/src/view.h b/source/exhumed/src/view.h index 1acc748c3..c46eb6f1c 100644 --- a/source/exhumed/src/view.h +++ b/source/exhumed/src/view.h @@ -46,6 +46,12 @@ extern short bTouchFloor; extern short nChunkTotal; extern int gFov; +struct Loc +{ + int x, y, z, ang; +}; +extern Loc oldLocs[MAXSPRITES]; + static inline int angle_interpolate16(int a, int b, int smooth) { return a + mulscale16(((b+1024-a)&2047)-1024, smooth);