]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/spawnfunc.qh
Monsters: resolve assertion failures
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / spawnfunc.qh
index 8a17854cb924af606baaaf77ffe7efdb477019ad..ef0d68f008d2cdc66b0ab2a1c815df416521f996 100644 (file)
@@ -28,11 +28,24 @@ noref bool require_spawnfunc_prefix;
        #define _spawnfunc_check(fld) \
                if (fieldname == #fld) continue;
 
-               #define spawnfunc_1(id, whitelist) spawnfunc_2(id, whitelist)
+       noref entity __spawnfunc_expect;
+       bool __spawnfunc_unreachable_workaround = true;
+
+       #define spawnfunc_1(id) spawnfunc_2(id, FIELDS_UNION)
        #define spawnfunc_2(id, whitelist) \
-               void spawnfunc_##id(entity this) \
+               void __spawnfunc_##id(entity this); \
+               [[accumulate]] void spawnfunc_##id(entity this) \
                { \
-                       this = self; \
+                       if (self == __spawnfunc_expect) \
+                       { \
+                               /* engine call */ \
+                               __spawnfunc_expect = NULL; \
+                               this = self; \
+                       } \
+                       else \
+                       { \
+                               assert(this); \
+                       } \
                        if (!this.sourceLocFile) \
                        { \
                                this.sourceLocFile = __FILE__; \
@@ -53,8 +66,10 @@ noref bool require_spawnfunc_prefix;
                                } \
                                this.spawnfunc_checked = true; \
                        } \
+                       __spawnfunc_##id(this); \
+                       if (__spawnfunc_unreachable_workaround) return; \
                } \
-               [[accumulate]] void spawnfunc_##id(entity this)
+               void __spawnfunc_##id(entity this)
 
        #define FIELD_SCALAR(fld, n) \
                fld(n)
@@ -125,7 +140,9 @@ noref bool require_spawnfunc_prefix;
                FIELD_SCALAR(fld, modelindex) \
                FIELD_SCALAR(fld, modelscale) \
                FIELD_SCALAR(fld, model) \
+               FIELD_SCALAR(fld, monsterid) \
                FIELD_SCALAR(fld, monster_moveflags) \
+               FIELD_SCALAR(fld, monster_name) \
                FIELD_SCALAR(fld, movetype) \
                FIELD_SCALAR(fld, netname) \
                FIELD_SCALAR(fld, nextthink) \
@@ -176,6 +193,6 @@ noref bool require_spawnfunc_prefix;
                FIELD_VEC(fld, velocity) \
                /**/
 
-       #define spawnfunc(...) EVAL(OVERLOAD(spawnfunc, __VA_ARGS__, FIELDS_UNION))
+       #define spawnfunc(...) EVAL(OVERLOAD(spawnfunc, __VA_ARGS__))
 
 #endif