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