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
56 prvm_int_t ivector[3];
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
73 float freetime; // realtime of last change to "free" (i.e. also set on allocation)
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;
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;
98 // vec3_t moved_fromangles;
99 // ... } server_edict_private_t;
101 // typedef struct server_edict_private_s {
104 // vec3_t moved_from;
105 // vec3_t moved_fromangles;
106 // ... } server_edict_private_t;
107 // However, the first one should be preferred.
109 // QuakeC fields (stored in dynamically resized array)
114 // entvars_t *server;
115 // cl_entvars_t *client;
119 extern prvm_eval_t prvm_badvalue;
121 #define PRVM_alledictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
122 #define PRVM_alledictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
123 #define PRVM_alledictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
124 #define PRVM_alledictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
125 #define PRVM_alledictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
126 #define PRVM_allglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
127 #define PRVM_allglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
128 #define PRVM_allglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
129 #define PRVM_allglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
130 #define PRVM_allglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
131 #define PRVM_allfunction(funcname) (prog->funcoffsets.funcname)
133 #define PRVM_drawedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
134 #define PRVM_drawedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
135 #define PRVM_drawedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
136 #define PRVM_drawedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
137 #define PRVM_drawedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
138 #define PRVM_drawglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
139 #define PRVM_drawglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
140 #define PRVM_drawglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
141 #define PRVM_drawglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
142 #define PRVM_drawglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
143 #define PRVM_drawfunction(funcname) (prog->funcoffsets.funcname)
145 #define PRVM_gameedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
146 #define PRVM_gameedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
147 #define PRVM_gameedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
148 #define PRVM_gameedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
149 #define PRVM_gameedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
150 #define PRVM_gameglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
151 #define PRVM_gameglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
152 #define PRVM_gameglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
153 #define PRVM_gameglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
154 #define PRVM_gameglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
155 #define PRVM_gamefunction(funcname) (prog->funcoffsets.funcname)
157 #define PRVM_serveredictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
158 #define PRVM_serveredictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
159 #define PRVM_serveredictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
160 #define PRVM_serveredictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
161 #define PRVM_serveredictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
162 #define PRVM_serverglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
163 #define PRVM_serverglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
164 #define PRVM_serverglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
165 #define PRVM_serverglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
166 #define PRVM_serverglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
167 #define PRVM_serverfunction(funcname) (prog->funcoffsets.funcname)
169 #define PRVM_clientedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
170 #define PRVM_clientedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
171 #define PRVM_clientedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
172 #define PRVM_clientedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
173 #define PRVM_clientedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
174 #define PRVM_clientglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
175 #define PRVM_clientglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
176 #define PRVM_clientglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
177 #define PRVM_clientglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
178 #define PRVM_clientglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
179 #define PRVM_clientfunction(funcname) (prog->funcoffsets.funcname)
181 #define PRVM_menuedictfloat(ed, fieldname) (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
182 #define PRVM_menuedictvector(ed, fieldname) (PRVM_EDICTFIELDVECTOR(ed, prog->fieldoffsets.fieldname))
183 #define PRVM_menuedictstring(ed, fieldname) (PRVM_EDICTFIELDSTRING(ed, prog->fieldoffsets.fieldname))
184 #define PRVM_menuedictedict(ed, fieldname) (PRVM_EDICTFIELDEDICT(ed, prog->fieldoffsets.fieldname))
185 #define PRVM_menuedictfunction(ed, fieldname) (PRVM_EDICTFIELDFUNCTION(ed, prog->fieldoffsets.fieldname))
186 #define PRVM_menuglobalfloat(fieldname) (PRVM_GLOBALFIELDFLOAT(prog->globaloffsets.fieldname))
187 #define PRVM_menuglobalvector(fieldname) (PRVM_GLOBALFIELDVECTOR(prog->globaloffsets.fieldname))
188 #define PRVM_menuglobalstring(fieldname) (PRVM_GLOBALFIELDSTRING(prog->globaloffsets.fieldname))
189 #define PRVM_menuglobaledict(fieldname) (PRVM_GLOBALFIELDEDICT(prog->globaloffsets.fieldname))
190 #define PRVM_menuglobalfunction(fieldname) (PRVM_GLOBALFIELDFUNCTION(prog->globaloffsets.fieldname))
191 #define PRVM_menufunction(funcname) (prog->funcoffsets.funcname)
194 #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)))
195 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->_float)
196 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->vector)
197 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->string)
198 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->edict)
199 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->function)
200 #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)))
201 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->_float)
202 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->vector)
203 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->string)
204 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->edict)
205 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->function)
207 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)(ed->fields.fp + fieldoffset))
208 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->_float)
209 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->vector)
210 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->string)
211 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->edict)
212 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->function)
213 #define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)(prog->globals.fp + fieldoffset))
214 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->_float)
215 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->vector)
216 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->string)
217 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->edict)
218 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->function)
221 //============================================================================
222 #define PRVM_OP_STATE 1
224 #ifdef DP_SMALLMEMORY
225 #define PRVM_MAX_STACK_DEPTH 128
226 #define PRVM_LOCALSTACK_SIZE 2048
228 #define PRVM_MAX_OPENFILES 16
229 #define PRVM_MAX_OPENSEARCHES 8
231 #define PRVM_MAX_STACK_DEPTH 1024
232 #define PRVM_LOCALSTACK_SIZE 16384
234 #define PRVM_MAX_OPENFILES 256
235 #define PRVM_MAX_OPENSEARCHES 128
239 typedef void (*prvm_builtin_t) (struct prvm_prog_s *prog);
241 // NOTE: field offsets use -1 for NULL
242 typedef struct prvm_prog_fieldoffsets_s
244 #define PRVM_DECLARE_serverglobalfloat(x)
245 #define PRVM_DECLARE_serverglobalvector(x)
246 #define PRVM_DECLARE_serverglobalstring(x)
247 #define PRVM_DECLARE_serverglobaledict(x)
248 #define PRVM_DECLARE_serverglobalfunction(x)
249 #define PRVM_DECLARE_clientglobalfloat(x)
250 #define PRVM_DECLARE_clientglobalvector(x)
251 #define PRVM_DECLARE_clientglobalstring(x)
252 #define PRVM_DECLARE_clientglobaledict(x)
253 #define PRVM_DECLARE_clientglobalfunction(x)
254 #define PRVM_DECLARE_menuglobalfloat(x)
255 #define PRVM_DECLARE_menuglobalvector(x)
256 #define PRVM_DECLARE_menuglobalstring(x)
257 #define PRVM_DECLARE_menuglobaledict(x)
258 #define PRVM_DECLARE_menuglobalfunction(x)
259 #define PRVM_DECLARE_serverfieldfloat(x)
260 #define PRVM_DECLARE_serverfieldvector(x)
261 #define PRVM_DECLARE_serverfieldstring(x)
262 #define PRVM_DECLARE_serverfieldedict(x)
263 #define PRVM_DECLARE_serverfieldfunction(x)
264 #define PRVM_DECLARE_clientfieldfloat(x)
265 #define PRVM_DECLARE_clientfieldvector(x)
266 #define PRVM_DECLARE_clientfieldstring(x)
267 #define PRVM_DECLARE_clientfieldedict(x)
268 #define PRVM_DECLARE_clientfieldfunction(x)
269 #define PRVM_DECLARE_menufieldfloat(x)
270 #define PRVM_DECLARE_menufieldvector(x)
271 #define PRVM_DECLARE_menufieldstring(x)
272 #define PRVM_DECLARE_menufieldedict(x)
273 #define PRVM_DECLARE_menufieldfunction(x)
274 #define PRVM_DECLARE_serverfunction(x)
275 #define PRVM_DECLARE_clientfunction(x)
276 #define PRVM_DECLARE_menufunction(x)
277 #define PRVM_DECLARE_field(x) int x;
278 #define PRVM_DECLARE_global(x)
279 #define PRVM_DECLARE_function(x)
280 #include "prvm_offsets.h"
281 #undef PRVM_DECLARE_serverglobalfloat
282 #undef PRVM_DECLARE_serverglobalvector
283 #undef PRVM_DECLARE_serverglobalstring
284 #undef PRVM_DECLARE_serverglobaledict
285 #undef PRVM_DECLARE_serverglobalfunction
286 #undef PRVM_DECLARE_clientglobalfloat
287 #undef PRVM_DECLARE_clientglobalvector
288 #undef PRVM_DECLARE_clientglobalstring
289 #undef PRVM_DECLARE_clientglobaledict
290 #undef PRVM_DECLARE_clientglobalfunction
291 #undef PRVM_DECLARE_menuglobalfloat
292 #undef PRVM_DECLARE_menuglobalvector
293 #undef PRVM_DECLARE_menuglobalstring
294 #undef PRVM_DECLARE_menuglobaledict
295 #undef PRVM_DECLARE_menuglobalfunction
296 #undef PRVM_DECLARE_serverfieldfloat
297 #undef PRVM_DECLARE_serverfieldvector
298 #undef PRVM_DECLARE_serverfieldstring
299 #undef PRVM_DECLARE_serverfieldedict
300 #undef PRVM_DECLARE_serverfieldfunction
301 #undef PRVM_DECLARE_clientfieldfloat
302 #undef PRVM_DECLARE_clientfieldvector
303 #undef PRVM_DECLARE_clientfieldstring
304 #undef PRVM_DECLARE_clientfieldedict
305 #undef PRVM_DECLARE_clientfieldfunction
306 #undef PRVM_DECLARE_menufieldfloat
307 #undef PRVM_DECLARE_menufieldvector
308 #undef PRVM_DECLARE_menufieldstring
309 #undef PRVM_DECLARE_menufieldedict
310 #undef PRVM_DECLARE_menufieldfunction
311 #undef PRVM_DECLARE_serverfunction
312 #undef PRVM_DECLARE_clientfunction
313 #undef PRVM_DECLARE_menufunction
314 #undef PRVM_DECLARE_field
315 #undef PRVM_DECLARE_global
316 #undef PRVM_DECLARE_function
318 prvm_prog_fieldoffsets_t;
320 // NOTE: global offsets use -1 for NULL
321 typedef struct prvm_prog_globaloffsets_s
323 #define PRVM_DECLARE_serverglobalfloat(x)
324 #define PRVM_DECLARE_serverglobalvector(x)
325 #define PRVM_DECLARE_serverglobalstring(x)
326 #define PRVM_DECLARE_serverglobaledict(x)
327 #define PRVM_DECLARE_serverglobalfunction(x)
328 #define PRVM_DECLARE_clientglobalfloat(x)
329 #define PRVM_DECLARE_clientglobalvector(x)
330 #define PRVM_DECLARE_clientglobalstring(x)
331 #define PRVM_DECLARE_clientglobaledict(x)
332 #define PRVM_DECLARE_clientglobalfunction(x)
333 #define PRVM_DECLARE_menuglobalfloat(x)
334 #define PRVM_DECLARE_menuglobalvector(x)
335 #define PRVM_DECLARE_menuglobalstring(x)
336 #define PRVM_DECLARE_menuglobaledict(x)
337 #define PRVM_DECLARE_menuglobalfunction(x)
338 #define PRVM_DECLARE_serverfieldfloat(x)
339 #define PRVM_DECLARE_serverfieldvector(x)
340 #define PRVM_DECLARE_serverfieldstring(x)
341 #define PRVM_DECLARE_serverfieldedict(x)
342 #define PRVM_DECLARE_serverfieldfunction(x)
343 #define PRVM_DECLARE_clientfieldfloat(x)
344 #define PRVM_DECLARE_clientfieldvector(x)
345 #define PRVM_DECLARE_clientfieldstring(x)
346 #define PRVM_DECLARE_clientfieldedict(x)
347 #define PRVM_DECLARE_clientfieldfunction(x)
348 #define PRVM_DECLARE_menufieldfloat(x)
349 #define PRVM_DECLARE_menufieldvector(x)
350 #define PRVM_DECLARE_menufieldstring(x)
351 #define PRVM_DECLARE_menufieldedict(x)
352 #define PRVM_DECLARE_menufieldfunction(x)
353 #define PRVM_DECLARE_serverfunction(x)
354 #define PRVM_DECLARE_clientfunction(x)
355 #define PRVM_DECLARE_menufunction(x)
356 #define PRVM_DECLARE_field(x)
357 #define PRVM_DECLARE_global(x) int x;
358 #define PRVM_DECLARE_function(x)
359 #include "prvm_offsets.h"
360 #undef PRVM_DECLARE_serverglobalfloat
361 #undef PRVM_DECLARE_serverglobalvector
362 #undef PRVM_DECLARE_serverglobalstring
363 #undef PRVM_DECLARE_serverglobaledict
364 #undef PRVM_DECLARE_serverglobalfunction
365 #undef PRVM_DECLARE_clientglobalfloat
366 #undef PRVM_DECLARE_clientglobalvector
367 #undef PRVM_DECLARE_clientglobalstring
368 #undef PRVM_DECLARE_clientglobaledict
369 #undef PRVM_DECLARE_clientglobalfunction
370 #undef PRVM_DECLARE_menuglobalfloat
371 #undef PRVM_DECLARE_menuglobalvector
372 #undef PRVM_DECLARE_menuglobalstring
373 #undef PRVM_DECLARE_menuglobaledict
374 #undef PRVM_DECLARE_menuglobalfunction
375 #undef PRVM_DECLARE_serverfieldfloat
376 #undef PRVM_DECLARE_serverfieldvector
377 #undef PRVM_DECLARE_serverfieldstring
378 #undef PRVM_DECLARE_serverfieldedict
379 #undef PRVM_DECLARE_serverfieldfunction
380 #undef PRVM_DECLARE_clientfieldfloat
381 #undef PRVM_DECLARE_clientfieldvector
382 #undef PRVM_DECLARE_clientfieldstring
383 #undef PRVM_DECLARE_clientfieldedict
384 #undef PRVM_DECLARE_clientfieldfunction
385 #undef PRVM_DECLARE_menufieldfloat
386 #undef PRVM_DECLARE_menufieldvector
387 #undef PRVM_DECLARE_menufieldstring
388 #undef PRVM_DECLARE_menufieldedict
389 #undef PRVM_DECLARE_menufieldfunction
390 #undef PRVM_DECLARE_serverfunction
391 #undef PRVM_DECLARE_clientfunction
392 #undef PRVM_DECLARE_menufunction
393 #undef PRVM_DECLARE_field
394 #undef PRVM_DECLARE_global
395 #undef PRVM_DECLARE_function
397 prvm_prog_globaloffsets_t;
399 // NOTE: function offsets use 0 for NULL
400 typedef struct prvm_prog_funcoffsets_s
402 #define PRVM_DECLARE_serverglobalfloat(x)
403 #define PRVM_DECLARE_serverglobalvector(x)
404 #define PRVM_DECLARE_serverglobalstring(x)
405 #define PRVM_DECLARE_serverglobaledict(x)
406 #define PRVM_DECLARE_serverglobalfunction(x)
407 #define PRVM_DECLARE_clientglobalfloat(x)
408 #define PRVM_DECLARE_clientglobalvector(x)
409 #define PRVM_DECLARE_clientglobalstring(x)
410 #define PRVM_DECLARE_clientglobaledict(x)
411 #define PRVM_DECLARE_clientglobalfunction(x)
412 #define PRVM_DECLARE_menuglobalfloat(x)
413 #define PRVM_DECLARE_menuglobalvector(x)
414 #define PRVM_DECLARE_menuglobalstring(x)
415 #define PRVM_DECLARE_menuglobaledict(x)
416 #define PRVM_DECLARE_menuglobalfunction(x)
417 #define PRVM_DECLARE_serverfieldfloat(x)
418 #define PRVM_DECLARE_serverfieldvector(x)
419 #define PRVM_DECLARE_serverfieldstring(x)
420 #define PRVM_DECLARE_serverfieldedict(x)
421 #define PRVM_DECLARE_serverfieldfunction(x)
422 #define PRVM_DECLARE_clientfieldfloat(x)
423 #define PRVM_DECLARE_clientfieldvector(x)
424 #define PRVM_DECLARE_clientfieldstring(x)
425 #define PRVM_DECLARE_clientfieldedict(x)
426 #define PRVM_DECLARE_clientfieldfunction(x)
427 #define PRVM_DECLARE_menufieldfloat(x)
428 #define PRVM_DECLARE_menufieldvector(x)
429 #define PRVM_DECLARE_menufieldstring(x)
430 #define PRVM_DECLARE_menufieldedict(x)
431 #define PRVM_DECLARE_menufieldfunction(x)
432 #define PRVM_DECLARE_serverfunction(x)
433 #define PRVM_DECLARE_clientfunction(x)
434 #define PRVM_DECLARE_menufunction(x)
435 #define PRVM_DECLARE_field(x)
436 #define PRVM_DECLARE_global(x)
437 #define PRVM_DECLARE_function(x) int x;
438 #include "prvm_offsets.h"
439 #undef PRVM_DECLARE_serverglobalfloat
440 #undef PRVM_DECLARE_serverglobalvector
441 #undef PRVM_DECLARE_serverglobalstring
442 #undef PRVM_DECLARE_serverglobaledict
443 #undef PRVM_DECLARE_serverglobalfunction
444 #undef PRVM_DECLARE_clientglobalfloat
445 #undef PRVM_DECLARE_clientglobalvector
446 #undef PRVM_DECLARE_clientglobalstring
447 #undef PRVM_DECLARE_clientglobaledict
448 #undef PRVM_DECLARE_clientglobalfunction
449 #undef PRVM_DECLARE_menuglobalfloat
450 #undef PRVM_DECLARE_menuglobalvector
451 #undef PRVM_DECLARE_menuglobalstring
452 #undef PRVM_DECLARE_menuglobaledict
453 #undef PRVM_DECLARE_menuglobalfunction
454 #undef PRVM_DECLARE_serverfieldfloat
455 #undef PRVM_DECLARE_serverfieldvector
456 #undef PRVM_DECLARE_serverfieldstring
457 #undef PRVM_DECLARE_serverfieldedict
458 #undef PRVM_DECLARE_serverfieldfunction
459 #undef PRVM_DECLARE_clientfieldfloat
460 #undef PRVM_DECLARE_clientfieldvector
461 #undef PRVM_DECLARE_clientfieldstring
462 #undef PRVM_DECLARE_clientfieldedict
463 #undef PRVM_DECLARE_clientfieldfunction
464 #undef PRVM_DECLARE_menufieldfloat
465 #undef PRVM_DECLARE_menufieldvector
466 #undef PRVM_DECLARE_menufieldstring
467 #undef PRVM_DECLARE_menufieldedict
468 #undef PRVM_DECLARE_menufieldfunction
469 #undef PRVM_DECLARE_serverfunction
470 #undef PRVM_DECLARE_clientfunction
471 #undef PRVM_DECLARE_menufunction
472 #undef PRVM_DECLARE_field
473 #undef PRVM_DECLARE_global
474 #undef PRVM_DECLARE_function
476 prvm_prog_funcoffsets_t;
478 // stringbuffer flags
479 #define STRINGBUFFER_SAVED 1 // saved in savegames
480 #define STRINGBUFFER_QCFLAGS 1 // allowed to be set by QC
481 #define STRINGBUFFER_TEMP 128 // internal use ONLY
482 typedef struct prvm_stringbuffer_s
492 // flags for knownstrings
493 #define KNOWNSTRINGFLAG_ENGINE 1
494 #define KNOWNSTRINGFLAG_GCMARK 2
495 #define KNOWNSTRINGFLAG_GCPRUNE 4 // cleared by GCMARK code, string is freed if prune remains after two sweeps
497 typedef enum prvm_prog_garbagecollection_state_stage_e
500 PRVM_GC_GLOBALS_MARK,
502 PRVM_GC_KNOWNSTRINGS_SWEEP,
505 prvm_prog_garbagecollection_state_stage_t;
507 typedef struct prvm_prog_garbagecollection_state_s
509 prvm_prog_garbagecollection_state_stage_t stage;
510 int globals_mark_progress;
511 int fields_mark_progress;
512 int fields_mark_progress_entity;
513 int knownstrings_sweep_progress;
515 prvm_prog_garbagecollection_state_t;
517 // [INIT] variables flagged with this token can be initialized by 'you'
518 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
519 typedef struct prvm_prog_s
521 double starttime; // system time when PRVM_Prog_Load was called
522 double inittime; // system time when QC initialization code finished (any entity created before is not a leak)
523 double profiletime; // system time when last PRVM_CallProfile was called (or PRVM_Prog_Load initially)
524 mfunction_t *functions;
525 int functions_covered;
530 mstatement_t *statements;
531 int entityfields; // number of vec_t fields in progs (some variables are 3)
532 int entityfieldsarea; // LadyHavoc: equal to max_edicts * entityfields (for bounds checking)
534 // loaded values from the disk format
537 int progs_numstatements;
538 int progs_numglobaldefs;
539 int progs_numfielddefs;
540 int progs_numfunctions;
541 int progs_numstrings;
542 int progs_numglobals;
543 int progs_entityfields;
545 // real values in memory (some modified by loader)
553 int *statement_linenums; // NULL if not available
554 int *statement_columnnums; // NULL if not available
556 double *statement_profile; // only incremented if prvm_statementprofiling is on
557 int statements_covered;
558 double *explicit_profile; // only incremented if prvm_statementprofiling is on
559 int explicit_covered;
560 int numexplicitcoveragestatements;
565 // globalvars_t *server;
566 // cl_globalvars_t *client;
571 // this is updated whenever a string is removed or added
572 // (simple optimization of the free string search)
573 int firstfreeknownstring;
574 const char **knownstrings;
575 unsigned char *knownstrings_flags;
576 const char **knownstrings_origin;
577 const char ***stringshash;
579 memexpandablearray_t stringbuffersarray;
581 // garbage collection status
582 prvm_prog_garbagecollection_state_t gc;
584 // all memory allocations related to this vm_prog (code, edicts, strings)
585 mempool_t *progs_mempool; // [INIT]
587 prvm_builtin_t *builtins; // [INIT]
588 int numbuiltins; // [INIT]
594 int break_stack_index;
596 etype_t watch_global_type;
597 prvm_eval_t watch_global_value;
600 etype_t watch_field_type;
601 prvm_eval_t watch_edictfield_value;
603 mfunction_t *xfunction;
606 // stacktrace writes into stack[MAX_STACK_DEPTH]
607 // thus increase the array, so depth wont be overwritten
608 prvm_stack_t stack[PRVM_MAX_STACK_DEPTH+1];
611 prvm_int_t localstack[PRVM_LOCALSTACK_SIZE];
614 unsigned short filecrc;
616 //============================================================================
617 // until this point everything also exists (with the pr_ prefix) in the old vm
619 qfile_t *openfiles[PRVM_MAX_OPENFILES];
620 const char * openfiles_origin[PRVM_MAX_OPENFILES];
621 fssearch_t *opensearches[PRVM_MAX_OPENSEARCHES];
622 const char * opensearches_origin[PRVM_MAX_OPENSEARCHES];
623 skeleton_t *skeletons[MAX_EDICTS];
624 cmd_state_t *console_cmd; // points to the relevant console command interpreter for this vm (&cmd_client or &cmd_server), also used to access cvars
626 // buffer for storing all tempstrings created during one invocation of ExecuteProgram
627 sizebuf_t tempstringsbuf;
629 // in csqc the polygonbegin,polygonvertex,polygonend sequencing is
630 // stateful, so this tracks the last polygonbegin's choice of
631 // CL_Mesh_CSQC or CL_Mesh_UI for this polygon
632 dp_model_t *polygonbegin_model;
633 // indicates if polygonbegin should be interpreted as 2d
634 // (clearscene sets this to false, renderscene sets this to true, drawpic
635 // also sets this to true)
636 // note that in FTEQW polygonbegin with 2 args is handled very differently,
637 // where the behavior is always 3D unless DRAWFLAG_2D is passed, but
638 // DRAWFLAG_2D conflicts with our DRAWFLAG_SCREEN.
639 qboolean polygonbegin_guess2d;
641 // copies of some vars that were former read from sv
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]
648 // number of reserved edicts (allocated from 1)
649 int reserved_edicts; // [INIT]
651 prvm_edict_t *edicts;
659 // size of the engine private struct
660 int edictprivate_size; // [INIT]
662 prvm_prog_fieldoffsets_t fieldoffsets;
663 prvm_prog_globaloffsets_t globaloffsets;
664 prvm_prog_funcoffsets_t funcoffsets;
666 // allow writing to world entity fields, this is set by server init and
667 // cleared before first server frame
668 qboolean allowworldwrites;
670 // name of the prog, e.g. "Server", "Client" or "Menu" (used for text output)
671 const char *name; // [INIT]
673 // flag - used to store general flags like PRVM_GE_SELF, etc.
676 const char *extensionstring; // [INIT]
678 qboolean loadintoworld; // [INIT]
680 // used to indicate whether a prog is loaded
682 qboolean leaktest_active;
684 // translation buffer (only needs to be freed on unloading progs, type is private to prvm_edict.c)
687 // printed together with backtraces
688 const char *statestring;
690 struct animatemodel_cache *animatemodel_cache;
692 // prvm_builtin_mem_t *mem_list;
694 // now passed as parameter of PRVM_LoadProgs
695 // char **required_func;
696 // int numrequiredfunc;
698 //============================================================================
700 ddef_t *self; // if self != 0 then there is a global self
702 //============================================================================
705 void (*begin_increase_edicts)(struct prvm_prog_s *prog); // [INIT] used by PRVM_MEM_Increase_Edicts
706 void (*end_increase_edicts)(struct prvm_prog_s *prog); // [INIT]
708 void (*init_edict)(struct prvm_prog_s *prog, prvm_edict_t *edict); // [INIT] used by PRVM_ED_ClearEdict
709 void (*free_edict)(struct prvm_prog_s *prog, prvm_edict_t *ed); // [INIT] used by PRVM_ED_Free
711 void (*count_edicts)(struct prvm_prog_s *prog); // [INIT] used by PRVM_ED_Count_f
713 qboolean (*load_edict)(struct prvm_prog_s *prog, prvm_edict_t *ent); // [INIT] used by PRVM_ED_LoadFromFile
715 void (*init_cmd)(struct prvm_prog_s *prog); // [INIT] used by PRVM_InitProg
716 void (*reset_cmd)(struct prvm_prog_s *prog); // [INIT] used by PRVM_ResetProg
718 void (*error_cmd)(const char *format, ...) DP_FUNC_PRINTF(1); // [INIT]
720 void (*ExecuteProgram)(struct prvm_prog_s *prog, func_t fnum, const char *errormessage); // pointer to one of the *VM_ExecuteProgram functions
723 typedef enum prvm_progindex_e
732 extern prvm_prog_t prvm_prog_list[PRVM_PROG_MAX];
733 prvm_prog_t *PRVM_ProgFromString(const char *str);
734 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)
735 #define PRVM_GetProg(n) (&prvm_prog_list[(n)])
736 #define PRVM_ProgLoaded(n) (PRVM_GetProg(n)->loaded)
737 #define SVVM_prog (&prvm_prog_list[PRVM_PROG_SERVER])
738 #define CLVM_prog (&prvm_prog_list[PRVM_PROG_CLIENT])
740 #define MVM_prog (&prvm_prog_list[PRVM_PROG_MENU])
743 //============================================================================
746 extern prvm_builtin_t vm_sv_builtins[];
747 extern prvm_builtin_t vm_cl_builtins[];
748 extern prvm_builtin_t vm_m_builtins[];
750 extern const int vm_sv_numbuiltins;
751 extern const int vm_cl_numbuiltins;
752 extern const int vm_m_numbuiltins;
754 extern const char * vm_sv_extensions; // client also uses this
755 extern const char * vm_m_extensions;
757 void SVVM_init_cmd(prvm_prog_t *prog);
758 void SVVM_reset_cmd(prvm_prog_t *prog);
760 void CLVM_init_cmd(prvm_prog_t *prog);
761 void CLVM_reset_cmd(prvm_prog_t *prog);
764 void MVM_init_cmd(prvm_prog_t *prog);
765 void MVM_reset_cmd(prvm_prog_t *prog);
768 void VM_Cmd_Init(prvm_prog_t *prog);
769 void VM_Cmd_Reset(prvm_prog_t *prog);
770 //============================================================================
772 void PRVM_Init (void);
775 void SVVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
776 void CLVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
778 void MVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
781 #define SVVM_ExecuteProgram PRVM_ExecuteProgram
782 #define CLVM_ExecuteProgram PRVM_ExecuteProgram
784 #define MVM_ExecuteProgram PRVM_ExecuteProgram
786 void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessage);
789 #define PRVM_Alloc(buffersize) Mem_Alloc(prog->progs_mempool, buffersize)
790 #define PRVM_Free(buffer) Mem_Free(buffer)
792 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby);
793 void PRVM_Profile_f(cmd_state_t *cmd);
794 void PRVM_ChildProfile_f(cmd_state_t *cmd);
795 void PRVM_CallProfile_f(cmd_state_t *cmd);
796 void PRVM_PrintFunction_f(cmd_state_t *cmd);
798 void PRVM_PrintState(prvm_prog_t *prog, int stack_index);
799 void PRVM_Crash(prvm_prog_t *prog);
800 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize);
801 const char *PRVM_AllocationOrigin(prvm_prog_t *prog);
802 void PRVM_GarbageCollection(prvm_prog_t *prog);
804 ddef_t *PRVM_ED_FindField(prvm_prog_t *prog, const char *name);
805 ddef_t *PRVM_ED_FindGlobal(prvm_prog_t *prog, const char *name);
806 mfunction_t *PRVM_ED_FindFunction(prvm_prog_t *prog, const char *name);
808 int PRVM_ED_FindFieldOffset(prvm_prog_t *prog, const char *name);
809 int PRVM_ED_FindGlobalOffset(prvm_prog_t *prog, const char *name);
810 func_t PRVM_ED_FindFunctionOffset(prvm_prog_t *prog, const char *name);
811 #define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
812 #define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
814 void PRVM_MEM_IncreaseEdicts(prvm_prog_t *prog);
816 qboolean PRVM_ED_CanAlloc(prvm_prog_t *prog, prvm_edict_t *e);
817 prvm_edict_t *PRVM_ED_Alloc(prvm_prog_t *prog);
818 void PRVM_ED_Free(prvm_prog_t *prog, prvm_edict_t *ed);
819 void PRVM_ED_ClearEdict(prvm_prog_t *prog, prvm_edict_t *e);
821 void PRVM_PrintFunctionStatements(prvm_prog_t *prog, const char *name);
822 void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fieldname);
823 void PRVM_ED_Write(prvm_prog_t *prog, qfile_t *f, prvm_edict_t *ed);
824 const char *PRVM_ED_ParseEdict(prvm_prog_t *prog, const char *data, prvm_edict_t *ent);
826 void PRVM_ED_WriteGlobals(prvm_prog_t *prog, qfile_t *f);
827 void PRVM_ED_ParseGlobals(prvm_prog_t *prog, const char *data);
829 void PRVM_ED_LoadFromFile(prvm_prog_t *prog, const char *data);
831 unsigned int PRVM_EDICT_NUM_ERROR(prvm_prog_t *prog, unsigned int n, const char *filename, int fileline);
832 #define PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? (unsigned int)(n) : PRVM_EDICT_NUM_ERROR(prog, (unsigned int)(n), __FILE__, __LINE__))
833 #define PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
835 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
836 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
837 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
839 #define PRVM_NEXT_EDICT(e) ((e) + 1)
841 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
842 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
843 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
844 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
846 //============================================================================
848 #define PRVM_G_FLOAT(o) (prog->globals.fp[o])
849 #define PRVM_G_INT(o) (prog->globals.ip[o])
850 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(prog->globals.ip[o]))
851 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
852 #define PRVM_G_VECTOR(o) (&prog->globals.fp[o])
853 #define PRVM_G_STRING(o) (PRVM_GetString(prog, prog->globals.ip[o]))
854 //#define PRVM_G_FUNCTION(prog, o) (prog->globals.ip[o])
856 // FIXME: make these go away?
857 #define PRVM_E_FLOAT(e,o) (e->fields.fp[o])
858 #define PRVM_E_INT(e,o) (e->fields.ip[o])
859 //#define PRVM_E_VECTOR(e,o) (&(e->fields.fp[o]))
860 #define PRVM_E_STRING(e,o) (PRVM_GetString(prog, e->fields.ip[o]))
862 extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to
863 // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything
865 void PRVM_Init_Exec(prvm_prog_t *prog);
867 void PRVM_ED_PrintEdicts_f(cmd_state_t *cmd);
868 void PRVM_ED_PrintNum (prvm_prog_t *prog, int ent, const char *wildcard_fieldname);
870 const char *PRVM_GetString(prvm_prog_t *prog, int num);
871 int PRVM_SetEngineString(prvm_prog_t *prog, const char *s);
872 const char *PRVM_ChangeEngineString(prvm_prog_t *prog, int i, const char *s);
873 int PRVM_SetTempString(prvm_prog_t *prog, const char *s);
874 int PRVM_AllocString(prvm_prog_t *prog, size_t bufferlength, char **pointer);
875 void PRVM_FreeString(prvm_prog_t *prog, int num);
877 ddef_t *PRVM_ED_FieldAtOfs(prvm_prog_t *prog, int ofs);
878 qboolean PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, ddef_t *key, const char *s, qboolean parsebackslash);
879 char *PRVM_UglyValueString(prvm_prog_t *prog, etype_t type, prvm_eval_t *val, char *line, size_t linelength);
880 char *PRVM_GlobalString(prvm_prog_t *prog, int ofs, char *line, size_t linelength);
881 char *PRVM_GlobalStringNoContents(prvm_prog_t *prog, int ofs, char *line, size_t linelength);
883 //============================================================================
887 Call InitProg with the num
888 Set up the fields marked with [INIT] in the prog struct
889 Load a program with LoadProgs
891 // Load expects to be called right after Reset
892 void PRVM_Prog_Init(prvm_prog_t *prog, cmd_state_t *cmd);
893 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);
894 void PRVM_Prog_Reset(prvm_prog_t *prog);
896 void PRVM_StackTrace(prvm_prog_t *prog);
897 void PRVM_Breakpoint(prvm_prog_t *prog, int stack_index, const char *text);
898 void PRVM_Watchpoint(prvm_prog_t *prog, int stack_index, const char *text, etype_t type, prvm_eval_t *o, prvm_eval_t *n);
900 void VM_Warning(prvm_prog_t *prog, const char *fmt, ...) DP_FUNC_PRINTF(2);
902 void VM_GenerateFrameGroupBlend(prvm_prog_t *prog, framegroupblend_t *framegroupblend, const prvm_edict_t *ed);
903 void VM_FrameBlendFromFrameGroupBlend(frameblend_t *frameblend, const framegroupblend_t *framegroupblend, const dp_model_t *model, double curtime);
904 void VM_UpdateEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed, const dp_model_t *edmodel, const frameblend_t *frameblend);
905 void VM_RemoveEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed);
907 void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement);