]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/registry.qh
Don't call these 2 LOG_FATALF directly from 2 macros that are called literally thousa...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / registry.qh
index 163ca17b40033190ff312f703dce90843011e8bc..4e8e09083f7749cb481655d64a0e01665f62b440 100644 (file)
@@ -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); \