]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/registry.qh
Add an option (off by default) to allow the vortex to charge even while not in hand
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / registry.qh
index 8ca07b43f3d34ecaa83e63b1810f415e26ad47a6..a48e83ac1a32593f7ccced9044b55de4308d7b79 100644 (file)
@@ -22,9 +22,9 @@
  */
 #define REGISTRY(id, max) \
        void Register##id(); \
-       [[accumulate]] void REGISTRY_DEPENDS_(id) {} \
-       [[accumulate]] REGISTRY_BEGIN(id) {} \
-       [[accumulate]] REGISTRY_END(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); } \
 #define REGISTRY_DEPENDS_(id) Register##id##_Depends()
 
 /** Called before initializing a registry. */
-#define REGISTRY_BEGIN(id) [[accumulate]] void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id)
+#define REGISTRY_BEGIN(id) ACCUMULATE void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id)
 #define REGISTRY_BEGIN_(id) Register##id##_First()
 
 /** Called after initializing a registry. */
-#define REGISTRY_END(id) [[accumulate]] void REGISTRY_END_(id) { noref void() f = Register##id; } void REGISTRY_END_(id)
+#define REGISTRY_END(id) ACCUMULATE void REGISTRY_END_(id) { noref void() f = Register##id; } void REGISTRY_END_(id)
 #define REGISTRY_END_(id) Register##id##_Done()
 
 REGISTRY(Registries, BITS(8))
@@ -52,6 +52,14 @@ REGISTRY(Registries, BITS(8))
 /** registered item identifier */
 .string registered_id;
 
+void _regCheck(int i, int _max)
+{
+       // this is inside a function to avoid expanding it on compilation everytime
+       // (this very long line would be repeated literally thousands times!)
+       if (i >= _max)
+               LOG_FATALF("Registry capacity exceeded (%d)", _max);
+}
+
 /**
  * Register a new entity with a registry.
  * Must be followed by a semicolon or a function body with a `this` parameter.
@@ -79,7 +87,7 @@ REGISTRY(Registries, BITS(8))
        { \
                entity this = id; \
                if (this == NULL) { \
-                       if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%d)", registry##_MAX); \
+                       _regCheck(registry##_COUNT, registry##_MAX); \
                        this = id = inst; \
                        this.registered_id = #id; \
                        REGISTRY_PUSH(registry, fld, this); \
@@ -89,22 +97,22 @@ REGISTRY(Registries, BITS(8))
        ACCUMULATE_FUNCTION(_Register##registry, Register_##id) \
        REGISTER_INIT(id)
 
-#define REGISTRY_PUSH(registry, fld, it) MACRO_BEGIN \
+#define REGISTRY_PUSH(registry, fld, it) 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
+MACRO_END
 
-#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN \
+#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN \
        entity e = new_pure(registry_reserved); \
        e.registered_id = #id "/" #suffix; \
        REGISTRY_PUSH(registry, fld, e); \
-MACRO_END
+MACRO_END
 
-#define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this)
+#define REGISTER_INIT(id) ACCUMULATE void Register_##id##_init(entity this)
 
 /** internal next pointer */
 #define REGISTRY_NEXT enemy
@@ -147,9 +155,9 @@ REGISTRY(Registries, BITS(8))
 #define REGISTRY_HASH(id) Registry_hash_##id
 
 ERASEABLE
-[[accumulate]] void Registry_check(string r, string server) { }
+ACCUMULATE void Registry_check(string r, string sv) { }
 ERASEABLE
-[[accumulate]] void Registry_send_all() { }
+ACCUMULATE void Registry_send_all() { }
 
 #ifdef SVQC
 void Registry_send(string id, string hash);
@@ -162,12 +170,10 @@ void Registry_send(string id, string hash);
        STATIC_INIT(Registry_check_##id) \
        { \
                /* Note: SHA256 isn't always available, use MD4 instead */ \
-               string algo = "MD4"; \
-               string join = ":"; \
                string s = ""; \
-               FOREACH(id, true, s = strcat(s, join, it.registered_id)); \
-               s = substring(s, strlen(join), -1); \
-               string h = REGISTRY_HASH(id) = strzone(digest_hex(algo, 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) \
@@ -187,7 +193,7 @@ void Registry_send(string id, string hash);
 #define EVAL_REGISTER_REGISTRY(...) __VA_ARGS__
 #define REGISTER_REGISTRY_1(id) REGISTER_REGISTRY_2(id, #id)
 #define REGISTER_REGISTRY_2(id, str) \
-       ACCUMULATE_FUNCTION(__static_init, Register##id) \
+       ACCUMULATE_FUNCTION(__static_init_1, Register##id) \
        CLASS(id##Registry, Object) \
                ATTRIB(id##Registry, m_name, string, str); \
                ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first); \