1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef R1_TEXTURE_MANAGER_HH
|
---|
10 | #define R1_TEXTURE_MANAGER_HH
|
---|
11 |
|
---|
12 |
|
---|
13 | #include "arch.hh"
|
---|
14 | #include "tex_id.hh"
|
---|
15 | #include "math/num_type.hh"
|
---|
16 |
|
---|
17 | #include "file/file.hh"
|
---|
18 | #include "palette/pal.hh"
|
---|
19 | #include "memory/array.hh"
|
---|
20 | #include "mip.hh"
|
---|
21 |
|
---|
22 | class i4_image_class;
|
---|
23 | extern w32 R1_CHROMA_COLOR;
|
---|
24 |
|
---|
25 | struct r1_texture_entry_struct
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | w32 id; // checksum of filename
|
---|
29 | w8 flags;
|
---|
30 |
|
---|
31 | w32 average_color;
|
---|
32 |
|
---|
33 | r1_miplevel_t *mipmaps[R1_MAX_MIP_LEVELS+1]; //null terminated
|
---|
34 | w32 file_offsets[R1_MAX_MIP_LEVELS];
|
---|
35 |
|
---|
36 | i4_bool is_transparent()
|
---|
37 | {
|
---|
38 | if (flags & R1_MIP_IS_TRANSPARENT)
|
---|
39 | return i4_T;
|
---|
40 | else
|
---|
41 | return i4_F;
|
---|
42 | }
|
---|
43 |
|
---|
44 | i4_bool is_alphatexture()
|
---|
45 | {
|
---|
46 | if (flags & R1_MIP_IS_ALPHATEXTURE)
|
---|
47 | return i4_T;
|
---|
48 | else
|
---|
49 | return i4_F;
|
---|
50 | }
|
---|
51 | };
|
---|
52 |
|
---|
53 |
|
---|
54 | struct r1_texture_matchup_struct
|
---|
55 | {
|
---|
56 | w32 id;
|
---|
57 | w16 handle;
|
---|
58 | sw16 left, right;
|
---|
59 | char name[128];
|
---|
60 | };
|
---|
61 |
|
---|
62 | struct r1_texture_animation_entry_struct
|
---|
63 | {
|
---|
64 | w32 id;
|
---|
65 | w16 total_frames;
|
---|
66 | r1_texture_handle *frames;
|
---|
67 | };
|
---|
68 |
|
---|
69 | class r1_texture_manager_class
|
---|
70 | {
|
---|
71 | public:
|
---|
72 | i4_bool textures_loaded;
|
---|
73 |
|
---|
74 | r1_texture_manager_class(const i4_pal *pal);
|
---|
75 |
|
---|
76 | virtual void init();
|
---|
77 | virtual void uninit();
|
---|
78 |
|
---|
79 | w32 average_texture_color(r1_texture_handle handle, w32 frame_num);
|
---|
80 |
|
---|
81 | void matchup_textures();
|
---|
82 |
|
---|
83 | r1_texture_handle find_texture(w32 id);
|
---|
84 |
|
---|
85 | i4_bool texture_resolution_change()
|
---|
86 | {
|
---|
87 | i4_bool ret = texture_resolution_changed;
|
---|
88 | texture_resolution_changed = i4_F;
|
---|
89 | return ret;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void keep_resident(const i4_const_str &tname, sw32 desired_width);
|
---|
93 |
|
---|
94 | char *get_texture_name(r1_texture_handle handle);
|
---|
95 | r1_texture_handle register_texture(const i4_const_str &tname,
|
---|
96 | const i4_const_str &error_string,
|
---|
97 | i4_bool *has_been_loaded=0);
|
---|
98 |
|
---|
99 | r1_texture_handle register_image(i4_image_class *image);
|
---|
100 |
|
---|
101 | // loads textures previously registered with register_texture
|
---|
102 | i4_bool load_textures();
|
---|
103 |
|
---|
104 | w32 get_animation_length(r1_texture_handle handle)
|
---|
105 | {
|
---|
106 | if (handle>=0) return 1;
|
---|
107 | else return tanims[-handle-1].total_frames;
|
---|
108 | }
|
---|
109 |
|
---|
110 | virtual void next_frame();
|
---|
111 |
|
---|
112 | virtual void reset();
|
---|
113 |
|
---|
114 | virtual void toggle_texture_loading();
|
---|
115 |
|
---|
116 | virtual r1_miplevel_t *get_texture(r1_texture_handle handle,
|
---|
117 | w32 frame_counter,
|
---|
118 | sw32 desired_width,
|
---|
119 | sw32 &w, sw32 &h);
|
---|
120 |
|
---|
121 | virtual i4_bool valid_handle(r1_texture_handle handle)
|
---|
122 | {
|
---|
123 | if (handle<registered_tnames.size() && registered_tnames[handle].handle != 0)
|
---|
124 | return i4_T;
|
---|
125 | else
|
---|
126 | return i4_F;
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected:
|
---|
130 |
|
---|
131 | void keep_cache_current(i4_array<w32> *file_ids);
|
---|
132 |
|
---|
133 | i4_bool build_cache_file(i4_array<w32> &texture_file_ids,
|
---|
134 | const i4_const_str &network_dir,
|
---|
135 | const i4_const_str &local_dir);
|
---|
136 |
|
---|
137 | i4_bool update_cache_file(i4_array<w32> &update_ids,
|
---|
138 | const i4_const_str &network_dir,
|
---|
139 | const i4_const_str &local_dir);
|
---|
140 |
|
---|
141 | i4_array<r1_texture_matchup_struct> registered_tnames;
|
---|
142 | i4_array<r1_texture_entry_struct> *entries;
|
---|
143 | r1_texture_animation_entry_struct *tanims;
|
---|
144 |
|
---|
145 | sw32 total_textures;
|
---|
146 | sw32 total_tanims;
|
---|
147 |
|
---|
148 | //time keeper
|
---|
149 | sw32 frame_count;
|
---|
150 |
|
---|
151 | i4_bool texture_load_toggle;
|
---|
152 |
|
---|
153 | i4_bool texture_resolution_changed;
|
---|
154 |
|
---|
155 | const i4_pal *pal;
|
---|
156 |
|
---|
157 | //////////////////////////// derive / specify these for each texture manager derivative
|
---|
158 | i4_pixel_format regular_format;
|
---|
159 | i4_pixel_format chroma_format;
|
---|
160 | i4_pixel_format alpha_format;
|
---|
161 |
|
---|
162 | sw32 min_texture_dimention;
|
---|
163 | sw32 max_texture_dimention;
|
---|
164 | i4_bool square_textures;
|
---|
165 |
|
---|
166 | public:
|
---|
167 | virtual i4_bool immediate_mip_load(r1_mip_load_info *load_info) = 0;
|
---|
168 |
|
---|
169 | virtual i4_bool async_mip_load(r1_mip_load_info *load_info) = 0;
|
---|
170 |
|
---|
171 | virtual void free_mip(r1_vram_handle_type vram_handle) = 0;
|
---|
172 | };
|
---|
173 |
|
---|
174 |
|
---|
175 | #endif
|
---|