]> icculus.org git repositories - btb/d2x.git/blob - main/mglobal.c
add anisotropic texture filtering suport (d1x r1.33, r1.32, r1.23, r1.32)
[btb/d2x.git] / main / mglobal.c
1 /* $Id: mglobal.c,v 1.4 2003-10-10 09:36:35 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Global variables for main directory
18  *
19  * Old Log:
20  * Revision 1.1  1995/12/05  16:03:10  allender
21  * Initial revision
22  *
23  * Revision 1.3  1995/10/10  11:49:41  allender
24  * removed malloc of static data now in ai module
25  *
26  * Revision 1.2  1995/07/12  12:48:52  allender
27  * malloc out edge_list global here, not static in automap.c
28  *
29  * Revision 1.1  1995/05/16  15:27:40  allender
30  * Initial revision
31  *
32  * Revision 2.2  1995/03/14  18:24:37  john
33  * Force Destination Saturn to use CD-ROM drive.
34  *
35  * Revision 2.1  1995/03/06  16:47:23  mike
36  * destination saturn
37  *
38  * Revision 2.0  1995/02/27  11:30:00  john
39  * New version 2.0, which has no anonymous unions, builds with
40  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
41  *
42  * Revision 1.43  1995/01/19  17:00:53  john
43  * Made save game work between levels.
44  *
45  * Revision 1.42  1994/12/05  14:23:53  adam
46  * changed default detail to max, not custom
47  *
48  * Revision 1.41  1994/11/19  15:15:07  mike
49  * remove unused code and data
50  *
51  * Revision 1.40  1994/11/03  10:13:19  yuan
52  * Added #include "game.h"
53  *
54  * Revision 1.39  1994/11/03  10:09:59  matt
55  * Properly initialize detail & difficulty levels
56  *
57  * Revision 1.38  1994/10/30  14:11:21  mike
58  * rip out local segments stuff.
59  *
60  * Revision 1.37  1994/10/26  15:21:30  mike
61  * detail level.
62  *
63  * Revision 1.36  1994/09/22  10:46:12  mike
64  * Add difficulty levels.
65  *
66  * Revision 1.35  1994/09/13  11:19:11  mike
67  * Add Next_missile_fire_time.
68  *
69  * Revision 1.34  1994/08/31  19:25:34  mike
70  * GameTime and laser-firing limiting stuff added.
71  *
72  * Revision 1.33  1994/08/11  18:58:53  mike
73  * Add Side_to_verts_int.
74  *
75  * Revision 1.32  1994/07/21  19:01:38  mike
76  * Add Lsegment.
77  *
78  * Revision 1.31  1994/07/21  13:11:24  matt
79  * Ripped out remants of old demo system, and added demo only system that
80  * disables object movement and game options from menu.
81  *
82  * Revision 1.30  1994/06/17  18:06:48  matt
83  * Made password be treated as lowercase, since cmdline parsing converts
84  * everything to lowercase.
85  *
86  * Revision 1.29  1994/03/15  16:33:04  yuan
87  * Cleaned up bm-loading code.
88  * (Fixed structures too)
89  *
90  * Revision 1.28  1994/02/17  11:32:45  matt
91  * Changes in object system
92  *
93  * Revision 1.27  1994/02/16  17:08:43  matt
94  * Added needed include of 3d.h
95  *
96  * Revision 1.26  1994/02/16  13:47:58  mike
97  * fix bugs so editor can compile out.
98  *
99  * Revision 1.25  1994/02/11  21:52:13  matt
100  * Made password protection selectable by #define (and thus INFERNO.INI)
101  *
102  * Revision 1.24  1994/02/10  15:35:56  matt
103  * Various changes to make editor compile out.
104  *
105  * Revision 1.23  1994/02/02  12:34:29  mike
106  * take out BATS encryption.
107  *
108  * Revision 1.22  1994/01/21  16:08:11  matt
109  * Added FrameCount variable
110  *
111  * Revision 1.21  1994/01/06  17:13:10  john
112  * Added Video clip functionality
113  *
114  * Revision 1.20  1993/12/08  17:45:08  matt
115  * Changed password again
116  *
117  * Revision 1.19  1993/12/08  17:41:05  matt
118  * Changed password
119  *
120  * Revision 1.18  1993/12/08  10:55:10  mike
121  * Add free_obj_list
122  *
123  * Revision 1.17  1993/12/07  13:46:38  john
124  * Added Explosion bitmap array
125  *
126  * Revision 1.16  1993/12/06  18:40:35  matt
127  * Changed object loading & handling
128  *
129  * Revision 1.15  1993/12/05  22:47:48  matt
130  * Reworked include files in an attempt to cut down on build times
131  *
132  * Revision 1.14  1993/12/01  11:44:11  matt
133  * Chagned Frfract to FrameTime
134  *
135  * Revision 1.13  1993/12/01  00:27:11  yuan
136  * Implemented new bitmap structure system...
137  * overall bitmap scheme still needs some work.
138  *
139  * Revision 1.12  1993/11/19  17:21:59  matt
140  * Changed the bitmap number of object class UNICLASS
141  * Removed static initialization for objects
142  *
143  * Revision 1.11  1993/11/18  13:51:47  mike
144  * Add Classes, Class_views, Objects
145  *
146  * Revision 1.10  1993/11/04  18:52:36  matt
147  * Made Vertices[] and Segment_points[] use same constant for size, since
148  * they must be the same size anyway
149  *
150  * Revision 1.9  1993/11/04  14:01:06  matt
151  * Mucked with include files
152  *
153  * Revision 1.8  1993/10/26  13:58:42  mike
154  * Add password protection.
155  *
156  * Revision 1.7  1993/10/14  18:05:50  mike
157  * Change Side_to_verts to use MAX_SIDES_PER_SEGMENT in place of CONNECTIVITY
158  *
159  * Revision 1.6  1993/10/12  13:57:19  john
160  * added texture[]
161  *
162  * Revision 1.5  1993/10/12  09:58:15  mike
163  * Move Side_to_verts here from eglobal.c, since it is needed in the game.
164  *
165  * Revision 1.4  1993/10/09  15:52:30  mike
166  * Move test_pos, test_orient here from render.c.
167  *
168  * Revision 1.3  1993/10/02  18:15:45  mike
169  * Killed include of segment.h, which gets included by inferno.h.
170  *
171  * Revision 1.2  1993/09/23  17:54:24  mike
172  * Add Segment_points
173  *
174  * Revision 1.1  1993/09/23  15:01:50  mike
175  * Initial revision
176  *
177  *
178  */
179
180 #ifdef HAVE_CONFIG_H
181 #include <conf.h>
182 #endif
183
184 #ifdef RCS
185 static char rcsid[] = "$Id: mglobal.c,v 1.4 2003-10-10 09:36:35 btb Exp $";
186 #endif
187
188 #include "fix.h"
189 #include "vecmat.h"
190 #include "inferno.h"
191 #include "segment.h"
192 #include "object.h"
193 #include "bm.h"
194 #include "3d.h"
195 #include "game.h"
196
197
198 // Global array of vertices, common to one mine.
199 vms_vector Vertices[MAX_VERTICES];
200 g3s_point Segment_points[MAX_VERTICES];
201
202 fix FrameTime = 0x1000; // Time since last frame, in seconds
203 fix GameTime = 0;                       //      Time in game, in seconds
204
205 //How many frames we've rendered
206 int FrameCount = 0;
207
208 //      This is the global mine which create_new_mine returns.
209 segment Segments[MAX_SEGMENTS];
210 segment2        Segment2s[MAX_SEGMENTS];
211 //lsegment      Lsegments[MAX_SEGMENTS];
212
213 // Number of vertices in current mine (ie, Vertices, pointed to by Vp)
214 int             Num_vertices = 0;
215 int             Num_segments = 0;
216
217 int             Highest_vertex_index=0;
218 int             Highest_segment_index=0;
219
220 //      Translate table to get opposite side of a face on a segment.
221 char    Side_opposite[MAX_SIDES_PER_SEGMENT] = {WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK};
222
223 #define TOLOWER(c) ((((c)>='A') && ((c)<='Z'))?((c)+('a'-'A')):(c))
224
225 #ifdef PASSWORD
226 #define encrypt(a,b,c,d)        a ^ TOLOWER((((int) PASSWORD)>>24)&255), \
227                                                                         b ^ TOLOWER((((int) PASSWORD)>>16)&255), \
228                                                                         c ^ TOLOWER((((int) PASSWORD)>>8)&255), \
229                                                                         d ^ TOLOWER((((int) PASSWORD))&255)
230 #else
231 #define encrypt(a,b,c,d) a,b,c,d
232 #endif
233
234 sbyte Side_to_verts[MAX_SIDES_PER_SEGMENT][4] = {
235                         { encrypt(7,6,2,3) },                   // left
236                         { encrypt(0,4,7,3) },                   // top
237                         { encrypt(0,1,5,4) },                   // right
238                         { encrypt(2,6,5,1) },                   // bottom
239                         { encrypt(4,5,6,7) },                   // back
240                         { encrypt(3,2,1,0) },                   // front
241 };              
242
243 //      Note, this MUST be the same as Side_to_verts, it is an int for speed reasons.
244 int Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4] = {
245                         { encrypt(7,6,2,3) },                   // left
246                         { encrypt(0,4,7,3) },                   // top
247                         { encrypt(0,1,5,4) },                   // right
248                         { encrypt(2,6,5,1) },                   // bottom
249                         { encrypt(4,5,6,7) },                   // back
250                         { encrypt(3,2,1,0) },                   // front
251 };              
252
253 // Texture map stuff
254
255 int NumTextures = 0;
256 bitmap_index Textures[MAX_TEXTURES];            // All textures.
257
258 fix     Next_laser_fire_time;                   //      Time at which player can next fire his selected laser.
259 fix     Next_missile_fire_time;                 //      Time at which player can next fire his selected missile.
260 //--unused-- fix        Laser_delay_time = F1_0/6;              //      Delay between laser fires.
261
262 #if defined(MACINTOSH) && defined(APPLE_DEMO)
263 #define DEFAULT_DIFFICULTY              0               // trainee for apple demo
264 #else
265 #define DEFAULT_DIFFICULTY              1
266 #endif
267
268 int     Difficulty_level=DEFAULT_DIFFICULTY;    //      Difficulty level in 0..NDL-1, 0 = easiest, NDL-1 = hardest
269 int     Detail_level=NUM_DETAIL_LEVELS-2;               //      Detail level in 0..NUM_DETAIL_LEVELS-1, 0 = boringest, NUM_DETAIL_LEVELS = coolest
270