Pages in a polymodel if its not already in memory
| 2148 | |
| 2149 | // Pages in a polymodel if its not already in memory |
| 2150 | void PageInPolymodel(int polynum, int type, float *size_ptr) { |
| 2151 | if (!(Poly_models[polynum].flags & PMF_NOT_RESIDENT)) { |
| 2152 | if (!(Poly_models[polynum].flags & PMF_SIZE_COMPUTED)) |
| 2153 | if (type != -1) { |
| 2154 | ComputeDefaultSize(type, polynum, size_ptr); |
| 2155 | } |
| 2156 | return; |
| 2157 | } |
| 2158 | |
| 2159 | mprintf(0, "Paging in polymodel %s.\n", Poly_models[polynum].name); |
| 2160 | |
| 2161 | CFILE *infile; |
| 2162 | infile = (CFILE *)cfopen(Poly_models[polynum].name, "rb"); |
| 2163 | |
| 2164 | if (!infile) { |
| 2165 | // due to a bug in some 3rd party tablefile editors, full paths might |
| 2166 | // have been used when they shouldn't have been |
| 2167 | char *end_ptr, *start_ptr; |
| 2168 | start_ptr = Poly_models[polynum].name; |
| 2169 | end_ptr = start_ptr + strlen(start_ptr) - 1; |
| 2170 | while ((end_ptr >= start_ptr) && (*end_ptr != '\\')) |
| 2171 | end_ptr--; |
| 2172 | if (end_ptr < start_ptr) { |
| 2173 | Error("Failed to page in %s.", Poly_models[polynum].name); |
| 2174 | return; |
| 2175 | } |
| 2176 | |
| 2177 | ASSERT(*end_ptr == '\\'); |
| 2178 | end_ptr++; |
| 2179 | |
| 2180 | infile = (CFILE *)cfopen(end_ptr, "rb"); |
| 2181 | if (!infile) { |
| 2182 | Error("Failed to page in %s.", Poly_models[polynum].name); |
| 2183 | return; |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | // ASSERT(infile); |
| 2188 | |
| 2189 | int ret = ReadNewModelFile(polynum, infile); |
| 2190 | |
| 2191 | cfclose(infile); |
| 2192 | ASSERT(ret > 0); |
| 2193 | |
| 2194 | // See if textures need to be remapped |
| 2195 | int remap = 0; |
| 2196 | for (int t = 0; t < Poly_models[polynum].n_textures; t++) |
| 2197 | if (Poly_models[polynum].textures[t] == 0) // is there a bad texture? |
| 2198 | remap = 1; |
| 2199 | |
| 2200 | if (remap == 1) { |
| 2201 | // remap the damn textures |
| 2202 | mprintf(0, "Remapping model textures for model %s.\n", Poly_models[polynum].name); |
| 2203 | ReloadModelTextures(polynum); |
| 2204 | } |
| 2205 | |
| 2206 | if (type != -1) { |
| 2207 | ComputeDefaultSize(type, polynum, size_ptr); |
no test coverage detected