]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/registry.qh
Merge branch 'terencehill/menu_hudskin_selector' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / registry.qh
index f2bdd1e26199984910fd35f0384985ac593de4e7..7f38afe2a7c65553816dd0d61b7662ba805ac544 100644 (file)
@@ -4,13 +4,15 @@
 #include "oo.qh"
 
 #if 1
-       #define _R_MAP(r, max) AL_declare(r); STATIC_INIT(r) { AL_init(r, max, NULL, e); }
+       #define _R_MAP(r, max) ArrayList r; STATIC_INIT(r) { AL_NEW(r, max, NULL, e); }
        #define _R_GET(r, i) AL_gete(r, i)
        #define _R_SET(r, i, e) AL_sete(r, i, e)
+       #define _R_DEL(r) AL_DELETE(r)
 #else
        #define _R_MAP(r, max) entity r[max]
        #define _R_GET(r, i) r[i]
        #define _R_SET(r, i, e) r[i] = e
+       #define _R_DEL(r)
 #endif
 
 /**
@@ -24,6 +26,7 @@
        const int id##_MAX = max; \
        noref entity id##_first, id##_last; \
        _R_MAP(_##id, id##_MAX); \
+       SHUTDOWN(id) { _R_DEL(_##id); } \
        int id##_COUNT; \
        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; }
 
@@ -68,20 +71,21 @@ REGISTRY(Registries, BITS(8))
        ACCUMULATE_FUNCTION(Register##registry, Register_##id) \
        REGISTER_INIT(id)
 
-#define REGISTRY_PUSH(registry, fld, it) do { \
+#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; \
-} while (0)
+} MACRO_END
 
-#define REGISTRY_RESERVE(registry, fld, id, suffix) do { \
+#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN { \
        entity e = new(registry_reserved); \
+       make_pure(e); \
        e.registered_id = #id "/" #suffix; \
        REGISTRY_PUSH(registry, fld, e); \
-} while (0)
+} MACRO_END
 
 #define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this)
 #define REGISTER_INIT_POST(id) [[accumulate]] void Register_##id##_init_post(entity this)