2014-03-15 16:59:03 +00:00
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
2023-03-31 12:53:31 +00:00
// Copyright (C) 1999-2023 by Sonic Team Junior.
2014-03-15 16:59:03 +00:00
//
// 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_things.c
/// \brief Refresh of things, i.e. objects represented by sprites
# include "doomdef.h"
# include "console.h"
# include "g_game.h"
# include "r_local.h"
# include "st_stuff.h"
# include "w_wad.h"
# include "z_zone.h"
2016-07-14 13:39:22 +00:00
# include "m_menu.h" // character select
2014-03-15 16:59:03 +00:00
# include "m_misc.h"
2017-01-17 00:16:23 +00:00
# include "info.h" // spr2names
2014-03-15 16:59:03 +00:00
# include "i_video.h" // rendermode
2019-08-18 17:16:48 +00:00
# include "i_system.h"
2022-04-12 23:39:11 +00:00
# include "r_fps.h"
2014-03-15 16:59:03 +00:00
# include "r_things.h"
2019-10-28 18:28:42 +00:00
# include "r_patch.h"
2020-10-10 21:53:05 +00:00
# include "r_patchrotation.h"
2020-01-06 21:22:23 +00:00
# include "r_picformats.h"
2014-03-15 16:59:03 +00:00
# include "r_plane.h"
2019-06-03 11:33:12 +00:00
# include "r_portal.h"
2020-10-12 03:13:22 +00:00
# include "r_splats.h"
2014-03-15 16:59:03 +00:00
# include "p_tick.h"
# include "p_local.h"
2015-10-10 16:57:35 +00:00
# include "p_slopes.h"
2022-12-31 13:10:19 +00:00
# include "netcode/d_netfil.h" // blargh. for nameonly().
2014-03-15 16:59:03 +00:00
# include "m_cheat.h" // objectplace
# ifdef HWRENDER
# include "hardware/hw_md2.h"
2019-08-18 17:16:48 +00:00
# include "hardware/hw_glob.h"
# include "hardware/hw_light.h"
# include "hardware/hw_drv.h"
2014-03-15 16:59:03 +00:00
# endif
# define MINZ (FRACUNIT*4)
# define BASEYCENTER (BASEVIDHEIGHT / 2)
typedef struct
{
INT32 x1 , x2 ;
INT32 column ;
INT32 topclip , bottomclip ;
} maskdraw_t ;
//
// Sprite rotation 0 is facing the viewer,
// rotation 1 is one angle turn CLOCKWISE around the axis.
// This is not the same as the angle,
// which increases counter clockwise (protractor).
// There was a lot of stuff grabbed wrong, so I changed it...
//
static lighttable_t * * spritelights ;
// constant arrays used for psprite clipping and initializing clipping
INT16 negonearray [ MAXVIDWIDTH ] ;
INT16 screenheightarray [ MAXVIDWIDTH ] ;
2019-09-28 22:13:51 +00:00
spriteinfo_t spriteinfo [ NUMSPRITES ] ;
2014-03-15 16:59:03 +00:00
//
// INITIALIZATION FUNCTIONS
//
// variables used to look up and range check thing_t sprites patches
spritedef_t * sprites ;
size_t numsprites ;
static spriteframe_t sprtemp [ 64 ] ;
static size_t maxframe ;
static const char * spritename ;
2023-07-26 03:06:52 +00:00
//
// Clipping against drawsegs optimization, from prboom-plus
//
// TODO: This should be done with proper subsector pass through
// sprites which would ideally remove the need to do it at all.
// Unfortunately, SRB2's drawing loop has lots of annoying
// changes from Doom for portals, which make it hard to implement.
typedef struct drawseg_xrange_item_s
{
INT16 x1 , x2 ;
drawseg_t * user ;
} drawseg_xrange_item_t ;
typedef struct drawsegs_xrange_s
{
drawseg_xrange_item_t * items ;
INT32 count ;
} drawsegs_xrange_t ;
# define DS_RANGES_COUNT 3
static drawsegs_xrange_t drawsegs_xranges [ DS_RANGES_COUNT ] ;
static drawseg_xrange_item_t * drawsegs_xrange ;
static size_t drawsegs_xrange_size = 0 ;
static INT32 drawsegs_xrange_count = 0 ;
2014-03-15 16:59:03 +00:00
// ==========================================================================
//
// Sprite loading routines: support sprites in pwad, dehacked sprite renaming,
// replacing not all frames of an existing sprite, add sprites at run-time,
// add wads at run-time.
//
// ==========================================================================
//
//
//
static void R_InstallSpriteLump ( UINT16 wad , // graphics patch
UINT16 lump ,
size_t lumpid , // identifier
UINT8 frame ,
UINT8 rotation ,
UINT8 flipped )
{
2020-01-08 20:49:14 +00:00
char cn = R_Frame2Char ( frame ) , cr = R_Rotation2Char ( rotation ) ; // for debugging
2014-04-14 05:14:58 +00:00
2020-10-10 21:43:26 +00:00
INT32 r ;
2014-03-15 16:59:03 +00:00
lumpnum_t lumppat = wad ;
lumppat < < = 16 ;
lumppat + = lump ;
if ( maxframe = = ( size_t ) - 1 | | frame > maxframe )
maxframe = frame ;
2019-08-18 17:16:48 +00:00
# ifdef ROTSPRITE
2020-01-08 20:49:14 +00:00
for ( r = 0 ; r < 16 ; r + + )
2019-08-18 17:16:48 +00:00
{
2023-10-25 12:00:04 +00:00
sprtemp [ frame ] . rotated [ r ] = NULL ;
2019-08-18 17:16:48 +00:00
}
2020-10-10 21:43:26 +00:00
# endif
2019-08-18 17:16:48 +00:00
2014-03-15 16:59:03 +00:00
if ( rotation = = 0 )
{
// the lump should be used for all rotations
2016-07-18 23:04:00 +00:00
if ( sprtemp [ frame ] . rotate = = SRF_SINGLE )
2014-04-14 05:14:58 +00:00
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has multiple rot = 0 lump \n " , spritename , cn ) ;
2020-01-08 20:49:14 +00:00
else if ( sprtemp [ frame ] . rotate ! = SRF_NONE ) // Let's bundle 1-8/16 and L/R rotations into one debug message.
2014-04-14 05:14:58 +00:00
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has rotations and a rot = 0 lump \n " , spritename , cn ) ;
2014-03-15 16:59:03 +00:00
2016-07-18 23:04:00 +00:00
sprtemp [ frame ] . rotate = SRF_SINGLE ;
2020-01-08 20:49:14 +00:00
for ( r = 0 ; r < 16 ; r + + )
2014-03-15 16:59:03 +00:00
{
sprtemp [ frame ] . lumppat [ r ] = lumppat ;
sprtemp [ frame ] . lumpid [ r ] = lumpid ;
}
2020-01-08 20:49:14 +00:00
sprtemp [ frame ] . flip = flipped ? 0xFFFF : 0 ; // 1111111111111111 in binary
2014-03-15 16:59:03 +00:00
return ;
}
2016-07-18 23:04:00 +00:00
if ( rotation = = ROT_L | | rotation = = ROT_R )
{
UINT8 rightfactor = ( ( rotation = = ROT_R ) ? 4 : 0 ) ;
// the lump should be used for half of all rotations
2020-01-08 20:49:14 +00:00
if ( sprtemp [ frame ] . rotate = = SRF_NONE )
sprtemp [ frame ] . rotate = SRF_SINGLE ;
else if ( sprtemp [ frame ] . rotate = = SRF_SINGLE )
2016-07-18 23:04:00 +00:00
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has L/R rotations and a rot = 0 lump \n " , spritename , cn ) ;
else if ( sprtemp [ frame ] . rotate = = SRF_3D )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has both L/R and 1-8 rotations \n " , spritename , cn ) ;
2020-01-08 20:49:14 +00:00
else if ( sprtemp [ frame ] . rotate = = SRF_3DGE )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has both L/R and 1-G rotations \n " , spritename , cn ) ;
2016-07-18 23:04:00 +00:00
else if ( ( sprtemp [ frame ] . rotate & SRF_LEFT ) & & ( rotation = = ROT_L ) )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has multiple L rotations \n " , spritename , cn ) ;
else if ( ( sprtemp [ frame ] . rotate & SRF_RIGHT ) & & ( rotation = = ROT_R ) )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has multiple R rotations \n " , spritename , cn ) ;
sprtemp [ frame ] . rotate | = ( ( rotation = = ROT_R ) ? SRF_RIGHT : SRF_LEFT ) ;
2020-01-08 20:49:14 +00:00
if ( ( sprtemp [ frame ] . rotate & SRF_2D ) = = SRF_2D )
sprtemp [ frame ] . rotate & = ~ SRF_3DMASK ; // SRF_3D|SRF_2D being enabled at the same time doesn't HURT in the current sprite angle implementation, but it DOES mean more to check in some of the helper functions. Let's not allow this scenario to happen.
2016-07-18 23:04:00 +00:00
2020-01-08 20:49:14 +00:00
// load into every relevant angle, including the front one
for ( r = 0 ; r < 4 ; r + + )
2016-07-18 23:04:00 +00:00
{
sprtemp [ frame ] . lumppat [ r + rightfactor ] = lumppat ;
sprtemp [ frame ] . lumpid [ r + rightfactor ] = lumpid ;
2020-01-08 20:49:14 +00:00
sprtemp [ frame ] . lumppat [ r + rightfactor + 8 ] = lumppat ;
sprtemp [ frame ] . lumpid [ r + rightfactor + 8 ] = lumpid ;
2016-07-18 23:04:00 +00:00
}
2016-08-08 16:24:36 +00:00
if ( flipped )
2020-01-08 20:49:14 +00:00
sprtemp [ frame ] . flip | = ( 0x0F0F < < rightfactor ) ; // 0000111100001111 or 1111000011110000 in binary, depending on rotation being ROT_L or ROT_R
2016-08-08 16:24:36 +00:00
else
2020-01-08 20:49:14 +00:00
sprtemp [ frame ] . flip & = ~ ( 0x0F0F < < rightfactor ) ; // ditto
2016-08-08 16:24:36 +00:00
2016-07-18 23:04:00 +00:00
return ;
}
2014-03-15 16:59:03 +00:00
2020-01-08 20:49:14 +00:00
if ( sprtemp [ frame ] . rotate = = SRF_NONE )
sprtemp [ frame ] . rotate = SRF_SINGLE ;
else if ( sprtemp [ frame ] . rotate = = SRF_SINGLE )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has 1-8/G rotations and a rot = 0 lump \n " , spritename , cn ) ;
else if ( sprtemp [ frame ] . rotate & SRF_2D )
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s frame %c has both L/R and 1-8/G rotations \n " , spritename , cn ) ;
2014-03-15 16:59:03 +00:00
// make 0 based
rotation - - ;
2020-01-08 20:49:14 +00:00
{
// SRF_3D|SRF_3DGE being enabled at the same time doesn't HURT in the current sprite angle implementation, but it DOES mean more to check in some of the helper functions. Let's not allow this scenario to happen.
UINT8 threedrot = ( rotation > 7 ) ? SRF_3DGE : ( sprtemp [ frame ] . rotate & SRF_3DMASK ) ;
if ( ! threedrot )
threedrot = SRF_3D ;
if ( rotation = = 0 | | rotation = = 4 ) // Front or back...
sprtemp [ frame ] . rotate = threedrot ; // Prevent L and R changeover
else if ( ( rotation & 7 ) > 3 ) // Right side
sprtemp [ frame ] . rotate = ( threedrot | ( sprtemp [ frame ] . rotate & SRF_LEFT ) ) ; // Continue allowing L frame changeover
else // if ((rotation & 7) <= 3) // Left side
sprtemp [ frame ] . rotate = ( threedrot | ( sprtemp [ frame ] . rotate & SRF_RIGHT ) ) ; // Continue allowing R frame changeover
}
2016-07-18 23:04:00 +00:00
2014-03-15 16:59:03 +00:00
if ( sprtemp [ frame ] . lumppat [ rotation ] ! = LUMPERROR )
2020-01-08 20:49:14 +00:00
CONS_Debug ( DBG_SETUP , " R_InitSprites: Sprite %s: %c%c has two lumps mapped to it \n " , spritename , cn , cr ) ;
2014-03-15 16:59:03 +00:00
// lumppat & lumpid are the same for original Doom, but different
// when using sprites in pwad : the lumppat points the new graphics
sprtemp [ frame ] . lumppat [ rotation ] = lumppat ;
sprtemp [ frame ] . lumpid [ rotation ] = lumpid ;
if ( flipped )
sprtemp [ frame ] . flip | = ( 1 < < rotation ) ;
else
sprtemp [ frame ] . flip & = ~ ( 1 < < rotation ) ;
}
// Install a single sprite, given its identifying name (4 chars)
//
// (originally part of R_AddSpriteDefs)
//
// Pass: name of sprite : 4 chars
// spritedef_t
// wadnum : wad number, indexes wadfiles[], where patches
// for frames are found
// startlump : first lump to search for sprite frames
// endlump : AFTER the last lump to search
//
// Returns true if the sprite was succesfully added
//
2020-03-08 19:32:07 +00:00
boolean R_AddSingleSpriteDef ( const char * sprname , spritedef_t * spritedef , UINT16 wadnum , UINT16 startlump , UINT16 endlump )
2014-03-15 16:59:03 +00:00
{
UINT16 l ;
UINT8 frame ;
UINT8 rotation ;
lumpinfo_t * lumpinfo ;
2020-08-08 08:16:47 +00:00
softwarepatch_t patch ;
2021-04-25 18:01:51 +00:00
UINT16 numadded = 0 ;
2014-03-15 16:59:03 +00:00
memset ( sprtemp , 0xFF , sizeof ( sprtemp ) ) ;
maxframe = ( size_t ) - 1 ;
2020-03-08 19:51:18 +00:00
spritename = sprname ;
2014-03-15 16:59:03 +00:00
// are we 'patching' a sprite already loaded ?
// if so, it might patch only certain frames, not all
if ( spritedef - > numframes ) // (then spriteframes is not null)
{
// copy the already defined sprite frames
M_Memcpy ( sprtemp , spritedef - > spriteframes ,
spritedef - > numframes * sizeof ( spriteframe_t ) ) ;
maxframe = spritedef - > numframes - 1 ;
}
// scan the lumps,
// filling in the frames for whatever is found
lumpinfo = wadfiles [ wadnum ] - > lumpinfo ;
if ( endlump > wadfiles [ wadnum ] - > numlumps )
endlump = wadfiles [ wadnum ] - > numlumps ;
for ( l = startlump ; l < endlump ; l + + )
{
if ( memcmp ( lumpinfo [ l ] . name , sprname , 4 ) = = 0 )
{
2020-10-02 22:48:13 +00:00
INT32 width , height ;
INT16 topoffset , leftoffset ;
# ifndef NO_PNG_LUMPS
boolean isPNG = false ;
# endif
2014-04-14 05:14:58 +00:00
frame = R_Char2Frame ( lumpinfo [ l ] . name [ 4 ] ) ;
2020-01-08 20:49:14 +00:00
rotation = R_Char2Rotation ( lumpinfo [ l ] . name [ 5 ] ) ;
2014-03-15 16:59:03 +00:00
2020-01-08 20:49:14 +00:00
if ( frame > = 64 | | rotation = = 255 ) // Give an actual NAME error -_-...
2014-03-15 16:59:03 +00:00
{
CONS_Alert ( CONS_WARNING , M_GetText ( " Bad sprite name: %s \n " ) , W_CheckNameForNumPwad ( wadnum , l ) ) ;
continue ;
}
// skip NULL sprites from very old dmadds pwads
if ( W_LumpLengthPwad ( wadnum , l ) < = 8 )
continue ;
// store sprite info in lookup tables
//FIXME : numspritelumps do not duplicate sprite replacements
2020-10-02 22:48:13 +00:00
2019-09-11 19:59:28 +00:00
# ifndef NO_PNG_LUMPS
{
2020-08-08 08:16:47 +00:00
softwarepatch_t * png = W_CacheLumpNumPwad ( wadnum , l , PU_STATIC ) ;
2019-09-11 19:59:28 +00:00
size_t len = W_LumpLengthPwad ( wadnum , l ) ;
2020-10-02 22:48:13 +00:00
2020-01-06 23:16:48 +00:00
if ( Picture_IsLumpPNG ( ( UINT8 * ) png , len ) )
2019-09-11 19:59:28 +00:00
{
2020-10-02 22:48:13 +00:00
Picture_PNGDimensions ( ( UINT8 * ) png , & width , & height , & topoffset , & leftoffset , len ) ;
isPNG = true ;
2019-09-11 19:59:28 +00:00
}
2020-10-02 22:48:13 +00:00
2019-09-11 19:59:28 +00:00
Z_Free ( png ) ;
}
2020-10-02 22:48:13 +00:00
if ( ! isPNG )
2019-09-11 19:59:28 +00:00
# endif
2020-10-02 22:48:13 +00:00
{
2020-11-22 06:47:15 +00:00
W_ReadLumpHeaderPwad ( wadnum , l , & patch , sizeof ( INT16 ) * 4 , 0 ) ;
2020-11-22 23:02:47 +00:00
width = ( INT32 ) ( SHORT ( patch . width ) ) ;
height = ( INT32 ) ( SHORT ( patch . height ) ) ;
topoffset = ( INT16 ) ( SHORT ( patch . topoffset ) ) ;
leftoffset = ( INT16 ) ( SHORT ( patch . leftoffset ) ) ;
2020-10-02 22:48:13 +00:00
}
spritecachedinfo [ numspritelumps ] . width = width < < FRACBITS ;
spritecachedinfo [ numspritelumps ] . offset = leftoffset < < FRACBITS ;
spritecachedinfo [ numspritelumps ] . topoffset = topoffset < < FRACBITS ;
spritecachedinfo [ numspritelumps ] . height = height < < FRACBITS ;
2014-03-15 16:59:03 +00:00
2020-11-22 23:02:47 +00:00
// BP: we cannot use special tric in hardware mode because feet in ground caused by z-buffer
2023-09-21 15:13:55 +00:00
// Monster Iestyn (21 Sep 2023): the above comment no longer makes sense in context!!! So I give an explanation here!
// FEETADJUST was originally an OpenGL-exclusive hack from Doom Legacy to avoid the player's feet being clipped as
// a result of rendering partially under the ground, but sometime before SRB2 2.1's release this was changed to apply
// to the software renderer as well.
// TODO: kill FEETADJUST altogether somehow and somehow fix OpenGL not to clip sprites that are partially underground (if possible)?
2020-11-22 23:02:47 +00:00
spritecachedinfo [ numspritelumps ] . topoffset + = FEETADJUST ;
2014-03-15 16:59:03 +00:00
//----------------------------------------------------
R_InstallSpriteLump ( wadnum , l , numspritelumps , frame , rotation , 0 ) ;
if ( lumpinfo [ l ] . name [ 6 ] )
{
2014-04-14 05:14:58 +00:00
frame = R_Char2Frame ( lumpinfo [ l ] . name [ 6 ] ) ;
2020-01-08 20:49:14 +00:00
rotation = R_Char2Rotation ( lumpinfo [ l ] . name [ 7 ] ) ;
if ( frame > = 64 | | rotation = = 255 ) // Give an actual NAME error -_-...
{
CONS_Alert ( CONS_WARNING , M_GetText ( " Bad sprite name: %s \n " ) , W_CheckNameForNumPwad ( wadnum , l ) ) ;
continue ;
}
2014-03-15 16:59:03 +00:00
R_InstallSpriteLump ( wadnum , l , numspritelumps , frame , rotation , 1 ) ;
}
if ( + + numspritelumps > = max_spritelumps )
{
max_spritelumps * = 2 ;
Z_Realloc ( spritecachedinfo , max_spritelumps * sizeof ( * spritecachedinfo ) , PU_STATIC , & spritecachedinfo ) ;
}
+ + numadded ;
}
}
//
// if no frames found for this sprite
//
if ( maxframe = = ( size_t ) - 1 )
{
// the first time (which is for the original wad),
// all sprites should have their initial frames
// and then, patch wads can replace it
// we will skip non-replaced sprite frames, only if
// they have already have been initially defined (original wad)
//check only after all initial pwads added
//if (spritedef->numframes == 0)
// I_Error("R_AddSpriteDefs: no initial frames found for sprite %s\n",
// namelist[i]);
// sprite already has frames, and is not replaced by this wad
return false ;
}
else if ( ! numadded )
{
// Nothing related to this spritedef has been changed
// so there is no point going back through these checks again.
return false ;
}
maxframe + + ;
//
// some checks to help development
//
for ( frame = 0 ; frame < maxframe ; frame + + )
{
switch ( sprtemp [ frame ] . rotate )
{
2016-07-18 23:04:00 +00:00
case SRF_NONE :
2014-03-15 16:59:03 +00:00
// no rotations were found for that frame at all
2016-06-13 21:52:20 +00:00
I_Error ( " R_AddSingleSpriteDef: No patches found for %.4s frame %c " , sprname , R_Frame2Char ( frame ) ) ;
2014-03-15 16:59:03 +00:00
break ;
2016-07-18 23:04:00 +00:00
case SRF_SINGLE :
2014-03-15 16:59:03 +00:00
// only the first rotation is needed
break ;
2016-07-18 23:04:00 +00:00
case SRF_2D : // both Left and Right rotations
// we test to see whether the left and right slots are present
if ( ( sprtemp [ frame ] . lumppat [ 2 ] = = LUMPERROR ) | | ( sprtemp [ frame ] . lumppat [ 6 ] = = LUMPERROR ) )
2020-01-08 20:49:14 +00:00
I_Error ( " R_AddSingleSpriteDef: Sprite %.4s frame %c is missing rotations (L-R mode) " ,
2016-07-18 23:04:00 +00:00
sprname , R_Frame2Char ( frame ) ) ;
2016-08-09 12:01:56 +00:00
break ;
2016-07-18 23:04:00 +00:00
default :
2020-01-08 20:49:14 +00:00
// must have all 8/16 frames
rotation = ( ( sprtemp [ frame ] . rotate & SRF_3DGE ) ? 16 : 8 ) ;
while ( rotation - - )
2014-03-15 16:59:03 +00:00
// we test the patch lump, or the id lump whatever
// if it was not loaded the two are LUMPERROR
if ( sprtemp [ frame ] . lumppat [ rotation ] = = LUMPERROR )
2020-01-08 20:49:14 +00:00
I_Error ( " R_AddSingleSpriteDef: Sprite %.4s frame %c is missing rotations (1-%c mode) " ,
sprname , R_Frame2Char ( frame ) , ( ( sprtemp [ frame ] . rotate & SRF_3DGE ) ? ' G ' : ' 8 ' ) ) ;
2014-03-15 16:59:03 +00:00
break ;
}
}
// allocate space for the frames present and copy sprtemp to it
if ( spritedef - > numframes & & // has been allocated
spritedef - > numframes < maxframe ) // more frames are defined ?
{
Z_Free ( spritedef - > spriteframes ) ;
spritedef - > spriteframes = NULL ;
}
// allocate this sprite's frames
if ( ! spritedef - > spriteframes )
spritedef - > spriteframes =
Z_Malloc ( maxframe * sizeof ( * spritedef - > spriteframes ) , PU_STATIC , NULL ) ;
spritedef - > numframes = maxframe ;
M_Memcpy ( spritedef - > spriteframes , sprtemp , maxframe * sizeof ( spriteframe_t ) ) ;
return true ;
}
//
// Search for sprites replacements in a wad whose names are in namelist
//
void R_AddSpriteDefs ( UINT16 wadnum )
{
size_t i , addsprites = 0 ;
UINT16 start , end ;
char wadname [ MAX_WADPATH ] ;
2017-05-16 19:10:02 +00:00
// Find the sprites section in this resource file.
2018-11-23 15:58:16 +00:00
switch ( wadfiles [ wadnum ] - > type )
{
case RET_WAD :
2020-02-08 03:41:45 +00:00
start = W_CheckNumForMarkerStartPwad ( " S_START " , wadnum , 0 ) ;
2017-10-10 06:41:28 +00:00
if ( start = = INT16_MAX )
2020-02-08 03:41:45 +00:00
start = W_CheckNumForMarkerStartPwad ( " SS_START " , wadnum , 0 ) ; //deutex compatib.
2015-01-22 15:23:45 +00:00
2018-11-23 15:58:16 +00:00
end = W_CheckNumForNamePwad ( " S_END " , wadnum , start ) ;
if ( end = = INT16_MAX )
end = W_CheckNumForNamePwad ( " SS_END " , wadnum , start ) ; //deutex compatib.
break ;
case RET_PK3 :
2021-03-23 02:56:55 +00:00
case RET_FOLDER :
2018-11-23 15:58:16 +00:00
start = W_CheckNumForFolderStartPK3 ( " Sprites/ " , wadnum , 0 ) ;
end = W_CheckNumForFolderEndPK3 ( " Sprites/ " , wadnum , start ) ;
break ;
default :
return ;
2017-05-16 19:10:02 +00:00
}
2019-11-08 02:27:06 +00:00
if ( start = = INT16_MAX )
{
// ignore skin wads (we don't want skin sprites interfering with vanilla sprites)
if ( W_CheckNumForNamePwad ( " S_SKIN " , wadnum , 0 ) ! = UINT16_MAX )
return ;
start = 0 ; //let say S_START is lump 0
}
2019-01-08 05:19:42 +00:00
2019-12-03 21:05:05 +00:00
if ( end = = INT16_MAX | | start > = end )
2014-03-15 16:59:03 +00:00
{
CONS_Debug ( DBG_SETUP , " no sprites in pwad %d \n " , wadnum ) ;
return ;
}
2017-05-16 19:10:02 +00:00
2014-03-15 16:59:03 +00:00
//
// scan through lumps, for each sprite, find all the sprite frames
//
for ( i = 0 ; i < numsprites ; i + + )
{
2020-03-08 19:51:18 +00:00
if ( sprnames [ i ] [ 4 ] & & wadnum > = ( UINT16 ) sprnames [ i ] [ 4 ] )
2014-03-15 16:59:03 +00:00
continue ;
2020-03-08 19:51:18 +00:00
if ( R_AddSingleSpriteDef ( sprnames [ i ] , & sprites [ i ] , wadnum , start , end ) )
2014-03-15 16:59:03 +00:00
{
// if a new sprite was added (not just replaced)
addsprites + + ;
# ifndef ZDEBUG
2020-03-08 19:51:18 +00:00
CONS_Debug ( DBG_SETUP , " sprite %s set in pwad %d \n " , sprnames [ i ] , wadnum ) ;
2014-03-15 16:59:03 +00:00
# endif
}
}
nameonly ( strcpy ( wadname , wadfiles [ wadnum ] - > filename ) ) ;
CONS_Printf ( M_GetText ( " %s added %d frames in %s sprites \n " ) , wadname , end - start , sizeu1 ( addsprites ) ) ;
}
//
// GAME FUNCTIONS
//
2023-09-03 20:02:35 +00:00
UINT32 visspritecount , numvisiblesprites ;
2014-11-12 00:55:07 +00:00
static UINT32 clippedvissprites ;
2014-03-15 16:59:03 +00:00
static vissprite_t * visspritechunks [ MAXVISSPRITES > > VISSPRITECHUNKBITS ] = { NULL } ;
//
// R_InitSprites
// Called at program start.
//
void R_InitSprites ( void )
{
2019-09-29 22:03:10 +00:00
size_t i ;
2019-08-18 17:16:48 +00:00
# ifdef ROTSPRITE
2019-12-27 00:27:30 +00:00
INT32 angle ;
2019-08-18 17:16:48 +00:00
float fa ;
# endif
2014-03-15 16:59:03 +00:00
for ( i = 0 ; i < MAXVIDWIDTH ; i + + )
negonearray [ i ] = - 1 ;
2019-08-18 17:16:48 +00:00
# ifdef ROTSPRITE
2019-12-27 00:27:30 +00:00
for ( angle = 1 ; angle < ROTANGLES ; angle + + )
2019-08-18 17:16:48 +00:00
{
2019-12-27 00:27:30 +00:00
fa = ANG2RAD ( FixedAngle ( ( ROTANGDIFF * angle ) < < FRACBITS ) ) ;
rollcosang [ angle ] = FLOAT_TO_FIXED ( cos ( - fa ) ) ;
rollsinang [ angle ] = FLOAT_TO_FIXED ( sin ( - fa ) ) ;
2014-03-15 16:59:03 +00:00
}
2019-08-18 17:16:48 +00:00
# endif
2014-03-15 16:59:03 +00:00
//
// count the number of sprite names, and allocate sprites table
//
numsprites = 0 ;
for ( i = 0 ; i < NUMSPRITES + 1 ; i + + )
if ( sprnames [ i ] [ 0 ] ! = ' \0 ' ) numsprites + + ;
if ( ! numsprites )
I_Error ( " R_AddSpriteDefs: no sprites in namelist \n " ) ;
sprites = Z_Calloc ( numsprites * sizeof ( * sprites ) , PU_STATIC , NULL ) ;
// find sprites in each -file added pwad
for ( i = 0 ; i < numwadfiles ; i + + )
R_AddSpriteDefs ( ( UINT16 ) i ) ;
//
// now check for skins
//
// it can be is do before loading config for skin cvar possible value
R_InitSkins ( ) ;
for ( i = 0 ; i < numwadfiles ; i + + )
A good and bad ending cutscene now exist.
Also:
* SPR2_XTRA - instead of defining lumpnames in S_SKIN, those kinds of assets can just be bundled into the spriteset. Required for ending cutscene stuff, I guess, but also done for HUD life icon and character select image (aside from Sonic&Tails, still SOC'd in).
* Minor oversights in SPR2 support corrected.
* Better evaluation, featuring ending assets.
* Intro has warping-in blackrock, reusing ending assets.
* Cutscene text now supports lowercase (intro and custom).
* Disable the asset-fucking "gamma correction" I put in over two years ago when implementing colour cube. (This is the only thing I could move into another branch if you MUST, but it's basically invisble in the diff so w/e.)
* Don't blank the screen if the top left pixel of a screen-covering patch is transparent. (Checked via nonzero topdelta for first column)
Bugs:
* OPENGL ONLY: The first ~20 frames of both endings are fucked. A little help here? Might be HWR_DrawFadeFill's fault, which I just created. OR it could be in f_finale, but I doubt it, since it doesn't appear in Software.
2019-07-27 23:32:57 +00:00
{
2021-04-25 11:18:32 +00:00
R_AddSkins ( ( UINT16 ) i , true ) ;
R_PatchSkins ( ( UINT16 ) i , true ) ;
2019-09-29 22:03:10 +00:00
R_LoadSpriteInfoLumps ( i , wadfiles [ i ] - > numlumps ) ;
A good and bad ending cutscene now exist.
Also:
* SPR2_XTRA - instead of defining lumpnames in S_SKIN, those kinds of assets can just be bundled into the spriteset. Required for ending cutscene stuff, I guess, but also done for HUD life icon and character select image (aside from Sonic&Tails, still SOC'd in).
* Minor oversights in SPR2 support corrected.
* Better evaluation, featuring ending assets.
* Intro has warping-in blackrock, reusing ending assets.
* Cutscene text now supports lowercase (intro and custom).
* Disable the asset-fucking "gamma correction" I put in over two years ago when implementing colour cube. (This is the only thing I could move into another branch if you MUST, but it's basically invisble in the diff so w/e.)
* Don't blank the screen if the top left pixel of a screen-covering patch is transparent. (Checked via nonzero topdelta for first column)
Bugs:
* OPENGL ONLY: The first ~20 frames of both endings are fucked. A little help here? Might be HWR_DrawFadeFill's fault, which I just created. OR it could be in f_finale, but I doubt it, since it doesn't appear in Software.
2019-07-27 23:32:57 +00:00
}
ST_ReloadSkinFaceGraphics ( ) ;
2014-03-15 16:59:03 +00:00
2021-08-09 18:57:07 +00:00
# ifdef HWRENDER
if ( rendermode = = render_opengl )
HWR_LoadModels ( ) ;
# endif
2014-03-15 16:59:03 +00:00
}
//
// R_ClearSprites
// Called at frame start.
//
void R_ClearSprites ( void )
{
2023-09-03 20:02:35 +00:00
visspritecount = numvisiblesprites = clippedvissprites = 0 ;
2014-03-15 16:59:03 +00:00
}
//
// R_NewVisSprite
//
static vissprite_t overflowsprite ;
static vissprite_t * R_GetVisSprite ( UINT32 num )
{
UINT32 chunk = num > > VISSPRITECHUNKBITS ;
// Allocate chunk if necessary
if ( ! visspritechunks [ chunk ] )
Z_Malloc ( sizeof ( vissprite_t ) * VISSPRITESPERCHUNK , PU_LEVEL , & visspritechunks [ chunk ] ) ;
return visspritechunks [ chunk ] + ( num & VISSPRITEINDEXMASK ) ;
}
static vissprite_t * R_NewVisSprite ( void )
{
if ( visspritecount = = MAXVISSPRITES )
return & overflowsprite ;
return R_GetVisSprite ( visspritecount + + ) ;
}
//
// R_DrawMaskedColumn
// Used for sprites and masked mid textures.
// Masked means: partly transparent, i.e. stored
// in posts/runs of opaque pixels.
//
INT16 * mfloorclip ;
INT16 * mceilingclip ;
fixed_t spryscale = 0 , sprtopscreen = 0 , sprbotscreen = 0 ;
fixed_t windowtop = 0 , windowbottom = 0 ;
2024-01-16 16:49:47 +00:00
void R_DrawMaskedColumn ( column_t * column , unsigned lengthcol )
2014-03-15 16:59:03 +00:00
{
2023-07-30 23:56:28 +00:00
fixed_t basetexturemid = dc_texturemid ;
2014-03-15 16:59:03 +00:00
2024-01-16 16:49:47 +00:00
( void ) lengthcol ;
2023-09-03 16:27:49 +00:00
for ( unsigned i = 0 ; i < column - > num_posts ; i + + )
2014-03-15 16:59:03 +00:00
{
2023-07-30 23:56:28 +00:00
post_t * post = & column - > posts [ i ] ;
INT32 topscreen = sprtopscreen + spryscale * post - > topdelta ;
INT32 bottomscreen = topscreen + spryscale * post - > length ;
2014-03-15 16:59:03 +00:00
dc_yl = ( topscreen + FRACUNIT - 1 ) > > FRACBITS ;
dc_yh = ( bottomscreen - 1 ) > > FRACBITS ;
if ( windowtop ! = INT32_MAX & & windowbottom ! = INT32_MAX )
{
if ( windowtop > topscreen )
dc_yl = ( windowtop + FRACUNIT - 1 ) > > FRACBITS ;
if ( windowbottom < bottomscreen )
dc_yh = ( windowbottom - 1 ) > > FRACBITS ;
}
if ( dc_yh > = mfloorclip [ dc_x ] )
dc_yh = mfloorclip [ dc_x ] - 1 ;
if ( dc_yl < = mceilingclip [ dc_x ] )
dc_yl = mceilingclip [ dc_x ] + 1 ;
if ( dc_yl < 0 )
dc_yl = 0 ;
2020-01-11 16:24:00 +00:00
if ( dc_yh > = vid . height ) // dc_yl must be < vid.height, so reduces number of checks in tight loop
2014-03-15 16:59:03 +00:00
dc_yh = vid . height - 1 ;
2020-01-11 16:24:00 +00:00
if ( dc_yl < = dc_yh & & dc_yh > 0 )
2014-03-15 16:59:03 +00:00
{
2023-07-30 23:56:28 +00:00
dc_source = column - > pixels + post - > data_offset ;
dc_texturemid = basetexturemid - ( post - > topdelta < < FRACBITS ) ;
2014-03-15 16:59:03 +00:00
2024-01-16 16:49:47 +00:00
colfunc ( ) ;
2014-03-15 16:59:03 +00:00
}
}
dc_texturemid = basetexturemid ;
}
2024-01-16 16:49:47 +00:00
static UINT8 * flippedcol = NULL ;
static size_t flippedcolsize = 0 ;
2020-01-11 16:24:00 +00:00
2024-01-16 16:49:47 +00:00
void R_DrawFlippedMaskedColumn ( column_t * column , unsigned lengthcol )
2014-03-15 16:59:03 +00:00
{
INT32 topscreen ;
INT32 bottomscreen ;
fixed_t basetexturemid = dc_texturemid ;
UINT8 * d , * s ;
2023-09-03 16:27:49 +00:00
for ( unsigned i = 0 ; i < column - > num_posts ; i + + )
2014-03-15 16:59:03 +00:00
{
2023-07-30 23:56:28 +00:00
post_t * post = & column - > posts [ i ] ;
2024-01-16 16:49:47 +00:00
if ( ! post - > length )
continue ;
2023-07-30 23:56:28 +00:00
INT32 topdelta = lengthcol - post - > length - post - > topdelta ;
2014-03-15 16:59:03 +00:00
topscreen = sprtopscreen + spryscale * topdelta ;
2023-07-30 23:56:28 +00:00
bottomscreen = sprbotscreen = = INT32_MAX ? topscreen + spryscale * post - > length
: sprbotscreen + spryscale * post - > length ;
2014-03-15 16:59:03 +00:00
dc_yl = ( topscreen + FRACUNIT - 1 ) > > FRACBITS ;
dc_yh = ( bottomscreen - 1 ) > > FRACBITS ;
if ( windowtop ! = INT32_MAX & & windowbottom ! = INT32_MAX )
{
if ( windowtop > topscreen )
dc_yl = ( windowtop + FRACUNIT - 1 ) > > FRACBITS ;
if ( windowbottom < bottomscreen )
dc_yh = ( windowbottom - 1 ) > > FRACBITS ;
}
if ( dc_yh > = mfloorclip [ dc_x ] )
dc_yh = mfloorclip [ dc_x ] - 1 ;
if ( dc_yl < = mceilingclip [ dc_x ] )
dc_yl = mceilingclip [ dc_x ] + 1 ;
if ( dc_yl < 0 )
dc_yl = 0 ;
2020-01-11 16:24:00 +00:00
if ( dc_yh > = vid . height ) // dc_yl must be < vid.height, so reduces number of checks in tight loop
2014-03-15 16:59:03 +00:00
dc_yh = vid . height - 1 ;
2020-01-11 16:24:00 +00:00
if ( dc_yl < = dc_yh & & dc_yh > 0 )
2014-03-15 16:59:03 +00:00
{
2024-01-16 16:49:47 +00:00
if ( post - > length > flippedcolsize )
{
flippedcolsize = post - > length ;
flippedcol = Z_Realloc ( flippedcol , flippedcolsize , PU_STATIC , NULL ) ;
}
for ( s = column - > pixels + post - > data_offset + post - > length , d = flippedcol ; d < flippedcol + post - > length ; - - s )
2014-03-15 16:59:03 +00:00
* d + + = * s ;
2024-01-16 16:49:47 +00:00
dc_source = flippedcol ;
2014-03-15 16:59:03 +00:00
dc_texturemid = basetexturemid - ( topdelta < < FRACBITS ) ;
2024-01-16 16:49:47 +00:00
colfunc ( ) ;
2014-03-15 16:59:03 +00:00
}
}
dc_texturemid = basetexturemid ;
}
2020-10-12 03:13:22 +00:00
boolean R_SpriteIsFlashing ( vissprite_t * vis )
{
return ( ! ( vis - > cut & SC_PRECIP )
& & ( vis - > mobj - > flags & ( MF_ENEMY | MF_BOSS ) )
& & ( vis - > mobj - > flags2 & MF2_FRET )
& & ! ( vis - > mobj - > flags & MF_GRENADEBOUNCE )
& & ( leveltime & 1 ) ) ;
}
UINT8 * R_GetSpriteTranslation ( vissprite_t * vis )
{
if ( R_SpriteIsFlashing ( vis ) ) // Bosses "flash"
{
if ( vis - > mobj - > type = = MT_CYBRAKDEMON | | vis - > mobj - > colorized )
return R_GetTranslationColormap ( TC_ALLWHITE , 0 , GTC_CACHE ) ;
else if ( vis - > mobj - > type = = MT_METALSONIC_BATTLE )
return R_GetTranslationColormap ( TC_METALSONIC , 0 , GTC_CACHE ) ;
else
2021-07-06 08:36:05 +00:00
return R_GetTranslationColormap ( TC_BOSS , vis - > color , GTC_CACHE ) ;
2020-10-12 03:13:22 +00:00
}
2021-07-06 08:36:05 +00:00
else if ( vis - > color )
2020-10-12 03:13:22 +00:00
{
// New colormap stuff for skins Tails 06-07-2002
if ( ! ( vis - > cut & SC_PRECIP ) & & vis - > mobj - > colorized )
2021-07-06 08:36:05 +00:00
return R_GetTranslationColormap ( TC_RAINBOW , vis - > color , GTC_CACHE ) ;
2020-10-12 03:13:22 +00:00
else if ( ! ( vis - > cut & SC_PRECIP )
& & vis - > mobj - > player & & vis - > mobj - > player - > dashmode > = DASHMODE_THRESHOLD
& & ( vis - > mobj - > player - > charflags & SF_DASHMODE )
& & ( ( leveltime / 2 ) & 1 ) )
{
if ( vis - > mobj - > player - > charflags & SF_MACHINE )
return R_GetTranslationColormap ( TC_DASHMODE , 0 , GTC_CACHE ) ;
else
2021-07-06 08:36:05 +00:00
return R_GetTranslationColormap ( TC_RAINBOW , vis - > color , GTC_CACHE ) ;
2020-10-12 03:13:22 +00:00
}
else if ( ! ( vis - > cut & SC_PRECIP ) & & vis - > mobj - > skin & & vis - > mobj - > sprite = = SPR_PLAY ) // This thing is a player!
{
2021-08-10 18:17:22 +00:00
UINT8 skinnum = ( ( skin_t * ) vis - > mobj - > skin ) - > skinnum ;
2023-10-28 22:09:42 +00:00
return R_GetTranslationColormap ( skinnum , vis - > color , GTC_CACHE ) ;
2020-10-12 03:13:22 +00:00
}
else // Use the defaults
2021-07-06 08:36:05 +00:00
return R_GetTranslationColormap ( TC_DEFAULT , vis - > color , GTC_CACHE ) ;
2020-10-12 03:13:22 +00:00
}
else if ( vis - > mobj - > sprite = = SPR_PLAY ) // Looks like a player, but doesn't have a color? Get rid of green sonic syndrome.
return R_GetTranslationColormap ( TC_DEFAULT , SKINCOLOR_BLUE , GTC_CACHE ) ;
return NULL ;
}
2014-03-15 16:59:03 +00:00
//
// R_DrawVisSprite
// mfloorclip and mceilingclip should also be set.
//
static void R_DrawVisSprite ( vissprite_t * vis )
{
column_t * column ;
2024-01-16 16:49:47 +00:00
void ( * localcolfunc ) ( column_t * , unsigned ) ;
2020-01-11 16:24:00 +00:00
INT32 pwidth ;
2014-03-15 16:59:03 +00:00
fixed_t frac ;
2019-08-18 17:16:48 +00:00
patch_t * patch = vis - > patch ;
2021-02-28 19:23:40 +00:00
fixed_t this_scale = vis - > thingscale ;
2014-03-15 16:59:03 +00:00
INT32 x1 , x2 ;
2016-05-02 12:29:30 +00:00
INT64 overflow_test ;
2024-01-16 16:49:47 +00:00
INT32 lengthcol ;
2014-03-15 16:59:03 +00:00
if ( ! patch )
return ;
2016-05-02 12:29:30 +00:00
// Check for overflow
overflow_test = ( INT64 ) centeryfrac - ( ( ( INT64 ) vis - > texturemid * vis - > scale ) > > FRACBITS ) ;
if ( overflow_test < 0 ) overflow_test = - overflow_test ;
if ( ( UINT64 ) overflow_test & 0xFFFFFFFF80000000ULL ) return ; // fixed point mult would overflow
2016-08-20 00:03:35 +00:00
if ( vis - > scalestep ) // handles right edge too
{
overflow_test = ( INT64 ) centeryfrac - ( ( ( INT64 ) vis - > texturemid * ( vis - > scale + ( vis - > scalestep * ( vis - > x2 - vis - > x1 ) ) ) ) > > FRACBITS ) ;
if ( overflow_test < 0 ) overflow_test = - overflow_test ;
if ( ( UINT64 ) overflow_test & 0xFFFFFFFF80000000ULL ) return ; // ditto
}
2023-09-03 21:31:08 +00:00
// TODO This check should not be necessary. But Papersprites near to the camera will sometimes create invalid values
// for the vissprite's startfrac. This happens because they are not depth culled like other sprites.
// Someone who is more familiar with papersprites pls check and try to fix <3
if ( vis - > startfrac < 0 | | vis - > startfrac > ( patch - > width < < FRACBITS ) )
{
// never draw vissprites with startfrac out of patch range
return ;
}
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ BASEDRAWFUNC ] ; // hack: this isn't resetting properly somewhere.
2014-03-15 16:59:03 +00:00
dc_colormap = vis - > colormap ;
2020-10-12 03:13:22 +00:00
dc_translation = R_GetSpriteTranslation ( vis ) ;
if ( R_SpriteIsFlashing ( vis ) ) // Bosses "flash"
colfunc = colfuncs [ COLDRAWFUNC_TRANS ] ; // translate certain pixels to white
2021-07-06 08:36:05 +00:00
else if ( vis - > color & & vis - > transmap ) // Color mapping
2014-03-15 16:59:03 +00:00
{
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ COLDRAWFUNC_TRANSTRANS ] ;
2014-03-15 16:59:03 +00:00
dc_transmap = vis - > transmap ;
}
else if ( vis - > transmap )
{
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ COLDRAWFUNC_FUZZY ] ;
2014-03-15 16:59:03 +00:00
dc_transmap = vis - > transmap ; //Fab : 29-04-98: translucency table
}
2021-07-06 08:36:05 +00:00
else if ( vis - > color ) // translate green skin to another color
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ COLDRAWFUNC_TRANS ] ;
2014-03-15 16:59:03 +00:00
else if ( vis - > mobj - > sprite = = SPR_PLAY ) // Looks like a player, but doesn't have a color? Get rid of green sonic syndrome.
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ COLDRAWFUNC_TRANS ] ;
2014-03-15 16:59:03 +00:00
2022-01-04 20:30:50 +00:00
// Hack: Use a special column function for drop shadows that bypasses
// invalid memory access crashes caused by R_ProjectDropShadow putting wrong values
// in dc_texturemid and dc_iscale when the shadow is sloped.
if ( vis - > cut & SC_SHADOW )
colfunc = R_DrawDropShadowColumn_8 ;
2020-10-27 22:54:10 +00:00
if ( vis - > extra_colormap & & ! ( vis - > renderflags & RF_NOCOLORMAPS ) )
2014-03-15 16:59:03 +00:00
{
if ( ! dc_colormap )
dc_colormap = vis - > extra_colormap - > colormap ;
else
dc_colormap = & vis - > extra_colormap - > colormap [ dc_colormap - colormaps ] ;
}
if ( ! dc_colormap )
dc_colormap = colormaps ;
dc_texturemid = vis - > texturemid ;
dc_texheight = 0 ;
frac = vis - > startfrac ;
windowtop = windowbottom = sprbotscreen = INT32_MAX ;
2023-09-03 21:59:39 +00:00
if ( vis - > cut & SC_SHADOW & & vis - > mobj - > skin & & ( ( skin_t * ) vis - > mobj - > skin ) - > flags & SF_HIRES )
2014-03-15 16:59:03 +00:00
this_scale = FixedMul ( this_scale , ( ( skin_t * ) vis - > mobj - > skin ) - > highresscale ) ;
if ( this_scale < = 0 )
this_scale = 1 ;
if ( this_scale ! = FRACUNIT )
{
2017-06-26 13:44:10 +00:00
if ( ! ( vis - > cut & SC_ISSCALED ) )
2014-03-15 16:59:03 +00:00
{
vis - > scale = FixedMul ( vis - > scale , this_scale ) ;
2016-08-17 20:14:01 +00:00
vis - > scalestep = FixedMul ( vis - > scalestep , this_scale ) ;
2023-09-03 21:59:39 +00:00
vis - > xiscale = FixedDiv ( vis - > xiscale , this_scale ) ;
2017-06-26 13:44:10 +00:00
vis - > cut | = SC_ISSCALED ;
2014-03-15 16:59:03 +00:00
}
2023-09-03 21:59:39 +00:00
dc_texturemid = FixedDiv ( dc_texturemid , this_scale ) ;
2016-08-20 11:18:00 +00:00
}
2014-03-15 16:59:03 +00:00
2016-08-20 11:18:00 +00:00
spryscale = vis - > scale ;
2014-03-15 16:59:03 +00:00
2016-08-20 11:18:00 +00:00
if ( ! ( vis - > scalestep ) )
{
2014-03-15 16:59:03 +00:00
sprtopscreen = centeryfrac - FixedMul ( dc_texturemid , spryscale ) ;
2020-01-09 03:52:10 +00:00
sprtopscreen + = vis - > shear . tan * vis - > shear . offset ;
2016-08-20 11:18:00 +00:00
dc_iscale = FixedDiv ( FRACUNIT , vis - > scale ) ;
2014-03-15 16:59:03 +00:00
}
x1 = vis - > x1 ;
x2 = vis - > x2 ;
if ( vis - > x1 < 0 )
2016-08-20 11:18:00 +00:00
{
spryscale + = vis - > scalestep * ( - vis - > x1 ) ;
2014-03-15 16:59:03 +00:00
vis - > x1 = 0 ;
2016-08-20 11:18:00 +00:00
}
2014-03-15 16:59:03 +00:00
if ( vis - > x2 > = vid . width )
vis - > x2 = vid . width - 1 ;
2020-01-11 16:24:00 +00:00
localcolfunc = ( vis - > cut & SC_VFLIP ) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn ;
2020-11-22 23:02:47 +00:00
lengthcol = patch - > height ;
2020-01-11 16:24:00 +00:00
2019-12-27 17:48:40 +00:00
// Split drawing loops for paper and non-paper to reduce conditional checks per sprite
if ( vis - > scalestep )
2014-03-15 16:59:03 +00:00
{
2020-10-12 20:25:18 +00:00
fixed_t horzscale = FixedMul ( vis - > spritexscale , this_scale ) ;
fixed_t scalestep = FixedMul ( vis - > scalestep , vis - > spriteyscale ) ;
2020-11-22 23:02:47 +00:00
pwidth = patch - > width ;
2019-12-27 17:48:40 +00:00
2020-01-11 16:24:00 +00:00
// Papersprite drawing loop
2020-10-12 20:25:18 +00:00
for ( dc_x = vis - > x1 ; dc_x < = vis - > x2 ; dc_x + + , spryscale + = scalestep )
2016-08-16 22:17:45 +00:00
{
2019-12-27 10:57:16 +00:00
angle_t angle = ( ( vis - > centerangle + xtoviewangle [ dc_x ] ) > > ANGLETOFINESHIFT ) & 0xFFF ;
2023-11-06 21:43:41 +00:00
INT32 texturecolumn = ( vis - > paperoffset - FixedMul ( FINETANGENT ( angle ) , vis - > paperdistance ) ) / horzscale ;
2019-12-27 10:57:16 +00:00
2020-01-11 16:24:00 +00:00
if ( texturecolumn < 0 | | texturecolumn > = pwidth )
2019-12-27 10:57:16 +00:00
continue ;
2019-12-27 17:48:40 +00:00
if ( vis - > xiscale < 0 ) // Flipped sprite
2020-01-11 16:24:00 +00:00
texturecolumn = pwidth - 1 - texturecolumn ;
2019-12-27 10:57:16 +00:00
2016-08-16 22:17:45 +00:00
sprtopscreen = ( centeryfrac - FixedMul ( dc_texturemid , spryscale ) ) ;
2016-08-17 20:24:53 +00:00
dc_iscale = ( 0xffffffffu / ( unsigned ) spryscale ) ;
2019-12-27 17:48:40 +00:00
2023-11-06 21:43:41 +00:00
column = & patch - > columns [ texturecolumn ] ;
2019-12-27 17:48:40 +00:00
2024-01-16 16:49:47 +00:00
localcolfunc ( column , lengthcol ) ;
2016-08-16 22:17:45 +00:00
}
2019-12-27 17:48:40 +00:00
}
2020-10-12 03:13:22 +00:00
else if ( vis - > cut & SC_SHEAR )
{
# ifdef RANGECHECK
2020-11-22 23:02:47 +00:00
pwidth = patch - > width ;
2020-10-12 03:13:22 +00:00
# endif
// Vertically sheared sprite
for ( dc_x = vis - > x1 ; dc_x < = vis - > x2 ; dc_x + + , frac + = vis - > xiscale , dc_texturemid - = vis - > shear . tan )
{
2023-11-06 21:43:41 +00:00
column = & patch - > columns [ frac > > FRACBITS ] ;
2020-10-12 03:13:22 +00:00
sprtopscreen = ( centeryfrac - FixedMul ( dc_texturemid , spryscale ) ) ;
2024-01-16 16:49:47 +00:00
localcolfunc ( column , lengthcol ) ;
2016-08-16 22:17:45 +00:00
}
2019-12-27 17:48:40 +00:00
}
else
{
2020-01-11 16:24:00 +00:00
# ifdef RANGECHECK
2020-11-22 23:02:47 +00:00
pwidth = patch - > width ;
2020-01-11 16:24:00 +00:00
# endif
2019-12-27 17:48:40 +00:00
// Non-paper drawing loop
2020-01-09 03:52:10 +00:00
for ( dc_x = vis - > x1 ; dc_x < = vis - > x2 ; dc_x + + , frac + = vis - > xiscale , sprtopscreen + = vis - > shear . tan )
2019-12-27 10:57:16 +00:00
{
2023-11-06 21:43:41 +00:00
column = & patch - > columns [ frac > > FRACBITS ] ;
2024-01-16 16:49:47 +00:00
localcolfunc ( column , lengthcol ) ;
2019-12-27 10:57:16 +00:00
}
2014-03-15 16:59:03 +00:00
}
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ BASEDRAWFUNC ] ;
2014-03-15 16:59:03 +00:00
dc_hires = 0 ;
vis - > x1 = x1 ;
vis - > x2 = x2 ;
}
// Special precipitation drawer Tails 08-18-2002
static void R_DrawPrecipitationVisSprite ( vissprite_t * vis )
{
2023-11-06 21:43:41 +00:00
patch_t * patch = vis - > patch ;
2014-03-15 16:59:03 +00:00
if ( ! patch )
return ;
2017-03-02 19:37:21 +00:00
// Check for overflow
2023-11-06 21:43:41 +00:00
INT64 overflow_test = ( INT64 ) centeryfrac - ( ( ( INT64 ) vis - > texturemid * vis - > scale ) > > FRACBITS ) ;
2017-03-02 19:37:21 +00:00
if ( overflow_test < 0 ) overflow_test = - overflow_test ;
if ( ( UINT64 ) overflow_test & 0xFFFFFFFF80000000ULL ) return ; // fixed point mult would overflow
2014-03-15 16:59:03 +00:00
if ( vis - > transmap )
{
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ COLDRAWFUNC_FUZZY ] ;
2014-03-15 16:59:03 +00:00
dc_transmap = vis - > transmap ; //Fab : 29-04-98: translucency table
}
dc_colormap = colormaps ;
dc_iscale = FixedDiv ( FRACUNIT , vis - > scale ) ;
dc_texturemid = vis - > texturemid ;
dc_texheight = 0 ;
spryscale = vis - > scale ;
sprtopscreen = centeryfrac - FixedMul ( dc_texturemid , spryscale ) ;
windowtop = windowbottom = sprbotscreen = INT32_MAX ;
if ( vis - > x1 < 0 )
vis - > x1 = 0 ;
if ( vis - > x2 > = vid . width )
vis - > x2 = vid . width - 1 ;
2023-11-06 21:43:41 +00:00
fixed_t frac = vis - > startfrac ;
2014-03-15 16:59:03 +00:00
for ( dc_x = vis - > x1 ; dc_x < = vis - > x2 ; dc_x + + , frac + = vis - > xiscale )
2024-01-16 16:49:47 +00:00
R_DrawMaskedColumn ( & patch - > columns [ frac > > FRACBITS ] , patch - > height ) ;
2014-03-15 16:59:03 +00:00
2019-12-13 15:26:47 +00:00
colfunc = colfuncs [ BASEDRAWFUNC ] ;
2014-03-15 16:59:03 +00:00
}
//
// R_SplitSprite
2020-01-03 01:58:23 +00:00
// runs through a sector's lightlist and Knuckles
2017-06-26 13:44:10 +00:00
static void R_SplitSprite ( vissprite_t * sprite )
2014-03-15 16:59:03 +00:00
{
INT32 i , lightnum , lindex ;
INT16 cutfrac ;
sector_t * sector ;
vissprite_t * newsprite ;
sector = sprite - > sector ;
for ( i = 1 ; i < sector - > numlights ; i + + )
{
2020-03-22 14:17:16 +00:00
fixed_t testheight ;
2015-05-18 05:23:44 +00:00
2022-07-31 10:04:42 +00:00
if ( ! ( sector - > lightlist [ i ] . caster - > fofflags & FOF_CUTSPRITES ) )
2015-05-18 05:23:44 +00:00
continue ;
2020-03-22 14:17:16 +00:00
testheight = P_GetLightZAt ( & sector - > lightlist [ i ] , sprite - > gx , sprite - > gy ) ;
2015-05-18 05:23:44 +00:00
if ( testheight > = sprite - > gzt )
2014-03-15 16:59:03 +00:00
continue ;
2015-05-18 05:23:44 +00:00
if ( testheight < = sprite - > gz )
2014-03-15 16:59:03 +00:00
return ;
2022-11-05 01:33:41 +00:00
cutfrac = ( INT16 ) ( ( centeryfrac - FixedMul ( testheight - viewz , sprite - > linkscale ) ) > > FRACBITS ) ;
2014-03-15 16:59:03 +00:00
if ( cutfrac < 0 )
continue ;
2016-04-10 19:27:55 +00:00
if ( cutfrac > viewheight )
2014-03-15 16:59:03 +00:00
return ;
// Found a split! Make a new sprite, copy the old sprite to it, and
// adjust the heights.
newsprite = M_Memcpy ( R_NewVisSprite ( ) , sprite , sizeof ( vissprite_t ) ) ;
2017-06-26 13:44:10 +00:00
newsprite - > cut | = ( sprite - > cut & SC_FLAGMASK ) ;
2017-06-25 19:46:30 +00:00
2014-03-15 16:59:03 +00:00
sprite - > cut | = SC_BOTTOM ;
2015-05-18 05:23:44 +00:00
sprite - > gz = testheight ;
2014-03-15 16:59:03 +00:00
newsprite - > gzt = sprite - > gz ;
sprite - > sz = cutfrac ;
newsprite - > szt = ( INT16 ) ( sprite - > sz - 1 ) ;
2020-12-23 03:02:31 +00:00
if ( testheight < sprite - > pzt & & testheight > sprite - > pz )
sprite - > pz = newsprite - > pzt = testheight ;
else
{
newsprite - > pz = newsprite - > gz ;
newsprite - > pzt = newsprite - > gzt ;
}
2014-03-15 16:59:03 +00:00
newsprite - > szt - = 8 ;
newsprite - > cut | = SC_TOP ;
2022-07-31 10:04:42 +00:00
if ( ! ( sector - > lightlist [ i ] . caster - > fofflags & FOF_NOSHADE ) )
2014-03-15 16:59:03 +00:00
{
lightnum = ( * sector - > lightlist [ i ] . lightlevel > > LIGHTSEGSHIFT ) ;
if ( lightnum < 0 )
spritelights = scalelight [ 0 ] ;
else if ( lightnum > = LIGHTLEVELS )
spritelights = scalelight [ LIGHTLEVELS - 1 ] ;
else
spritelights = scalelight [ lightnum ] ;
2018-09-12 20:06:56 +00:00
newsprite - > extra_colormap = * sector - > lightlist [ i ] . extra_colormap ;
2014-03-15 16:59:03 +00:00
2020-02-16 19:19:24 +00:00
if ( ! ( newsprite - > cut & SC_FULLBRIGHT )
| | ( newsprite - > extra_colormap & & ( newsprite - > extra_colormap - > flags & CMF_FADEFULLBRIGHTSPRITES ) ) )
2014-03-15 16:59:03 +00:00
{
2020-01-18 06:16:18 +00:00
lindex = FixedMul ( sprite - > xscale , LIGHTRESOLUTIONFIX ) > > ( LIGHTSCALESHIFT ) ;
2014-03-15 16:59:03 +00:00
if ( lindex > = MAXLIGHTSCALE )
lindex = MAXLIGHTSCALE - 1 ;
2021-11-15 17:03:07 +00:00
if ( newsprite - > cut & SC_SEMIBRIGHT )
lindex = ( MAXLIGHTSCALE / 2 ) + ( lindex > > 1 ) ;
2014-03-15 16:59:03 +00:00
newsprite - > colormap = spritelights [ lindex ] ;
}
}
sprite = newsprite ;
}
}
2020-01-09 05:19:52 +00:00
//
// R_GetShadowZ(thing, shadowslope)
// Get the first visible floor below the object for shadows
// shadowslope is filled with the floor's slope, if provided
//
fixed_t R_GetShadowZ ( mobj_t * thing , pslope_t * * shadowslope )
2019-12-27 21:31:20 +00:00
{
2021-12-25 07:07:56 +00:00
fixed_t halfHeight ;
2020-05-30 17:21:26 +00:00
boolean isflipped = thing - > eflags & MFE_VERTICALFLIP ;
2021-12-25 07:07:56 +00:00
fixed_t floorz ;
fixed_t ceilingz ;
2020-05-30 17:21:26 +00:00
fixed_t z , groundz = isflipped ? INT32_MAX : INT32_MIN ;
pslope_t * slope , * groundslope = NULL ;
2020-01-09 05:19:52 +00:00
msecnode_t * node ;
sector_t * sector ;
ffloor_t * rover ;
2022-04-11 03:29:52 +00:00
// for frame interpolation
2022-04-12 23:39:11 +00:00
interpmobjstate_t interp = { 0 } ;
2022-04-11 03:29:52 +00:00
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2022-04-11 03:29:52 +00:00
{
2022-04-12 23:39:11 +00:00
R_InterpolateMobjState ( thing , rendertimefrac , & interp ) ;
}
else
{
R_InterpolateMobjState ( thing , FRACUNIT , & interp ) ;
2022-04-11 03:29:52 +00:00
}
2023-08-25 08:42:12 +00:00
halfHeight = interp . z + ( interp . height > > 1 ) ;
2022-04-26 00:14:53 +00:00
floorz = P_GetFloorZ ( thing , interp . subsector - > sector , interp . x , interp . y , NULL ) ;
ceilingz = P_GetCeilingZ ( thing , interp . subsector - > sector , interp . x , interp . y , NULL ) ;
2021-12-25 07:07:56 +00:00
# define CHECKZ (isflipped ? z > halfHeight && z < groundz : z < halfHeight && z > groundz)
2019-12-30 02:19:27 +00:00
2020-01-09 05:19:52 +00:00
for ( node = thing - > touching_sectorlist ; node ; node = node - > m_sectorlist_next )
2019-12-27 21:31:20 +00:00
{
2020-01-09 05:19:52 +00:00
sector = node - > m_sector ;
2020-05-30 17:21:26 +00:00
slope = sector - > heightsec ! = - 1 ? NULL : ( isflipped ? sector - > c_slope : sector - > f_slope ) ;
2020-03-22 14:17:16 +00:00
if ( sector - > heightsec ! = - 1 )
2020-05-30 17:21:26 +00:00
z = isflipped ? sectors [ sector - > heightsec ] . ceilingheight : sectors [ sector - > heightsec ] . floorheight ;
2020-03-22 14:17:16 +00:00
else
2022-04-12 23:39:11 +00:00
z = isflipped ? P_GetSectorCeilingZAt ( sector , interp . x , interp . y ) : P_GetSectorFloorZAt ( sector , interp . x , interp . y ) ;
2019-12-27 21:31:20 +00:00
2020-05-30 17:21:26 +00:00
if CHECKZ
2019-12-27 21:31:20 +00:00
{
2020-05-30 17:21:26 +00:00
groundz = z ;
groundslope = slope ;
2020-01-09 05:19:52 +00:00
}
2019-12-30 02:19:27 +00:00
2020-01-09 05:19:52 +00:00
if ( sector - > ffloors )
for ( rover = sector - > ffloors ; rover ; rover = rover - > next )
2019-12-30 02:19:27 +00:00
{
2022-07-31 10:04:42 +00:00
if ( ! ( rover - > fofflags & FOF_EXISTS ) | | ! ( rover - > fofflags & FOF_RENDERPLANES ) | | ( rover - > alpha < 90 & & ! ( rover - > fofflags & FOF_SWIMMABLE ) ) )
2019-12-30 02:19:27 +00:00
continue ;
2019-12-27 21:31:20 +00:00
2022-04-12 23:39:11 +00:00
z = isflipped ? P_GetFFloorBottomZAt ( rover , interp . x , interp . y ) : P_GetFFloorTopZAt ( rover , interp . x , interp . y ) ;
2020-05-30 17:21:26 +00:00
if CHECKZ
2019-12-30 02:19:27 +00:00
{
2020-05-30 17:21:26 +00:00
groundz = z ;
groundslope = isflipped ? * rover - > b_slope : * rover - > t_slope ;
2019-12-30 02:19:27 +00:00
}
}
2020-01-09 05:19:52 +00:00
}
2019-12-30 02:19:27 +00:00
2022-04-26 00:14:53 +00:00
// Check polyobjects and see if groundz needs to be altered
2020-01-09 05:19:52 +00:00
{
2022-04-26 00:14:53 +00:00
// This isn't very precise, but the precise method was far too slow.
// (Polies are just naturally pretty flickery anyway :P)
polyobj_t * po = interp . subsector - > polyList ;
2020-01-09 05:19:52 +00:00
2022-04-26 00:14:53 +00:00
while ( po )
{
if ( ! ( po - > flags & POF_RENDERPLANES ) | | ! P_MobjInsidePolyobj ( po , thing ) )
2019-12-30 02:19:27 +00:00
{
2022-04-26 00:14:53 +00:00
po = ( polyobj_t * ) ( po - > link . next ) ;
continue ;
}
2020-01-09 05:19:52 +00:00
2022-04-26 00:14:53 +00:00
// We're inside it! Yess...
z = isflipped ? po - > lines [ 0 ] - > backsector - > floorheight : po - > lines [ 0 ] - > backsector - > ceilingheight ;
if CHECKZ
{
groundz = z ;
groundslope = NULL ;
}
2020-01-09 05:19:52 +00:00
2022-04-26 00:14:53 +00:00
po = ( polyobj_t * ) ( po - > link . next ) ;
}
}
2020-01-09 05:19:52 +00:00
2023-08-25 08:42:12 +00:00
if ( isflipped ? ( ceilingz < groundz - ( ! groundslope ? 0 : FixedMul ( abs ( groundslope - > zdelta ) , interp . radius * 3 / 2 ) ) )
: ( floorz > groundz + ( ! groundslope ? 0 : FixedMul ( abs ( groundslope - > zdelta ) , interp . radius * 3 / 2 ) ) ) )
2022-04-26 00:14:53 +00:00
{
groundz = isflipped ? ceilingz : floorz ;
groundslope = NULL ;
2019-12-27 21:31:20 +00:00
}
2020-01-09 05:19:52 +00:00
if ( shadowslope ! = NULL )
2020-05-30 17:21:26 +00:00
* shadowslope = groundslope ;
2020-01-09 05:19:52 +00:00
2020-05-30 17:21:26 +00:00
return groundz ;
2020-05-30 17:26:23 +00:00
# undef CHECKZ
2020-01-09 05:19:52 +00:00
}
2020-10-12 03:13:22 +00:00
static void R_SkewShadowSprite (
mobj_t * thing , pslope_t * groundslope ,
fixed_t groundz , INT32 spriteheight , fixed_t scalemul ,
fixed_t * shadowyscale , fixed_t * shadowskew )
{
2022-04-11 03:29:52 +00:00
2020-10-12 03:13:22 +00:00
// haha let's try some dumb stuff
fixed_t xslope , zslope ;
2022-04-11 03:29:52 +00:00
angle_t sloperelang ;
// for frame interpolation
2022-04-12 23:39:11 +00:00
interpmobjstate_t interp = { 0 } ;
2022-04-11 03:29:52 +00:00
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2022-04-11 03:29:52 +00:00
{
2022-04-12 23:39:11 +00:00
R_InterpolateMobjState ( thing , rendertimefrac , & interp ) ;
2022-04-11 03:29:52 +00:00
}
2022-04-12 23:39:11 +00:00
else
{
R_InterpolateMobjState ( thing , FRACUNIT , & interp ) ;
}
sloperelang = ( R_PointToAngle ( interp . x , interp . y ) - groundslope - > xydirection ) > > ANGLETOFINESHIFT ;
2020-10-12 03:13:22 +00:00
xslope = FixedMul ( FINESINE ( sloperelang ) , groundslope - > zdelta ) ;
zslope = FixedMul ( FINECOSINE ( sloperelang ) , groundslope - > zdelta ) ;
//CONS_Printf("Shadow is sloped by %d %d\n", xslope, zslope);
if ( viewz < groundz )
2023-08-25 08:42:12 +00:00
* shadowyscale + = FixedMul ( FixedMul ( interp . radius * 2 / spriteheight , scalemul ) , zslope ) ;
2020-10-12 03:13:22 +00:00
else
2023-08-25 08:42:12 +00:00
* shadowyscale - = FixedMul ( FixedMul ( interp . radius * 2 / spriteheight , scalemul ) , zslope ) ;
2020-10-12 03:13:22 +00:00
* shadowyscale = abs ( ( * shadowyscale ) ) ;
* shadowskew = xslope ;
}
2020-01-09 05:24:31 +00:00
static void R_ProjectDropShadow ( mobj_t * thing , vissprite_t * vis , fixed_t scale , fixed_t tx , fixed_t tz )
2020-01-09 05:19:52 +00:00
{
vissprite_t * shadow ;
patch_t * patch ;
fixed_t xscale , yscale , shadowxscale , shadowyscale , shadowskew , x1 , x2 ;
2022-03-21 22:40:24 +00:00
INT32 heightsec , phs ;
2023-08-04 03:31:51 +00:00
fixed_t scalemul ;
UINT8 trans ;
2020-01-09 05:19:52 +00:00
fixed_t floordiff ;
2020-05-30 17:21:26 +00:00
fixed_t groundz ;
pslope_t * groundslope ;
boolean isflipped = thing - > eflags & MFE_VERTICALFLIP ;
2022-04-12 23:39:11 +00:00
interpmobjstate_t interp = { 0 } ;
2019-12-27 21:31:20 +00:00
2020-05-30 17:21:26 +00:00
groundz = R_GetShadowZ ( thing , & groundslope ) ;
2019-12-30 02:19:27 +00:00
2020-05-30 17:21:26 +00:00
if ( abs ( groundz - viewz ) / tz > 4 ) return ; // Prevent stretchy shadows and possible crashes
2019-12-30 00:30:29 +00:00
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2022-04-12 23:39:11 +00:00
{
R_InterpolateMobjState ( thing , rendertimefrac , & interp ) ;
}
else
{
R_InterpolateMobjState ( thing , FRACUNIT , & interp ) ;
}
2022-03-21 22:40:24 +00:00
heightsec = thing - > subsector - > sector - > heightsec ;
if ( viewplayer - > mo & & viewplayer - > mo - > subsector )
phs = viewplayer - > mo - > subsector - > sector - > heightsec ;
else
phs = - 1 ;
if ( heightsec ! = - 1 & & phs ! = - 1 ) // only clip things which are in special sectors
{
if ( viewz < sectors [ phs ] . floorheight ?
groundz > = sectors [ heightsec ] . floorheight :
groundz < sectors [ heightsec ] . floorheight )
return ;
if ( viewz > sectors [ phs ] . ceilingheight ?
groundz < sectors [ heightsec ] . ceilingheight & & viewz > = sectors [ heightsec ] . ceilingheight :
groundz > = sectors [ heightsec ] . ceilingheight )
return ;
}
2023-08-25 08:42:12 +00:00
floordiff = abs ( ( isflipped ? interp . height : 0 ) + interp . z - groundz ) ;
2019-12-27 21:31:20 +00:00
trans = floordiff / ( 100 * FRACUNIT ) + 3 ;
if ( trans > = 9 ) return ;
2020-01-09 05:24:31 +00:00
scalemul = FixedMul ( FRACUNIT - floordiff / 640 , scale ) ;
2019-12-30 02:53:28 +00:00
2020-09-07 05:23:07 +00:00
patch = W_CachePatchName ( " DSHADOW " , PU_SPRITE ) ;
2019-12-27 21:31:20 +00:00
xscale = FixedDiv ( projection , tz ) ;
yscale = FixedDiv ( projectiony , tz ) ;
2023-08-25 08:42:12 +00:00
shadowxscale = FixedMul ( interp . radius * 2 , scalemul ) ;
shadowyscale = FixedMul ( FixedMul ( interp . radius * 2 , scalemul ) , FixedDiv ( abs ( groundz - viewz ) , tz ) ) ;
2020-10-12 03:13:22 +00:00
shadowyscale = min ( shadowyscale , shadowxscale ) / patch - > height ;
shadowxscale / = patch - > width ;
2019-12-30 02:19:27 +00:00
shadowskew = 0 ;
2020-05-30 17:21:26 +00:00
if ( groundslope )
2020-10-12 03:13:22 +00:00
R_SkewShadowSprite ( thing , groundslope , groundz , patch - > height , scalemul , & shadowyscale , & shadowskew ) ;
2019-12-30 02:19:27 +00:00
2020-10-12 03:13:22 +00:00
tx - = patch - > width * shadowxscale / 2 ;
2019-12-27 21:31:20 +00:00
x1 = ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ;
if ( x1 > = viewwidth ) return ;
2020-10-12 03:13:22 +00:00
tx + = patch - > width * shadowxscale ;
2019-12-27 21:31:20 +00:00
x2 = ( ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ) ; x2 - - ;
if ( x2 < 0 | | x2 < = x1 ) return ;
2020-10-12 03:13:22 +00:00
if ( shadowyscale < FRACUNIT / patch - > height ) return ; // fix some crashes?
2019-12-27 21:31:20 +00:00
shadow = R_NewVisSprite ( ) ;
shadow - > patch = patch ;
shadow - > heightsec = vis - > heightsec ;
2020-12-23 03:02:31 +00:00
shadow - > thingheight = FRACUNIT ;
shadow - > pz = groundz + ( isflipped ? - shadow - > thingheight : 0 ) ;
shadow - > pzt = shadow - > pz + shadow - > thingheight ;
2019-12-27 21:31:20 +00:00
shadow - > mobjflags = 0 ;
shadow - > sortscale = vis - > sortscale ;
shadow - > dispoffset = vis - > dispoffset - 5 ;
2022-04-12 23:39:11 +00:00
shadow - > gx = interp . x ;
shadow - > gy = interp . y ;
2020-12-23 03:02:31 +00:00
shadow - > gzt = ( isflipped ? shadow - > pzt : shadow - > pz ) + patch - > height * shadowyscale / 2 ;
2020-10-12 03:13:22 +00:00
shadow - > gz = shadow - > gzt - patch - > height * shadowyscale ;
2022-04-29 01:14:04 +00:00
shadow - > texturemid = FixedMul ( interp . scale , FixedDiv ( shadow - > gzt - viewz , shadowyscale ) ) ;
2020-01-09 05:33:43 +00:00
if ( thing - > skin & & ( ( skin_t * ) thing - > skin ) - > flags & SF_HIRES )
shadow - > texturemid = FixedMul ( shadow - > texturemid , ( ( skin_t * ) thing - > skin ) - > highresscale ) ;
2019-12-27 21:31:20 +00:00
shadow - > scalestep = 0 ;
2020-01-09 03:52:10 +00:00
shadow - > shear . tan = shadowskew ; // repurposed variable
2019-12-27 21:31:20 +00:00
shadow - > mobj = thing ; // Easy access! Tails 06-07-2002
2021-07-06 08:36:05 +00:00
shadow - > color = thing - > color ;
2019-12-27 21:31:20 +00:00
2020-01-18 05:21:11 +00:00
shadow - > x1 = x1 < portalclipstart ? portalclipstart : x1 ;
shadow - > x2 = x2 > = portalclipend ? portalclipend - 1 : x2 ;
2019-12-30 04:15:01 +00:00
2019-12-27 21:31:20 +00:00
shadow - > xscale = FixedMul ( xscale , shadowxscale ) ; //SoM: 4/17/2000
shadow - > scale = FixedMul ( yscale , shadowyscale ) ;
2022-04-29 01:14:04 +00:00
shadow - > thingscale = interp . scale ;
2019-12-27 21:31:20 +00:00
shadow - > sector = vis - > sector ;
shadow - > szt = ( INT16 ) ( ( centeryfrac - FixedMul ( shadow - > gzt - viewz , yscale ) ) > > FRACBITS ) ;
shadow - > sz = ( INT16 ) ( ( centeryfrac - FixedMul ( shadow - > gz - viewz , yscale ) ) > > FRACBITS ) ;
2019-12-30 00:30:29 +00:00
shadow - > cut = SC_ISSCALED | SC_SHADOW ; //check this
2019-12-27 21:31:20 +00:00
shadow - > startfrac = 0 ;
2019-12-30 02:45:07 +00:00
//shadow->xiscale = 0x7ffffff0 / (shadow->xscale/2);
2020-10-12 03:13:22 +00:00
shadow - > xiscale = ( patch - > width < < FRACBITS ) / ( x2 - x1 + 1 ) ; // fuck it
2019-12-27 21:31:20 +00:00
if ( shadow - > x1 > x1 )
2019-12-30 01:19:26 +00:00
shadow - > startfrac + = shadow - > xiscale * ( shadow - > x1 - x1 ) ;
2019-12-27 21:31:20 +00:00
2019-12-30 02:19:27 +00:00
// reusing x1 variable
x1 + = ( x2 - x1 ) / 2 ;
2020-01-17 06:34:57 +00:00
shadow - > shear . offset = shadow - > x1 - x1 ;
2019-12-30 02:19:27 +00:00
2020-10-27 22:54:10 +00:00
if ( thing - > renderflags & RF_NOCOLORMAPS )
shadow - > extra_colormap = NULL ;
else
2023-08-04 03:31:51 +00:00
shadow - > extra_colormap = P_GetColormapFromSectorAt ( thing - > subsector - > sector , interp . x , interp . y , shadow - > gzt ) ;
2019-12-27 21:31:20 +00:00
2020-10-27 03:03:41 +00:00
shadow - > transmap = R_GetTranslucencyTable ( trans + 1 ) ;
2019-12-27 21:31:20 +00:00
shadow - > colormap = scalelight [ 0 ] [ 0 ] ; // full dark!
objectsdrawn + + ;
}
2022-09-11 04:27:37 +00:00
static void R_ProjectBoundingBox ( mobj_t * thing , vissprite_t * vis )
{
fixed_t gx , gy ;
fixed_t tx , tz ;
vissprite_t * box ;
if ( ! R_ThingBoundingBoxVisible ( thing ) )
{
return ;
}
2023-06-13 00:05:58 +00:00
// uncapped/interpolation
boolean interpolate = cv_renderhitboxinterpolation . value ;
interpmobjstate_t interp = { 0 } ;
// do interpolation
if ( R_UsingFrameInterpolation ( ) & & ! paused & & interpolate )
{
R_InterpolateMobjState ( thing , rendertimefrac , & interp ) ;
}
else
{
R_InterpolateMobjState ( thing , FRACUNIT , & interp ) ;
}
2022-09-11 04:27:37 +00:00
// 1--3
// | |
// 0--2
// start in the (0) corner
2023-08-25 08:42:12 +00:00
gx = interp . x - interp . radius - viewx ;
gy = interp . y - interp . radius - viewy ;
2022-09-11 04:27:37 +00:00
tz = FixedMul ( gx , viewcos ) + FixedMul ( gy , viewsin ) ;
// thing is behind view plane?
// if parent vis is visible, ignore this
2023-06-13 00:05:58 +00:00
if ( ! vis & & ( tz < FixedMul ( MINZ , interp . scale ) ) )
2022-09-11 04:27:37 +00:00
{
return ;
}
tx = FixedMul ( gx , viewsin ) - FixedMul ( gy , viewcos ) ;
// too far off the side?
if ( ! vis & & abs ( tx ) > FixedMul ( tz , fovtan ) < < 2 )
{
return ;
}
box = R_NewVisSprite ( ) ;
box - > mobj = thing ;
box - > mobjflags = thing - > flags ;
2023-08-25 08:42:12 +00:00
box - > thingheight = interp . height ;
2022-09-11 04:27:37 +00:00
box - > cut = SC_BBOX ;
box - > gx = tx ;
box - > gy = tz ;
2023-08-25 08:42:12 +00:00
box - > scale = 2 * FixedMul ( interp . radius , viewsin ) ;
box - > xscale = 2 * FixedMul ( interp . radius , viewcos ) ;
2022-09-11 04:27:37 +00:00
2023-06-13 00:05:58 +00:00
box - > pz = interp . z ;
2022-09-11 04:27:37 +00:00
box - > pzt = box - > pz + box - > thingheight ;
box - > gzt = box - > pzt ;
box - > gz = box - > pz ;
box - > texturemid = box - > gzt - viewz ;
if ( vis )
{
box - > x1 = vis - > x1 ;
box - > x2 = vis - > x2 ;
box - > szt = vis - > szt ;
box - > sz = vis - > sz ;
box - > sortscale = vis - > sortscale ; // link sorting to sprite
box - > dispoffset = vis - > dispoffset + 5 ;
box - > cut | = SC_LINKDRAW ;
}
else
{
fixed_t xscale = FixedDiv ( projection , tz ) ;
fixed_t yscale = FixedDiv ( projectiony , tz ) ;
fixed_t top = ( centeryfrac - FixedMul ( box - > texturemid , yscale ) ) ;
box - > x1 = ( centerxfrac + FixedMul ( box - > gx , xscale ) ) / FRACUNIT ;
box - > x2 = box - > x1 ;
box - > szt = top / FRACUNIT ;
box - > sz = ( top + FixedMul ( box - > thingheight , yscale ) ) / FRACUNIT ;
box - > sortscale = yscale ;
box - > dispoffset = 0 ;
}
}
2014-03-15 16:59:03 +00:00
//
// R_ProjectSprite
// Generates a vissprite for a thing
// if it might be visible.
//
static void R_ProjectSprite ( mobj_t * thing )
{
2017-06-25 19:46:30 +00:00
mobj_t * oldthing = thing ;
2014-03-15 16:59:03 +00:00
fixed_t tr_x , tr_y ;
fixed_t tx , tz ;
2020-10-13 05:24:18 +00:00
fixed_t xscale , yscale ; //added : 02-02-98 : aaargll..if I were a math-guy!!!
2023-08-25 08:42:12 +00:00
fixed_t radius , height ; // For drop shadows
2020-10-13 05:24:18 +00:00
fixed_t sortscale , sortsplat = 0 ;
2022-11-05 01:33:41 +00:00
fixed_t linkscale = 0 ;
2020-10-14 01:42:07 +00:00
fixed_t sort_x = 0 , sort_y = 0 , sort_z ;
2014-03-15 16:59:03 +00:00
INT32 x1 , x2 ;
spritedef_t * sprdef ;
spriteframe_t * sprframe ;
2019-11-13 15:36:44 +00:00
# ifdef ROTSPRITE
2019-09-29 15:13:51 +00:00
spriteinfo_t * sprinfo ;
2019-11-13 15:36:44 +00:00
# endif
2014-03-15 16:59:03 +00:00
size_t lump ;
2020-05-19 15:58:53 +00:00
size_t frame , rot ;
2020-01-08 20:49:14 +00:00
UINT16 flip ;
2020-10-12 03:13:22 +00:00
boolean vflip = ( ! ( thing - > eflags & MFE_VERTICALFLIP ) ! = ! R_ThingVerticallyFlipped ( thing ) ) ;
2020-06-07 20:11:36 +00:00
boolean mirrored = thing - > mirrored ;
2020-10-12 03:13:22 +00:00
boolean hflip = ( ! R_ThingHorizontallyFlipped ( thing ) ! = ! mirrored ) ;
2014-03-15 16:59:03 +00:00
INT32 lindex ;
2020-10-12 03:13:22 +00:00
INT32 trans ;
2014-03-15 16:59:03 +00:00
vissprite_t * vis ;
2020-10-12 03:13:22 +00:00
patch_t * patch ;
2014-03-15 16:59:03 +00:00
2017-06-25 19:46:30 +00:00
spritecut_e cut = SC_NONE ;
2016-09-16 16:09:33 +00:00
angle_t ang = 0 ; // compiler complaints
2014-03-15 16:59:03 +00:00
fixed_t iscale ;
2016-09-16 16:09:33 +00:00
fixed_t scalestep ;
2016-08-18 11:40:45 +00:00
fixed_t offset , offset2 ;
2019-12-27 10:57:16 +00:00
2020-10-12 03:13:22 +00:00
fixed_t sheartan = 0 ;
fixed_t shadowscale = FRACUNIT ;
2021-02-19 11:45:28 +00:00
fixed_t basetx , basetz ; // drop shadows
2019-12-27 21:31:20 +00:00
2020-10-12 03:13:22 +00:00
boolean shadowdraw , shadoweffects , shadowskew ;
boolean splat = R_ThingIsFloorSprite ( thing ) ;
boolean papersprite = ( R_ThingIsPaperSprite ( thing ) & & ! splat ) ;
fixed_t paperoffset = 0 , paperdistance = 0 ;
angle_t centerangle = 0 ;
2014-03-15 16:59:03 +00:00
2022-01-13 07:53:26 +00:00
INT32 dispoffset = thing - > dispoffset ;
2016-09-16 16:09:33 +00:00
2014-03-15 16:59:03 +00:00
//SoM: 3/17/2000
2020-10-13 03:14:27 +00:00
fixed_t gz = 0 , gzt = 0 ;
2014-03-15 16:59:03 +00:00
INT32 heightsec , phs ;
INT32 light = 0 ;
2022-04-28 02:39:47 +00:00
fixed_t this_scale ;
2020-10-12 03:13:22 +00:00
fixed_t spritexscale , spriteyscale ;
2014-03-15 16:59:03 +00:00
2019-08-18 17:16:48 +00:00
// rotsprite
fixed_t spr_width , spr_height ;
fixed_t spr_offset , spr_topoffset ;
2020-10-12 03:13:22 +00:00
2019-08-18 17:16:48 +00:00
# ifdef ROTSPRITE
patch_t * rotsprite = NULL ;
2019-12-27 00:27:30 +00:00
INT32 rollangle = 0 ;
2020-10-30 19:54:58 +00:00
angle_t spriterotangle = 0 ;
2019-08-18 17:16:48 +00:00
# endif
2019-10-06 22:40:52 +00:00
// uncapped/interpolation
2022-04-12 23:39:11 +00:00
interpmobjstate_t interp = { 0 } ;
2019-10-06 22:40:52 +00:00
// do interpolation
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2019-10-06 22:40:52 +00:00
{
2022-04-29 01:07:07 +00:00
R_InterpolateMobjState ( oldthing , rendertimefrac , & interp ) ;
2022-04-12 23:39:11 +00:00
}
else
{
2022-04-29 01:07:07 +00:00
R_InterpolateMobjState ( oldthing , FRACUNIT , & interp ) ;
2019-10-06 22:40:52 +00:00
}
2022-04-28 02:39:47 +00:00
this_scale = interp . scale ;
2023-08-25 08:42:12 +00:00
radius = interp . radius ; // For drop shadows
height = interp . height ; // Ditto
2022-04-28 02:39:47 +00:00
2014-03-15 16:59:03 +00:00
// transform the origin point
2023-05-29 14:37:48 +00:00
if ( thing - > type = = MT_OVERLAY ) // Handle overlays
R_ThingOffsetOverlay ( thing , & interp . x , & interp . y ) ;
2022-04-12 23:39:11 +00:00
tr_x = interp . x - viewx ;
tr_y = interp . y - viewy ;
2014-03-15 16:59:03 +00:00
2021-02-19 11:45:28 +00:00
basetz = tz = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ; // near/far distance
2014-03-15 16:59:03 +00:00
// thing is behind view plane?
2019-12-27 17:42:02 +00:00
if ( ! papersprite & & ( tz < FixedMul ( MINZ , this_scale ) ) ) // papersprite clipping is handled later
2014-03-15 16:59:03 +00:00
return ;
2020-05-19 15:48:50 +00:00
basetx = tx = FixedMul ( tr_x , viewsin ) - FixedMul ( tr_y , viewcos ) ; // sideways distance
2014-03-15 16:59:03 +00:00
// too far off the side?
2020-05-19 17:54:39 +00:00
if ( ! papersprite & & abs ( tx ) > FixedMul ( tz , fovtan ) < < 2 ) // papersprite clipping is handled later
2014-03-15 16:59:03 +00:00
return ;
// aspect ratio stuff
xscale = FixedDiv ( projection , tz ) ;
2016-08-19 14:06:10 +00:00
sortscale = FixedDiv ( projectiony , tz ) ;
2014-03-15 16:59:03 +00:00
// decide which patch to use for sprite relative to player
# ifdef RANGECHECK
if ( ( size_t ) ( thing - > sprite ) > = numsprites )
I_Error ( " R_ProjectSprite: invalid sprite number %d " , thing - > sprite ) ;
# endif
2020-05-19 15:58:53 +00:00
frame = thing - > frame & FF_FRAMEMASK ;
2014-03-15 16:59:03 +00:00
//Fab : 02-08-98: 'skin' override spritedef currently used for skin
if ( thing - > skin & & thing - > sprite = = SPR_PLAY )
{
2015-01-22 15:23:45 +00:00
sprdef = & ( ( skin_t * ) thing - > skin ) - > sprites [ thing - > sprite2 ] ;
2019-11-13 15:36:44 +00:00
# ifdef ROTSPRITE
2019-09-29 15:13:51 +00:00
sprinfo = & ( ( skin_t * ) thing - > skin ) - > sprinfo [ thing - > sprite2 ] ;
2019-11-13 15:36:44 +00:00
# endif
2020-05-19 15:58:53 +00:00
if ( frame > = sprdef - > numframes ) {
CONS_Alert ( CONS_ERROR , M_GetText ( " R_ProjectSprite: invalid skins[ \" %s \" ].sprites[%sSPR2_%s] frame %s \n " ) , ( ( skin_t * ) thing - > skin ) - > name , ( ( thing - > sprite2 & FF_SPR2SUPER ) ? " FF_SPR2SUPER| " : " " ) , spr2names [ ( thing - > sprite2 & ~ FF_SPR2SUPER ) ] , sizeu5 ( frame ) ) ;
2015-01-22 15:23:45 +00:00
thing - > sprite = states [ S_UNKNOWN ] . sprite ;
thing - > frame = states [ S_UNKNOWN ] . frame ;
2014-03-15 16:59:03 +00:00
sprdef = & sprites [ thing - > sprite ] ;
2019-11-13 15:36:44 +00:00
# ifdef ROTSPRITE
2020-10-10 21:43:26 +00:00
sprinfo = & spriteinfo [ thing - > sprite ] ;
2019-11-13 15:36:44 +00:00
# endif
2020-05-19 15:58:53 +00:00
frame = thing - > frame & FF_FRAMEMASK ;
2015-01-22 15:23:45 +00:00
}
2014-03-15 16:59:03 +00:00
}
else
2019-09-29 15:13:51 +00:00
{
2014-03-15 16:59:03 +00:00
sprdef = & sprites [ thing - > sprite ] ;
2019-11-13 15:36:44 +00:00
# ifdef ROTSPRITE
2020-10-10 21:43:26 +00:00
sprinfo = & spriteinfo [ thing - > sprite ] ;
2019-11-13 15:36:44 +00:00
# endif
2014-03-15 16:59:03 +00:00
2020-05-19 15:58:53 +00:00
if ( frame > = sprdef - > numframes )
2014-03-15 16:59:03 +00:00
{
2019-11-15 12:47:21 +00:00
CONS_Alert ( CONS_ERROR , M_GetText ( " R_ProjectSprite: invalid sprite frame %s/%s for %s \n " ) ,
2020-05-19 15:58:53 +00:00
sizeu1 ( frame ) , sizeu2 ( sprdef - > numframes ) , sprnames [ thing - > sprite ] ) ;
2019-11-15 12:47:21 +00:00
if ( thing - > sprite = = thing - > state - > sprite & & thing - > frame = = thing - > state - > frame )
{
thing - > state - > sprite = states [ S_UNKNOWN ] . sprite ;
thing - > state - > frame = states [ S_UNKNOWN ] . frame ;
}
thing - > sprite = states [ S_UNKNOWN ] . sprite ;
thing - > frame = states [ S_UNKNOWN ] . frame ;
sprdef = & sprites [ thing - > sprite ] ;
2020-10-10 21:43:26 +00:00
sprinfo = & spriteinfo [ thing - > sprite ] ;
2020-05-19 15:58:53 +00:00
frame = thing - > frame & FF_FRAMEMASK ;
2014-03-15 16:59:03 +00:00
}
}
2020-05-19 15:58:53 +00:00
sprframe = & sprdef - > spriteframes [ frame ] ;
2014-03-15 16:59:03 +00:00
# ifdef PARANOIA
if ( ! sprframe )
I_Error ( " R_ProjectSprite: sprframes NULL for sprite %d \n " , thing - > sprite ) ;
# endif
2022-11-01 02:03:09 +00:00
if ( splat )
{
ang = R_PointToAngle2 ( 0 , viewz , 0 , interp . z ) ;
}
else if ( sprframe - > rotate ! = SRF_SINGLE | | papersprite )
2020-06-07 20:11:36 +00:00
{
2022-04-12 23:39:11 +00:00
ang = R_PointToAngle ( interp . x , interp . y ) - interp . angle ;
2020-06-07 20:11:36 +00:00
if ( mirrored )
ang = InvAngle ( ang ) ;
}
2016-08-15 19:54:05 +00:00
2016-07-18 23:04:00 +00:00
if ( sprframe - > rotate = = SRF_SINGLE )
2014-03-15 16:59:03 +00:00
{
// use single rotation for all views
rot = 0 ; //Fab: for vis->patch below
lump = sprframe - > lumpid [ 0 ] ; //Fab: see note above
2020-01-08 20:49:14 +00:00
flip = sprframe - > flip ; // Will only be 0 or 0xFFFF
2014-03-15 16:59:03 +00:00
}
2016-07-18 23:04:00 +00:00
else
{
// choose a different rotation based on player view
2022-04-12 23:39:11 +00:00
//ang = R_PointToAngle (interp.x, interp.y) - interpangle;
2016-07-18 23:04:00 +00:00
2016-08-06 23:21:16 +00:00
if ( ( sprframe - > rotate & SRF_RIGHT ) & & ( ang < ANGLE_180 ) ) // See from right
2016-07-18 23:04:00 +00:00
rot = 6 ; // F7 slot
2016-08-06 23:21:16 +00:00
else if ( ( sprframe - > rotate & SRF_LEFT ) & & ( ang > = ANGLE_180 ) ) // See from left
2016-07-18 23:04:00 +00:00
rot = 2 ; // F3 slot
2020-01-08 20:49:14 +00:00
else if ( sprframe - > rotate & SRF_3DGE ) // 16-angle mode
{
rot = ( ang + ANGLE_180 + ANGLE_11hh ) > > 28 ;
rot = ( ( rot & 1 ) < < 3 ) | ( rot > > 1 ) ;
}
2016-07-18 23:04:00 +00:00
else // Normal behaviour
rot = ( ang + ANGLE_202h ) > > 29 ;
//Fab: lumpid is the index for spritewidth,spriteoffset... tables
lump = sprframe - > lumpid [ rot ] ;
flip = sprframe - > flip & ( 1 < < rot ) ;
}
2014-03-15 16:59:03 +00:00
I_Assert ( lump < max_spritelumps ) ;
2019-08-18 17:16:48 +00:00
spr_width = spritecachedinfo [ lump ] . width ;
spr_height = spritecachedinfo [ lump ] . height ;
spr_offset = spritecachedinfo [ lump ] . offset ;
spr_topoffset = spritecachedinfo [ lump ] . topoffset ;
2020-10-12 03:13:22 +00:00
//Fab: lumppat is the lump number of the patch to use, this is different
// than lumpid for sprites-in-pwad : the graphics are patched
patch = W_CachePatchNum ( sprframe - > lumppat [ rot ] , PU_SPRITE ) ;
2019-08-18 17:16:48 +00:00
# ifdef ROTSPRITE
2020-10-30 19:54:58 +00:00
spriterotangle = R_SpriteRotationAngle ( & interp ) ;
if ( spriterotangle ! = 0
2020-10-12 03:13:22 +00:00
& & ! ( splat & & ! ( thing - > renderflags & RF_NOSPLATROLLANGLE ) ) )
2019-08-18 17:16:48 +00:00
{
2022-03-22 09:53:21 +00:00
if ( papersprite & & ang > = ANGLE_180 )
{
// Makes Software act much more sane like OpenGL
2020-10-30 19:54:58 +00:00
rollangle = R_GetRollAngle ( InvAngle ( spriterotangle ) ) ;
2022-03-22 09:53:21 +00:00
}
else
{
2020-10-30 19:54:58 +00:00
rollangle = R_GetRollAngle ( spriterotangle ) ;
2022-03-22 09:53:21 +00:00
}
2023-09-21 14:50:30 +00:00
rotsprite = Patch_GetRotatedSprite ( sprframe , ( thing - > frame & FF_FRAMEMASK ) , rot , flip , sprinfo , rollangle ) ;
2020-10-12 03:13:22 +00:00
2019-08-18 17:16:48 +00:00
if ( rotsprite ! = NULL )
{
2020-10-12 03:13:22 +00:00
patch = rotsprite ;
cut | = SC_ISROTATED ;
spr_width = rotsprite - > width < < FRACBITS ;
spr_height = rotsprite - > height < < FRACBITS ;
spr_offset = rotsprite - > leftoffset < < FRACBITS ;
spr_topoffset = rotsprite - > topoffset < < FRACBITS ;
spr_topoffset + = FEETADJUST ;
2019-08-18 17:16:48 +00:00
// flip -> rotate, not rotate -> flip
flip = 0 ;
}
}
# endif
2020-06-07 20:11:36 +00:00
flip = ! flip ! = ! hflip ;
2014-03-15 16:59:03 +00:00
// calculate edges of the shape
2022-04-29 19:21:30 +00:00
spritexscale = interp . spritexscale ;
spriteyscale = interp . spriteyscale ;
2023-09-03 21:59:39 +00:00
if ( thing - > skin & & ( ( skin_t * ) thing - > skin ) - > flags & SF_HIRES )
{
fixed_t highresscale = ( ( skin_t * ) thing - > skin ) - > highresscale ;
spritexscale = FixedMul ( spritexscale , highresscale ) ;
spriteyscale = FixedMul ( spriteyscale , highresscale ) ;
}
2020-10-12 03:13:22 +00:00
if ( spritexscale < 1 | | spriteyscale < 1 )
return ;
2020-10-13 15:57:36 +00:00
if ( thing - > renderflags & RF_ABSOLUTEOFFSETS )
{
2022-04-29 19:21:30 +00:00
spr_offset = interp . spritexoffset ;
spr_topoffset = interp . spriteyoffset ;
2020-10-13 15:57:36 +00:00
}
else
{
SINT8 flipoffset = 1 ;
if ( ( thing - > renderflags & RF_FLIPOFFSETS ) & & flip )
flipoffset = - 1 ;
2022-04-29 19:21:30 +00:00
spr_offset + = interp . spritexoffset * flipoffset ;
spr_topoffset + = interp . spriteyoffset * flipoffset ;
2020-10-13 15:57:36 +00:00
}
2014-03-15 16:59:03 +00:00
if ( flip )
2019-08-18 17:16:48 +00:00
offset = spr_offset - spr_width ;
2014-03-15 16:59:03 +00:00
else
2019-08-18 17:16:48 +00:00
offset = - spr_offset ;
2020-10-12 03:13:22 +00:00
offset = FixedMul ( offset , FixedMul ( spritexscale , this_scale ) ) ;
offset2 = FixedMul ( spr_width , FixedMul ( spritexscale , this_scale ) ) ;
2014-03-15 16:59:03 +00:00
2016-08-20 14:15:48 +00:00
if ( papersprite )
2016-08-16 22:17:45 +00:00
{
2019-12-27 17:42:02 +00:00
fixed_t xscale2 , yscale2 , cosmul , sinmul , tx2 , tz2 ;
2016-08-16 22:17:45 +00:00
INT32 range ;
2016-08-18 11:40:45 +00:00
if ( ang > = ANGLE_180 )
{
offset * = - 1 ;
offset2 * = - 1 ;
}
2022-04-25 22:15:59 +00:00
cosmul = FINECOSINE ( interp . angle > > ANGLETOFINESHIFT ) ;
sinmul = FINESINE ( interp . angle > > ANGLETOFINESHIFT ) ;
2016-08-18 11:55:04 +00:00
tr_x + = FixedMul ( offset , cosmul ) ;
tr_y + = FixedMul ( offset , sinmul ) ;
2020-05-19 15:48:50 +00:00
tz = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ;
2016-08-16 22:17:45 +00:00
2020-05-19 15:48:50 +00:00
tx = FixedMul ( tr_x , viewsin ) - FixedMul ( tr_y , viewcos ) ;
2019-11-24 16:42:13 +00:00
2019-12-27 10:57:16 +00:00
// Get paperoffset (offset) and paperoffset (distance)
paperoffset = - FixedMul ( tr_x , cosmul ) - FixedMul ( tr_y , sinmul ) ;
paperdistance = - FixedMul ( tr_x , sinmul ) + FixedMul ( tr_y , cosmul ) ;
if ( paperdistance < 0 )
{
paperoffset = - paperoffset ;
paperdistance = - paperdistance ;
}
2022-04-25 22:15:59 +00:00
centerangle = viewangle - interp . angle ;
2019-11-24 16:42:13 +00:00
2016-08-18 11:55:04 +00:00
tr_x + = FixedMul ( offset2 , cosmul ) ;
tr_y + = FixedMul ( offset2 , sinmul ) ;
2020-05-19 15:48:50 +00:00
tz2 = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ;
2016-08-16 22:17:45 +00:00
2020-05-19 15:48:50 +00:00
tx2 = FixedMul ( tr_x , viewsin ) - FixedMul ( tr_y , viewcos ) ;
2019-12-27 17:42:02 +00:00
if ( max ( tz , tz2 ) < FixedMul ( MINZ , this_scale ) ) // non-papersprite clipping is handled earlier
return ;
// Needs partially clipped
if ( tz < FixedMul ( MINZ , this_scale ) )
{
fixed_t div = FixedDiv ( tz2 - tz , FixedMul ( MINZ , this_scale ) - tz ) ;
tx + = FixedDiv ( tx2 - tx , div ) ;
tz = FixedMul ( MINZ , this_scale ) ;
}
else if ( tz2 < FixedMul ( MINZ , this_scale ) )
{
fixed_t div = FixedDiv ( tz - tz2 , FixedMul ( MINZ , this_scale ) - tz2 ) ;
tx2 + = FixedDiv ( tx - tx2 , div ) ;
tz2 = FixedMul ( MINZ , this_scale ) ;
}
2020-05-19 17:54:39 +00:00
if ( tx2 < - ( FixedMul ( tz2 , fovtan ) < < 2 ) | | tx > FixedMul ( tz , fovtan ) < < 2 ) // too far off the side?
2020-05-19 17:43:33 +00:00
return ;
2020-05-19 21:00:34 +00:00
yscale = FixedDiv ( projectiony , tz ) ;
xscale = FixedDiv ( projection , tz ) ;
2020-05-19 16:19:44 +00:00
2020-05-19 16:23:22 +00:00
x1 = ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ;
2019-12-27 17:42:02 +00:00
// off the right side?
if ( x1 > viewwidth )
return ;
2019-11-24 16:42:13 +00:00
2020-05-19 21:00:34 +00:00
yscale2 = FixedDiv ( projectiony , tz2 ) ;
xscale2 = FixedDiv ( projection , tz2 ) ;
2020-05-19 16:23:22 +00:00
x2 = ( centerxfrac + FixedMul ( tx2 , xscale2 ) ) > > FRACBITS ;
2019-11-24 16:42:13 +00:00
// off the left side
if ( x2 < 0 )
return ;
2016-08-20 11:18:00 +00:00
2019-11-24 16:42:13 +00:00
if ( ( range = x2 - x1 ) < = 0 )
2019-12-01 13:21:41 +00:00
return ;
2016-08-18 11:40:45 +00:00
2019-12-05 09:28:28 +00:00
range + + ; // fencepost problem
2023-01-01 00:35:07 +00:00
// Compatibility with MSVC - SSNTails
scalestep = ( ( yscale2 - yscale ) / range ) ;
if ( ! scalestep )
scalestep = 1 ;
2019-12-27 10:57:16 +00:00
xscale = FixedDiv ( range < < FRACBITS , abs ( offset2 ) ) ;
2016-08-19 11:26:26 +00:00
2016-08-20 11:18:00 +00:00
// The following two are alternate sorting methods which might be more applicable in some circumstances. TODO - maybe enable via MF2?
// sortscale = max(yscale, yscale2);
// sortscale = min(yscale, yscale2);
2016-08-16 22:17:45 +00:00
}
2016-08-18 11:40:45 +00:00
else
2016-08-18 14:45:44 +00:00
{
2016-08-18 11:40:45 +00:00
scalestep = 0 ;
2016-08-19 14:06:10 +00:00
yscale = sortscale ;
2019-11-24 16:42:13 +00:00
tx + = offset ;
x1 = ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ;
2016-08-15 19:54:05 +00:00
2019-11-24 16:42:13 +00:00
// off the right side?
if ( x1 > viewwidth )
return ;
tx + = offset2 ;
x2 = ( ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ) ; x2 - - ;
// off the left side
if ( x2 < 0 )
return ;
}
2016-08-15 19:54:05 +00:00
2020-10-13 05:24:18 +00:00
// Adjust the sort scale if needed
2020-10-13 04:45:18 +00:00
if ( splat )
{
2020-10-14 01:42:07 +00:00
sort_z = ( patch - > height - patch - > topoffset ) * FRACUNIT ;
2020-10-13 04:45:18 +00:00
ang = ( viewangle > > ANGLETOFINESHIFT ) ;
2020-10-14 01:42:07 +00:00
sort_x = FixedMul ( FixedMul ( FixedMul ( spritexscale , this_scale ) , sort_z ) , FINECOSINE ( ang ) ) ;
sort_y = FixedMul ( FixedMul ( FixedMul ( spriteyscale , this_scale ) , sort_z ) , FINESINE ( ang ) ) ;
2022-11-01 21:56:52 +00:00
tr_x = ( interp . x + sort_x ) - viewx ;
tr_y = ( interp . y + sort_y ) - viewy ;
sort_z = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ;
sortscale = FixedDiv ( projectiony , sort_z ) ;
2020-10-13 04:45:18 +00:00
}
2016-09-16 16:09:33 +00:00
if ( ( thing - > flags2 & MF2_LINKDRAW ) & & thing - > tracer ) // toast 16/09/16 (SYMMETRY)
{
2022-04-28 02:07:17 +00:00
interpmobjstate_t tracer_interp = { 0 } ;
2016-09-16 16:09:33 +00:00
2017-06-25 19:46:30 +00:00
thing = thing - > tracer ;
2016-09-16 16:09:33 +00:00
2020-01-18 04:56:32 +00:00
if ( ! R_ThingVisible ( thing ) )
2017-06-26 13:44:10 +00:00
return ;
2016-09-16 16:09:33 +00:00
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2019-10-06 22:40:52 +00:00
{
2022-04-28 02:07:17 +00:00
R_InterpolateMobjState ( thing , rendertimefrac , & tracer_interp ) ;
2022-04-12 23:39:11 +00:00
}
else
{
2022-04-28 02:07:17 +00:00
R_InterpolateMobjState ( thing , FRACUNIT , & tracer_interp ) ;
2019-10-06 22:40:52 +00:00
}
2023-08-25 08:42:12 +00:00
radius = tracer_interp . radius ; // For drop shadows
height = tracer_interp . height ; // Ditto
2016-09-16 16:09:33 +00:00
2023-05-29 14:37:48 +00:00
if ( thing - > type = = MT_OVERLAY ) // Handle overlays
R_ThingOffsetOverlay ( thing , & tracer_interp . x , & tracer_interp . y ) ;
2022-04-28 02:07:17 +00:00
tr_x = ( tracer_interp . x + sort_x ) - viewx ;
tr_y = ( tracer_interp . y + sort_y ) - viewy ;
2020-05-19 15:48:50 +00:00
tz = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ;
2016-09-16 16:09:33 +00:00
linkscale = FixedDiv ( projectiony , tz ) ;
if ( tz < FixedMul ( MINZ , this_scale ) )
return ;
if ( sortscale < linkscale )
dispoffset * = - 1 ; // if it's physically behind, make sure it's ordered behind (if dispoffset > 0)
2022-11-01 21:56:52 +00:00
//sortscale = linkscale; // now make sure it's linked
// No need to do that, linkdraw already excludes it from regular sorting.
2020-10-12 03:13:22 +00:00
cut | = SC_LINKDRAW ;
2016-09-16 16:09:33 +00:00
}
2022-11-05 01:33:41 +00:00
else
{
linkscale = sortscale ;
}
2016-09-16 16:09:33 +00:00
2020-10-13 05:24:18 +00:00
// Calculate the splat's sortscale
if ( splat )
{
2022-04-12 23:39:11 +00:00
tr_x = ( interp . x - sort_x ) - viewx ;
tr_y = ( interp . y - sort_y ) - viewy ;
2020-10-14 01:42:07 +00:00
sort_z = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ;
sortsplat = FixedDiv ( projectiony , sort_z ) ;
2022-11-01 02:01:44 +00:00
centerangle = interp . angle ;
2016-09-16 16:09:33 +00:00
}
2014-11-12 00:55:07 +00:00
// PORTAL SPRITE CLIPPING
2019-06-01 11:07:23 +00:00
if ( portalrender & & portalclipline )
2014-11-12 00:55:07 +00:00
{
2020-05-15 19:17:31 +00:00
if ( x2 < portalclipstart | | x1 > = portalclipend )
2014-11-12 00:55:07 +00:00
return ;
2022-04-12 23:39:11 +00:00
if ( P_PointOnLineSide ( interp . x , interp . y , portalclipline ) ! = 0 )
2014-11-12 00:55:07 +00:00
return ;
}
2021-11-15 18:07:20 +00:00
INT32 blendmode ;
if ( oldthing - > frame & FF_BLENDMASK )
blendmode = ( ( oldthing - > frame & FF_BLENDMASK ) > > FF_BLENDSHIFT ) + 1 ;
else
blendmode = oldthing - > blendmode ;
2020-10-12 03:13:22 +00:00
// Determine the translucency value.
if ( oldthing - > flags2 & MF2_SHADOW | | thing - > flags2 & MF2_SHADOW ) // actually only the player should use this (temporary invisibility)
trans = tr_trans80 ; // because now the translucency is set through FF_TRANSMASK
else if ( oldthing - > frame & FF_TRANSMASK )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
trans = ( oldthing - > frame & FF_TRANSMASK ) > > FF_TRANSSHIFT ;
2021-11-15 18:07:20 +00:00
if ( ! R_BlendLevelVisible ( blendmode , trans ) )
2020-10-27 20:02:35 +00:00
return ;
2014-03-15 16:59:03 +00:00
}
else
2020-10-12 03:13:22 +00:00
trans = 0 ;
// Check if this sprite needs to be rendered like a shadow
shadowdraw = ( ! ! ( thing - > renderflags & RF_SHADOWDRAW ) & & ! ( papersprite | | splat ) ) ;
shadoweffects = ( thing - > renderflags & RF_SHADOWEFFECTS ) ;
shadowskew = ( shadowdraw & & thing - > standingslope ) ;
if ( shadowdraw | | shadoweffects )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
fixed_t groundz = R_GetShadowZ ( thing , NULL ) ;
boolean isflipped = ( thing - > eflags & MFE_VERTICALFLIP ) ;
if ( shadoweffects )
{
mobj_t * caster = thing - > target ;
2023-01-01 00:35:07 +00:00
interpmobjstate_t casterinterp = { 0 } ; // MSVC compatibility - SSNTails
2022-04-29 01:14:04 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
{
R_InterpolateMobjState ( caster , rendertimefrac , & casterinterp ) ;
}
else
{
R_InterpolateMobjState ( caster , FRACUNIT , & casterinterp ) ;
}
2020-10-12 03:13:22 +00:00
if ( caster & & ! P_MobjWasRemoved ( caster ) )
{
fixed_t floordiff ;
if ( abs ( groundz - viewz ) / tz > 4 )
return ; // Prevent stretchy shadows and possible crashes
2023-08-25 08:42:12 +00:00
floordiff = abs ( ( isflipped ? casterinterp . height : 0 ) + casterinterp . z - groundz ) ;
2020-10-12 03:13:22 +00:00
trans + = ( ( floordiff / ( 100 * FRACUNIT ) ) + 3 ) ;
2022-04-29 01:14:04 +00:00
shadowscale = FixedMul ( FRACUNIT - floordiff / 640 , casterinterp . scale ) ;
2020-10-12 03:13:22 +00:00
}
else
trans + = 3 ;
2020-10-27 20:02:35 +00:00
if ( trans > = NUMTRANSMAPS )
2020-10-12 03:13:22 +00:00
return ;
trans - - ;
}
if ( shadowdraw )
{
2023-08-25 08:42:12 +00:00
spritexscale = FixedMul ( radius * 2 , FixedMul ( shadowscale , spritexscale ) ) ;
spriteyscale = FixedMul ( radius * 2 , FixedMul ( shadowscale , spriteyscale ) ) ;
2020-10-12 03:13:22 +00:00
spriteyscale = FixedMul ( spriteyscale , FixedDiv ( abs ( groundz - viewz ) , tz ) ) ;
spriteyscale = min ( spriteyscale , spritexscale ) / patch - > height ;
2020-10-12 22:53:21 +00:00
spritexscale / = patch - > width ;
2020-10-12 03:13:22 +00:00
}
else
2020-10-12 22:53:21 +00:00
{
spritexscale = FixedMul ( shadowscale , spritexscale ) ;
spriteyscale = FixedMul ( shadowscale , spriteyscale ) ;
}
2020-10-12 03:13:22 +00:00
if ( shadowskew )
{
R_SkewShadowSprite ( thing , thing - > standingslope , groundz , patch - > height , shadowscale , & spriteyscale , & sheartan ) ;
2023-08-25 08:42:12 +00:00
gzt = ( isflipped ? ( interp . z + height ) : interp . z ) + patch - > height * spriteyscale / 2 ;
2020-10-12 03:13:22 +00:00
gz = gzt - patch - > height * spriteyscale ;
cut | = SC_SHEAR ;
}
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
if ( ! shadowskew )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
//SoM: 3/17/2000: Disregard sprites that are out of view..
if ( vflip )
{
// 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.
// remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes!
2023-08-25 08:42:12 +00:00
gz = interp . z + interp . height - FixedMul ( spr_topoffset , FixedMul ( spriteyscale , this_scale ) ) ;
2020-10-12 03:13:22 +00:00
gzt = gz + FixedMul ( spr_height , FixedMul ( spriteyscale , this_scale ) ) ;
}
else
{
2022-04-12 23:39:11 +00:00
gzt = interp . z + FixedMul ( spr_topoffset , FixedMul ( spriteyscale , this_scale ) ) ;
2020-10-12 03:13:22 +00:00
gz = gzt - FixedMul ( spr_height , FixedMul ( spriteyscale , this_scale ) ) ;
}
2014-03-15 16:59:03 +00:00
}
if ( thing - > subsector - > sector - > cullheight )
{
2014-11-12 00:55:07 +00:00
if ( R_DoCulling ( thing - > subsector - > sector - > cullheight , viewsector - > cullheight , viewz , gz , gzt ) )
return ;
2014-03-15 16:59:03 +00:00
}
if ( thing - > subsector - > sector - > numlights )
{
2023-08-04 03:31:51 +00:00
light = P_GetSectorLightAt ( thing - > subsector - > sector , interp . x , interp . y , splat ? gz : gzt ) ;
2014-03-15 16:59:03 +00:00
2023-08-04 03:31:51 +00:00
INT32 lightnum = ( * thing - > subsector - > sector - > lightlist [ light ] . lightlevel > > LIGHTSEGSHIFT ) ;
2014-03-15 16:59:03 +00:00
if ( lightnum < 0 )
spritelights = scalelight [ 0 ] ;
else if ( lightnum > = LIGHTLEVELS )
spritelights = scalelight [ LIGHTLEVELS - 1 ] ;
else
spritelights = scalelight [ lightnum ] ;
}
heightsec = thing - > subsector - > sector - > heightsec ;
if ( viewplayer - > mo & & viewplayer - > mo - > subsector )
phs = viewplayer - > mo - > subsector - > sector - > heightsec ;
else
phs = - 1 ;
if ( heightsec ! = - 1 & & phs ! = - 1 ) // only clip things which are in special sectors
{
2022-03-21 22:40:24 +00:00
fixed_t top = gzt ;
2022-04-12 23:39:11 +00:00
fixed_t bottom = interp . z ;
2022-03-21 22:40:24 +00:00
if ( splat )
top = bottom ;
2014-03-15 16:59:03 +00:00
if ( viewz < sectors [ phs ] . floorheight ?
2022-03-21 22:40:24 +00:00
bottom > = sectors [ heightsec ] . floorheight :
top < sectors [ heightsec ] . floorheight )
2014-03-15 16:59:03 +00:00
return ;
if ( viewz > sectors [ phs ] . ceilingheight ?
2022-03-21 22:40:24 +00:00
top < sectors [ heightsec ] . ceilingheight & & viewz > = sectors [ heightsec ] . ceilingheight :
bottom > = sectors [ heightsec ] . ceilingheight )
2014-03-15 16:59:03 +00:00
return ;
}
// store information in a vissprite
vis = R_NewVisSprite ( ) ;
2020-10-12 03:13:22 +00:00
vis - > renderflags = thing - > renderflags ;
vis - > rotateflags = sprframe - > rotate ;
2014-03-15 16:59:03 +00:00
vis - > heightsec = heightsec ; //SoM: 3/17/2000
vis - > mobjflags = thing - > flags ;
2016-08-18 14:45:44 +00:00
vis - > sortscale = sortscale ;
2020-10-13 05:24:18 +00:00
vis - > sortsplat = sortsplat ;
2022-11-05 01:33:41 +00:00
vis - > linkscale = linkscale ;
2016-09-16 16:09:33 +00:00
vis - > dispoffset = dispoffset ; // Monster Iestyn: 23/11/15
2022-04-12 23:39:11 +00:00
vis - > gx = interp . x ;
vis - > gy = interp . y ;
2014-03-15 16:59:03 +00:00
vis - > gz = gz ;
vis - > gzt = gzt ;
2023-08-25 08:42:12 +00:00
vis - > thingheight = height ;
2022-04-12 23:39:11 +00:00
vis - > pz = interp . z ;
2020-12-23 03:02:31 +00:00
vis - > pzt = vis - > pz + vis - > thingheight ;
2020-10-12 03:13:22 +00:00
vis - > texturemid = FixedDiv ( gzt - viewz , spriteyscale ) ;
2016-08-15 19:54:05 +00:00
vis - > scalestep = scalestep ;
2019-12-27 10:57:16 +00:00
vis - > paperoffset = paperoffset ;
vis - > paperdistance = paperdistance ;
vis - > centerangle = centerangle ;
2020-10-12 03:13:22 +00:00
vis - > shear . tan = sheartan ;
2020-01-09 03:52:10 +00:00
vis - > shear . offset = 0 ;
2021-08-26 16:22:32 +00:00
vis - > viewpoint . x = viewx ;
vis - > viewpoint . y = viewy ;
vis - > viewpoint . z = viewz ;
vis - > viewpoint . angle = viewangle ;
2014-03-15 16:59:03 +00:00
vis - > mobj = thing ; // Easy access! Tails 06-07-2002
2021-07-06 08:56:45 +00:00
if ( ( oldthing - > flags2 & MF2_LINKDRAW ) & & oldthing - > tracer & & oldthing - > color = = SKINCOLOR_NONE )
vis - > color = oldthing - > tracer - > color ;
else
vis - > color = oldthing - > color ;
2014-03-15 16:59:03 +00:00
2020-01-18 05:21:11 +00:00
vis - > x1 = x1 < portalclipstart ? portalclipstart : x1 ;
vis - > x2 = x2 > = portalclipend ? portalclipend - 1 : x2 ;
2014-11-12 00:55:07 +00:00
2014-03-15 16:59:03 +00:00
vis - > sector = thing - > subsector - > sector ;
2022-11-05 01:33:41 +00:00
// Using linkscale here improves cut detection for LINKDRAW.
vis - > szt = ( INT16 ) ( ( centeryfrac - FixedMul ( vis - > gzt - viewz , linkscale ) ) > > FRACBITS ) ;
vis - > sz = ( INT16 ) ( ( centeryfrac - FixedMul ( vis - > gz - viewz , linkscale ) ) > > FRACBITS ) ;
2017-06-25 19:46:30 +00:00
vis - > cut = cut ;
2020-10-12 03:13:22 +00:00
2014-03-15 16:59:03 +00:00
if ( thing - > subsector - > sector - > numlights )
2018-09-12 20:06:56 +00:00
vis - > extra_colormap = * thing - > subsector - > sector - > lightlist [ light ] . extra_colormap ;
2014-03-15 16:59:03 +00:00
else
vis - > extra_colormap = thing - > subsector - > sector - > extra_colormap ;
2020-10-12 03:13:22 +00:00
vis - > xscale = FixedMul ( spritexscale , xscale ) ; //SoM: 4/17/2000
vis - > scale = FixedMul ( spriteyscale , yscale ) ; //<<detailshift;
2022-04-29 01:07:07 +00:00
vis - > thingscale = interp . scale ;
2020-10-12 03:13:22 +00:00
2020-10-12 20:25:18 +00:00
vis - > spritexscale = spritexscale ;
vis - > spriteyscale = spriteyscale ;
2020-10-13 15:57:36 +00:00
vis - > spritexoffset = spr_offset ;
vis - > spriteyoffset = spr_topoffset ;
2020-10-12 20:25:18 +00:00
2020-10-12 03:13:22 +00:00
if ( shadowdraw | | shadoweffects )
{
iscale = ( patch - > width < < FRACBITS ) / ( x2 - x1 + 1 ) ; // fuck it
x1 + = ( x2 - x1 ) / 2 ; // reusing x1 variable
vis - > shear . offset = vis - > x1 - x1 ;
}
else
iscale = FixedDiv ( FRACUNIT , vis - > xscale ) ;
2014-03-15 16:59:03 +00:00
2020-10-13 15:57:36 +00:00
vis - > shadowscale = shadowscale ;
2014-03-15 16:59:03 +00:00
if ( flip )
{
2019-08-18 17:16:48 +00:00
vis - > startfrac = spr_width - 1 ;
2014-03-15 16:59:03 +00:00
vis - > xiscale = - iscale ;
}
else
{
vis - > startfrac = 0 ;
vis - > xiscale = iscale ;
}
if ( vis - > x1 > x1 )
2016-08-16 22:25:01 +00:00
{
2020-10-12 20:25:18 +00:00
vis - > startfrac + = FixedDiv ( vis - > xiscale , this_scale ) * ( vis - > x1 - x1 ) ;
vis - > scale + = FixedMul ( scalestep , spriteyscale ) * ( vis - > x1 - x1 ) ;
2016-08-16 22:25:01 +00:00
}
2014-03-15 16:59:03 +00:00
2021-11-15 18:07:20 +00:00
if ( ( blendmode ! = AST_COPY ) & & cv_translucency . value )
vis - > transmap = R_GetBlendTable ( blendmode , trans ) ;
2019-08-18 17:16:48 +00:00
else
2020-10-15 17:05:18 +00:00
vis - > transmap = NULL ;
2014-03-15 16:59:03 +00:00
2020-10-12 03:13:22 +00:00
if ( R_ThingIsFullBright ( oldthing ) | | oldthing - > flags2 & MF2_SHADOW | | thing - > flags2 & MF2_SHADOW )
2017-06-26 15:30:23 +00:00
vis - > cut | = SC_FULLBRIGHT ;
2021-11-15 17:03:07 +00:00
else if ( R_ThingIsSemiBright ( oldthing ) )
vis - > cut | = SC_SEMIBRIGHT ;
2020-10-12 03:13:22 +00:00
else if ( R_ThingIsFullDark ( oldthing ) )
vis - > cut | = SC_FULLDARK ;
2014-03-15 16:59:03 +00:00
2020-10-15 17:05:18 +00:00
//
// determine the colormap (lightlevel & special effects)
//
2017-06-26 15:30:23 +00:00
if ( vis - > cut & SC_FULLBRIGHT
2020-02-16 19:19:24 +00:00
& & ( ! vis - > extra_colormap | | ! ( vis - > extra_colormap - > flags & CMF_FADEFULLBRIGHTSPRITES ) ) )
2014-03-15 16:59:03 +00:00
{
// full bright: goggles
vis - > colormap = colormaps ;
}
2020-10-12 03:13:22 +00:00
else if ( vis - > cut & SC_FULLDARK )
vis - > colormap = scalelight [ 0 ] [ 0 ] ;
2014-03-15 16:59:03 +00:00
else
{
// diminished light
2020-01-18 06:16:18 +00:00
lindex = FixedMul ( xscale , LIGHTRESOLUTIONFIX ) > > ( LIGHTSCALESHIFT ) ;
2014-03-15 16:59:03 +00:00
if ( lindex > = MAXLIGHTSCALE )
lindex = MAXLIGHTSCALE - 1 ;
2021-11-15 17:03:07 +00:00
if ( vis - > cut & SC_SEMIBRIGHT )
lindex = ( MAXLIGHTSCALE / 2 ) + ( lindex > > 1 ) ;
2014-03-15 16:59:03 +00:00
vis - > colormap = spritelights [ lindex ] ;
}
2017-06-26 13:44:10 +00:00
if ( vflip )
vis - > cut | = SC_VFLIP ;
2020-10-12 03:13:22 +00:00
if ( splat )
vis - > cut | = SC_SPLAT ; // I like ya cut g
2014-03-15 16:59:03 +00:00
2020-10-15 17:05:18 +00:00
vis - > patch = patch ;
2020-10-12 03:13:22 +00:00
if ( thing - > subsector - > sector - > numlights & & ! ( shadowdraw | | splat ) )
2017-06-26 13:44:10 +00:00
R_SplitSprite ( vis ) ;
2014-03-15 16:59:03 +00:00
2020-01-17 06:20:10 +00:00
if ( oldthing - > shadowscale & & cv_shadow . value )
2021-02-19 11:45:28 +00:00
R_ProjectDropShadow ( oldthing , vis , oldthing - > shadowscale , basetx , basetz ) ;
2019-12-27 21:31:20 +00:00
2022-09-11 04:27:37 +00:00
R_ProjectBoundingBox ( oldthing , vis ) ;
2014-03-15 16:59:03 +00:00
// Debug
+ + objectsdrawn ;
}
static void R_ProjectPrecipitationSprite ( precipmobj_t * thing )
{
fixed_t tr_x , tr_y ;
fixed_t tx , tz ;
fixed_t xscale , yscale ; //added : 02-02-98 : aaargll..if I were a math-guy!!!
INT32 x1 , x2 ;
spritedef_t * sprdef ;
spriteframe_t * sprframe ;
size_t lump ;
vissprite_t * vis ;
fixed_t iscale ;
//SoM: 3/17/2000
2017-06-25 19:46:30 +00:00
fixed_t gz , gzt ;
2014-03-15 16:59:03 +00:00
2019-10-06 22:40:52 +00:00
// uncapped/interpolation
2022-04-12 23:39:11 +00:00
interpmobjstate_t interp = { 0 } ;
2019-10-06 22:40:52 +00:00
// do interpolation
2022-03-27 03:48:08 +00:00
if ( R_UsingFrameInterpolation ( ) & & ! paused )
2019-10-06 22:40:52 +00:00
{
2022-04-12 23:39:11 +00:00
R_InterpolatePrecipMobjState ( thing , rendertimefrac , & interp ) ;
}
else
{
R_InterpolatePrecipMobjState ( thing , FRACUNIT , & interp ) ;
2019-10-06 22:40:52 +00:00
}
2014-03-15 16:59:03 +00:00
// transform the origin point
2022-04-12 23:39:11 +00:00
tr_x = interp . x - viewx ;
tr_y = interp . y - viewy ;
2014-03-15 16:59:03 +00:00
2020-05-19 15:48:50 +00:00
tz = FixedMul ( tr_x , viewcos ) + FixedMul ( tr_y , viewsin ) ; // near/far distance
2014-03-15 16:59:03 +00:00
// thing is behind view plane?
if ( tz < MINZ )
return ;
2020-05-19 15:48:50 +00:00
tx = FixedMul ( tr_x , viewsin ) - FixedMul ( tr_y , viewcos ) ; // sideways distance
2014-03-15 16:59:03 +00:00
// too far off the side?
2020-05-20 18:34:18 +00:00
if ( abs ( tx ) > FixedMul ( tz , fovtan ) < < 2 )
2014-03-15 16:59:03 +00:00
return ;
// aspect ratio stuff :
xscale = FixedDiv ( projection , tz ) ;
yscale = FixedDiv ( projectiony , tz ) ;
// decide which patch to use for sprite relative to player
# ifdef RANGECHECK
if ( ( unsigned ) thing - > sprite > = numsprites )
I_Error ( " R_ProjectPrecipitationSprite: invalid sprite number %d " ,
thing - > sprite ) ;
# endif
sprdef = & sprites [ thing - > sprite ] ;
# ifdef RANGECHECK
if ( ( UINT8 ) ( thing - > frame & FF_FRAMEMASK ) > = sprdef - > numframes )
I_Error ( " R_ProjectPrecipitationSprite: invalid sprite frame %d : %d for %s " ,
thing - > sprite , thing - > frame , sprnames [ thing - > sprite ] ) ;
# endif
sprframe = & sprdef - > spriteframes [ thing - > frame & FF_FRAMEMASK ] ;
# ifdef PARANOIA
if ( ! sprframe )
I_Error ( " R_ProjectPrecipitationSprite: sprframes NULL for sprite %d \n " , thing - > sprite ) ;
# endif
// use single rotation for all views
lump = sprframe - > lumpid [ 0 ] ; //Fab: see note above
// calculate edges of the shape
tx - = spritecachedinfo [ lump ] . offset ;
x1 = ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ;
// off the right side?
if ( x1 > viewwidth )
return ;
tx + = spritecachedinfo [ lump ] . width ;
x2 = ( ( centerxfrac + FixedMul ( tx , xscale ) ) > > FRACBITS ) - 1 ;
// off the left side
if ( x2 < 0 )
return ;
2014-11-12 00:55:07 +00:00
// PORTAL SPRITE CLIPPING
2019-06-01 11:07:23 +00:00
if ( portalrender & & portalclipline )
2014-11-12 00:55:07 +00:00
{
2020-05-15 19:17:31 +00:00
if ( x2 < portalclipstart | | x1 > = portalclipend )
2014-11-12 00:55:07 +00:00
return ;
2022-04-12 23:39:11 +00:00
if ( P_PointOnLineSide ( interp . x , interp . y , portalclipline ) ! = 0 )
2014-11-12 00:55:07 +00:00
return ;
}
2018-10-07 14:00:58 +00:00
2014-03-15 16:59:03 +00:00
//SoM: 3/17/2000: Disregard sprites that are out of view..
2022-04-12 23:39:11 +00:00
gzt = interp . z + spritecachedinfo [ lump ] . topoffset ;
2014-11-12 00:55:07 +00:00
gz = gzt - spritecachedinfo [ lump ] . height ;
2014-03-15 16:59:03 +00:00
if ( thing - > subsector - > sector - > cullheight )
{
2014-11-12 00:55:07 +00:00
if ( R_DoCulling ( thing - > subsector - > sector - > cullheight , viewsector - > cullheight , viewz , gz , gzt ) )
2019-06-18 12:33:35 +00:00
goto weatherthink ;
2014-03-15 16:59:03 +00:00
}
// store information in a vissprite
vis = R_NewVisSprite ( ) ;
2016-08-19 14:06:10 +00:00
vis - > scale = vis - > sortscale = yscale ; //<<detailshift;
2015-11-23 16:39:32 +00:00
vis - > dispoffset = 0 ; // Monster Iestyn: 23/11/15
2022-04-12 23:39:11 +00:00
vis - > gx = interp . x ;
vis - > gy = interp . y ;
2014-11-12 00:55:07 +00:00
vis - > gz = gz ;
2014-03-15 16:59:03 +00:00
vis - > gzt = gzt ;
2020-12-23 03:02:31 +00:00
vis - > thingheight = 4 * FRACUNIT ;
2022-04-12 23:39:11 +00:00
vis - > pz = interp . z ;
2020-12-23 03:02:31 +00:00
vis - > pzt = vis - > pz + vis - > thingheight ;
2014-03-15 16:59:03 +00:00
vis - > texturemid = vis - > gzt - viewz ;
2016-08-20 00:03:35 +00:00
vis - > scalestep = 0 ;
2019-12-30 02:19:27 +00:00
vis - > paperdistance = 0 ;
2020-01-09 03:52:10 +00:00
vis - > shear . tan = 0 ;
vis - > shear . offset = 0 ;
2014-03-15 16:59:03 +00:00
2020-01-18 05:21:11 +00:00
vis - > x1 = x1 < portalclipstart ? portalclipstart : x1 ;
vis - > x2 = x2 > = portalclipend ? portalclipend - 1 : x2 ;
2014-11-12 00:55:07 +00:00
2014-03-15 16:59:03 +00:00
vis - > xscale = xscale ; //SoM: 4/17/2000
vis - > sector = thing - > subsector - > sector ;
vis - > szt = ( INT16 ) ( ( centeryfrac - FixedMul ( vis - > gzt - viewz , yscale ) ) > > FRACBITS ) ;
vis - > sz = ( INT16 ) ( ( centeryfrac - FixedMul ( vis - > gz - viewz , yscale ) ) > > FRACBITS ) ;
iscale = FixedDiv ( FRACUNIT , xscale ) ;
vis - > startfrac = 0 ;
vis - > xiscale = iscale ;
if ( vis - > x1 > x1 )
vis - > startfrac + = vis - > xiscale * ( vis - > x1 - x1 ) ;
//Fab: lumppat is the lump number of the patch to use, this is different
// than lumpid for sprites-in-pwad : the graphics are patched
2020-09-07 05:23:07 +00:00
vis - > patch = W_CachePatchNum ( sprframe - > lumppat [ 0 ] , PU_SPRITE ) ;
2014-03-15 16:59:03 +00:00
// specific translucency
if ( thing - > frame & FF_TRANSMASK )
2021-03-30 20:03:05 +00:00
vis - > transmap = R_GetTranslucencyTable ( ( thing - > frame & FF_TRANSMASK ) > > FF_TRANSSHIFT ) ;
2014-03-15 16:59:03 +00:00
else
vis - > transmap = NULL ;
2017-06-26 14:53:20 +00:00
vis - > mobj = ( mobj_t * ) thing ;
2014-03-15 16:59:03 +00:00
vis - > mobjflags = 0 ;
2017-06-26 13:44:10 +00:00
vis - > cut = SC_PRECIP ;
2014-03-15 16:59:03 +00:00
vis - > extra_colormap = thing - > subsector - > sector - > extra_colormap ;
vis - > heightsec = thing - > subsector - > sector - > heightsec ;
2021-07-06 08:36:05 +00:00
vis - > color = SKINCOLOR_NONE ;
2014-03-15 16:59:03 +00:00
// Fullbright
vis - > colormap = colormaps ;
2019-06-18 12:33:35 +00:00
weatherthink :
// okay... this is a hack, but weather isn't networked, so it should be ok
if ( ! ( thing - > precipflags & PCF_THUNK ) )
{
if ( thing - > precipflags & PCF_RAIN )
P_RainThinker ( thing ) ;
else
P_SnowThinker ( thing ) ;
thing - > precipflags | = PCF_THUNK ;
}
2014-03-15 16:59:03 +00:00
}
// R_AddSprites
// During BSP traversal, this adds sprites by sector.
//
void R_AddSprites ( sector_t * sec , INT32 lightlevel )
{
mobj_t * thing ;
precipmobj_t * precipthing ; // Tails 08-25-2002
INT32 lightnum ;
2020-01-18 04:45:55 +00:00
fixed_t limit_dist , hoop_limit_dist ;
2014-03-15 16:59:03 +00:00
if ( rendermode ! = render_soft )
return ;
// BSP is traversed by subsector.
// A sector might have been split into several
// subsectors during BSP building.
// Thus we check whether its already added.
if ( sec - > validcount = = validcount )
return ;
// Well, now it will be done.
sec - > validcount = validcount ;
if ( ! sec - > numlights )
{
if ( sec - > heightsec = = - 1 ) lightlevel = sec - > lightlevel ;
lightnum = ( lightlevel > > LIGHTSEGSHIFT ) ;
if ( lightnum < 0 )
spritelights = scalelight [ 0 ] ;
else if ( lightnum > = LIGHTLEVELS )
spritelights = scalelight [ LIGHTLEVELS - 1 ] ;
else
spritelights = scalelight [ lightnum ] ;
}
// Handle all things in sector.
// If a limit exists, handle things a tiny bit different.
2019-10-11 19:02:11 +00:00
limit_dist = ( fixed_t ) ( cv_drawdist . value ) < < FRACBITS ;
hoop_limit_dist = ( fixed_t ) ( cv_drawdist_nights . value ) < < FRACBITS ;
2020-01-18 04:45:55 +00:00
for ( thing = sec - > thinglist ; thing ; thing = thing - > snext )
2014-03-15 16:59:03 +00:00
{
2022-09-11 04:27:37 +00:00
if ( R_ThingWithinDist ( thing , limit_dist , hoop_limit_dist ) )
{
const INT32 oldobjectsdrawn = objectsdrawn ;
if ( R_ThingVisible ( thing ) )
{
R_ProjectSprite ( thing ) ;
}
// I'm so smart :^)
if ( objectsdrawn = = oldobjectsdrawn )
{
/*
Object is invisible OR is off screen but
render its bbox even if the latter because
radius could be bigger than sprite .
*/
R_ProjectBoundingBox ( thing , NULL ) ;
}
}
2014-03-15 16:59:03 +00:00
}
2019-06-18 12:33:35 +00:00
// no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off
2014-03-15 16:59:03 +00:00
if ( ( limit_dist = ( fixed_t ) cv_drawdist_precip . value < < FRACBITS ) )
{
for ( precipthing = sec - > preciplist ; precipthing ; precipthing = precipthing - > snext )
{
2020-01-18 04:45:55 +00:00
if ( R_PrecipThingVisible ( precipthing , limit_dist ) )
R_ProjectPrecipitationSprite ( precipthing ) ;
2014-03-15 16:59:03 +00:00
}
}
}
2022-11-01 21:56:52 +00:00
static boolean R_SortVisSpriteFunc ( vissprite_t * ds , fixed_t bestscale , INT32 bestdispoffset )
{
if ( ds - > sortscale < bestscale )
{
return true ;
}
// order visprites of same scale by dispoffset, smallest first
else if ( ds - > sortscale = = bestscale & & ds - > dispoffset < bestdispoffset )
{
return true ;
}
return false ;
}
2014-03-15 16:59:03 +00:00
//
// R_SortVisSprites
//
2019-06-05 10:10:59 +00:00
static void R_SortVisSprites ( vissprite_t * vsprsortedhead , UINT32 start , UINT32 end )
2014-03-15 16:59:03 +00:00
{
2017-06-26 13:44:10 +00:00
UINT32 i , linkedvissprites = 0 ;
2014-03-15 16:59:03 +00:00
vissprite_t * ds , * dsprev , * dsnext , * dsfirst ;
vissprite_t * best = NULL ;
vissprite_t unsorted ;
fixed_t bestscale ;
2015-11-23 16:39:32 +00:00
INT32 bestdispoffset ;
2014-03-15 16:59:03 +00:00
unsorted . next = unsorted . prev = & unsorted ;
2019-06-05 10:10:59 +00:00
dsfirst = R_GetVisSprite ( start ) ;
2014-03-15 16:59:03 +00:00
// The first's prev and last's next will be set to
// nonsense, but are fixed in a moment
2019-06-05 10:10:59 +00:00
for ( i = start , dsnext = dsfirst , ds = NULL ; i < end ; i + + )
2014-03-15 16:59:03 +00:00
{
dsprev = ds ;
ds = dsnext ;
2019-06-05 10:10:59 +00:00
if ( i < end - 1 ) dsnext = R_GetVisSprite ( i + 1 ) ;
2014-03-15 16:59:03 +00:00
ds - > next = dsnext ;
ds - > prev = dsprev ;
2017-06-25 19:46:30 +00:00
ds - > linkdraw = NULL ;
2014-03-15 16:59:03 +00:00
}
// Fix first and last. ds still points to the last one after the loop
dsfirst - > prev = & unsorted ;
unsorted . next = dsfirst ;
2016-06-13 14:07:10 +00:00
if ( ds )
2017-06-25 19:46:30 +00:00
{
2016-06-13 14:07:10 +00:00
ds - > next = & unsorted ;
2017-06-25 19:46:30 +00:00
ds - > linkdraw = NULL ;
}
2014-03-15 16:59:03 +00:00
unsorted . prev = ds ;
2017-06-25 19:46:30 +00:00
// bundle linkdraw
2017-06-26 13:44:10 +00:00
for ( ds = unsorted . prev ; ds ! = & unsorted ; ds = ds - > prev )
2017-06-25 19:46:30 +00:00
{
2023-09-03 20:02:35 +00:00
// Remove this sprite if it was determined to not be visible
if ( ds - > cut & SC_NOTVISIBLE )
{
ds - > next - > prev = ds - > prev ;
ds - > prev - > next = ds - > next ;
continue ;
}
2017-06-25 19:46:30 +00:00
if ( ! ( ds - > cut & SC_LINKDRAW ) )
continue ;
2019-12-30 00:30:29 +00:00
if ( ds - > cut & SC_SHADOW )
continue ;
2017-06-25 19:46:30 +00:00
// reuse dsfirst...
2017-06-26 13:44:10 +00:00
for ( dsfirst = unsorted . prev ; dsfirst ! = & unsorted ; dsfirst = dsfirst - > prev )
2017-06-25 19:46:30 +00:00
{
// don't connect if it's also a link
if ( dsfirst - > cut & SC_LINKDRAW )
continue ;
2019-12-30 00:30:29 +00:00
// don't connect to your shadow!
if ( dsfirst - > cut & SC_SHADOW )
continue ;
2022-09-11 04:27:37 +00:00
// don't connect to your bounding box!
if ( dsfirst - > cut & SC_BBOX )
continue ;
2017-06-25 19:46:30 +00:00
// don't connect if it's not the tracer
if ( dsfirst - > mobj ! = ds - > mobj )
continue ;
// don't connect if the tracer's top is cut off, but lower than the link's top
2023-09-03 20:02:35 +00:00
if ( ( dsfirst - > cut & SC_TOP ) & & dsfirst - > szt > ds - > szt )
2017-06-25 19:46:30 +00:00
continue ;
// don't connect if the tracer's bottom is cut off, but higher than the link's bottom
2023-09-03 20:02:35 +00:00
if ( ( dsfirst - > cut & SC_BOTTOM ) & & dsfirst - > sz < ds - > sz )
2017-06-25 19:46:30 +00:00
continue ;
2023-09-03 20:02:35 +00:00
// If the object isn't visible, then the bounding box isn't either
if ( ds - > cut & SC_BBOX & & dsfirst - > cut & SC_NOTVISIBLE )
ds - > cut | = SC_NOTVISIBLE ;
2017-06-26 15:11:50 +00:00
break ;
}
2017-06-26 13:44:10 +00:00
2017-06-26 15:11:50 +00:00
// remove from chain
ds - > next - > prev = ds - > prev ;
ds - > prev - > next = ds - > next ;
2023-09-03 20:02:35 +00:00
if ( ds - > cut & SC_NOTVISIBLE )
continue ;
2017-06-26 15:11:50 +00:00
linkedvissprites + + ;
if ( dsfirst ! = & unsorted )
{
2017-06-26 13:44:10 +00:00
if ( ! ( ds - > cut & SC_FULLBRIGHT ) )
ds - > colormap = dsfirst - > colormap ;
ds - > extra_colormap = dsfirst - > extra_colormap ;
// reusing dsnext...
dsnext = dsfirst - > linkdraw ;
2022-11-01 21:56:52 +00:00
if ( dsnext = = NULL | | R_SortVisSpriteFunc ( ds , dsnext - > sortscale , dsnext - > dispoffset ) = = true )
2017-06-26 13:44:10 +00:00
{
ds - > next = dsnext ;
dsfirst - > linkdraw = ds ;
}
else
{
for ( ; dsnext - > next ! = NULL ; dsnext = dsnext - > next )
2022-11-01 21:56:52 +00:00
{
if ( R_SortVisSpriteFunc ( ds , dsnext - > next - > sortscale , dsnext - > next - > dispoffset ) = = true )
{
2017-06-26 13:44:10 +00:00
break ;
2022-11-01 21:56:52 +00:00
}
}
2017-06-26 13:44:10 +00:00
ds - > next = dsnext - > next ;
dsnext - > next = ds ;
}
2017-06-25 19:46:30 +00:00
}
2017-06-26 13:44:10 +00:00
}
2017-06-25 19:46:30 +00:00
2014-03-15 16:59:03 +00:00
// pull the vissprites out by scale
2019-06-05 10:10:59 +00:00
vsprsortedhead - > next = vsprsortedhead - > prev = vsprsortedhead ;
for ( i = start ; i < end - linkedvissprites ; i + + )
2014-03-15 16:59:03 +00:00
{
2015-11-23 16:39:32 +00:00
bestscale = bestdispoffset = INT32_MAX ;
2014-03-15 16:59:03 +00:00
for ( ds = unsorted . next ; ds ! = & unsorted ; ds = ds - > next )
{
2017-06-26 15:11:50 +00:00
# ifdef PARANOIA
2017-06-26 13:44:10 +00:00
if ( ds - > cut & SC_LINKDRAW )
2017-06-26 15:11:50 +00:00
I_Error ( " R_SortVisSprites: no link or discardal made for linkdraw! " ) ;
# endif
2017-06-26 13:44:10 +00:00
2022-11-01 21:56:52 +00:00
if ( R_SortVisSpriteFunc ( ds , bestscale , bestdispoffset ) = = true )
2014-03-15 16:59:03 +00:00
{
2016-08-18 14:45:44 +00:00
bestscale = ds - > sortscale ;
2015-11-23 16:39:32 +00:00
bestdispoffset = ds - > dispoffset ;
best = ds ;
}
2014-03-15 16:59:03 +00:00
}
2023-09-03 20:02:35 +00:00
if ( best )
{
best - > next - > prev = best - > prev ;
best - > prev - > next = best - > next ;
best - > next = vsprsortedhead ;
best - > prev = vsprsortedhead - > prev ;
vsprsortedhead - > prev - > next = best ;
vsprsortedhead - > prev = best ;
}
2014-03-15 16:59:03 +00:00
}
}
//
// R_CreateDrawNodes
// Creates and sorts a list of drawnodes for the scene being rendered.
static drawnode_t * R_CreateDrawNode ( drawnode_t * link ) ;
static drawnode_t nodebankhead ;
2019-06-04 18:15:42 +00:00
static void R_CreateDrawNodes ( maskcount_t * mask , drawnode_t * head , boolean tempskip )
2014-03-15 16:59:03 +00:00
{
drawnode_t * entry ;
drawseg_t * ds ;
INT32 i , p , best , x1 , x2 ;
fixed_t bestdelta , delta ;
vissprite_t * rover ;
2019-06-05 10:10:59 +00:00
static vissprite_t vsprsortedhead ;
2014-03-15 16:59:03 +00:00
drawnode_t * r2 ;
visplane_t * plane ;
INT32 sintersect ;
fixed_t scale = 0 ;
// Add the 3D floors, thicksides, and masked textures...
2019-06-04 18:15:42 +00:00
for ( ds = drawsegs + mask - > drawsegs [ 1 ] ; ds - - > drawsegs + mask - > drawsegs [ 0 ] ; )
2014-03-15 16:59:03 +00:00
{
if ( ds - > numthicksides )
{
for ( i = 0 ; i < ds - > numthicksides ; i + + )
{
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2014-03-15 16:59:03 +00:00
entry - > thickseg = ds ;
entry - > ffloor = ds - > thicksides [ i ] ;
}
}
2016-10-11 21:35:46 +00:00
// Check for a polyobject plane, but only if this is a front line
if ( ds - > curline - > polyseg & & ds - > curline - > polyseg - > visplane & & ! ds - > curline - > side ) {
plane = ds - > curline - > polyseg - > visplane ;
R_PlaneBounds ( plane ) ;
2015-04-06 16:22:27 +00:00
2018-12-14 17:08:25 +00:00
if ( plane - > low < 0 | | plane - > high > vid . height | | plane - > high > plane - > low )
2016-10-11 21:35:46 +00:00
;
else {
// Put it in!
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2016-10-11 21:35:46 +00:00
entry - > plane = plane ;
2015-04-06 16:22:27 +00:00
entry - > seg = ds ;
}
2016-10-11 21:35:46 +00:00
ds - > curline - > polyseg - > visplane = NULL ;
}
if ( ds - > maskedtexturecol )
{
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2014-03-15 16:59:03 +00:00
entry - > seg = ds ;
}
if ( ds - > numffloorplanes )
{
for ( i = 0 ; i < ds - > numffloorplanes ; i + + )
{
best = - 1 ;
bestdelta = 0 ;
for ( p = 0 ; p < ds - > numffloorplanes ; p + + )
{
if ( ! ds - > ffloorplanes [ p ] )
continue ;
plane = ds - > ffloorplanes [ p ] ;
R_PlaneBounds ( plane ) ;
2018-12-14 17:08:25 +00:00
if ( plane - > low < 0 | | plane - > high > vid . height | | plane - > high > plane - > low | | plane - > polyobj )
2014-03-15 16:59:03 +00:00
{
ds - > ffloorplanes [ p ] = NULL ;
continue ;
}
delta = abs ( plane - > height - viewz ) ;
if ( delta > bestdelta )
{
best = p ;
bestdelta = delta ;
}
}
if ( best ! = - 1 )
{
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2014-03-15 16:59:03 +00:00
entry - > plane = ds - > ffloorplanes [ best ] ;
entry - > seg = ds ;
ds - > ffloorplanes [ best ] = NULL ;
}
else
break ;
}
}
}
2019-06-04 18:15:42 +00:00
if ( tempskip )
return ;
2016-11-16 17:50:44 +00:00
// find all the remaining polyobject planes and add them on the end of the list
// probably this is a terrible idea if we wanted them to be sorted properly
// but it works getting them in for now
for ( i = 0 ; i < numPolyObjects ; i + + )
{
if ( ! PolyObjects [ i ] . visplane )
continue ;
plane = PolyObjects [ i ] . visplane ;
R_PlaneBounds ( plane ) ;
2018-12-14 17:08:25 +00:00
if ( plane - > low < 0 | | plane - > high > vid . height | | plane - > high > plane - > low )
2016-11-16 17:50:44 +00:00
{
PolyObjects [ i ] . visplane = NULL ;
continue ;
}
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2016-11-16 17:50:44 +00:00
entry - > plane = plane ;
// note: no seg is set, for what should be obvious reasons
PolyObjects [ i ] . visplane = NULL ;
}
2019-06-05 10:10:59 +00:00
// No vissprites in this mask?
if ( mask - > vissprites [ 1 ] - mask - > vissprites [ 0 ] = = 0 )
2014-03-15 16:59:03 +00:00
return ;
2019-06-05 10:10:59 +00:00
R_SortVisSprites ( & vsprsortedhead , mask - > vissprites [ 0 ] , mask - > vissprites [ 1 ] ) ;
2014-03-15 16:59:03 +00:00
for ( rover = vsprsortedhead . prev ; rover ! = & vsprsortedhead ; rover = rover - > prev )
{
if ( rover - > szt > vid . height | | rover - > sz < 0 )
continue ;
sintersect = ( rover - > x1 + rover - > x2 ) / 2 ;
2019-06-04 18:15:42 +00:00
for ( r2 = head - > next ; r2 ! = head ; r2 = r2 - > next )
2014-03-15 16:59:03 +00:00
{
if ( r2 - > plane )
{
2015-05-18 02:49:13 +00:00
fixed_t planeobjectz , planecameraz ;
2014-03-15 16:59:03 +00:00
if ( r2 - > plane - > minx > rover - > x2 | | r2 - > plane - > maxx < rover - > x1 )
continue ;
if ( rover - > szt > r2 - > plane - > low | | rover - > sz < r2 - > plane - > high )
continue ;
2015-05-18 02:49:13 +00:00
// Effective height may be different for each comparison in the case of slopes
2020-05-18 13:23:56 +00:00
planeobjectz = P_GetZAt ( r2 - > plane - > slope , rover - > gx , rover - > gy , r2 - > plane - > height ) ;
planecameraz = P_GetZAt ( r2 - > plane - > slope , viewx , viewy , r2 - > plane - > height ) ;
2015-05-17 17:03:52 +00:00
2020-12-23 03:02:31 +00:00
if ( rover - > mobjflags & MF_NOCLIPHEIGHT )
2014-03-15 16:59:03 +00:00
{
2020-12-23 03:02:31 +00:00
//Objects with NOCLIPHEIGHT can appear halfway in.
if ( planecameraz < viewz & & rover - > pz + ( rover - > thingheight / 2 ) > = planeobjectz )
continue ;
if ( planecameraz > viewz & & rover - > pzt - ( rover - > thingheight / 2 ) < = planeobjectz )
2014-03-15 16:59:03 +00:00
continue ;
}
2020-12-23 03:02:31 +00:00
else
2014-03-15 16:59:03 +00:00
{
2020-12-23 03:02:31 +00:00
if ( planecameraz < viewz & & rover - > pz > = planeobjectz )
continue ;
if ( planecameraz > viewz & & rover - > pzt < = planeobjectz )
2014-03-15 16:59:03 +00:00
continue ;
}
// SoM: NOTE: Because a visplane's shape and scale is not directly
// bound to any single linedef, a simple poll of it's frontscale is
// not adequate. We must check the entire frontscale array for any
// part that is in front of the sprite.
x1 = rover - > x1 ;
x2 = rover - > x2 ;
if ( x1 < r2 - > plane - > minx ) x1 = r2 - > plane - > minx ;
if ( x2 > r2 - > plane - > maxx ) x2 = r2 - > plane - > maxx ;
2016-11-16 17:50:44 +00:00
if ( r2 - > seg ) // if no seg set, assume the whole thing is in front or something stupid
2014-03-15 16:59:03 +00:00
{
2016-11-16 17:50:44 +00:00
for ( i = x1 ; i < = x2 ; i + + )
{
2017-01-07 15:03:59 +00:00
if ( r2 - > seg - > frontscale [ i ] > rover - > sortscale )
2016-11-16 17:50:44 +00:00
break ;
}
if ( i > x2 )
continue ;
2014-03-15 16:59:03 +00:00
}
entry = R_CreateDrawNode ( NULL ) ;
( entry - > prev = r2 - > prev ) - > next = entry ;
( entry - > next = r2 ) - > prev = entry ;
entry - > sprite = rover ;
break ;
}
else if ( r2 - > thickseg )
{
2020-12-23 03:02:31 +00:00
fixed_t topplaneobjectz , topplanecameraz , botplaneobjectz , botplanecameraz ;
2014-03-15 16:59:03 +00:00
if ( rover - > x1 > r2 - > thickseg - > x2 | | rover - > x2 < r2 - > thickseg - > x1 )
continue ;
scale = r2 - > thickseg - > scale1 > r2 - > thickseg - > scale2 ? r2 - > thickseg - > scale1 : r2 - > thickseg - > scale2 ;
2016-08-20 02:02:40 +00:00
if ( scale < = rover - > sortscale )
2014-03-15 16:59:03 +00:00
continue ;
scale = r2 - > thickseg - > scale1 + ( r2 - > thickseg - > scalestep * ( sintersect - r2 - > thickseg - > x1 ) ) ;
2016-08-20 02:02:40 +00:00
if ( scale < = rover - > sortscale )
2014-03-15 16:59:03 +00:00
continue ;
2020-03-22 14:17:16 +00:00
topplaneobjectz = P_GetFFloorTopZAt ( r2 - > ffloor , rover - > gx , rover - > gy ) ;
topplanecameraz = P_GetFFloorTopZAt ( r2 - > ffloor , viewx , viewy ) ;
botplaneobjectz = P_GetFFloorBottomZAt ( r2 - > ffloor , rover - > gx , rover - > gy ) ;
botplanecameraz = P_GetFFloorBottomZAt ( r2 - > ffloor , viewx , viewy ) ;
2015-05-18 02:49:13 +00:00
if ( ( topplanecameraz > viewz & & botplanecameraz < viewz ) | |
( topplanecameraz < viewz & & rover - > gzt < topplaneobjectz ) | |
( botplanecameraz > viewz & & rover - > gz > botplaneobjectz ) )
2014-03-15 16:59:03 +00:00
{
entry = R_CreateDrawNode ( NULL ) ;
( entry - > prev = r2 - > prev ) - > next = entry ;
( entry - > next = r2 ) - > prev = entry ;
entry - > sprite = rover ;
break ;
}
}
else if ( r2 - > seg )
{
if ( rover - > x1 > r2 - > seg - > x2 | | rover - > x2 < r2 - > seg - > x1 )
continue ;
scale = r2 - > seg - > scale1 > r2 - > seg - > scale2 ? r2 - > seg - > scale1 : r2 - > seg - > scale2 ;
2016-08-20 02:02:40 +00:00
if ( scale < = rover - > sortscale )
2014-03-15 16:59:03 +00:00
continue ;
scale = r2 - > seg - > scale1 + ( r2 - > seg - > scalestep * ( sintersect - r2 - > seg - > x1 ) ) ;
2016-08-20 02:02:40 +00:00
if ( rover - > sortscale < scale )
2014-03-15 16:59:03 +00:00
{
entry = R_CreateDrawNode ( NULL ) ;
( entry - > prev = r2 - > prev ) - > next = entry ;
( entry - > next = r2 ) - > prev = entry ;
entry - > sprite = rover ;
break ;
}
}
else if ( r2 - > sprite )
{
2020-10-13 04:09:17 +00:00
boolean infront = ( r2 - > sprite - > sortscale > rover - > sortscale
| | ( r2 - > sprite - > sortscale = = rover - > sortscale & & r2 - > sprite - > dispoffset > rover - > dispoffset ) ) ;
2020-10-13 05:24:18 +00:00
if ( rover - > cut & SC_SPLAT | | r2 - > sprite - > cut & SC_SPLAT )
2020-10-13 04:09:17 +00:00
{
2020-10-13 05:24:18 +00:00
fixed_t scale1 = ( rover - > cut & SC_SPLAT ? rover - > sortsplat : rover - > sortscale ) ;
fixed_t scale2 = ( r2 - > sprite - > cut & SC_SPLAT ? r2 - > sprite - > sortsplat : r2 - > sprite - > sortscale ) ;
boolean behind = ( scale2 > scale1 | | ( scale2 = = scale1 & & r2 - > sprite - > dispoffset > rover - > dispoffset ) ) ;
2020-10-13 04:09:17 +00:00
2020-10-13 05:24:18 +00:00
if ( ! behind )
2020-10-13 04:09:17 +00:00
{
2020-12-23 03:02:31 +00:00
fixed_t z1 = 0 , z2 = 0 ;
if ( rover - > mobj - > z - viewz > 0 )
{
z1 = rover - > pz ;
z2 = r2 - > sprite - > pz ;
}
2020-10-13 05:24:18 +00:00
else
2020-12-23 03:02:31 +00:00
{
z1 = r2 - > sprite - > pz ;
z2 = rover - > pz ;
}
z1 - = viewz ;
z2 - = viewz ;
infront = ( z1 > = z2 ) ;
2020-10-13 05:24:18 +00:00
}
2020-10-13 04:09:17 +00:00
}
else
2020-10-12 03:13:22 +00:00
{
if ( r2 - > sprite - > x1 > rover - > x2 | | r2 - > sprite - > x2 < rover - > x1 )
continue ;
if ( r2 - > sprite - > szt > rover - > sz | | r2 - > sprite - > sz < rover - > szt )
continue ;
}
2014-03-15 16:59:03 +00:00
2020-10-13 04:09:17 +00:00
if ( infront )
2014-03-15 16:59:03 +00:00
{
entry = R_CreateDrawNode ( NULL ) ;
( entry - > prev = r2 - > prev ) - > next = entry ;
( entry - > next = r2 ) - > prev = entry ;
entry - > sprite = rover ;
break ;
}
}
}
2019-06-04 18:15:42 +00:00
if ( r2 = = head )
2014-03-15 16:59:03 +00:00
{
2019-06-04 18:15:42 +00:00
entry = R_CreateDrawNode ( head ) ;
2014-03-15 16:59:03 +00:00
entry - > sprite = rover ;
}
}
}
static drawnode_t * R_CreateDrawNode ( drawnode_t * link )
{
drawnode_t * node = nodebankhead . next ;
if ( node = = & nodebankhead )
{
node = malloc ( sizeof ( * node ) ) ;
if ( ! node )
I_Error ( " No more free memory to CreateDrawNode " ) ;
}
else
( nodebankhead . next = node - > next ) - > prev = & nodebankhead ;
if ( link )
{
node - > next = link ;
node - > prev = link - > prev ;
link - > prev - > next = node ;
link - > prev = node ;
}
node - > plane = NULL ;
node - > seg = NULL ;
node - > thickseg = NULL ;
node - > ffloor = NULL ;
node - > sprite = NULL ;
2020-05-02 17:43:53 +00:00
2021-10-25 17:49:15 +00:00
ps_numdrawnodes . value . i + + ;
2014-03-15 16:59:03 +00:00
return node ;
}
static void R_DoneWithNode ( drawnode_t * node )
{
( node - > next - > prev = node - > prev ) - > next = node - > next ;
( node - > next = nodebankhead . next ) - > prev = node ;
( node - > prev = & nodebankhead ) - > next = node ;
}
2019-06-04 18:15:42 +00:00
static void R_ClearDrawNodes ( drawnode_t * head )
2014-03-15 16:59:03 +00:00
{
drawnode_t * rover ;
drawnode_t * next ;
2019-06-04 18:15:42 +00:00
for ( rover = head - > next ; rover ! = head ; )
2014-03-15 16:59:03 +00:00
{
next = rover - > next ;
R_DoneWithNode ( rover ) ;
rover = next ;
}
2019-06-04 18:15:42 +00:00
head - > next = head - > prev = head ;
2014-03-15 16:59:03 +00:00
}
void R_InitDrawNodes ( void )
{
nodebankhead . next = nodebankhead . prev = & nodebankhead ;
}
//
// R_DrawSprite
//
//Fab : 26-04-98:
// NOTE : uses con_clipviewtop, so that when console is on,
// don't draw the part of sprites hidden under the console
static void R_DrawSprite ( vissprite_t * spr )
{
2014-11-12 00:55:07 +00:00
mfloorclip = spr - > clipbot ;
mceilingclip = spr - > cliptop ;
2020-10-12 03:13:22 +00:00
2022-09-11 04:27:37 +00:00
if ( spr - > cut & SC_BBOX )
R_DrawThingBoundingBox ( spr ) ;
else if ( spr - > cut & SC_SPLAT )
2021-03-30 02:04:13 +00:00
R_DrawFloorSplat ( spr ) ;
2020-10-12 03:13:22 +00:00
else
R_DrawVisSprite ( spr ) ;
2014-11-12 00:55:07 +00:00
}
2014-03-15 16:59:03 +00:00
2014-11-12 00:55:07 +00:00
// Special drawer for precipitation sprites Tails 08-18-2002
static void R_DrawPrecipitationSprite ( vissprite_t * spr )
{
mfloorclip = spr - > clipbot ;
mceilingclip = spr - > cliptop ;
R_DrawPrecipitationVisSprite ( spr ) ;
}
2014-03-15 16:59:03 +00:00
2022-03-21 22:40:24 +00:00
//SoM: 3/17/2000: Clip sprites in water.
static void R_HeightSecClip ( vissprite_t * spr , INT32 x1 , INT32 x2 )
{
fixed_t mh , h ;
INT32 x , phs ;
if ( spr - > heightsec = = - 1 )
return ;
if ( spr - > cut & ( SC_SPLAT | SC_SHADOW ) | | spr - > renderflags & RF_SHADOWDRAW )
return ;
phs = viewplayer - > mo - > subsector - > sector - > heightsec ;
if ( ( mh = sectors [ spr - > heightsec ] . floorheight ) > spr - > gz & &
( h = centeryfrac - FixedMul ( mh - = viewz , spr - > sortscale ) ) > = 0 & &
( h > > = FRACBITS ) < viewheight )
{
if ( mh < = 0 | | ( phs ! = - 1 & & viewz > sectors [ phs ] . floorheight ) )
{ // clip bottom
for ( x = x1 ; x < = x2 ; x + + )
if ( spr - > clipbot [ x ] = = - 2 | | h < spr - > clipbot [ x ] )
spr - > clipbot [ x ] = ( INT16 ) h ;
}
else // clip top
{
for ( x = x1 ; x < = x2 ; x + + )
if ( spr - > cliptop [ x ] = = - 2 | | h > spr - > cliptop [ x ] )
spr - > cliptop [ x ] = ( INT16 ) h ;
}
}
if ( ( mh = sectors [ spr - > heightsec ] . ceilingheight ) < spr - > gzt & &
( h = centeryfrac - FixedMul ( mh - viewz , spr - > sortscale ) ) > = 0 & &
( h > > = FRACBITS ) < viewheight )
{
if ( phs ! = - 1 & & viewz > = sectors [ phs ] . ceilingheight )
{ // clip bottom
for ( x = x1 ; x < = x2 ; x + + )
if ( spr - > clipbot [ x ] = = - 2 | | h < spr - > clipbot [ x ] )
spr - > clipbot [ x ] = ( INT16 ) h ;
}
else // clip top
{
for ( x = x1 ; x < = x2 ; x + + )
if ( spr - > cliptop [ x ] = = - 2 | | h > spr - > cliptop [ x ] )
spr - > cliptop [ x ] = ( INT16 ) h ;
}
}
}
2023-09-03 21:59:39 +00:00
static boolean R_CheckSpriteVisible ( vissprite_t * spr , INT32 x1 , INT32 x2 )
{
INT16 sz = spr - > sz ;
INT16 szt = spr - > szt ;
2023-09-10 14:10:32 +00:00
fixed_t texturemid = 0 , yscale = 0 , scalestep = spr - > scalestep ; // "= 0" pleases the compiler
INT32 height = 0 ;
2023-09-03 21:59:39 +00:00
if ( scalestep )
{
2023-09-03 22:35:58 +00:00
height = spr - > patch - > height ;
2023-09-03 21:59:39 +00:00
yscale = spr - > scale ;
scalestep = FixedMul ( scalestep , spr - > spriteyscale ) ;
if ( spr - > thingscale ! = FRACUNIT )
texturemid = FixedDiv ( spr - > texturemid , max ( spr - > thingscale , 1 ) ) ;
else
texturemid = spr - > texturemid ;
}
for ( INT32 x = x1 ; x < = x2 ; x + + )
{
if ( scalestep )
{
2023-09-03 22:35:58 +00:00
fixed_t top = centeryfrac - FixedMul ( texturemid , yscale ) ;
fixed_t bottom = top + ( height * yscale ) ;
szt = ( INT16 ) ( top > > FRACBITS ) ;
sz = ( INT16 ) ( bottom > > FRACBITS ) ;
2023-09-03 21:59:39 +00:00
yscale + = scalestep ;
}
if ( spr - > cliptop [ x ] < spr - > clipbot [ x ] & & sz > spr - > cliptop [ x ] & & szt < spr - > clipbot [ x ] )
return true ;
}
return false ;
}
2020-10-12 03:13:22 +00:00
// R_ClipVisSprite
2014-11-12 00:55:07 +00:00
// Clips vissprites without drawing, so that portals can work. -Red
2023-07-26 03:06:52 +00:00
static void R_ClipVisSprite ( vissprite_t * spr , INT32 x1 , INT32 x2 , portal_t * portal )
2014-11-12 00:55:07 +00:00
{
2020-10-12 03:13:22 +00:00
drawseg_t * ds ;
INT32 x ;
INT32 r1 ;
INT32 r2 ;
fixed_t scale ;
fixed_t lowscale ;
INT32 silhouette ;
for ( x = x1 ; x < = x2 ; x + + )
spr - > clipbot [ x ] = spr - > cliptop [ x ] = - 2 ;
// Scan drawsegs from end to start for obscuring segs.
// The first drawseg that has a greater scale
// is the clip seg.
//SoM: 4/8/2000:
// Pointer check was originally nonportable
// and buggy, by going past LEFT end of array:
2023-07-26 03:06:52 +00:00
// e6y: optimization
if ( drawsegs_xrange_size )
2020-10-12 03:13:22 +00:00
{
2023-07-26 03:06:52 +00:00
const drawseg_xrange_item_t * last = & drawsegs_xrange [ drawsegs_xrange_count - 1 ] ;
drawseg_xrange_item_t * curr = & drawsegs_xrange [ - 1 ] ;
2014-03-15 16:59:03 +00:00
2023-07-26 03:06:52 +00:00
while ( + + curr < = last )
2014-03-15 16:59:03 +00:00
{
2023-07-26 03:06:52 +00:00
// determine if the drawseg obscures the sprite
if ( curr - > x1 > x2 | | curr - > x2 < x1 )
{
// does not cover sprite
continue ;
}
ds = curr - > user ;
2020-10-12 03:13:22 +00:00
if ( ds - > portalpass > 0 & & ds - > portalpass < = portalrender )
continue ; // is a portal
if ( ds - > scale1 > ds - > scale2 )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
lowscale = ds - > scale2 ;
scale = ds - > scale1 ;
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
else
2019-06-05 14:35:48 +00:00
{
2020-10-12 03:13:22 +00:00
lowscale = ds - > scale1 ;
scale = ds - > scale2 ;
}
2014-11-12 00:55:07 +00:00
2020-10-12 03:13:22 +00:00
if ( scale < spr - > sortscale | |
( lowscale < spr - > sortscale & &
! R_PointOnSegSide ( spr - > gx , spr - > gy , ds - > curline ) ) )
{
// masked mid texture?
/*if (ds->maskedtexturecol)
R_RenderMaskedSegRange ( ds , r1 , r2 ) ; */
// seg is behind sprite
continue ;
2014-03-15 16:59:03 +00:00
}
2023-07-26 03:06:52 +00:00
r1 = ds - > x1 < x1 ? x1 : ds - > x1 ;
r2 = ds - > x2 > x2 ? x2 : ds - > x2 ;
2014-03-15 16:59:03 +00:00
2023-07-26 03:06:52 +00:00
// clip this piece of the sprite
silhouette = ds - > silhouette ;
2014-03-15 16:59:03 +00:00
2023-07-26 03:06:52 +00:00
if ( spr - > gz > = ds - > bsilheight )
silhouette & = ~ SIL_BOTTOM ;
2014-03-15 16:59:03 +00:00
2023-07-26 03:06:52 +00:00
if ( spr - > gzt < = ds - > tsilheight )
silhouette & = ~ SIL_TOP ;
2014-03-15 16:59:03 +00:00
2023-07-26 03:06:52 +00:00
if ( silhouette = = SIL_BOTTOM )
{
// bottom sil
for ( x = r1 ; x < = r2 ; x + + )
if ( spr - > clipbot [ x ] = = - 2 )
spr - > clipbot [ x ] = ds - > sprbottomclip [ x ] ;
}
else if ( silhouette = = SIL_TOP )
{
// top sil
for ( x = r1 ; x < = r2 ; x + + )
if ( spr - > cliptop [ x ] = = - 2 )
spr - > cliptop [ x ] = ds - > sprtopclip [ x ] ;
}
else if ( silhouette = = ( SIL_TOP | SIL_BOTTOM ) )
2014-11-12 00:55:07 +00:00
{
2023-07-26 03:06:52 +00:00
// both
for ( x = r1 ; x < = r2 ; x + + )
{
if ( spr - > clipbot [ x ] = = - 2 )
spr - > clipbot [ x ] = ds - > sprbottomclip [ x ] ;
if ( spr - > cliptop [ x ] = = - 2 )
spr - > cliptop [ x ] = ds - > sprtopclip [ x ] ;
}
2014-11-12 00:55:07 +00:00
}
2020-10-12 03:13:22 +00:00
}
}
2022-03-21 22:40:24 +00:00
R_HeightSecClip ( spr , x1 , x2 ) ;
2020-10-12 03:13:22 +00:00
if ( spr - > cut & SC_TOP & & spr - > cut & SC_BOTTOM )
{
for ( x = x1 ; x < = x2 ; x + + )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
if ( spr - > cliptop [ x ] = = - 2 | | spr - > szt > spr - > cliptop [ x ] )
spr - > cliptop [ x ] = spr - > szt ;
2014-11-12 00:55:07 +00:00
2020-10-12 03:13:22 +00:00
if ( spr - > clipbot [ x ] = = - 2 | | spr - > sz < spr - > clipbot [ x ] )
spr - > clipbot [ x ] = spr - > sz ;
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
}
else if ( spr - > cut & SC_TOP )
{
for ( x = x1 ; x < = x2 ; x + + )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
if ( spr - > cliptop [ x ] = = - 2 | | spr - > szt > spr - > cliptop [ x ] )
spr - > cliptop [ x ] = spr - > szt ;
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
}
else if ( spr - > cut & SC_BOTTOM )
{
for ( x = x1 ; x < = x2 ; x + + )
2014-03-15 16:59:03 +00:00
{
2020-10-12 03:13:22 +00:00
if ( spr - > clipbot [ x ] = = - 2 | | spr - > sz < spr - > clipbot [ x ] )
spr - > clipbot [ x ] = spr - > sz ;
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
}
2014-03-15 16:59:03 +00:00
2020-10-12 03:13:22 +00:00
// all clipping has been performed, so store the values - what, did you think we were drawing them NOW?
2014-03-15 16:59:03 +00:00
2020-10-12 03:13:22 +00:00
// check for unclipped columns
for ( x = x1 ; x < = x2 ; x + + )
{
if ( spr - > clipbot [ x ] = = - 2 )
spr - > clipbot [ x ] = ( INT16 ) viewheight ;
2014-03-15 16:59:03 +00:00
2020-10-12 03:13:22 +00:00
if ( spr - > cliptop [ x ] = = - 2 )
2023-09-03 20:02:35 +00:00
spr - > cliptop [ x ] = - 1 ;
2020-10-12 03:13:22 +00:00
}
2019-06-05 14:35:48 +00:00
2020-10-12 03:13:22 +00:00
if ( portal )
{
2022-01-14 17:53:03 +00:00
INT32 start_index = max ( portal - > start , x1 ) ;
INT32 end_index = min ( portal - > start + portal - > end - portal - > start , x2 ) ;
for ( x = x1 ; x < start_index ; x + + )
{
spr - > clipbot [ x ] = - 1 ;
spr - > cliptop [ x ] = - 1 ;
}
for ( x = start_index ; x < = end_index ; x + + )
2019-06-05 14:35:48 +00:00
{
2020-10-12 03:13:22 +00:00
if ( spr - > clipbot [ x ] > portal - > floorclip [ x - portal - > start ] )
spr - > clipbot [ x ] = portal - > floorclip [ x - portal - > start ] ;
if ( spr - > cliptop [ x ] < portal - > ceilingclip [ x - portal - > start ] )
spr - > cliptop [ x ] = portal - > ceilingclip [ x - portal - > start ] ;
2019-06-05 14:35:48 +00:00
}
2022-01-14 17:53:03 +00:00
for ( x = end_index + 1 ; x < = x2 ; x + + )
{
spr - > clipbot [ x ] = - 1 ;
spr - > cliptop [ x ] = - 1 ;
}
2014-03-15 16:59:03 +00:00
}
2023-09-03 20:02:35 +00:00
// Check if it'll be visible
// Not done for floorsprites.
if ( cv_spriteclip . value & & ( spr - > cut & SC_SPLAT ) = = 0 )
{
2023-09-03 21:59:39 +00:00
if ( ! R_CheckSpriteVisible ( spr , x1 , x2 ) )
spr - > cut | = SC_NOTVISIBLE ;
2023-09-03 20:02:35 +00:00
}
2014-03-15 16:59:03 +00:00
}
2020-10-12 03:13:22 +00:00
void R_ClipSprites ( drawseg_t * dsstart , portal_t * portal )
{
2023-07-26 03:06:52 +00:00
const size_t maxdrawsegs = ds_p - drawsegs ;
const INT32 cx = viewwidth / 2 ;
drawseg_t * ds ;
INT32 i ;
// e6y
// Reducing of cache misses in the following R_DrawSprite()
// Makes sense for scenes with huge amount of drawsegs.
// ~12% of speed improvement on epic.wad map05
for ( i = 0 ; i < DS_RANGES_COUNT ; i + + )
{
drawsegs_xranges [ i ] . count = 0 ;
}
if ( visspritecount - clippedvissprites < = 0 )
{
return ;
}
if ( drawsegs_xrange_size < maxdrawsegs )
{
drawsegs_xrange_size = 2 * maxdrawsegs ;
for ( i = 0 ; i < DS_RANGES_COUNT ; i + + )
{
drawsegs_xranges [ i ] . items = Z_Realloc (
drawsegs_xranges [ i ] . items ,
drawsegs_xrange_size * sizeof ( drawsegs_xranges [ i ] . items [ 0 ] ) ,
PU_STATIC , NULL
) ;
}
}
for ( ds = ds_p ; ds - - > dsstart ; )
{
if ( ds - > silhouette | | ds - > maskedtexturecol )
{
drawsegs_xranges [ 0 ] . items [ drawsegs_xranges [ 0 ] . count ] . x1 = ds - > x1 ;
drawsegs_xranges [ 0 ] . items [ drawsegs_xranges [ 0 ] . count ] . x2 = ds - > x2 ;
drawsegs_xranges [ 0 ] . items [ drawsegs_xranges [ 0 ] . count ] . user = ds ;
// e6y: ~13% of speed improvement on sunder.wad map10
if ( ds - > x1 < cx )
{
drawsegs_xranges [ 1 ] . items [ drawsegs_xranges [ 1 ] . count ] =
drawsegs_xranges [ 0 ] . items [ drawsegs_xranges [ 0 ] . count ] ;
drawsegs_xranges [ 1 ] . count + + ;
}
if ( ds - > x2 > = cx )
{
drawsegs_xranges [ 2 ] . items [ drawsegs_xranges [ 2 ] . count ] =
drawsegs_xranges [ 0 ] . items [ drawsegs_xranges [ 0 ] . count ] ;
drawsegs_xranges [ 2 ] . count + + ;
}
drawsegs_xranges [ 0 ] . count + + ;
}
}
2020-10-12 03:13:22 +00:00
for ( ; clippedvissprites < visspritecount ; clippedvissprites + + )
{
vissprite_t * spr = R_GetVisSprite ( clippedvissprites ) ;
2022-09-11 04:27:37 +00:00
2023-09-03 21:59:39 +00:00
if ( cv_spriteclip . value
& & ( spr - > szt > vid . height | | spr - > sz < 0 )
& & ! ( ( spr - > cut & SC_SPLAT ) | | spr - > scalestep ) )
2023-09-03 20:02:35 +00:00
{
spr - > cut | = SC_NOTVISIBLE ;
continue ;
}
2023-07-26 03:06:52 +00:00
if ( spr - > cut & SC_BBOX )
2023-09-03 20:14:48 +00:00
{
numvisiblesprites + + ;
2023-07-26 03:06:52 +00:00
continue ;
2023-09-03 20:14:48 +00:00
}
2023-07-26 03:06:52 +00:00
INT32 x1 = ( spr - > cut & SC_SPLAT ) ? 0 : spr - > x1 ;
INT32 x2 = ( spr - > cut & SC_SPLAT ) ? viewwidth : spr - > x2 ;
if ( x2 < cx )
{
drawsegs_xrange = drawsegs_xranges [ 1 ] . items ;
drawsegs_xrange_count = drawsegs_xranges [ 1 ] . count ;
}
else if ( x1 > = cx )
2022-09-11 04:27:37 +00:00
{
2023-07-26 03:06:52 +00:00
drawsegs_xrange = drawsegs_xranges [ 2 ] . items ;
drawsegs_xrange_count = drawsegs_xranges [ 2 ] . count ;
2022-09-11 04:27:37 +00:00
}
2023-07-26 03:06:52 +00:00
else
{
drawsegs_xrange = drawsegs_xranges [ 0 ] . items ;
drawsegs_xrange_count = drawsegs_xranges [ 0 ] . count ;
}
R_ClipVisSprite ( spr , x1 , x2 , portal ) ;
2023-09-03 20:02:35 +00:00
if ( ( spr - > cut & SC_NOTVISIBLE ) = = 0 )
numvisiblesprites + + ;
2020-10-12 03:13:22 +00:00
}
}
2020-01-18 04:45:55 +00:00
/* Check if thing may be drawn from our current view. */
boolean R_ThingVisible ( mobj_t * thing )
{
return ( ! (
2023-06-29 22:09:20 +00:00
( thing - > sprite = = SPR_NULL ) | | // Don't draw null-sprites
( thing - > flags2 & MF2_DONTDRAW ) | | // Don't draw MF2_LINKDRAW objects
( thing - > drawonlyforplayer & & thing - > drawonlyforplayer ! = viewplayer ) | | // Don't draw other players' personal objects
( r_viewmobj & & (
( r_viewmobj = = thing ) | | // Don't draw first-person players or awayviewmobj objects
( r_viewmobj - > player & & r_viewmobj - > player - > followmobj = = thing ) | | // Don't draw first-person players' followmobj
( r_viewmobj = = thing - > dontdrawforviewmobj ) // Don't draw objects that are hidden for the current view
) )
2020-01-18 04:45:55 +00:00
) ) ;
}
2022-09-11 04:27:37 +00:00
boolean R_ThingWithinDist ( mobj_t * thing ,
2020-01-18 04:45:55 +00:00
fixed_t limit_dist ,
fixed_t hoop_limit_dist )
{
2022-09-11 04:27:37 +00:00
const fixed_t approx_dist = P_AproxDistance ( viewx - thing - > x , viewy - thing - > y ) ;
2020-01-18 04:45:55 +00:00
if ( thing - > sprite = = SPR_HOOP )
{
if ( hoop_limit_dist & & approx_dist > hoop_limit_dist )
return false ;
}
else
{
if ( limit_dist & & approx_dist > limit_dist )
return false ;
}
return true ;
}
/* Check if precipitation may be drawn from our current view. */
boolean R_PrecipThingVisible ( precipmobj_t * precipthing ,
fixed_t limit_dist )
{
fixed_t approx_dist ;
if ( ( precipthing - > precipflags & PCF_INVISIBLE ) )
return false ;
2021-02-13 16:45:20 +00:00
approx_dist = P_AproxDistance ( viewx - precipthing - > x , viewy - precipthing - > y ) ;
2020-01-18 04:45:55 +00:00
return ( approx_dist < = limit_dist ) ;
}
2020-10-12 03:13:22 +00:00
boolean R_ThingHorizontallyFlipped ( mobj_t * thing )
{
return ( thing - > frame & FF_HORIZONTALFLIP | | thing - > renderflags & RF_HORIZONTALFLIP ) ;
}
boolean R_ThingVerticallyFlipped ( mobj_t * thing )
{
return ( thing - > frame & FF_VERTICALFLIP | | thing - > renderflags & RF_VERTICALFLIP ) ;
}
boolean R_ThingIsPaperSprite ( mobj_t * thing )
{
return ( thing - > frame & FF_PAPERSPRITE | | thing - > renderflags & RF_PAPERSPRITE ) ;
}
boolean R_ThingIsFloorSprite ( mobj_t * thing )
{
2021-11-15 17:03:07 +00:00
return ( thing - > flags2 & MF2_SPLAT | | thing - > frame & FF_FLOORSPRITE | | thing - > renderflags & RF_FLOORSPRITE ) ;
2020-10-12 03:13:22 +00:00
}
2020-11-05 00:43:16 +00:00
boolean R_ThingIsFullBright ( mobj_t * thing )
2020-10-12 03:13:22 +00:00
{
2021-11-15 17:03:07 +00:00
return ( ( thing - > frame & FF_BRIGHTMASK ) = = FF_FULLBRIGHT | | ( thing - > renderflags & RF_BRIGHTMASK ) = = RF_FULLBRIGHT ) ;
}
boolean R_ThingIsSemiBright ( mobj_t * thing )
{
return ( ( thing - > frame & FF_BRIGHTMASK ) = = FF_SEMIBRIGHT | | ( thing - > renderflags & RF_BRIGHTMASK ) = = RF_SEMIBRIGHT ) ;
2020-10-12 03:13:22 +00:00
}
2020-11-05 00:43:16 +00:00
boolean R_ThingIsFullDark ( mobj_t * thing )
2020-10-12 03:13:22 +00:00
{
2021-11-15 17:03:07 +00:00
return ( ( thing - > frame & FF_BRIGHTMASK ) = = FF_FULLDARK | | ( thing - > renderflags & RF_BRIGHTMASK ) = = RF_FULLDARK ) ;
2020-10-12 03:13:22 +00:00
}
2023-05-29 14:37:48 +00:00
// Offsets MT_OVERLAY towards the camera at render-time - Works in splitscreen!
// The &x and &y arguments should be pre-interpolated, and will be modified
void R_ThingOffsetOverlay ( mobj_t * thing , fixed_t * x , fixed_t * y )
{
mobj_t * mobj = thing ;
INT16 offset = 0 ; // Offset towards or away from the camera, and how much
fixed_t offsetscale = thing - > scale ; // Occasionally needs to be interpolated
angle_t viewingangle ;
UINT8 looplimit = 255 ; // Prevent infinite loops - A chain of 255 connected overlays is enough for any sane use case
# ifdef PARANOIA
if ( P_MobjWasRemoved ( mobj ) | | ! x | | ! y )
I_Error ( " R_ThingOffsetOverlay: thing, x, or y is invalid " ) ;
# endif
do // Get the overlay's offset
{
// Does the overlay use FF_ANIMATE? If not, if var1 is non-zero, it's an underlay instead of an overlay
if ( ! ( mobj - > state - > frame & FF_ANIMATE ) & & mobj - > state - > var1 )
offset + = 1 ; // Underlay below the target, away from the camera
else
offset - = 1 ; // Overlay on top of the target, towards the camera
looplimit - = 1 ;
mobj = mobj - > target ;
} while ( ! P_MobjWasRemoved ( mobj ) & & mobj - > type = = MT_OVERLAY & & looplimit > 0 ) ; // Handle overlays following other overlays
// Does the offset scale need to be interpolated?
if ( thing - > scale ! = thing - > old_scale & & R_UsingFrameInterpolation ( ) & & ! paused )
{
interpmobjstate_t interp = { 0 } ;
R_InterpolateMobjState ( thing , rendertimefrac , & interp ) ;
offsetscale = interp . scale ;
}
// Get the angle from the camera to the X and Y coordinates
viewingangle = R_PointToAngle ( * x , * y ) ;
// Finally, offset the X and Y coordinates towards or away from the camera
* x + = P_ReturnThrustX ( thing , viewingangle , FixedMul ( offset * ( FRACUNIT / 4 ) , offsetscale ) ) ;
* y + = P_ReturnThrustY ( thing , viewingangle , FixedMul ( offset * ( FRACUNIT / 4 ) , offsetscale ) ) ;
}
2014-03-15 16:59:03 +00:00
//
// R_DrawMasked
//
2019-06-04 18:15:42 +00:00
static void R_DrawMaskedList ( drawnode_t * head )
2014-03-15 16:59:03 +00:00
{
drawnode_t * r2 ;
drawnode_t * next ;
2019-06-04 18:15:42 +00:00
for ( r2 = head - > next ; r2 ! = head ; r2 = r2 - > next )
2014-03-15 16:59:03 +00:00
{
if ( r2 - > plane )
{
next = r2 - > prev ;
R_DrawSinglePlane ( r2 - > plane ) ;
R_DoneWithNode ( r2 ) ;
r2 = next ;
}
else if ( r2 - > seg & & r2 - > seg - > maskedtexturecol ! = NULL )
{
next = r2 - > prev ;
R_RenderMaskedSegRange ( r2 - > seg , r2 - > seg - > x1 , r2 - > seg - > x2 ) ;
r2 - > seg - > maskedtexturecol = NULL ;
R_DoneWithNode ( r2 ) ;
r2 = next ;
}
else if ( r2 - > thickseg )
{
next = r2 - > prev ;
R_RenderThickSideRange ( r2 - > thickseg , r2 - > thickseg - > x1 , r2 - > thickseg - > x2 , r2 - > ffloor ) ;
R_DoneWithNode ( r2 ) ;
r2 = next ;
}
else if ( r2 - > sprite )
{
next = r2 - > prev ;
// Tails 08-18-2002
2017-06-26 13:44:10 +00:00
if ( r2 - > sprite - > cut & SC_PRECIP )
2014-03-15 16:59:03 +00:00
R_DrawPrecipitationSprite ( r2 - > sprite ) ;
2017-06-25 19:46:30 +00:00
else if ( ! r2 - > sprite - > linkdraw )
2014-03-15 16:59:03 +00:00
R_DrawSprite ( r2 - > sprite ) ;
2017-06-25 19:46:30 +00:00
else // unbundle linkdraw
{
2017-06-26 13:44:10 +00:00
vissprite_t * ds = r2 - > sprite - > linkdraw ;
2017-06-25 19:46:30 +00:00
2017-06-26 13:44:10 +00:00
for ( ;
2022-11-01 21:56:52 +00:00
( ds ! = NULL & & r2 - > sprite - > dispoffset > ds - > dispoffset ) ;
ds = ds - > next )
{
2017-06-26 13:44:10 +00:00
R_DrawSprite ( ds ) ;
2022-11-01 21:56:52 +00:00
}
2017-06-26 13:44:10 +00:00
R_DrawSprite ( r2 - > sprite ) ;
2017-06-25 19:46:30 +00:00
2022-11-01 21:56:52 +00:00
for ( ;
ds ! = NULL ;
ds = ds - > next )
{
2017-06-25 19:46:30 +00:00
R_DrawSprite ( ds ) ;
2022-11-01 21:56:52 +00:00
}
2017-06-25 19:46:30 +00:00
}
2014-03-15 16:59:03 +00:00
R_DoneWithNode ( r2 ) ;
r2 = next ;
}
}
2019-06-04 18:15:42 +00:00
}
2022-01-25 02:53:09 +00:00
void R_DrawMasked ( maskcount_t * masks , INT32 nummasks )
2019-06-04 18:15:42 +00:00
{
2019-07-29 23:02:45 +00:00
drawnode_t * heads ; /**< Drawnode lists; as many as number of views/portals. */
2022-01-25 02:53:09 +00:00
INT32 i ;
2019-06-04 18:15:42 +00:00
2019-07-29 23:02:45 +00:00
heads = calloc ( nummasks , sizeof ( drawnode_t ) ) ;
2019-06-04 18:15:42 +00:00
for ( i = 0 ; i < nummasks ; i + + )
{
heads [ i ] . next = heads [ i ] . prev = & heads [ i ] ;
2019-06-06 11:30:50 +00:00
viewx = masks [ i ] . viewx ;
viewy = masks [ i ] . viewy ;
2019-06-05 10:10:59 +00:00
viewz = masks [ i ] . viewz ;
2019-06-06 11:30:50 +00:00
viewsector = masks [ i ] . viewsector ;
2019-06-05 10:10:59 +00:00
R_CreateDrawNodes ( & masks [ i ] , & heads [ i ] , false ) ;
2019-06-04 18:15:42 +00:00
}
2019-06-05 14:35:48 +00:00
//for (i = 0; i < nummasks; i++)
// CONS_Printf("Mask no.%d:\ndrawsegs: %d\n vissprites: %d\n\n", i, masks[i].drawsegs[1] - masks[i].drawsegs[0], masks[i].vissprites[1] - masks[i].vissprites[0]);
2019-06-04 18:15:42 +00:00
for ( ; nummasks > 0 ; nummasks - - )
{
2019-06-06 11:30:50 +00:00
viewx = masks [ nummasks - 1 ] . viewx ;
viewy = masks [ nummasks - 1 ] . viewy ;
2019-06-05 10:10:59 +00:00
viewz = masks [ nummasks - 1 ] . viewz ;
2019-06-06 11:30:50 +00:00
viewsector = masks [ nummasks - 1 ] . viewsector ;
2019-06-05 14:35:48 +00:00
2019-06-04 18:15:42 +00:00
R_DrawMaskedList ( & heads [ nummasks - 1 ] ) ;
R_ClearDrawNodes ( & heads [ nummasks - 1 ] ) ;
}
2019-07-29 23:02:45 +00:00
free ( heads ) ;
2014-03-15 16:59:03 +00:00
}