From e0f4da0103522f25cf446980d9fbdc5c7731a98f Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 26 Sep 2023 00:58:06 +0300 Subject: [PATCH] gl1,gl3,vk: sync code structure --- src/client/refresh/gl1/gl1_model.c | 269 ++++++++++++++--------------- src/client/refresh/gl3/gl3_model.c | 100 +++++------ src/client/refresh/vk/vk_model.c | 86 ++++----- 3 files changed, 223 insertions(+), 232 deletions(-) diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 8ed19c42..481e006f 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -35,7 +35,6 @@ static int mod_numknown; static int mod_max = 0; int registration_sequence; -static void Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen); void LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa); void LM_CreateSurfaceLightmap(msurface_t *surf); void LM_EndBuildingLightmaps(void); @@ -127,140 +126,6 @@ Mod_Init(void) memset(mod_novis, 0xff, sizeof(mod_novis)); } -/* - * Loads in a model for the given name - */ -static model_t * -Mod_ForName (const char *name, model_t *parent_model, qboolean crash) -{ - model_t *mod; - void *buf; - int i; - - if (!name[0]) - { - ri.Sys_Error(ERR_DROP, "%s: NULL name", __func__); - } - - /* inline models are grabbed only from worldmodel */ - if (name[0] == '*' && parent_model) - { - i = (int)strtol(name + 1, (char **)NULL, 10); - - if (i < 1 || i >= parent_model->numsubmodels) - { - ri.Sys_Error(ERR_DROP, "%s: bad inline model number", - __func__); - } - - return &parent_model->submodels[i]; - } - - /* search the currently loaded models */ - for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) - { - if (!mod->name[0]) - { - continue; - } - - if (!strcmp(mod->name, name)) - { - return mod; - } - } - - /* find a free model slot spot */ - for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) - { - if (!mod->name[0]) - { - break; /* free spot */ - } - } - - if (i == mod_numknown) - { - if (mod_numknown == MAX_MOD_KNOWN) - { - ri.Sys_Error(ERR_DROP, "mod_numknown == MAX_MOD_KNOWN"); - } - - mod_numknown++; - } - - strcpy(mod->name, name); - - /* load the file */ - modfilelen = Mod_LoadFile (mod->name, &buf); - - if (!buf) - { - if (crash) - { - ri.Sys_Error(ERR_DROP, "%s: %s not found", - __func__, mod->name); - } - - memset(mod->name, 0, sizeof(mod->name)); - return NULL; - } - - /* call the apropriate loader */ - switch (LittleLong(*(unsigned *)buf)) - { - case DKMHEADER: - /* fall through */ - case RAVENFMHEADER: - /* fall through */ - case IDALIASHEADER: - /* fall through */ - case IDMDLHEADER: - { - mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen, - mod->mins, mod->maxs, - (struct image_s **)mod->skins, (findimage_t)R_FindImage, - &(mod->type)); - if (!mod->extradata) - { - ri.Sys_Error(ERR_DROP, "%s: Failed to load %s", - __func__, mod->name); - } - }; - break; - - case IDSPRITEHEADER: - { - mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen, - (struct image_s **)mod->skins, (findimage_t)R_FindImage, - &(mod->type)); - if (!mod->extradata) - { - ri.Sys_Error(ERR_DROP, "%s: Failed to load %s", - __func__, mod->name); - } - } - break; - - case IDBSPHEADER: - /* fall through */ - case QDBSPHEADER: - Mod_LoadBrushModel(mod, buf, modfilelen); - break; - - default: - ri.Sys_Error(ERR_DROP, "%s: unknown fileid for %s", - __func__, mod->name); - break; - } - - mod->extradatasize = Hunk_End(); - - ri.FS_FreeFile(buf); - - return mod; -} - static void Mod_LoadSubmodels (model_t *loadmodel, const byte *mod_base, const lump_t *l) { @@ -1147,6 +1012,140 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) mod->numframes = 2; /* regular and alternate animation */ } +/* + * Loads in a model for the given name + */ +static model_t * +Mod_ForName (const char *name, model_t *parent_model, qboolean crash) +{ + model_t *mod; + void *buf; + int i; + + if (!name[0]) + { + ri.Sys_Error(ERR_DROP, "%s: NULL name", __func__); + } + + /* inline models are grabbed only from worldmodel */ + if (name[0] == '*' && parent_model) + { + i = (int)strtol(name + 1, (char **)NULL, 10); + + if (i < 1 || i >= parent_model->numsubmodels) + { + ri.Sys_Error(ERR_DROP, "%s: bad inline model number", + __func__); + } + + return &parent_model->submodels[i]; + } + + /* search the currently loaded models */ + for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) + { + if (!mod->name[0]) + { + continue; + } + + if (!strcmp(mod->name, name)) + { + return mod; + } + } + + /* find a free model slot spot */ + for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) + { + if (!mod->name[0]) + { + break; /* free spot */ + } + } + + if (i == mod_numknown) + { + if (mod_numknown == MAX_MOD_KNOWN) + { + ri.Sys_Error(ERR_DROP, "mod_numknown == MAX_MOD_KNOWN"); + } + + mod_numknown++; + } + + strcpy(mod->name, name); + + /* load the file */ + modfilelen = Mod_LoadFile (mod->name, &buf); + + if (!buf) + { + if (crash) + { + ri.Sys_Error(ERR_DROP, "%s: %s not found", + __func__, mod->name); + } + + memset(mod->name, 0, sizeof(mod->name)); + return NULL; + } + + /* call the apropriate loader */ + switch (LittleLong(*(unsigned *)buf)) + { + case DKMHEADER: + /* fall through */ + case RAVENFMHEADER: + /* fall through */ + case IDALIASHEADER: + /* fall through */ + case IDMDLHEADER: + { + mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen, + mod->mins, mod->maxs, + (struct image_s **)mod->skins, (findimage_t)R_FindImage, + &(mod->type)); + if (!mod->extradata) + { + ri.Sys_Error(ERR_DROP, "%s: Failed to load %s", + __func__, mod->name); + } + }; + break; + + case IDSPRITEHEADER: + { + mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen, + (struct image_s **)mod->skins, (findimage_t)R_FindImage, + &(mod->type)); + if (!mod->extradata) + { + ri.Sys_Error(ERR_DROP, "%s: Failed to load %s", + __func__, mod->name); + } + } + break; + + case IDBSPHEADER: + /* fall through */ + case QDBSPHEADER: + Mod_LoadBrushModel(mod, buf, modfilelen); + break; + + default: + ri.Sys_Error(ERR_DROP, "%s: unknown fileid for %s", + __func__, mod->name); + break; + } + + mod->extradatasize = Hunk_End(); + + ri.FS_FreeFile(buf); + + return mod; +} + void Mod_Free(model_t *mod) { diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 0b105fbd..7fd625cb 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -397,7 +397,29 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t } static void -Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) +SetSurfaceLighting(gl3model_t *loadmodel, msurface_t *out, byte *styles, int lightofs) +{ + int i; + + /* lighting info */ + for (i = 0; i < MAX_LIGHTMAPS_PER_SURFACE; i++) + { + out->styles[i] = styles[i]; + } + + i = LittleLong(lightofs); + if (i == -1 || loadmodel->lightdata == NULL) + { + out->samples = NULL; + } + else + { + out->samples = loadmodel->lightdata + i; + } +} + +static void +Mod_LoadFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l) { int i, count, surfnum; msurface_t *out; @@ -462,22 +484,7 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) Mod_CalcSurfaceExtents(loadmodel, out); - /* lighting info */ - for (i = 0; i < MAX_LIGHTMAPS_PER_SURFACE; i++) - { - out->styles[i] = in->styles[i]; - } - - i = LittleLong(in->lightofs); - - if (i == -1) - { - out->samples = NULL; - } - else - { - out->samples = loadmodel->lightdata + i; - } + SetSurfaceLighting(loadmodel, out, in->styles, in->lightofs); /* set the drawing flags */ if (out->texinfo->flags & SURF_WARP) @@ -582,22 +589,7 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l) Mod_CalcSurfaceExtents(loadmodel, out); - /* lighting info */ - for (i = 0; i < MAX_LIGHTMAPS_PER_SURFACE; i++) - { - out->styles[i] = in->styles[i]; - } - - i = LittleLong(in->lightofs); - - if (i == -1) - { - out->samples = NULL; - } - else - { - out->samples = loadmodel->lightdata + i; - } + SetSurfaceLighting(loadmodel, out, in->styles, in->lightofs); /* set the drawing flags */ if (out->texinfo->flags & SURF_WARP) @@ -936,27 +928,6 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int modfilelen) mod->numframes = 2; /* regular and alternate animation */ } -static void -Mod_Free(gl3model_t *mod) -{ - Hunk_Free(mod->extradata); - memset(mod, 0, sizeof(*mod)); -} - -void -GL3_Mod_FreeAll(void) -{ - int i; - - for (i = 0; i < mod_numknown; i++) - { - if (mod_known[i].extradatasize) - { - Mod_Free(&mod_known[i]); - } - } -} - /* * Loads in a model for the given name */ @@ -1091,6 +1062,27 @@ Mod_ForName (const char *name, gl3model_t *parent_model, qboolean crash) return mod; } +static void +Mod_Free(gl3model_t *mod) +{ + Hunk_Free(mod->extradata); + memset(mod, 0, sizeof(*mod)); +} + +void +GL3_Mod_FreeAll(void) +{ + int i; + + for (i = 0; i < mod_numknown; i++) + { + if (mod_known[i].extradatasize) + { + Mod_Free(&mod_known[i]); + } + } +} + /* * Specifies the model that will be used as the world */ diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 6195b6fe..60bc4301 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -96,49 +96,6 @@ Mod_Init(void) Mod_Reallocate (); } -static void -Mod_Free(model_t *mod) -{ - if (!mod->extradata) - { - // looks as empty model - memset (mod, 0, sizeof(*mod)); - return; - } - - if (r_validation->value > 0) - { - R_Printf(PRINT_ALL, "%s: Unload %s[%d]\n", __func__, mod->name, mod_loaded); - } - - Hunk_Free (mod->extradata); - memset (mod, 0, sizeof(*mod)); - mod_loaded --; - if (mod_loaded < 0) - { - ri.Sys_Error (ERR_DROP, "%s: Broken unload", __func__); - } -} - -void -Mod_FreeAll (void) -{ - int i; - - for (i=0 ; iextradata) + { + // looks as empty model + memset (mod, 0, sizeof(*mod)); + return; + } + + if (r_validation->value > 0) + { + R_Printf(PRINT_ALL, "%s: Unload %s[%d]\n", __func__, mod->name, mod_loaded); + } + + Hunk_Free (mod->extradata); + memset (mod, 0, sizeof(*mod)); + mod_loaded --; + if (mod_loaded < 0) + { + ri.Sys_Error (ERR_DROP, "%s: Broken unload", __func__); + } +} + +void +Mod_FreeAll (void) +{ + int i; + + for (i=0 ; i