renders: models load code cleanup

This commit is contained in:
Denis Pauk 2025-04-06 00:11:25 +03:00
parent 8e054bfc3e
commit 00384e4021
10 changed files with 24 additions and 216 deletions

View file

@ -526,6 +526,9 @@ set(Client-Source
${COMMON_SRC_DIR}/md4.c
${COMMON_SRC_DIR}/movemsg.c
${COMMON_SRC_DIR}/models/loadfile.c
${COMMON_SRC_DIR}/models/models.c
${COMMON_SRC_DIR}/models/models_md5.c
${COMMON_SRC_DIR}/models/models_mdr.c
${COMMON_SRC_DIR}/frame.c
${COMMON_SRC_DIR}/netchan.c
${COMMON_SRC_DIR}/pmove.c
@ -588,6 +591,8 @@ set(Client-Header
${COMMON_SRC_DIR}/header/glob.h
${COMMON_SRC_DIR}/header/shared.h
${COMMON_SRC_DIR}/header/zone.h
${COMMON_SRC_DIR}/models/anorms.h
${COMMON_SRC_DIR}/models/models.h
${COMMON_SRC_DIR}/unzip/ioapi.h
${COMMON_SRC_DIR}/unzip/unzip.h
${COMMON_SRC_DIR}/unzip/miniz/miniz.h
@ -608,6 +613,10 @@ set(Server-Source
${COMMON_SRC_DIR}/filesystem.c
${COMMON_SRC_DIR}/glob.c
${COMMON_SRC_DIR}/maps.c
${COMMON_SRC_DIR}/models/loadfile.c
${COMMON_SRC_DIR}/models/models.c
${COMMON_SRC_DIR}/models/models_md5.c
${COMMON_SRC_DIR}/models/models_mdr.c
${COMMON_SRC_DIR}/md4.c
${COMMON_SRC_DIR}/frame.c
${COMMON_SRC_DIR}/movemsg.c
@ -644,6 +653,8 @@ set(Server-Header
${COMMON_SRC_DIR}/header/zone.h
${COMMON_SRC_DIR}/unzip/ioapi.h
${COMMON_SRC_DIR}/unzip/unzip.h
${COMMON_SRC_DIR}/models/anorms.h
${COMMON_SRC_DIR}/models/models.h
${COMMON_SRC_DIR}/unzip/miniz/miniz.h
${COMMON_SRC_DIR}/unzip/miniz/miniz_tdef.h
${COMMON_SRC_DIR}/unzip/miniz/miniz_tinfl.h
@ -670,8 +681,6 @@ set(GL1-Source
${REF_SRC_DIR}/files/maps.c
${REF_SRC_DIR}/files/mesh.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/models_md5.c
${REF_SRC_DIR}/files/models_mdr.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c
@ -686,7 +695,6 @@ set(Glad-GLES1-Source ${REF_SRC_DIR}/gl1/glad-gles1/src/glad.c)
set(GL1-Header
${REF_SRC_DIR}/ref_shared.h
${REF_SRC_DIR}/constants/anorms.h
${REF_SRC_DIR}/constants/anormtab.h
${REF_SRC_DIR}/constants/warpsin.h
${REF_SRC_DIR}/files/stb_image.h
@ -720,8 +728,6 @@ set(GL3-Source
${REF_SRC_DIR}/files/maps.c
${REF_SRC_DIR}/files/mesh.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/models_md5.c
${REF_SRC_DIR}/files/models_mdr.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c
@ -737,7 +743,6 @@ set(Glad-GLES3-Source ${REF_SRC_DIR}/gl3/glad-gles3/src/glad.c)
set(GL3-Header
${REF_SRC_DIR}/ref_shared.h
${REF_SRC_DIR}/constants/anorms.h
${REF_SRC_DIR}/constants/anormtab.h
${REF_SRC_DIR}/constants/warpsin.h
${REF_SRC_DIR}/files/stb_image.h
@ -776,8 +781,6 @@ set(GL4-Source
${REF_SRC_DIR}/files/maps.c
${REF_SRC_DIR}/files/mesh.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/models_md5.c
${REF_SRC_DIR}/files/models_mdr.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c
@ -792,7 +795,6 @@ set(Glad-GL4-Source ${REF_SRC_DIR}/gl4/glad/src/glad.c)
set(GL4-Header
${REF_SRC_DIR}/ref_shared.h
${REF_SRC_DIR}/constants/anorms.h
${REF_SRC_DIR}/constants/anormtab.h
${REF_SRC_DIR}/constants/warpsin.h
${REF_SRC_DIR}/files/stb_image.h
@ -831,8 +833,6 @@ set(SOFT-Source
${REF_SRC_DIR}/files/maps.c
${REF_SRC_DIR}/files/mesh.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/models_md5.c
${REF_SRC_DIR}/files/models_mdr.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c
@ -877,8 +877,6 @@ set(VK-Source
${REF_SRC_DIR}/files/maps.c
${REF_SRC_DIR}/files/mesh.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/models_md5.c
${REF_SRC_DIR}/files/models_mdr.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c

View file

@ -149,6 +149,7 @@ Goals, fully finished goals could be checked in [here](CHANGELOG):
* [ ] Anachronox: rowdys map models disappear on dance space,
* [ ] Anachronox: CTC entity format,
* [ ] Anachronox: Support material load textures/textureinfo.dat,
* [ ] soft: fix crash with md5 models in player model select and ASAN=1
* [ ] soft: q64/outpost scale textures unsupported,
* [ ] soft: broken wall light and wall glitch,
* [ ] soft: build with SDL3 has glitch in menu,
@ -159,7 +160,9 @@ Goals, fully finished goals could be checked in [here](CHANGELOG):
* [ ] DoD: Fix statusbar `roarke`,
* [ ] vulkan: Group `it_pic` images,
* [ ] vulkan: Rearange surfaces before render,
* [ ] Use shared model cache in client code insted reimplemnet in each render,
* [x] Use shared model cache in client code insted reimplement in each render,
* [ ] reuse memory from models cache in renders model list,
* [ ] reuse memory from models cache for bsp,
* [ ] Fix transparent textures in Daikatana/SiN maps,
* [ ] game: Cleanup function declarations in game save code,
* [ ] game: Fix broken base3 with sorted fields names,

View file

@ -211,8 +211,7 @@ Mod_LoadModel
void *
Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, loadimage_t load_image, readfile_t read_file,
modtype_t *type)
findimage_t find_image, loadimage_t load_image, modtype_t *type)
{
void *extradata;

View file

@ -407,26 +407,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
}
}
/* Temporary solution, need to use load file dirrectly */
static int
Mod_ReadFile(const char *path, void **buffer)
{
char *data;
int size;
size = ri.FS_LoadFile(path, (void **)&data);
if (size <= 0)
{
return size;
}
*buffer = malloc(size);
memcpy(*buffer, data, size);
ri.FS_FreeFile((void *)data);
return size;
}
/*
* Loads in a model for the given name
*/
@ -525,32 +505,14 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
/* call the apropriate loader */
switch (LittleLong(*(unsigned *)buf))
{
case MDAHEADER:
/* fall through */
case SDEFHEADER:
/* fall through */
case MDXHEADER:
/* fall through */
case DKMHEADER:
/* fall through */
case RAVENFMHEADER:
/* fall through */
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case ID3HEADER:
/* fall through */
case MDR_IDENT:
/* fall through */
case IDMD5HEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic, Mod_ReadFile,
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
&(mod->type));
if (!mod->extradata)
{

View file

@ -408,26 +408,6 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int modfilelen)
}
}
/* Temporary solution, need to use load file dirrectly */
static int
Mod_ReadFile(const char *path, void **buffer)
{
char *data;
int size;
size = ri.FS_LoadFile(path, (void **)&data);
if (size <= 0)
{
return size;
}
*buffer = malloc(size);
memcpy(*buffer, data, size);
ri.FS_FreeFile((void *)data);
return size;
}
/*
* Loads in a model for the given name
*/
@ -526,32 +506,14 @@ Mod_ForName(const char *name, gl3model_t *parent_model, qboolean crash)
/* call the apropriate loader */
switch (LittleLong(*(unsigned *)buf))
{
case MDAHEADER:
/* fall through */
case SDEFHEADER:
/* fall through */
case MDXHEADER:
/* fall through */
case DKMHEADER:
/* fall through */
case RAVENFMHEADER:
/* fall through */
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case ID3HEADER:
/* fall through */
case MDR_IDENT:
/* fall through */
case IDMD5HEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL3_FindImage, (loadimage_t)GL3_LoadPic, Mod_ReadFile,
(findimage_t)GL3_FindImage, (loadimage_t)GL3_LoadPic,
&(mod->type));
if (!mod->extradata)
{

View file

@ -408,26 +408,6 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int modfilelen)
}
}
/* Temporary solution, need to use load file dirrectly */
static int
Mod_ReadFile(const char *path, void **buffer)
{
char *data;
int size;
size = ri.FS_LoadFile(path, (void **)&data);
if (size <= 0)
{
return size;
}
*buffer = malloc(size);
memcpy(*buffer, data, size);
ri.FS_FreeFile((void *)data);
return size;
}
/*
* Loads in a model for the given name
*/
@ -526,32 +506,14 @@ Mod_ForName(const char *name, gl4model_t *parent_model, qboolean crash)
/* call the apropriate loader */
switch (LittleLong(*(unsigned *)buf))
{
case MDAHEADER:
/* fall through */
case SDEFHEADER:
/* fall through */
case MDXHEADER:
/* fall through */
case DKMHEADER:
/* fall through */
case RAVENFMHEADER:
/* fall through */
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case ID3HEADER:
/* fall through */
case MDR_IDENT:
/* fall through */
case IDMD5HEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL4_FindImage, (loadimage_t)GL4_LoadPic, Mod_ReadFile,
(findimage_t)GL4_FindImage, (loadimage_t)GL4_LoadPic,
&(mod->type));
if (!mod->extradata)
{

View file

@ -315,12 +315,10 @@ typedef struct
} bspxlightgrid_t;
/* Shared models func */
typedef int (*readfile_t)(const char *path, void **buffer);
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, loadimage_t load_image, readfile_t read_file,
modtype_t *type);
findimage_t find_image, loadimage_t load_image, modtype_t *type);
extern int Mod_ReLoadSkins(const char *name, struct image_s **skins, findimage_t find_image,
loadimage_t load_image, void *extradata, modtype_t type);
extern struct image_s *GetSkyImage(const char *skyname, const char* surfname,

View file

@ -415,26 +415,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
R_InitSkyBox(mod);
}
/* Temporary solution, need to use load file dirrectly */
static int
Mod_ReadFile(const char *path, void **buffer)
{
char *data;
int size;
size = ri.FS_LoadFile(path, (void **)&data);
if (size <= 0)
{
return size;
}
*buffer = malloc(size);
memcpy(*buffer, data, size);
ri.FS_FreeFile((void *)data);
return size;
}
/*
* Loads in a model for the given name
*/
@ -533,32 +513,14 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
/* call the apropriate loader */
switch (LittleLong(*(unsigned *)buf))
{
case MDAHEADER:
/* fall through */
case SDEFHEADER:
/* fall through */
case MDXHEADER:
/* fall through */
case DKMHEADER:
/* fall through */
case RAVENFMHEADER:
/* fall through */
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case ID3HEADER:
/* fall through */
case MDR_IDENT:
/* fall through */
case IDMD5HEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic, Mod_ReadFile,
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
&(mod->type));
if (!mod->extradata)
{

View file

@ -382,26 +382,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen)
}
}
/* Temporary solution, need to use load file dirrectly */
static int
Mod_ReadFile(const char *path, void **buffer)
{
char *data;
int size;
size = ri.FS_LoadFile(path, (void **)&data);
if (size <= 0)
{
return size;
}
*buffer = malloc(size);
memcpy(*buffer, data, size);
ri.FS_FreeFile((void *)data);
return size;
}
/*
* Loads in a model for the given name
*/
@ -509,32 +489,14 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
/* call the apropriate loader */
switch (LittleLong(*(unsigned *)buf))
{
case MDAHEADER:
/* fall through */
case SDEFHEADER:
/* fall through */
case MDXHEADER:
/* fall through */
case DKMHEADER:
/* fall through */
case RAVENFMHEADER:
/* fall through */
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case ID3HEADER:
/* fall through */
case MDR_IDENT:
/* fall through */
case IDMD5HEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)Vk_FindImage, (loadimage_t)Vk_LoadPic, Mod_ReadFile,
(findimage_t)Vk_FindImage, (loadimage_t)Vk_LoadPic,
&(mod->type));
if (!mod->extradata)
{

View file

@ -512,7 +512,7 @@ Mod_LoadFile(const char *name, void **buffer)
for (i = 0; i < MAX_MOD_KNOWN; i++)
{
if (!strcmp(namewe, mod_known[i].name))
if (!strcmp(name, mod_known[i].name))
{
*buffer = Z_Malloc(mod_known[i].extradatasize);
memcpy(*buffer, mod_known[i].extradata, mod_known[i].extradatasize);
@ -552,7 +552,7 @@ Mod_LoadFile(const char *name, void **buffer)
}
/* save and convert */
mod = Mod_AliasSave(namewe, filesize, *buffer);
mod = Mod_AliasSave(name, filesize, *buffer);
if (mod)
{
/* free old buffer */