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 // forward declaration of clgecko_t
43 typedef struct prvm_stack_s
49 double builtinsprofile_acc;
53 typedef union prvm_eval_s
64 typedef struct prvm_required_field_s
68 } prvm_required_field_t;
71 // AK: I dont call it engine private cause it doesnt really belongs to the engine
72 // it belongs to prvm.
73 typedef struct prvm_edict_private_s
78 const char *allocation_origin;
79 } prvm_edict_private_t;
81 typedef struct prvm_edict_s
83 // engine-private fields (stored in dynamically resized array)
84 //edict_engineprivate_t *e;
87 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 cl_entvars_t *client;
118 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))
119 #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->_float)
120 #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->vector)
121 #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->string)
122 #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->edict)
123 #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->function)
124 #define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))
125 #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->_float)
126 #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->vector)
127 #define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->string)
128 #define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->edict)
129 #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->function)
131 //============================================================================
132 #define PRVM_OP_STATE 1
134 #ifdef DP_SMALLMEMORY
135 #define PRVM_MAX_STACK_DEPTH 128
136 #define PRVM_LOCALSTACK_SIZE 2048
138 #define PRVM_MAX_OPENFILES 16
139 #define PRVM_MAX_OPENSEARCHES 8
140 #define PRVM_MAX_GECKOINSTANCES 1
142 #define PRVM_MAX_STACK_DEPTH 1024
143 #define PRVM_LOCALSTACK_SIZE 16384
145 #define PRVM_MAX_OPENFILES 256
146 #define PRVM_MAX_OPENSEARCHES 128
147 #define PRVM_MAX_GECKOINSTANCES 32
150 typedef void (*prvm_builtin_t) (void);
152 // NOTE: field offsets use -1 for NULL
153 typedef struct prvm_prog_fieldoffsets_s
155 // server and client use a lot of similar fields, so this is combined
156 int SendEntity; // ssqc
157 int SendFlags; // ssqc
158 int Version; // ssqc (legacy)
159 int alpha; // ssqc / csqc
160 int ammo_cells1; // ssqc - Dissolution of Eternity mission pack
161 int ammo_lava_nails; // ssqc - Dissolution of Eternity mission pack
162 int ammo_multi_rockets; // ssqc - Dissolution of Eternity mission pack
163 int ammo_nails1; // ssqc - Dissolution of Eternity mission pack
164 int ammo_plasma; // ssqc - Dissolution of Eternity mission pack
165 int ammo_rockets1; // ssqc - Dissolution of Eternity mission pack
166 int ammo_shells1; // ssqc - Dissolution of Eternity mission pack
167 int angles; // common - used by changeyaw/changepitch
175 int button10; // ssqc
176 int button11; // ssqc
177 int button12; // ssqc
178 int button13; // ssqc
179 int button14; // ssqc
180 int button15; // ssqc
181 int button16; // ssqc
182 int buttonchat; // ssqc
183 int buttonuse; // ssqc
184 int chain; // common - used by find builtins
185 int classname; // common
186 int clientcamera; // ssqc
187 int clientcolors; // ssqc
188 int clientstatus; // ssqc
190 int colormod; // ssqc / csqc
191 int contentstransition; // ssqc
192 int cursor_active; // ssqc
193 int cursor_screen; // ssqc
194 int cursor_trace_endpos; // ssqc
195 int cursor_trace_ent; // ssqc
196 int cursor_trace_start; // ssqc
197 int customizeentityforclient; // ssqc
198 int dimension_hit; // ssqc / csqc
199 int dimension_solid; // ssqc / csqc
200 int disableclientprediction; // ssqc
201 int discardabledemo; // ssqc
202 int dphitcontentsmask; // ssqc / csqc
203 int drawonlytoclient; // ssqc
204 int exteriormodeltoclient; // ssqc
205 int fatness; // ssqc / csqc
206 int forceshader; // csqc
207 int frame1time; // csqc
209 int frame2time; // csqc
211 int frame3time; // csqc
213 int frame4time; // csqc
214 int frame; // common - used by OP_STATE
215 int fullbright; // ssqc - Nehahra support
216 int glow_color; // ssqc
217 int glow_size; // ssqc
218 int glow_trail; // ssqc
219 int glowmod; // ssqc / csqc
221 int groundentity; // ssqc / csqc
222 int hull; // ssqc / csqc
223 int ideal_yaw; // ssqc / csqc
224 int idealpitch; // ssqc / csqc
226 int lerpfrac3; // csqc
227 int lerpfrac4; // csqc
228 int lerpfrac; // csqc
229 int light_lev; // ssqc
231 int modelflags; // ssqc
232 int movement; // ssqc
233 int movetypesteplandevent; // ssqc
234 int netaddress; // ssqc
235 int nextthink; // common - used by OP_STATE
236 int nodrawtoclient; // ssqc
239 int ping_packetloss; // ssqc
240 int ping_movementloss; // ssqc
241 int pitch_speed; // ssqc / csqc
242 int playermodel; // ssqc
243 int playerskin; // ssqc
245 int punchvector; // ssqc
246 int renderamt; // ssqc - HalfLife support
247 int renderflags; // csqc
248 int rendermode; // ssqc - HalfLife support
249 int scale; // ssqc / csqc
250 int shadertime; // csqc
251 int skeletonindex; // csqc / ssqc FTE_CSQC_SKELETONOBJECTS / DP_SKELETONOBJECTS
253 int tag_entity; // ssqc / csqc
254 int tag_index; // ssqc / csqc
255 int think; // common - used by OP_STATE
256 int viewmodelforclient; // ssqc
257 int viewzoom; // ssqc
258 int yaw_speed; // ssqc / csqc
259 int bouncefactor; // ssqc
260 int bouncestop; // ssqc
261 int sendcomplexanimation; // ssqc
263 int solid; // ssqc / csqc (physics)
264 int movetype; // ssqc / csqc (physics)
265 int modelindex; // ssqc / csqc (physics)
266 int mins; // ssqc / csqc (physics)
267 int maxs; // ssqc / csqc (physics)
268 int mass; // ssqc / csqc (physics)
269 int origin; // ssqc / csqc (physics)
270 int velocity; // ssqc / csqc (physics)
271 //int axis_forward; // ssqc / csqc (physics)
272 //int axis_left; // ssqc / csqc (physics)
273 //int axis_up; // ssqc / csqc (physics)
274 //int spinvelocity; // ssqc / csqc (physics)
275 //int angles; // ssqc / csqc (physics)
276 int avelocity; // ssqc / csqc (physics)
277 int jointtype; // ssqc / csqc (physics)
278 int enemy; // ssqc / csqc (physics)
279 int aiment; // ssqc / csqc (physics)
280 int movedir; // ssqc / csqc (physics)
282 int camera_transform; // csqc (warpzones)
284 int userwavefunc_param0; // csqc (userwavefunc)
285 int userwavefunc_param1; // csqc (userwavefunc)
286 int userwavefunc_param2; // csqc (userwavefunc)
287 int userwavefunc_param3; // csqc (userwavefunc)
289 int crypto_keyfp; // ssqc (DP_CRYPTO)
290 int crypto_mykeyfp; // ssqc (DP_CRYPTO)
291 int crypto_idfp; // ssqc (DP_CRYPTO)
292 int crypto_encryptmethod; // ssqc (DP_CRYPTO)
293 int crypto_signmethod; // ssqc (DP_CRYPTO)
295 prvm_prog_fieldoffsets_t;
297 // NOTE: global offsets use -1 for NULL
298 typedef struct prvm_prog_globaloffsets_s
300 // server and client use a lot of similar globals, so this is combined
301 int SV_InitCmd; // ssqc
303 int time; // ssqc / csqc
304 int v_forward; // ssqc / csqc
305 int v_right; // ssqc / csqc
306 int v_up; // ssqc / csqc
307 int view_angles; // csqc
308 int view_punchangle; // csqc
309 int view_punchvector; // csqc
310 int trace_allsolid; // ssqc / csqc
311 int trace_startsolid; // ssqc / csqc
312 int trace_fraction; // ssqc / csqc
313 int trace_inwater; // ssqc / csqc
314 int trace_inopen; // ssqc / csqc
315 int trace_endpos; // ssqc / csqc
316 int trace_plane_normal; // ssqc / csqc
317 int trace_plane_dist; // ssqc / csqc
318 int trace_ent; // ssqc / csqc
319 int trace_networkentity; // csqc
320 int trace_dphitcontents; // ssqc / csqc
321 int trace_dphitq3surfaceflags; // ssqc / csqc
322 int trace_dphittexturename; // ssqc / csqc
323 int trace_dpstartcontents; // ssqc / csqc
324 int intermission; // csqc
326 int deathmatch; // csqc
327 int dmg_take; // csqc
328 int dmg_save; // csqc
329 int dmg_origin; // csqc
330 int sb_showscores; // csqc
331 int drawfont; // csqc / menu
332 int drawfontscale; // csqc / menu
333 int require_spawnfunc_prefix; // ssqc
334 int worldstatus; // ssqc
335 int servertime; // csqc
336 int serverprevtime; // csqc
337 int serverdeltatime; // csqc
338 int gettaginfo_name; // ssqc / csqc
339 int gettaginfo_parent; // ssqc / csqc
340 int gettaginfo_offset; // ssqc / csqc
341 int gettaginfo_forward; // ssqc / csqc
342 int gettaginfo_right; // ssqc / csqc
343 int gettaginfo_up; // ssqc / csqc
344 int transparent_offset; // csqc
346 int particles_alphamin; // csqc
347 int particles_alphamax; // csqc
348 int particles_colormin; // csqc
349 int particles_colormax; // csqc
351 prvm_prog_globaloffsets_t;
353 // these are initialized using PRVM_ED_FindFunction
354 // NOTE: function offsets use 0 for NULL
355 typedef struct prvm_prog_funcoffsets_s
357 func_t CSQC_ConsoleCommand; // csqc
358 func_t CSQC_Ent_Remove; // csqc
359 func_t CSQC_Ent_Spawn; // csqc DP_CSQC_ENT_SPAWN extension (BlackHC - TODO: needs to be added to dpextensions.qc)
360 func_t CSQC_Ent_Update; // csqc
361 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...
362 func_t CSQC_Event_Sound; // csqc : called by engine when an incoming sound packet arrives so CSQC can act on it
363 func_t CSQC_Init; // csqc
364 func_t CSQC_InputEvent; // csqc
365 func_t CSQC_Parse_CenterPrint; // csqc
366 func_t CSQC_Parse_Print; // csqc
367 func_t CSQC_Parse_StuffCmd; // csqc
368 func_t CSQC_Parse_TempEntity; // csqc [515]: very helpfull when you want to create your own particles/decals/etc for effects that already exist
369 func_t CSQC_Shutdown; // csqc
370 func_t CSQC_UpdateView; // csqc
371 func_t Gecko_Query; // csqc, mqc
372 func_t EndFrame; // ssqc
373 func_t RestoreGame; // ssqc
374 func_t SV_ChangeTeam; // ssqc
375 func_t SV_ParseClientCommand; // ssqc
376 func_t SV_PlayerPhysics; // ssqc
377 func_t SV_OnEntityPreSpawnFunction; // ssqc
378 func_t SV_OnEntityNoSpawnFunction; // ssqc
379 func_t SV_OnEntityPostSpawnFunction; // ssqc
380 func_t GameCommand; // any
381 func_t SV_Shutdown; // ssqc
382 func_t URI_Get_Callback; // any
383 func_t SV_PausedTic; //ssqc
385 // menu qc only uses some functions, nothing else
386 func_t m_draw; // mqc
387 func_t m_init; // mqc
388 func_t m_keydown; // mqc
389 func_t m_keyup; // mqc
390 func_t m_shutdown; // mqc
391 func_t m_toggle; // mqc
392 func_t m_newmap; // mqc
394 prvm_prog_funcoffsets_t;
396 // stringbuffer flags
397 #define STRINGBUFFER_SAVED 1 // saved in savegames
399 typedef struct prvm_stringbuffer_s
409 // [INIT] variables flagged with this token can be initialized by 'you'
410 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
411 typedef struct prvm_prog_s
414 unsigned int id; // increasing unique id of progs instance
415 mfunction_t *functions;
420 mstatement_t *statements;
421 int entityfields; // number of vec_t fields in progs (some variables are 3)
422 int entityfieldsarea; // LordHavoc: equal to max_edicts * entityfields (for bounds checking)
424 // loaded values from the disk format
427 int progs_numstatements;
428 int progs_numglobaldefs;
429 int progs_numfielddefs;
430 int progs_numfunctions;
431 int progs_numstrings;
432 int progs_numglobals;
433 int progs_entityfields;
435 // real values in memory (some modified by loader)
443 int *statement_linenums; // NULL if not available
445 double *statement_profile; // only incremented if prvm_statementprofiling is on
449 globalvars_t *server;
450 cl_globalvars_t *client;
455 // this is updated whenever a string is removed or added
456 // (simple optimization of the free string search)
457 int firstfreeknownstring;
458 const char **knownstrings;
459 unsigned char *knownstrings_freeable;
460 const char **knownstrings_origin;
461 const char ***stringshash;
463 memexpandablearray_t stringbuffersarray;
465 // all memory allocations related to this vm_prog (code, edicts, strings)
466 mempool_t *progs_mempool; // [INIT]
468 prvm_builtin_t *builtins; // [INIT]
469 int numbuiltins; // [INIT]
474 mfunction_t *xfunction;
477 // stacktrace writes into stack[MAX_STACK_DEPTH]
478 // thus increase the array, so depth wont be overwritten
479 prvm_stack_t stack[PRVM_MAX_STACK_DEPTH+1];
482 int localstack[PRVM_LOCALSTACK_SIZE];
485 unsigned short headercrc; // [INIT]
486 unsigned short headercrc2; // [INIT] alternate CRC for tenebrae progs.dat
488 unsigned short filecrc;
490 //============================================================================
491 // until this point everything also exists (with the pr_ prefix) in the old vm
493 qfile_t *openfiles[PRVM_MAX_OPENFILES];
494 const char * openfiles_origin[PRVM_MAX_OPENFILES];
495 fssearch_t *opensearches[PRVM_MAX_OPENSEARCHES];
496 const char * opensearches_origin[PRVM_MAX_OPENSEARCHES];
497 struct clgecko_s *opengeckoinstances[PRVM_MAX_GECKOINSTANCES];
498 skeleton_t *skeletons[MAX_EDICTS];
500 // copies of some vars that were former read from sv
502 // number of edicts for which space has been (should be) allocated
503 int max_edicts; // [INIT]
504 // used instead of the constant MAX_EDICTS
505 int limit_edicts; // [INIT]
507 // number of reserved edicts (allocated from 1)
508 int reserved_edicts; // [INIT]
510 prvm_edict_t *edicts;
514 // size of the engine private struct
515 int edictprivate_size; // [INIT]
517 prvm_prog_fieldoffsets_t fieldoffsets;
518 prvm_prog_globaloffsets_t globaloffsets;
519 prvm_prog_funcoffsets_t funcoffsets;
521 // allow writing to world entity fields, this is set by server init and
522 // cleared before first server frame
523 qboolean allowworldwrites;
525 // name of the prog, e.g. "Server", "Client" or "Menu" (used for text output)
526 const char *name; // [INIT]
528 // flag - used to store general flags like PRVM_GE_SELF, etc.
531 const char *extensionstring; // [INIT]
533 qboolean loadintoworld; // [INIT]
535 // used to indicate whether a prog is loaded
537 qboolean leaktest_active;
539 // translation buffer (only needs to be freed on unloading progs, type is private to prvm_edict.c)
542 // printed together with backtraces
543 const char *statestring;
545 // prvm_builtin_mem_t *mem_list;
547 // now passed as parameter of PRVM_LoadProgs
548 // char **required_func;
549 // int numrequiredfunc;
551 //============================================================================
553 ddef_t *self; // if self != 0 then there is a global self
555 //============================================================================
558 void (*begin_increase_edicts)(void); // [INIT] used by PRVM_MEM_Increase_Edicts
559 void (*end_increase_edicts)(void); // [INIT]
561 void (*init_edict)(prvm_edict_t *edict); // [INIT] used by PRVM_ED_ClearEdict
562 void (*free_edict)(prvm_edict_t *ed); // [INIT] used by PRVM_ED_Free
564 void (*count_edicts)(void); // [INIT] used by PRVM_ED_Count_f
566 qboolean (*load_edict)(prvm_edict_t *ent); // [INIT] used by PRVM_ED_LoadFromFile
568 void (*init_cmd)(void); // [INIT] used by PRVM_InitProg
569 void (*reset_cmd)(void); // [INIT] used by PRVM_ResetProg
571 void (*error_cmd)(const char *format, ...) DP_FUNC_PRINTF(1); // [INIT]
573 void (*ExecuteProgram)(func_t fnum, const char *errormessage); // pointer to one of the *VM_ExecuteProgram functions
576 extern prvm_prog_t * prog;
578 #define PRVM_MAXPROGS 3
579 #define PRVM_SERVERPROG 0 // actually not used at the moment
580 #define PRVM_CLIENTPROG 1
581 #define PRVM_MENUPROG 2
583 extern prvm_prog_t prvm_prog_list[PRVM_MAXPROGS];
585 //============================================================================
588 extern prvm_builtin_t vm_sv_builtins[];
589 extern prvm_builtin_t vm_cl_builtins[];
590 extern prvm_builtin_t vm_m_builtins[];
592 extern const int vm_sv_numbuiltins;
593 extern const int vm_cl_numbuiltins;
594 extern const int vm_m_numbuiltins;
596 extern const char * vm_sv_extensions; // client also uses this
597 extern const char * vm_m_extensions;
599 void VM_SV_Cmd_Init(void);
600 void VM_SV_Cmd_Reset(void);
602 void VM_CL_Cmd_Init(void);
603 void VM_CL_Cmd_Reset(void);
605 void VM_M_Cmd_Init(void);
606 void VM_M_Cmd_Reset(void);
608 void VM_Cmd_Init(void);
609 void VM_Cmd_Reset(void);
610 //============================================================================
612 void PRVM_Init (void);
615 void MVM_ExecuteProgram (func_t fnum, const char *errormessage);
616 void CLVM_ExecuteProgram (func_t fnum, const char *errormessage);
617 void SVVM_ExecuteProgram (func_t fnum, const char *errormessage);
619 #define MVM_ExecuteProgram SVVM_ExecuteProgram
620 #define CLVM_ExecuteProgram SVVM_ExecuteProgram
621 void SVVM_ExecuteProgram (func_t fnum, const char *errormessage);
623 #define PRVM_ExecuteProgram prog->ExecuteProgram
625 #define PRVM_Alloc(buffersize) _PRVM_Alloc(buffersize, __FILE__, __LINE__)
626 #define PRVM_Free(buffer) _PRVM_Free(buffer, __FILE__, __LINE__)
627 #define PRVM_FreeAll() _PRVM_FreeAll(__FILE__, __LINE__)
628 void *_PRVM_Alloc (size_t buffersize, const char *filename, int fileline);
629 void _PRVM_Free (void *buffer, const char *filename, int fileline);
630 void _PRVM_FreeAll (const char *filename, int fileline);
632 void PRVM_Profile (int maxfunctions, double mintime, int sortby);
633 void PRVM_Profile_f (void);
634 void PRVM_ChildProfile_f (void);
635 void PRVM_CallProfile_f (void);
636 void PRVM_PrintFunction_f (void);
638 void PRVM_PrintState(void);
639 void PRVM_CrashAll (void);
640 void PRVM_Crash (void);
641 void PRVM_ShortStackTrace(char *buf, size_t bufsize);
642 const char *PRVM_AllocationOrigin(void);
644 ddef_t *PRVM_ED_FindField(const char *name);
645 ddef_t *PRVM_ED_FindGlobal(const char *name);
646 mfunction_t *PRVM_ED_FindFunction(const char *name);
648 int PRVM_ED_FindFieldOffset(const char *name);
649 int PRVM_ED_FindGlobalOffset(const char *name);
650 func_t PRVM_ED_FindFunctionOffset(const char *name);
651 #define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
652 #define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
654 void PRVM_MEM_IncreaseEdicts(void);
656 qboolean PRVM_ED_CanAlloc(prvm_edict_t *e);
657 prvm_edict_t *PRVM_ED_Alloc (void);
658 void PRVM_ED_Free (prvm_edict_t *ed);
659 void PRVM_ED_ClearEdict (prvm_edict_t *e);
661 void PRVM_PrintFunctionStatements (const char *name);
662 void PRVM_ED_Print(prvm_edict_t *ed, const char *wildcard_fieldname);
663 void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed);
664 const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent);
666 void PRVM_ED_WriteGlobals (qfile_t *f);
667 void PRVM_ED_ParseGlobals (const char *data);
669 void PRVM_ED_LoadFromFile (const char *data);
671 unsigned int PRVM_EDICT_NUM_ERROR(unsigned int n, const char *filename, int fileline);
672 #define PRVM_EDICT(n) (((unsigned)(n) < (unsigned int)prog->max_edicts) ? (unsigned int)(n) : PRVM_EDICT_NUM_ERROR((unsigned int)(n), __FILE__, __LINE__))
673 #define PRVM_EDICT_NUM(n) (prog->edicts + PRVM_EDICT(n))
675 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
676 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
677 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
679 #define PRVM_NEXT_EDICT(e) ((e) + 1)
681 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
682 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
683 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
684 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
686 //============================================================================
688 #define PRVM_G_FLOAT(o) (prog->globals.generic[o])
689 #define PRVM_G_INT(o) (*(int *)&prog->globals.generic[o])
690 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&prog->globals.generic[o]))
691 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
692 #define PRVM_G_VECTOR(o) (&prog->globals.generic[o])
693 #define PRVM_G_STRING(o) (PRVM_GetString(*(string_t *)&prog->globals.generic[o]))
694 //#define PRVM_G_FUNCTION(o) (*(func_t *)&prog->globals.generic[o])
696 // FIXME: make these go away?
697 #define PRVM_E_FLOAT(e,o) (((float*)e->fields.vp)[o])
698 #define PRVM_E_INT(e,o) (((int*)e->fields.vp)[o])
699 //#define PRVM_E_VECTOR(e,o) (&((float*)e->fields.vp)[o])
700 #define PRVM_E_STRING(e,o) (PRVM_GetString(*(string_t *)&((float*)e->fields.vp)[o]))
702 extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to
703 // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything
705 void PRVM_Init_Exec(void);
707 void PRVM_ED_PrintEdicts_f (void);
708 void PRVM_ED_PrintNum (int ent, const char *wildcard_fieldname);
710 const char *PRVM_GetString(int num);
711 int PRVM_SetEngineString(const char *s);
712 const char *PRVM_ChangeEngineString(int i, const char *s);
713 int PRVM_SetTempString(const char *s);
714 int PRVM_AllocString(size_t bufferlength, char **pointer);
715 void PRVM_FreeString(int num);
717 //============================================================================
719 // used as replacement for a prog stack
720 //#define PRVM_DEBUGPRSTACK
722 #ifdef PRVM_DEBUGPRSTACK
723 #define PRVM_Begin if(prog != 0) Con_Printf("prog not 0(prog = %i) in file: %s line: %i!\n", PRVM_GetProgNr(), __FILE__, __LINE__)
724 #define PRVM_End prog = 0
727 #define PRVM_End prog = 0
730 //#define PRVM_SAFENAME
731 #ifndef PRVM_SAFENAME
732 # define PRVM_NAME (prog->name)
734 # define PRVM_NAME (prog->name ? prog->name : "Unknown prog name")
737 // helper macro to make function pointer calls easier
738 #define PRVM_GCALL(func) if(prog->func) prog->func
740 #define PRVM_ERROR prog->error_cmd
742 // other prog handling functions
743 qboolean PRVM_SetProgFromString(const char *str);
744 void PRVM_SetProg(int prognr);
748 Call InitProg with the num
749 Set up the fields marked with [INIT] in the prog struct
750 Load a program with LoadProgs
752 void PRVM_InitProg(int prognr);
753 // LoadProgs expects to be called right after InitProg
754 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);
755 void PRVM_ResetProg(void);
757 qboolean PRVM_ProgLoaded(int prognr);
759 int PRVM_GetProgNr(void);
761 void VM_Warning(const char *fmt, ...) DP_FUNC_PRINTF(1);
763 // TODO: fill in the params
764 //void PRVM_Create();
766 void VM_GenerateFrameGroupBlend(framegroupblend_t *framegroupblend, const prvm_edict_t *ed);
767 void VM_FrameBlendFromFrameGroupBlend(frameblend_t *frameblend, const framegroupblend_t *framegroupblend, const dp_model_t *model);
768 void VM_UpdateEdictSkeleton(prvm_edict_t *ed, const dp_model_t *edmodel, const frameblend_t *frameblend);
769 void VM_RemoveEdictSkeleton(prvm_edict_t *ed);