Merge branch 'model-fallback' into 'next'

Model fallback

See merge request STJr/SRB2!1167
This commit is contained in:
James R 2020-10-18 16:52:42 -04:00
commit 1cd73315f1

View file

@ -92,7 +92,13 @@ static void md2_freeModel (model_t *model)
static model_t *md2_readModel(const char *filename) static model_t *md2_readModel(const char *filename)
{ {
//Filename checking fixed ~Monster Iestyn and Golden //Filename checking fixed ~Monster Iestyn and Golden
if (FIL_FileExists(va("%s"PATHSEP"%s", srb2home, filename)))
return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC); return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC);
if (FIL_FileExists(va("%s"PATHSEP"%s", srb2path, filename)))
return LoadModel(va("%s"PATHSEP"%s", srb2path, filename), PU_STATIC);
return NULL;
} }
static inline void md2_printModelInfo (model_t *model) static inline void md2_printModelInfo (model_t *model)
@ -160,7 +166,11 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
png_FILE = fopen(pngfilename, "rb"); png_FILE = fopen(pngfilename, "rb");
if (!png_FILE) if (!png_FILE)
{ {
pngfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename);
FIL_ForceExtension(pngfilename, ".png");
png_FILE = fopen(pngfilename, "rb");
//CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename); //CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename);
if (!png_FILE)
return 0; return 0;
} }
@ -285,10 +295,16 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
//Filename checking fixed ~Monster Iestyn and Golden //Filename checking fixed ~Monster Iestyn and Golden
char *pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2home, filename); char *pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2home, filename);
FIL_ForceExtension(pcxfilename, ".pcx");
file = fopen(pcxfilename, "rb");
if (!file)
{
pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename);
FIL_ForceExtension(pcxfilename, ".pcx"); FIL_ForceExtension(pcxfilename, ".pcx");
file = fopen(pcxfilename, "rb"); file = fopen(pcxfilename, "rb");
if (!file) if (!file)
return 0; return 0;
}
if (fread(&header, sizeof (PcxHeader), 1, file) != 1) if (fread(&header, sizeof (PcxHeader), 1, file) != 1)
{ {
@ -491,12 +507,16 @@ void HWR_InitModels(void)
//Filename checking fixed ~Monster Iestyn and Golden //Filename checking fixed ~Monster Iestyn and Golden
f = fopen(va("%s"PATHSEP"%s", srb2home, "models.dat"), "rt"); f = fopen(va("%s"PATHSEP"%s", srb2home, "models.dat"), "rt");
if (!f)
{
f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt");
if (!f) if (!f)
{ {
CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno));
nomd2s = true; nomd2s = true;
return; return;
} }
}
// length of the player model prefix // length of the player model prefix
prefixlen = strlen(PLAYERMODELPREFIX); prefixlen = strlen(PLAYERMODELPREFIX);
@ -569,10 +589,14 @@ void HWR_AddPlayerModel(int skin) // For skins that were added after startup
if (!f) if (!f)
{ {
CONS_Printf("Error while loading models.dat\n"); f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt");
if (!f)
{
CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno));
nomd2s = true; nomd2s = true;
return; return;
} }
}
// length of the player model prefix // length of the player model prefix
prefixlen = strlen(PLAYERMODELPREFIX); prefixlen = strlen(PLAYERMODELPREFIX);
@ -624,10 +648,14 @@ void HWR_AddSpriteModel(size_t spritenum) // For sprites that were added after s
if (!f) if (!f)
{ {
CONS_Printf("Error while loading models.dat\n"); f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt");
if (!f)
{
CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno));
nomd2s = true; nomd2s = true;
return; return;
} }
}
// Check for any models that match the names of sprite names! // Check for any models that match the names of sprite names!
while (fscanf(f, "%25s %31s %f %f", name, filename, &scale, &offset) == 4) while (fscanf(f, "%25s %31s %f %f", name, filename, &scale, &offset) == 4)