Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spawnfunc.qh
Go to the documentation of this file.
1#pragma once
2
3// remove this ifdef when client or menu will actually make use of this stuff
4#ifdef SVQC
5
10noref string __fullspawndata;
12
13// Optional type checking; increases compile time too much to be enabled by default
14#if 0
15 bool entityfieldassignablefromeditor(int i)
16 {
17 switch (entityfieldtype(i))
18 {
19 case FIELD_STRING:
20 case FIELD_FLOAT:
21 case FIELD_VECTOR:
22 return true;
23 }
24 return false;
25 }
26
27 #define _spawnfunc_checktypes(fld) \
28 if (s == #fld) \
29 if (!entityfieldassignablefromeditor(i)) \
30 LOG_FATALF("Entity field '%s' cannot be whitelisted", s);
31#else
32 #define _spawnfunc_checktypes(fld)
33#endif
34 #define _spawnfunc_check(fld) \
35 if (s == #fld) \
36 continue;
37
41
42 .void(entity) __spawnfunc_constructor;
44
45 #define SPAWNFUNC_INTERNAL_FIELDS(X) \
46 X(string, classname, "spawnfunc") \
47 X(string, target, string_null) \
48 X(string, target2, string_null) \
49 X(string, target3, string_null) \
50 X(string, target4, string_null) \
51 X(string, targetname, string_null) \
52 /**/
53
54 #define X(T, fld, def) .T fld, __spawnfunc_##fld;
56 #undef X
57
58 void __spawnfunc_defer(entity prototype, void(entity) constructor)
59 {
60 IL_PUSH(g_spawn_queue, prototype);
61 #define X(T, fld, def) \
62 { \
63 prototype.__spawnfunc_##fld = prototype.fld; \
64 prototype.fld = def; \
65 }
67 #undef X
68 prototype.__spawnfunc_constructor = constructor;
69 }
70
72 #define __spawnfunc_spawn_all() MACRO_BEGIN \
73 g_map_entities = IL_NEW(); \
74 IL_EACH(g_spawn_queue, true, __spawnfunc_spawn(it)); \
75 MACRO_END
76#ifdef SVQC
78#endif
79 void __spawnfunc_spawn(entity prototype)
80 {
81 entity e = new(clone);
82 copyentity_qc(prototype, e);
84 #define X(T, fld, def) \
85 { \
86 e.fld = e.__spawnfunc_##fld; \
87 e.__spawnfunc_##fld = def; \
88 }
90 #undef X
91#ifdef SVQC
93 if (wasfreed(e))
94 return;
95#endif
96 e.__spawnfunc_constructor(e);
97 }
98
101{
103}
104
106
107#define spawnfunc(id) \
108 void __spawnfunc_##id(entity this); \
109 ACCUMULATE void spawnfunc_##id(entity this) \
110 { \
111 if (!__spawnfunc_first) \
112 { \
113 __spawnfunc_first = true; \
114 static_init_early(); \
115 } \
116 bool dospawn = true; \
117 if (__spawnfunc_expecting > 1) \
118 __spawnfunc_expecting = 0; \
119 else if (__spawnfunc_expecting) \
120 { \
121 /* engine call */ \
122 if (!g_spawn_queue) \
123 g_spawn_queue_spawn(); \
124 __spawnfunc_expecting = 0; \
125 this = __spawnfunc_expect; \
126 __spawnfunc_expect = NULL; \
127 dospawn = false; \
128 } \
129 else \
130 /* userland call */ \
131 assert(this); \
132 if (!this.sourceLoc) \
133 this.sourceLoc = __FILE__":"STR(__LINE__); \
134 this.classname = #id; \
135 if (!this.spawnfunc_checked) \
136 { \
137 if (__fullspawndata) \
138 /* not supported in old DP */ \
139 /* must be read inside the real spawnfunc */ \
140 this.fullspawndata = __fullspawndata; \
141 this.spawnfunc_checked = true; \
142 if (this) \
143 { \
144 /* not worldspawn, delay spawn */ \
145 /* clear some dangerous fields (TODO: properly support these in the map!) */ \
146 this.think = func_null; \
147 this.nextthink = 0; \
148 __spawnfunc_defer(this, __spawnfunc_##id); \
149 } \
150 else \
151 /* world might not be "worldspawn" */ \
152 this.__spawnfunc_constructor = __spawnfunc_##id; \
153 } \
154 if (dospawn) \
155 __spawnfunc_##id(this); \
156 if (__spawnfunc_unreachable_workaround) \
157 return; \
158 } \
159 void __spawnfunc_##id(entity this)
160
161#endif // SVQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
float FIELD_VECTOR
float FIELD_STRING
float FIELD_FLOAT
#define X()
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define IL_NEW()
void copyentity_qc(entity src, entity dst)
Definition oo.qh:88
noref IntrusiveList g_map_entities
Definition spawnfunc.qh:71
void g_spawn_queue_spawn()
This function simply avoids expanding IL_NEW during compilation for each spawning entity.
Definition spawnfunc.qh:100
#define SPAWNFUNC_INTERNAL_FIELDS(X)
Definition spawnfunc.qh:45
noref bool __spawnfunc_first
Definition spawnfunc.qh:105
noref string __fullspawndata
Not for production use, provides access to a dump of the entity's fields when it is parsed from map d...
Definition spawnfunc.qh:10
void __spawnfunc_spawn(entity prototype)
Definition spawnfunc.qh:79
noref bool __spawnfunc_unreachable_workaround
Definition spawnfunc.qh:40
void _SV_OnEntityPreSpawnFunction(entity this)
void __spawnfunc_defer(entity prototype, void(entity) constructor)
Definition spawnfunc.qh:58
noref entity __spawnfunc_expect
Definition spawnfunc.qh:39
noref bool require_spawnfunc_prefix
If this global exists, only functions with spawnfunc_ name prefix qualify as spawn functions.
Definition spawnfunc.qh:7
string fullspawndata
Definition spawnfunc.qh:11
bool spawnfunc_checked
Definition spawnfunc.qh:8
noref IntrusiveList g_spawn_queue
Definition spawnfunc.qh:43
noref int __spawnfunc_expecting
Definition spawnfunc.qh:38