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