Share Mod_ReLoadSkins for reload images on model load

This commit is contained in:
Denis Pauk 2022-10-17 22:35:01 +03:00
parent b2e8fbb086
commit b628fa9133
5 changed files with 64 additions and 69 deletions

View file

@ -260,3 +260,38 @@ Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
return extradata; return extradata;
} }
/*
=================
Mod_ReLoad
Reload images in SP2/MD2 (mark registration_sequence)
=================
*/
int
Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
modtype_t type)
{
if (type == mod_sprite)
{
dsprite_t *sprout;
int i;
sprout = (dsprite_t *)extradata;
for (i=0 ; i<sprout->numframes ; i++)
skins[i] = find_image (sprout->frames[i].name, it_sprite);
return sprout->numframes;
}
else if (type == mod_alias)
{
dmdl_t *pheader;
int i;
pheader = (dmdl_t *)extradata;
for (i=0 ; i<pheader->num_skins ; i++)
skins[i] = find_image ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
return pheader->num_frames;
}
// Unknow format, no images associated with it
return 0;
}

View file

@ -1126,9 +1126,6 @@ struct model_s *
RI_RegisterModel(char *name) RI_RegisterModel(char *name)
{ {
model_t *mod; model_t *mod;
int i;
dsprite_t *sprout;
dmdl_t *pheader;
mod = Mod_ForName(name, r_worldmodel, false); mod = Mod_ForName(name, r_worldmodel, false);
@ -1137,35 +1134,22 @@ RI_RegisterModel(char *name)
mod->registration_sequence = registration_sequence; mod->registration_sequence = registration_sequence;
/* register any images used by the models */ /* register any images used by the models */
if (mod->type == mod_sprite) if (mod->type == mod_brush)
{ {
sprout = (dsprite_t *)mod->extradata; int i;
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = R_FindImage(sprout->frames[i].name, it_sprite);
}
}
else if (mod->type == mod_alias)
{
pheader = (dmdl_t *)mod->extradata;
for (i = 0; i < pheader->num_skins; i++)
{
mod->skins[i] = R_FindImage((char *)pheader + pheader->ofs_skins +
i * MAX_SKINNAME, it_skin);
}
mod->numframes = pheader->num_frames;
}
else if (mod->type == mod_brush)
{
for (i = 0; i < mod->numtexinfo; i++) for (i = 0; i < mod->numtexinfo; i++)
{ {
mod->texinfo[i].image->registration_sequence = mod->texinfo[i].image->registration_sequence =
registration_sequence; registration_sequence;
} }
} }
else
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)R_FindImage, mod->extradata, mod->type);
}
} }
return mod; return mod;

View file

@ -1124,9 +1124,6 @@ struct model_s *
GL3_RegisterModel(char *name) GL3_RegisterModel(char *name)
{ {
gl3model_t *mod; gl3model_t *mod;
int i;
dsprite_t *sprout;
dmdl_t *pheader;
mod = Mod_ForName(name, gl3_worldmodel, false); mod = Mod_ForName(name, gl3_worldmodel, false);
@ -1135,33 +1132,21 @@ GL3_RegisterModel(char *name)
mod->registration_sequence = registration_sequence; mod->registration_sequence = registration_sequence;
/* register any images used by the models */ /* register any images used by the models */
if (mod->type == mod_sprite) if (mod->type == mod_brush)
{ {
sprout = (dsprite_t *)mod->extradata; int i;
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = GL3_FindImage(sprout->frames[i].name, it_sprite);
}
}
else if (mod->type == mod_alias)
{
pheader = (dmdl_t *)mod->extradata;
for (i = 0; i < pheader->num_skins; i++)
{
mod->skins[i] = GL3_FindImage((char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME, it_skin);
}
mod->numframes = pheader->num_frames;
}
else if (mod->type == mod_brush)
{
for (i = 0; i < mod->numtexinfo; i++) for (i = 0; i < mod->numtexinfo; i++)
{ {
mod->texinfo[i].image->registration_sequence = registration_sequence; mod->texinfo[i].image->registration_sequence = registration_sequence;
} }
} }
else
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)GL3_FindImage, mod->extradata, mod->type);
}
} }
return mod; return mod;

View file

@ -97,8 +97,10 @@ extern const byte* Mod_DecompressVis(const byte *in, int row);
typedef struct image_s* (*findimage_t)(char *name, imagetype_t type); typedef struct image_s* (*findimage_t)(char *name, imagetype_t type);
void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s **skins, vec3_t mins, vec3_t maxs, struct image_s **skins,
findimage_t findImage, modtype_t *type); findimage_t find_image, modtype_t *type);
void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen, extern void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
struct image_s **skins, findimage_t findImage, modtype_t *type); struct image_s **skins, findimage_t find_image, modtype_t *type);
extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image,
void *extradata, modtype_t type);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View file

@ -1108,33 +1108,22 @@ RE_RegisterModel (char *name)
mod = Mod_ForName (name, r_worldmodel, false); mod = Mod_ForName (name, r_worldmodel, false);
if (mod) if (mod)
{ {
int i;
mod->registration_sequence = registration_sequence; mod->registration_sequence = registration_sequence;
// register any images used by the models // register any images used by the models
if (mod->type == mod_sprite) if (mod->type == mod_brush)
{ {
dsprite_t *sprout; int i;
sprout = (dsprite_t *)mod->extradata;
for (i=0 ; i<sprout->numframes ; i++)
mod->skins[i] = R_FindImage (sprout->frames[i].name, it_sprite);
}
else if (mod->type == mod_alias)
{
dmdl_t *pheader;
pheader = (dmdl_t *)mod->extradata;
for (i=0 ; i<pheader->num_skins ; i++)
mod->skins[i] = R_FindImage ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
mod->numframes = pheader->num_frames;
}
else if (mod->type == mod_brush)
{
for (i=0 ; i<mod->numtexinfo ; i++) for (i=0 ; i<mod->numtexinfo ; i++)
mod->texinfo[i].image->registration_sequence = registration_sequence; mod->texinfo[i].image->registration_sequence = registration_sequence;
} }
else
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)R_FindImage, mod->extradata, mod->type);
}
} }
return mod; return mod;
} }