From a75c38eda98fa2689593eb7dc2fccb9826798595 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Wed, 14 Dec 2022 10:05:54 +0100 Subject: [PATCH] Crosshair lock fixes (#844) * draw crosshair before weapon sprites to make sure they don't overlap * prevent tracking targets out of view * restrict crosshair coordinates to view window * Gosh, widescreen * fix up signs --- src/hu_stuff.c | 11 ++++------- src/hu_stuff.h | 1 + src/r_things.c | 31 ++++++++++++++++++------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f88d5dba..da0780d7 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -42,6 +42,7 @@ #include "p_map.h" // crosshair (linetarget) #include "m_misc2.h" #include "m_swap.h" +#include "r_main.h" // global heads up display controls @@ -1087,11 +1088,11 @@ static void HU_UpdateCrosshair(void) void HU_UpdateCrosshairLock(int x, int y) { - crosshair.x += x; - crosshair.y += y; + crosshair.x = ((viewwindowx + x) >> hires) - WIDESCREENDELTA; + crosshair.y = ((viewwindowy + y) >> hires); } -static void HU_DrawCrosshair(void) +void HU_DrawCrosshair(void) { if (plr->playerstate != PST_LIVE || automapactive || @@ -1724,10 +1725,6 @@ void HU_Drawer(void) // display the interactive buffer for chat entry HUlib_drawIText(&w_chat); - - // display crosshair - if (hud_crosshair) - HU_DrawCrosshair(); } // [FG] draw Time widget on intermission screen diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 98c3f2c4..dd038b39 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -108,6 +108,7 @@ extern crosstarget_t hud_crosshair_target; extern boolean hud_crosshair_lockon; extern mobj_t *crosshair_target; void HU_UpdateCrosshairLock(int x, int y); +void HU_DrawCrosshair(void); extern int hud_crosshair_color; extern int hud_crosshair_target_color; diff --git a/src/r_things.c b/src/r_things.c index 6b2d9df6..f9e8d218 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -452,7 +452,7 @@ boolean flipcorpses = false; void R_ProjectSprite (mobj_t* thing) { fixed_t gzt; // killough 3/27/98 - fixed_t tx; + fixed_t tx, txc; fixed_t xscale; int x1; int x2; @@ -549,18 +549,7 @@ void R_ProjectSprite (mobj_t* thing) flip = !flip; } - // [Alaux] Lock crosshair on target - if (STRICTMODE(hud_crosshair_lockon) && thing == crosshair_target) - { - HU_UpdateCrosshairLock - ( - FixedMul(tx, xscale >> hires) >> FRACBITS, - (FixedMul(viewz - (interpz + crosshair_target->height/2), xscale >> hires) >> FRACBITS) - + (viewplayer->lookdir / MLOOKUNIT + viewplayer->recoilpitch) - ); - - crosshair_target = NULL; // Don't update it again until next tic - } + txc = tx; // [FG] sprite center coordinate // calculate edges of the shape // [crispy] fix sprite offsets for mirrored sprites @@ -655,6 +644,18 @@ void R_ProjectSprite (mobj_t* thing) vis->colormap[1] = fullcolormap; } vis->brightmap = R_BrightmapForSprite(thing->sprite); + + // [Alaux] Lock crosshair on target + if (STRICTMODE(hud_crosshair_lockon) && thing == crosshair_target) + { + HU_UpdateCrosshairLock + ( + BETWEEN(0, viewwidth - 1, (centerxfrac + FixedMul(txc, xscale)) >> FRACBITS), + BETWEEN(0, viewheight - 1, (centeryfrac + FixedMul(viewz - interpz - crosshair_target->height/2, xscale)) >> FRACBITS) + ); + + crosshair_target = NULL; // Don't update it again until next tic + } } // @@ -865,6 +866,10 @@ void R_DrawPlayerSprites(void) mfloorclip = screenheightarray; mceilingclip = negonearray; + // display crosshair + if (hud_crosshair) + HU_DrawCrosshair(); + // add all active psprites for (i=0, psp=viewplayer->psprites; istate)