Skip to content

Commit

Permalink
Fix crosshair not being drawn in some cases
Browse files Browse the repository at this point in the history
Specifically, fixed crosshair not being drawn if the chasecam mode were set even if the chasecam itself were disabled.

Additionally, some refactoring, and added a missing comment.
  • Loading branch information
MrAlaux committed May 25, 2024
1 parent a49a6af commit e445c9c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

## Bug Fixes

None.
- **Crosshair not being drawn if the chasecam mode were set** even if the chasecam itself were disabled
2 changes: 1 addition & 1 deletion src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void D_Display (void)
st_crispyhud = (hud_type == HUD_TYPE_CRISPY) && hud_displayed && automap_off
&& hud_active > 0; // [Nugget] NUGHUD

input_ready = (!menuactive && ((gamestate == GS_LEVEL && !paused) || R_GetFreecamOn()));
input_ready = (!menuactive && ((gamestate == GS_LEVEL && !paused) || R_GetFreecamOn())); // [Nugget] Freecam

if (uncapped)
{
Expand Down
2 changes: 1 addition & 1 deletion src/hu_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ void HU_DrawCrosshair(void)
// Crash fix
!crosshair.cr ||
// Chasecam
(chasecam_mode && !chasecam_crosshair) ||
(R_GetChasecamOn() && !chasecam_crosshair) ||
// Freecam
(R_GetFreecamOn() && (R_GetFreecamMode() != FREECAM_CAM || R_GetFreecamMobj())) ||
// Alt. intermission background
Expand Down
24 changes: 13 additions & 11 deletions src/p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,23 +2118,25 @@ static boolean PTR_ChasecamTraverse(intercept_t *in)
}

// Hit line
chasecam.hit = true;
R_SetChasecamHit(true);

// Position a bit closer
frac = in->frac - FixedDiv(FRACUNIT, attackrange);
chasecam.x = trace.x + FixedMul(trace.dx, frac);
chasecam.y = trace.y + FixedMul(trace.dy, frac);
chasecam.z = shootz + FixedMul(aimslope, FixedMul(frac, attackrange));
fixed_t x = trace.x + FixedMul(trace.dx, frac);
fixed_t y = trace.y + FixedMul(trace.dy, frac);
fixed_t z = shootz + FixedMul(aimslope, FixedMul(frac, attackrange));

sec = R_PointInSubsector(chasecam.x, chasecam.y)->sector;
sec = R_PointInSubsector(x, y)->sector;

if (chasecam.z < sec->floorheight+FRACUNIT || sec->ceilingheight-FRACUNIT < chasecam.z)
if (z < sec->floorheight+FRACUNIT || sec->ceilingheight-FRACUNIT < z)
{
chasecam.z = BETWEEN(sec->floorheight+FRACUNIT, sec->ceilingheight-FRACUNIT, chasecam.z);
frac = FixedDiv(chasecam.z - shootz, FixedMul(aimslope, attackrange));
chasecam.x = trace.x + FixedMul(trace.dx, frac);
chasecam.y = trace.y + FixedMul(trace.dy, frac);
z = BETWEEN(sec->floorheight+FRACUNIT, sec->ceilingheight-FRACUNIT, z);
frac = FixedDiv(z - shootz, FixedMul(aimslope, attackrange));
x = trace.x + FixedMul(trace.dx, frac);
y = trace.y + FixedMul(trace.dy, frac);
}

R_UpdateChasecam(x, y, z);
}

// Don't go any further
Expand All @@ -2153,7 +2155,7 @@ void P_PositionChasecam(fixed_t z, fixed_t dist, fixed_t slope)
shootz = z;
attackrange = dist;
aimslope = slope;
chasecam.hit = false;
R_SetChasecamHit(false);

overflow[emu_intercepts].enabled = false;
P_PathTraverse(viewx, viewy, x2, y2, PT_ADDLINES, PTR_ChasecamTraverse);
Expand Down
23 changes: 22 additions & 1 deletion src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,34 @@ void R_ExplosionShake(fixed_t bombx, fixed_t bomby, int force, int range)

// Chasecam -----------------------------------------------

chasecam_t chasecam;
static struct {
fixed_t x, y, z;
boolean hit;
} chasecam;

boolean chasecam_on = false;

// For Automap
fixed_t chasexofs, chaseyofs;
angle_t chaseaofs;

boolean R_GetChasecamOn(void)
{
return chasecam_on;
}

void R_SetChasecamHit(const boolean value)
{
chasecam.hit = value;
}

void R_UpdateChasecam(fixed_t x, fixed_t y, fixed_t z)
{
chasecam.x = x;
chasecam.y = y;
chasecam.z = z;
}

// Freecam ------------------------------------------------

static boolean freecam_on = false;
Expand Down Expand Up @@ -1228,6 +1248,7 @@ void R_SetupFrame (player_t *player)
// Chasecam -------------------------

chasecam_on = STRICTMODE(chasecam_mode || (death_camera && player->mo->health <= 0 && player->playerstate == PST_DEAD))
&& !(freecam_on && !freecam.mobj)
&& !(WI_UsingAltInterpic() && (gamestate == GS_INTERMISSION));

if (chasecam_on)
Expand Down
11 changes: 3 additions & 8 deletions src/r_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,9 @@ extern void R_ExplosionShake(fixed_t bombx, fixed_t bomby, int force, int range)

// Chasecam -----------------------------------------------

typedef struct chasecam_s {
fixed_t x, y, z;
boolean hit;
} chasecam_t;

extern chasecam_t chasecam;

extern boolean chasecam_on;
extern boolean R_GetChasecamOn(void);
extern void R_SetChasecamHit(const boolean value);
extern void R_UpdateChasecam(fixed_t x, fixed_t y, fixed_t z);

// Freecam ------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions src/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void R_ProjectSprite (mobj_t* thing)
fixed_t interpx, interpy, interpz, interpangle;

// [Nugget] Freecam
if (thing == R_GetFreecamMobj() && !chasecam_on)
if (thing == R_GetFreecamMobj() && !R_GetChasecamOn())
{ return; }

// andrewj: voxel support
Expand Down Expand Up @@ -900,7 +900,7 @@ void R_DrawPSprite (pspdef_t *psp, boolean translucent) // [Nugget] Translucent

if (STRICTMODE(hide_weapon)
// [Nugget]
|| chasecam_on // Chasecam
|| R_GetChasecamOn() // Chasecam
|| R_GetFreecamOn() // Freecam
|| (WI_UsingAltInterpic() && (gamestate == GS_INTERMISSION))) // Alt. intermission background
return;
Expand Down
2 changes: 1 addition & 1 deletion src/r_voxel.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ boolean VX_ProjectVoxel (mobj_t * thing)

// skip the player thing we are viewing from
// [Nugget] Unless using chasecam or freecam
if (thing->player == viewplayer && !(chasecam_on || R_GetFreecamOn()))
if (thing->player == viewplayer && !(R_GetChasecamOn() || R_GetFreecamOn()))
return true;

// does the voxel model exist?
Expand Down

0 comments on commit e445c9c

Please sign in to comment.