]> icculus.org git repositories - btb/d2x.git/blob - main/gamepal.c
remove all the redundant Polygon Acceleration stuff (include/pa_enabl.h)
[btb/d2x.git] / main / gamepal.c
1 /* $Id: gamepal.c,v 1.6 2005-07-30 01:50:17 chris 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  * Functions for loading palettes
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <string.h>
26 #include <stdlib.h>
27 #include <math.h>
28
29 #include "fix.h"
30 #include "vecmat.h"
31 #include "gr.h"
32 #include "3d.h"
33 #include "palette.h"
34 #include "rle.h"
35
36 #include "inferno.h"
37 #include "gamepal.h"
38 #include "mission.h"
39 #include "newmenu.h"
40 #include "texmerge.h"
41 #include "piggy.h"
42 #include "strutil.h"
43
44 extern void g3_remap_interp_colors();
45
46 char Current_level_palette[FILENAME_LEN];
47
48 extern int Color_0_31_0, HUD_color;
49
50 //give a filename a new extension
51 void change_filename_ext( char *dest, char *src, char *ext )
52 {
53         char *p;
54
55         strcpy (dest, src);
56
57         if (ext[0] == '.')
58                 ext++;
59
60         p = strchr(dest,'.');
61         if (!p) {
62                 p = dest + strlen(dest);
63                 *p = '.';
64         }
65
66         strcpy(p+1,ext);
67 }
68
69 //background for boxed messages
70 typedef struct bkg {
71         short x, y, w, h;                       // The location of the menu.
72         grs_bitmap * bmp;                       // The background under the menu.
73 } bkg;
74
75 extern bkg bg;
76
77 void load_background_bitmap(void);
78
79 char last_palette_loaded[FILENAME_LEN]="";
80 char last_palette_loaded_pig[FILENAME_LEN]="";
81
82 ubyte last_palette_for_color_fonts[768];
83
84 void remap_fonts_and_menus(int do_fadetable_hack)
85 {
86         nm_remap_background();
87         gr_remap_color_fonts();
88
89         if (do_fadetable_hack) {
90                 int i;
91                 float g = 1.0;
92                 double intensity;
93                 ubyte gamma[64];
94
95                 intensity = (double)(14)/(double)(32);
96                 for (i=0;i<64;i++)
97                         gamma[i] = (int)((pow(intensity, 1.0/g)*i) + 0.5);
98                 for (i=0;i<256;i++) {
99                         int c;
100                         c = gr_find_closest_color(gamma[gr_palette[i*3]],gamma[gr_palette[i*3+1]],gamma[gr_palette[i*3+2]]);
101                         gr_fade_table[14*256+i] = c;
102                 }
103         }
104
105         memcpy(last_palette_for_color_fonts,gr_palette,sizeof(last_palette_for_color_fonts));
106 }
107
108 //load a palette by name. returns 1 if new palette loaded, else 0
109 //if used_for_level is set, load pig, etc.
110 //if no_change_screen is set, the current screen does not get remapped,
111 //and the hardware palette does not get changed
112 int load_palette(char *name,int used_for_level,int no_change_screen)
113 {
114         char pigname[FILENAME_LEN];
115         ubyte old_pal[256*3];
116
117         //special hack to tell that palette system about a pig that's been loaded elsewhere
118         if (used_for_level == -2) {
119                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
120                 return 1;
121         }
122
123         if (name==NULL)
124                 name = last_palette_loaded_pig;
125
126         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
127
128                 _splitpath(name,NULL,NULL,pigname,NULL);
129                 strcat(pigname,".pig");
130                 //if not editor, load pig first so small install message can come
131                 //up in old palette.  If editor version, we must load the pig after
132                 //the palette is loaded so we can remap new textures.
133                 #ifndef EDITOR
134                 piggy_new_pigfile(pigname);
135                 #endif
136         }
137
138         if (stricmp(last_palette_loaded,name) != 0) {
139
140                 memcpy(old_pal,gr_palette,sizeof(old_pal));
141
142                 strncpy(last_palette_loaded,name,sizeof(last_palette_loaded));
143
144                 gr_use_palette_table(name);
145
146                 if (Function_mode == FMODE_GAME && !no_change_screen)
147                         gr_remap_bitmap_good( &grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1 );
148
149         if (bg.bmp)
150             gr_remap_bitmap_good( bg.bmp, old_pal, -1, -1 );
151
152                 if (!gr_palette_faded_out && !no_change_screen)
153                         gr_palette_load(gr_palette);
154
155                 remap_fonts_and_menus(0);
156
157                 Color_0_31_0 = -1;              //for gauges
158                 HUD_color = -1;
159
160                 load_background_bitmap();
161
162                 g3_remap_interp_colors();
163         }
164
165
166         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
167
168                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
169
170                 #ifdef EDITOR
171                 piggy_new_pigfile(pigname);
172                 #endif
173
174                 texmerge_flush();
175                 rle_cache_flush();
176         }
177
178         return 1;
179 }
180