MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / LoadPolyModel

Function LoadPolyModel

model/polymodel.cpp:2056–2147  ·  view source on GitHub ↗

given a filename, reads in a POF and returns an index into the Poly_models array returns -1 if something is wrong

Source from the content-addressed store, hash-verified

2054// given a filename, reads in a POF and returns an index into the Poly_models array
2055// returns -1 if something is wrong
2056int 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 }

Callers 14

mng_AssignShipPageToShipFunction · 0.85
mng_AssignDoorPageToDoorFunction · 0.85
ProcessPageFromFileMethod · 0.85
OnGenericAddNewMethod · 0.85
OnGenericChangeModelMethod · 0.85
OnPshipLoadModelMethod · 0.85
InitCockpitFunction · 0.85
InitMarkersFunction · 0.85
LoadWeaponFireImageFunction · 0.85
LoadShipImageFunction · 0.85

Calls 9

ChangePolyModelNameFunction · 0.85
FindPolyModelNameFunction · 0.85
FreePolyModelFunction · 0.85
cfopenFunction · 0.85
AllocPolyModelFunction · 0.85
cfilelengthFunction · 0.85
ReadNewModelFileFunction · 0.85
cfcloseFunction · 0.85
WBClearInfoFunction · 0.70

Tested by

no test coverage detected