From 7749b0f7b90bd78bbb908b665db856168981ad2f Mon Sep 17 00:00:00 2001 From: NY00123 Date: Tue, 14 Apr 2020 18:17:08 +0300 Subject: [PATCH] SW: Interpolate sector objects in non-demo, single player games. Let's see if this is breaking anything. --- source/sw/src/draw.cpp | 4 ++-- source/sw/src/game.cpp | 2 ++ source/sw/src/game.h | 1 + source/sw/src/interp.cpp | 9 +++++++++ source/sw/src/interp.h | 5 +++++ source/sw/src/track.cpp | 43 +++++++++++++++++++++++++++++++++++----- source/sw/src/weapon.cpp | 5 +++++ 7 files changed, 62 insertions(+), 7 deletions(-) diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 2ea7805da..4dc3182c4 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -2013,7 +2013,7 @@ drawscreen(PLAYERp pp) tx = camerapp->oposx + mulscale16(camerapp->posx - camerapp->oposx, smoothratio); ty = camerapp->oposy + mulscale16(camerapp->posy - camerapp->oposy, smoothratio); tz = camerapp->oposz + mulscale16(camerapp->posz - camerapp->oposz, smoothratio); - if (PedanticMode || + if (PedanticMode || pp->sop_control || pp == Player+myconnectindex && TEST(pp->Flags, PF_DEAD)) { tq16ang = camerapp->oq16ang + mulscale16(((camerapp->q16ang + fix16_from_int(1024) - camerapp->oq16ang) & 0x7FFFFFF) - fix16_from_int(1024), smoothratio); @@ -2056,7 +2056,7 @@ drawscreen(PLAYERp pp) if (pp->sop_riding || pp->sop_control) { - if (pp->sop_control) + if (pp->sop_control && !InterpolateSectObj) { tx = pp->posx; ty = pp->posy; diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index a6aba173e..44973b836 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -187,6 +187,7 @@ SWBOOL NoDemoStartup = FALSE; SWBOOL FirstTimeIntoGame; SWBOOL PedanticMode; +SWBOOL InterpolateSectObj; SWBOOL BorderAdjust = FALSE; SWBOOL LocationInfo = 0; @@ -958,6 +959,7 @@ void InitLevelGlobals(void) memset(BossSpriteNum,-1,sizeof(BossSpriteNum)); PedanticMode = (DemoPlaying || DemoRecording || DemoEdit || DemoMode); + InterpolateSectObj = !CommEnabled && !PedanticMode; } void InitLevelGlobals2(void) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index da2e45f73..2c6c21a0a 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -886,6 +886,7 @@ extern int PlayerYellVocs[MAX_YELLSOUNDS]; void BossHealthMeter(void); extern SWBOOL PedanticMode; +extern SWBOOL InterpolateSectObj; // Global variables used for modifying variouse things from the Console diff --git a/source/sw/src/interp.cpp b/source/sw/src/interp.cpp index c8b5615fe..9cf009479 100644 --- a/source/sw/src/interp.cpp +++ b/source/sw/src/interp.cpp @@ -111,4 +111,13 @@ void restoreinterpolations(void) // Stick at end of drawscreen for (i = numinterpolations - 1; i >= 0; i--) *curipos[i] = bakipos[i]; } + +void togglespriteinterpolation(spritetype *sp, int set) +{ + auto func = set ? setinterpolation : stopinterpolation; + func(&sp->x); + func(&sp->y); + func(&sp->z); +} + END_SW_NS diff --git a/source/sw/src/interp.h b/source/sw/src/interp.h index c9d36e4ea..dee5990e1 100644 --- a/source/sw/src/interp.h +++ b/source/sw/src/interp.h @@ -49,6 +49,11 @@ void updateinterpolations(void); void dointerpolations(int smoothratio); void restoreinterpolations(void); +void togglespriteinterpolation(spritetype *sp, int set); + +static void FORCE_INLINE setspriteinterpolation(spritetype *sp) { togglespriteinterpolation(sp, 1); } +static void FORCE_INLINE stopspriteinterpolation(spritetype *sp) { togglespriteinterpolation(sp, 0); } + #endif END_SW_NS diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 429d03d08..c00472ddc 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -34,6 +34,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "ai.h" #include "player.h" #include "game.h" +#include "interp.h" #include "network.h" #include "sprite.h" #include "track.h" @@ -848,6 +849,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) // // Make sure every sector object has an outer loop tagged - important + // Further setup interpolation // FoundOutsideLoop = FALSE; @@ -860,6 +862,21 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) // move all walls in sectors for (k = startwall; k <= endwall; k++) { + uint16_t const nextwall = wall[k].nextwall; + + // setup interpolation + if (InterpolateSectObj) + { + setinterpolation(&wall[k].x); + setinterpolation(&wall[k].y); + + if (nextwall < MAXWALLS) + { + setinterpolation(&wall[wall[nextwall].point2].x); + setinterpolation(&wall[wall[nextwall].point2].y); + } + } + // for morph point - tornado style if (wall[k].lotag == TAG_WALL_ALIGN_SLOPE_TO_POINT) sop->morph_wall_point = k; @@ -869,10 +886,16 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) // each wall has this set - for collision detection SET(wall[k].extra, WALLFX_SECTOR_OBJECT|WALLFX_DONT_STICK); - uint16_t const nextwall = wall[k].nextwall; if (nextwall < MAXWALLS) SET(wall[nextwall].extra, WALLFX_SECTOR_OBJECT|WALLFX_DONT_STICK); } + + // interpolate floor and ceiling + if (InterpolateSectObj && (k != startwall)) + { + setinterpolation(&(*sectp)->ceilingz); + setinterpolation(&(*sectp)->floorz); + } } if (!FoundOutsideLoop) @@ -972,6 +995,8 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop) ASSERT(sn < SIZ(sop->sp_num) - 1); sop->sp_num[sn] = sp_num; + if (InterpolateSectObj) + setspriteinterpolation(sp); if (!TEST(sop->flags, SOBJ_SPRITE_OBJ)) @@ -1630,8 +1655,11 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny) pp->posx += BOUND_4PIX(nx); pp->posy += BOUND_4PIX(ny); - pp->oposx = pp->posx; - pp->oposy = pp->posy; + if (!InterpolateSectObj) + { + pp->oposx = pp->posx; + pp->oposy = pp->posy; + } if (TEST(sop->flags, SOBJ_DONT_ROTATE)) { @@ -1676,7 +1704,9 @@ 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 - pp->oq16ang = pp->q16ang = fix16_from_int(NORM_ANGLE(pp->RevolveAng + pp->RevolveDeltaAng)); + pp->q16ang = fix16_from_int(NORM_ANGLE(pp->RevolveAng + pp->RevolveDeltaAng)); + if (!InterpolateSectObj) + pp->oq16ang = pp->q16ang; UpdatePlayerSprite(pp); } @@ -1929,7 +1959,8 @@ PlayerPart: pp->SpriteP->z = pp->loz; } } - pp->oposz = pp->posz; + if (!InterpolateSectObj) + pp->oposz = pp->posz; } else { @@ -2044,6 +2075,8 @@ void KillSectorObjectSprites(SECTOR_OBJECTp sop) if (sp->picnum == ST1 && sp->hitag == SPAWN_SPOT) continue; + if (InterpolateSectObj) + stopspriteinterpolation(sp); KillSprite(sop->sp_num[i]); } diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index 3bcb556ea..0756a69db 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -31,6 +31,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "names2.h" #include "panel.h" #include "game.h" +#include "interp.h" #include "tags.h" #include "common_game.h" #include "break.h" @@ -11392,6 +11393,8 @@ AddSpriteToSectorObject(short SpriteNum, SECTOR_OBJECTp sop) ASSERT(sn < SIZ(sop->sp_num) - 1); sop->sp_num[sn] = SpriteNum; + if (InterpolateSectObj) + setspriteinterpolation(sp); SET(u->Flags, SPR_ON_SO_SECTOR|SPR_SO_ATTACHED); @@ -11458,6 +11461,8 @@ SpawnBigGunFlames(int16_t Weapon, int16_t Operator, SECTOR_OBJECTp sop) ASSERT(sn < SIZ(sop->sp_num) - 1); sop->sp_num[sn] = explosion; + if (InterpolateSectObj) + setspriteinterpolation(exp); // Place sprite exactly where shoot point is //exp->x = eu->ox = sop->xmid - u->sx;