diff options
author | 2025-04-05 16:41:32 +0100 | |
---|---|---|
committer | 2025-04-06 20:59:36 +0100 | |
commit | 7ac57c976d95bce5a7a98e0f269e4cd3d61f3055 (patch) | |
tree | fb31a7fa5716579dadf437ebcf799fac62634a2d | |
parent | 44eb8344a000dd315d5e21039871f353441601af (diff) | |
download | sst-7ac57c976d95bce5a7a98e0f269e4cd3d61f3055.tar.gz sst-7ac57c976d95bce5a7a98e0f269e4cd3d61f3055.zip |
Pass screen width and height into HudPaint events
This makes it unnecessary to call hud_screensize in basically
every handler.
-rw-r--r-- | src/hud.c | 9 | ||||
-rw-r--r-- | src/hud.h | 2 | ||||
-rw-r--r-- | src/inputhud.c | 4 | ||||
-rw-r--r-- | src/xhair.c | 4 |
4 files changed, 7 insertions, 12 deletions
@@ -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); } @@ -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); |