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 #ifndef PROGS_H 22 #define PROGS_H 23 24 #include "pr_comp.h" // defs shared with qcc 25 #include "progdefs.h" // generated by program cdefs 26 #include "common.h" 27 28 typedef union eval_s { 29 string_t string; 30 float _float; 31 float vector[3]; 32 func_t function; 33 int _int; 34 int edict; 35 } eval_t; 36 37 #define MAX_ENT_LEAFS 48 38 typedef struct edict_s { 39 qboolean free; 40 link_t area; // linked to a division node or leaf 41 42 int num_leafs; 43 int leafnums[MAX_ENT_LEAFS]; 44 45 entity_state_t baseline; 46 47 float freetime; // sv.time when the object was freed 48 entvars_t v; // C exported fields from progs 49 // other fields from progs come immediately after 50 } edict_t; 51 52 #define EDICT_FROM_AREA(l) container_of(l,edict_t,area) 53 54 //============================================================================ 55 56 extern dprograms_t *progs; 57 extern dfunction_t *pr_functions; 58 extern char *pr_strings; 59 extern int pr_strings_size; 60 extern dstatement_t *pr_statements; 61 extern globalvars_t *pr_global_struct; 62 extern float *pr_globals; // same as pr_global_struct 63 64 extern int pr_edict_size; // in bytes 65 66 //============================================================================ 67 68 void PR_Init(void); 69 70 void PR_ExecuteProgram(func_t fnum); 71 void PR_LoadProgs(void); 72 73 void PR_Profile_f(void); 74 75 edict_t *ED_Alloc(void); 76 void ED_Free(edict_t *ed); 77 78 // returns a copy of the string allocated from the server's string heap 79 80 void ED_Print(edict_t *ed); 81 void ED_Write(FILE *f, edict_t *ed); 82 const char *ED_ParseEdict(const char *data, edict_t *ent); 83 84 void ED_WriteGlobals(FILE *f); 85 void ED_ParseGlobals(const char *data); 86 87 void ED_LoadFromFile(const char *data); 88 89 //define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size)) 90 //define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size) 91 92 edict_t *EDICT_NUM(int n); 93 int NUM_FOR_EDICT(const edict_t *e); 94 95 #define NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size)) 96 97 #define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts) 98 #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e)) 99 100 //============================================================================ 101 102 #define G_FLOAT(o) (pr_globals[o]) 103 #define G_INT(o) (*(int *)&pr_globals[o]) 104 #define G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o])) 105 #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) 106 #define G_VECTOR(o) (&pr_globals[o]) 107 #define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o])) 108 #define G_FUNCTION(o) (*(func_t *)&pr_globals[o]) 109 110 #define E_FLOAT(e,o) (((float*)&e->v)[o]) 111 #define E_INT(e,o) (*(int *)&((float*)&e->v)[o]) 112 #define E_VECTOR(e,o) (&((float*)&e->v)[o]) 113 #define E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)&e->v)[o])) 114 115 typedef void (*builtin_t) (void); 116 extern builtin_t *pr_builtins; 117 extern int pr_numbuiltins; 118 119 extern int pr_argc; 120 121 extern qboolean pr_trace; 122 extern dfunction_t *pr_xfunction; 123 extern int pr_xstatement; 124 125 #ifdef NQ_HACK 126 extern unsigned short pr_crc; 127 #endif 128 #if defined(QW_HACK) && defined(SERVERONLY) 129 extern func_t SpectatorConnect; 130 extern func_t SpectatorThink; 131 extern func_t SpectatorDisconnect; 132 #endif 133 134 void PR_RunError(const char *error, ...); 135 136 void ED_PrintEdicts(void); 137 void ED_PrintNum(int ent); 138 139 eval_t *GetEdictFieldValue(edict_t *ed, const char *field); 140 141 /* 142 * PR Strings stuff 143 */ 144 void PR_InitStringTable(void); 145 const char *PR_GetString(int num); 146 int PR_SetString(const char *s); 147 148 /* 149 * Somehow, I don't think this should be exposed - but better to have it here 150 * than have hidden exports between .c files. 151 */ 152 void PF_changeyaw(void); 153 154 #endif /* PROGS_H */ 155