From 7ac57c976d95bce5a7a98e0f269e4cd3d61f3055 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 5 Apr 2025 16:41:32 +0100 Subject: Pass screen width and height into HudPaint events This makes it unnecessary to call hud_screensize in basically every handler. --- src/hud.c | 9 ++++----- src/hud.h | 2 +- src/inputhud.c | 4 +--- src/xhair.c | 4 +--- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/hud.c b/src/hud.c index f95acbc..dc69a36 100644 --- a/src/hud.c +++ b/src/hud.c @@ -58,7 +58,7 @@ REQUIRE_GAMEDATA(vtidx_GetIScheme) // IScheme REQUIRE_GAMEDATA(vtidx_GetFont) -DEF_EVENT(HudPaint) +DEF_EVENT(HudPaint, int /*width*/, int /*height*/) // we just use ulongs for API, but keep a struct for vcalls to ensure we get the // right calling convention (x86 Windows/MSVC is funny about passing structs...) @@ -96,10 +96,9 @@ static void *matsurf, *toolspanel, *scheme; typedef void (*VCALLCONV Paint_func)(void *); static Paint_func orig_Paint; void VCALLCONV hook_Paint(void *this) { - // hopefully a smart branch predictor can figure this out - but we still - // want it to be the "slow" path, so that every other path does *not* need a - // prediction record. or.. I dunno, in theory that does make sense. shrug. - if_cold (this == toolspanel) EMIT_HudPaint(); + int width, height; + hud_screensize(&width, &height); + if (this == toolspanel) EMIT_HudPaint(width, height); orig_Paint(this); } diff --git a/src/hud.h b/src/hud.h index e3aea1d..8dc2d23 100644 --- a/src/hud.h +++ b/src/hud.h @@ -33,7 +33,7 @@ typedef int hud_wchar; * Emitted when the game HUD is being drawn. Allows features to draw their own * additional overlays atop the game's standard HUD. */ -DECL_EVENT(HudPaint, void) +DECL_EVENT(HudPaint, int /*width*/, int /*height*/) /* Font style flags */ #define HUD_FONT_ITALIC 1 diff --git a/src/inputhud.c b/src/inputhud.c index 0dd4f11..6eaa857 100644 --- a/src/inputhud.c +++ b/src/inputhud.c @@ -310,10 +310,8 @@ static const char *const fontnames[] = { }; static struct { ulong h; int sz; } fonts[countof(fontnames)]; -HANDLE_EVENT(HudPaint) { +HANDLE_EVENT(HudPaint, int screenw, int screenh) { if (!con_getvari(sst_inputhud)) return; - int screenw, screenh; - hud_screensize(&screenw, &screenh); int basesz = screenw > screenh ? screenw : screenh; int boxsz = ceilf(basesz * 0.025f); if (boxsz < 24) boxsz = 24; diff --git a/src/xhair.c b/src/xhair.c index 1f9d1a6..1ba87f1 100644 --- a/src/xhair.c +++ b/src/xhair.c @@ -54,11 +54,9 @@ static inline void drawrect(int x0, int y0, int x1, int y1, struct rgba colour, if (outline) hud_drawrect(x0, y0, x1, y1, (struct rgba){.a = 255}, false); } -HANDLE_EVENT(HudPaint) { +HANDLE_EVENT(HudPaint, int w, int h) { if (!con_getvari(sst_xhair)) return; if (has_vtidx_IsInGame && engclient && !IsInGame(engclient)) return; - int w, h; - hud_screensize(&w, &h); int thick = con_getvari(sst_xhair_thickness); int thick1 = (thick + 1) / 2, thick2 = thick - thick1; int sz = con_getvari(sst_xhair_size); -- cgit v1.2.3-54-g00ecf