]> git.xonotic.org Git - xonotic/darkplaces.git/blob - pr_comp.h
Merge PR 'Make particles solid squares when cl_particles_quake is set to 2'
[xonotic/darkplaces.git] / pr_comp.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 // this file is shared by quake and qcc
22
23 #ifndef PR_COMP_H
24 #define PR_COMP_H
25
26 typedef unsigned int    func_t;
27 typedef int     string_t;
28
29 typedef enum etype_e {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t;
30
31
32 #define OFS_NULL                0
33 #define OFS_RETURN              1
34 #define OFS_PARM0               4               // leave 3 ofs for each parm to hold vectors
35 #define OFS_PARM1               7
36 #define OFS_PARM2               10
37 #define OFS_PARM3               13
38 #define OFS_PARM4               16
39 #define OFS_PARM5               19
40 #define OFS_PARM6               22
41 #define OFS_PARM7               25
42 #define RESERVED_OFS    28
43
44
45 typedef enum opcode_e
46 {
47         OP_DONE,
48         OP_MUL_F,
49         OP_MUL_V,
50         OP_MUL_FV,
51         OP_MUL_VF,
52         OP_DIV_F,
53         OP_ADD_F,
54         OP_ADD_V,
55         OP_SUB_F,
56         OP_SUB_V,
57
58         OP_EQ_F,
59         OP_EQ_V,
60         OP_EQ_S,
61         OP_EQ_E,
62         OP_EQ_FNC,
63
64         OP_NE_F,
65         OP_NE_V,
66         OP_NE_S,
67         OP_NE_E,
68         OP_NE_FNC,
69
70         OP_LE,
71         OP_GE,
72         OP_LT,
73         OP_GT,
74
75         OP_LOAD_F,
76         OP_LOAD_V,
77         OP_LOAD_S,
78         OP_LOAD_ENT,
79         OP_LOAD_FLD,
80         OP_LOAD_FNC,
81
82         OP_ADDRESS,
83
84         OP_STORE_F,
85         OP_STORE_V,
86         OP_STORE_S,
87         OP_STORE_ENT,
88         OP_STORE_FLD,
89         OP_STORE_FNC,
90
91         OP_STOREP_F,
92         OP_STOREP_V,
93         OP_STOREP_S,
94         OP_STOREP_ENT,
95         OP_STOREP_FLD,
96         OP_STOREP_FNC,
97
98         OP_RETURN,
99         OP_NOT_F,
100         OP_NOT_V,
101         OP_NOT_S,
102         OP_NOT_ENT,
103         OP_NOT_FNC,
104         OP_IF,
105         OP_IFNOT,
106         OP_CALL0,
107         OP_CALL1,
108         OP_CALL2,
109         OP_CALL3,
110         OP_CALL4,
111         OP_CALL5,
112         OP_CALL6,
113         OP_CALL7,
114         OP_CALL8,
115         OP_STATE,
116         OP_GOTO,
117         OP_AND,
118         OP_OR,
119
120         OP_BITAND,
121         OP_BITOR,
122
123         // TODO: actually support Hexen 2?
124         
125         OP_MULSTORE_F,  //66 redundant, for h2 compat
126         OP_MULSTORE_VF, //67 redundant, for h2 compat
127         OP_MULSTOREP_F, //68
128         OP_MULSTOREP_VF,//69
129
130         OP_DIVSTORE_F,  //70 redundant, for h2 compat
131         OP_DIVSTOREP_F, //71
132
133         OP_ADDSTORE_F,  //72 redundant, for h2 compat
134         OP_ADDSTORE_V,  //73 redundant, for h2 compat
135         OP_ADDSTOREP_F, //74
136         OP_ADDSTOREP_V, //75
137
138         OP_SUBSTORE_F,  //76 redundant, for h2 compat
139         OP_SUBSTORE_V,  //77 redundant, for h2 compat
140         OP_SUBSTOREP_F, //78
141         OP_SUBSTOREP_V, //79
142
143         OP_FETCH_GBL_F, //80 has built-in bounds check
144         OP_FETCH_GBL_V, //81 has built-in bounds check
145         OP_FETCH_GBL_S, //82 has built-in bounds check
146         OP_FETCH_GBL_E, //83 has built-in bounds check
147         OP_FETCH_GBL_FNC,//84 has built-in bounds check
148
149         OP_CSTATE,              //85
150         OP_CWSTATE,             //86
151
152         OP_THINKTIME,   //87 shortcut for OPA.nextthink=time+OPB
153
154         OP_BITSETSTORE_F,       //88 redundant, for h2 compat
155         OP_BITSETSTOREP_F,      //89
156         OP_BITCLRSTORE_F,       //90
157         OP_BITCLRSTOREP_F,      //91
158
159         OP_RAND0,               //92    OPC = random()
160         OP_RAND1,               //93    OPC = random()*OPA
161         OP_RAND2,               //94    OPC = random()*(OPB-OPA)+OPA
162         OP_RANDV0,              //95    //3d/box versions of the above.
163         OP_RANDV1,              //96
164         OP_RANDV2,              //97
165
166         OP_SWITCH_F,    //98    switchref=OPA; PC += OPB   --- the jump allows the jump table (such as it is) to be inserted after the block.
167         OP_SWITCH_V,    //99
168         OP_SWITCH_S,    //100
169         OP_SWITCH_E,    //101
170         OP_SWITCH_FNC,  //102
171
172         OP_CASE,                //103   if (OPA===switchref) PC += OPB
173         OP_CASERANGE,   //104   if (OPA<=switchref&&switchref<=OPB) PC += OPC
174
175         //hexen2 calling convention (-TH2 requires us to remap OP_CALLX to these on load, -TFTE just uses these directly.)
176         OP_CALL1H,      //OFS_PARM0=OPB
177         OP_CALL2H,      //OFS_PARM0,1=OPB,OPC
178         OP_CALL3H,      //no extra args
179         OP_CALL4H,
180         OP_CALL5H,
181         OP_CALL6H,
182         OP_CALL7H,
183         OP_CALL8H,
184
185         OP_STORE_I,
186         OP_STORE_IF,
187         OP_STORE_FI,
188
189         OP_ADD_I,
190         OP_ADD_FI,
191         OP_ADD_IF,
192
193         OP_SUB_I,
194         OP_SUB_FI,
195         OP_SUB_IF,
196
197         OP_CONV_IF,
198         OP_CONV_FI,
199         
200         OP_LOADP_IF,
201         OP_LOADP_FI,
202
203         OP_LOAD_I,
204
205         OP_STOREP_I,
206         OP_STOREP_IF,
207         OP_STOREP_FI,
208
209         OP_BITAND_I,
210         OP_BITOR_I,
211
212         OP_MUL_I,
213         OP_DIV_I,
214         OP_EQ_I,
215         OP_NE_I,
216
217         OP_IFNOT_S,
218
219         OP_IF_S,
220
221         OP_NOT_I,
222
223         OP_DIV_VF,
224
225         OP_BITXOR_I,
226         OP_RSHIFT_I,
227         OP_LSHIFT_I,
228
229         OP_GLOBALADDRESS,
230         OP_ADD_PIW,
231
232         OP_LOADA_F,
233         OP_LOADA_V,     
234         OP_LOADA_S,
235         OP_LOADA_ENT,
236         OP_LOADA_FLD,
237         OP_LOADA_FNC,
238         OP_LOADA_I,
239
240         OP_STORE_P,
241         OP_LOAD_P,
242
243         OP_LOADP_F,
244         OP_LOADP_V,     
245         OP_LOADP_S,
246         OP_LOADP_ENT,
247         OP_LOADP_FLD,
248         OP_LOADP_FNC,
249         OP_LOADP_I,
250
251         OP_LE_I,
252         OP_GE_I,
253         OP_LT_I,
254         OP_GT_I,
255         
256         OP_LE_IF,
257         OP_GE_IF,
258         OP_LT_IF,
259         OP_GT_IF,
260
261         OP_LE_FI,
262         OP_GE_FI,
263         OP_LT_FI,
264         OP_GT_FI,
265
266         OP_EQ_IF,
267         OP_EQ_FI,
268
269         OP_ADD_SF,
270         OP_SUB_S,
271         OP_STOREP_C,
272         OP_LOADP_C,
273
274         OP_MUL_IF,
275         OP_MUL_FI,
276         OP_MUL_VI,
277         OP_MUL_IV,
278         OP_DIV_IF,
279         OP_DIV_FI,
280         OP_BITAND_IF,
281         OP_BITOR_IF,
282         OP_BITAND_FI,
283         OP_BITOR_FI,
284         OP_AND_I,
285         OP_OR_I,
286         OP_AND_IF,
287         OP_OR_IF,
288         OP_AND_FI,
289         OP_OR_FI,
290         OP_NE_IF,
291         OP_NE_FI,
292
293         OP_GSTOREP_I,
294         OP_GSTOREP_F,
295         OP_GSTOREP_ENT,
296         OP_GSTOREP_FLD,
297         OP_GSTOREP_S,
298         OP_GSTOREP_FNC,         
299         OP_GSTOREP_V,
300         OP_GADDRESS,
301         OP_GLOAD_I,
302         OP_GLOAD_F,
303         OP_GLOAD_FLD,
304         OP_GLOAD_ENT,
305         OP_GLOAD_S,
306         OP_GLOAD_FNC,
307         OP_BOUNDCHECK,
308
309         OP_UNUSED,      //used to be OP_STOREP_P, which is now emulated with OP_STOREP_I, fteqcc nor fte generated it
310         OP_PUSH,        //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
311         OP_POP,         //pop those ones that were pushed (don't over do it). Needs assembler.
312         OP_SWITCH_I,
313
314         OP_GLOAD_V,
315
316         OP_IF_F,                //compares as an actual float, instead of treating -0 as positive.
317         OP_IFNOT_F,
318
319         OP_STOREF_V,    //3 elements...
320         OP_STOREF_F,    //1 fpu element...
321         OP_STOREF_S,    //1 string reference
322         OP_STOREF_I,    //1 non-string reference/int
323 }
324 opcode_t;
325
326 // Statements (16 bit format) - 8 bytes each
327 typedef struct statement16_s
328 {
329         uint16_t        op;
330         int16_t         a, b, c;
331 }
332 dstatement16_t;
333
334 // Statements (32 bit format) - 16 bytes each
335 typedef struct statement32_s
336 {
337         uint32_t        op;
338         int32_t         a, b, c;
339 }
340 dstatement32_t;
341
342 // Global and fielddefs (16 bit format) - 8 bytes each
343 typedef struct ddef16_s
344 {
345         uint16_t        type;           // if DEF_SAVEGLOBAL bit is set
346                                                         // the variable needs to be saved in savegames
347         uint16_t        ofs;
348         int32_t s_name;
349 }
350 ddef16_t, dfield16_t;
351
352 // Global and fielddefs (32 bit format) - 12 bytes each
353 typedef struct ddef32_s
354 {
355         uint32_t        type;           // if DEF_SAVEGLOBAL bit is set
356                                                         // the variable needs to be saved in savegames
357         uint32_t        ofs;
358         int32_t s_name;
359 }
360 ddef32_t, dfield32_t, mdef_t;
361
362 #define DEF_SAVEGLOBAL  (1<<15)
363
364 #define MAX_PARMS       8
365
366 // Functions - 36 bytes each
367 typedef struct dfunction_s
368 {
369         int32_t                 first_statement;        // negative numbers are builtins
370         int32_t         parm_start;                     // first local
371         int32_t         locals;                         // total ints of parms + locals
372
373         int32_t         profile;                // runtime
374
375         int32_t         s_name;                 // function name
376         int32_t         s_file;                 // source file defined in
377
378         int32_t                 numparms;               // number of args
379         uint8_t                 parm_size[MAX_PARMS]; // and size
380 }
381 dfunction_t;
382
383 typedef struct mfunction_s
384 {
385         int32_t                 first_statement;        // negative numbers are builtins
386         int32_t         parm_start;
387         int32_t         locals;                         // total ints of parms + locals
388
389         // these are doubles so that they can count up to 54bits or so rather than 32bit
390         double  tprofile;           // realtime in this function
391         double  tbprofile;          // realtime in builtins called by this function (NOTE: builtins also have a tprofile!)
392         double  profile;                // runtime
393         double  builtinsprofile; // cost of builtin functions called by this function
394         double  callcount; // times the functions has been called since the last profile call
395         double  totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
396         double  tprofile_total;         // runtime (NOTE: tbprofile_total makes no real sense, so not accumulating that)
397         double  profile_total;          // runtime
398         double  builtinsprofile_total; // cost of builtin functions called by this function
399         int     recursion;
400
401         int32_t         s_name;
402         int32_t         s_file;                 // source file defined in
403
404         int32_t         numparms;
405         uint8_t         parm_size[MAX_PARMS];
406 }
407 mfunction_t;
408
409 typedef struct mstatement_s
410 {
411         opcode_t        op;
412         int                     operand[3]; // always a global or -1 for unused
413         int                     jumpabsolute; // only used by IF, IFNOT, GOTO
414 }
415 mstatement_t;
416
417 // Header - 64 bytes
418 #define PROG_VERSION    6
419 typedef struct dprograms_s
420 {
421         int32_t version;                // Version (usually 6)
422         int32_t crc;                    // CRC-16 of header file. Last 2 bytes are skipped
423
424         // Sizes of and offsets to each section
425         uint32_t        ofs_statements;
426         uint32_t        numstatements;  // statement 0 is an error
427
428         uint32_t        ofs_globaldefs;
429         uint32_t        numglobaldefs;
430
431         uint32_t        ofs_fielddefs;
432         uint32_t        numfielddefs;
433
434         uint32_t        ofs_functions;
435         uint32_t        numfunctions;   // function 0 is an empty
436
437         uint32_t        ofs_strings;
438         uint32_t        numstrings;             // first string is a null string
439
440         uint32_t        ofs_globals;
441         uint32_t        numglobals;
442
443         uint32_t        entityfields;
444 }
445 dprograms_t;
446
447 typedef struct dprograms_v7_s
448 {       //extended header written by fteqcc.
449         dprograms_t     v6;     //for easier casting.
450
451         //debug / version 7 extensions
452         uint32_t        ofsfiles;                       //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip.
453         uint32_t        ofslinenums;            //ignored. alternative to external .lno files.
454         uint32_t        ofsbodylessfuncs;       //unsupported. function names imported from other modules. must be 0.
455         uint32_t        numbodylessfuncs;       //unsupported. must be 0.
456
457         uint32_t        ofs_types;                      //unsupported+deprecated. rich type info. must be 0.
458         uint32_t        numtypes;                       //unsupported+deprecated. rich type info. must be 0.
459         uint32_t        blockscompressed;       //unsupported. per-block compression. must be 0.
460
461         int32_t         secondaryversion;       //if not known then its kkqwsv's v7, qfcc's v7, or uhexen2's v7, or something. abandon all hope when not recognised.
462 #define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24)))       //regular 16bit statements.
463 #define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24)))       //statements+globaldefs+fielddefs extended to 32bit.
464 }
465 dprograms_v7_t;
466
467 #endif
468