]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/registry.qh
Merge branch 'drjaska/2809-splashdmgforcecalcfix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / registry.qh
index b25878c349b71dbd362021321b0166f89e83aac9..fdcc730a068527b73b4a1e2291fc910616e9b53f 100644 (file)
@@ -19,8 +19,9 @@
 /**
  * Declare a new registry.
  *
- * Don't forget to call `REGISTER_REGISTRY`:
+ * Don't forget to call REGISTER_REGISTRY and REGISTRY_DEFINE_GET:
  *     REGISTER_REGISTRY(Foos)
+ *     REGISTRY_DEFINE_GET(Foos, null_ent)
  */
 #define REGISTRY(id, max) \
        void Register##id(); \
        noref entity id##_first, id##_last; \
        _R_MAP(_##id, id##_MAX); \
        SHUTDOWN(id) { _R_DEL(_##id); } \
-       entity _##id##_from(int i, entity null) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; }
+
+#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_GET(id, i) id##_from(i)
 
 /** Add registry dependencies to a registry */
 #define REGISTRY_DEPENDS(id, dep) void Register##dep(); void REGISTRY_DEPENDS_(id) { Register##dep(); }
@@ -191,10 +196,7 @@ void Registry_send(string id, string hash);
        } \
        void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } \
 
-#define REGISTER_REGISTRY(...) EVAL_REGISTER_REGISTRY(OVERLOAD(REGISTER_REGISTRY, __VA_ARGS__))
-#define EVAL_REGISTER_REGISTRY(...) __VA_ARGS__
-#define REGISTER_REGISTRY_1(id) REGISTER_REGISTRY_2(id, #id)
-#define REGISTER_REGISTRY_2(id, str) \
+#define _REGISTER_REGISTRY(id, str) \
        ACCUMULATE_FUNCTION(__static_init_1, Register##id) \
        CLASS(id##Registry, Object) \
                ATTRIB(id##Registry, m_name, string, str); \
@@ -206,3 +208,5 @@ void Registry_send(string id, string hash);
                id##_state = 0; \
                Register##id(); \
        }
+
+#define REGISTER_REGISTRY(id) _REGISTER_REGISTRY(id, #id)