]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - progs.h
494
[xonotic/darkplaces.git] / progs.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 #ifndef PROGS_H
22 #define PROGS_H
23 #include "pr_comp.h"                    // defs shared with qcc
24
25 typedef struct link_s
26 {
27         int entitynumber;
28         struct link_s   *prev, *next;
29 } link_t;
30
31 #define ENTITYGRIDAREAS 16
32 #define MAX_ENTITYCLUSTERS 16
33
34 typedef struct edict_engineprivate_s
35 {
36         // true if this edict is unused
37         qboolean free;
38         // sv.time when the object was freed (to prevent early reuse which could
39         // mess up client interpolation or obscure severe QuakeC bugs)
40         float freetime;
41         // initially false to prevent projectiles from moving on their first frame
42         // (even if they were spawned by an synchronous client think)
43         qboolean move;
44
45         // cached cluster links for quick stationary object visibility checking
46         vec3_t cullmins, cullmaxs;
47         int pvs_numclusters;
48         int pvs_clusterlist[MAX_ENTITYCLUSTERS];
49
50         // physics grid areas this edict is linked into
51         link_t areagrid[ENTITYGRIDAREAS];
52         // since the areagrid can have multiple references to one entity,
53         // we should avoid extensive checking on entities already encountered
54         int areagridmarknumber;
55
56         // PROTOCOL_QUAKE, PROTOCOL_QUAKEDP, PROTOCOL_NEHAHRAMOVIE, PROTOCOL_QUAKEWORLD
57         // baseline values
58         entity_state_t baseline;
59
60         // LordHavoc: gross hack to make floating items still work
61         int suspendedinairflag;
62         // used by PushMove to keep track of where objects were before they were
63         // moved, in case they need to be moved back
64         vec3_t moved_from;
65         vec3_t moved_fromangles;
66 }
67 edict_engineprivate_t;
68
69 // LordHavoc: in an effort to eliminate time wasted on GetEdictFieldValue...  see pr_edict.c for the functions which use these.
70 extern int eval_gravity;
71 extern int eval_button3;
72 extern int eval_button4;
73 extern int eval_button5;
74 extern int eval_button6;
75 extern int eval_button7;
76 extern int eval_button8;
77 extern int eval_button9;
78 extern int eval_button10;
79 extern int eval_button11;
80 extern int eval_button12;
81 extern int eval_button13;
82 extern int eval_button14;
83 extern int eval_button15;
84 extern int eval_button16;
85 extern int eval_buttonuse;
86 extern int eval_buttonchat;
87 extern int eval_glow_size;
88 extern int eval_glow_trail;
89 extern int eval_glow_color;
90 extern int eval_items2;
91 extern int eval_scale;
92 extern int eval_alpha;
93 extern int eval_renderamt; // HalfLife support
94 extern int eval_rendermode; // HalfLife support
95 extern int eval_fullbright;
96 extern int eval_ammo_shells1;
97 extern int eval_ammo_nails1;
98 extern int eval_ammo_lava_nails;
99 extern int eval_ammo_rockets1;
100 extern int eval_ammo_multi_rockets;
101 extern int eval_ammo_cells1;
102 extern int eval_ammo_plasma;
103 extern int eval_idealpitch;
104 extern int eval_pitch_speed;
105 extern int eval_viewmodelforclient;
106 extern int eval_nodrawtoclient;
107 extern int eval_exteriormodeltoclient;
108 extern int eval_drawonlytoclient;
109 extern int eval_ping;
110 extern int eval_movement;
111 extern int eval_pmodel;
112 extern int eval_punchvector;
113 extern int eval_viewzoom;
114 extern int eval_clientcolors;
115 extern int eval_tag_entity;
116 extern int eval_tag_index;
117 extern int eval_light_lev;
118 extern int eval_color;
119 extern int eval_style;
120 extern int eval_pflags;
121 extern int eval_cursor_active;
122 extern int eval_cursor_screen;
123 extern int eval_cursor_trace_start;
124 extern int eval_cursor_trace_endpos;
125 extern int eval_cursor_trace_ent;
126 extern int eval_colormod;
127 extern int eval_playermodel;
128 extern int eval_playerskin;
129 extern int eval_SendEntity;
130 extern int eval_Version;
131 extern int eval_customizeentityforclient;
132 extern int eval_dphitcontentsmask;
133
134 extern int gval_trace_dpstartcontents;
135 extern int gval_trace_dphitcontents;
136 extern int gval_trace_dphitq3surfaceflags;
137 extern int gval_trace_dphittexturename;
138
139
140
141 extern mfunction_t *SV_PlayerPhysicsQC;
142 extern mfunction_t *EndFrameQC;
143 //KrimZon - SERVER COMMANDS IN QUAKEC
144 extern mfunction_t *SV_ParseClientCommandQC;
145
146 #endif
147
148
149
150
151
152
153 //////////////////////////////////
154 #if 0
155
156 #include "pr_comp.h"                    // defs shared with qcc
157 #include "progdefs.h"                   // generated by program cdefs
158
159 typedef union eval_s
160 {
161         string_t                string;
162         float                   _float;
163         float                   vector[3];
164         func_t                  function;
165         int                             ivector[3];
166         int                             _int;
167         int                             edict;
168 } prvm_eval_t;
169
170 typedef struct link_s
171 {
172         int entitynumber;
173         struct link_s   *prev, *next;
174 } link_t;
175
176 #define ENTITYGRIDAREAS 16
177
178 typedef struct edict_engineprivate_s
179 {
180         // true if this edict is unused
181         qboolean free;
182         // sv.time when the object was freed (to prevent early reuse which could
183         // mess up client interpolation or obscure severe QuakeC bugs)
184         float freetime;
185
186         // cached cluster links for quick stationary object visibility checking
187         vec3_t cullmins, cullmaxs;
188         int pvs_numclusters;
189         int pvs_clusterlist[MAX_ENTITYCLUSTERS];
190
191         // physics grid areas this edict is linked into
192         link_t areagrid[ENTITYGRIDAREAS];
193         // since the areagrid can have multiple references to one entity,
194         // we should avoid extensive checking on entities already encountered
195         int areagridmarknumber;
196
197         // PROTOCOL_QUAKE, PROTOCOL_QUAKEDP, PROTOCOL_NEHAHRAMOVIE, PROTOCOL_QUAKEWORLD
198         // baseline values
199         entity_state_t baseline;
200
201         // LordHavoc: gross hack to make floating items still work
202         int suspendedinairflag;
203         // used by PushMove to keep track of where objects were before they were
204         // moved, in case they need to be moved back
205         vec3_t moved_from;
206         vec3_t moved_fromangles;
207 }
208 edict_engineprivate_t;
209
210 // the entire server entity structure
211 // NOTE: keep this small!  priv and v are dynamic but this struct is not!
212 typedef struct edict_s
213 {
214         // engine-private fields (stored in dynamically resized array)
215         edict_engineprivate_t *e;
216         // QuakeC fields (stored in dynamically resized array)
217         entvars_t *v;
218 }
219 prvm_edict_t;
220
221 // LordHavoc: in an effort to eliminate time wasted on GetEdictFieldValue...  see pr_edict.c for the functions which use these.
222 extern int eval_gravity;
223 extern int eval_button3;
224 extern int eval_button4;
225 extern int eval_button5;
226 extern int eval_button6;
227 extern int eval_button7;
228 extern int eval_button8;
229 extern int eval_buttonuse;
230 extern int eval_buttonchat;
231 extern int eval_glow_size;
232 extern int eval_glow_trail;
233 extern int eval_glow_color;
234 extern int eval_items2;
235 extern int eval_scale;
236 extern int eval_alpha;
237 extern int eval_renderamt; // HalfLife support
238 extern int eval_rendermode; // HalfLife support
239 extern int eval_fullbright;
240 extern int eval_ammo_shells1;
241 extern int eval_ammo_nails1;
242 extern int eval_ammo_lava_nails;
243 extern int eval_ammo_rockets1;
244 extern int eval_ammo_multi_rockets;
245 extern int eval_ammo_cells1;
246 extern int eval_ammo_plasma;
247 extern int eval_idealpitch;
248 extern int eval_pitch_speed;
249 extern int eval_viewmodelforclient;
250 extern int eval_nodrawtoclient;
251 extern int eval_exteriormodeltoclient;
252 extern int eval_drawonlytoclient;
253 extern int eval_ping;
254 extern int eval_movement;
255 extern int eval_pmodel;
256 extern int eval_punchvector;
257 extern int eval_viewzoom;
258 extern int eval_clientcolors;
259 extern int eval_tag_entity;
260 extern int eval_tag_index;
261 extern int eval_light_lev;
262 extern int eval_color;
263 extern int eval_style;
264 extern int eval_pflags;
265 extern int eval_cursor_active;
266 extern int eval_cursor_screen;
267 extern int eval_cursor_trace_start;
268 extern int eval_cursor_trace_endpos;
269 extern int eval_cursor_trace_ent;
270 extern int eval_colormod;
271 extern int eval_playermodel;
272 extern int eval_playerskin;
273
274 #define PRVM_GETEDICTFIELDVALUE(ed, fieldoffset) (fieldoffset ? (prvm_eval_t *)((unsigned char *)ed->v + fieldoffset) : NULL)
275
276 extern mfunction_t *SV_PlayerPhysicsQC;
277 extern mfunction_t *EndFrameQC;
278 //KrimZon - SERVER COMMANDS IN QUAKEC
279 extern mfunction_t *SV_ParseClientCommandQC;
280
281 //============================================================================
282
283 extern  dprograms_t             *progs;
284 extern  mfunction_t             *prog->functions;
285 extern  char                    *pr_strings;
286 extern  int                             pr_stringssize;
287 extern  ddef_t                  *pr_globaldefs;
288 extern  ddef_t                  *pr_fielddefs;
289 extern  dstatement_t    *pr_statements;
290 extern  globalvars_t    *pr_global_struct;
291 extern  float                   *pr_globals;                    // same as pr_global_struct
292
293 extern  int                             prog->edict_size;       // in bytes
294 extern  int                             pr_edictareasize; // LordHavoc: for bounds checking
295
296 extern  int                             pr_maxknownstrings;
297 extern  int                             pr_numknownstrings;
298 extern  const char              **pr_knownstrings;
299
300 //============================================================================
301
302 void PR_Init (void);
303 void PR_Shutdown (void);
304
305 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage);
306 void PR_LoadProgs (const char *progsname);
307
308 #define PR_Alloc(buffersize) _PR_Alloc(buffersize, __FILE__, __LINE__)
309 #define PR_Free(buffer) _PR_Free(buffer, __FILE__, __LINE__)
310 #define PR_FreeAll() _PR_FreeAll(__FILE__, __LINE__)
311 void *_PR_Alloc (size_t buffersize, const char *filename, int fileline);
312 void _PR_Free (void *buffer, const char *filename, int fileline);
313 void _PR_FreeAll (const char *filename, int fileline);
314
315 void PR_Profile_f (void);
316
317 void PR_PrintState(void);
318 void PR_Crash (void);
319
320 void SV_IncreaseEdicts(void);
321
322 prvm_edict_t *ED_Alloc (void);
323 void ED_Free (prvm_edict_t *ed);
324 void ED_ClearEdict (prvm_edict_t *e);
325
326 void ED_Print(prvm_edict_t *ed);
327 void ED_Write (qfile_t *f, prvm_edict_t *ed);
328 const char *ED_ParseEdict (const char *data, prvm_edict_t *ent);
329
330 void ED_WriteGlobals (qfile_t *f);
331 void ED_ParseGlobals (const char *data);
332
333 void ED_LoadFromFile (const char *data);
334
335 prvm_edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline);
336 #define PRVM_EDICT_NUM(n) (((n) >= 0 && (n) < prog->max_edicts) ? prog->edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
337 #define EDICT_NUM_UNSIGNED(n) (((n) < prog->max_edicts) ? prog->edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
338
339 //int NUM_FOR_EDICT_ERROR(prvm_edict_t *e);
340 #define PRVM_NUM_FOR_EDICT(e) ((int)((prvm_edict_t *)(e) - prog->edicts))
341 //int PRVM_NUM_FOR_EDICT(prvm_edict_t *e);
342
343 #define PRVM_NEXT_EDICT(e) ((e) + 1)
344
345 #define PRVM_EDICT_TO_PROG(e) (PRVM_NUM_FOR_EDICT(e))
346 //int PRVM_EDICT_TO_PROG(prvm_edict_t *e);
347 #define PRVM_PROG_TO_EDICT(n) (PRVM_EDICT_NUM(n))
348 //prvm_edict_t *PRVM_PROG_TO_EDICT(int n);
349
350 //============================================================================
351
352 #define PRVM_G_FLOAT(o) (pr_globals[o])
353 #define PRVM_G_INT(o) (*(int *)&pr_globals[o])
354 #define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&pr_globals[o]))
355 #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o))
356 #define PRVM_G_VECTOR(o) (&pr_globals[o])
357 #define PRVM_G_STRING(o) (PRVM_GetString(*(string_t *)&pr_globals[o]))
358 //#define       G_FUNCTION(o) (*(func_t *)&pr_globals[o])
359
360 // FIXME: make these go away?
361 #define E_FLOAT(e,o) (((float*)e->v)[o])
362 //#define       E_INT(e,o) (((int*)e->v)[o])
363 //#define       E_VECTOR(e,o) (&((float*)e->v)[o])
364 #define E_STRING(e,o) (PRVM_GetString(*(string_t *)&((float*)e->v)[o]))
365
366 extern  int             type_size[8];
367
368 typedef void (*builtin_t) (void);
369 extern  builtin_t *pr_builtins;
370 extern int pr_numbuiltins;
371
372 extern int              pr_argc;
373
374 extern  int                     pr_trace;
375 extern  mfunction_t     *pr_xfunction;
376 extern  int                     pr_xstatement;
377
378 extern  unsigned short          pr_crc;
379
380 void PR_Execute_ProgsLoaded(void);
381
382 void ED_PrintEdicts (void);
383 void ED_PrintNum (int ent);
384
385 const char *PRVM_GetString(int num);
386 int PR_SetQCString(const char *s);
387 int PRVM_SetEngineString(const char *s);
388 char *PR_AllocString(int bufferlength);
389 void PR_FreeString(char *s);
390
391 #endif
392