diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 203c62432..967d52cc5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4437,7 +4437,10 @@ static void HWR_ProjectSprite(mobj_t *thing) boolean mirrored; boolean hflip; - angle_t ang, camang; + angle_t ang = 0; +#ifdef ROTSPRITE + angle_t camang = 0; +#endif boolean papersprite; INT32 heightsec, phs; INT32 dist = -1; @@ -4447,7 +4450,7 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE patch_t *rotsprite = NULL; INT32 rollangle = 0; - angle_t rollsum = 0; + angle_t pitchnroll = 0; angle_t sliptiderollangle = 0; #endif @@ -4502,7 +4505,12 @@ static void HWR_ProjectSprite(mobj_t *thing) I_Error("HWR_ProjectSprite: invalid sprite number %i ", thing->sprite); #endif - rot = thing->frame&FF_FRAMEMASK; + rot = (thing->frame & FF_FRAMEMASK); + +#ifdef ROTSPRITE + // determine here if sprite should rotate for optimization + const boolean shouldrotate = (cv_spriteroll.value && (interp.roll || interp.pitch || interp.sloperoll || interp.slopepitch || thing->rollangle)); +#endif //Fab : 02-08-98: 'skin' override spritedef currently used for skin if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) @@ -4530,7 +4538,7 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE sprinfo = &spriteinfo[thing->sprite]; #endif - rot = thing->frame&FF_FRAMEMASK; + rot = (thing->frame & FF_FRAMEMASK); thing->state->sprite = thing->sprite; thing->state->frame = thing->frame; } @@ -4543,7 +4551,13 @@ static void HWR_ProjectSprite(mobj_t *thing) #endif ang = R_PointToAngle (interp.x, interp.y) - interp.angle; - camang = R_PointToAngle (interp.x, interp.y); + +#ifdef ROTSPRITE + if (shouldrotate) + { + camang = R_PointToAngle (interp.x, interp.y); + } +#endif if (mirrored) ang = InvAngle(ang); @@ -4585,33 +4599,40 @@ static void HWR_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lumpoff].topoffset; #ifdef ROTSPRITE - if (cv_spriteroll.value) + if (shouldrotate) { - rollangle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp.roll) - + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp.pitch) - + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp.sloperoll) - + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp.slopepitch) - + thing->rollangle; - - if ((rollangle)||(thing->player && thing->player->sliproll)) + if (papersprite) { - if (thing->player) + // a positive rollangle should should pitch papersprites upwards relative to their facing angle + rollangle = InvAngle(thing->rollangle); + } + else + { + // this is very messy, but it on-the-fly calculates rotations for all the + // pitch and roll variables + pitchnroll = R_RotationAngle(ang, camang, &interp); + rollangle = thing->rollangle; + } + + if (rollangle || pitchnroll || (thing->player && thing->player->sliproll)) + { + if (thing->player && cv_sliptideroll.value) { - sliptiderollangle = cv_sliptideroll.value ? thing->player->sliproll*(thing->player->sliptidemem) : 0; - rollsum = rollangle+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + sliptiderollangle = thing->player->sliproll * (thing->player->sliptidemem); + pitchnroll += rollangle + FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); } else - rollsum = rollangle; + pitchnroll += rollangle; // this is kinda dumb lkmao, but try to mitigate shadows being weirdly offset on slopes if (thing->type == MT_SHADOW) { sprinfo->available = true; // < lmao sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].x = spr_offset>>FRACBITS; - sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].y = -8; // noones gonna replace shadow sprite anyways, right? that random value ftw, otherwise this clips into the ground Zzz... + sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].y = -8; // noones gonna replace shadow sprite anyways, right? this random value works, cant get any better otherwise this clips into the ground Zzz... } - rollangle = R_GetRollAngle(rollsum); + rollangle = R_GetRollAngle(pitchnroll); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); if (rotsprite != NULL) @@ -4718,7 +4739,7 @@ static void HWR_ProjectSprite(mobj_t *thing) vis->spriteyoffset = FIXED_TO_FLOAT(spr_topoffset); #ifdef ROTSPRITE - if ((rotsprite) && (cv_spriteroll.value)) + if (rotsprite && cv_spriteroll.value) vis->gpatch = (GLPatch_t *)rotsprite; else #endif diff --git a/src/r_patch.c b/src/r_patch.c index 37e7a2321..ae8ec4f5e 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -17,6 +17,7 @@ #include "i_video.h" #include "r_data.h" #include "r_draw.h" +#include "r_fps.h" #include "r_patch.h" #include "r_things.h" #include "z_zone.h" @@ -803,6 +804,14 @@ INT32 R_GetRollAngle(angle_t rollangle) return ra; } +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp) +{ + return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch); +} + patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, boolean adjustfeet, void *info, INT32 rotationangle) { rotsprite_t *rotsprite; diff --git a/src/r_patch.h b/src/r_patch.h index ac8072a43..5edaa46fb 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -15,6 +15,7 @@ #define __R_PATCH__ #include "r_defs.h" +#include "r_fps.h" #include "doomdef.h" // Structs @@ -53,6 +54,8 @@ void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); // Sprite rotation #ifdef ROTSPRITE INT32 R_GetRollAngle(angle_t rollangle); +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp); + patch_t *Patch_GetRotatedSprite( spriteframe_t *sprite, size_t frame, size_t spriteangle, diff --git a/src/r_things.c b/src/r_things.c index f3c698b9d..1e8c33d32 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1142,7 +1142,9 @@ static void R_ProjectSprite(mobj_t *thing) vissprite_t *vis; angle_t ang = 0; // gcc 4.6 and lower fix +#ifdef ROTSPRITE angle_t camang = 0; +#endif fixed_t iscale; fixed_t scalestep; // toast '16 fixed_t offset, offset2; @@ -1163,7 +1165,6 @@ static void R_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE patch_t *rotsprite = NULL; INT32 rollangle = 0; - angle_t rollsum = 0; angle_t pitchnroll = 0; angle_t sliptiderollangle = 0; #endif @@ -1219,7 +1220,12 @@ static void R_ProjectSprite(mobj_t *thing) I_Error("R_ProjectSprite: invalid sprite number %d ", thing->sprite); #endif - rot = thing->frame&FF_FRAMEMASK; + rot = (thing->frame & FF_FRAMEMASK); + +#ifdef ROTSPRITE + // determine here if sprite should rotate for optimization + const boolean shouldrotate = (cv_spriteroll.value && (interp.roll || interp.pitch || interp.sloperoll || interp.slopepitch || thing->rollangle)); +#endif //Fab : 02-08-98: 'skin' override spritedef currently used for skin if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) @@ -1250,7 +1256,7 @@ static void R_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE sprinfo = &spriteinfo[thing->sprite]; #endif - rot = thing->frame&FF_FRAMEMASK; + rot = (thing->frame & FF_FRAMEMASK); if (!thing->skin) { thing->state->sprite = thing->sprite; @@ -1265,10 +1271,18 @@ static void R_ProjectSprite(mobj_t *thing) I_Error("R_ProjectSprite: sprframes NULL for sprite %d\n", thing->sprite); #endif - if (sprframe->rotate != SRF_SINGLE || papersprite || (cv_sloperoll.value == 2 && cv_spriteroll.value)) + if (sprframe->rotate != SRF_SINGLE || papersprite || +#ifdef ROTSPRITE + (shouldrotate) +#endif + ) { ang = R_PointToAngle (interp.x, interp.y) - interp.angle; - camang = R_PointToAngle (interp.x, interp.y); + +#ifdef ROTSPRITE + if (shouldrotate) + camang = R_PointToAngle (interp.x, interp.y); +#endif if (mirrored) ang = InvAngle(ang); @@ -1311,9 +1325,7 @@ static void R_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lump].topoffset; #ifdef ROTSPRITE - pitchnroll = 0; // set this to 0, non-paper sprites will affect this value - - if (cv_spriteroll.value) + if (shouldrotate) { if (papersprite) { @@ -1331,29 +1343,29 @@ static void R_ProjectSprite(mobj_t *thing) { // this is very messy, but it on-the-fly calculates rotations for all the // pitch and roll variables - pitchnroll = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp.roll) + - FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp.pitch) + - FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp.sloperoll) + - FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp.slopepitch); - + pitchnroll = R_RotationAngle(ang, camang, &interp); rollangle = thing->rollangle; } if (rollangle || pitchnroll || (thing->player && thing->player->sliproll)) { - rollsum = pitchnroll; - - if (thing->player) + if (thing->player && cv_sliptideroll.value) { - sliptiderollangle = - cv_sliptideroll.value ? thing->player->sliproll * (thing->player->sliptidemem) : 0; - rollsum += thing->rollangle + - FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + sliptiderollangle = thing->player->sliproll * (thing->player->sliptidemem); + pitchnroll += rollangle + FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); } else - rollsum += thing->rollangle; + pitchnroll += rollangle; - rollangle = R_GetRollAngle(rollsum); + // this is kinda dumb lkmao, but try to mitigate shadows being weirdly offset on slopes + if (thing->type == MT_SHADOW) + { + sprinfo->available = true; // < lmao + sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].x = spr_offset>>FRACBITS; + sprinfo->pivot[(thing->frame & FF_FRAMEMASK)].y = -12; // noones gonna replace shadow sprite anyways, right? + } + + rollangle = R_GetRollAngle(pitchnroll); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); if (rotsprite != NULL)