]> icculus.org git repositories - btb/d2x.git/blob - main/gamepal.c
remove rcs tags
[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
35 #include "inferno.h"
36 #include "gamepal.h"
37 #include "mission.h"
38 #include "newmenu.h"
39 #include "texmerge.h"
40 #include "piggy.h"
41 #include "strutil.h"
42
43 extern void g3_remap_interp_colors();
44
45 char Current_level_palette[FILENAME_LEN];
46
47 extern int Color_0_31_0, HUD_color;
48
49 //background for boxed messages
50 typedef struct bkg {
51         short x, y, w, h;                       // The location of the menu.
52         grs_bitmap * bmp;                       // The background under the menu.
53 } bkg;
54
55 extern bkg bg;
56
57 void load_background_bitmap(void);
58
59 char last_palette_loaded[FILENAME_LEN]="";
60 char last_palette_loaded_pig[FILENAME_LEN]="";
61
62 ubyte last_palette_for_color_fonts[768];
63
64 void remap_fonts_and_menus(int do_fadetable_hack)
65 {
66         nm_remap_background();
67         gr_remap_color_fonts();
68
69         if (do_fadetable_hack) {
70                 int i;
71                 float g = 1.0;
72                 double intensity;
73                 ubyte gamma[64];
74
75                 intensity = (double)(14)/(double)(32);
76                 for (i=0;i<64;i++)
77                         gamma[i] = (int)((pow(intensity, 1.0/g)*i) + 0.5);
78                 for (i=0;i<256;i++) {
79                         int c;
80                         c = gr_find_closest_color(gamma[gr_palette[i*3]],gamma[gr_palette[i*3+1]],gamma[gr_palette[i*3+2]]);
81                         gr_fade_table[14*256+i] = c;
82                 }
83         }
84
85         memcpy(last_palette_for_color_fonts,gr_palette,sizeof(last_palette_for_color_fonts));
86 }
87
88 //load a palette by name. returns 1 if new palette loaded, else 0
89 //if used_for_level is set, load pig, etc.
90 //if no_change_screen is set, the current screen does not get remapped,
91 //and the hardware palette does not get changed
92 int load_palette(char *name,int used_for_level,int no_change_screen)
93 {
94         char pigname[FILENAME_LEN];
95         ubyte old_pal[256*3];
96
97         //special hack to tell that palette system about a pig that's been loaded elsewhere
98         if (used_for_level == -2) {
99                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
100                 return 1;
101         }
102
103         if (name==NULL)
104                 name = last_palette_loaded_pig;
105
106         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
107
108                 _splitpath(name,NULL,NULL,pigname,NULL);
109                 strcat(pigname,".pig");
110                 //if not editor, load pig first so small install message can come
111                 //up in old palette.  If editor version, we must load the pig after
112                 //the palette is loaded so we can remap new textures.
113                 #ifndef EDITOR
114                 piggy_new_pigfile(pigname);
115                 #endif
116         }
117
118         if (stricmp(last_palette_loaded,name) != 0) {
119
120                 memcpy(old_pal,gr_palette,sizeof(old_pal));
121
122                 strncpy(last_palette_loaded,name,sizeof(last_palette_loaded));
123
124                 gr_use_palette_table(name);
125
126                 if (Function_mode == FMODE_GAME && !no_change_screen)
127                         gr_remap_bitmap_good( &grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1 );
128
129         if (bg.bmp)
130             gr_remap_bitmap_good( bg.bmp, old_pal, -1, -1 );
131
132                 if (!gr_palette_faded_out && !no_change_screen)
133                         gr_palette_load(gr_palette);
134
135                 remap_fonts_and_menus(0);
136
137                 Color_0_31_0 = -1;              //for gauges
138                 HUD_color = -1;
139
140                 load_background_bitmap();
141
142                 g3_remap_interp_colors();
143         }
144
145
146         if (used_for_level && stricmp(last_palette_loaded_pig,name) != 0) {
147
148                 strncpy(last_palette_loaded_pig,name,sizeof(last_palette_loaded_pig));
149
150                 #ifdef EDITOR
151                 piggy_new_pigfile(pigname);
152                 #endif
153
154                 texmerge_flush();
155                 rle_cache_flush();
156         }
157
158         return 1;
159 }
160