]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/spawnfunc.qh
put sv_damagetext to defaultServer so that resetting server reenables damagetext too
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / spawnfunc.qh
index 98922d4876194748d636ca5978abfff084a5ac4e..f1eb477a00195188c942ca3f7d5ce6b889343d1a 100644 (file)
@@ -33,14 +33,20 @@ noref bool require_spawnfunc_prefix;
 
     .void(entity) __spawnfunc_constructor;
     noref IntrusiveList g_spawn_queue;
-    .string targetname, __spawnfunc_targetname;
+
     #define SPAWNFUNC_INTERNAL_FIELDS(X) \
-        X(targetname, string_null) \
+        X(string, classname, "spawnfunc") \
+        X(string, targetname, string_null) \
         /**/
+
+    #define X(T, fld, def) .T fld, __spawnfunc_##fld;
+    SPAWNFUNC_INTERNAL_FIELDS(X)
+    #undef X
+
     void __spawnfunc_defer(entity prototype, void(entity) constructor)
     {
         IL_PUSH(g_spawn_queue, prototype);
-        #define X(fld, def) { prototype.__spawnfunc_##fld = prototype.fld; prototype.fld = def; }
+        #define X(T, fld, def) { prototype.__spawnfunc_##fld = prototype.fld; prototype.fld = def; }
         SPAWNFUNC_INTERNAL_FIELDS(X);
         #undef X
         prototype.__spawnfunc_constructor = constructor;
@@ -51,23 +57,37 @@ noref bool require_spawnfunc_prefix;
         g_map_entities = IL_NEW(); \
         IL_EACH(g_spawn_queue, true, __spawnfunc_spawn(it)); \
     MACRO_END
-
+#ifdef SVQC
+    void _SV_OnEntityPreSpawnFunction(entity this);
+#endif
     void __spawnfunc_spawn(entity prototype)
     {
         entity e = new(clone);
         copyentity(prototype, e);
         IL_PUSH(g_map_entities, e);
-        #define X(fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; }
+        #define X(T, fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; }
         SPAWNFUNC_INTERNAL_FIELDS(X);
         #undef X
+#ifdef SVQC
+        _SV_OnEntityPreSpawnFunction(e);
+        if (wasfreed(e)) {
+            return;
+        }
+#endif
         e.__spawnfunc_constructor(e);
     }
 
+       noref bool __spawnfunc_first;
+
        #define spawnfunc_1(id) spawnfunc_2(id, FIELDS_UNION)
        #define spawnfunc_2(id, whitelist) \
                void __spawnfunc_##id(entity this); \
                [[accumulate]] void spawnfunc_##id(entity this) \
                { \
+                   if (!__spawnfunc_first) { \
+                __spawnfunc_first = true; \
+                static_init_early(); \
+                   } \
                    bool dospawn = true; \
                    if (__spawnfunc_expecting > 1) { __spawnfunc_expecting = false; } \
                        else if (__spawnfunc_expecting) { \
@@ -99,6 +119,9 @@ noref bool require_spawnfunc_prefix;
                                if (this) { \
                     /* not worldspawn, delay spawn */ \
                     __spawnfunc_defer(this, __spawnfunc_##id); \
+                } else { \
+                    /* world might not be "worldspawn" */ \
+                    this.__spawnfunc_constructor = __spawnfunc_##id; \
                 } \
                        } \
                        if (dospawn) { __spawnfunc_##id(this); } \