Skip to content

Commit

Permalink
Further correct view pitch as FOV changes
Browse files Browse the repository at this point in the history
Additionally, some reformatting.
  • Loading branch information
MrAlaux committed Nov 22, 2023
1 parent c26d01a commit 25f9410
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

## Bug Fixes

- **Further corrected view pitch as FOV changes**
- **Disabled teleport-to-Automap-pointer during non-Casual Play**
- **Excess speed when airborne with noclip enabled** [thanks @kitchen-ace]
- **Teleporter Zoom and BFG "explosion" shake affecting all players in multiplayer**
Expand Down
4 changes: 2 additions & 2 deletions src/r_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#define MAXFOV 160

#define LOOKDIRMAX 100
#define LOOKDIRMAX2 (LOOKDIRMAX+24) // [Nugget]
#define PITCHMAX (LOOKDIRMAX+24) // [Nugget] Accommodate pitch effects (e.g. recoil)
// [crispy] lookdir range: -100..100
// [Nugget] Increased to accommodate variable FOV
#define LOOKDIRS ((2*LOOKDIRMAX2+1)*ORIGFOV/MINFOV)
#define LOOKDIRS ((2*PITCHMAX+1) * ORIGFOV / (MINFOV-2))
#define MLOOKUNIT 8

// Retrieve column data for span blitting.
Expand Down
73 changes: 38 additions & 35 deletions src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,16 @@ lighttable_t **colormaps;
int extralight; // bumped light from gun blasts
int extra_level_brightness; // level brightness feature

// [Nugget] FOV from Doom Retro /------
// [Nugget] FOV from Doom Retro /---------------------------------------------

boolean fovchange = true;
static int bfov; // Base FOV
static int rfov; // Rendered (currently applied) FOV, with effects added to it
float fovdiff; // Used for some corrections
#define FOVDIFF2 (fovdiff + ((fovdiff - 1.0) * ((fovdiff < 1.0) ? 0.5 : 0.22)))

static fixed_t fovscale;
static int lookdirmax;
static int pitchmax;

static fovfx_t fovfx[NUMFOVFX]; // FOV effects (recoil, teleport)
static int zoomed = 0; // Current zoom state
Expand Down Expand Up @@ -175,9 +176,9 @@ void R_SetZoom(const int state)
{ zoomed = ZOOM_OFF; }
}

// [Nugget] --------------------------/
// [Nugget] -----------------------------------------------------------------/

// [Nugget] Explosion shake effect /---------------------------------
// [Nugget] Explosion shake effect /------------------------------------------

static fixed_t shake;
#define MAXSHAKE 50
Expand Down Expand Up @@ -219,7 +220,7 @@ void R_ExplosionShake(fixed_t bombx, fixed_t bomby, int force, int range)
#undef SHAKERANGEMULT
}

// [Nugget] --------------------------------------------------------/
// [Nugget] -----------------------------------------------------------------/

void (*colfunc)(void) = R_DrawColumn; // current column draw function

Expand Down Expand Up @@ -603,7 +604,8 @@ void R_ExecuteSetViewSize (void)
viewblocks = MIN(setblocks, 10) << hires;

// [Nugget] FOV changes
if (fovchange) {
if (fovchange)
{
static int oldtic = -1;
int fx = 0;
int zoomtarget;
Expand All @@ -629,26 +631,31 @@ void R_ExecuteSetViewSize (void)
else for (i = 0; i < NUMFOVFX; i++)
if (fovfx[i].target || fovfx[i].current) { fovchange = true; }
}

if (fovchange) {

if (fovchange)
{
if (oldtic != gametic)
{
fovchange = false;

fovfx[FOVFX_ZOOM].old = fovfx[FOVFX_ZOOM].current = fovfx[FOVFX_ZOOM].target;
if (zoomtarget || fovfx[FOVFX_ZOOM].target) { // Special handling for zoom
if (zoomtarget || fovfx[FOVFX_ZOOM].target)
{
// Special handling for zoom
int step = zoomtarget - fovfx[FOVFX_ZOOM].target;
const int sign = ((step > 0) ? 1 : -1);
step = BETWEEN(2, 16, abs(step) / 4);

fovfx[FOVFX_ZOOM].target += step*sign;
if ( (sign > 0 && fovfx[FOVFX_ZOOM].target > zoomtarget)
||(sign < 0 && fovfx[FOVFX_ZOOM].target < zoomtarget))

if ( (sign > 0 && fovfx[FOVFX_ZOOM].target > zoomtarget)
|| (sign < 0 && fovfx[FOVFX_ZOOM].target < zoomtarget))
{ fovfx[FOVFX_ZOOM].target = zoomtarget; }

if (fovfx[FOVFX_ZOOM].current != fovfx[FOVFX_ZOOM].target)
{ fovchange = true; }
}

fovfx[FOVFX_TELEPORT].old = fovfx[FOVFX_TELEPORT].current = fovfx[FOVFX_TELEPORT].target;
if (fovfx[FOVFX_TELEPORT].target)
{
Expand All @@ -662,24 +669,23 @@ void R_ExecuteSetViewSize (void)
for (i = 0; i < NUMFOVFX; i++)
{ fovfx[i].current = fovfx[i].old + ((fovfx[i].target - fovfx[i].old) * ((float) fractionaltic/FRACUNIT)); }
}

oldtic = gametic;

for (i = 0; i < NUMFOVFX; i++)
{ fx += fovfx[i].current; }

rfov = bfov + fx;
fovdiff = (float) ORIGFOV / rfov;
lookdirmax = LOOKDIRMAX2 * fovdiff;
pitchmax = PITCHMAX * FOVDIFF2; // Mitigate `PLAYER_SLOPE()` and `lookdir` misalignment
}

// [Nugget] FOV from Doom Retro
if (widescreen) {
// fov * 0.82 is vertical FOV for 4:3 aspect ratio
WIDEFOVDELTA = (atan(SCREENWIDTH / ((SCREENHEIGHT * 1.2) / tan(rfov * 0.82 * M_PI / 360.0))) * 360.0 / M_PI) - rfov;
}
else
{ WIDEFOVDELTA = 0; }
else { WIDEFOVDELTA = 0; }

centery = viewheight/2;
centerx = viewwidth/2;
Expand Down Expand Up @@ -710,12 +716,11 @@ void R_ExecuteSetViewSize (void)
for (j = 0; j < LOOKDIRS; j++)
{
// [crispy] re-generate lookup-table for yslope[] whenever "viewheight" or "hires" change
// [Nugget] Mitigate PLAYER_SLOPE() and 'lookdir' misalignment
fixed_t dy = abs(((i-viewheight/2-(j-lookdirmax)*viewblocks/10)<<FRACBITS)+FRACUNIT/2);
fixed_t dy = abs(((i-viewheight/2-(j-pitchmax)*viewblocks/10)<<FRACBITS)+FRACUNIT/2);
yslopes[j][i] = FixedDiv(num, dy);
}
}
yslope = yslopes[lookdirmax]; // [Nugget] Mitigate PLAYER_SLOPE() and 'lookdir' misalignment
yslope = yslopes[pitchmax];

for (i=0 ; i<viewwidth ; i++)
{
Expand Down Expand Up @@ -870,8 +875,8 @@ void R_SetupFrame (player_t *player)
pitch = lookdir + player->recoilpitch + player->impactpitch; // [Nugget]
}

// [Nugget] Mitigate PLAYER_SLOPE() and 'lookdir' misalignment
pitch *= fovdiff;
// [Nugget] Mitigate `PLAYER_SLOPE()` and `lookdir` misalignment
pitch *= FOVDIFF2;

// [Nugget] Explosion shake effect
chasecamheight = chasecam_height * FRACUNIT;
Expand All @@ -882,7 +887,7 @@ void R_SetupFrame (player_t *player)
if (!(menuactive || paused))
{
static int oldtime = -1;

#define CALCSHAKE (((Woof_Random() - 128) % 3) * FRACUNIT) * shake / MAXSHAKE
xofs = CALCSHAKE;
yofs = CALCSHAKE;
Expand Down Expand Up @@ -932,7 +937,7 @@ void R_SetupFrame (player_t *player)
oldtic = gametic;
}

P_PositionChasecam(z, dist, slope = ((-(lookdir * FRACUNIT) / PLAYER_SLOPE_DENOM) / fovdiff));
P_PositionChasecam(z, dist, slope = (-(lookdir * FRACUNIT) / PLAYER_SLOPE_DENOM));

if (chasecam.hit) {
viewx = chasecam.x;
Expand Down Expand Up @@ -964,8 +969,7 @@ void R_SetupFrame (player_t *player)
chaseyofs = viewy - oldviewy;
chaseaofs = viewangle - oldviewangle;
}
else
{ chasexofs = chaseyofs = chaseaofs = 0; }
else { chasexofs = chaseyofs = chaseaofs = 0; }

// [Nugget]: [crispy] A11Y
if (!NOTSTRICTMODE(a11y_weapon_flash))
Expand All @@ -975,19 +979,18 @@ void R_SetupFrame (player_t *player)

extralight += STRICTMODE(LIGHTBRIGHT * extra_level_brightness); // level brightness feature

// [Nugget] Mitigate PLAYER_SLOPE() and 'lookdir' misalignment
if (pitch > lookdirmax)
pitch = lookdirmax;
else if (pitch < -lookdirmax)
pitch = -lookdirmax;
if (pitch > pitchmax)
pitch = pitchmax;
else if (pitch < -pitchmax)
pitch = -pitchmax;

// apply new yslope[] whenever "lookdir", "viewheight" or "hires" change
tempCentery = viewheight/2 + pitch * viewblocks / 10;
if (centery != tempCentery)
{
centery = tempCentery;
centeryfrac = centery << FRACBITS;
yslope = yslopes[lookdirmax + pitch]; // [Nugget] Mitigate PLAYER_SLOPE() and 'lookdir' misalignment
yslope = yslopes[pitchmax + pitch];
}

viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
Expand Down

0 comments on commit 25f9410

Please sign in to comment.