Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
registry.qh File Reference
#include "oo.qh"
Include dependency graph for registry.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _R_DEL(r)
#define _R_GET(r, i)
#define _R_MAP(r, max)
#define _R_SET(r, i, e)
#define _REGISTER_REGISTRY(id, str)
#define EVAL_REGISTER(...)
#define EVAL_REGISTRY_SORT(...)
#define REGISTER(...)
 Register a new entity with a registry.
#define REGISTER_4(registry, id, fld, inst)
#define REGISTER_5(registry, ns, id, fld, inst)
#define REGISTER_INIT(id)
#define REGISTER_REGISTRY(id)
#define REGISTRY(id, max)
 Declare a new registry.
#define REGISTRY_BEGIN(id)
 Called before initializing a registry.
#define REGISTRY_BEGIN_(id)
#define REGISTRY_CHECK(id)
#define REGISTRY_COUNT(id)
#define REGISTRY_DEFINE_GET(id, null)
#define REGISTRY_DEPENDS(id, dep)
 Add registry dependencies to a registry.
#define REGISTRY_DEPENDS_(id)
#define REGISTRY_END(id)
 Called after initializing a registry.
#define REGISTRY_END_(id)
#define REGISTRY_GET(id, i)
#define REGISTRY_HASH(id)
#define REGISTRY_MAX(id)
#define REGISTRY_NEXT   enemy
 internal next pointer
#define REGISTRY_PUSH(registry, fld, it)
#define REGISTRY_RESERVE(registry, fld, id, suffix)
#define REGISTRY_SORT(...)
#define REGISTRY_SORT_1(id)
#define REGISTRY_SORT_2(id, skip)

Functions

void _regCheck (int i, int _max)
ERASEABLE ACCUMULATE void Registry_check (string r, string sv)
void Registry_send (string id, string hash)
ERASEABLE ACCUMULATE void Registry_send_all ()

Variables

string registered_id
 registered item identifier
entity REGISTRY_NEXT

Macro Definition Documentation

◆ _R_DEL

#define _R_DEL ( r)
Value:
#define AL_DELETE(this)
Definition arraylist.qh:18

Definition at line 9 of file registry.qh.

◆ _R_GET

#define _R_GET ( r,
i )
Value:
AL_gete(r, i)
#define AL_gete(this, idx)
Definition arraylist.qh:56

Definition at line 7 of file registry.qh.

◆ _R_MAP

#define _R_MAP ( r,
max )
Value:
ArrayList r; STATIC_INIT(r) { AL_NEW(r, max, NULL, e); }
#define AL_NEW(this, n, default, T)
Definition arraylist.qh:7
entity ArrayList
Definition arraylist.qh:3
float max(float f,...)
#define NULL
Definition post.qh:14
#define STATIC_INIT(func)
during worldspawn
Definition static.qh:32

Definition at line 6 of file registry.qh.

◆ _R_SET

#define _R_SET ( r,
i,
e )
Value:
AL_sete(r, i, e)
#define AL_sete(this, idx, val)
Definition arraylist.qh:57

Definition at line 8 of file registry.qh.

◆ _REGISTER_REGISTRY

#define _REGISTER_REGISTRY ( id,
str )
Value:
CLASS(id##Registry, Object) \
ATTRIB(id##Registry, m_name, string, str); \
ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first); \
METHOD(id##Registry, m_reload, void()); \
ENDCLASS(id##Registry) \
REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry)); \
METHOD(id##Registry, m_reload, void()) { \
id##_state = 0; \
Register##id(); \
}
#define ACCUMULATE_FUNCTION(func, otherfunc)
Definition accumulate.qh:31
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string m_name
Definition scores.qh:142
int m_id
Definition effect.qh:19
#define NEW(cname,...)
Definition oo.qh:117
#define REGISTRY_NEXT
internal next pointer
Definition registry.qh:125
#define REGISTRY(id, max)
Declare a new registry.
Definition registry.qh:26
void __static_init_1()
Definition static.qh:34

Definition at line 216 of file registry.qh.

216#define _REGISTER_REGISTRY(id, str) \
217 ACCUMULATE_FUNCTION(__static_init_1, Register##id) \
218 CLASS(id##Registry, Object) \
219 ATTRIB(id##Registry, m_name, string, str); \
220 ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first); \
221 METHOD(id##Registry, m_reload, void()); \
222 ENDCLASS(id##Registry) \
223 REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry)); \
224 METHOD(id##Registry, m_reload, void()) { \
225 id##_state = 0; \
226 Register##id(); \
227 }

◆ EVAL_REGISTER

#define EVAL_REGISTER ( ...)
Value:
__VA_ARGS__

Definition at line 88 of file registry.qh.

◆ EVAL_REGISTRY_SORT

#define EVAL_REGISTRY_SORT ( ...)
Value:
__VA_ARGS__

Definition at line 129 of file registry.qh.

◆ REGISTER

#define REGISTER ( ...)
Value:
#define OVERLOAD_(F,...)
for use within macros
Definition misc.qh:14
#define REGISTER(...)
Register a new entity with a registry.
Definition registry.qh:87
#define EVAL_REGISTER(...)
Definition registry.qh:88

Register a new entity with a registry.

Must be followed by a semicolon or a function body with a this parameter. Wrapper macros may perform actions after user initialization like so: #define REGISTER_FOO(id) \ REGISTER(Foos, FOO, id, m_id, NEW(Foo)) { \ print("Registering foo #", this.m_id + 1, "\n"); \ } \ REGISTER_INIT(FOO, id)

Parameters
registryThe registry to add each entity to.
nsShort for namespace, prefix for each global (ns##_##id)
idThe identifier of the current entity being registered
fldThe field to store the locally unique unique entity id
instAn expression to create a new instance, invoked for every registration

Definition at line 87 of file registry.qh.

Referenced by REGISTER().

◆ REGISTER_4

#define REGISTER_4 ( registry,
id,
fld,
inst )
Value:
entity id; \
REGISTER_INIT(id) {} \
void Register_##id() \
{ \
entity this = id; \
if (this == NULL) { \
_regCheck(registry##_COUNT, registry##_MAX); \
this = id = inst; \
this.registered_id = #id; \
REGISTRY_PUSH(registry, fld, this); \
} \
Register_##id##_init(this); \
} \
ACCUMULATE_FUNCTION(_Register##registry, Register_##id) \
REGISTER_INIT(id)
string registered_id
registered item identifier
Definition registry.qh:60

Definition at line 90 of file registry.qh.

90#define REGISTER_4(registry, id, fld, inst) \
91 entity id; \
92 REGISTER_INIT(id) {} \
93 void Register_##id() \
94 { \
95 entity this = id; \
96 if (this == NULL) { \
97 _regCheck(registry##_COUNT, registry##_MAX); \
98 this = id = inst; \
99 this.registered_id = #id; \
100 REGISTRY_PUSH(registry, fld, this); \
101 } \
102 Register_##id##_init(this); \
103 } \
104 ACCUMULATE_FUNCTION(_Register##registry, Register_##id) \
105 REGISTER_INIT(id)

◆ REGISTER_5

#define REGISTER_5 ( registry,
ns,
id,
fld,
inst )
Value:
REGISTER_4(registry, ns##_##id, fld, inst)
#define REGISTER_4(registry, id, fld, inst)
Definition registry.qh:90

Definition at line 89 of file registry.qh.

◆ REGISTER_INIT

#define REGISTER_INIT ( id)
Value:
ACCUMULATE void Register_##id##_init(entity this)
#define ACCUMULATE
Definition _all.inc:31

Definition at line 122 of file registry.qh.

◆ REGISTER_REGISTRY

#define REGISTER_REGISTRY ( id)
Value:
#define _REGISTER_REGISTRY(id, str)
Definition registry.qh:216

Definition at line 229 of file registry.qh.

Referenced by stopsound().

◆ REGISTRY

#define REGISTRY ( id,
max )
Value:
void Register##id(); \
REGISTRY_BEGIN(id) {} \
REGISTRY_END(id) {} \
void _Register##id() {} \
int id##_state = 0; \
void Register##id() { if (id##_state) return; id##_state = 1; REGISTRY_DEPENDS_(id); REGISTRY_BEGIN_(id); _Register##id(); id##_state = 2; REGISTRY_END_(id); } \
const int id##_MAX = max; \
int id##_COUNT; \
noref entity id##_first, id##_last; \
_R_MAP(_##id, id##_MAX); \
SHUTDOWN(id) { _R_DEL(_##id); } \
entity() spawn
#define REGISTRY_DEPENDS_(id)
Definition registry.qh:47
#define REGISTRY_END_(id)
Definition registry.qh:55
#define _R_DEL(r)
Definition registry.qh:9
#define REGISTRY_BEGIN_(id)
Definition registry.qh:51

Declare a new registry.

Don't forget to call REGISTER_REGISTRY and REGISTRY_DEFINE_GET: REGISTER_REGISTRY(Foos) REGISTRY_DEFINE_GET(Foos, null_ent)

Definition at line 26 of file registry.qh.

26#define REGISTRY(id, max) \
27 void Register##id(); \
28 ACCUMULATE void REGISTRY_DEPENDS_(id) {} \
29 REGISTRY_BEGIN(id) {} \
30 REGISTRY_END(id) {} \
31 void _Register##id() {} \
32 int id##_state = 0; \
33 void Register##id() { if (id##_state) return; id##_state = 1; REGISTRY_DEPENDS_(id); REGISTRY_BEGIN_(id); _Register##id(); id##_state = 2; REGISTRY_END_(id); } \
34 const int id##_MAX = max; \
35 int id##_COUNT; \
36 noref entity id##_first, id##_last; \
37 _R_MAP(_##id, id##_MAX); \
38 SHUTDOWN(id) { _R_DEL(_##id); } \
39

◆ REGISTRY_BEGIN

#define REGISTRY_BEGIN ( id)
Value:
ACCUMULATE void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id)
void
Definition self.qh:72

Called before initializing a registry.

Definition at line 50 of file registry.qh.

◆ REGISTRY_BEGIN_

#define REGISTRY_BEGIN_ ( id)
Value:
Register##id##_First()

Definition at line 51 of file registry.qh.

◆ REGISTRY_CHECK

#define REGISTRY_CHECK ( id)

Definition at line 175 of file registry.qh.

175#define REGISTRY_CHECK(id) \
176 string REGISTRY_HASH(id); \
177 STATIC_INIT(Registry_check_##id) \
178 { \
179 /* Note: SHA256 isn't always available, use MD4 instead */ \
180 string s = "", group = ""; \
181 int str_len = 0, digests_len = 0, group_idx = 0; \
182 FOREACH(id, true, { \
183 group = strcat(group, ":", it.registered_id); \
184 if (++group_idx < 50) /* this is to reduce strlen calls */ \
185 continue; \
186 int group_len = strlen(group); \
187 if (str_len + 1 + group_len >= VM_TEMPSTRING_MAXSIZE) \
188 { \
189 /* keep previous digests and replace current string with its digest */ \
190 s = strcat(substring(s, 0, digests_len), ":", digest_hex("MD4", s)); \
191 digests_len = str_len = strlen(s); \
192 } \
193 s = strcat(s, group); \
194 str_len += group_len; \
195 group = ""; \
196 group_idx = 0; \
197 }); \
198 s = strcat(s, group); \
199 s = substring(s, 1, -1); /* remove initial ":" */ \
200 string h = REGISTRY_HASH(id) = strzone(digest_hex("MD4", s)); \
201 LOG_DEBUGF(#id ": %s\n[%s]", h, s); \
202 } \
203 void Registry_check(string r, string sv) /* called by CSQC */ \
204 { \
205 if (r == #id) \
206 { \
207 string cl = REGISTRY_HASH(id); \
208 if (cl != sv) \
209 { \
210 LOG_FATALF("client/server mismatch (%s).\nCL: %s\nSV: %s", r, cl, sv); \
211 } \
212 } \
213 } \
214 void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } /* called by SVQC */ \
215

◆ REGISTRY_COUNT

◆ REGISTRY_DEFINE_GET

#define REGISTRY_DEFINE_GET ( id,
null )
Value:
entity id##_from(int i) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; }
#define _R_GET(r, i)
Definition registry.qh:7

Definition at line 40 of file registry.qh.

40#define REGISTRY_DEFINE_GET(id, null) \
41 entity id##_from(int i) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; }

Referenced by REGISTER(), REGISTER_MONSTER(), REGISTER_RADARICON(), REGISTER_TURRET(), REGISTER_VEHICLE(), REGISTER_WEAPON(), and STATIC_INIT().

◆ REGISTRY_DEPENDS

#define REGISTRY_DEPENDS ( id,
dep )
Value:
void Register##dep(); void REGISTRY_DEPENDS_(id) { Register##dep(); }

Add registry dependencies to a registry.

Definition at line 46 of file registry.qh.

◆ REGISTRY_DEPENDS_

#define REGISTRY_DEPENDS_ ( id)
Value:
Register##id##_Depends()

Definition at line 47 of file registry.qh.

◆ REGISTRY_END

#define REGISTRY_END ( id)
Value:
ACCUMULATE void REGISTRY_END_(id) { noref void() f = Register##id; } void REGISTRY_END_(id)

Called after initializing a registry.

Definition at line 54 of file registry.qh.

◆ REGISTRY_END_

#define REGISTRY_END_ ( id)
Value:
Register##id##_Done()

Definition at line 55 of file registry.qh.

◆ REGISTRY_GET

#define REGISTRY_GET ( id,
i )
Value:
id##_from(i)

Definition at line 43 of file registry.qh.

Referenced by bot_cmd_select_weapon(), BUFF_NAME(), bumble_raygun_draw(), CL_Weapon_GetShotOrg(), Deathtype_Name(), DrawAmmoNades(), fixPriorityList(), Get_Notif_Ent(), SettingSource::getEntry(), SettingSource::getEntryTooltip(), GiveWeapon(), havocbot_chooseweapon(), HUD_Configure_Frame(), HUD_Crosshair_Vehicle(), HUD_Main(), HUD_Notify(), HUD_Panel_Check_Mouse_Pos(), HUD_Panel_CheckMove(), HUD_Panel_CheckResize(), HUD_Panel_ExportCfg(), HUD_Panel_Highlight(), HUD_Panel_InputEvent(), HUD_Radar(), HUD_Vehicle(), Inventory_Write(), Item_GiveTo(), Item_RespawnCountdown(), MDL_GIB_ROBO_RANDOM(), MDL_NUM(), Monster_Dead_Think(), MUTATOR_HOOKFUNCTION(), nade_boom(), nade_burn_spawn(), nade_customize(), nade_pickup(), nade_prime(), nade_spawn(), Nades_GetType(), Net_ClientCommand(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NIX_CanChooseWeapon(), NIX_GiveCurrentWeapon(), notif_arg_item_wepammo(), Obituary_SpecialDeath(), Projectile_DrawTrail(), ServerList_TypeSort_Click(), SND_BRASS_RANDOM(), SND_CASINGS_RANDOM(), SND_FLACEXP_RANDOM(), SND_GIB_SPLAT_RANDOM(), SND_GRENADE_BOUNCE_RANDOM(), SND_HAGEXP_RANDOM(), SND_NEXWHOOSH_RANDOM(), SND_RIC_RANDOM(), SND_SEEKEREXP_RANDOM(), SND_TAGEXP_RANDOM(), spritelookupblinkvalue(), spritelookupcolor(), spritelookupicon(), spritelookuptext(), StartItem(), STATIC_INIT(), StatusEffects_Write(), View_EventChase(), W_CycleWeapon(), W_DropEvent(), W_FixWeaponOrder_BuildImpulseList_cmp(), W_GetCycleWeapon(), W_GiveWeapon(), W_IsWeaponThrowable(), W_LastWeapon(), W_NameWeaponOrder_MapFunc(), W_NextWeaponOnImpulse(), W_ThrowNewWeapon(), XonoticKeyBinder_resizeNotify(), XonoticMutatorsDialog_fill(), XonoticWeaponsList_drawListBoxItem(), XonoticWeaponsList_resizeNotify(), and XonoticWeaponsList_toString().

◆ REGISTRY_HASH

#define REGISTRY_HASH ( id)
Value:
Registry_hash_##id

Definition at line 162 of file registry.qh.

◆ REGISTRY_MAX

◆ REGISTRY_NEXT

#define REGISTRY_NEXT   enemy

internal next pointer

Definition at line 125 of file registry.qh.

◆ REGISTRY_PUSH

#define REGISTRY_PUSH ( registry,
fld,
it )
Value:
MACRO_BEGIN \
it.fld = registry##_COUNT; \
_R_SET(_##registry, registry##_COUNT, it); \
++registry##_COUNT; \
if (!registry##_first) registry##_first = it; \
if (registry##_last) registry##_last.REGISTRY_NEXT = it; \
registry##_last = it; \
#define MACRO_END
Definition macro.qh:7

Definition at line 107 of file registry.qh.

107#define REGISTRY_PUSH(registry, fld, it) MACRO_BEGIN \
108 it.fld = registry##_COUNT; \
109 _R_SET(_##registry, registry##_COUNT, it); \
110 ++registry##_COUNT; \
111 if (!registry##_first) registry##_first = it; \
112 if (registry##_last) registry##_last.REGISTRY_NEXT = it; \
113 registry##_last = it; \
114MACRO_END

◆ REGISTRY_RESERVE

#define REGISTRY_RESERVE ( registry,
fld,
id,
suffix )
Value:
MACRO_BEGIN \
entity e = new_pure(registry_reserved); \
e.registered_id = #id "/" #suffix; \
REGISTRY_PUSH(registry, fld, e); \
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67

Definition at line 116 of file registry.qh.

116#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN \
117 entity e = new_pure(registry_reserved); \
118 e.registered_id = #id "/" #suffix; \
119 REGISTRY_PUSH(registry, fld, e); \
120MACRO_END

◆ REGISTRY_SORT

#define REGISTRY_SORT ( ...)
Value:
#define OVERLOAD(F,...)
Definition misc.qh:12
#define REGISTRY_SORT(...)
Definition registry.qh:128
#define EVAL_REGISTRY_SORT(...)
Definition registry.qh:129

Definition at line 128 of file registry.qh.

◆ REGISTRY_SORT_1

#define REGISTRY_SORT_1 ( id)
Value:
#define REGISTRY_SORT_2(id, skip)
Definition registry.qh:131

Definition at line 130 of file registry.qh.

◆ REGISTRY_SORT_2

#define REGISTRY_SORT_2 ( id,
skip )
Value:
void _REGISTRY_SWAP_##id(int i, int j, entity pass) \
{ \
i += skip; j += skip; \
\
entity a = _R_GET(_##id, i), b = _R_GET(_##id, j); \
_R_SET(_##id, i, b); \
_R_SET(_##id, j, a); \
\
entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \
a.REGISTRY_NEXT = b_next; \
b.REGISTRY_NEXT = a_next; \
\
if (i == 0) id##_first = b; \
else _R_GET(_##id, i - 1).REGISTRY_NEXT = b; \
\
if (j == 0) id##_first = a; \
else _R_GET(_##id, j - 1).REGISTRY_NEXT = a; \
} \
int _REGISTRY_CMP_##id(int i, int j, entity pass) \
{ \
i += skip; j += skip; \
string a = _R_GET(_##id, i).registered_id; \
string b = _R_GET(_##id, j).registered_id; \
return strcmp(a, b); \
} \
STATIC_INIT(Registry_sort_##id) \
{ \
heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
}
#define pass(name, colormin, colormax)

Definition at line 131 of file registry.qh.

131#define REGISTRY_SORT_2(id, skip) \
132 void _REGISTRY_SWAP_##id(int i, int j, entity pass) \
133 { \
134 i += skip; j += skip; \
135 \
136 entity a = _R_GET(_##id, i), b = _R_GET(_##id, j); \
137 _R_SET(_##id, i, b); \
138 _R_SET(_##id, j, a); \
139 \
140 entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \
141 a.REGISTRY_NEXT = b_next; \
142 b.REGISTRY_NEXT = a_next; \
143 \
144 if (i == 0) id##_first = b; \
145 else _R_GET(_##id, i - 1).REGISTRY_NEXT = b; \
146 \
147 if (j == 0) id##_first = a; \
148 else _R_GET(_##id, j - 1).REGISTRY_NEXT = a; \
149 } \
150 int _REGISTRY_CMP_##id(int i, int j, entity pass) \
151 { \
152 i += skip; j += skip; \
153 string a = _R_GET(_##id, i).registered_id; \
154 string b = _R_GET(_##id, j).registered_id; \
155 return strcmp(a, b); \
156 } \
157 STATIC_INIT(Registry_sort_##id) \
158 { \
159 heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
160 }

Function Documentation

◆ _regCheck()

void _regCheck ( int i,
int _max )

Definition at line 62 of file registry.qh.

63{
64 // this is inside a function to avoid expanding it on compilation everytime
65 // (this very long line would be repeated literally thousands times!)
66 if (i >= _max)
67 LOG_FATALF("Registry capacity exceeded (%d)", _max);
68}
#define LOG_FATALF(...)
Definition log.qh:54

References LOG_FATALF.

◆ Registry_check()

ERASEABLE ACCUMULATE void Registry_check ( string r,
string sv )

Definition at line 165 of file registry.qh.

165{ }

References ACCUMULATE.

Referenced by NET_HANDLE().

◆ Registry_send()

void Registry_send ( string id,
string hash )

Definition at line 20 of file registry_net.qh.

21{
22 int channel = MSG_ONE;
23 WriteHeader(channel, registry);
24 WriteString(channel, id);
25 WriteString(channel, hash);
26}
#define WriteHeader(to, id)
Definition net.qh:221
float MSG_ONE
Definition menudefs.qc:56
void WriteString(string data, float dest, float desto)

References MSG_ONE, WriteHeader, and WriteString().

◆ Registry_send_all()

ERASEABLE ACCUMULATE void Registry_send_all ( )

Definition at line 167 of file registry.qh.

167{ }

References ACCUMULATE.

Referenced by ClientInit_SendEntity().

Variable Documentation

◆ registered_id

string registered_id

registered item identifier

Definition at line 60 of file registry.qh.

Referenced by Animation::LOG_DEBUGF(), and Mutator_SendEntity().

◆ REGISTRY_NEXT

entity REGISTRY_NEXT

Definition at line 126 of file registry.qh.