]> git.xonotic.org Git - xonotic/darkplaces.git/blob - progsvm.h
CLVM: remove cruft
[xonotic/darkplaces.git] / progsvm.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 /*
21 This is a try to make the vm more generic, it is mainly based on the progs.h file.
22 For the license refer to progs.h.
23
24 Generic means, less as possible hard-coded links with the other parts of the engine.
25 This means no edict_engineprivate struct usage, etc.
26 The code uses void pointers instead.
27 */
28
29 #ifndef PROGSVM_H
30 #define PROGSVM_H
31
32 #include <stddef.h>
33 #include "qtypes.h"
34 #include "qdefs.h"
35 #include "common.h"
36 #include "zone.h"
37 #include "pr_comp.h"                    // defs shared with qcc
38 #include "progdefs.h"                   // generated by program cdefs
39 #include "clprogdefs.h"                 // generated by program cdefs
40
41 struct framegroupblend_s;
42 struct frameblend_s;
43 struct cmd_state_s;
44 struct qfile_s;
45
46 #ifndef DP_SMALLMEMORY
47 #define PROFILING
48 #endif
49
50 typedef struct prvm_stack_s
51 {
52         int                             s;
53         mfunction_t             *f;
54         double                  tprofile_acc;
55         double                  profile_acc;
56         double                  builtinsprofile_acc;
57 } prvm_stack_t;
58
59
60 typedef union prvm_eval_s
61 {
62         prvm_int_t              string;
63         prvm_vec_t      _float;
64         prvm_vec_t      vector[3];
65         prvm_int_t              function;
66         prvm_int_t              ivector[3];
67         prvm_int_t              _int;
68         prvm_int_t              edict;
69 } prvm_eval_t;
70
71 typedef struct prvm_required_field_s
72 {
73         int type;
74         const char *name;
75 } prvm_required_field_t;
76
77 #define PRVM_EDICT_MARK_WAIT_FOR_SETORIGIN -1
78 #define PRVM_EDICT_MARK_SETORIGIN_CAUGHT -2
79 // AK: I dont call it engine private cause it doesnt really belongs to the engine
80 //     it belongs to prvm.
81 typedef struct prvm_edict_private_s
82 {
83         // mark for the leak detector
84         int mark;
85         // place in the code where it was allocated (for the leak detector)
86         const char *allocation_origin;
87 } prvm_edict_private_t;
88
89 typedef struct prvm_edict_s
90 {
91         // true if this edict is unused
92         qbool free;
93         // sv.time when the object was freed (to prevent early reuse which could
94         // mess up client interpolation or obscure severe QuakeC bugs)
95         double freetime;
96
97         // engine-private fields (stored in dynamically resized array)
98         union
99         {
100                 prvm_edict_private_t *required;
101                 prvm_vec_t *fp;
102                 prvm_int_t *ip;
103                 // FIXME: this server pointer really means world, not server
104                 // (it is used by both server qc and client qc, but not menu qc)
105                 struct edict_engineprivate_s *server;
106                 // add other private structs as you desire
107                 // new structs have to start with the elements of prvm_edit_private_t
108                 // e.g. a new struct has to either look like this:
109                 //      typedef struct server_edict_private_s {
110                 //              prvm_edict_private_t base;
111                 //              vec3_t moved_from;
112                 //      vec3_t moved_fromangles;
113                 //              ... } server_edict_private_t;
114                 // or:
115                 //      typedef struct server_edict_private_s {
116                 //              qbool free;
117                 //              float freetime;
118                 //              vec3_t moved_from;
119                 //      vec3_t moved_fromangles;
120                 //              ... } server_edict_private_t;
121                 // However, the first one should be preferred.
122         } priv;
123         // QuakeC fields (stored in dynamically resized array)
124         union
125         {
126                 prvm_vec_t *fp;
127                 prvm_int_t *ip;
128 //              entvars_t               *server;
129 //              cl_entvars_t    *client;
130         } fields;
131 } prvm_edict_t;
132
133 extern prvm_eval_t prvm_badvalue;
134
135 #define PRVM_alledictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
136 #define PRVM_alledictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
137 #define PRVM_alledictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
138 #define PRVM_alledictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
139 #define PRVM_alledictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
140 #define PRVM_allglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
141 #define PRVM_allglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
142 #define PRVM_allglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
143 #define PRVM_allglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
144 #define PRVM_allglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
145 #define PRVM_allfunction(funcname)           (prog->funcoffsets.funcname)
146
147 #define PRVM_drawedictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
148 #define PRVM_drawedictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
149 #define PRVM_drawedictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
150 #define PRVM_drawedictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
151 #define PRVM_drawedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
152 #define PRVM_drawglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
153 #define PRVM_drawglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
154 #define PRVM_drawglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
155 #define PRVM_drawglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
156 #define PRVM_drawglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
157 #define PRVM_drawfunction(funcname)           (prog->funcoffsets.funcname)
158
159 #define PRVM_gameedictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
160 #define PRVM_gameedictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
161 #define PRVM_gameedictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
162 #define PRVM_gameedictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
163 #define PRVM_gameedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
164 #define PRVM_gameglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
165 #define PRVM_gameglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
166 #define PRVM_gameglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
167 #define PRVM_gameglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
168 #define PRVM_gameglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
169 #define PRVM_gamefunction(funcname)           (prog->funcoffsets.funcname)
170
171 #define PRVM_serveredictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
172 #define PRVM_serveredictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
173 #define PRVM_serveredictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
174 #define PRVM_serveredictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
175 #define PRVM_serveredictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
176 #define PRVM_serverglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
177 #define PRVM_serverglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
178 #define PRVM_serverglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
179 #define PRVM_serverglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
180 #define PRVM_serverglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
181 #define PRVM_serverfunction(funcname)           (prog->funcoffsets.funcname)
182
183 #define PRVM_clientedictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
184 #define PRVM_clientedictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
185 #define PRVM_clientedictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
186 #define PRVM_clientedictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
187 #define PRVM_clientedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
188 #define PRVM_clientglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
189 #define PRVM_clientglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
190 #define PRVM_clientglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
191 #define PRVM_clientglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
192 #define PRVM_clientglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
193 #define PRVM_clientfunction(funcname)           (prog->funcoffsets.funcname)
194
195 #define PRVM_menuedictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
196 #define PRVM_menuedictvector(ed, fieldname)   (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
197 #define PRVM_menuedictstring(ed, fieldname)   (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
198 #define PRVM_menuedictedict(ed, fieldname)    (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
199 #define PRVM_menuedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
200 #define PRVM_menuglobalfloat(fieldname)       (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
201 #define PRVM_menuglobalvector(fieldname)      (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
202 #define PRVM_menuglobalstring(fieldname)      (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
203 #define PRVM_menuglobaledict(fieldname)       (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
204 #define PRVM_menuglobalfunction(fieldname)    (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
205 #define PRVM_menufunction(funcname)           (prog->funcoffsets.funcname)
206
207 #if 1
208 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset)    ((fieldoffset) < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)((ed)->fields.fp + (fieldoffset)))
209 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset)    (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->_float)
210 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset)   (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->vector)
211 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset)   (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->string)
212 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset)    (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->edict)
213 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->function)
214 #define PRVM_GLOBALFIELDVALUE(fieldoffset)       ((fieldoffset) < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)(prog->globals.fp + (fieldoffset)))
215 #define PRVM_GLOBALFIELDFLOAT(fieldoffset)       (PRVM_GLOBALFIELDVALUE(fieldoffset)->_float)
216 #define PRVM_GLOBALFIELDVECTOR(fieldoffset)      (PRVM_GLOBALFIELDVALUE(fieldoffset)->vector)
217 #define PRVM_GLOBALFIELDSTRING(fieldoffset)      (PRVM_GLOBALFIELDVALUE(fieldoffset)->string)
218 #define PRVM_GLOBALFIELDEDICT(fieldoffset)       (PRVM_GLOBALFIELDVALUE(fieldoffset)->edict)
219 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset)    (PRVM_GLOBALFIELDVALUE(fieldoffset)->function)
220 #else
221 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)(ed->fields.fp + fieldoffset))
222 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->_float)
223 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->vector)
224 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->string)
225 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->edict)
226 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->function)
227 #define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)(prog->globals.fp + fieldoffset))
228 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->_float)
229 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->vector)
230 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->string)
231 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->edict)
232 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->function)
233 #endif
234
235 //============================================================================
236 #define PRVM_OP_STATE           1
237
238 #ifdef DP_SMALLMEMORY
239 #define PRVM_MAX_STACK_DEPTH            128
240 #define PRVM_LOCALSTACK_SIZE            2048
241
242 #define PRVM_MAX_OPENFILES 16
243 #define PRVM_MAX_OPENSEARCHES 8
244 #else
245 #define PRVM_MAX_STACK_DEPTH            1024
246 #define PRVM_LOCALSTACK_SIZE            16384
247
248 #define PRVM_MAX_OPENFILES 256
249 #define PRVM_MAX_OPENSEARCHES 128
250 #endif
251
252 struct prvm_prog_s;
253 typedef void (*prvm_builtin_t) (struct prvm_prog_s *prog);
254
255 // NOTE: field offsets use -1 for NULL
256 typedef struct prvm_prog_fieldoffsets_s
257 {
258 #define PRVM_DECLARE_serverglobalfloat(x)
259 #define PRVM_DECLARE_serverglobalvector(x)
260 #define PRVM_DECLARE_serverglobalstring(x)
261 #define PRVM_DECLARE_serverglobaledict(x)
262 #define PRVM_DECLARE_serverglobalfunction(x)
263 #define PRVM_DECLARE_clientglobalfloat(x)
264 #define PRVM_DECLARE_clientglobalvector(x)
265 #define PRVM_DECLARE_clientglobalstring(x)
266 #define PRVM_DECLARE_clientglobaledict(x)
267 #define PRVM_DECLARE_clientglobalfunction(x)
268 #define PRVM_DECLARE_menuglobalfloat(x)
269 #define PRVM_DECLARE_menuglobalvector(x)
270 #define PRVM_DECLARE_menuglobalstring(x)
271 #define PRVM_DECLARE_menuglobaledict(x)
272 #define PRVM_DECLARE_menuglobalfunction(x)
273 #define PRVM_DECLARE_serverfieldfloat(x)
274 #define PRVM_DECLARE_serverfieldvector(x)
275 #define PRVM_DECLARE_serverfieldstring(x)
276 #define PRVM_DECLARE_serverfieldedict(x)
277 #define PRVM_DECLARE_serverfieldfunction(x)
278 #define PRVM_DECLARE_clientfieldfloat(x)
279 #define PRVM_DECLARE_clientfieldvector(x)
280 #define PRVM_DECLARE_clientfieldstring(x)
281 #define PRVM_DECLARE_clientfieldedict(x)
282 #define PRVM_DECLARE_clientfieldfunction(x)
283 #define PRVM_DECLARE_menufieldfloat(x)
284 #define PRVM_DECLARE_menufieldvector(x)
285 #define PRVM_DECLARE_menufieldstring(x)
286 #define PRVM_DECLARE_menufieldedict(x)
287 #define PRVM_DECLARE_menufieldfunction(x)
288 #define PRVM_DECLARE_serverfunction(x)
289 #define PRVM_DECLARE_clientfunction(x)
290 #define PRVM_DECLARE_menufunction(x)
291 #define PRVM_DECLARE_field(x) int x;
292 #define PRVM_DECLARE_global(x)
293 #define PRVM_DECLARE_function(x)
294 #include "prvm_offsets.h"
295 #undef PRVM_DECLARE_serverglobalfloat
296 #undef PRVM_DECLARE_serverglobalvector
297 #undef PRVM_DECLARE_serverglobalstring
298 #undef PRVM_DECLARE_serverglobaledict
299 #undef PRVM_DECLARE_serverglobalfunction
300 #undef PRVM_DECLARE_clientglobalfloat
301 #undef PRVM_DECLARE_clientglobalvector
302 #undef PRVM_DECLARE_clientglobalstring
303 #undef PRVM_DECLARE_clientglobaledict
304 #undef PRVM_DECLARE_clientglobalfunction
305 #undef PRVM_DECLARE_menuglobalfloat
306 #undef PRVM_DECLARE_menuglobalvector
307 #undef PRVM_DECLARE_menuglobalstring
308 #undef PRVM_DECLARE_menuglobaledict
309 #undef PRVM_DECLARE_menuglobalfunction
310 #undef PRVM_DECLARE_serverfieldfloat
311 #undef PRVM_DECLARE_serverfieldvector
312 #undef PRVM_DECLARE_serverfieldstring
313 #undef PRVM_DECLARE_serverfieldedict
314 #undef PRVM_DECLARE_serverfieldfunction
315 #undef PRVM_DECLARE_clientfieldfloat
316 #undef PRVM_DECLARE_clientfieldvector
317 #undef PRVM_DECLARE_clientfieldstring
318 #undef PRVM_DECLARE_clientfieldedict
319 #undef PRVM_DECLARE_clientfieldfunction
320 #undef PRVM_DECLARE_menufieldfloat
321 #undef PRVM_DECLARE_menufieldvector
322 #undef PRVM_DECLARE_menufieldstring
323 #undef PRVM_DECLARE_menufieldedict
324 #undef PRVM_DECLARE_menufieldfunction
325 #undef PRVM_DECLARE_serverfunction
326 #undef PRVM_DECLARE_clientfunction
327 #undef PRVM_DECLARE_menufunction
328 #undef PRVM_DECLARE_field
329 #undef PRVM_DECLARE_global
330 #undef PRVM_DECLARE_function
331 }
332 prvm_prog_fieldoffsets_t;
333
334 // NOTE: global offsets use -1 for NULL
335 typedef struct prvm_prog_globaloffsets_s
336 {
337 #define PRVM_DECLARE_serverglobalfloat(x)
338 #define PRVM_DECLARE_serverglobalvector(x)
339 #define PRVM_DECLARE_serverglobalstring(x)
340 #define PRVM_DECLARE_serverglobaledict(x)
341 #define PRVM_DECLARE_serverglobalfunction(x)
342 #define PRVM_DECLARE_clientglobalfloat(x)
343 #define PRVM_DECLARE_clientglobalvector(x)
344 #define PRVM_DECLARE_clientglobalstring(x)
345 #define PRVM_DECLARE_clientglobaledict(x)
346 #define PRVM_DECLARE_clientglobalfunction(x)
347 #define PRVM_DECLARE_menuglobalfloat(x)
348 #define PRVM_DECLARE_menuglobalvector(x)
349 #define PRVM_DECLARE_menuglobalstring(x)
350 #define PRVM_DECLARE_menuglobaledict(x)
351 #define PRVM_DECLARE_menuglobalfunction(x)
352 #define PRVM_DECLARE_serverfieldfloat(x)
353 #define PRVM_DECLARE_serverfieldvector(x)
354 #define PRVM_DECLARE_serverfieldstring(x)
355 #define PRVM_DECLARE_serverfieldedict(x)
356 #define PRVM_DECLARE_serverfieldfunction(x)
357 #define PRVM_DECLARE_clientfieldfloat(x)
358 #define PRVM_DECLARE_clientfieldvector(x)
359 #define PRVM_DECLARE_clientfieldstring(x)
360 #define PRVM_DECLARE_clientfieldedict(x)
361 #define PRVM_DECLARE_clientfieldfunction(x)
362 #define PRVM_DECLARE_menufieldfloat(x)
363 #define PRVM_DECLARE_menufieldvector(x)
364 #define PRVM_DECLARE_menufieldstring(x)
365 #define PRVM_DECLARE_menufieldedict(x)
366 #define PRVM_DECLARE_menufieldfunction(x)
367 #define PRVM_DECLARE_serverfunction(x)
368 #define PRVM_DECLARE_clientfunction(x)
369 #define PRVM_DECLARE_menufunction(x)
370 #define PRVM_DECLARE_field(x)
371 #define PRVM_DECLARE_global(x) int x;
372 #define PRVM_DECLARE_function(x)
373 #include "prvm_offsets.h"
374 #undef PRVM_DECLARE_serverglobalfloat
375 #undef PRVM_DECLARE_serverglobalvector
376 #undef PRVM_DECLARE_serverglobalstring
377 #undef PRVM_DECLARE_serverglobaledict
378 #undef PRVM_DECLARE_serverglobalfunction
379 #undef PRVM_DECLARE_clientglobalfloat
380 #undef PRVM_DECLARE_clientglobalvector
381 #undef PRVM_DECLARE_clientglobalstring
382 #undef PRVM_DECLARE_clientglobaledict
383 #undef PRVM_DECLARE_clientglobalfunction
384 #undef PRVM_DECLARE_menuglobalfloat
385 #undef PRVM_DECLARE_menuglobalvector
386 #undef PRVM_DECLARE_menuglobalstring
387 #undef PRVM_DECLARE_menuglobaledict
388 #undef PRVM_DECLARE_menuglobalfunction
389 #undef PRVM_DECLARE_serverfieldfloat
390 #undef PRVM_DECLARE_serverfieldvector
391 #undef PRVM_DECLARE_serverfieldstring
392 #undef PRVM_DECLARE_serverfieldedict
393 #undef PRVM_DECLARE_serverfieldfunction
394 #undef PRVM_DECLARE_clientfieldfloat
395 #undef PRVM_DECLARE_clientfieldvector
396 #undef PRVM_DECLARE_clientfieldstring
397 #undef PRVM_DECLARE_clientfieldedict
398 #undef PRVM_DECLARE_clientfieldfunction
399 #undef PRVM_DECLARE_menufieldfloat
400 #undef PRVM_DECLARE_menufieldvector
401 #undef PRVM_DECLARE_menufieldstring
402 #undef PRVM_DECLARE_menufieldedict
403 #undef PRVM_DECLARE_menufieldfunction
404 #undef PRVM_DECLARE_serverfunction
405 #undef PRVM_DECLARE_clientfunction
406 #undef PRVM_DECLARE_menufunction
407 #undef PRVM_DECLARE_field
408 #undef PRVM_DECLARE_global
409 #undef PRVM_DECLARE_function
410 }
411 prvm_prog_globaloffsets_t;
412
413 // NOTE: function offsets use 0 for NULL
414 typedef struct prvm_prog_funcoffsets_s
415 {
416 #define PRVM_DECLARE_serverglobalfloat(x)
417 #define PRVM_DECLARE_serverglobalvector(x)
418 #define PRVM_DECLARE_serverglobalstring(x)
419 #define PRVM_DECLARE_serverglobaledict(x)
420 #define PRVM_DECLARE_serverglobalfunction(x)
421 #define PRVM_DECLARE_clientglobalfloat(x)
422 #define PRVM_DECLARE_clientglobalvector(x)
423 #define PRVM_DECLARE_clientglobalstring(x)
424 #define PRVM_DECLARE_clientglobaledict(x)
425 #define PRVM_DECLARE_clientglobalfunction(x)
426 #define PRVM_DECLARE_menuglobalfloat(x)
427 #define PRVM_DECLARE_menuglobalvector(x)
428 #define PRVM_DECLARE_menuglobalstring(x)
429 #define PRVM_DECLARE_menuglobaledict(x)
430 #define PRVM_DECLARE_menuglobalfunction(x)
431 #define PRVM_DECLARE_serverfieldfloat(x)
432 #define PRVM_DECLARE_serverfieldvector(x)
433 #define PRVM_DECLARE_serverfieldstring(x)
434 #define PRVM_DECLARE_serverfieldedict(x)
435 #define PRVM_DECLARE_serverfieldfunction(x)
436 #define PRVM_DECLARE_clientfieldfloat(x)
437 #define PRVM_DECLARE_clientfieldvector(x)
438 #define PRVM_DECLARE_clientfieldstring(x)
439 #define PRVM_DECLARE_clientfieldedict(x)
440 #define PRVM_DECLARE_clientfieldfunction(x)
441 #define PRVM_DECLARE_menufieldfloat(x)
442 #define PRVM_DECLARE_menufieldvector(x)
443 #define PRVM_DECLARE_menufieldstring(x)
444 #define PRVM_DECLARE_menufieldedict(x)
445 #define PRVM_DECLARE_menufieldfunction(x)
446 #define PRVM_DECLARE_serverfunction(x)
447 #define PRVM_DECLARE_clientfunction(x)
448 #define PRVM_DECLARE_menufunction(x)
449 #define PRVM_DECLARE_field(x)
450 #define PRVM_DECLARE_global(x)
451 #define PRVM_DECLARE_function(x) int x;
452 #include "prvm_offsets.h"
453 #undef PRVM_DECLARE_serverglobalfloat
454 #undef PRVM_DECLARE_serverglobalvector
455 #undef PRVM_DECLARE_serverglobalstring
456 #undef PRVM_DECLARE_serverglobaledict
457 #undef PRVM_DECLARE_serverglobalfunction
458 #undef PRVM_DECLARE_clientglobalfloat
459 #undef PRVM_DECLARE_clientglobalvector
460 #undef PRVM_DECLARE_clientglobalstring
461 #undef PRVM_DECLARE_clientglobaledict
462 #undef PRVM_DECLARE_clientglobalfunction
463 #undef PRVM_DECLARE_menuglobalfloat
464 #undef PRVM_DECLARE_menuglobalvector
465 #undef PRVM_DECLARE_menuglobalstring
466 #undef PRVM_DECLARE_menuglobaledict
467 #undef PRVM_DECLARE_menuglobalfunction
468 #undef PRVM_DECLARE_serverfieldfloat
469 #undef PRVM_DECLARE_serverfieldvector
470 #undef PRVM_DECLARE_serverfieldstring
471 #undef PRVM_DECLARE_serverfieldedict
472 #undef PRVM_DECLARE_serverfieldfunction
473 #undef PRVM_DECLARE_clientfieldfloat
474 #undef PRVM_DECLARE_clientfieldvector
475 #undef PRVM_DECLARE_clientfieldstring
476 #undef PRVM_DECLARE_clientfieldedict
477 #undef PRVM_DECLARE_clientfieldfunction
478 #undef PRVM_DECLARE_menufieldfloat
479 #undef PRVM_DECLARE_menufieldvector
480 #undef PRVM_DECLARE_menufieldstring
481 #undef PRVM_DECLARE_menufieldedict
482 #undef PRVM_DECLARE_menufieldfunction
483 #undef PRVM_DECLARE_serverfunction
484 #undef PRVM_DECLARE_clientfunction
485 #undef PRVM_DECLARE_menufunction
486 #undef PRVM_DECLARE_field
487 #undef PRVM_DECLARE_global
488 #undef PRVM_DECLARE_function
489 }
490 prvm_prog_funcoffsets_t;
491
492 // stringbuffer flags
493 #define STRINGBUFFER_SAVED     1   // saved in savegames
494 #define STRINGBUFFER_QCFLAGS   1   // allowed to be set by QC
495 #define STRINGBUFFER_TEMP      128 // internal use ONLY 
496 typedef struct prvm_stringbuffer_s
497 {
498         int max_strings;
499         int num_strings;
500         char **strings;
501         const char *origin;
502         unsigned char flags;
503 }
504 prvm_stringbuffer_t;
505
506 // flags for knownstrings
507 #define KNOWNSTRINGFLAG_ENGINE 1
508 #define KNOWNSTRINGFLAG_GCMARK 2
509 #define KNOWNSTRINGFLAG_GCPRUNE 4 // cleared by GCMARK code, string is freed if prune remains after two sweeps
510
511 typedef enum prvm_prog_garbagecollection_state_stage_e
512 {
513         PRVM_GC_START = 0,
514         PRVM_GC_GLOBALS_MARK,
515         PRVM_GC_FIELDS_MARK,
516         PRVM_GC_KNOWNSTRINGS_SWEEP,
517         PRVM_GC_RESET,
518 }
519 prvm_prog_garbagecollection_state_stage_t;
520
521 typedef struct prvm_prog_garbagecollection_state_s
522 {
523         int stage;
524         int globals_mark_progress;
525         int fields_mark_progress;
526         int fields_mark_progress_entity;
527         int knownstrings_sweep_progress;
528 }
529 prvm_prog_garbagecollection_state_t;
530
531 // [INIT] variables flagged with this token can be initialized by 'you'
532 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
533 typedef struct prvm_prog_s
534 {
535         double                          starttime; // system time when PRVM_Prog_Load was called
536         double                          inittime; // system time when QC initialization code finished (any entity created before is not a leak)
537         double                          profiletime; // system time when last PRVM_CallProfile was called (or PRVM_Prog_Load initially)
538         mfunction_t                     *functions;
539         int                             functions_covered;
540         char                            *strings;
541         int                                     stringssize;
542         mdef_t                          *fielddefs;
543         mdef_t                          *globaldefs;
544         mstatement_t            *statements;
545         int                                     entityfields;                   // number of vec_t fields in progs (some variables are 3)
546         int                                     entityfieldsarea;               // LadyHavoc: equal to max_edicts * entityfields (for bounds checking)
547
548         // loaded values from the disk format
549         int                                     progs_version;
550         int                                     progs_crc;
551         int                                     progs_numstatements;
552         int                                     progs_numglobaldefs;
553         int                                     progs_numfielddefs;
554         int                                     progs_numfunctions;
555         int                                     progs_numstrings;
556         int                                     progs_numglobals;
557         int                                     progs_entityfields;
558
559         // real values in memory (some modified by loader)
560         int                                     numstatements;
561         int                                     numglobaldefs;
562         int                                     numfielddefs;
563         int                                     numfunctions;
564         int                                     numstrings;
565         int                                     numglobals;
566
567         int                                     *statement_linenums; // NULL if not available
568         int                                     *statement_columnnums; // NULL if not available
569
570         double                          *statement_profile; // only incremented if prvm_statementprofiling is on
571         int                             statements_covered;
572         double                          *explicit_profile; // only incremented if prvm_statementprofiling is on
573         int                             explicit_covered;
574         int                             numexplicitcoveragestatements;
575
576         union {
577                 prvm_vec_t *fp;
578                 prvm_int_t *ip;
579 //              globalvars_t *server;
580 //              cl_globalvars_t *client;
581         } globals;
582
583         int                                     maxknownstrings;
584         int                                     numknownstrings;
585         // this is updated whenever a string is removed or added
586         // (simple optimization of the free string search)
587         int                                     firstfreeknownstring;
588         const char                      **knownstrings;
589         unsigned char           *knownstrings_flags;
590         const char          **knownstrings_origin;
591         const char                      ***stringshash;
592
593         memexpandablearray_t    stringbuffersarray;
594
595         // garbage collection status
596         prvm_prog_garbagecollection_state_t gc;
597
598         // all memory allocations related to this vm_prog (code, edicts, strings)
599         mempool_t                       *progs_mempool; // [INIT]
600
601         prvm_builtin_t          *builtins; // [INIT]
602         int                                     numbuiltins; // [INIT]
603
604         int                                     argc;
605
606         int                                     trace;
607         int                                     break_statement;
608         int                                     break_stack_index;
609         int                                     watch_global;
610         etype_t                                 watch_global_type;
611         prvm_eval_t                             watch_global_value;
612         int                                     watch_edict;
613         int                                     watch_field;
614         etype_t                                 watch_field_type;
615         prvm_eval_t                             watch_edictfield_value;
616
617         mfunction_t                     *xfunction;
618         int                                     xstatement;
619
620         // stacktrace writes into stack[MAX_STACK_DEPTH]
621         // thus increase the array, so depth wont be overwritten
622         prvm_stack_t            stack[PRVM_MAX_STACK_DEPTH+1];
623         int                                     depth;
624
625         prvm_int_t                      localstack[PRVM_LOCALSTACK_SIZE];
626         int                                     localstack_used;
627
628         unsigned short          filecrc;
629
630         //============================================================================
631         // until this point everything also exists (with the pr_ prefix) in the old vm
632
633         struct qfile_s                          *openfiles[PRVM_MAX_OPENFILES];
634         const char *         openfiles_origin[PRVM_MAX_OPENFILES];
635         struct fssearch_s                       *opensearches[PRVM_MAX_OPENSEARCHES];
636         const char *         opensearches_origin[PRVM_MAX_OPENSEARCHES];
637         struct skeleton_s       *skeletons[MAX_EDICTS];
638         struct cmd_state_s      *console_cmd; // points to the relevant console command interpreter for this vm (cmd_local or &cmd_server), also used to access cvars
639
640         // buffer for storing all tempstrings created during one invocation of ExecuteProgram
641         sizebuf_t                       tempstringsbuf;
642
643         // polygonbegin, polygonvertex, polygonend state
644         // the polygon is buffered here until polygonend commits it to the relevant
645         // CL_Mesh entity, because important decisions depend on the vertex data
646         // provided (e.g. whether the polygon is transparent), we can't really do much
647         // with it until we have all of the data...
648
649         // this tracks the last polygonbegin's choice of
650         // CL_Mesh_CSQC or CL_Mesh_UI for this polygon
651         struct model_s          *polygonbegin_model;
652         // indicates if polygonbegin should be interpreted as 2d
653         // (clearscene sets this to false, renderscene sets this to true, drawpic
654         //  also sets this to true)
655         // note that in FTEQW polygonbegin with 2 args is handled very differently,
656         // where the behavior is always 3D unless DRAWFLAG_2D is passed, but
657         // DRAWFLAG_2D conflicts with our DRAWFLAG_SCREEN.
658         qbool                   polygonbegin_guess2d;
659         // the texture name and drawflags provided to polygonbegin
660         char                            polygonbegin_texname[MAX_QPATH];
661         int                                     polygonbegin_drawflags;
662         // the vertex data
663         int                                     polygonbegin_numvertices;
664         int                                     polygonbegin_maxvertices;
665         float                           *polygonbegin_vertexdata;
666
667         // copies of some vars that were former read from sv
668         int                                     num_edicts;
669         // number of edicts for which space has been (should be) allocated
670         int                                     max_edicts; // [INIT]
671         // used instead of the constant MAX_EDICTS
672         int                                     limit_edicts; // [INIT]
673
674         // number of reserved edicts (allocated from 1)
675         int                                     reserved_edicts; // [INIT]
676
677         prvm_edict_t            *edicts;
678         union
679         {
680                 prvm_vec_t *fp;
681                 prvm_int_t *ip;
682         } edictsfields;
683         void                            *edictprivate;
684
685         // size of the engine private struct
686         int                                     edictprivate_size; // [INIT]
687
688         prvm_prog_fieldoffsets_t        fieldoffsets;
689         prvm_prog_globaloffsets_t       globaloffsets;
690         prvm_prog_funcoffsets_t funcoffsets;
691
692         // allow writing to world entity fields, this is set by server init and
693         // cleared before first server frame
694         qbool                   allowworldwrites;
695
696         // name of the prog, e.g. "Server", "Client" or "Menu" (used for text output)
697         const char                      *name; // [INIT]
698
699         // flag - used to store general flags like PRVM_GE_SELF, etc.
700         int                             flag;
701
702         const char                      **extensionstring; // [INIT]
703
704         qbool                   loadintoworld; // [INIT]
705
706         // used to indicate whether a prog is loaded
707         qbool                   loaded;
708         qbool                   leaktest_active;
709
710         // translation buffer (only needs to be freed on unloading progs, type is private to prvm_edict.c)
711         void *po;
712
713         // printed together with backtraces
714         const char *statestring;
715
716         struct animatemodel_cache *animatemodel_cache;
717
718 //      prvm_builtin_mem_t  *mem_list;
719
720 // now passed as parameter of PRVM_Prog_Load
721 //      char                            **required_func;
722 //      int                                     numrequiredfunc;
723
724         //============================================================================
725
726         mdef_t                          *self; // if self != 0 then there is a global self
727
728         //============================================================================
729         // function pointers
730
731         void                            (*begin_increase_edicts)(struct prvm_prog_s *prog); // [INIT] used by PRVM_MEM_Increase_Edicts
732         void                            (*end_increase_edicts)(struct prvm_prog_s *prog); // [INIT]
733
734         void                            (*init_edict)(struct prvm_prog_s *prog, prvm_edict_t *edict); // [INIT] used by PRVM_ED_ClearEdict
735         void                            (*free_edict)(struct prvm_prog_s *prog, prvm_edict_t *ed); // [INIT] used by PRVM_ED_Free
736
737         void                            (*count_edicts)(struct prvm_prog_s *prog); // [INIT] used by PRVM_ED_Count_f
738
739         qbool                   (*load_edict)(struct prvm_prog_s *prog, prvm_edict_t *ent); // [INIT] used by PRVM_ED_LoadFromFile
740
741         void                            (*init_cmd)(struct prvm_prog_s *prog); // [INIT] used by PRVM_InitProg
742         void                            (*reset_cmd)(struct prvm_prog_s *prog); // [INIT] used by PRVM_ResetProg
743
744         void                            (*error_cmd)(const char *format, ...) DP_FUNC_PRINTF(1); // [INIT]
745
746         void                            (*ExecuteProgram)(struct prvm_prog_s *prog, func_t fnum, const char *errormessage); // pointer to one of the *VM_ExecuteProgram functions
747 } prvm_prog_t;
748
749 typedef enum prvm_progindex_e
750 {
751         PRVM_PROG_SERVER,
752         PRVM_PROG_CLIENT,
753         PRVM_PROG_MENU,
754         PRVM_PROG_MAX
755 }
756 prvm_progindex_t;
757
758 extern prvm_prog_t prvm_prog_list[PRVM_PROG_MAX];
759 prvm_prog_t *PRVM_ProgFromString(const char *str);
760 prvm_prog_t *PRVM_FriendlyProgFromString(const char *str); // for console commands (prints error if name unknown and returns NULL, prints error if prog not loaded and returns NULL)
761 #define PRVM_GetProg(n) (&prvm_prog_list[(n)])
762 #define PRVM_ProgLoaded(n) (PRVM_GetProg(n)->loaded)
763 #define SVVM_prog (&prvm_prog_list[PRVM_PROG_SERVER])
764 #define CLVM_prog (&prvm_prog_list[PRVM_PROG_CLIENT])
765 #ifdef CONFIG_MENU
766 #define MVM_prog (&prvm_prog_list[PRVM_PROG_MENU])
767 #endif
768
769 //============================================================================
770 // prvm_cmds part
771
772 extern prvm_builtin_t vm_sv_builtins[];
773 extern prvm_builtin_t vm_cl_builtins[];
774 extern prvm_builtin_t vm_m_builtins[];
775
776 extern const int vm_sv_numbuiltins;
777 extern const int vm_cl_numbuiltins;
778 extern const int vm_m_numbuiltins;
779
780 extern const char *vm_sv_extensions[]; // client also uses this
781 extern const char *vm_m_extensions[];
782
783 void SVVM_init_cmd(prvm_prog_t *prog);
784 void SVVM_reset_cmd(prvm_prog_t *prog);
785
786 void CLVM_init_cmd(prvm_prog_t *prog);
787 void CLVM_reset_cmd(prvm_prog_t *prog);
788
789 #ifdef CONFIG_MENU
790 void MVM_init_cmd(prvm_prog_t *prog);
791 void MVM_reset_cmd(prvm_prog_t *prog);
792 #endif
793
794 void VM_Cmd_Init(prvm_prog_t *prog);
795 void VM_Cmd_Reset(prvm_prog_t *prog);
796 //============================================================================
797
798 void PRVM_Init (void);
799
800 #ifdef PROFILING
801 void SVVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
802 void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
803 #ifdef CONFIG_MENU
804 void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
805 #endif
806 #else
807 #define SVVM_ExecuteProgram PRVM_ExecuteProgram
808 #define CLVM_ExecuteProgram PRVM_ExecuteProgram
809 #ifdef CONFIG_MENU
810 #define MVM_ExecuteProgram PRVM_ExecuteProgram
811 #endif
812 void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
813 #endif
814
815 #define PRVM_Alloc(buffersize) Mem_Alloc(prog->progs_mempool, buffersize)
816 #define PRVM_Free(buffer) Mem_Free(buffer)
817
818 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby);
819 void PRVM_Profile_f(struct cmd_state_s *cmd);
820 void PRVM_ChildProfile_f(struct cmd_state_s *cmd);
821 void PRVM_CallProfile_f(struct cmd_state_s *cmd);
822 void PRVM_PrintFunction_f(struct cmd_state_s *cmd);
823
824 void PRVM_PrintState(prvm_prog_t *prog, int stack_index);
825 void PRVM_Crash(void);
826 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize);
827 const char *PRVM_AllocationOrigin(prvm_prog_t *prog);
828 void PRVM_GarbageCollection(prvm_prog_t *prog);
829
830 mdef_t *PRVM_ED_FindField(prvm_prog_t *prog, const char *name);
831 mdef_t *PRVM_ED_FindGlobal(prvm_prog_t *prog, const char *name);
832 prvm_eval_t *PRVM_ED_FindGlobalEval(prvm_prog_t *prog, const char *name);
833 mfunction_t *PRVM_ED_FindFunction(prvm_prog_t *prog, const char *name);
834
835 int PRVM_ED_FindFieldOffset(prvm_prog_t *prog, const char *name);
836 int PRVM_ED_FindGlobalOffset(prvm_prog_t *prog, const char *name);
837 func_t PRVM_ED_FindFunctionOffset(prvm_prog_t *prog, const char *name);
838 #define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
839 #define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
840
841 void PRVM_MEM_IncreaseEdicts(prvm_prog_t *prog);
842
843 qbool PRVM_ED_CanAlloc(prvm_prog_t *prog, prvm_edict_t *e);
844 prvm_edict_t *PRVM_ED_Alloc(prvm_prog_t *prog);
845 void PRVM_ED_Free(prvm_prog_t *prog, prvm_edict_t *ed);
846 void PRVM_ED_ClearEdict(prvm_prog_t *prog, prvm_edict_t *e);
847
848 void PRVM_PrintFunctionStatements(prvm_prog_t *prog, const char *name);
849 void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fieldname);
850 void PRVM_ED_Write(prvm_prog_t *prog, struct qfile_s *f, prvm_edict_t *ed);
851 const char *PRVM_ED_ParseEdict(prvm_prog_t *prog, const char *data, prvm_edict_t *ent);
852
853 void PRVM_ED_WriteGlobals(prvm_prog_t *prog, struct qfile_s *f);
854 void PRVM_ED_ParseGlobals(prvm_prog_t *prog, const char *data);
855
856 void PRVM_ED_CallPrespawnFunction(prvm_prog_t *prog, prvm_edict_t *ent);
857 qbool PRVM_ED_CallSpawnFunction(prvm_prog_t *prog, prvm_edict_t *ent, const char *data, const char *start);
858 void PRVM_ED_CallPostspawnFunction (prvm_prog_t *prog, prvm_edict_t *ent);
859
860 void PRVM_ED_LoadFromFile(prvm_prog_t *prog, const char *data);
861
862 unsigned int PRVM_EDICT_NUM_ERROR(prvm_prog_t *prog, unsigned int n, const char *filename, int fileline);
863 #define PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? (unsigned int)(n) : PRVM_EDICT_NUM_ERROR(prog, (unsigned int)(n), __FILE__, __LINE__))
864 #define PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
865
866 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
867 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
868 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
869
870 #define PRVM_NEXT_EDICT(e) ((e) + 1)
871
872 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
873 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
874 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
875 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
876
877 //============================================================================
878
879 #define PRVM_G_FLOAT(o) (prog->globals.fp[o])
880 #define PRVM_G_INT(o) (prog->globals.ip[o])
881 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(prog->globals.ip[o]))
882 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
883 #define PRVM_G_VECTOR(o) (&prog->globals.fp[o])
884 #define PRVM_G_STRING(o) (PRVM_GetString(prog, prog->globals.ip[o]))
885 //#define PRVM_G_FUNCTION(prog, o) (prog->globals.ip[o])
886
887 // FIXME: make these go away?
888 #define PRVM_E_FLOAT(e,o) (e->fields.fp[o])
889 #define PRVM_E_INT(e,o) (e->fields.ip[o])
890 //#define PRVM_E_VECTOR(e,o) (&(e->fields.fp[o]))
891 #define PRVM_E_STRING(e,o) (PRVM_GetString(prog, e->fields.ip[o]))
892
893 extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to
894 // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything
895
896 void PRVM_Init_Exec(prvm_prog_t *prog);
897
898 void PRVM_ED_PrintEdicts_f(struct cmd_state_s *cmd);
899 void PRVM_ED_PrintNum (prvm_prog_t *prog, int ent, const char *wildcard_fieldname);
900
901 const char *PRVM_GetString(prvm_prog_t *prog, int num);
902 int PRVM_SetEngineString(prvm_prog_t *prog, const char *s);
903 const char *PRVM_ChangeEngineString(prvm_prog_t *prog, int i, const char *s);
904 /// Takes an strlen (not a buffer size).
905 int PRVM_SetTempString(prvm_prog_t *prog, const char *s, size_t slen);
906 int PRVM_AllocString(prvm_prog_t *prog, size_t bufferlength, char **pointer);
907 void PRVM_FreeString(prvm_prog_t *prog, int num);
908
909 mdef_t *PRVM_ED_FieldAtOfs(prvm_prog_t *prog, unsigned int ofs);
910 qbool PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, mdef_t *key, const char *s, qbool parsebackslash);
911 char *PRVM_UglyValueString(prvm_prog_t *prog, etype_t type, prvm_eval_t *val, char *line, size_t linelength);
912 char *PRVM_GlobalString(prvm_prog_t *prog, int ofs, char *line, size_t linelength);
913 char *PRVM_GlobalStringNoContents(prvm_prog_t *prog, int ofs, char *line, size_t linelength);
914
915 //============================================================================
916
917 /*
918 Initializing a vm:
919 Call InitProg with the num
920 Set up the fields marked with [INIT] in the prog struct
921 Load a program with LoadProgs
922 */
923 // Load expects to be called right after Reset
924 void PRVM_Prog_Init(prvm_prog_t *prog, struct cmd_state_s *cmd);
925 void PRVM_Prog_Load(prvm_prog_t *prog, const char *filename, unsigned char *data, int64_t size, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global);
926 void PRVM_Prog_Reset(prvm_prog_t *prog);
927
928 void PRVM_StackTrace(prvm_prog_t *prog);
929 void PRVM_Breakpoint(prvm_prog_t *prog, int stack_index, const char *text);
930 void PRVM_Watchpoint(prvm_prog_t *prog, int stack_index, const char *text, etype_t type, prvm_eval_t *o, prvm_eval_t *n);
931
932 void VM_Warning(prvm_prog_t *prog, const char *fmt, ...) DP_FUNC_PRINTF(2);
933
934 void VM_GenerateFrameGroupBlend(prvm_prog_t *prog, struct framegroupblend_s *framegroupblend, const prvm_edict_t *ed);
935 void VM_FrameBlendFromFrameGroupBlend(struct frameblend_s *frameblend, const struct framegroupblend_s *framegroupblend, const struct model_s *model, double curtime);
936 void VM_UpdateEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed, const struct model_s *edmodel, const struct frameblend_s *frameblend);
937 void VM_RemoveEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed);
938
939 void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement);
940
941 #endif