#define LEGACY_IMPULSE_ID(alias, id) LEGACY_IMPULSE(alias, id, sprintf("impulse %d", IMP_##alias.impulse))
+void _impCheck(string s, string alias)
+{
+ // this is inside a function to avoid expanding it on compilation everytime
+ if (s == alias)
+ LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s);
+}
+
#define LEGACY_IMPULSE(alias, id, new) \
STATIC_INIT(legacy_##alias) { \
string s = new; \
- if (s == #alias) LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s); \
+ _impCheck(s, #alias); \
IMPULSE_ALIAS(alias, s); \
} \
SHUTDOWN(legacy_##alias) { IMPULSE_ALIAS(alias, "impulse " #id); }
/** 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.
{ \
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); \