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