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
This commit is contained in:
Fabian Greffrath 2022-12-14 10:05:54 +01:00 committed by GitHub
parent 2f27fa739a
commit a75c38eda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 20 deletions

View File

@ -42,6 +42,7 @@
#include "p_map.h" // crosshair (linetarget) #include "p_map.h" // crosshair (linetarget)
#include "m_misc2.h" #include "m_misc2.h"
#include "m_swap.h" #include "m_swap.h"
#include "r_main.h"
// global heads up display controls // global heads up display controls
@ -1087,11 +1088,11 @@ static void HU_UpdateCrosshair(void)
void HU_UpdateCrosshairLock(int x, int y) void HU_UpdateCrosshairLock(int x, int y)
{ {
crosshair.x += x; crosshair.x = ((viewwindowx + x) >> hires) - WIDESCREENDELTA;
crosshair.y += y; crosshair.y = ((viewwindowy + y) >> hires);
} }
static void HU_DrawCrosshair(void) void HU_DrawCrosshair(void)
{ {
if (plr->playerstate != PST_LIVE || if (plr->playerstate != PST_LIVE ||
automapactive || automapactive ||
@ -1724,10 +1725,6 @@ void HU_Drawer(void)
// display the interactive buffer for chat entry // display the interactive buffer for chat entry
HUlib_drawIText(&w_chat); HUlib_drawIText(&w_chat);
// display crosshair
if (hud_crosshair)
HU_DrawCrosshair();
} }
// [FG] draw Time widget on intermission screen // [FG] draw Time widget on intermission screen

View File

@ -108,6 +108,7 @@ extern crosstarget_t hud_crosshair_target;
extern boolean hud_crosshair_lockon; extern boolean hud_crosshair_lockon;
extern mobj_t *crosshair_target; extern mobj_t *crosshair_target;
void HU_UpdateCrosshairLock(int x, int y); void HU_UpdateCrosshairLock(int x, int y);
void HU_DrawCrosshair(void);
extern int hud_crosshair_color; extern int hud_crosshair_color;
extern int hud_crosshair_target_color; extern int hud_crosshair_target_color;

View File

@ -452,7 +452,7 @@ boolean flipcorpses = false;
void R_ProjectSprite (mobj_t* thing) void R_ProjectSprite (mobj_t* thing)
{ {
fixed_t gzt; // killough 3/27/98 fixed_t gzt; // killough 3/27/98
fixed_t tx; fixed_t tx, txc;
fixed_t xscale; fixed_t xscale;
int x1; int x1;
int x2; int x2;
@ -549,18 +549,7 @@ void R_ProjectSprite (mobj_t* thing)
flip = !flip; flip = !flip;
} }
// [Alaux] Lock crosshair on target txc = tx; // [FG] sprite center coordinate
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
}
// calculate edges of the shape // calculate edges of the shape
// [crispy] fix sprite offsets for mirrored sprites // [crispy] fix sprite offsets for mirrored sprites
@ -655,6 +644,18 @@ void R_ProjectSprite (mobj_t* thing)
vis->colormap[1] = fullcolormap; vis->colormap[1] = fullcolormap;
} }
vis->brightmap = R_BrightmapForSprite(thing->sprite); 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; mfloorclip = screenheightarray;
mceilingclip = negonearray; mceilingclip = negonearray;
// display crosshair
if (hud_crosshair)
HU_DrawCrosshair();
// add all active psprites // add all active psprites
for (i=0, psp=viewplayer->psprites; i<NUMPSPRITES; i++,psp++) for (i=0, psp=viewplayer->psprites; i<NUMPSPRITES; i++,psp++)
if (psp->state) if (psp->state)