X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fspawnfunc.qh;h=22047bbc9daac0d285478015cbecbcf14ceb6303;hb=2a38620bbb43f7b62bbd93e8c22b6abbe627ca86;hp=8a17854cb924af606baaaf77ffe7efdb477019ad;hpb=b683bf23a495d3b1b3f6df3bda75bfe0f069ab05;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/spawnfunc.qh b/qcsrc/lib/spawnfunc.qh index 8a17854cb..22047bbc9 100644 --- a/qcsrc/lib/spawnfunc.qh +++ b/qcsrc/lib/spawnfunc.qh @@ -1,5 +1,4 @@ -#ifndef SPAWNFUNC_H -#define SPAWNFUNC_H +#pragma once /** If this global exists, only functions with spawnfunc_ name prefix qualify as spawn functions */ noref bool require_spawnfunc_prefix; @@ -28,15 +27,27 @@ 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 (!this.sourceLocFile) \ + if (__self == __spawnfunc_expect) \ + { \ + /* engine call */ \ + __spawnfunc_expect = NULL; \ + this = __self; \ + } \ + else \ + { \ + assert(this); \ + } \ + if (!this.sourceLoc) \ { \ - this.sourceLocFile = __FILE__; \ - this.sourceLocLine = __LINE__; \ + this.sourceLoc = __FILE__ ":" STR(__LINE__); \ } \ if (!this.spawnfunc_checked) \ { \ @@ -53,8 +64,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) @@ -69,12 +82,12 @@ noref bool require_spawnfunc_prefix; #define FIELDS_COMMON(fld) \ FIELD_SCALAR(fld, classname) \ + FIELD_SCALAR(fld, sourceLoc) \ FIELD_SCALAR(fld, spawnfunc_checked) \ + FIELD_VEC(fld, origin) \ /**/ #define FIELDS_UNION(fld) \ - FIELD_SCALAR(fld, sourceLocFile) \ - FIELD_SCALAR(fld, sourceLocLine) \ FIELD_SCALAR(fld, Version) \ FIELD_SCALAR(fld, ammo_cells) \ FIELD_SCALAR(fld, ammo_nails) \ @@ -125,7 +138,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) \ @@ -137,6 +152,7 @@ noref bool require_spawnfunc_prefix; FIELD_SCALAR(fld, platmovetype) \ FIELD_SCALAR(fld, race_place) \ FIELD_SCALAR(fld, radius) \ + FIELD_SCALAR(fld, respawntimestart) \ FIELD_SCALAR(fld, respawntimejitter) \ FIELD_SCALAR(fld, respawntime) \ FIELD_SCALAR(fld, restriction) \ @@ -172,10 +188,8 @@ noref bool require_spawnfunc_prefix; FIELD_VEC(fld, maxs) \ FIELD_VEC(fld, mins) \ FIELD_VEC(fld, modelscale_vec) \ - FIELD_VEC(fld, origin) \ FIELD_VEC(fld, velocity) \ /**/ - #define spawnfunc(...) EVAL(OVERLOAD(spawnfunc, __VA_ARGS__, FIELDS_UNION)) - -#endif + #define spawnfunc(...) EVAL_spawnfunc(OVERLOAD(spawnfunc, __VA_ARGS__)) + #define EVAL_spawnfunc(...) __VA_ARGS__