2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
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.
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.
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
36 #ifndef DP_SMALLMEMORY
40 typedef struct prvm_stack_s
46 double builtinsprofile_acc;
50 typedef union prvm_eval_s
61 typedef struct prvm_required_field_s
65 } prvm_required_field_t;
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
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;
80 typedef struct prvm_edict_s
82 // engine-private fields (stored in dynamically resized array)
83 //edict_engineprivate_t *e;
86 prvm_edict_private_t *required;
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;
97 // vec3_t moved_fromangles;
98 // ... } server_edict_private_t;
100 // typedef struct server_edict_private_s {
103 // vec3_t moved_from;
104 // vec3_t moved_fromangles;
105 // ... } server_edict_private_t;
106 // However, the first one should be preferred.
108 // QuakeC fields (stored in dynamically resized array)
112 // entvars_t *server;
113 // cl_entvars_t *client;
117 extern prvm_eval_t prvm_badvalue;
119 #define PRVM_alledictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
120 #define PRVM_alledictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
121 #define PRVM_alledictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
122 #define PRVM_alledictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
123 #define PRVM_alledictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
124 #define PRVM_allglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
125 #define PRVM_allglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
126 #define PRVM_allglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
127 #define PRVM_allglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
128 #define PRVM_allglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
129 #define PRVM_allfunction(funcname) (prog->funcoffsets.funcname)
131 #define PRVM_drawedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
132 #define PRVM_drawedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
133 #define PRVM_drawedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
134 #define PRVM_drawedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
135 #define PRVM_drawedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
136 #define PRVM_drawglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
137 #define PRVM_drawglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
138 #define PRVM_drawglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
139 #define PRVM_drawglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
140 #define PRVM_drawglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
141 #define PRVM_drawfunction(funcname) (prog->funcoffsets.funcname)
143 #define PRVM_gameedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
144 #define PRVM_gameedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
145 #define PRVM_gameedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
146 #define PRVM_gameedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
147 #define PRVM_gameedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
148 #define PRVM_gameglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
149 #define PRVM_gameglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
150 #define PRVM_gameglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
151 #define PRVM_gameglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
152 #define PRVM_gameglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
153 #define PRVM_gamefunction(funcname) (prog->funcoffsets.funcname)
155 #define PRVM_serveredictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
156 #define PRVM_serveredictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
157 #define PRVM_serveredictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
158 #define PRVM_serveredictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
159 #define PRVM_serveredictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
160 #define PRVM_serverglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
161 #define PRVM_serverglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
162 #define PRVM_serverglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
163 #define PRVM_serverglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
164 #define PRVM_serverglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
165 #define PRVM_serverfunction(funcname) (prog->funcoffsets.funcname)
167 #define PRVM_clientedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
168 #define PRVM_clientedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
169 #define PRVM_clientedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
170 #define PRVM_clientedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
171 #define PRVM_clientedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
172 #define PRVM_clientglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
173 #define PRVM_clientglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
174 #define PRVM_clientglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
175 #define PRVM_clientglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
176 #define PRVM_clientglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
177 #define PRVM_clientfunction(funcname) (prog->funcoffsets.funcname)
179 #define PRVM_menuedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
180 #define PRVM_menuedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
181 #define PRVM_menuedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
182 #define PRVM_menuedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
183 #define PRVM_menuedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
184 #define PRVM_menuglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
185 #define PRVM_menuglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
186 #define PRVM_menuglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
187 #define PRVM_menuglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
188 #define PRVM_menuglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
189 #define PRVM_menufunction(funcname) (prog->funcoffsets.funcname)
192 #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))
193 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->_float)
194 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->vector)
195 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->string)
196 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->edict)
197 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->function)
198 #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))
199 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->_float)
200 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->vector)
201 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->string)
202 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->edict)
203 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->function)
205 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))
206 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->_float)
207 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->vector)
208 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->string)
209 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->edict)
210 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->function)
211 #define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))
212 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->_float)
213 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->vector)
214 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->string)
215 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->edict)
216 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->function)
219 //============================================================================
220 #define PRVM_OP_STATE 1
222 #ifdef DP_SMALLMEMORY
223 #define PRVM_MAX_STACK_DEPTH 128
224 #define PRVM_LOCALSTACK_SIZE 2048
226 #define PRVM_MAX_OPENFILES 16
227 #define PRVM_MAX_OPENSEARCHES 8
229 #define PRVM_MAX_STACK_DEPTH 1024
230 #define PRVM_LOCALSTACK_SIZE 16384
232 #define PRVM_MAX_OPENFILES 256
233 #define PRVM_MAX_OPENSEARCHES 128
236 typedef void (*prvm_builtin_t) (void);
238 // NOTE: field offsets use -1 for NULL
239 typedef struct prvm_prog_fieldoffsets_s
241 #define PRVM_DECLARE_serverglobalfloat(x)
242 #define PRVM_DECLARE_serverglobalvector(x)
243 #define PRVM_DECLARE_serverglobalstring(x)
244 #define PRVM_DECLARE_serverglobaledict(x)
245 #define PRVM_DECLARE_serverglobalfunction(x)
246 #define PRVM_DECLARE_clientglobalfloat(x)
247 #define PRVM_DECLARE_clientglobalvector(x)
248 #define PRVM_DECLARE_clientglobalstring(x)
249 #define PRVM_DECLARE_clientglobaledict(x)
250 #define PRVM_DECLARE_clientglobalfunction(x)
251 #define PRVM_DECLARE_menuglobalfloat(x)
252 #define PRVM_DECLARE_menuglobalvector(x)
253 #define PRVM_DECLARE_menuglobalstring(x)
254 #define PRVM_DECLARE_menuglobaledict(x)
255 #define PRVM_DECLARE_menuglobalfunction(x)
256 #define PRVM_DECLARE_serverfieldfloat(x)
257 #define PRVM_DECLARE_serverfieldvector(x)
258 #define PRVM_DECLARE_serverfieldstring(x)
259 #define PRVM_DECLARE_serverfieldedict(x)
260 #define PRVM_DECLARE_serverfieldfunction(x)
261 #define PRVM_DECLARE_clientfieldfloat(x)
262 #define PRVM_DECLARE_clientfieldvector(x)
263 #define PRVM_DECLARE_clientfieldstring(x)
264 #define PRVM_DECLARE_clientfieldedict(x)
265 #define PRVM_DECLARE_clientfieldfunction(x)
266 #define PRVM_DECLARE_menufieldfloat(x)
267 #define PRVM_DECLARE_menufieldvector(x)
268 #define PRVM_DECLARE_menufieldstring(x)
269 #define PRVM_DECLARE_menufieldedict(x)
270 #define PRVM_DECLARE_menufieldfunction(x)
271 #define PRVM_DECLARE_serverfunction(x)
272 #define PRVM_DECLARE_clientfunction(x)
273 #define PRVM_DECLARE_menufunction(x)
274 #define PRVM_DECLARE_field(x) int x;
275 #define PRVM_DECLARE_global(x)
276 #define PRVM_DECLARE_function(x)
277 #include "prvm_offsets.h"
278 #undef PRVM_DECLARE_serverglobalfloat
279 #undef PRVM_DECLARE_serverglobalvector
280 #undef PRVM_DECLARE_serverglobalstring
281 #undef PRVM_DECLARE_serverglobaledict
282 #undef PRVM_DECLARE_serverglobalfunction
283 #undef PRVM_DECLARE_clientglobalfloat
284 #undef PRVM_DECLARE_clientglobalvector
285 #undef PRVM_DECLARE_clientglobalstring
286 #undef PRVM_DECLARE_clientglobaledict
287 #undef PRVM_DECLARE_clientglobalfunction
288 #undef PRVM_DECLARE_menuglobalfloat
289 #undef PRVM_DECLARE_menuglobalvector
290 #undef PRVM_DECLARE_menuglobalstring
291 #undef PRVM_DECLARE_menuglobaledict
292 #undef PRVM_DECLARE_menuglobalfunction
293 #undef PRVM_DECLARE_serverfieldfloat
294 #undef PRVM_DECLARE_serverfieldvector
295 #undef PRVM_DECLARE_serverfieldstring
296 #undef PRVM_DECLARE_serverfieldedict
297 #undef PRVM_DECLARE_serverfieldfunction
298 #undef PRVM_DECLARE_clientfieldfloat
299 #undef PRVM_DECLARE_clientfieldvector
300 #undef PRVM_DECLARE_clientfieldstring
301 #undef PRVM_DECLARE_clientfieldedict
302 #undef PRVM_DECLARE_clientfieldfunction
303 #undef PRVM_DECLARE_menufieldfloat
304 #undef PRVM_DECLARE_menufieldvector
305 #undef PRVM_DECLARE_menufieldstring
306 #undef PRVM_DECLARE_menufieldedict
307 #undef PRVM_DECLARE_menufieldfunction
308 #undef PRVM_DECLARE_serverfunction
309 #undef PRVM_DECLARE_clientfunction
310 #undef PRVM_DECLARE_menufunction
311 #undef PRVM_DECLARE_field
312 #undef PRVM_DECLARE_global
313 #undef PRVM_DECLARE_function
315 prvm_prog_fieldoffsets_t;
317 // NOTE: global offsets use -1 for NULL
318 typedef struct prvm_prog_globaloffsets_s
320 #define PRVM_DECLARE_serverglobalfloat(x)
321 #define PRVM_DECLARE_serverglobalvector(x)
322 #define PRVM_DECLARE_serverglobalstring(x)
323 #define PRVM_DECLARE_serverglobaledict(x)
324 #define PRVM_DECLARE_serverglobalfunction(x)
325 #define PRVM_DECLARE_clientglobalfloat(x)
326 #define PRVM_DECLARE_clientglobalvector(x)
327 #define PRVM_DECLARE_clientglobalstring(x)
328 #define PRVM_DECLARE_clientglobaledict(x)
329 #define PRVM_DECLARE_clientglobalfunction(x)
330 #define PRVM_DECLARE_menuglobalfloat(x)
331 #define PRVM_DECLARE_menuglobalvector(x)
332 #define PRVM_DECLARE_menuglobalstring(x)
333 #define PRVM_DECLARE_menuglobaledict(x)
334 #define PRVM_DECLARE_menuglobalfunction(x)
335 #define PRVM_DECLARE_serverfieldfloat(x)
336 #define PRVM_DECLARE_serverfieldvector(x)
337 #define PRVM_DECLARE_serverfieldstring(x)
338 #define PRVM_DECLARE_serverfieldedict(x)
339 #define PRVM_DECLARE_serverfieldfunction(x)
340 #define PRVM_DECLARE_clientfieldfloat(x)
341 #define PRVM_DECLARE_clientfieldvector(x)
342 #define PRVM_DECLARE_clientfieldstring(x)
343 #define PRVM_DECLARE_clientfieldedict(x)
344 #define PRVM_DECLARE_clientfieldfunction(x)
345 #define PRVM_DECLARE_menufieldfloat(x)
346 #define PRVM_DECLARE_menufieldvector(x)
347 #define PRVM_DECLARE_menufieldstring(x)
348 #define PRVM_DECLARE_menufieldedict(x)
349 #define PRVM_DECLARE_menufieldfunction(x)
350 #define PRVM_DECLARE_serverfunction(x)
351 #define PRVM_DECLARE_clientfunction(x)
352 #define PRVM_DECLARE_menufunction(x)
353 #define PRVM_DECLARE_field(x)
354 #define PRVM_DECLARE_global(x) int x;
355 #define PRVM_DECLARE_function(x)
356 #include "prvm_offsets.h"
357 #undef PRVM_DECLARE_serverglobalfloat
358 #undef PRVM_DECLARE_serverglobalvector
359 #undef PRVM_DECLARE_serverglobalstring
360 #undef PRVM_DECLARE_serverglobaledict
361 #undef PRVM_DECLARE_serverglobalfunction
362 #undef PRVM_DECLARE_clientglobalfloat
363 #undef PRVM_DECLARE_clientglobalvector
364 #undef PRVM_DECLARE_clientglobalstring
365 #undef PRVM_DECLARE_clientglobaledict
366 #undef PRVM_DECLARE_clientglobalfunction
367 #undef PRVM_DECLARE_menuglobalfloat
368 #undef PRVM_DECLARE_menuglobalvector
369 #undef PRVM_DECLARE_menuglobalstring
370 #undef PRVM_DECLARE_menuglobaledict
371 #undef PRVM_DECLARE_menuglobalfunction
372 #undef PRVM_DECLARE_serverfieldfloat
373 #undef PRVM_DECLARE_serverfieldvector
374 #undef PRVM_DECLARE_serverfieldstring
375 #undef PRVM_DECLARE_serverfieldedict
376 #undef PRVM_DECLARE_serverfieldfunction
377 #undef PRVM_DECLARE_clientfieldfloat
378 #undef PRVM_DECLARE_clientfieldvector
379 #undef PRVM_DECLARE_clientfieldstring
380 #undef PRVM_DECLARE_clientfieldedict
381 #undef PRVM_DECLARE_clientfieldfunction
382 #undef PRVM_DECLARE_menufieldfloat
383 #undef PRVM_DECLARE_menufieldvector
384 #undef PRVM_DECLARE_menufieldstring
385 #undef PRVM_DECLARE_menufieldedict
386 #undef PRVM_DECLARE_menufieldfunction
387 #undef PRVM_DECLARE_serverfunction
388 #undef PRVM_DECLARE_clientfunction
389 #undef PRVM_DECLARE_menufunction
390 #undef PRVM_DECLARE_field
391 #undef PRVM_DECLARE_global
392 #undef PRVM_DECLARE_function
394 prvm_prog_globaloffsets_t;
396 // NOTE: function offsets use 0 for NULL
397 typedef struct prvm_prog_funcoffsets_s
399 #define PRVM_DECLARE_serverglobalfloat(x)
400 #define PRVM_DECLARE_serverglobalvector(x)
401 #define PRVM_DECLARE_serverglobalstring(x)
402 #define PRVM_DECLARE_serverglobaledict(x)
403 #define PRVM_DECLARE_serverglobalfunction(x)
404 #define PRVM_DECLARE_clientglobalfloat(x)
405 #define PRVM_DECLARE_clientglobalvector(x)
406 #define PRVM_DECLARE_clientglobalstring(x)
407 #define PRVM_DECLARE_clientglobaledict(x)
408 #define PRVM_DECLARE_clientglobalfunction(x)
409 #define PRVM_DECLARE_menuglobalfloat(x)
410 #define PRVM_DECLARE_menuglobalvector(x)
411 #define PRVM_DECLARE_menuglobalstring(x)
412 #define PRVM_DECLARE_menuglobaledict(x)
413 #define PRVM_DECLARE_menuglobalfunction(x)
414 #define PRVM_DECLARE_serverfieldfloat(x)
415 #define PRVM_DECLARE_serverfieldvector(x)
416 #define PRVM_DECLARE_serverfieldstring(x)
417 #define PRVM_DECLARE_serverfieldedict(x)
418 #define PRVM_DECLARE_serverfieldfunction(x)
419 #define PRVM_DECLARE_clientfieldfloat(x)
420 #define PRVM_DECLARE_clientfieldvector(x)
421 #define PRVM_DECLARE_clientfieldstring(x)
422 #define PRVM_DECLARE_clientfieldedict(x)
423 #define PRVM_DECLARE_clientfieldfunction(x)
424 #define PRVM_DECLARE_menufieldfloat(x)
425 #define PRVM_DECLARE_menufieldvector(x)
426 #define PRVM_DECLARE_menufieldstring(x)
427 #define PRVM_DECLARE_menufieldedict(x)
428 #define PRVM_DECLARE_menufieldfunction(x)
429 #define PRVM_DECLARE_serverfunction(x)
430 #define PRVM_DECLARE_clientfunction(x)
431 #define PRVM_DECLARE_menufunction(x)
432 #define PRVM_DECLARE_field(x)
433 #define PRVM_DECLARE_global(x)
434 #define PRVM_DECLARE_function(x) int x;
435 #include "prvm_offsets.h"
436 #undef PRVM_DECLARE_serverglobalfloat
437 #undef PRVM_DECLARE_serverglobalvector
438 #undef PRVM_DECLARE_serverglobalstring
439 #undef PRVM_DECLARE_serverglobaledict
440 #undef PRVM_DECLARE_serverglobalfunction
441 #undef PRVM_DECLARE_clientglobalfloat
442 #undef PRVM_DECLARE_clientglobalvector
443 #undef PRVM_DECLARE_clientglobalstring
444 #undef PRVM_DECLARE_clientglobaledict
445 #undef PRVM_DECLARE_clientglobalfunction
446 #undef PRVM_DECLARE_menuglobalfloat
447 #undef PRVM_DECLARE_menuglobalvector
448 #undef PRVM_DECLARE_menuglobalstring
449 #undef PRVM_DECLARE_menuglobaledict
450 #undef PRVM_DECLARE_menuglobalfunction
451 #undef PRVM_DECLARE_serverfieldfloat
452 #undef PRVM_DECLARE_serverfieldvector
453 #undef PRVM_DECLARE_serverfieldstring
454 #undef PRVM_DECLARE_serverfieldedict
455 #undef PRVM_DECLARE_serverfieldfunction
456 #undef PRVM_DECLARE_clientfieldfloat
457 #undef PRVM_DECLARE_clientfieldvector
458 #undef PRVM_DECLARE_clientfieldstring
459 #undef PRVM_DECLARE_clientfieldedict
460 #undef PRVM_DECLARE_clientfieldfunction
461 #undef PRVM_DECLARE_menufieldfloat
462 #undef PRVM_DECLARE_menufieldvector
463 #undef PRVM_DECLARE_menufieldstring
464 #undef PRVM_DECLARE_menufieldedict
465 #undef PRVM_DECLARE_menufieldfunction
466 #undef PRVM_DECLARE_serverfunction
467 #undef PRVM_DECLARE_clientfunction
468 #undef PRVM_DECLARE_menufunction
469 #undef PRVM_DECLARE_field
470 #undef PRVM_DECLARE_global
471 #undef PRVM_DECLARE_function
473 prvm_prog_funcoffsets_t;
475 // stringbuffer flags
476 #define STRINGBUFFER_SAVED 1 // saved in savegames
478 typedef struct prvm_stringbuffer_s
488 // [INIT] variables flagged with this token can be initialized by 'you'
489 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
490 typedef struct prvm_prog_s
493 unsigned int id; // increasing unique id of progs instance
494 mfunction_t *functions;
499 mstatement_t *statements;
500 int entityfields; // number of vec_t fields in progs (some variables are 3)
501 int entityfieldsarea; // LordHavoc: equal to max_edicts * entityfields (for bounds checking)
503 // loaded values from the disk format
506 int progs_numstatements;
507 int progs_numglobaldefs;
508 int progs_numfielddefs;
509 int progs_numfunctions;
510 int progs_numstrings;
511 int progs_numglobals;
512 int progs_entityfields;
514 // real values in memory (some modified by loader)
522 int *statement_linenums; // NULL if not available
524 double *statement_profile; // only incremented if prvm_statementprofiling is on
528 // globalvars_t *server;
529 // cl_globalvars_t *client;
534 // this is updated whenever a string is removed or added
535 // (simple optimization of the free string search)
536 int firstfreeknownstring;
537 const char **knownstrings;
538 unsigned char *knownstrings_freeable;
539 const char **knownstrings_origin;
540 const char ***stringshash;
542 memexpandablearray_t stringbuffersarray;
544 // all memory allocations related to this vm_prog (code, edicts, strings)
545 mempool_t *progs_mempool; // [INIT]
547 prvm_builtin_t *builtins; // [INIT]
548 int numbuiltins; // [INIT]
553 mfunction_t *xfunction;
556 // stacktrace writes into stack[MAX_STACK_DEPTH]
557 // thus increase the array, so depth wont be overwritten
558 prvm_stack_t stack[PRVM_MAX_STACK_DEPTH+1];
561 int localstack[PRVM_LOCALSTACK_SIZE];
564 unsigned short filecrc;
566 //============================================================================
567 // until this point everything also exists (with the pr_ prefix) in the old vm
569 qfile_t *openfiles[PRVM_MAX_OPENFILES];
570 const char * openfiles_origin[PRVM_MAX_OPENFILES];
571 fssearch_t *opensearches[PRVM_MAX_OPENSEARCHES];
572 const char * opensearches_origin[PRVM_MAX_OPENSEARCHES];
573 skeleton_t *skeletons[MAX_EDICTS];
575 // copies of some vars that were former read from sv
577 // number of edicts for which space has been (should be) allocated
578 int max_edicts; // [INIT]
579 // used instead of the constant MAX_EDICTS
580 int limit_edicts; // [INIT]
582 // number of reserved edicts (allocated from 1)
583 int reserved_edicts; // [INIT]
585 prvm_edict_t *edicts;
589 // size of the engine private struct
590 int edictprivate_size; // [INIT]
592 prvm_prog_fieldoffsets_t fieldoffsets;
593 prvm_prog_globaloffsets_t globaloffsets;
594 prvm_prog_funcoffsets_t funcoffsets;
596 // allow writing to world entity fields, this is set by server init and
597 // cleared before first server frame
598 qboolean allowworldwrites;
600 // name of the prog, e.g. "Server", "Client" or "Menu" (used for text output)
601 const char *name; // [INIT]
603 // flag - used to store general flags like PRVM_GE_SELF, etc.
606 const char *extensionstring; // [INIT]
608 qboolean loadintoworld; // [INIT]
610 // used to indicate whether a prog is loaded
612 qboolean leaktest_active;
614 // translation buffer (only needs to be freed on unloading progs, type is private to prvm_edict.c)
617 // printed together with backtraces
618 const char *statestring;
620 // prvm_builtin_mem_t *mem_list;
622 // now passed as parameter of PRVM_LoadProgs
623 // char **required_func;
624 // int numrequiredfunc;
626 //============================================================================
628 ddef_t *self; // if self != 0 then there is a global self
630 //============================================================================
633 void (*begin_increase_edicts)(void); // [INIT] used by PRVM_MEM_Increase_Edicts
634 void (*end_increase_edicts)(void); // [INIT]
636 void (*init_edict)(prvm_edict_t *edict); // [INIT] used by PRVM_ED_ClearEdict
637 void (*free_edict)(prvm_edict_t *ed); // [INIT] used by PRVM_ED_Free
639 void (*count_edicts)(void); // [INIT] used by PRVM_ED_Count_f
641 qboolean (*load_edict)(prvm_edict_t *ent); // [INIT] used by PRVM_ED_LoadFromFile
643 void (*init_cmd)(void); // [INIT] used by PRVM_InitProg
644 void (*reset_cmd)(void); // [INIT] used by PRVM_ResetProg
646 void (*error_cmd)(const char *format, ...) DP_FUNC_PRINTF(1); // [INIT]
648 void (*ExecuteProgram)(func_t fnum, const char *errormessage); // pointer to one of the *VM_ExecuteProgram functions
651 extern prvm_prog_t * prog;
653 #define PRVM_MAXPROGS 3
654 #define PRVM_SERVERPROG 0 // actually not used at the moment
655 #define PRVM_CLIENTPROG 1
656 #define PRVM_MENUPROG 2
658 extern prvm_prog_t prvm_prog_list[PRVM_MAXPROGS];
660 //============================================================================
663 extern prvm_builtin_t vm_sv_builtins[];
664 extern prvm_builtin_t vm_cl_builtins[];
665 extern prvm_builtin_t vm_m_builtins[];
667 extern const int vm_sv_numbuiltins;
668 extern const int vm_cl_numbuiltins;
669 extern const int vm_m_numbuiltins;
671 extern const char * vm_sv_extensions; // client also uses this
672 extern const char * vm_m_extensions;
674 void VM_SV_Cmd_Init(void);
675 void VM_SV_Cmd_Reset(void);
677 void VM_CL_Cmd_Init(void);
678 void VM_CL_Cmd_Reset(void);
680 void VM_M_Cmd_Init(void);
681 void VM_M_Cmd_Reset(void);
683 void VM_Cmd_Init(void);
684 void VM_Cmd_Reset(void);
685 //============================================================================
687 void PRVM_Init (void);
690 void MVM_ExecuteProgram (func_t fnum, const char *errormessage);
691 void CLVM_ExecuteProgram (func_t fnum, const char *errormessage);
692 void SVVM_ExecuteProgram (func_t fnum, const char *errormessage);
694 #define MVM_ExecuteProgram SVVM_ExecuteProgram
695 #define CLVM_ExecuteProgram SVVM_ExecuteProgram
696 void SVVM_ExecuteProgram (func_t fnum, const char *errormessage);
698 #define PRVM_ExecuteProgram prog->ExecuteProgram
700 #define PRVM_Alloc(buffersize) _PRVM_Alloc(buffersize, __FILE__, __LINE__)
701 #define PRVM_Free(buffer) _PRVM_Free(buffer, __FILE__, __LINE__)
702 #define PRVM_FreeAll() _PRVM_FreeAll(__FILE__, __LINE__)
703 void *_PRVM_Alloc (size_t buffersize, const char *filename, int fileline);
704 void _PRVM_Free (void *buffer, const char *filename, int fileline);
705 void _PRVM_FreeAll (const char *filename, int fileline);
707 void PRVM_Profile (int maxfunctions, double mintime, int sortby);
708 void PRVM_Profile_f (void);
709 void PRVM_ChildProfile_f (void);
710 void PRVM_CallProfile_f (void);
711 void PRVM_PrintFunction_f (void);
713 void PRVM_PrintState(void);
714 void PRVM_CrashAll (void);
715 void PRVM_Crash (void);
716 void PRVM_ShortStackTrace(char *buf, size_t bufsize);
717 const char *PRVM_AllocationOrigin(void);
719 ddef_t *PRVM_ED_FindField(const char *name);
720 ddef_t *PRVM_ED_FindGlobal(const char *name);
721 mfunction_t *PRVM_ED_FindFunction(const char *name);
723 int PRVM_ED_FindFieldOffset(const char *name);
724 int PRVM_ED_FindGlobalOffset(const char *name);
725 func_t PRVM_ED_FindFunctionOffset(const char *name);
726 #define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
727 #define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
729 void PRVM_MEM_IncreaseEdicts(void);
731 qboolean PRVM_ED_CanAlloc(prvm_edict_t *e);
732 prvm_edict_t *PRVM_ED_Alloc (void);
733 void PRVM_ED_Free (prvm_edict_t *ed);
734 void PRVM_ED_ClearEdict (prvm_edict_t *e);
736 void PRVM_PrintFunctionStatements (const char *name);
737 void PRVM_ED_Print(prvm_edict_t *ed, const char *wildcard_fieldname);
738 void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed);
739 const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent);
741 void PRVM_ED_WriteGlobals (qfile_t *f);
742 void PRVM_ED_ParseGlobals (const char *data);
744 void PRVM_ED_LoadFromFile (const char *data);
746 unsigned int PRVM_EDICT_NUM_ERROR(unsigned int n, const char *filename, int fileline);
747 #define PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? (unsigned int)(n) : PRVM_EDICT_NUM_ERROR((unsigned int)(n), __FILE__, __LINE__))
748 #define PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
750 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
751 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
752 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
754 #define PRVM_NEXT_EDICT(e) ((e) + 1)
756 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
757 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
758 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
759 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
761 //============================================================================
763 #define PRVM_G_FLOAT(o) (prog->globals.generic[o])
764 #define PRVM_G_INT(o) (*(int *)&prog->globals.generic[o])
765 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&prog->globals.generic[o]))
766 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
767 #define PRVM_G_VECTOR(o) (&prog->globals.generic[o])
768 #define PRVM_G_STRING(o) (PRVM_GetString(*(string_t *)&prog->globals.generic[o]))
769 //#define PRVM_G_FUNCTION(o) (*(func_t *)&prog->globals.generic[o])
771 // FIXME: make these go away?
772 #define PRVM_E_FLOAT(e,o) (((float*)e->fields.vp)[o])
773 #define PRVM_E_INT(e,o) (((int*)e->fields.vp)[o])
774 //#define PRVM_E_VECTOR(e,o) (&((float*)e->fields.vp)[o])
775 #define PRVM_E_STRING(e,o) (PRVM_GetString(*(string_t *)&((float*)e->fields.vp)[o]))
777 extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to
778 // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything
780 void PRVM_Init_Exec(void);
782 void PRVM_ED_PrintEdicts_f (void);
783 void PRVM_ED_PrintNum (int ent, const char *wildcard_fieldname);
785 const char *PRVM_GetString(int num);
786 int PRVM_SetEngineString(const char *s);
787 const char *PRVM_ChangeEngineString(int i, const char *s);
788 int PRVM_SetTempString(const char *s);
789 int PRVM_AllocString(size_t bufferlength, char **pointer);
790 void PRVM_FreeString(int num);
792 //============================================================================
794 // used as replacement for a prog stack
795 //#define PRVM_DEBUGPRSTACK
797 #ifdef PRVM_DEBUGPRSTACK
798 #define PRVM_Begin if(prog != 0) Con_Printf("prog not 0(prog = %i) in file: %s line: %i!\n", PRVM_GetProgNr(), __FILE__, __LINE__)
799 #define PRVM_End prog = 0
802 #define PRVM_End prog = 0
805 //#define PRVM_SAFENAME
806 #ifndef PRVM_SAFENAME
807 # define PRVM_NAME (prog->name)
809 # define PRVM_NAME (prog->name ? prog->name : "Unknown prog name")
812 // helper macro to make function pointer calls easier
813 #define PRVM_GCALL(func) if(prog->func) prog->func
815 #define PRVM_ERROR prog->error_cmd
817 // other prog handling functions
818 qboolean PRVM_SetProgFromString(const char *str);
819 void PRVM_SetProg(int prognr);
823 Call InitProg with the num
824 Set up the fields marked with [INIT] in the prog struct
825 Load a program with LoadProgs
827 void PRVM_InitProg(int prognr);
828 // LoadProgs expects to be called right after InitProg
829 void PRVM_LoadProgs (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);
830 void PRVM_ResetProg(void);
832 qboolean PRVM_ProgLoaded(int prognr);
834 int PRVM_GetProgNr(void);
836 void VM_Warning(const char *fmt, ...) DP_FUNC_PRINTF(1);
838 // TODO: fill in the params
839 //void PRVM_Create();
841 void VM_GenerateFrameGroupBlend(framegroupblend_t *framegroupblend, const prvm_edict_t *ed);
842 void VM_FrameBlendFromFrameGroupBlend(frameblend_t *frameblend, const framegroupblend_t *framegroupblend, const dp_model_t *model);
843 void VM_UpdateEdictSkeleton(prvm_edict_t *ed, const dp_model_t *edmodel, const frameblend_t *frameblend);
844 void VM_RemoveEdictSkeleton(prvm_edict_t *ed);