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 | #include "tmanage.hh"
|
---|
10 |
|
---|
11 | void async_read_callback(w32 count, void *context)
|
---|
12 | {
|
---|
13 | ((r1_texture_manager_class *)context)->async_read_finish(count);
|
---|
14 | }
|
---|
15 |
|
---|
16 | sw32 r1_expect_size;
|
---|
17 |
|
---|
18 | void r1_texture_manager_class::async_read_finish(sw32 count)
|
---|
19 | {
|
---|
20 | /*
|
---|
21 | r1_texture_node_struct *thi=current_load.new_texture;
|
---|
22 | r1_texture_node_struct *tlo=thi->lower;
|
---|
23 | r1_texture_entry_struct *e=thi->entry;
|
---|
24 |
|
---|
25 | // make sure this are in local byte order
|
---|
26 | thi->w=s_to_lsb(thi->w);
|
---|
27 | thi->h=s_to_lsb(thi->h);
|
---|
28 | thi->next_size=l_to_lsb(thi->next_size);
|
---|
29 |
|
---|
30 | tlo->higher=thi;
|
---|
31 |
|
---|
32 | int han=thi->entry - entries;
|
---|
33 |
|
---|
34 |
|
---|
35 | // tlo->entry=0;
|
---|
36 | e->highest=thi; // at this point the texture is visible to the main process
|
---|
37 |
|
---|
38 | delete async_file;
|
---|
39 | async_file=0;
|
---|
40 |
|
---|
41 | // is there another texture to load?
|
---|
42 | if (next_load.in_use)
|
---|
43 | {
|
---|
44 | current_load=next_load;
|
---|
45 | next_load.in_use=i4_F;
|
---|
46 | load_current();
|
---|
47 | }
|
---|
48 | else current_load.in_use=i4_F;
|
---|
49 | */
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 | void r1_texture_manager_class::load_current()
|
---|
54 | {
|
---|
55 | /*
|
---|
56 | r1_texture_entry_struct *e=current_load.entry;
|
---|
57 | if (e)
|
---|
58 | {
|
---|
59 | r1_texture_node_struct *lower=e->highest, *tn;
|
---|
60 |
|
---|
61 | sw32 size=lower->next_size;
|
---|
62 | tn=alloc(size);
|
---|
63 |
|
---|
64 |
|
---|
65 | // this shouldn't fail because we checked before for space
|
---|
66 | if (!tn)
|
---|
67 | i4_error("load current alloc failed");
|
---|
68 |
|
---|
69 | tn->entry=e;
|
---|
70 | tn->higher=0;
|
---|
71 | tn->lower=lower;
|
---|
72 | tn->last_used=frame_count;
|
---|
73 |
|
---|
74 | current_load.new_texture=tn;
|
---|
75 |
|
---|
76 | sw32 offset=e->next_texture_file_offset();
|
---|
77 |
|
---|
78 | //e->offset + r1_texture_disk_space(lower->width, lower->height);
|
---|
79 |
|
---|
80 |
|
---|
81 | i4_str *texture_file=r1_texture_id_to_filename(e->id, *texture_dir);
|
---|
82 | async_file=i4_open(*texture_file);
|
---|
83 | delete texture_file;
|
---|
84 |
|
---|
85 | if (async_file)
|
---|
86 | {
|
---|
87 | async_file->seek(offset);
|
---|
88 | async_file->async_read(&tn->w, size + 8, async_read_callback, this);
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | i4_warning("texture id %d missing",e->id);
|
---|
93 | current_load.in_use=i4_F;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | else current_load.in_use=i4_F;
|
---|
97 | */
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /*
|
---|
102 | i4_bool r1_texture_manager_class::increase_texture_detail(r1_texture_node_struct *tn)
|
---|
103 | {
|
---|
104 | sw32 load_size=tn->next_size;
|
---|
105 | i4_bool ret;
|
---|
106 |
|
---|
107 | // if this is a bigger texture than the one we are currently planning to load
|
---|
108 | // plan on loading this one instead if it will fit in memory
|
---|
109 | if ((!next_load.in_use || next_load.load_size<load_size) &&
|
---|
110 | (!current_load.in_use || tn->entry!=current_load.entry))
|
---|
111 | {
|
---|
112 | if (can_alloc(load_size)) // is there enough space for this texture?
|
---|
113 | {
|
---|
114 | next_load.entry=tn->entry;
|
---|
115 | next_load.load_size=load_size;
|
---|
116 | next_load.in_use=i4_T;
|
---|
117 | ret=i4_T;
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | smallest_sys_failure=load_size;
|
---|
122 | need_gc=i4_T; // need to do garbage collection
|
---|
123 | ret=i4_F;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | else ret=i4_F;
|
---|
127 |
|
---|
128 | // if we are not currently loading a texture then we should move next_load to current_load
|
---|
129 | // and load it if next_load has been suggested
|
---|
130 | if (!current_load.in_use)
|
---|
131 | {
|
---|
132 | if (next_load.in_use)
|
---|
133 | {
|
---|
134 | current_load=next_load;
|
---|
135 | next_load.in_use=i4_F;
|
---|
136 | load_current();
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | was_a_miss=i4_T;
|
---|
141 | return ret;
|
---|
142 | return i4_F;
|
---|
143 | }
|
---|
144 | */
|
---|
145 |
|
---|
146 |
|
---|