From bc9198ba9b654117118a06399d4dbf273262501d Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 25 Sep 2024 18:25:08 +0100 Subject: Create and use macros to define accessor functions Avoids the need to manually mess around with mem_offset() and gamedata off_ and sz_ values as often, because that's kind of annoying. Should also make the codebase a little less confusing for new players. --- src/ent.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ent.c') diff --git a/src/ent.c b/src/ent.c index 1845b1f..2eb8e51 100644 --- a/src/ent.c +++ b/src/ent.c @@ -14,6 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ +#include "accessor.h" #include "con_.h" #include "dictmaptree.h" #include "engineapi.h" @@ -31,12 +32,16 @@ FEATURE() DECL_VFUNC_DYN(void *, PEntityOfEntIndex, int) + +DEF_PTR_ACCESSOR(struct edict *, edicts) +DEF_ARRAYIDX_ACCESSOR(edict) + static struct edict **edicts = 0; struct edict *ent_getedict(int idx) { if (edicts) { // globalvars->edicts seems to be null when disconnected - if_hot (*edicts) return mem_offset(*edicts, sz_edict * idx); + if_hot (*edicts) return arrayidx_edict(*edicts, idx); return 0; } else { @@ -177,7 +182,7 @@ INIT { // can just call the function later. if (has_vtidx_PEntityOfEntIndex) return true; if (globalvars && has_off_edicts) { - edicts = mem_offset(globalvars, off_edicts); + edicts = getptr_edicts(globalvars); return true; } errmsg_warnx("not implemented for this engine"); -- cgit v1.2.3-54-g00ecf