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