gl1,gl3,vk: sync code structure

This commit is contained in:
Denis Pauk 2023-09-26 00:58:06 +03:00
parent c4a31e42c9
commit e0f4da0103
3 changed files with 223 additions and 232 deletions

View file

@ -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)
{

View file

@ -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
*/

View file

@ -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 ; i<mod_numknown ; i++)
{
if (models_known[i].extradatasize)
Mod_Free (&models_known[i]);
}
}
void
Mod_FreeModelsKnown (void)
{
free(models_known);
models_known = NULL;
}
static void
Mod_LoadSubmodels (model_t *loadmodel, const byte *mod_base, const lump_t *l)
{
@ -1192,6 +1149,49 @@ Mod_ForName (const char *name, model_t *parent_model, qboolean crash)
return mod;
}
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 ; i<mod_numknown ; i++)
{
if (models_known[i].extradatasize)
Mod_Free (&models_known[i]);
}
}
void
Mod_FreeModelsKnown (void)
{
free(models_known);
models_known = NULL;
}
/*
* Specifies the model that will be used as the world
*/