]> icculus.org git repositories - btb/d2x.git/blob - main/gamepal.c
more header fixes
[btb/d2x.git] / main / gamepal.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Functions for loading palettes
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <math.h>
27
28 #include "fix.h"
29 #include "vecmat.h"
30 #include "gr.h"
31 #include "3d.h"
32 #include "palette.h"
33 #include "rle.h"
34 #include "inferno.h"
35 #include "strutil.h"
36
37
38 extern void g3_remap_interp_colors();
39
40 char Current_level_palette[FILENAME_LEN];
41
42 extern int Color_0_31_0, HUD_color;
43
44 //background for boxed messages
45 typedef struct bkg {
46         short x, y, w, h;                       // The location of the menu.
47         grs_bitmap * bmp;                       // The background under the menu.
48 } bkg;
49
50 extern bkg bg;
51
52 void load_background_bitmap(void);
53
54 char last_palette_loaded[FILENAME_LEN]="";
55 char last_palette_loaded_pig[FILENAME_LEN]="";
56
57 ubyte last_palette_for_color_fonts[768];
58
59 void remap_fonts_and_menus(int do_fadetable_hack)
60 {
61         nm_remap_background();
62         gr_remap_color_fonts();
63
64         if (do_fadetable_hack) {
65                 int i;
66                 float g = 1.0;
67                 double intensity;
68                 ubyte gamma[64];
69
70                 intensity = (double)(14)/(double)(32);
71                 for (i=0;i<64;i++)
72                         gamma[i] = (int)((pow(intensity, 1.0/g)*i) + 0.5);
73                 for (i=0;i<256;i++) {
74                         int c;
75                         c = gr_find_closest_color(gamma[gr_palette[i*3]],gamma[gr_palette[i*3+1]],gamma[gr_palette[i*3+2]]);
76                         gr_fade_table[14*256+i] = c;
77                 }
78         }
79
80         memcpy(last_palette_for_color_fonts,gr_palette,sizeof(last_palette_for_color_fonts));
81 }
82
83 //load a palette by name. returns 1 if new palette loaded, else 0
84 //if used_for_level is set, load pig, etc.
85 //if no_change_screen is set, the current screen does not get remapped,
86 //and the hardware palette does not get changed
87 int load_palette(char *name,int used_for_level,int no_change_screen)
88 {
89         char pigname[FILENAME_LEN];
90         ubyte old_pal[256*3];
91
92         //special hack to tell that palette system about a pig that's been loaded elsewhere
93         if (used_for_level == -2) {
94                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
95                 return 1;
96         }
97
98         if (name==NULL)
99                 name = last_palette_loaded_pig;
100
101         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
102
103                 _splitpath(name,NULL,NULL,pigname,NULL);
104                 strcat(pigname,".pig");
105                 //if not editor, load pig first so small install message can come
106                 //up in old palette.  If editor version, we must load the pig after
107                 //the palette is loaded so we can remap new textures.
108                 #ifndef EDITOR
109                 piggy_new_pigfile(pigname);
110                 #endif
111         }
112
113         if (stricmp(last_palette_loaded,name) != 0) {
114
115                 memcpy(old_pal,gr_palette,sizeof(old_pal));
116
117                 strncpy(last_palette_loaded,name,sizeof(last_palette_loaded));
118
119                 gr_use_palette_table(name);
120
121                 if (Function_mode == FMODE_GAME && !no_change_screen)
122                         gr_remap_bitmap_good( &grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1 );
123
124         if (bg.bmp)
125             gr_remap_bitmap_good( bg.bmp, old_pal, -1, -1 );
126
127                 if (!gr_palette_faded_out && !no_change_screen)
128                         gr_palette_load(gr_palette);
129
130                 remap_fonts_and_menus(0);
131
132                 Color_0_31_0 = -1;              //for gauges
133                 HUD_color = -1;
134
135                 load_background_bitmap();
136
137                 g3_remap_interp_colors();
138         }
139
140
141         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
142
143                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
144
145                 #ifdef EDITOR
146                 piggy_new_pigfile(pigname);
147                 #endif
148
149                 texmerge_flush();
150                 rle_cache_flush();
151         }
152
153         return 1;
154 }
155