Debian Codegraph @

common/main/bm.h

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Bitmap and Palette loading functions.
23 *
24 */
25
26 #pragma once
27
28 #include <physfs.h>
29 #include "maths.h"
30 #include "fwd-vclip.h"
31 #include "fwd-game.h"
32 #include "fwd-piggy.h"
33 #include "fwd-robot.h"
34 #include "d_array.h"
35 #include "inferno.h"
36 #include <cstdint>
37 #include "physfsx.h"
38
39 namespace dcx {
40
41 struct grs_bitmap;
42
43 enum class tmapinfo_flag : uint8_t
44 {
45 lava = 1 << 0, //this material blows up when hit
46 /* if DXX_BUILD_DESCENT == 2 */
47 water = 1 << 1, //this material is water
48 force_field = 1 << 2, //this is force field - flares don't stick
49 goal_blue = 1 << 3, //this is used to remap the blue goal
50 goal_red = 1 << 4, //this is used to remap the red goal
51 goal_hoard = 1 << 5,//this is used to remap the goals
52 /* endif */
53 };
54
55 enum class tmapinfo_flags : uint8_t
56 {
57 };
58
59 static constexpr uint8_t operator&(tmapinfo_flags flags, tmapinfo_flag mask)
60 {
61 return static_cast<uint8_t>(flags) & static_cast<uint8_t>(mask);
62 }
63
64 static constexpr tmapinfo_flags &operator|=(tmapinfo_flags &flags, tmapinfo_flag mask)
65 {
66 return flags = static_cast<tmapinfo_flags>(static_cast<uint8_t>(flags) | static_cast<uint8_t>(mask));
67 }
68
69 static constexpr tmapinfo_flag operator|(tmapinfo_flag a, tmapinfo_flag b)
70 {
71 return static_cast<tmapinfo_flag>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
72 }
73
74 }
75
76 #ifdef DXX_BUILD_DESCENT
77 namespace dsx {
78 #if DXX_BUILD_DESCENT == 1
79 constexpr std::integral_constant<unsigned, 800> MAX_TEXTURES{};
80 #elif DXX_BUILD_DESCENT == 2
81 constexpr std::integral_constant<unsigned, 1200> MAX_TEXTURES{};
82 #endif
83
84 struct tmap_info : prohibit_void_ptr<tmap_info>
85 {
86 #if DXX_BUILD_DESCENT == 1
87 d_fname filename;
88 tmapinfo_flags flags;
89 fix lighting; // 0 to 1
90 fix damage; //how much damage being against this does
91 unsigned eclip_num; //if not -1, the eclip that changes this
92 #elif DXX_BUILD_DESCENT == 2
93 fix lighting; //how much light this casts
94 fix damage; //how much damage being against this does (for lava)
95 uint16_t eclip_num; //the eclip that changes this, or -1
96 short destroyed; //bitmap to show when destroyed, or -1
97 short slide_u,slide_v; //slide rates of texture, stored in 8:8 fix
98 tmapinfo_flags flags;
99 #if DXX_USE_EDITOR
100 d_fname filename; //used by editor to remap textures
101 #endif
102
103 #define TMAP_INFO_SIZE 20 // how much space it takes up on disk
104 #endif
105 };
106 }
107
108 namespace dcx {
109 extern int Num_object_types;
110 #if DXX_USE_EDITOR
111 extern int Num_object_subtypes; // Number of possible IDs for the current type of object to be placed
112 #endif
113
114 struct player_ship;
115 //right now there's only one player ship, but we can have another by
116 //adding an array and setting the pointer to the active ship.
117 extern struct player_ship only_player_ship;
118 constexpr struct player_ship *Player_ship = &only_player_ship;
119 extern unsigned Num_cockpits;
120 }
121
122 namespace dsx {
123 #if DXX_USE_EDITOR
124 using tmap_xlate_table_array = std::array<short, MAX_TEXTURES>;
125 extern tmap_xlate_table_array tmap_xlate_table;
126 #endif
127
128 /* This is level-unique because hoard mode assumes it can overwrite a
129 * texture.
130 */
131 struct d_level_unique_tmap_info_state
132 {
133 using TmapInfo_array = std::array<tmap_info, MAX_TEXTURES>;
134 unsigned Num_tmaps;
135 TmapInfo_array TmapInfo;
136 };
137
138 extern d_level_unique_tmap_info_state LevelUniqueTmapInfoState;
139 // Initializes the palette, bitmap system...
140 void gamedata_close();
141 }
142 void bm_close();
143
144 // Initializes the Texture[] array of bmd_bitmap structures.
145 void init_textures();
146
147 namespace dsx {
148
149 int gamedata_init(d_level_shared_robot_info_state &LevelSharedRobotInfoState);
150
151 #if DXX_BUILD_DESCENT == 1
152
153 #define OL_ROBOT 1
154 #define OL_HOSTAGE 2
155 #define OL_POWERUP 3
156 #define OL_CONTROL_CENTER 4
157 #define OL_PLAYER 5
158 #define OL_CLUTTER 6 //some sort of misc object
159 #define OL_EXIT 7 //the exit model for external scenes
160
161 #define MAX_OBJTYPE 100
162
163 extern int Num_total_object_types; // Total number of object types, including robots, hostages, powerups, control centers, faces
164 extern int8_t ObjType[MAX_OBJTYPE]; // Type of an object, such as Robot, eg if ObjType[11] == OL_ROBOT, then object #11 is a robot
165 extern std::array<polygon_model_index, MAX_OBJTYPE> ObjId; // ID of a robot, within its class, eg if ObjType[11] == 3, then object #11 is the third robot
166 extern fix ObjStrength[MAX_OBJTYPE]; // initial strength of each object
167
168 constexpr std::integral_constant<unsigned, 210> MAX_OBJ_BITMAPS{};
169 constexpr std::size_t N_COCKPIT_BITMAPS{4};
170
171 #elif DXX_BUILD_DESCENT == 2
172
173 extern int Robot_replacements_loaded;
174 constexpr std::integral_constant<unsigned, 610> MAX_OBJ_BITMAPS{};
175 constexpr std::size_t N_COCKPIT_BITMAPS{6};
176 extern unsigned N_ObjBitmaps;
177 #endif
178
179 enum class object_bitmap_index : uint16_t
180 {
181 None = UINT16_MAX
182 };
183 extern enumerated_array<bitmap_index, MAX_OBJ_BITMAPS, object_bitmap_index> ObjBitmaps;
184 extern std::array<object_bitmap_index, MAX_OBJ_BITMAPS> ObjBitmapPtrs;
185
186 enum class cockpit_bitmap_index : uint8_t
187 {
188 full_cockpit, // normal screen with cockpit
189 rear_view, // looking back with bitmap
190 status_bar, // small status bar, w/ reticle
191 #if DXX_BUILD_DESCENT == 2
192 hires_full_cockpit,
193 hires_rear_view,
194 hires_status_bar,
195 #endif
196 };
197
198 }
199
200 extern int First_multi_bitmap_num;
201 void compute_average_rgb(grs_bitmap *bm, std::array<fix, 3> &rgb);
202
203 namespace dsx {
204 extern enumerated_array<bitmap_index, N_COCKPIT_BITMAPS, cockpit_bitmap_index> cockpit_bitmap;
205 void load_robot_replacements(const d_fname &level_name);
206 #if DXX_BUILD_DESCENT == 1 || (DXX_BUILD_DESCENT == 2 && DXX_USE_EDITOR)
207 // Initializes all bitmaps from BITMAPS.TBL file.
208 int gamedata_read_tbl(d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_vclip_array &Vclip, int pc_shareware);
209 #endif
210
211 void bm_read_all(d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_vclip_array &Vclip, NamedPHYSFS_File fp);
212 #if DXX_BUILD_DESCENT == 1
213 void properties_read_cmp(d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_vclip_array &Vclip, NamedPHYSFS_File fp);
214 #endif
215 int ds_load(int skip, const char * filename );
216 int compute_average_pixel(grs_bitmap *n);
217
218 #if DXX_BUILD_DESCENT == 2
219 int load_exit_models();
220 //these values are the number of each item in the release of d2
221 //extra items added after the release get written in an additional hamfile
222 constexpr std::integral_constant<unsigned, 66> N_D2_ROBOT_TYPES{};
223 constexpr std::integral_constant<unsigned, 1145> N_D2_ROBOT_JOINTS{};
224 constexpr std::integral_constant<unsigned, 422> N_D2_OBJBITMAPS{};
225 constexpr std::integral_constant<unsigned, 502> N_D2_OBJBITMAPPTRS{};
226 constexpr std::integral_constant<unsigned, 62> N_D2_WEAPON_TYPES{};
227 #endif
228 }
229
230 #endif