summaryrefslogtreecommitdiffhomepage
path: root/src/hud.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2024-08-03 23:40:31 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2024-08-23 20:37:37 +0100
commit83da606072ce272eb053d4e1497d77e647cfecae (patch)
tree71d0110881ff8685184c5f4ab720cc8d49c24678 /src/hud.c
parentacbd30e0427b16f885f96aed59881ec04eff25bc (diff)
Revise syntax macros and add a ton of branch hints
My new programming style is branch hints. All non-confusing branches must be hinted when I can be bothered. It's faster, sometimes, maybe. Also, start trying to use more signed sizes in at least some of the places where it makes sense. Unsigned sizes are surprisingly error-prone!
Diffstat (limited to 'src/hud.c')
-rw-r--r--src/hud.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/hud.c b/src/hud.c
index 24d8563..b1cbb56 100644
--- a/src/hud.c
+++ b/src/hud.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2022 Matthew Wozniak <sirtomato999@gmail.com>
+ * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -23,6 +24,7 @@
#include "hook.h"
#include "hud.h"
#include "intdefs.h"
+#include "langext.h"
#include "mem.h"
#include "os.h"
#include "sst.h"
@@ -92,7 +94,10 @@ static void *matsurf, *toolspanel, *scheme;
typedef void (*VCALLCONV Paint_func)(void *);
static Paint_func orig_Paint;
void VCALLCONV hook_Paint(void *this) {
- if (this == toolspanel) EMIT_HudPaint();
+ // 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();
orig_Paint(this);
}
@@ -156,21 +161,21 @@ static bool find_toolspanel(void *enginevgui) {
INIT {
matsurf = factory_engine("MatSystemSurface006", 0);
- if (!matsurf) {
+ if_cold (!matsurf) {
errmsg_errorx("couldn't get MatSystemSurface006 interface");
return false;
}
void *schememgr = factory_engine("VGUI_Scheme010", 0);
- if (!schememgr) {
+ if_cold (!schememgr) {
errmsg_errorx("couldn't get VGUI_Scheme010 interface");
return false;
}
- if (!find_toolspanel(vgui)) {
+ if_cold (!find_toolspanel(vgui)) {
errmsg_errorx("couldn't find engine tools panel");
return false;
}
void **vtable = *(void ***)toolspanel;
- if (!os_mprot(vtable + vtidx_Paint, sizeof(void *),
+ if_cold (!os_mprot(vtable + vtidx_Paint, sizeof(void *),
PAGE_READWRITE)) {
errmsg_errorsys("couldn't make virtual table writable");
return false;
@@ -184,8 +189,8 @@ INIT {
}
END {
- // don't unhook toolspanel if exiting, it's already long gone!
- if (sst_userunloaded) {
+ // don't unhook toolspanel if exiting: it's already long gone!
+ if_cold (sst_userunloaded) {
unhook_vtable(*(void ***)toolspanel, vtidx_Paint, (void *)orig_Paint);
SetPaintEnabled(toolspanel, false);
}