Implement interpolation at the renderer level

Instead of interpolating thinkers, we interpolate mobjs inside the
renderer. Further interpolation is TBI.
This commit is contained in:
Eidolon 2019-10-06 17:40:52 -05:00 committed by Sally Coolatta
parent 0fad5f5a23
commit 1550210188
20 changed files with 573 additions and 163 deletions

View file

@ -162,7 +162,7 @@ ifdef DEBUGMODE
ifdef GCC48 ifdef GCC48
opts+=-Og opts+=-Og
else else
opts+=O0 opts+=-O0
endif endif
endif endif

View file

@ -56,6 +56,7 @@ tables.c
r_bsp.c r_bsp.c
r_data.c r_data.c
r_draw.c r_draw.c
r_fps.c
r_main.c r_main.c
r_plane.c r_plane.c
r_segs.c r_segs.c

View file

@ -88,6 +88,12 @@ tic_t I_GetTime(void)
return (since_start*TICRATE)/1000000; return (since_start*TICRATE)/1000000;
} }
fixed_t I_GetTimeFrac(void)
{
//stub
return 0;
}
void I_Sleep(void){} void I_Sleep(void){}
void I_GetEvent(void){} void I_GetEvent(void){}

View file

@ -5288,6 +5288,7 @@ void TryRunTics(tic_t realtics)
while (neededtic > gametic) while (neededtic > gametic)
{ {
DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic));
prev_tics = I_GetTime();
ps_tictime = I_GetPreciseTime(); ps_tictime = I_GetPreciseTime();

View file

@ -63,6 +63,7 @@
#include "deh_tables.h" // Dehacked list test #include "deh_tables.h" // Dehacked list test
#include "m_cond.h" // condition initialization #include "m_cond.h" // condition initialization
#include "fastcmp.h" #include "fastcmp.h"
#include "r_fps.h" // Frame interpolation/uncapped
#include "keys.h" #include "keys.h"
#include "filesrch.h" // refreshdirmenu #include "filesrch.h" // refreshdirmenu
#include "g_input.h" // tutorial mode control scheming #include "g_input.h" // tutorial mode control scheming
@ -154,6 +155,7 @@ event_t events[MAXEVENTS];
INT32 eventhead, eventtail; INT32 eventhead, eventtail;
boolean dedicated = false; boolean dedicated = false;
boolean tic_happened = false; // Frame interpolation/uncapped
// //
// D_PostEvent // D_PostEvent
@ -755,7 +757,7 @@ void D_SRB2Loop(void)
debugload--; debugload--;
#endif #endif
if (!realtics && !singletics) if (!realtics && !singletics && cv_frameinterpolation.value != 1)
{ {
I_Sleep(); I_Sleep();
continue; continue;
@ -771,15 +773,27 @@ void D_SRB2Loop(void)
realtics = 1; realtics = 1;
// process tics (but maybe not if realtic == 0) // process tics (but maybe not if realtic == 0)
tic_happened = realtics ? true : false;
TryRunTics(realtics); TryRunTics(realtics);
if (cv_frameinterpolation.value == 1)
rendertimefrac = I_GetTimeFrac();
else
rendertimefrac = FRACUNIT;
if (cv_frameinterpolation.value == 1)
{
D_Display();
}
if (lastdraw || singletics || gametic > rendergametic) if (lastdraw || singletics || gametic > rendergametic)
{ {
rendergametic = gametic; rendergametic = gametic;
rendertimeout = entertic+TICRATE/17; rendertimeout = entertic+TICRATE/17;
// Update display, next frame, with current state. // Update display, next frame, with current state.
D_Display(); // (Only display if not already done for frame interp)
cv_frameinterpolation.value == 0 ? D_Display() : 0;
if (moviemode) if (moviemode)
M_SaveFrame(); M_SaveFrame();
@ -788,7 +802,22 @@ void D_SRB2Loop(void)
} }
else if (rendertimeout < entertic) // in case the server hang or netsplit else if (rendertimeout < entertic) // in case the server hang or netsplit
{ {
D_Display(); #if 0
// Lagless camera! Yay!
if (gamestate == GS_LEVEL && netgame)
{
INT32 i;
for (i = 0; i <= r_splitscreen; i++)
{
if (camera[i].chase)
P_MoveChaseCamera(&players[displayplayers[i]], &camera[i], false);
}
}
#endif
// (Only display if not already done for frame interp)
cv_frameinterpolation.value == 0 ? D_Display() : 0;
if (moviemode) if (moviemode)
M_SaveFrame(); M_SaveFrame();

View file

@ -26,6 +26,7 @@ extern char srb2home[256]; //Alam: My Home
extern boolean usehome; //Alam: which path? extern boolean usehome; //Alam: which path?
extern const char *pandf; //Alam: how to path? extern const char *pandf; //Alam: how to path?
extern char srb2path[256]; //Alam: SRB2's Home extern char srb2path[256]; //Alam: SRB2's Home
extern boolean tic_happened; // Frame interpolation/uncapped
// the infinite loop of D_SRB2Loop() called from win_main for windows version // the infinite loop of D_SRB2Loop() called from win_main for windows version
void D_SRB2Loop(void) FUNCNORETURN; void D_SRB2Loop(void) FUNCNORETURN;

View file

@ -16,7 +16,7 @@ tic_t I_GetTime(void)
return 0; return 0;
} }
int I_GetTimeMicros(void) fixed_t I_GetTimeFrac(void)
{ {
return 0; return 0;
} }

View file

@ -45,8 +45,8 @@
#include "y_inter.h" #include "y_inter.h"
#include "v_video.h" #include "v_video.h"
#include "lua_hook.h" #include "lua_hook.h"
#include "k_bot.h"
#include "m_cond.h" // condition sets #include "m_cond.h" // condition sets
#include "r_fps.h" // frame interpolation/uncapped
#include "lua_hud.h" #include "lua_hud.h"
// SRB2kart // SRB2kart
@ -56,6 +56,7 @@
#include "k_color.h" #include "k_color.h"
#include "k_respawn.h" #include "k_respawn.h"
#include "k_grandprix.h" #include "k_grandprix.h"
#include "k_bot.h"
#include "doomstat.h" #include "doomstat.h"
#ifdef HAVE_DISCORDRPC #ifdef HAVE_DISCORDRPC
@ -1920,6 +1921,8 @@ void G_Ticker(boolean run)
F_TextPromptTicker(); F_TextPromptTicker();
AM_Ticker(); AM_Ticker();
HU_Ticker(); HU_Ticker();
R_UpdateViewInterpolation();
break; break;
case GS_INTERMISSION: case GS_INTERMISSION:
@ -1976,7 +1979,12 @@ void G_Ticker(boolean run)
break; break;
case GS_TITLESCREEN: case GS_TITLESCREEN:
if (titlemapinaction) P_Ticker(run); if (titlemapinaction)
{
P_Ticker(run);
R_UpdateViewInterpolation();
}
F_TitleScreenTicker(run); F_TitleScreenTicker(run);
break; break;

View file

@ -38,6 +38,7 @@
#include "../m_cheat.h" #include "../m_cheat.h"
#include "../f_finale.h" #include "../f_finale.h"
#include "../r_things.h" // R_GetShadowZ #include "../r_things.h" // R_GetShadowZ
#include "../d_main.h"
#include "../p_slopes.h" #include "../p_slopes.h"
#include "hw_md2.h" #include "hw_md2.h"
@ -5013,10 +5014,6 @@ static void HWR_AddSprites(sector_t *sec)
// BP why not use xtoviexangle/viewangletox like in bsp ?.... // BP why not use xtoviexangle/viewangletox like in bsp ?....
static void HWR_ProjectSprite(mobj_t *thing) static void HWR_ProjectSprite(mobj_t *thing)
{ {
fixed_t thingxpos = thing->x + thing->sprxoff;
fixed_t thingypos = thing->y + thing->spryoff;
fixed_t thingzpos = thing->z + thing->sprzoff;
gl_vissprite_t *vis; gl_vissprite_t *vis;
float tr_x, tr_y; float tr_x, tr_y;
float tz; float tz;
@ -5056,13 +5053,34 @@ static void HWR_ProjectSprite(mobj_t *thing)
angle_t spriterotangle = 0; angle_t spriterotangle = 0;
#endif #endif
// uncapped/interpolation
fixed_t interpx;
fixed_t interpy;
fixed_t interpz;
angle_t interpangle;
if (!thing) if (!thing)
return; return;
if (thing->spritexscale < 1 || thing->spriteyscale < 1) if (thing->spritexscale < 1 || thing->spriteyscale < 1)
return; return;
// hitlag vibrating dispoffset = thing->info->dispoffset;
interpx = thing->x + thing->sprxoff;
interpy = thing->y + thing->spryoff;
interpz = thing->z + thing->sprzoff;
interpangle = mobjangle;
if (cv_frameinterpolation.value == 1 && !paused)
{
interpx = thing->old_x + FixedMul(rendertimefrac, thing->x - thing->old_x);
interpy = thing->old_y + FixedMul(rendertimefrac, thing->y - thing->old_y);
interpz = thing->old_z + FixedMul(rendertimefrac, thing->z - thing->old_z);
interpangle = mobjangle;
}
// hitlag vibrating (todo: interp somehow?)
if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG))
{ {
fixed_t mul = thing->hitlag * (FRACUNIT / 10); fixed_t mul = thing->hitlag * (FRACUNIT / 10);
@ -5072,20 +5090,18 @@ static void HWR_ProjectSprite(mobj_t *thing)
mul = -mul; mul = -mul;
} }
thingxpos += FixedMul(thing->momx, mul); interpx += FixedMul(thing->momx, mul);
thingypos += FixedMul(thing->momy, mul); interpy += FixedMul(thing->momy, mul);
thingzpos += FixedMul(thing->momz, mul); interpz += FixedMul(thing->momz, mul);
} }
dispoffset = thing->info->dispoffset;
this_scale = FIXED_TO_FLOAT(thing->scale); this_scale = FIXED_TO_FLOAT(thing->scale);
spritexscale = FIXED_TO_FLOAT(thing->spritexscale); spritexscale = FIXED_TO_FLOAT(thing->spritexscale);
spriteyscale = FIXED_TO_FLOAT(thing->spriteyscale); spriteyscale = FIXED_TO_FLOAT(thing->spriteyscale);
// transform the origin point // transform the origin point
tr_x = FIXED_TO_FLOAT(thingxpos) - gl_viewx; tr_x = FIXED_TO_FLOAT(interpx) - gl_viewx;
tr_y = FIXED_TO_FLOAT(thingypos) - gl_viewy; tr_y = FIXED_TO_FLOAT(interpy) - gl_viewy;
// rotation around vertical axis // rotation around vertical axis
tz = (tr_x * gl_viewcos) + (tr_y * gl_viewsin); tz = (tr_x * gl_viewcos) + (tr_y * gl_viewsin);
@ -5108,8 +5124,8 @@ static void HWR_ProjectSprite(mobj_t *thing)
} }
// The above can stay as it works for cutting sprites that are too close // The above can stay as it works for cutting sprites that are too close
tr_x = FIXED_TO_FLOAT(thingxpos); tr_x = FIXED_TO_FLOAT(interpx);
tr_y = FIXED_TO_FLOAT(thingypos); tr_y = FIXED_TO_FLOAT(interpy);
// decide which patch to use for sprite relative to player // decide which patch to use for sprite relative to player
#ifdef RANGECHECK #ifdef RANGECHECK
@ -5157,7 +5173,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
I_Error("sprframes NULL for sprite %d\n", thing->sprite); I_Error("sprframes NULL for sprite %d\n", thing->sprite);
#endif #endif
ang = R_PointToAngle (thingxpos, thingypos) - mobjangle; ang = R_PointToAngle (interpx, interpy) - interpangle;
if (mirrored) if (mirrored)
ang = InvAngle(ang); ang = InvAngle(ang);
@ -5304,12 +5320,12 @@ static void HWR_ProjectSprite(mobj_t *thing)
if (vflip) if (vflip)
{ {
gz = FIXED_TO_FLOAT(thingzpos + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); gz = FIXED_TO_FLOAT(interpz + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale);
gzt = gz + (FIXED_TO_FLOAT(spr_height) * this_yscale); gzt = gz + (FIXED_TO_FLOAT(spr_height) * this_yscale);
} }
else else
{ {
gzt = FIXED_TO_FLOAT(thingzpos) + (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); gzt = FIXED_TO_FLOAT(interpz) + (FIXED_TO_FLOAT(spr_topoffset) * this_yscale);
gz = gzt - (FIXED_TO_FLOAT(spr_height) * this_yscale); gz = gzt - (FIXED_TO_FLOAT(spr_height) * this_yscale);
} }
@ -5328,12 +5344,12 @@ static void HWR_ProjectSprite(mobj_t *thing)
if (heightsec != -1 && phs != -1) // only clip things which are in special sectors if (heightsec != -1 && phs != -1) // only clip things which are in special sectors
{ {
if (gl_viewz < FIXED_TO_FLOAT(sectors[phs].floorheight) ? if (gl_viewz < FIXED_TO_FLOAT(sectors[phs].floorheight) ?
FIXED_TO_FLOAT(thingzpos) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : FIXED_TO_FLOAT(interpz) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) :
gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight))
return; return;
if (gl_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? if (gl_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ?
gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gl_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gl_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) :
FIXED_TO_FLOAT(thingzpos) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) FIXED_TO_FLOAT(interpz) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight))
return; return;
} }
@ -5468,9 +5484,29 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
unsigned rot = 0; unsigned rot = 0;
UINT8 flip; UINT8 flip;
// uncapped/interpolation
fixed_t interpx;
fixed_t interpy;
fixed_t interpz;
if (!thing)
return;
interpx = thing->x;
interpy = thing->y;
interpz = thing->z;
// do interpolation
if (cv_frameinterpolation.value == 1 && !paused)
{
interpx = thing->old_x + FixedMul(rendertimefrac, thing->x - thing->old_x);
interpy = thing->old_y + FixedMul(rendertimefrac, thing->y - thing->old_y);
interpz = thing->old_z + FixedMul(rendertimefrac, thing->z - thing->old_z);
}
// transform the origin point // transform the origin point
tr_x = FIXED_TO_FLOAT(thing->x) - gl_viewx; tr_x = FIXED_TO_FLOAT(interpx) - gl_viewx;
tr_y = FIXED_TO_FLOAT(thing->y) - gl_viewy; tr_y = FIXED_TO_FLOAT(interpy) - gl_viewy;
// rotation around vertical axis // rotation around vertical axis
tz = (tr_x * gl_viewcos) + (tr_y * gl_viewsin); tz = (tr_x * gl_viewcos) + (tr_y * gl_viewsin);
@ -5479,8 +5515,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
if (tz < ZCLIP_PLANE) if (tz < ZCLIP_PLANE)
return; return;
tr_x = FIXED_TO_FLOAT(thing->x); tr_x = FIXED_TO_FLOAT(interpx);
tr_y = FIXED_TO_FLOAT(thing->y); tr_y = FIXED_TO_FLOAT(interpy);
// decide which patch to use for sprite relative to player // decide which patch to use for sprite relative to player
if ((unsigned)thing->sprite >= numsprites) if ((unsigned)thing->sprite >= numsprites)
@ -5547,7 +5583,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
#endif #endif
// set top/bottom coords // set top/bottom coords
vis->gzt = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset); vis->gzt = FIXED_TO_FLOAT(interpz + spritecachedinfo[lumpoff].topoffset);
vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height);
vis->precip = true; vis->precip = true;
@ -6651,6 +6687,7 @@ INT32 HWR_GetTextureUsed(void)
void HWR_DoPostProcessor(player_t *player) void HWR_DoPostProcessor(player_t *player)
{ {
postimg_t *type = &postimgtype[0]; postimg_t *type = &postimgtype[0];
fixed_t fractime;
SINT8 i; SINT8 i;
HWD.pfnUnSetShader(); HWD.pfnUnSetShader();
@ -6702,6 +6739,8 @@ void HWR_DoPostProcessor(player_t *player)
// 10 by 10 grid. 2 coordinates (xy) // 10 by 10 grid. 2 coordinates (xy)
float v[SCREENVERTS][SCREENVERTS][2]; float v[SCREENVERTS][SCREENVERTS][2];
static double disStart = 0; static double disStart = 0;
static float last_fractime = 0;
UINT8 x, y; UINT8 x, y;
INT32 WAVELENGTH; INT32 WAVELENGTH;
INT32 AMPLITUDE; INT32 AMPLITUDE;
@ -6733,6 +6772,16 @@ void HWR_DoPostProcessor(player_t *player)
HWD.pfnPostImgRedraw(v); HWD.pfnPostImgRedraw(v);
if (!(paused || P_AutoPause())) if (!(paused || P_AutoPause()))
disStart += 1; disStart += 1;
fractime = I_GetTimeFrac();
if (tic_happened)
{
disStart = disStart - last_fractime + 1 + FIXED_TO_FLOAT(fractime);
}
else
{
disStart = disStart - last_fractime + FIXED_TO_FLOAT(fractime);
}
last_fractime = fractime;
// Capture the screen again for screen waving on the intermission // Capture the screen again for screen waving on the intermission
if(gamestate != GS_INTERMISSION) if(gamestate != GS_INTERMISSION)

View file

@ -46,6 +46,10 @@ UINT32 I_GetFreeMem(UINT32 *total);
*/ */
tic_t I_GetTime(void); tic_t I_GetTime(void);
/** \brief Get the current time as a fraction of a tic since the last tic.
*/
fixed_t I_GetTimeFrac(void);
/** \brief Returns precise time value for performance measurement. /** \brief Returns precise time value for performance measurement.
*/ */
precise_t I_GetPreciseTime(void); precise_t I_GetPreciseTime(void);

View file

@ -3636,6 +3636,11 @@ void P_NullPrecipThinker(precipmobj_t *mobj)
void P_PrecipThinker(precipmobj_t *mobj) void P_PrecipThinker(precipmobj_t *mobj)
{ {
// reset old state (for interpolation)
mobj->old_x = mobj->x;
mobj->old_y = mobj->y;
mobj->old_z = mobj->z;
P_CycleStateAnimation((mobj_t *)mobj); P_CycleStateAnimation((mobj_t *)mobj);
if (mobj->state == &states[S_RAINRETURN]) if (mobj->state == &states[S_RAINRETURN])
@ -8593,6 +8598,11 @@ void P_MobjThinker(mobj_t *mobj)
I_Assert(mobj != NULL); I_Assert(mobj != NULL);
I_Assert(!P_MobjWasRemoved(mobj)); I_Assert(!P_MobjWasRemoved(mobj));
// Set old position (for interpolation)
mobj->old_x = mobj->x;
mobj->old_y = mobj->y;
mobj->old_z = mobj->z;
// Remove dead target/tracer. // Remove dead target/tracer.
if (mobj->target && P_MobjWasRemoved(mobj->target)) if (mobj->target && P_MobjWasRemoved(mobj->target))
P_SetTarget(&mobj->target, NULL); P_SetTarget(&mobj->target, NULL);
@ -9743,6 +9753,11 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
if (CheckForReverseGravity && !(mobj->flags & MF_NOBLOCKMAP)) if (CheckForReverseGravity && !(mobj->flags & MF_NOBLOCKMAP))
P_CheckGravity(mobj, false); P_CheckGravity(mobj, false);
// set initial old positions (for interpolation)
mobj->old_x = mobj->x;
mobj->old_y = mobj->y;
mobj->old_z = mobj->z;
return mobj; return mobj;
} }
@ -9794,6 +9809,11 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype
|| mobj->subsector->sector->floorpic == skyflatnum) || mobj->subsector->sector->floorpic == skyflatnum)
mobj->precipflags |= PCF_PIT; mobj->precipflags |= PCF_PIT;
// set initial old positions (for interpolation)
mobj->old_x = mobj->x;
mobj->old_y = mobj->y;
mobj->old_z = mobj->z;
return mobj; return mobj;
} }

View file

@ -275,6 +275,7 @@ typedef struct mobj_s
// Info for drawing: position. // Info for drawing: position.
fixed_t x, y, z; fixed_t x, y, z;
fixed_t old_x, old_y, old_z; // position interpolation
// More list: links in sector (if needed) // More list: links in sector (if needed)
struct mobj_s *snext; struct mobj_s *snext;
@ -412,6 +413,7 @@ typedef struct precipmobj_s
// Info for drawing: position. // Info for drawing: position.
fixed_t x, y, z; fixed_t x, y, z;
fixed_t old_x, old_y, old_z; // position interpolation
// More list: links in sector (if needed) // More list: links in sector (if needed)
struct precipmobj_s *snext; struct precipmobj_s *snext;

View file

@ -24,6 +24,7 @@
#include "lua_hook.h" #include "lua_hook.h"
#include "m_perfstats.h" #include "m_perfstats.h"
#include "i_system.h" // I_GetPreciseTime #include "i_system.h" // I_GetPreciseTime
#include "r_fps.h"
// Object place // Object place
#include "m_cheat.h" #include "m_cheat.h"

175
src/r_fps.c Normal file
View file

@ -0,0 +1,175 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2000 by Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze, Andrey Budko (prboom)
// Copyright (C) 1999-2019 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_fps.h
/// \brief Uncapped framerate stuff.
#include "r_fps.h"
#include "r_main.h"
#include "g_game.h"
#include "i_video.h"
#include "r_plane.h"
#include "p_spec.h"
#include "r_state.h"
#include "doomstat.h" // MAXSPLITSCREENPLAYERS
#ifdef HWRENDER
#include "hardware/hw_main.h" // for cv_glshearing
#endif
static viewvars_t pview_old[MAXSPLITSCREENPLAYERS];
static viewvars_t pview_new[MAXSPLITSCREENPLAYERS];
static viewvars_t skyview_old[MAXSPLITSCREENPLAYERS];
static viewvars_t skyview_new[MAXSPLITSCREENPLAYERS];
static viewvars_t *oldview = &pview_old[0];
viewvars_t *newview = &pview_new[0];
enum viewcontext_e viewcontext = VIEWCONTEXT_PLAYER1;
// recalc necessary stuff for mouseaiming
// slopes are already calculated for the full possible view (which is 4*viewheight).
// 18/08/18: (No it's actually 16*viewheight, thanks Jimita for finding this out)
static void R_SetupFreelook(player_t *player, boolean skybox)
{
#ifndef HWRENDER
(void)player;
(void)skybox;
#endif
// clip it in the case we are looking a hardware 90 degrees full aiming
// (lmps, network and use F12...)
if (rendermode == render_soft
#ifdef HWRENDER
|| (rendermode == render_opengl
&& (cv_glshearing.value == 1
|| (cv_glshearing.value == 2 && R_IsViewpointThirdPerson(player, skybox))))
#endif
)
{
G_SoftwareClipAimingPitch((INT32 *)&aimingangle);
}
centeryfrac = (viewheight/2)<<FRACBITS;
if (rendermode == render_soft)
centeryfrac += FixedMul(AIMINGTODY(aimingangle), FixedDiv(viewwidth<<FRACBITS, BASEVIDWIDTH<<FRACBITS));
centery = FixedInt(FixedRound(centeryfrac));
if (rendermode == render_soft)
yslope = &yslopetab[viewssnum][viewheight*8 - centery];
}
#undef AIMINGTODY
void R_InterpolateView(fixed_t frac)
{
boolean skybox = false;
INT32 i;
if (FIXED_TO_FLOAT(frac) < 0)
frac = 0;
viewx = oldview->x + R_LerpFixed(oldview->x, newview->x, frac);
viewy = oldview->y + R_LerpFixed(oldview->y, newview->y, frac);
viewz = oldview->z + R_LerpFixed(oldview->z, newview->z, frac);
viewangle = oldview->angle + R_LerpAngle(oldview->angle, newview->angle, frac);
aimingangle = oldview->aim + R_LerpAngle(oldview->aim, newview->aim, frac);
viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT);
viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT);
// this is gonna create some interesting visual errors for long distance teleports...
// might want to recalculate the view sector every frame instead...
if (frac >= FRACUNIT)
{
viewplayer = newview->player;
viewsector = newview->sector;
}
else
{
viewplayer = oldview->player;
viewsector = oldview->sector;
}
// well, this ain't pretty
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
if (newview == &skyview_new[i])
{
skybox = true;
break;
}
}
R_SetupFreelook(newview->player, skybox);
}
void R_UpdateViewInterpolation(void)
{
INT32 i;
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
pview_old[i] = pview_new[i];
skyview_old[i] = skyview_new[i];
}
}
void R_SetViewContext(enum viewcontext_e _viewcontext)
{
INT32 i;
I_Assert(_viewcontext >= VIEWCONTEXT_PLAYER1
&& _viewcontext <= VIEWCONTEXT_SKY4);
viewcontext = _viewcontext;
switch (viewcontext)
{
case VIEWCONTEXT_PLAYER1:
case VIEWCONTEXT_PLAYER2:
case VIEWCONTEXT_PLAYER3:
case VIEWCONTEXT_PLAYER4:
i = viewcontext - VIEWCONTEXT_PLAYER1;
oldview = &pview_old[i];
newview = &pview_new[i];
break;
case VIEWCONTEXT_SKY1:
case VIEWCONTEXT_SKY2:
case VIEWCONTEXT_SKY3:
case VIEWCONTEXT_SKY4:
i = viewcontext - VIEWCONTEXT_SKY1;
oldview = &skyview_old[i];
newview = &skyview_new[i];
break;
default:
I_Error("viewcontext value is invalid: we should never get here without an assert!!");
break;
}
}
fixed_t R_LerpFixed(fixed_t from, fixed_t to, fixed_t frac)
{
return FixedMul(frac, to - from);
}
INT32 R_LerpInt32(INT32 from, INT32 to, fixed_t frac)
{
return FixedInt(FixedMul(frac, (to*FRACUNIT) - (from*FRACUNIT)));
}
angle_t R_LerpAngle(angle_t from, angle_t to, fixed_t frac)
{
return FixedMul(frac, to - from);
}

63
src/r_fps.h Normal file
View file

@ -0,0 +1,63 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2000 by Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze, Andrey Budko (prboom)
// Copyright (C) 1999-2019 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_fps.h
/// \brief Uncapped framerate stuff.
#ifndef __R_FPS_H__
#define __R_FPS_H__
#include "m_fixed.h"
#include "p_local.h"
#include "r_state.h"
enum viewcontext_e
{
VIEWCONTEXT_PLAYER1 = 0,
VIEWCONTEXT_PLAYER2,
VIEWCONTEXT_PLAYER3,
VIEWCONTEXT_PLAYER4,
VIEWCONTEXT_SKY1,
VIEWCONTEXT_SKY2,
VIEWCONTEXT_SKY3,
VIEWCONTEXT_SKY4
};
typedef struct {
fixed_t x;
fixed_t y;
fixed_t z;
boolean sky;
sector_t *sector;
player_t *player;
angle_t angle;
angle_t aim;
fixed_t cos;
fixed_t sin;
mobj_t *mobj;
} viewvars_t;
extern viewvars_t *newview;
// Interpolates the current view variables (r_state.h) against the selected view context in R_SetViewContext
void R_InterpolateView(fixed_t frac);
// Buffer the current new views into the old views. Call once after each real tic.
void R_UpdateViewInterpolation(void);
// Set the current view context (the viewvars pointed to by newview)
void R_SetViewContext(enum viewcontext_e _viewcontext);
fixed_t R_LerpFixed(fixed_t from, fixed_t to, fixed_t frac);
INT32 R_LerpInt32(INT32 from, INT32 to, fixed_t frac);
UINT32 R_LerpUInt32(UINT32 from, UINT32 to, fixed_t frac);
angle_t R_LerpAngle(angle_t from, angle_t to, fixed_t frac);
#endif

View file

@ -36,6 +36,7 @@
#include "r_main.h" #include "r_main.h"
#include "i_system.h" // I_GetPreciseTime #include "i_system.h" // I_GetPreciseTime
#include "doomstat.h" // MAXSPLITSCREENPLAYERS #include "doomstat.h" // MAXSPLITSCREENPLAYERS
#include "r_fps.h" // Frame interpolation/uncapped
#ifdef HWRENDER #ifdef HWRENDER
#include "hardware/hw_main.h" #include "hardware/hw_main.h"
@ -79,6 +80,8 @@ mobj_t *r_viewmobj;
int r_splitscreen; int r_splitscreen;
fixed_t rendertimefrac;
// //
// precalculated math tables // precalculated math tables
// //
@ -100,6 +103,9 @@ lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
lighttable_t *scalelightfixed[MAXLIGHTSCALE]; lighttable_t *scalelightfixed[MAXLIGHTSCALE];
lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
// Frame interpolation/uncapped
tic_t prev_tics;
// Hack to support extra boom colormaps. // Hack to support extra boom colormaps.
extracolormap_t *extra_colormaps = NULL; extracolormap_t *extra_colormaps = NULL;
@ -172,6 +178,9 @@ consvar_t cv_fov[MAXSPLITSCREENPLAYERS] = {
CVAR_INIT ("fov4", "90", CV_FLOAT|CV_CALL, fov_cons_t, Fov_OnChange) CVAR_INIT ("fov4", "90", CV_FLOAT|CV_CALL, fov_cons_t, Fov_OnChange)
}; };
// Frame interpolation/uncapped
consvar_t cv_frameinterpolation = CVAR_INIT ("frameinterpolation", "On", CV_SAVE, CV_OnOff, NULL);
// Okay, whoever said homremoval causes a performance hit should be shot. // Okay, whoever said homremoval causes a performance hit should be shot.
consvar_t cv_homremoval = CVAR_INIT ("homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL); consvar_t cv_homremoval = CVAR_INIT ("homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL);
@ -1193,40 +1202,6 @@ subsector_t *R_PointInSubsectorOrNull(fixed_t x, fixed_t y)
// R_SetupFrame // R_SetupFrame
// //
// recalc necessary stuff for mouseaiming
// slopes are already calculated for the full possible view (which is 4*viewheight).
// 18/08/18: (No it's actually 16*viewheight, thanks Jimita for finding this out)
static void R_SetupFreelook(player_t *player, boolean skybox)
{
#ifndef HWRENDER
(void)player;
(void)skybox;
#endif
// clip it in the case we are looking a hardware 90 degrees full aiming
// (lmps, network and use F12...)
if (rendermode == render_soft
#ifdef HWRENDER
|| (rendermode == render_opengl
&& (cv_glshearing.value == 1
|| (cv_glshearing.value == 2 && R_IsViewpointThirdPerson(player, skybox))))
#endif
)
{
G_SoftwareClipAimingPitch((INT32 *)&aimingangle);
}
centeryfrac = (viewheight/2)<<FRACBITS;
if (rendermode == render_soft)
centeryfrac += FixedMul(AIMINGTODY(aimingangle), FixedDiv(viewwidth<<FRACBITS, BASEVIDWIDTH<<FRACBITS));
centery = FixedInt(FixedRound(centeryfrac));
if (rendermode == render_soft)
yslope = &yslopetab[viewssnum][viewheight*8 - centery];
}
void R_SetupFrame(player_t *player) void R_SetupFrame(player_t *player)
{ {
camera_t *thiscam = &camera[0]; camera_t *thiscam = &camera[0];
@ -1239,6 +1214,7 @@ void R_SetupFrame(player_t *player)
{ {
thiscam = &camera[i]; thiscam = &camera[i];
chasecam = (cv_chasecam[i].value != 0); chasecam = (cv_chasecam[i].value != 0);
R_SetViewContext(VIEWCONTEXT_PLAYER1 + i);
break; break;
} }
} }
@ -1257,73 +1233,75 @@ void R_SetupFrame(player_t *player)
else if (!chasecam) else if (!chasecam)
thiscam->chase = false; thiscam->chase = false;
newview->sky = false;
if (player->awayviewtics) if (player->awayviewtics)
{ {
// cut-away view stuff // cut-away view stuff
r_viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN r_viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN
I_Assert(r_viewmobj != NULL); I_Assert(r_viewmobj != NULL);
viewz = r_viewmobj->z + 20*FRACUNIT; newview->z = r_viewmobj->z + 20*FRACUNIT;
aimingangle = player->awayviewaiming; newview->aim = player->awayviewaiming;
viewangle = r_viewmobj->angle; newview->angle = r_viewmobj->angle;
} }
else if (!player->spectator && chasecam) else if (!player->spectator && chasecam)
// use outside cam view // use outside cam view
{ {
r_viewmobj = NULL; r_viewmobj = NULL;
viewz = thiscam->z + (thiscam->height>>1); newview->z = thiscam->z + (thiscam->height>>1);
aimingangle = thiscam->aiming; newview->aim = thiscam->aiming;
viewangle = thiscam->angle; newview->angle = thiscam->angle;
} }
else else
// use the player's eyes view // use the player's eyes view
{ {
viewz = player->viewz; newview->z = player->viewz;
r_viewmobj = player->mo; r_viewmobj = player->mo;
I_Assert(r_viewmobj != NULL); I_Assert(r_viewmobj != NULL);
aimingangle = player->aiming; newview->aim = player->aiming;
viewangle = r_viewmobj->angle; newview->angle = r_viewmobj->angle;
if (!demo.playback && player->playerstate != PST_DEAD) if (!demo.playback && player->playerstate != PST_DEAD)
{ {
viewangle = localangle[i]; // WARNING: camera uses this newview->angle = localangle[i]; // WARNING: camera uses this
aimingangle = localaiming[i]; newview->aim = localaiming[i];
} }
} }
viewz += quake.z; newview->z += quake.z;
viewplayer = player; newview->player = player;
if (chasecam && !player->awayviewtics && !player->spectator) if (chasecam && !player->awayviewtics && !player->spectator)
{ {
viewx = thiscam->x; newview->x = thiscam->x;
viewy = thiscam->y; newview->y = thiscam->y;
viewx += quake.x; newview->x += quake.x;
viewy += quake.y; newview->y += quake.y;
if (thiscam->subsector) if (thiscam->subsector)
viewsector = thiscam->subsector->sector; newview->sector = thiscam->subsector->sector;
else else
viewsector = R_PointInSubsector(viewx, viewy)->sector; newview->sector = R_PointInSubsector(newview->x, newview->y)->sector;
} }
else else
{ {
viewx = r_viewmobj->x; newview->x = r_viewmobj->x;
viewy = r_viewmobj->y; newview->y = r_viewmobj->y;
viewx += quake.x; newview->x += quake.x;
viewy += quake.y; newview->y += quake.y;
if (r_viewmobj->subsector) if (r_viewmobj->subsector)
viewsector = r_viewmobj->subsector->sector; newview->sector = r_viewmobj->subsector->sector;
else else
viewsector = R_PointInSubsector(viewx, viewy)->sector; newview->sector = R_PointInSubsector(newview->x, newview->y)->sector;
} }
viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT);
viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT);
R_SetupFreelook(player, false); R_InterpolateView(cv_frameinterpolation.value == 1 ? rendertimefrac : FRACUNIT);
} }
void R_SkyboxFrame(player_t *player) void R_SkyboxFrame(player_t *player)
@ -1338,6 +1316,7 @@ void R_SkyboxFrame(player_t *player)
if (player == &players[displayplayers[i]]) if (player == &players[displayplayers[i]])
{ {
thiscam = &camera[i]; thiscam = &camera[i];
R_SetViewContext(VIEWCONTEXT_SKY1 + i);
break; break;
} }
} }
@ -1349,6 +1328,7 @@ void R_SkyboxFrame(player_t *player)
} }
// cut-away view stuff // cut-away view stuff
newview->sky = true;
r_viewmobj = skyboxmo[0]; r_viewmobj = skyboxmo[0];
#ifdef PARANOIA #ifdef PARANOIA
if (!r_viewmobj) if (!r_viewmobj)
@ -1359,31 +1339,31 @@ void R_SkyboxFrame(player_t *player)
#endif #endif
if (player->awayviewtics) if (player->awayviewtics)
{ {
aimingangle = player->awayviewaiming; newview->aim = player->awayviewaiming;
viewangle = player->awayviewmobj->angle; newview->angle = player->awayviewmobj->angle;
} }
else if (thiscam->chase) else if (thiscam->chase)
{ {
aimingangle = thiscam->aiming; newview->aim = thiscam->aiming;
viewangle = thiscam->angle; newview->angle = thiscam->angle;
} }
else else
{ {
aimingangle = player->aiming; newview->aim = player->aiming;
viewangle = player->mo->angle; newview->angle = player->mo->angle;
if (/*!demo.playback && */player->playerstate != PST_DEAD) if (/*!demo.playback && */player->playerstate != PST_DEAD)
{ {
viewangle = localangle[i]; newview->angle = localangle[i];
aimingangle = localaiming[i]; newview->aim = localaiming[i];
} }
} }
viewangle += r_viewmobj->angle; newview->angle += r_viewmobj->angle;
viewplayer = player; newview->player = player;
viewx = r_viewmobj->x; newview->x = r_viewmobj->x;
viewy = r_viewmobj->y; newview->y = r_viewmobj->y;
viewz = r_viewmobj->z; // 26/04/17: use actual Z position instead of spawnpoint angle! newview->z = r_viewmobj->z; // 26/04/17: use actual Z position instead of spawnpoint angle!
if (mapheaderinfo[gamemap-1]) if (mapheaderinfo[gamemap-1])
{ {
@ -1425,46 +1405,46 @@ void R_SkyboxFrame(player_t *player)
if (r_viewmobj->angle == 0) if (r_viewmobj->angle == 0)
{ {
viewx += x; newview->x += x;
viewy += y; newview->y += y;
} }
else if (r_viewmobj->angle == ANGLE_90) else if (r_viewmobj->angle == ANGLE_90)
{ {
viewx -= y; newview->x -= y;
viewy += x; newview->y += x;
} }
else if (r_viewmobj->angle == ANGLE_180) else if (r_viewmobj->angle == ANGLE_180)
{ {
viewx -= x; newview->x -= x;
viewy -= y; newview->y -= y;
} }
else if (r_viewmobj->angle == ANGLE_270) else if (r_viewmobj->angle == ANGLE_270)
{ {
viewx += y; newview->x += y;
viewy -= x; newview->y -= x;
} }
else else
{ {
angle_t ang = r_viewmobj->angle>>ANGLETOFINESHIFT; angle_t ang = r_viewmobj->angle>>ANGLETOFINESHIFT;
viewx += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang)); newview->x += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang));
viewy += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang)); newview->y += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang));
} }
} }
if (mh->skybox_scalez > 0) if (mh->skybox_scalez > 0)
viewz += campos.z / mh->skybox_scalez; newview->z += campos.z / mh->skybox_scalez;
else if (mh->skybox_scalez < 0) else if (mh->skybox_scalez < 0)
viewz += campos.z * -mh->skybox_scalez; newview->z += campos.z * -mh->skybox_scalez;
} }
if (r_viewmobj->subsector) if (r_viewmobj->subsector)
viewsector = r_viewmobj->subsector->sector; newview->sector = r_viewmobj->subsector->sector;
else else
viewsector = R_PointInSubsector(viewx, viewy)->sector; newview->sector = R_PointInSubsector(newview->x, newview->y)->sector;
viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT);
viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT);
R_SetupFreelook(player, true); R_InterpolateView(cv_frameinterpolation.value == 1 ? rendertimefrac : FRACUNIT);
} }
boolean R_ViewpointHasChasecam(player_t *player) boolean R_ViewpointHasChasecam(player_t *player)
@ -1737,4 +1717,7 @@ void R_RegisterEngineStuff(void)
CV_RegisterVar(&cv_maxportals); CV_RegisterVar(&cv_maxportals);
CV_RegisterVar(&cv_movebob); CV_RegisterVar(&cv_movebob);
// Frame interpolation/uncapped
CV_RegisterVar(&cv_frameinterpolation);
} }

View file

@ -33,6 +33,8 @@ extern fixed_t fovtan[MAXSPLITSCREENPLAYERS];
extern size_t validcount, linecount, loopcount, framecount; extern size_t validcount, linecount, loopcount, framecount;
extern fixed_t rendertimefrac;
// //
// Lighting LUT. // Lighting LUT.
// Used for z-depth cuing per column/row, // Used for z-depth cuing per column/row,
@ -111,6 +113,10 @@ extern consvar_t cv_fov[MAXSPLITSCREENPLAYERS];
extern consvar_t cv_skybox; extern consvar_t cv_skybox;
extern consvar_t cv_tailspickup; extern consvar_t cv_tailspickup;
// Frame interpolation (uncapped framerate)
extern tic_t prev_tics;
extern consvar_t cv_frameinterpolation;
// Called by startup code. // Called by startup code.
void R_Init(void); void R_Init(void);

View file

@ -1361,15 +1361,11 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
// //
static void R_ProjectSprite(mobj_t *thing) static void R_ProjectSprite(mobj_t *thing)
{ {
fixed_t thingxpos = thing->x + thing->sprxoff;
fixed_t thingypos = thing->y + thing->spryoff;
fixed_t thingzpos = thing->z + thing->sprzoff;
mobj_t *oldthing = thing; mobj_t *oldthing = thing;
//const fixed_t oldthingxpos = oldthing->x + oldthing->sprxoff; //const fixed_t oldthingxpos = oldthing->x + oldthing->sprxoff;
//const fixed_t oldthingypos = oldthing->y + oldthing->spryoff; //const fixed_t oldthingypos = oldthing->y + oldthing->spryoff;
const fixed_t oldthingzpos = oldthing->z + oldthing->sprzoff; //const fixed_t oldthingzpos = oldthing->z + oldthing->sprzoff;
fixed_t tr_x, tr_y; fixed_t tr_x, tr_y;
fixed_t tx, tz; fixed_t tx, tz;
@ -1435,7 +1431,32 @@ static void R_ProjectSprite(mobj_t *thing)
angle_t spriterotangle = 0; angle_t spriterotangle = 0;
#endif #endif
// hitlag vibrating // uncapped/interpolation
fixed_t interpx = thing->x + thing->sprxoff;
fixed_t interpy = thing->y + thing->spryoff;
fixed_t interpz = thing->z + thing->sprzoff;
angle_t interpangle = thing->angle;
// use player drawangle if player
if (thing->player) interpangle = thing->player->drawangle;
// do interpolation
if (cv_frameinterpolation.value == 1 && !paused)
{
interpx = thing->old_x + FixedMul(rendertimefrac, thing->x - thing->old_x);
interpy = thing->old_y + FixedMul(rendertimefrac, thing->y - thing->old_y);
interpz = thing->old_z + FixedMul(rendertimefrac, thing->z - thing->old_z);
if (thing->player)
{
interpangle = thing->player->drawangle;
}
else
{
interpangle = thing->angle;
}
}
// hitlag vibrating (todo: interp somehow?)
if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG)) if (thing->hitlag > 0 && (thing->eflags & MFE_DAMAGEHITLAG))
{ {
fixed_t mul = thing->hitlag * (FRACUNIT / 10); fixed_t mul = thing->hitlag * (FRACUNIT / 10);
@ -1445,14 +1466,14 @@ static void R_ProjectSprite(mobj_t *thing)
mul = -mul; mul = -mul;
} }
thingxpos += FixedMul(thing->momx, mul); interpx += FixedMul(thing->momx, mul);
thingypos += FixedMul(thing->momy, mul); interpy += FixedMul(thing->momy, mul);
thingzpos += FixedMul(thing->momz, mul); interpz += FixedMul(thing->momz, mul);
} }
// transform the origin point // transform the origin point
tr_x = thingxpos - viewx; tr_x = interpx - viewx;
tr_y = thingypos - viewy; tr_y = interpy - viewy;
basetz = tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); // near/far distance basetz = tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); // near/far distance
@ -1529,7 +1550,7 @@ static void R_ProjectSprite(mobj_t *thing)
if (sprframe->rotate != SRF_SINGLE || papersprite) if (sprframe->rotate != SRF_SINGLE || papersprite)
{ {
ang = R_PointToAngle (thingxpos, thingypos) - (thing->player ? thing->player->drawangle : thing->angle); ang = R_PointToAngle (interpx, interpy) - interpangle;
if (mirrored) if (mirrored)
ang = InvAngle(ang); ang = InvAngle(ang);
} }
@ -1544,7 +1565,7 @@ static void R_ProjectSprite(mobj_t *thing)
else else
{ {
// choose a different rotation based on player view // choose a different rotation based on player view
//ang = R_PointToAngle (thingxpos, thingypos) - thing->angle; //ang = R_PointToAngle (interpx, interpy) - interpangle;
if ((sprframe->rotate & SRF_RIGHT) && (ang < ANGLE_180)) // See from right if ((sprframe->rotate & SRF_RIGHT) && (ang < ANGLE_180)) // See from right
rot = 6; // F7 slot rot = 6; // F7 slot
@ -1755,12 +1776,17 @@ static void R_ProjectSprite(mobj_t *thing)
fixed_t linkscale; fixed_t linkscale;
thing = thing->tracer; thing = thing->tracer;
if (cv_frameinterpolation.value == 1 && !paused)
{
interpx = thing->old_x + FixedMul(thing->x - thing->old_x, rendertimefrac);
interpy = thing->old_y + FixedMul(thing->y - thing->old_y, rendertimefrac);
}
if (! R_ThingVisible(thing)) if (! R_ThingVisible(thing))
return; return;
tr_x = (thingxpos + sort_x) - viewx; tr_x = (interpx + sort_x) - viewx;
tr_y = (thingypos + sort_y) - viewy; tr_y = (interpy + sort_y) - viewy;
tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin);
linkscale = FixedDiv(projectiony[viewssnum], tz); linkscale = FixedDiv(projectiony[viewssnum], tz);
@ -1775,8 +1801,8 @@ static void R_ProjectSprite(mobj_t *thing)
} }
else if (splat) else if (splat)
{ {
tr_x = (thingxpos + sort_x) - viewx; tr_x = (interpx + sort_x) - viewx;
tr_y = (thingypos + sort_y) - viewy; tr_y = (interpy + sort_y) - viewy;
sort_z = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); sort_z = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin);
sortscale = FixedDiv(projectiony[viewssnum], sort_z); sortscale = FixedDiv(projectiony[viewssnum], sort_z);
} }
@ -1796,7 +1822,7 @@ static void R_ProjectSprite(mobj_t *thing)
if (x2 < portalclipstart || x1 >= portalclipend) if (x2 < portalclipstart || x1 >= portalclipend)
return; return;
if (P_PointOnLineSide(thingxpos, thingypos, portalclipline) != 0) if (P_PointOnLineSide(interpx, interpy, portalclipline) != 0)
return; return;
} }
@ -1865,12 +1891,12 @@ static void R_ProjectSprite(mobj_t *thing)
// When vertical flipped, draw sprites from the top down, at least as far as offsets are concerned. // When vertical flipped, draw sprites from the top down, at least as far as offsets are concerned.
// sprite height - sprite topoffset is the proper inverse of the vertical offset, of course. // sprite height - sprite topoffset is the proper inverse of the vertical offset, of course.
// remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes! // remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes!
gz = oldthingzpos + oldthing->height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale)); gz = interpz + oldthing->height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale));
gzt = gz + FixedMul(spr_height, FixedMul(spriteyscale, this_scale)); gzt = gz + FixedMul(spr_height, FixedMul(spriteyscale, this_scale));
} }
else else
{ {
gzt = oldthingzpos + FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale)); gzt = interpz + FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale));
gz = gzt - FixedMul(spr_height, FixedMul(spriteyscale, this_scale)); gz = gzt - FixedMul(spr_height, FixedMul(spriteyscale, this_scale));
} }
} }
@ -1889,7 +1915,7 @@ static void R_ProjectSprite(mobj_t *thing)
// R_GetPlaneLight won't work on sloped lights! // R_GetPlaneLight won't work on sloped lights!
for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) { for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) {
fixed_t h = P_GetLightZAt(&thing->subsector->sector->lightlist[lightnum], thingxpos, thingypos); fixed_t h = P_GetLightZAt(&thing->subsector->sector->lightlist[lightnum], interpx, interpy);
if (h <= top) { if (h <= top) {
light = lightnum - 1; light = lightnum - 1;
break; break;
@ -1915,12 +1941,12 @@ static void R_ProjectSprite(mobj_t *thing)
if (heightsec != -1 && phs != -1) // only clip things which are in special sectors if (heightsec != -1 && phs != -1) // only clip things which are in special sectors
{ {
if (viewz < sectors[phs].floorheight ? if (viewz < sectors[phs].floorheight ?
thingzpos >= sectors[heightsec].floorheight : interpz >= sectors[heightsec].floorheight :
gzt < sectors[heightsec].floorheight) gzt < sectors[heightsec].floorheight)
return; return;
if (viewz > sectors[phs].ceilingheight ? if (viewz > sectors[phs].ceilingheight ?
gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight :
thingzpos >= sectors[heightsec].ceilingheight) interpz >= sectors[heightsec].ceilingheight)
return; return;
} }
@ -1933,12 +1959,12 @@ static void R_ProjectSprite(mobj_t *thing)
vis->sortscale = sortscale; vis->sortscale = sortscale;
vis->sortsplat = sortsplat; vis->sortsplat = sortsplat;
vis->dispoffset = dispoffset; // Monster Iestyn: 23/11/15 vis->dispoffset = dispoffset; // Monster Iestyn: 23/11/15
vis->gx = thingxpos; vis->gx = interpx;
vis->gy = thingypos; vis->gy = interpy;
vis->gz = gz; vis->gz = gz;
vis->gzt = gzt; vis->gzt = gzt;
vis->thingheight = thing->height; vis->thingheight = thing->height;
vis->pz = thingzpos; vis->pz = interpz;
vis->pzt = vis->pz + vis->thingheight; vis->pzt = vis->pz + vis->thingheight;
vis->texturemid = FixedDiv(gzt - viewz, spriteyscale); vis->texturemid = FixedDiv(gzt - viewz, spriteyscale);
vis->scalestep = scalestep; vis->scalestep = scalestep;
@ -2073,9 +2099,22 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
//SoM: 3/17/2000 //SoM: 3/17/2000
fixed_t gz, gzt; fixed_t gz, gzt;
// uncapped/interpolation
fixed_t interpx = thing->x;
fixed_t interpy = thing->y;
fixed_t interpz = thing->z;
// do interpolation
if (cv_frameinterpolation.value == 1 && !paused)
{
interpx = thing->old_x + FixedMul(rendertimefrac, thing->x - thing->old_x);
interpy = thing->old_y + FixedMul(rendertimefrac, thing->y - thing->old_y);
interpz = thing->old_z + FixedMul(rendertimefrac, thing->z - thing->old_z);
}
// transform the origin point // transform the origin point
tr_x = thing->x - viewx; tr_x = interpx - viewx;
tr_y = thing->y - viewy; tr_y = interpy - viewy;
tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); // near/far distance tz = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); // near/far distance
@ -2139,12 +2178,12 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
if (x2 < portalclipstart || x1 >= portalclipend) if (x2 < portalclipstart || x1 >= portalclipend)
return; return;
if (P_PointOnLineSide(thing->x, thing->y, portalclipline) != 0) if (P_PointOnLineSide(interpx, interpy, portalclipline) != 0)
return; return;
} }
//SoM: 3/17/2000: Disregard sprites that are out of view.. //SoM: 3/17/2000: Disregard sprites that are out of view..
gzt = thing->z + spritecachedinfo[lump].topoffset; gzt = interpz + spritecachedinfo[lump].topoffset;
gz = gzt - spritecachedinfo[lump].height; gz = gzt - spritecachedinfo[lump].height;
if (thing->subsector->sector->cullheight) if (thing->subsector->sector->cullheight)
@ -2157,10 +2196,13 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
vis = R_NewVisSprite(); vis = R_NewVisSprite();
vis->scale = vis->sortscale = yscale; //<<detailshift; vis->scale = vis->sortscale = yscale; //<<detailshift;
vis->dispoffset = 0; // Monster Iestyn: 23/11/15 vis->dispoffset = 0; // Monster Iestyn: 23/11/15
vis->gx = thing->x; vis->gx = interpx;
vis->gy = thing->y; vis->gy = interpy;
vis->gz = gz; vis->gz = gz;
vis->gzt = gzt; vis->gzt = gzt;
vis->thingheight = 4*FRACUNIT;
vis->pz = interpz;
vis->pzt = vis->pz + vis->thingheight;
vis->texturemid = vis->gzt - viewz; vis->texturemid = vis->gzt - viewz;
vis->scalestep = 0; vis->scalestep = 0;
vis->paperdistance = 0; vis->paperdistance = 0;

View file

@ -181,7 +181,7 @@ static char returnWadPath[256];
#include "../m_argv.h" #include "../m_argv.h"
#include "../m_menu.h" #include "../r_main.h" // Frame interpolation/uncapped
#ifdef MAC_ALERT #ifdef MAC_ALERT
#include "macosx/mac_alert.h" #include "macosx/mac_alert.h"
@ -1640,17 +1640,29 @@ static Uint64 timer_frequency;
static double tic_frequency; static double tic_frequency;
static Uint64 tic_epoch; static Uint64 tic_epoch;
static double elapsed_tics;
static void UpdateElapsedTics(void)
{
const Uint64 now = SDL_GetPerformanceCounter();
elapsed_tics += (now - tic_epoch) / tic_frequency;
tic_epoch = now; // moving epoch
}
tic_t I_GetTime(void) tic_t I_GetTime(void)
{ {
static double elapsed; double f = 0.0;
UpdateElapsedTics();
f = floor(elapsed_tics);
return (tic_t)f;
}
const Uint64 now = SDL_GetPerformanceCounter(); fixed_t I_GetTimeFrac(void)
{
UpdateElapsedTics();
elapsed += (now - tic_epoch) / tic_frequency; return FLOAT_TO_FIXED((float) (elapsed_tics - floor(elapsed_tics)));
tic_epoch = now; // moving epoch
return (tic_t)elapsed;
} }
precise_t I_GetPreciseTime(void) precise_t I_GetPreciseTime(void)
@ -1672,6 +1684,7 @@ void I_StartupTimer(void)
tic_epoch = SDL_GetPerformanceCounter(); tic_epoch = SDL_GetPerformanceCounter();
tic_frequency = timer_frequency / (double)NEWTICRATE; tic_frequency = timer_frequency / (double)NEWTICRATE;
elapsed_tics = 0.0;
} }
void I_Sleep(void) void I_Sleep(void)

View file

@ -45,6 +45,7 @@
#include "../d_main.h" #include "../d_main.h"
#include "../m_argv.h" #include "../m_argv.h"
#include "../m_fixed.h"
#include "../w_wad.h" #include "../w_wad.h"
#include "../z_zone.h" #include "../z_zone.h"
@ -261,6 +262,11 @@ tic_t I_GetTime(void)
return newtics; return newtics;
} }
fixed_t I_GetTimeFrac(void)
{
return 0;
}
void I_Sleep(void) void I_Sleep(void)
{ {
if (cv_sleep.value > 0) if (cv_sleep.value > 0)