given a filename, reads in a POF and returns an index into the Poly_models array returns -1 if something is wrong
| 2054 | // given a filename, reads in a POF and returns an index into the Poly_models array |
| 2055 | // returns -1 if something is wrong |
| 2056 | int LoadPolyModel(const std::filesystem::path &filename, int pageable) { |
| 2057 | int i, polynum = -1; |
| 2058 | CFILE *infile = nullptr; |
| 2059 | int overlay = 0; |
| 2060 | |
| 2061 | ASSERT(Num_poly_models >= 0); |
| 2062 | ASSERT(Num_poly_models < MAX_POLY_MODELS); |
| 2063 | |
| 2064 | std::filesystem::path name = ChangePolyModelName(filename); |
| 2065 | |
| 2066 | // If this polymodel is already in memory, just use that index |
| 2067 | i = FindPolyModelName(name); |
| 2068 | if (i != -1) { |
| 2069 | #ifdef RELEASE |
| 2070 | Poly_models[i].used++; |
| 2071 | return i; |
| 2072 | #endif |
| 2073 | |
| 2074 | int old_used = Poly_models[i].used; |
| 2075 | int not_res = 0; |
| 2076 | |
| 2077 | if (Poly_models[i].flags & PMF_NOT_RESIDENT) |
| 2078 | not_res = 1; |
| 2079 | |
| 2080 | mprintf(1, "Model '%s' usage count is now %d.\n", Poly_models[i].name, Poly_models[i].used + 1); |
| 2081 | |
| 2082 | Poly_models[i].used = 1; |
| 2083 | FreePolyModel(i); |
| 2084 | |
| 2085 | memset(&Poly_models[i], 0, sizeof(poly_model)); |
| 2086 | WBClearInfo(&Poly_models[i]); |
| 2087 | Poly_models[i].used = old_used + 1; |
| 2088 | if (not_res) |
| 2089 | Poly_models[i].flags = PMF_NOT_RESIDENT; |
| 2090 | |
| 2091 | overlay = 1; |
| 2092 | polynum = i; |
| 2093 | } |
| 2094 | |
| 2095 | // Not in memory, so we must load it |
| 2096 | |
| 2097 | if (!pageable) { |
| 2098 | infile = cfopen(filename, "rb"); |
| 2099 | if (!infile) |
| 2100 | return -1; |
| 2101 | } |
| 2102 | |
| 2103 | if (!overlay) |
| 2104 | polynum = AllocPolyModel(); |
| 2105 | else { |
| 2106 | if (!(Poly_models[polynum].flags & PMF_NOT_RESIDENT)) { |
| 2107 | if (pageable) { |
| 2108 | infile = cfopen(filename, "rb"); |
| 2109 | if (!infile) |
| 2110 | return -1; |
| 2111 | } |
| 2112 | pageable = 0; |
| 2113 | } |
no test coverage detected