Xonotic
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)   AL_DELETE(r)
 
#define _R_GET(r, i)   AL_gete(r, i)
 
#define _R_MAP(r, max)   ArrayList r; STATIC_INIT(r) { AL_NEW(r, max, NULL, e); }
 
#define _R_SET(r, i, e)   AL_sete(r, i, e)
 
#define _REGISTER_REGISTRY(id, str)
 
#define EVAL_REGISTER(...)   __VA_ARGS__
 
#define EVAL_REGISTRY_SORT(...)   __VA_ARGS__
 
#define REGISTER(...)   EVAL_REGISTER(OVERLOAD_(REGISTER, __VA_ARGS__))
 Register a new entity with a registry. More...
 
#define REGISTER_4(registry, id, fld, inst)
 
#define REGISTER_5(registry, ns, id, fld, inst)   REGISTER_4(registry, ns##_##id, fld, inst)
 
#define REGISTER_INIT(id)   ACCUMULATE void Register_##id##_init(entity this)
 
#define REGISTER_REGISTRY(id)   _REGISTER_REGISTRY(id, #id)
 
#define REGISTRY(id, max)
 Declare a new registry. More...
 
#define REGISTRY_BEGIN(id)   ACCUMULATE void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id)
 Called before initializing a registry. More...
 
#define REGISTRY_BEGIN_(id)   Register##id##_First()
 
#define REGISTRY_CHECK(id)
 
#define REGISTRY_COUNT(id)   id##_COUNT
 
#define REGISTRY_DEFINE_GET(id, null)   entity id##_from(int i) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; }
 
#define REGISTRY_DEPENDS(id, dep)   void Register##dep(); void REGISTRY_DEPENDS_(id) { Register##dep(); }
 Add registry dependencies to a registry. More...
 
#define REGISTRY_DEPENDS_(id)   Register##id##_Depends()
 
#define REGISTRY_END(id)   ACCUMULATE void REGISTRY_END_(id) { noref void() f = Register##id; } void REGISTRY_END_(id)
 Called after initializing a registry. More...
 
#define REGISTRY_END_(id)   Register##id##_Done()
 
#define REGISTRY_GET(id, i)   id##_from(i)
 
#define REGISTRY_HASH(id)   Registry_hash_##id
 
#define REGISTRY_MAX(id)   id##_MAX
 
#define REGISTRY_NEXT   enemy
 internal next pointer More...
 
#define REGISTRY_PUSH(registry, fld, it)
 
#define REGISTRY_RESERVE(registry, fld, id, suffix)
 
#define Registry_send(id, hash)
 
#define REGISTRY_SORT(...)   EVAL_REGISTRY_SORT(OVERLOAD(REGISTRY_SORT, __VA_ARGS__))
 
#define REGISTRY_SORT_1(id)   REGISTRY_SORT_2(id, 0)
 
#define REGISTRY_SORT_2(id, skip)
 

Functions

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

Variables

string registered_id
 registered item identifier More...
 
entity REGISTRY_NEXT
 

Macro Definition Documentation

◆ _R_DEL

#define _R_DEL (   r)    AL_DELETE(r)

Definition at line 9 of file registry.qh.

◆ _R_GET

#define _R_GET (   r,
 
)    AL_gete(r, i)

Definition at line 7 of file registry.qh.

◆ _R_MAP

#define _R_MAP (   r,
  max 
)    ArrayList r; STATIC_INIT(r) { AL_NEW(r, max, NULL, e); }

Definition at line 6 of file registry.qh.

◆ _R_SET

#define _R_SET (   r,
  i,
 
)    AL_sete(r, i, e)

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 NEW(cname,...)
Definition: oo.qh:105
entity() spawn
#define REGISTRY_NEXT
internal next pointer
Definition: registry.qh:125
void __static_init_1()
Definition: static.qh:34
int m_id
Definition: effect.qh:19
#define REGISTRY(id, max)
Declare a new registry.
Definition: registry.qh:26
#define ACCUMULATE_FUNCTION(func, otherfunc)
Definition: accumulate.qh:31
string m_name
Definition: scores.qh:135

Definition at line 199 of file registry.qh.

◆ EVAL_REGISTER

#define EVAL_REGISTER (   ...)    __VA_ARGS__

Definition at line 88 of file registry.qh.

◆ EVAL_REGISTRY_SORT

#define EVAL_REGISTRY_SORT (   ...)    __VA_ARGS__

Definition at line 129 of file registry.qh.

◆ REGISTER

#define REGISTER (   ...)    EVAL_REGISTER(OVERLOAD_(REGISTER, __VA_ARGS__))

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.

◆ 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)
entity() spawn
#define NULL
Definition: post.qh:17

Definition at line 90 of file registry.qh.

◆ REGISTER_5

#define REGISTER_5 (   registry,
  ns,
  id,
  fld,
  inst 
)    REGISTER_4(registry, ns##_##id, fld, inst)

Definition at line 89 of file registry.qh.

◆ REGISTER_INIT

#define REGISTER_INIT (   id)    ACCUMULATE void Register_##id##_init(entity this)

Definition at line 122 of file registry.qh.

◆ REGISTER_REGISTRY

#define REGISTER_REGISTRY (   id)    _REGISTER_REGISTRY(id, #id)

Definition at line 212 of file registry.qh.

Referenced by Gametype::Gametype ::gametype_init().

◆ REGISTRY

#define REGISTRY (   id,
  max 
)
Value:
void Register##id(); \
ACCUMULATE void REGISTRY_DEPENDS_(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); } \
#define _R_DEL(r)
Definition: registry.qh:9
#define REGISTRY_BEGIN_(id)
Definition: registry.qh:51
entity() spawn
#define REGISTRY_END_(id)
Definition: registry.qh:55
#define REGISTRY_DEPENDS_(id)
Definition: registry.qh:47

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.

Referenced by Gametype::Gametype ::gametype_init(), and Mutator::Mutator ::Mutator().

◆ REGISTRY_BEGIN

#define REGISTRY_BEGIN (   id)    ACCUMULATE void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id)

Called before initializing a registry.

Definition at line 50 of file registry.qh.

◆ REGISTRY_BEGIN_

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

Definition at line 51 of file registry.qh.

◆ REGISTRY_CHECK

#define REGISTRY_CHECK (   id)
Value:
string REGISTRY_HASH(id); \
STATIC_INIT(Registry_check_##id) \
{ \
/* Note: SHA256 isn't always available, use MD4 instead */ \
string s = ""; \
FOREACH(id, true, s = strcat(s, ":", it.registered_id)); \
s = substring(s, 1, -1); /* remove initial ":" */ \
string h = REGISTRY_HASH(id) = strzone(digest_hex("MD4", s)); \
LOG_DEBUGF(#id ": %s\n[%s]", h, s); \
} \
void Registry_check(string r, string sv) \
{ \
if (r == #id) \
{ \
string cl = REGISTRY_HASH(id); \
if (cl != sv) \
{ \
LOG_FATALF("client/server mismatch (%s).\nCL: %s\nSV: %s", r, cl, sv); \
} \
} \
} \
#define Registry_send(id, hash)
Definition: registry.qh:172
ERASEABLE ACCUMULATE void Registry_check(string r, string sv)
Definition: registry.qh:165
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define REGISTRY_HASH(id)
Definition: registry.qh:162
ERASEABLE ACCUMULATE void Registry_send_all()
Definition: registry.qh:167

Definition at line 175 of file registry.qh.

Referenced by Gametype::Gametype ::gametype_init(), and STATIC_INIT().

◆ REGISTRY_COUNT

◆ REGISTRY_DEFINE_GET

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

◆ REGISTRY_DEPENDS

#define REGISTRY_DEPENDS (   id,
  dep 
)    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)    Register##id##_Depends()

Definition at line 47 of file registry.qh.

◆ REGISTRY_END

#define REGISTRY_END (   id)    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)    Register##id##_Done()

Definition at line 55 of file registry.qh.

◆ REGISTRY_GET

◆ REGISTRY_HASH

#define REGISTRY_HASH (   id)    Registry_hash_##id

Definition at line 162 of file registry.qh.

◆ REGISTRY_MAX

#define REGISTRY_MAX (   id)    id##_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; \
MACRO_END

Definition at line 107 of file registry.qh.

◆ 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); \
MACRO_END
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62

Definition at line 116 of file registry.qh.

◆ Registry_send

#define Registry_send (   id,
  hash 
)

Definition at line 172 of file registry.qh.

Referenced by Registry_send_all().

◆ REGISTRY_SORT

#define REGISTRY_SORT (   ...)    EVAL_REGISTRY_SORT(OVERLOAD(REGISTRY_SORT, __VA_ARGS__))

Definition at line 128 of file registry.qh.

◆ REGISTRY_SORT_1

#define REGISTRY_SORT_1 (   id)    REGISTRY_SORT_2(id, 0)

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); \
}
entity() spawn
#define _R_GET(r, i)
Definition: registry.qh:7
if(IS_DEAD(this))
Definition: impulse.qc:92
#define pass(name, colormin, colormax)

Definition at line 131 of file registry.qh.

Function Documentation

◆ _regCheck()

void _regCheck ( int  i,
int  _max 
)

Definition at line 62 of file registry.qh.

References LOG_FATALF.

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:59

◆ Registry_check()

ERASEABLE ACCUMULATE void Registry_check ( string  r,
string  sv 
)

Definition at line 165 of file registry.qh.

References ERASEABLE.

165 { }

◆ Registry_send_all()

ERASEABLE ACCUMULATE void Registry_send_all ( )

Definition at line 167 of file registry.qh.

References Registry_send.

Referenced by ClientInit_SendEntity().

167 { }
+ Here is the caller graph for this function:

Variable Documentation

◆ registered_id

string registered_id

registered item identifier

Definition at line 60 of file registry.qh.

◆ REGISTRY_NEXT

entity REGISTRY_NEXT

Definition at line 126 of file registry.qh.