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

Function ReloadModelTextures

model/polymodel.cpp:901–976  ·  view source on GitHub ↗

Given a modelnumber, opens the original pof file and attempts to rematch that models textures with the bitmaps with have in memory

Source from the content-addressed store, hash-verified

899// Given a modelnumber, opens the original pof file and attempts to rematch that
900// models textures with the bitmaps with have in memory
901int ReloadModelTextures(int modelnum) {
902 CFILE *infile;
903 int done = 0, id, len;
904 poly_model *pm = &Poly_models[modelnum];
905
906 ASSERT(!(Poly_models[modelnum].flags & PMF_NOT_RESIDENT));
907
908 infile = cfopen(Poly_models[modelnum].name, "rb");
909 if (!infile)
910 return 0;
911
912 id = cf_ReadInt(infile);
913
914 if (id != 'OPSP')
915 Error("Bad ID in model file!");
916 cf_ReadInt(infile); // skip version
917
918 while (!done) {
919 if (cfeof(infile)) {
920 done = 1;
921 continue;
922 }
923
924 id = cf_ReadInt(infile); // read chunk type
925 len = cf_ReadInt(infile); // read chunk length
926
927 switch (id) {
928 case ID_TXTR: {
929 // Texture filename list
930 int i, n;
931 char name_buf[128];
932
933 n = cf_ReadInt(infile);
934 if (n != pm->n_textures) {
935 Int3(); // Get Jason, new model doesn't match old model!!!
936 cfclose(infile);
937 return 0;
938 }
939
940 for (i = 0; i < n; i++) {
941 int ret;
942 char temp[256];
943
944 // Read the name of this texture
945 ReadModelStringLen(name_buf, 127, infile);
946
947 strcpy(temp, name_buf);
948 strcat(temp, ".OGF");
949 ret = FindTextureBitmapName(temp);
950 if (ret == -1) {
951 // See if its already in memory
952 ret = FindTextureName(name_buf);
953 if (ret == -1) {
954 ret = 0;
955 // mprintf(0,"Object texture %s is not in memory!\n",name_buf);
956 }
957 }
958

Callers 2

PageInPolymodelFunction · 0.85
RemapPolyModelsFunction · 0.85

Calls 9

cfopenFunction · 0.85
cf_ReadIntFunction · 0.85
ErrorFunction · 0.85
cfeofFunction · 0.85
cfcloseFunction · 0.85
ReadModelStringLenFunction · 0.85
FindTextureBitmapNameFunction · 0.85
FindTextureNameFunction · 0.85
cfseekFunction · 0.85

Tested by

no test coverage detected