From e5d963c515a793616920ce1f847bd99c050d5fb7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 31 Aug 2020 19:27:22 +0200 Subject: [PATCH] - refactored third person view to only access the clock in its worker function Timer values in interface code are undefined, these should not access anything that changes at real time. Also use smoothratio to do the calculation in frame time, not tic time. --- source/games/duke/src/ccmds.cpp | 2 +- source/games/duke/src/cheats.cpp | 2 +- source/games/duke/src/d_menu.cpp | 4 +--- source/games/duke/src/funct.h | 2 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/player.cpp | 9 ++++++--- source/games/duke/src/render.cpp | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 272357dc7..147456766 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -297,7 +297,7 @@ static int osdcmd_third_person_view(CCmdFuncPtr parm) { ps[myconnectindex].over_shoulder_on = 1; cameradist = 0; - cameraclock = gameclock; + cameraclock = INT_MIN; } FTA(QUOTE_VIEW_MODE_OFF + ps[myconnectindex].over_shoulder_on, &ps[myconnectindex]); } diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 3ce0c9e87..8c69288b1 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -228,7 +228,7 @@ static bool cheatView(cheatseq_t *) { ps[myconnectindex].over_shoulder_on = 1; cameradist = 0; - cameraclock = gameclock; + cameraclock = INT_MIN; } //FTA(22,&ps[myconnectindex]); this message makes no sense. } diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index 3cc7107bb..67525e72b 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -258,12 +258,10 @@ void GameInterface::MenuClosed() auto& gm = ps[myconnectindex].gm; if (gm & MODE_GAME) { - // The following lines are here so that you cannot close the menu when no game is running. - if (ud.multimode < 2 && ud.recstat != 2) { ready2send = 1; - cameraclock = gameclock; + cameraclock = INT_MIN; cameradist = 65536; } } diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 07ddd95ef..307c93396 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -116,7 +116,7 @@ void playerLookUp(int snum, ESyncBits actions); void playerLookDown(int snum, ESyncBits actions); void playerAimUp(int snum, ESyncBits actions); void playerAimDown(int snum, ESyncBits actions); -bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, int horiz); +bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, int horiz, double smoothratio); void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n); int hits(int i); int hitasprite(int i, short* hitsp); diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 040e35eda..26ed10eaf 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -274,7 +274,7 @@ void drawoverlays(double smoothratio) fi.displaymasks(screenpeek, smoothratio); } if (!isRR()) - moveclouds(); + moveclouds(smoothratio); } if (automapMode != am_off) diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index a10df4c78..bf9a06c51 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -1215,7 +1215,7 @@ int haskey(int sect, int snum) // //--------------------------------------------------------------------------- -bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, int horiz) +bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, int horiz, double smoothratio) { spritetype* sp; int i, nx, ny, nz, hx, hy, hitx, hity, hitz; @@ -1264,9 +1264,12 @@ bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, *vx = (*vx) + mulscale16(nx, cameradist); *vy = (*vy) + mulscale16(ny, cameradist); *vz = (*vz) + mulscale16(nz, cameradist); + + int myclock = ud.levelclock + int(TICSPERFRAME/65536. * smoothratio); + if (cameraclock == INT_MIN) cameraclock = myclock; // third person view was just started. - cameradist = min(cameradist + ((gameclock - cameraclock) << 10), 65536); - cameraclock = gameclock; + cameradist = min(cameradist + ((myclock - cameraclock) << 10), 65536); + cameraclock = myclock; updatesectorz(*vx, *vy, *vz, vsectnum); diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 8e91d79df..71c43dde1 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -593,7 +593,7 @@ void displayrooms(int snum, double smoothratio) { if (cl_viewbob) cposz += p->opyoff + xs_CRoundToInt(fmulscale16(p->pyoff - p->opyoff, smoothratio)); } - else view(p, &cposx, &cposy, &cposz, §, cang.asbuild(), choriz.asbuild()); + else view(p, &cposx, &cposy, &cposz, §, cang.asbuild(), choriz.asbuild(), smoothratio); cz = hittype[p->i].ceilingz; fz = hittype[p->i].floorz;