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.
23 #include "pr_comp.h" // defs shared with qcc
25 #define ENTITYGRIDAREAS 16
26 #define MAX_ENTITYCLUSTERS 16
28 typedef struct edict_engineprivate_s
30 // true if this edict is unused
32 // sv.time when the object was freed (to prevent early reuse which could
33 // mess up client interpolation or obscure severe QuakeC bugs)
35 // initially false to prevent projectiles from moving on their first frame
36 // (even if they were spawned by an synchronous client think)
39 // cached cluster links for quick stationary object visibility checking
40 vec3_t cullmins, cullmaxs;
42 int pvs_clusterlist[MAX_ENTITYCLUSTERS];
44 // physics grid areas this edict is linked into
45 link_t areagrid[ENTITYGRIDAREAS];
46 // since the areagrid can have multiple references to one entity,
47 // we should avoid extensive checking on entities already encountered
48 int areagridmarknumber;
49 // mins/maxs passed to World_LinkEdict
50 vec3_t areamins, areamaxs;
52 // PROTOCOL_QUAKE, PROTOCOL_QUAKEDP, PROTOCOL_NEHAHRAMOVIE, PROTOCOL_QUAKEWORLD
54 entity_state_t baseline;
56 // LordHavoc: gross hack to make floating items still work
57 int suspendedinairflag;
58 // used by PushMove to keep track of where objects were before they were
59 // moved, in case they need to be moved back
61 vec3_t moved_fromangles;
63 edict_engineprivate_t;
72 //////////////////////////////////
75 #include "pr_comp.h" // defs shared with qcc
76 #include "progdefs.h" // generated by program cdefs
92 struct link_s *prev, *next;
95 #define ENTITYGRIDAREAS 16
97 typedef struct edict_engineprivate_s
99 // true if this edict is unused
101 // sv.time when the object was freed (to prevent early reuse which could
102 // mess up client interpolation or obscure severe QuakeC bugs)
105 // cached cluster links for quick stationary object visibility checking
106 vec3_t cullmins, cullmaxs;
108 int pvs_clusterlist[MAX_ENTITYCLUSTERS];
110 // physics grid areas this edict is linked into
111 link_t areagrid[ENTITYGRIDAREAS];
112 // since the areagrid can have multiple references to one entity,
113 // we should avoid extensive checking on entities already encountered
114 int areagridmarknumber;
116 // PROTOCOL_QUAKE, PROTOCOL_QUAKEDP, PROTOCOL_NEHAHRAMOVIE, PROTOCOL_QUAKEWORLD
118 entity_state_t baseline;
120 // LordHavoc: gross hack to make floating items still work
121 int suspendedinairflag;
122 // used by PushMove to keep track of where objects were before they were
123 // moved, in case they need to be moved back
125 vec3_t moved_fromangles;
127 edict_engineprivate_t;
129 // the entire server entity structure
130 // NOTE: keep this small! priv and v are dynamic but this struct is not!
131 typedef struct edict_s
133 // engine-private fields (stored in dynamically resized array)
134 edict_engineprivate_t *e;
135 // QuakeC fields (stored in dynamically resized array)
140 #define PRVM_EDICTFIELDVALUE(ed, fieldoffset) (fieldoffset ? (prvm_eval_t *)((int *)ed->v + fieldoffset) : NULL)
142 //============================================================================
144 extern dprograms_t *progs;
145 extern mfunction_t *pr_functions;
146 extern char *pr_strings;
147 extern int pr_stringssize;
148 extern ddef_t *pr_globaldefs;
149 extern ddef_t *pr_fielddefs;
150 extern dstatement_t *pr_statements;
151 extern globalvars_t *pr_global_struct;
152 extern float *pr_globals; // same as pr_global_struct
154 extern int prog->edict_size; // in bytes
155 extern int pr_edictareasize; // LordHavoc: for bounds checking
157 extern int pr_maxknownstrings;
158 extern int pr_numknownstrings;
159 extern const char **pr_knownstrings;
161 //============================================================================
164 void PR_Shutdown (void);
166 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage);
167 void PR_LoadProgs (const char *progsname);
169 #define PR_Alloc(buffersize) _PR_Alloc(buffersize, __FILE__, __LINE__)
170 #define PR_Free(buffer) _PR_Free(buffer, __FILE__, __LINE__)
171 #define PR_FreeAll() _PR_FreeAll(__FILE__, __LINE__)
172 void *_PR_Alloc (size_t buffersize, const char *filename, int fileline);
173 void _PR_Free (void *buffer, const char *filename, int fileline);
174 void _PR_FreeAll (const char *filename, int fileline);
176 void PR_Profile_f (void);
178 void PR_PrintState(void);
179 void PR_Crash (void);
181 void SV_IncreaseEdicts(void);
183 prvm_edict_t *ED_Alloc (void);
184 void ED_Free (prvm_edict_t *ed);
185 void ED_ClearEdict (prvm_edict_t *e);
187 void ED_Print(prvm_edict_t *ed);
188 void ED_Write (qfile_t *f, prvm_edict_t *ed);
189 const char *ED_ParseEdict (const char *data, prvm_edict_t *ent);
191 void ED_WriteGlobals (qfile_t *f);
192 void ED_ParseGlobals (const char *data);
194 void ED_LoadFromFile (const char *data);
196 prvm_edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline);
197 #define PRVM_EDICT_NUM(n) (((n) >= 0 && (n) < prog->max_edicts) ? prog->edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
198 #define EDICT_NUM_UNSIGNED(n) (((n) < prog->max_edicts) ? prog->edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
200 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
201 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
202 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
204 #define PRVM_NEXT_EDICT(e) ((e) + 1)
206 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
207 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
208 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
209 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
211 //============================================================================
213 #define PRVM_G_FLOAT(o) (pr_globals[o])
214 #define PRVM_G_INT(o) (*(int *)&pr_globals[o])
215 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&pr_globals[o]))
216 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
217 #define PRVM_G_VECTOR(o) (&pr_globals[o])
218 #define PRVM_G_STRING(o) (PRVM_GetString(*(string_t *)&pr_globals[o]))
219 //#define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
221 // FIXME: make these go away?
222 #define E_FLOAT(e,o) (((float*)e->v)[o])
223 //#define E_INT(e,o) (((int*)e->v)[o])
224 //#define E_VECTOR(e,o) (&((float*)e->v)[o])
225 #define E_STRING(e,o) (PRVM_GetString(*(string_t *)&((float*)e->v)[o]))
227 extern int type_size[8];
229 typedef void (*builtin_t) (void);
230 extern builtin_t *pr_builtins;
231 extern int pr_numbuiltins;
236 extern mfunction_t *pr_xfunction;
237 extern int pr_xstatement;
239 extern unsigned short pr_crc;
241 void PR_Execute_ProgsLoaded(void);
243 void ED_PrintEdicts (void);
244 void ED_PrintNum (int ent);
246 const char *PRVM_GetString(int num);
247 int PR_SetQCString(const char *s);
248 int PRVM_SetEngineString(const char *s);
249 int PRVM_SetTempString(const char *s);
250 char *PR_AllocString(int bufferlength);
251 void PR_FreeString(char *s);