mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 20:31:30 +00:00
8f354ad9c1
Co-Authored-By: Sally Coolatta <tehrealsalt@gmail.com> Co-Authored-By: James R <justsomejames2@gmail.com> Co-Authored-By: Monster Iestyn <iestynjealous@ntlworld.com> Co-Authored-By: katsy <katmint@live.com> Place Frame Interpolation in "Experimental" video options header This seems like an appropriate way to describe the feature for now. Add smooth level platter under interpolation, `renderdeltatics` `renderdeltatics` can be used as a standard delta time in any place, allowing for smooth menus. It will always be equal to `realtics` when frame interpolation is turned off, producing consistent framerate behavior everywhere it is used. Add smooth rendering to save select screen Add smooth rendering to Record/NiGHTS Attack, F_SkyScroll Ensure viewsector is accurate to viewx/viewy This fixes a potential crash in OpenGL when changing between levels. Ensure + commands get executed before map start Always have precise_t defined Fix misc dropshadow issues Reset view interpolation on level load Remove unnecessary precipmobj thinker hack Add reset interpolation state functions Reset precip interpolation on snap to ceil Reset mobj interp state on TeleportMove Only swap view interp state if a tick is run Run anti-lag chasecam at tic frequency Fixes jittery and unstable chasecam in high latency netgames Homogenize mobj interpolations Add sector plane level interpolations Add SectorScroll interpolator Add SideScroll interpolator Add Polyobj interpolator Intialize interpolator list at a better time Delete interpolators associated with thinkers Interpolate mobj angles and player drawangle Interpolate HWR_DrawModel Add functions to handle interpolation Much less code duplication P_InitAngle, to fix angle interpolation on spawning objects Fully fix drop shadows It used the thing's floorz / ceilingz directly -- that wouldn't account for interpolated coordinates. Do not speed up underwater/heatwave effect in OpenGL Closer OpenGL underwater/heatwave effect to Software Interpolate from time of previous tic Previously interpolated from last 35th of a second, which may be offset from game time due to connection lag. Consider this the proper fix to 54148a0dd0 too. Calculate FPS stuff even if frame is skipped I decided ultimately to actually keep the frame skip optimization disabled, because I think it is actually a little bit helpful that you can still get accurate rendering perfstats while paused, however if we decide otherwise then we can have this optimization back without making the game act like it's lagging. Keep rect in memory Feel better about this than creating one all da time Lots of FPS stuff - Disabled VSync, due to the numerous problems it has. - Instead, added an FPS cap. - Frame interpolation is now tied to fpscap != 35. - By default, the FPS cap is set to the monitor's refresh rate. - Rewrote the FPS counter. (This also consolidates several more commits ahead of this fixing various issues. -eid) Misc changes after Kart cherry-picks Fix renderdeltatics with new timing data Update mobj oldstates before all thinkers Allow FPS cap values Adjust how FPS cap is checked to improve FPS stability Fix precip crash from missing vars Improve the framerate limiter's timing for extreme stable FPS Handle the sleep at the end of D_SRB2Loop instead of the start Simplifies logic in the other parts of the loop, and fixes problems with it frequently waiting too long. Reset mobj interp state on add Add mobj interpolator on load netgame Move mobj interpolators to r_fps Dynamic slope interpolators I_GetFrameTime to try and improve frame pace (It doesn't feel that much better though.) Move I_FinishUpdate to D_SRB2Loop to sync screen updates with FPS cap, use timestamps in I_FrameCapSleep to simplify the code Fix plane interpolation light level flickering Fix flickering plane interpolation for OpenGL in the exact same way Funny OpenGL renderer being at least 50% copy-pasted Software code :) P_SetOrigin & P_MoveOrigin to replace P_TeleportMove Convert P_TeleportMove use to origin funcs Revert "P_InitAngle, to fix angle interpolation on spawning objects" This reverts commit a80c98bd164a2748cbbfad9027b34601185d93f5. Waypoint polyobjects interpolate z & children Add interpolation to more moving plane types Adds interpolation to the following: - Crumbling platforms - Mario blocks - Floatbob platforms (this one works really strangely due to two thinkers, maybe double-check this one?) Reset overlays interp states each TryRunTics Interpolate model interpolation (lol) Use interp tracer pos for GL linkdraw Papersprite angle interpolation Makes the ending signpost smooth Move intermission emerald bounce to ticker Bring back shadows on polyobjects Also optimizes the method used so rings can show their shadows too. Using just the subsector is a tad bit imprecise admittedly but any more precise methods get really laggy. Fix a bunch of ticking in hu_ drawing functions Revert "Reset overlays interp states each TryRunTics" This reverts commit a71a216faa20e8751b3bd0157354e8d748940c92. Move intro ticking out of the drawer Adjust 1up monitor icon z offsets Fixes interpolation issues with 1up monitors. Delta time choose player menu animations Add drawerlib deltaTime function Interpolate afterimages further back Use old sleep in dedicated mode Clamp cechotimer to 0 Fixes issues with cechos staying on-screen and glitching out (NiGHTS items for example). Revert "Remove unnecessary precipmobj thinker hack" This reverts commit 0e38208620d19ec2ab690740438ac2fc7862a49e. Fix frame pacing when game lags behind The frame timestamp should've been made at the start of the frame, not the end. Fix I_FrameCapSleep not respecting cpusleep Jonathan Joestar bruh Allow dedicated to use precise sleep timing again Instead of only using one old sleep, just enforce framerate cap to match TICRATE. Make Lua TeleportMove call MoveOrigin Reset Metal fume interp state on appear Add interpdebug Put interpdebug stuff in perfstats instead Add timescale cvar Slow the game down to debug animations / interpolation problems! Speed it up if you need to get somewhere quickly while mapping! Enable timescale outside of DEVELOP builds It has NETVAR, so it should be fine -- put an end to useful debugging features excluded in multiplayer! Force interpolation when timescale != 1.0 Reset old_z in MT_LOCKON think Fixes interpolation artifacting due to spawn pos. Fix cutscenes in interp Fix boss1 laser in interp Interpolate mobj scale Precalculate refresh rate Slower PCs can have issue querying mode over and over. This might kinda suck for windowed mode if you have different refresh rate displays but oh well Fix interp scaling crashing software Reset interp scale when Lua sets .scale Disable angle interp on fresh mobjs Fix interp scale crash for hires sprites Interp shadow scales Copy interp state in P_SpawnMobjFromMobj Fix multiplayer character select Don't interpolate mobj state if frac = 1.0 Fix Mario block item placement Interpolate spritescale/offset x/y Fix offset copies for SpawnMobjFromMobj THANKS SAL Add Lua HUD drawlists Buffers draw calls between tics to ensure hooks run at the originally intended rate. Rename drawerlib deltaTime to getDeltaTime Make renderisnewtic is false between tics I know what I'm doing! I swear Completely refactor timing system Time is now tracked internally in the game using I_GetPreciseTime and I_UpdateTime. I_Time now pulls from this internal timer. The system code no longer needs to keep track of time itself. This significantly improves frame and tic timing in interp mode, resulting in a much smoother image with essentially no judder at any framerate. Ensure mobj interpolators reset on level load Ensure view is not interpolated on first frame Disable sprite offset interpolation (for now) Refactor timing code even more System layer is greatly simplified and framecap logic has been moved internally. I_Sleep now takes a sleep duration and I_SleepDuration generically implements a precise sleep with spin loop.
406 lines
10 KiB
C
406 lines
10 KiB
C
// SONIC ROBO BLAST 2
|
|
//-----------------------------------------------------------------------------
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
|
// Copyright (C) 2013-2016 by Matthew "Inuyasha" Walsh.
|
|
// Copyright (C) 1999-2018 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 f_wipe.c
|
|
/// \brief SRB2 2.1 custom fade mask "wipe" behavior.
|
|
|
|
#include "f_finale.h"
|
|
#include "i_video.h"
|
|
#include "v_video.h"
|
|
|
|
#include "r_draw.h" // transtable
|
|
#include "p_pspr.h" // tr_transxxx
|
|
#include "w_wad.h"
|
|
#include "z_zone.h"
|
|
|
|
#include "i_time.h"
|
|
#include "i_system.h"
|
|
#include "i_threads.h"
|
|
#include "m_menu.h"
|
|
#include "console.h"
|
|
#include "d_main.h"
|
|
#include "m_misc.h" // movie mode
|
|
#include "d_clisrv.h" // So the network state can be updated during the wipe
|
|
|
|
#ifdef HWRENDER
|
|
#include "hardware/hw_main.h"
|
|
#endif
|
|
|
|
#if NUMSCREENS < 5
|
|
#define NOWIPE // do not enable wipe image post processing for ARM, SH and MIPS CPUs
|
|
#endif
|
|
|
|
typedef struct fademask_s {
|
|
UINT8* mask;
|
|
UINT16 width, height;
|
|
size_t size;
|
|
fixed_t xscale, yscale;
|
|
} fademask_t;
|
|
|
|
UINT8 wipedefs[NUMWIPEDEFS] = {
|
|
99, // wipe_credits_intermediate (0)
|
|
|
|
0, // wipe_level_toblack
|
|
UINT8_MAX, // wipe_intermission_toblack
|
|
0, // wipe_voting_toblack,
|
|
UINT8_MAX, // wipe_continuing_toblack
|
|
3, // wipe_titlescreen_toblack
|
|
0, // wipe_timeattack_toblack
|
|
99, // wipe_credits_toblack
|
|
0, // wipe_evaluation_toblack
|
|
0, // wipe_gameend_toblack
|
|
UINT8_MAX, // wipe_intro_toblack (hardcoded)
|
|
UINT8_MAX, // wipe_cutscene_toblack (hardcoded)
|
|
|
|
UINT8_MAX, // wipe_specinter_toblack
|
|
UINT8_MAX, // wipe_multinter_toblack
|
|
99, // wipe_speclevel_towhite
|
|
|
|
3, // wipe_level_final
|
|
0, // wipe_intermission_final
|
|
0, // wipe_voting_final
|
|
0, // wipe_continuing_final
|
|
3, // wipe_titlescreen_final
|
|
0, // wipe_timeattack_final
|
|
99, // wipe_credits_final
|
|
0, // wipe_evaluation_final
|
|
0, // wipe_gameend_final
|
|
99, // wipe_intro_final (hardcoded)
|
|
99, // wipe_cutscene_final (hardcoded)
|
|
|
|
0, // wipe_specinter_final
|
|
0 // wipe_multinter_final
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
// SCREEN WIPE PACKAGE
|
|
//--------------------------------------------------------------------------
|
|
|
|
boolean WipeInAction = false;
|
|
INT32 lastwipetic = 0;
|
|
|
|
#ifndef NOWIPE
|
|
static UINT8 *wipe_scr_start; //screen 3
|
|
static UINT8 *wipe_scr_end; //screen 4
|
|
static UINT8 *wipe_scr; //screen 0 (main drawing)
|
|
static fixed_t paldiv;
|
|
|
|
/** Create fademask_t from lump
|
|
*
|
|
* \param lump Lump name to get data from
|
|
* \return fademask_t for lump
|
|
*/
|
|
static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) {
|
|
static char lumpname[9] = "FADEmmss";
|
|
static fademask_t fm = {NULL,0,0,0,0,0};
|
|
lumpnum_t lumpnum;
|
|
UINT8 *lump, *mask;
|
|
size_t lsize;
|
|
RGBA_t *pcolor;
|
|
|
|
if (masknum > 99 || scrnnum > 99)
|
|
goto freemask;
|
|
|
|
// SRB2Kart: This suddenly triggers ERRORMODE now
|
|
//sprintf(&lumpname[4], "%.2hu%.2hu", (UINT16)masknum, (UINT16)scrnnum);
|
|
|
|
lumpname[4] = '0'+(masknum/10);
|
|
lumpname[5] = '0'+(masknum%10);
|
|
|
|
lumpname[6] = '0'+(scrnnum/10);
|
|
lumpname[7] = '0'+(scrnnum%10);
|
|
|
|
lumpnum = W_CheckNumForName(lumpname);
|
|
if (lumpnum == LUMPERROR)
|
|
goto freemask;
|
|
|
|
lump = W_CacheLumpNum(lumpnum, PU_CACHE);
|
|
lsize = W_LumpLength(lumpnum);
|
|
switch (lsize)
|
|
{
|
|
case 256000: // 640x400
|
|
fm.width = 640;
|
|
fm.height = 400;
|
|
break;
|
|
case 64000: // 320x200
|
|
fm.width = 320;
|
|
fm.height = 200;
|
|
break;
|
|
case 16000: // 160x100
|
|
fm.width = 160;
|
|
fm.height = 100;
|
|
break;
|
|
case 4000: // 80x50 (minimum)
|
|
fm.width = 80;
|
|
fm.height = 50;
|
|
break;
|
|
|
|
default: // bad lump
|
|
CONS_Alert(CONS_WARNING, "Fade mask lump %s of incorrect size, ignored\n", lumpname);
|
|
case 0: // end marker (not bad!, but still need clearing)
|
|
goto freemask;
|
|
}
|
|
if (lsize != fm.size)
|
|
fm.mask = Z_Realloc(fm.mask, lsize, PU_STATIC, NULL);
|
|
fm.size = lsize;
|
|
|
|
mask = fm.mask;
|
|
|
|
while (lsize--)
|
|
{
|
|
// Determine pixel to use from fademask
|
|
pcolor = &pLocalPalette[*lump++];
|
|
*mask++ = FixedDiv((pcolor->s.red+1)<<FRACBITS, paldiv)>>FRACBITS;
|
|
}
|
|
|
|
fm.xscale = FixedDiv(vid.width<<FRACBITS, fm.width<<FRACBITS);
|
|
fm.yscale = FixedDiv(vid.height<<FRACBITS, fm.height<<FRACBITS);
|
|
return &fm;
|
|
|
|
// Landing point for freeing data -- do this instead of just returning NULL
|
|
// this ensures the fade data isn't remaining in memory, unused
|
|
// (could be up to 256,000 bytes if it's a HQ fade!)
|
|
freemask:
|
|
if (fm.mask)
|
|
{
|
|
Z_Free(fm.mask);
|
|
fm.mask = NULL;
|
|
fm.size = 0;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/** Wipe ticker
|
|
*
|
|
* \param fademask pixels to change
|
|
*/
|
|
static void F_DoWipe(fademask_t *fademask)
|
|
{
|
|
// Software mask wipe -- optimized; though it might not look like it!
|
|
// Okay, to save you wondering *how* this is more optimized than the simpler
|
|
// version that came before it...
|
|
// ---
|
|
// The previous code did two FixedMul calls for every single pixel on the
|
|
// screen, of which there are hundreds of thousands -- if not millions -- of.
|
|
// This worked fine for smaller screen sizes, but with excessively large
|
|
// (1920x1200) screens that meant 4 million+ calls out to FixedMul, and that
|
|
// would take /just/ long enough that fades would start to noticably lag.
|
|
// ---
|
|
// This code iterates over the fade mask's pixels instead of the screen's,
|
|
// and deals with drawing over each rectangular area before it moves on to
|
|
// the next pixel in the fade mask. As a result, it's more complex (and might
|
|
// look a little messy; sorry!) but it simultaneously runs at twice the speed.
|
|
// In addition, we precalculate all the X and Y positions that we need to draw
|
|
// from and to, so it uses a little extra memory, but again, helps it run faster.
|
|
{
|
|
// wipe screen, start, end
|
|
UINT8 *w = wipe_scr;
|
|
const UINT8 *s = wipe_scr_start;
|
|
const UINT8 *e = wipe_scr_end;
|
|
|
|
// first pixel for each screen
|
|
UINT8 *w_base = w;
|
|
const UINT8 *s_base = s;
|
|
const UINT8 *e_base = e;
|
|
|
|
// mask data, end
|
|
UINT8 *transtbl;
|
|
const UINT8 *mask = fademask->mask;
|
|
const UINT8 *maskend = mask + fademask->size;
|
|
|
|
// rectangle draw hints
|
|
UINT32 draw_linestart, draw_rowstart;
|
|
UINT32 draw_lineend, draw_rowend;
|
|
UINT32 draw_linestogo, draw_rowstogo;
|
|
|
|
// rectangle coordinates, etc.
|
|
UINT16* scrxpos = (UINT16*)malloc((fademask->width + 1) * sizeof(UINT16));
|
|
UINT16* scrypos = (UINT16*)malloc((fademask->height + 1) * sizeof(UINT16));
|
|
UINT16 maskx, masky;
|
|
UINT32 relativepos;
|
|
|
|
// ---
|
|
// Screw it, we do the fixed point math ourselves up front.
|
|
scrxpos[0] = 0;
|
|
for (relativepos = 0, maskx = 1; maskx < fademask->width; ++maskx)
|
|
scrxpos[maskx] = (relativepos += fademask->xscale)>>FRACBITS;
|
|
scrxpos[fademask->width] = vid.width;
|
|
|
|
scrypos[0] = 0;
|
|
for (relativepos = 0, masky = 1; masky < fademask->height; ++masky)
|
|
scrypos[masky] = (relativepos += fademask->yscale)>>FRACBITS;
|
|
scrypos[fademask->height] = vid.height;
|
|
// ---
|
|
|
|
maskx = masky = 0;
|
|
do
|
|
{
|
|
draw_rowstart = scrxpos[maskx];
|
|
draw_rowend = scrxpos[maskx + 1];
|
|
draw_linestart = scrypos[masky];
|
|
draw_lineend = scrypos[masky + 1];
|
|
|
|
relativepos = (draw_linestart * vid.width) + draw_rowstart;
|
|
draw_linestogo = draw_lineend - draw_linestart;
|
|
|
|
if (*mask == 0)
|
|
{
|
|
// shortcut - memcpy source to work
|
|
while (draw_linestogo--)
|
|
{
|
|
M_Memcpy(w_base+relativepos, s_base+relativepos, draw_rowend-draw_rowstart);
|
|
relativepos += vid.width;
|
|
}
|
|
}
|
|
else if (*mask == 10)
|
|
{
|
|
// shortcut - memcpy target to work
|
|
while (draw_linestogo--)
|
|
{
|
|
M_Memcpy(w_base+relativepos, e_base+relativepos, draw_rowend-draw_rowstart);
|
|
relativepos += vid.width;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// pointer to transtable that this mask would use
|
|
transtbl = transtables + ((9 - *mask)<<FF_TRANSSHIFT);
|
|
|
|
// DRAWING LOOP
|
|
while (draw_linestogo--)
|
|
{
|
|
w = w_base + relativepos;
|
|
s = s_base + relativepos;
|
|
e = e_base + relativepos;
|
|
draw_rowstogo = draw_rowend - draw_rowstart;
|
|
|
|
while (draw_rowstogo--)
|
|
*w++ = transtbl[ ( *e++ << 8 ) + *s++ ];
|
|
|
|
relativepos += vid.width;
|
|
}
|
|
// END DRAWING LOOP
|
|
}
|
|
|
|
if (++maskx >= fademask->width)
|
|
++masky, maskx = 0;
|
|
} while (++mask < maskend);
|
|
|
|
free(scrxpos);
|
|
free(scrypos);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/** Save the "before" screen of a wipe.
|
|
*/
|
|
void F_WipeStartScreen(void)
|
|
{
|
|
#ifndef NOWIPE
|
|
#ifdef HWRENDER
|
|
if(rendermode != render_soft)
|
|
{
|
|
HWR_StartScreenWipe();
|
|
return;
|
|
}
|
|
#endif
|
|
wipe_scr_start = screens[3];
|
|
I_ReadScreen(wipe_scr_start);
|
|
#endif
|
|
}
|
|
|
|
/** Save the "after" screen of a wipe.
|
|
*/
|
|
void F_WipeEndScreen(void)
|
|
{
|
|
#ifndef NOWIPE
|
|
#ifdef HWRENDER
|
|
if(rendermode != render_soft)
|
|
{
|
|
HWR_EndScreenWipe();
|
|
return;
|
|
}
|
|
#endif
|
|
wipe_scr_end = screens[4];
|
|
I_ReadScreen(wipe_scr_end);
|
|
V_DrawBlock(0, 0, 0, vid.width, vid.height, wipe_scr_start);
|
|
#endif
|
|
}
|
|
|
|
/** After setting up the screens you want to wipe,
|
|
* calling this will do a 'typical' wipe.
|
|
*/
|
|
void F_RunWipe(UINT8 wipetype, boolean drawMenu)
|
|
{
|
|
#ifdef NOWIPE
|
|
(void)wipetype;
|
|
(void)drawMenu;
|
|
#else
|
|
tic_t nowtime;
|
|
UINT8 wipeframe = 0;
|
|
fademask_t *fmask;
|
|
|
|
paldiv = FixedDiv(257<<FRACBITS, 11<<FRACBITS);
|
|
|
|
// Init the wipe
|
|
WipeInAction = true;
|
|
wipe_scr = screens[0];
|
|
|
|
// lastwipetic should either be 0 or the tic we last wiped
|
|
// on for fade-to-black
|
|
for (;;)
|
|
{
|
|
// get fademask first so we can tell if it exists or not
|
|
fmask = F_GetFadeMask(wipetype, wipeframe++);
|
|
if (!fmask)
|
|
break;
|
|
|
|
// wait loop
|
|
while (!((nowtime = I_GetTime()) - lastwipetic))
|
|
{
|
|
I_Sleep(cv_sleep.value);
|
|
I_UpdateTime(cv_timescale.value);
|
|
}
|
|
lastwipetic = nowtime;
|
|
|
|
#ifdef HWRENDER
|
|
if (rendermode == render_opengl)
|
|
HWR_DoWipe(wipetype, wipeframe-1); // send in the wipe type and wipeframe because we need to cache the graphic
|
|
else
|
|
#endif
|
|
if (rendermode != render_none) //this allows F_RunWipe to be called in dedicated servers
|
|
F_DoWipe(fmask);
|
|
|
|
I_OsPolling();
|
|
I_UpdateNoBlit();
|
|
|
|
if (drawMenu)
|
|
{
|
|
#ifdef HAVE_THREADS
|
|
I_lock_mutex(&m_menu_mutex);
|
|
#endif
|
|
M_Drawer(); // menu is drawn even on top of wipes
|
|
#ifdef HAVE_THREADS
|
|
I_unlock_mutex(m_menu_mutex);
|
|
#endif
|
|
}
|
|
|
|
I_FinishUpdate(); // page flip or blit buffer
|
|
|
|
if (moviemode)
|
|
M_SaveFrame();
|
|
|
|
NetKeepAlive(); // Update the network so we don't cause timeouts
|
|
}
|
|
WipeInAction = false;
|
|
#endif
|
|
}
|