]> icculus.org git repositories - divverent/darkplaces.git/blob - progsvm.h
Fixed a invalid use of the sizeof() operator. Thanks to OpenBSD's custom GCC for...
[divverent/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 // forward declaration of clgecko_t
37 struct clgecko_s;
38
39 typedef struct prvm_stack_s
40 {
41         int                             s;
42         mfunction_t             *f;
43 } prvm_stack_t;
44
45
46 typedef union prvm_eval_s
47 {
48         string_t                string;
49         float                   _float;
50         float                   vector[3];
51         func_t                  function;
52         int                             ivector[3];
53         int                             _int;
54         int                             edict;
55 } prvm_eval_t;
56
57 typedef struct prvm_required_field_s
58 {
59         int type;
60         const char *name;
61 } prvm_required_field_t;
62
63
64 // AK: I dont call it engine private cause it doesnt really belongs to the engine
65 //     it belongs to prvm.
66 typedef struct prvm_edict_private_s
67 {
68         qboolean free;
69         float freetime;
70         int mark;
71         const char *allocation_origin;
72 } prvm_edict_private_t;
73
74 typedef struct prvm_edict_s
75 {
76         // engine-private fields (stored in dynamically resized array)
77         //edict_engineprivate_t *e;
78         union
79         {
80                 prvm_edict_private_t *required;
81                 void *vp;
82                 // FIXME: this server pointer really means world, not server
83                 // (it is used by both server qc and client qc, but not menu qc)
84                 edict_engineprivate_t *server;
85                 // add other private structs as you desire
86                 // new structs have to start with the elements of prvm_edit_private_t
87                 // e.g. a new struct has to either look like this:
88                 //      typedef struct server_edict_private_s {
89                 //              prvm_edict_private_t base;
90                 //              vec3_t moved_from;
91                 //      vec3_t moved_fromangles;
92                 //              ... } server_edict_private_t;
93                 // or:
94                 //      typedef struct server_edict_private_s {
95                 //              qboolean free;
96                 //              float freetime;
97                 //              vec3_t moved_from;
98                 //      vec3_t moved_fromangles;
99                 //              ... } server_edict_private_t;
100                 // However, the first one should be preferred.
101         } priv;
102         // QuakeC fields (stored in dynamically resized array)
103         union
104         {
105                 void *vp;
106                 entvars_t               *server;
107                 cl_entvars_t    *client;
108         } fields;
109 } prvm_edict_t;
110
111 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) (fieldoffset >= 0 ? (prvm_eval_t *)((int *)ed->fields.vp + fieldoffset) : NULL)
112 #define PRVM_GLOBALFIELDVALUE(fieldoffset) (fieldoffset >= 0 ? (prvm_eval_t *)((int *)prog->globals.generic + fieldoffset) : NULL)
113
114 //============================================================================
115 #define PRVM_OP_STATE           1
116
117 #define PRVM_MAX_STACK_DEPTH            1024
118 #define PRVM_LOCALSTACK_SIZE            16384
119
120 #define PRVM_MAX_OPENFILES 256
121 #define PRVM_MAX_OPENSEARCHES 128
122 #define PRVM_MAX_GECKOINSTANCES 32
123
124 typedef void (*prvm_builtin_t) (void);
125
126 // NOTE: field offsets use -1 for NULL
127 typedef struct prvm_prog_fieldoffsets_s
128 {
129         // server and client use a lot of similar fields, so this is combined
130         int SendEntity; // ssqc
131         int SendFlags; // ssqc
132         int Version; // ssqc (legacy)
133         int alpha; // ssqc / csqc
134         int ammo_cells1; // ssqc - Dissolution of Eternity mission pack
135         int ammo_lava_nails; // ssqc - Dissolution of Eternity mission pack
136         int ammo_multi_rockets; // ssqc - Dissolution of Eternity mission pack
137         int ammo_nails1; // ssqc - Dissolution of Eternity mission pack
138         int ammo_plasma; // ssqc - Dissolution of Eternity mission pack
139         int ammo_rockets1; // ssqc - Dissolution of Eternity mission pack
140         int ammo_shells1; // ssqc - Dissolution of Eternity mission pack
141         int angles; // common - used by changeyaw/changepitch
142         int button3; // ssqc
143         int button4; // ssqc
144         int button5; // ssqc
145         int button6; // ssqc
146         int button7; // ssqc
147         int button8; // ssqc
148         int button9; // ssqc
149         int button10; // ssqc
150         int button11; // ssqc
151         int button12; // ssqc
152         int button13; // ssqc
153         int button14; // ssqc
154         int button15; // ssqc
155         int button16; // ssqc
156         int buttonchat; // ssqc
157         int buttonuse; // ssqc
158         int chain; // common - used by find builtins
159         int classname; // common
160         int clientcamera; // ssqc
161         int clientcolors; // ssqc
162         int clientstatus; // ssqc
163         int color; // ssqc
164         int colormod; // ssqc / csqc
165         int contentstransition; // ssqc
166         int cursor_active; // ssqc
167         int cursor_screen; // ssqc
168         int cursor_trace_endpos; // ssqc
169         int cursor_trace_ent; // ssqc
170         int cursor_trace_start; // ssqc
171         int customizeentityforclient; // ssqc
172         int dimension_hit; // ssqc / csqc
173         int dimension_solid; // ssqc / csqc
174         int disableclientprediction; // ssqc
175         int dphitcontentsmask; // ssqc / csqc
176         int drawonlytoclient; // ssqc
177         int effects; // ssqc / csqc
178         int exteriormodeltoclient; // ssqc
179         int fatness; // ssqc / csqc
180         int forceshader; // csqc
181         int frame1time; // csqc
182         int frame2; // csqc
183         int frame2time; // csqc
184         int frame3; // csqc
185         int frame3time; // csqc
186         int frame4; // csqc
187         int frame4time; // csqc
188         int frame; // common - used by OP_STATE
189         int fullbright; // ssqc - Nehahra support
190         int glow_color; // ssqc
191         int glow_size; // ssqc
192         int glow_trail; // ssqc
193         int gravity; // ssqc
194         int groundentity; // ssqc / csqc
195         int hull; // ssqc / csqc
196         int ideal_yaw; // ssqc / csqc
197         int idealpitch; // ssqc / csqc
198         int items2; // ssqc
199         int lerpfrac3; // csqc
200         int lerpfrac4; // csqc
201         int lerpfrac; // csqc
202         int light_lev; // ssqc
203         int message; // csqc
204         int modelflags; // ssqc
205         int movement; // ssqc
206         int movetypesteplandevent; // ssqc
207         int netaddress; // ssqc
208         int nextthink; // common - used by OP_STATE
209         int nodrawtoclient; // ssqc
210         int pflags; // ssqc
211         int ping; // ssqc
212         int pitch_speed; // ssqc / csqc
213         int playermodel; // ssqc
214         int playerskin; // ssqc
215         int pmodel; // ssqc
216         int punchvector; // ssqc
217         int renderamt; // ssqc - HalfLife support
218         int renderflags; // csqc
219         int rendermode; // ssqc - HalfLife support
220         int scale; // ssqc / csqc
221         int shadertime; // csqc
222         int style; // ssqc
223         int tag_entity; // ssqc / csqc
224         int tag_index; // ssqc / csqc
225         int think; // common - used by OP_STATE
226         int viewmodelforclient; // ssqc
227         int viewzoom; // ssqc
228         int yaw_speed; // ssqc / csqc
229 }
230 prvm_prog_fieldoffsets_t;
231
232 // NOTE: global offsets use -1 for NULL
233 typedef struct prvm_prog_globaloffsets_s
234 {
235         // server and client use a lot of similar globals, so this is combined
236         int SV_InitCmd; // ssqc
237         int self; // common
238         int time; // ssqc / csqc
239         int v_forward; // ssqc / csqc
240         int v_right; // ssqc / csqc
241         int v_up; // ssqc / csqc
242         int view_angles; // csqc
243         int trace_allsolid; // ssqc / csqc
244         int trace_startsolid; // ssqc / csqc
245         int trace_fraction; // ssqc / csqc
246         int trace_inwater; // ssqc / csqc
247         int trace_inopen; // ssqc / csqc
248         int trace_endpos; // ssqc / csqc
249         int trace_plane_normal; // ssqc / csqc
250         int trace_plane_dist; // ssqc / csqc
251         int trace_ent; // ssqc / csqc
252         int trace_networkentity; // csqc
253         int trace_dphitcontents; // ssqc / csqc
254         int trace_dphitq3surfaceflags; // ssqc / csqc
255         int trace_dphittexturename; // ssqc / csqc
256         int trace_dpstartcontents; // ssqc / csqc
257         int intermission; // csqc
258         int coop; // csqc
259         int deathmatch; // csqc
260         int dmg_take; // csqc
261         int dmg_save; // csqc
262         int dmg_origin; // csqc
263         int sb_showscores; // csqc
264         int drawfont; // csqc / menu
265         int require_spawnfunc_prefix; // ssqc
266         int worldstatus; // ssqc
267         int servertime; // csqc
268         int serverprevtime; // csqc
269         int serverdeltatime; // csqc
270         int gettaginfo_name; // ssqc / csqc
271         int gettaginfo_parent; // ssqc / csqc
272         int gettaginfo_offset; // ssqc / csqc
273         int gettaginfo_forward; // ssqc / csqc
274         int gettaginfo_right; // ssqc / csqc
275         int gettaginfo_up; // ssqc / csqc
276 }
277 prvm_prog_globaloffsets_t;
278
279 // these are initialized using PRVM_ED_FindFunction
280 // NOTE: function offsets use 0 for NULL
281 typedef struct prvm_prog_funcoffsets_s
282 {
283         func_t CSQC_ConsoleCommand; // csqc
284         func_t CSQC_Ent_Remove; // csqc
285         func_t CSQC_Ent_Spawn; // csqc DP_CSQC_ENT_SPAWN extension (BlackHC - TODO: needs to be added to dpextensions.qc)
286         func_t CSQC_Ent_Update; // csqc
287         func_t CSQC_Event; // csqc [515]: engine call this for its own needs so csqc can do some things according to what engine it's running on.  example: to say about edicts increase, whatever...
288         func_t CSQC_Event_Sound; // csqc : called by engine when an incoming sound packet arrives so CSQC can act on it
289         func_t CSQC_Init; // csqc
290         func_t CSQC_InputEvent; // csqc
291         func_t CSQC_Parse_CenterPrint; // csqc
292         func_t CSQC_Parse_Print; // csqc
293         func_t CSQC_Parse_StuffCmd; // csqc
294         func_t CSQC_Parse_TempEntity; // csqc [515]: very helpfull when you want to create your own particles/decals/etc for effects that already exist
295         func_t CSQC_Shutdown; // csqc
296         func_t CSQC_UpdateView; // csqc
297         func_t Gecko_Query; // csqc, mqc
298         func_t EndFrame; // ssqc
299         func_t RestoreGame; // ssqc
300         func_t SV_ChangeTeam; // ssqc
301         func_t SV_ParseClientCommand; // ssqc
302         func_t SV_PlayerPhysics; // ssqc
303         func_t SV_OnEntityPreSpawnFunction; // ssqc
304         func_t SV_OnEntityNoSpawnFunction; // ssqc
305         func_t SV_OnEntityPostSpawnFunction; // ssqc
306         func_t GameCommand; // any
307         func_t SV_Shutdown; // ssqc
308         func_t URI_Get_Callback; // any
309         func_t SV_PausedTic; //ssqc
310
311         // menu qc only uses some functions, nothing else
312         func_t m_draw; // mqc
313         func_t m_init; // mqc
314         func_t m_keydown; // mqc
315         func_t m_keyup; // mqc
316         func_t m_shutdown; // mqc
317         func_t m_toggle; // mqc
318 }
319 prvm_prog_funcoffsets_t;
320
321 typedef struct prvm_stringbuffer_s
322 {
323         int max_strings;
324         int num_strings;
325         char **strings;
326         const char *origin;
327 }
328 prvm_stringbuffer_t;
329
330 // [INIT] variables flagged with this token can be initialized by 'you'
331 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
332 typedef struct prvm_prog_s
333 {
334         double              starttime;
335         dprograms_t                     *progs;
336         mfunction_t                     *functions;
337         char                            *strings;
338         int                                     stringssize;
339         ddef_t                          *fielddefs;
340         ddef_t                          *globaldefs;
341         dstatement_t            *statements;
342         int                                     edict_size;                     // in bytes
343         int                                     edictareasize;          // LordHavoc: in bytes (for bound checking)
344
345         int                                     *statement_linenums; // NULL if not available
346
347         double                          *statement_profile; // only incremented if prvm_statementprofiling is on
348
349         union {
350                 float *generic;
351                 globalvars_t *server;
352                 cl_globalvars_t *client;
353         } globals;
354
355         int                                     maxknownstrings;
356         int                                     numknownstrings;
357         // this is updated whenever a string is removed or added
358         // (simple optimization of the free string search)
359         int                                     firstfreeknownstring;
360         const char                      **knownstrings;
361         unsigned char           *knownstrings_freeable;
362         const char          **knownstrings_origin;
363         const char                      ***stringshash;
364
365         memexpandablearray_t    stringbuffersarray;
366
367         // all memory allocations related to this vm_prog (code, edicts, strings)
368         mempool_t                       *progs_mempool; // [INIT]
369
370         prvm_builtin_t          *builtins; // [INIT]
371         int                                     numbuiltins; // [INIT]
372
373         int                                     argc;
374
375         int                                     trace;
376         mfunction_t                     *xfunction;
377         int                                     xstatement;
378
379         // stacktrace writes into stack[MAX_STACK_DEPTH]
380         // thus increase the array, so depth wont be overwritten
381         prvm_stack_t            stack[PRVM_MAX_STACK_DEPTH+1];
382         int                                     depth;
383
384         int                                     localstack[PRVM_LOCALSTACK_SIZE];
385         int                                     localstack_used;
386
387         unsigned short          headercrc; // [INIT]
388         unsigned short          headercrc2; // [INIT] alternate CRC for tenebrae progs.dat
389
390         unsigned short          filecrc;
391
392         //============================================================================
393         // until this point everything also exists (with the pr_ prefix) in the old vm
394
395         qfile_t                         *openfiles[PRVM_MAX_OPENFILES];
396         const char *         openfiles_origin[PRVM_MAX_OPENFILES];
397         fssearch_t                      *opensearches[PRVM_MAX_OPENSEARCHES];
398         const char *         opensearches_origin[PRVM_MAX_OPENSEARCHES];
399         struct clgecko_s                *opengeckoinstances[PRVM_MAX_GECKOINSTANCES];
400
401         // copies of some vars that were former read from sv
402         int                                     num_edicts;
403         // number of edicts for which space has been (should be) allocated
404         int                                     max_edicts; // [INIT]
405         // used instead of the constant MAX_EDICTS
406         int                                     limit_edicts; // [INIT]
407
408         // number of reserved edicts (allocated from 1)
409         int                                     reserved_edicts; // [INIT]
410
411         prvm_edict_t            *edicts;
412         void                                    *edictsfields;
413         void                                    *edictprivate;
414
415         // size of the engine private struct
416         int                                     edictprivate_size; // [INIT]
417
418         prvm_prog_fieldoffsets_t        fieldoffsets;
419         prvm_prog_globaloffsets_t       globaloffsets;
420         prvm_prog_funcoffsets_t         funcoffsets;
421
422         // allow writing to world entity fields, this is set by server init and
423         // cleared before first server frame
424         qboolean                        allowworldwrites;
425
426         // name of the prog, e.g. "Server", "Client" or "Menu" (used for text output)
427         char                            *name; // [INIT]
428
429         // flag - used to store general flags like PRVM_GE_SELF, etc.
430         int                             flag;
431
432         char                            *extensionstring; // [INIT]
433
434         qboolean                        loadintoworld; // [INIT]
435
436         // used to indicate whether a prog is loaded
437         qboolean                        loaded;
438         qboolean                        leaktest_active;
439
440         // printed together with backtraces
441         const char *statestring;
442
443 //      prvm_builtin_mem_t  *mem_list;
444
445 // now passed as parameter of PRVM_LoadProgs
446 //      char                            **required_func;
447 //      int                                     numrequiredfunc;
448
449         //============================================================================
450
451         ddef_t                          *self; // if self != 0 then there is a global self
452
453         //============================================================================
454         // function pointers
455
456         void                            (*begin_increase_edicts)(void); // [INIT] used by PRVM_MEM_Increase_Edicts
457         void                            (*end_increase_edicts)(void); // [INIT]
458
459         void                            (*init_edict)(prvm_edict_t *edict); // [INIT] used by PRVM_ED_ClearEdict
460         void                            (*free_edict)(prvm_edict_t *ed); // [INIT] used by PRVM_ED_Free
461
462         void                            (*count_edicts)(void); // [INIT] used by PRVM_ED_Count_f
463
464         qboolean                        (*load_edict)(prvm_edict_t *ent); // [INIT] used by PRVM_ED_LoadFromFile
465
466         void                            (*init_cmd)(void); // [INIT] used by PRVM_InitProg
467         void                            (*reset_cmd)(void); // [INIT] used by PRVM_ResetProg
468
469         void                            (*error_cmd)(const char *format, ...) DP_FUNC_PRINTF(1); // [INIT]
470 } prvm_prog_t;
471
472 extern prvm_prog_t * prog;
473
474 #define PRVM_MAXPROGS 3
475 #define PRVM_SERVERPROG 0 // actually not used at the moment
476 #define PRVM_CLIENTPROG 1
477 #define PRVM_MENUPROG   2
478
479 extern prvm_prog_t prvm_prog_list[PRVM_MAXPROGS];
480
481 //============================================================================
482 // prvm_cmds part
483
484 extern prvm_builtin_t vm_sv_builtins[];
485 extern prvm_builtin_t vm_cl_builtins[];
486 extern prvm_builtin_t vm_m_builtins[];
487
488 extern const int vm_sv_numbuiltins;
489 extern const int vm_cl_numbuiltins;
490 extern const int vm_m_numbuiltins;
491
492 extern char * vm_sv_extensions; // client also uses this
493 extern char * vm_m_extensions;
494
495 void VM_SV_Cmd_Init(void);
496 void VM_SV_Cmd_Reset(void);
497
498 void VM_CL_Cmd_Init(void);
499 void VM_CL_Cmd_Reset(void);
500
501 void VM_M_Cmd_Init(void);
502 void VM_M_Cmd_Reset(void);
503
504 void VM_Cmd_Init(void);
505 void VM_Cmd_Reset(void);
506 //============================================================================
507
508 void PRVM_Init (void);
509
510 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage);
511
512 #define PRVM_Alloc(buffersize) _PRVM_Alloc(buffersize, __FILE__, __LINE__)
513 #define PRVM_Free(buffer) _PRVM_Free(buffer, __FILE__, __LINE__)
514 #define PRVM_FreeAll() _PRVM_FreeAll(__FILE__, __LINE__)
515 void *_PRVM_Alloc (size_t buffersize, const char *filename, int fileline);
516 void _PRVM_Free (void *buffer, const char *filename, int fileline);
517 void _PRVM_FreeAll (const char *filename, int fileline);
518
519 void PRVM_Profile (int maxfunctions, int mininstructions);
520 void PRVM_Profile_f (void);
521 void PRVM_CallProfile_f (void);
522 void PRVM_PrintFunction_f (void);
523
524 void PRVM_PrintState(void);
525 void PRVM_CrashAll (void);
526 void PRVM_Crash (void);
527 void PRVM_ShortStackTrace(char *buf, size_t bufsize);
528 const char *PRVM_AllocationOrigin();
529
530 ddef_t *PRVM_ED_FindField(const char *name);
531 ddef_t *PRVM_ED_FindGlobal(const char *name);
532 mfunction_t *PRVM_ED_FindFunction(const char *name);
533
534 int PRVM_ED_FindFieldOffset(const char *name);
535 int PRVM_ED_FindGlobalOffset(const char *name);
536 func_t PRVM_ED_FindFunctionOffset(const char *name);
537 #define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
538 #define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
539
540 void PRVM_MEM_IncreaseEdicts(void);
541
542 qboolean PRVM_ED_CanAlloc(prvm_edict_t *e);
543 prvm_edict_t *PRVM_ED_Alloc (void);
544 void PRVM_ED_Free (prvm_edict_t *ed);
545 void PRVM_ED_ClearEdict (prvm_edict_t *e);
546
547 void PRVM_PrintFunctionStatements (const char *name);
548 void PRVM_ED_Print(prvm_edict_t *ed, const char *wildcard_fieldname);
549 void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed);
550 const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent);
551
552 void PRVM_ED_WriteGlobals (qfile_t *f);
553 void PRVM_ED_ParseGlobals (const char *data);
554
555 void PRVM_ED_LoadFromFile (const char *data);
556
557 unsigned int PRVM_EDICT_NUM_ERROR(unsigned int n, char *filename, int fileline);
558 #define PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? (unsigned int)(n) : PRVM_EDICT_NUM_ERROR((unsigned int)(n), __FILE__, __LINE__))
559 #define PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
560
561 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
562 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
563 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
564
565 #define PRVM_NEXT_EDICT(e) ((e) + 1)
566
567 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
568 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
569 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
570 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
571
572 //============================================================================
573
574 #define PRVM_G_FLOAT(o) (prog->globals.generic[o])
575 #define PRVM_G_INT(o) (*(int *)&prog->globals.generic[o])
576 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&prog->globals.generic[o]))
577 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
578 #define PRVM_G_VECTOR(o) (&prog->globals.generic[o])
579 #define PRVM_G_STRING(o) (PRVM_GetString(*(string_t *)&prog->globals.generic[o]))
580 //#define       PRVM_G_FUNCTION(o) (*(func_t *)&prog->globals.generic[o])
581
582 // FIXME: make these go away?
583 #define PRVM_E_FLOAT(e,o) (((float*)e->fields.vp)[o])
584 #define PRVM_E_INT(e,o) (((int*)e->fields.vp)[o])
585 //#define       PRVM_E_VECTOR(e,o) (&((float*)e->fields.vp)[o])
586 #define PRVM_E_STRING(e,o) (PRVM_GetString(*(string_t *)&((float*)e->fields.vp)[o]))
587
588 extern  int             prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to
589 // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything
590
591 void PRVM_Init_Exec(void);
592
593 void PRVM_ED_PrintEdicts_f (void);
594 void PRVM_ED_PrintNum (int ent, const char *wildcard_fieldname);
595
596 const char *PRVM_GetString(int num);
597 int PRVM_SetEngineString(const char *s);
598 int PRVM_SetTempString(const char *s);
599 int PRVM_AllocString(size_t bufferlength, char **pointer);
600 void PRVM_FreeString(int num);
601
602 //============================================================================
603
604 // used as replacement for a prog stack
605 //#define PRVM_DEBUGPRSTACK
606
607 #ifdef PRVM_DEBUGPRSTACK
608 #define PRVM_Begin  if(prog != 0) Con_Printf("prog not 0(prog = %i) in file: %s line: %i!\n", PRVM_GetProgNr(), __FILE__, __LINE__)
609 #define PRVM_End        prog = 0
610 #else
611 #define PRVM_Begin
612 #define PRVM_End        prog = 0
613 #endif
614
615 //#define PRVM_SAFENAME
616 #ifndef PRVM_SAFENAME
617 #       define PRVM_NAME        (prog->name)
618 #else
619 #       define PRVM_NAME        (prog->name ? prog->name : "Unknown prog name")
620 #endif
621
622 // helper macro to make function pointer calls easier
623 #define PRVM_GCALL(func)        if(prog->func) prog->func
624
625 #define PRVM_ERROR              prog->error_cmd
626
627 // other prog handling functions
628 qboolean PRVM_SetProgFromString(const char *str);
629 void PRVM_SetProg(int prognr);
630
631 /*
632 Initializing a vm:
633 Call InitProg with the num
634 Set up the fields marked with [INIT] in the prog struct
635 Load a program with LoadProgs
636 */
637 void PRVM_InitProg(int prognr);
638 // LoadProgs expects to be called right after InitProg
639 void PRVM_LoadProgs (const char *filename, int numrequiredfunc, char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, char **required_global);
640 void PRVM_ResetProg(void);
641
642 qboolean PRVM_ProgLoaded(int prognr);
643
644 int     PRVM_GetProgNr(void);
645
646 void VM_Warning(const char *fmt, ...) DP_FUNC_PRINTF(1);
647
648 // TODO: fill in the params
649 //void PRVM_Create();
650
651 #endif