Share MD2/SP2 files

This commit is contained in:
Denis Pauk 2022-09-25 22:51:12 +03:00
parent caab3864c6
commit ae13c7e034
11 changed files with 489 additions and 736 deletions

View File

@ -571,8 +571,7 @@ set(GL1-Source
${REF_SRC_DIR}/gl1/gl1_surf.c
${REF_SRC_DIR}/gl1/gl1_warp.c
${REF_SRC_DIR}/gl1/gl1_sdl.c
${REF_SRC_DIR}/gl1/gl1_md2.c
${REF_SRC_DIR}/gl1/gl1_sp2.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/pcx.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/wal.c
@ -606,8 +605,7 @@ set(GL3-Source
${REF_SRC_DIR}/gl3/gl3_surf.c
${REF_SRC_DIR}/gl3/gl3_warp.c
${REF_SRC_DIR}/gl3/gl3_shaders.c
${REF_SRC_DIR}/gl3/gl3_md2.c
${REF_SRC_DIR}/gl3/gl3_sp2.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/pcx.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/wal.c
@ -660,6 +658,7 @@ set(SOFT-Source
${REF_SRC_DIR}/soft/sw_scan.c
${REF_SRC_DIR}/soft/sw_sprite.c
${REF_SRC_DIR}/soft/sw_surf.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/pcx.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/wal.c

View File

@ -927,8 +927,7 @@ REFGL1_OBJS_ := \
src/client/refresh/gl1/gl1_surf.o \
src/client/refresh/gl1/gl1_warp.o \
src/client/refresh/gl1/gl1_sdl.o \
src/client/refresh/gl1/gl1_md2.o \
src/client/refresh/gl1/gl1_sp2.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
src/client/refresh/files/wal.o \
@ -959,8 +958,7 @@ REFGL3_OBJS_ := \
src/client/refresh/gl3/gl3_surf.o \
src/client/refresh/gl3/gl3_warp.o \
src/client/refresh/gl3/gl3_shaders.o \
src/client/refresh/gl3/gl3_md2.o \
src/client/refresh/gl3/gl3_sp2.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
src/client/refresh/files/wal.o \
@ -1002,6 +1000,7 @@ REFSOFT_OBJS_ := \
src/client/refresh/soft/sw_scan.o \
src/client/refresh/soft/sw_sprite.o \
src/client/refresh/soft/sw_surf.o \
src/client/refresh/files/models.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
src/client/refresh/files/wal.o \

View File

@ -0,0 +1,239 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* The models file format
*
* =======================================================================
*/
#include "../ref_shared.h"
/*
=================
Mod_LoadAliasModel/Mod_LoadMD2
=================
*/
dmdl_t *
Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, void **extradata)
{
int i, j;
dmdl_t *pinmodel, *pheader;
dstvert_t *pinst, *poutst;
dtriangle_t *pintri, *pouttri;
int *pincmd, *poutcmd;
int version;
int ofs_end;
pinmodel = (dmdl_t *)buffer;
version = LittleLong (pinmodel->version);
if (version != ALIAS_VERSION)
{
R_Printf(PRINT_ALL, "%s: %s has wrong version number (%i should be %i)",
__func__, mod_name, version, ALIAS_VERSION);
return NULL;
}
ofs_end = LittleLong(pinmodel->ofs_end);
if (ofs_end < 0 || ofs_end > modfilelen)
{
R_Printf(PRINT_ALL, "%s: model %s file size(%d) too small, should be %d",
__func__, mod_name, modfilelen, ofs_end);
return NULL;
}
*extradata = Hunk_Begin(modfilelen);
pheader = Hunk_Alloc(ofs_end);
// byte swap the header fields and sanity check
for (i=0 ; i<sizeof(dmdl_t)/sizeof(int) ; i++)
((int *)pheader)[i] = LittleLong (((int *)buffer)[i]);
if (pheader->skinheight > MAX_LBM_HEIGHT)
{
R_Printf(PRINT_ALL, "%s: model %s has a skin taller than %d",
__func__, mod_name, MAX_LBM_HEIGHT);
return NULL;
}
if (pheader->num_xyz <= 0)
{
R_Printf(PRINT_ALL, "%s: model %s has no vertices",
__func__, mod_name);
return NULL;
}
if (pheader->num_xyz > MAX_VERTS)
{
R_Printf(PRINT_ALL, "%s: model %s has too many vertices",
__func__, mod_name);
return NULL;
}
if (pheader->num_st <= 0)
{
R_Printf(PRINT_ALL, "%s: model %s has no st vertices",
__func__, mod_name);
return NULL;
}
if (pheader->num_tris <= 0)
{
R_Printf(PRINT_ALL, "%s: model %s has no triangles",
__func__, mod_name);
return NULL;
}
if (pheader->num_frames <= 0)
{
R_Printf(PRINT_ALL, "%s: model %s has no frames",
__func__, mod_name);
return NULL;
}
//
// load base s and t vertices (not used in gl version)
//
pinst = (dstvert_t *) ((byte *)pinmodel + pheader->ofs_st);
poutst = (dstvert_t *) ((byte *)pheader + pheader->ofs_st);
for (i=0 ; i<pheader->num_st ; i++)
{
poutst[i].s = LittleShort (pinst[i].s);
poutst[i].t = LittleShort (pinst[i].t);
}
//
// load triangle lists
//
pintri = (dtriangle_t *) ((byte *)pinmodel + pheader->ofs_tris);
pouttri = (dtriangle_t *) ((byte *)pheader + pheader->ofs_tris);
for (i=0 ; i<pheader->num_tris ; i++)
{
for (j=0 ; j<3 ; j++)
{
pouttri[i].index_xyz[j] = LittleShort (pintri[i].index_xyz[j]);
pouttri[i].index_st[j] = LittleShort (pintri[i].index_st[j]);
}
}
//
// load the frames
//
for (i=0 ; i<pheader->num_frames ; i++)
{
daliasframe_t *pinframe, *poutframe;
pinframe = (daliasframe_t *) ((byte *)pinmodel
+ pheader->ofs_frames + i * pheader->framesize);
poutframe = (daliasframe_t *) ((byte *)pheader
+ pheader->ofs_frames + i * pheader->framesize);
memcpy (poutframe->name, pinframe->name, sizeof(poutframe->name));
for (j=0 ; j<3 ; j++)
{
poutframe->scale[j] = LittleFloat (pinframe->scale[j]);
poutframe->translate[j] = LittleFloat (pinframe->translate[j]);
}
// verts are all 8 bit, so no swapping needed
memcpy (poutframe->verts, pinframe->verts,
pheader->num_xyz*sizeof(dtrivertx_t));
}
//
// load the glcmds
//
pincmd = (int *) ((byte *)pinmodel + pheader->ofs_glcmds);
poutcmd = (int *) ((byte *)pheader + pheader->ofs_glcmds);
for (i=0; i < pheader->num_glcmds; i++)
{
poutcmd[i] = LittleLong (pincmd[i]);
}
if (poutcmd[pheader->num_glcmds-1] != 0)
{
R_Printf(PRINT_ALL, "%s: Entity %s has possible last element issues with %d verts.\n",
__func__, mod_name, poutcmd[pheader->num_glcmds-1]);
}
// register all skins
memcpy ((char *)pheader + pheader->ofs_skins, (char *)pinmodel + pheader->ofs_skins,
pheader->num_skins*MAX_SKINNAME);
return pheader;
}
/*
==============================================================================
SPRITE MODELS
==============================================================================
*/
/*
=================
Mod_LoadSP2
support for .sp2 sprites
====
*/
dsprite_t*
Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen, void **extradata)
{
dsprite_t *sprin, *sprout;
int i;
sprin = (dsprite_t *)buffer;
*extradata = Hunk_Begin(modfilelen);
sprout = Hunk_Alloc(modfilelen);
sprout->ident = LittleLong(sprin->ident);
sprout->version = LittleLong(sprin->version);
sprout->numframes = LittleLong(sprin->numframes);
if (sprout->version != SPRITE_VERSION)
{
R_Printf(PRINT_ALL, "%s has wrong version number (%i should be %i)",
mod_name, sprout->version, SPRITE_VERSION);
return NULL;
}
if (sprout->numframes > MAX_MD2SKINS)
{
R_Printf(PRINT_ALL, "%s has too many frames (%i > %i)",
mod_name, sprout->numframes, MAX_MD2SKINS);
return NULL;
}
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
sprout->frames[i].width = LittleLong(sprin->frames[i].width);
sprout->frames[i].height = LittleLong(sprin->frames[i].height);
sprout->frames[i].origin_x = LittleLong(sprin->frames[i].origin_x);
sprout->frames[i].origin_y = LittleLong(sprin->frames[i].origin_y);
memcpy(sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
}
return sprout;
}

View File

@ -1,178 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* MD2 file format
*
* =======================================================================
*/
#include "header/local.h"
void
LoadMD2(model_t *mod, void *buffer, int modfilelen)
{
int i, j;
dmdl_t *pinmodel, *pheader;
dstvert_t *pinst, *poutst;
dtriangle_t *pintri, *pouttri;
daliasframe_t *pinframe, *poutframe;
int *pincmd, *poutcmd;
int version;
int ofs_end;
pinmodel = (dmdl_t *)buffer;
version = LittleLong(pinmodel->version);
if (version != ALIAS_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s has wrong version number (%i should be %i)",
mod->name, version, ALIAS_VERSION);
}
ofs_end = LittleLong(pinmodel->ofs_end);
if (ofs_end < 0 || ofs_end > modfilelen)
ri.Sys_Error (ERR_DROP, "model %s file size(%d) too small, should be %d", mod->name,
modfilelen, ofs_end);
mod->extradata = Hunk_Begin(modfilelen);
pheader = Hunk_Alloc(ofs_end);
/* byte swap the header fields and sanity check */
for (i = 0; i < sizeof(dmdl_t) / 4; i++)
{
((int *)pheader)[i] = LittleLong(((int *)buffer)[i]);
}
if (pheader->skinheight > MAX_LBM_HEIGHT)
{
ri.Sys_Error(ERR_DROP, "model %s has a skin taller than %d", mod->name,
MAX_LBM_HEIGHT);
}
if (pheader->num_xyz <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no vertices", mod->name);
}
if (pheader->num_xyz > MAX_VERTS)
{
ri.Sys_Error(ERR_DROP, "model %s has too many vertices", mod->name);
}
if (pheader->num_st <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no st vertices", mod->name);
}
if (pheader->num_tris <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no triangles", mod->name);
}
if (pheader->num_frames <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no frames", mod->name);
}
/* load base s and t vertices (not used in gl version) */
pinst = (dstvert_t *)((byte *)pinmodel + pheader->ofs_st);
poutst = (dstvert_t *)((byte *)pheader + pheader->ofs_st);
for (i = 0; i < pheader->num_st; i++)
{
poutst[i].s = LittleShort(pinst[i].s);
poutst[i].t = LittleShort(pinst[i].t);
}
/* load triangle lists */
pintri = (dtriangle_t *)((byte *)pinmodel + pheader->ofs_tris);
pouttri = (dtriangle_t *)((byte *)pheader + pheader->ofs_tris);
for (i = 0; i < pheader->num_tris; i++)
{
for (j = 0; j < 3; j++)
{
pouttri[i].index_xyz[j] = LittleShort(pintri[i].index_xyz[j]);
pouttri[i].index_st[j] = LittleShort(pintri[i].index_st[j]);
}
}
/* load the frames */
for (i = 0; i < pheader->num_frames; i++)
{
pinframe = (daliasframe_t *)((byte *)pinmodel
+ pheader->ofs_frames + i * pheader->framesize);
poutframe = (daliasframe_t *)((byte *)pheader
+ pheader->ofs_frames + i * pheader->framesize);
memcpy(poutframe->name, pinframe->name, sizeof(poutframe->name));
for (j = 0; j < 3; j++)
{
poutframe->scale[j] = LittleFloat(pinframe->scale[j]);
poutframe->translate[j] = LittleFloat(pinframe->translate[j]);
}
/* verts are all 8 bit, so no swapping needed */
memcpy(poutframe->verts, pinframe->verts,
pheader->num_xyz * sizeof(dtrivertx_t));
}
mod->type = mod_alias;
/* load the glcmds */
pincmd = (int *)((byte *)pinmodel + pheader->ofs_glcmds);
poutcmd = (int *)((byte *)pheader + pheader->ofs_glcmds);
for (i = 0; i < pheader->num_glcmds; i++)
{
poutcmd[i] = LittleLong(pincmd[i]);
}
if (poutcmd[pheader->num_glcmds-1] != 0)
{
R_Printf(PRINT_ALL, "%s: Entity %s has possible last element issues with %d verts.\n",
__func__,
mod->name,
poutcmd[pheader->num_glcmds-1]);
}
/* register all skins */
memcpy((char *)pheader + pheader->ofs_skins,
(char *)pinmodel + pheader->ofs_skins,
pheader->num_skins * MAX_SKINNAME);
for (i = 0; i < pheader->num_skins; i++)
{
mod->skins[i] = R_FindImage(
(char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME,
it_skin);
}
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
}

View File

@ -35,9 +35,7 @@ static int mod_numknown;
static int mod_max = 0;
int registration_sequence;
void LoadSP2(model_t *mod, void *buffer, int modfilelen);
static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen);
void LoadMD2(model_t *mod, void *buffer, int modfilelen);
void LM_BuildPolygonFromSurface(model_t *currentmodel, msurface_t *fa);
void LM_CreateSurfaceLightmap(msurface_t *surf);
void LM_EndBuildingLightmaps(void);
@ -166,6 +164,58 @@ Mod_Init(void)
memset(mod_novis, 0xff, sizeof(mod_novis));
}
/*
=================
Mod_AliasModelFixup
=================
*/
static void
Mod_AliasModelFixup(model_t *mod, const dmdl_t *pheader)
{
mod->type = mod_alias;
if (pheader)
{
int i;
for (i=0 ; i<pheader->num_skins ; i++)
{
mod->skins[i] = R_FindImage((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
}
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
}
/*
=================
Mod_SP2Fixup
=================
*/
static void
Mod_SP2Fixup(model_t *mod, const dsprite_t *sprout)
{
mod->type = mod_sprite;
if (sprout)
{
int i;
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = R_FindImage(sprout->frames[i].name,
it_sprite);
}
}
}
/*
* Loads in a model for the given name
*/
@ -173,7 +223,7 @@ static model_t *
Mod_ForName (char *name, model_t *parent_model, qboolean crash)
{
model_t *mod;
unsigned *buf;
void *buf;
int i;
if (!name[0])
@ -249,11 +299,32 @@ Mod_ForName (char *name, model_t *parent_model, qboolean crash)
switch (LittleLong(*(unsigned *)buf))
{
case IDALIASHEADER:
LoadMD2(mod, buf, modfilelen);
{
const dmdl_t *pheader;
pheader = Mod_LoadMD2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_AliasModelFixup(mod, pheader);
};
break;
case IDSPRITEHEADER:
LoadSP2(mod, buf, modfilelen);
{
const dsprite_t *pheader;
pheader = Mod_LoadSP2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_SP2Fixup(mod, pheader);
}
break;
case IDBSPHEADER:

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* .sp2 sprites
*
* =======================================================================
*/
#include "header/local.h"
void
LoadSP2(model_t *mod, void *buffer, int modfilelen)
{
dsprite_t *sprin, *sprout;
int i;
sprin = (dsprite_t *)buffer;
mod->extradata = Hunk_Begin(modfilelen);
sprout = Hunk_Alloc(modfilelen);
sprout->ident = LittleLong(sprin->ident);
sprout->version = LittleLong(sprin->version);
sprout->numframes = LittleLong(sprin->numframes);
if (sprout->version != SPRITE_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s has wrong version number (%i should be %i)",
mod->name, sprout->version, SPRITE_VERSION);
}
if (sprout->numframes > MAX_MD2SKINS)
{
ri.Sys_Error(ERR_DROP, "%s has too many frames (%i > %i)",
mod->name, sprout->numframes, MAX_MD2SKINS);
}
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
sprout->frames[i].width = LittleLong(sprin->frames[i].width);
sprout->frames[i].height = LittleLong(sprin->frames[i].height);
sprout->frames[i].origin_x = LittleLong(sprin->frames[i].origin_x);
sprout->frames[i].origin_y = LittleLong(sprin->frames[i].origin_y);
memcpy(sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
mod->skins[i] = R_FindImage(sprout->frames[i].name,
it_sprite);
}
mod->type = mod_sprite;
}

View File

@ -1,178 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* MD2 file format
*
* =======================================================================
*/
#include "header/local.h"
void
GL3_LoadMD2(gl3model_t *mod, void *buffer, int modfilelen)
{
int i, j;
dmdl_t *pinmodel, *pheader;
dstvert_t *pinst, *poutst;
dtriangle_t *pintri, *pouttri;
daliasframe_t *pinframe, *poutframe;
int *pincmd, *poutcmd;
int version;
int ofs_end;
pinmodel = (dmdl_t *)buffer;
version = LittleLong(pinmodel->version);
if (version != ALIAS_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s has wrong version number (%i should be %i)",
mod->name, version, ALIAS_VERSION);
}
ofs_end = LittleLong(pinmodel->ofs_end);
if (ofs_end < 0 || ofs_end > modfilelen)
ri.Sys_Error (ERR_DROP, "model %s file size(%d) too small, should be %d", mod->name,
modfilelen, ofs_end);
mod->extradata = Hunk_Begin(modfilelen);
pheader = Hunk_Alloc(ofs_end);
/* byte swap the header fields and sanity check */
for (i = 0; i < sizeof(dmdl_t) / 4; i++)
{
((int *)pheader)[i] = LittleLong(((int *)buffer)[i]);
}
if (pheader->skinheight > MAX_LBM_HEIGHT)
{
ri.Sys_Error(ERR_DROP, "model %s has a skin taller than %d", mod->name,
MAX_LBM_HEIGHT);
}
if (pheader->num_xyz <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no vertices", mod->name);
}
if (pheader->num_xyz > MAX_VERTS)
{
ri.Sys_Error(ERR_DROP, "model %s has too many vertices", mod->name);
}
if (pheader->num_st <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no st vertices", mod->name);
}
if (pheader->num_tris <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no triangles", mod->name);
}
if (pheader->num_frames <= 0)
{
ri.Sys_Error(ERR_DROP, "model %s has no frames", mod->name);
}
/* load base s and t vertices (not used in gl version) */
pinst = (dstvert_t *)((byte *)pinmodel + pheader->ofs_st);
poutst = (dstvert_t *)((byte *)pheader + pheader->ofs_st);
for (i = 0; i < pheader->num_st; i++)
{
poutst[i].s = LittleShort(pinst[i].s);
poutst[i].t = LittleShort(pinst[i].t);
}
/* load triangle lists */
pintri = (dtriangle_t *)((byte *)pinmodel + pheader->ofs_tris);
pouttri = (dtriangle_t *)((byte *)pheader + pheader->ofs_tris);
for (i = 0; i < pheader->num_tris; i++)
{
for (j = 0; j < 3; j++)
{
pouttri[i].index_xyz[j] = LittleShort(pintri[i].index_xyz[j]);
pouttri[i].index_st[j] = LittleShort(pintri[i].index_st[j]);
}
}
/* load the frames */
for (i = 0; i < pheader->num_frames; i++)
{
pinframe = (daliasframe_t *)((byte *)pinmodel
+ pheader->ofs_frames + i * pheader->framesize);
poutframe = (daliasframe_t *)((byte *)pheader
+ pheader->ofs_frames + i * pheader->framesize);
memcpy(poutframe->name, pinframe->name, sizeof(poutframe->name));
for (j = 0; j < 3; j++)
{
poutframe->scale[j] = LittleFloat(pinframe->scale[j]);
poutframe->translate[j] = LittleFloat(pinframe->translate[j]);
}
/* verts are all 8 bit, so no swapping needed */
memcpy(poutframe->verts, pinframe->verts,
pheader->num_xyz * sizeof(dtrivertx_t));
}
mod->type = mod_alias;
/* load the glcmds */
pincmd = (int *)((byte *)pinmodel + pheader->ofs_glcmds);
poutcmd = (int *)((byte *)pheader + pheader->ofs_glcmds);
for (i = 0; i < pheader->num_glcmds; i++)
{
poutcmd[i] = LittleLong(pincmd[i]);
}
if (poutcmd[pheader->num_glcmds-1] != 0)
{
R_Printf(PRINT_ALL, "%s: Entity %s has possible last element issues with %d verts.\n",
__func__,
mod->name,
poutcmd[pheader->num_glcmds-1]);
}
/* register all skins */
memcpy((char *)pheader + pheader->ofs_skins,
(char *)pinmodel + pheader->ofs_skins,
pheader->num_skins * MAX_SKINNAME);
for (i = 0; i < pheader->num_skins; i++)
{
mod->skins[i] = GL3_FindImage(
(char *)pheader + pheader->ofs_skins + i * MAX_SKINNAME,
it_skin);
}
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
}

View File

@ -963,8 +963,57 @@ GL3_Mod_FreeAll(void)
}
}
extern void GL3_LoadMD2(gl3model_t *mod, void *buffer, int modfilelen);
extern void GL3_LoadSP2(gl3model_t *mod, void *buffer, int modfilelen);
/*
=================
Mod_AliasModelFixup
=================
*/
static void
Mod_AliasModelFixup(gl3model_t *mod, const dmdl_t *pheader)
{
mod->type = mod_alias;
if (pheader)
{
int i;
for (i=0 ; i<pheader->num_skins ; i++)
{
mod->skins[i] = GL3_FindImage((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
}
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
}
/*
=================
Mod_SP2Fixup
=================
*/
static void
Mod_SP2Fixup(gl3model_t *mod, const dsprite_t *sprout)
{
mod->type = mod_sprite;
if (sprout)
{
int i;
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = GL3_FindImage(sprout->frames[i].name,
it_sprite);
}
}
}
/*
* Loads in a model for the given name
@ -973,8 +1022,8 @@ static gl3model_t *
Mod_ForName (char *name, gl3model_t *parent_model, qboolean crash)
{
gl3model_t *mod;
unsigned *buf;
int i;
void *buf;
int i, modfilelen;
if (!name[0])
{
@ -1031,7 +1080,7 @@ Mod_ForName (char *name, gl3model_t *parent_model, qboolean crash)
strcpy(mod->name, name);
/* load the file */
int modfilelen = ri.FS_LoadFile(mod->name, (void **)&buf);
modfilelen = ri.FS_LoadFile(mod->name, (void **)&buf);
if (!buf)
{
@ -1049,11 +1098,32 @@ Mod_ForName (char *name, gl3model_t *parent_model, qboolean crash)
switch (LittleLong(*(unsigned *)buf))
{
case IDALIASHEADER:
GL3_LoadMD2(mod, buf, modfilelen);
{
const dmdl_t *pheader;
pheader = Mod_LoadMD2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_AliasModelFixup(mod, pheader);
};
break;
case IDSPRITEHEADER:
GL3_LoadSP2(mod, buf, modfilelen);
{
const dsprite_t *pheader;
pheader = Mod_LoadSP2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_SP2Fixup(mod, pheader);
}
break;
case IDBSPHEADER:

View File

@ -1,68 +0,0 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* .sp2 sprites
*
* =======================================================================
*/
#include "header/local.h"
void
GL3_LoadSP2(gl3model_t *mod, void *buffer, int modfilelen)
{
dsprite_t *sprin, *sprout;
int i;
sprin = (dsprite_t *)buffer;
mod->extradata = Hunk_Begin(modfilelen);
sprout = Hunk_Alloc(modfilelen);
sprout->ident = LittleLong(sprin->ident);
sprout->version = LittleLong(sprin->version);
sprout->numframes = LittleLong(sprin->numframes);
if (sprout->version != SPRITE_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s has wrong version number (%i should be %i)",
mod->name, sprout->version, SPRITE_VERSION);
}
if (sprout->numframes > MAX_MD2SKINS)
{
ri.Sys_Error(ERR_DROP, "%s has too many frames (%i > %i)",
mod->name, sprout->numframes, MAX_MD2SKINS);
}
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
sprout->frames[i].width = LittleLong(sprin->frames[i].width);
sprout->frames[i].height = LittleLong(sprin->frames[i].height);
sprout->frames[i].origin_x = LittleLong(sprin->frames[i].origin_x);
sprout->frames[i].origin_y = LittleLong(sprin->frames[i].origin_y);
memcpy(sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
mod->skins[i] = GL3_FindImage(sprout->frames[i].name, it_sprite);
}
mod->type = mod_sprite;
}

View File

@ -92,4 +92,11 @@ extern void GetM8Info(char *name, int *width, int *height);
extern float Mod_RadiusFromBounds(const vec3_t mins, const vec3_t maxs);
extern const byte* Mod_DecompressVis(const byte *in, int row);
/* Shared models load */
dmdl_t * Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
void **extradata);
dsprite_t *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
void **extradata);
#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */

View File

@ -25,9 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <limits.h>
#include "header/local.h"
static void Mod_LoadSpriteModel(model_t *mod, void *buffer, int modfilelen);
static void Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen);
static void Mod_LoadAliasModel(model_t *mod, void *buffer, int modfilelen);
static byte mod_novis[MAX_MAP_LEAFS/8];
@ -117,6 +115,66 @@ Mod_Init (void)
memset (mod_novis, 0xff, sizeof(mod_novis));
}
/*
==============================================================================
ALIAS MODELS
==============================================================================
*/
/*
=================
Mod_AliasModelFixup
=================
*/
static void
Mod_AliasModelFixup(model_t *mod, const dmdl_t *pheader)
{
mod->type = mod_alias;
if (pheader)
{
int i;
for (i=0 ; i<pheader->num_skins ; i++)
{
mod->skins[i] = R_FindImage ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
}
mod->mins[0] = -32;
mod->mins[1] = -32;
mod->mins[2] = -32;
mod->maxs[0] = 32;
mod->maxs[1] = 32;
mod->maxs[2] = 32;
}
/*
=================
Mod_SP2Fixup
=================
*/
static void
Mod_SP2Fixup(model_t *mod, const dsprite_t *sprout)
{
mod->type = mod_sprite;
if (sprout)
{
int i;
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = R_FindImage (sprout->frames[i].name,
it_sprite);
}
}
}
/*
==================
Mod_ForName
@ -128,7 +186,7 @@ static model_t *
Mod_ForName (char *name, model_t *parent_model, qboolean crash)
{
model_t *mod;
unsigned *buf;
void *buf;
int i, modfilelen;
if (!name[0])
@ -199,11 +257,32 @@ Mod_ForName (char *name, model_t *parent_model, qboolean crash)
switch (LittleLong(*(unsigned *)buf))
{
case IDALIASHEADER:
Mod_LoadAliasModel(mod, buf, modfilelen);
{
const dmdl_t *pheader;
pheader = Mod_LoadMD2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_AliasModelFixup(mod, pheader);
};
break;
case IDSPRITEHEADER:
Mod_LoadSpriteModel(mod, buf, modfilelen);
{
const dsprite_t *pheader;
pheader = Mod_LoadSP2(mod->name, buf, modfilelen, &(mod->extradata));
if (!pheader)
{
ri.Sys_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
Mod_SP2Fixup(mod, pheader);
}
break;
case IDBSPHEADER:
@ -1047,224 +1126,6 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen)
R_InitSkyBox (mod);
}
/*
==============================================================================
ALIAS MODELS
==============================================================================
*/
/*
=================
Mod_LoadAliasModel
=================
*/
static void
Mod_LoadAliasModel(model_t *mod, void *buffer, int modfilelen)
{
int i, j;
dmdl_t *pinmodel, *pheader;
dstvert_t *pinst, *poutst;
dtriangle_t *pintri, *pouttri;
int *pincmd, *poutcmd;
int version;
int ofs_end;
pinmodel = (dmdl_t *)buffer;
version = LittleLong (pinmodel->version);
if (version != ALIAS_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s: %s has wrong version number (%i should be %i)",
__func__, mod->name, version, ALIAS_VERSION);
}
ofs_end = LittleLong(pinmodel->ofs_end);
if (ofs_end < 0 || ofs_end > modfilelen)
{
ri.Sys_Error(ERR_DROP, "%s: model %s file size(%d) too small, should be %d", mod->name,
__func__, modfilelen, ofs_end);
}
mod->extradata = Hunk_Begin(modfilelen);
pheader = Hunk_Alloc(ofs_end);
// byte swap the header fields and sanity check
for (i=0 ; i<sizeof(dmdl_t)/4 ; i++)
((int *)pheader)[i] = LittleLong (((int *)buffer)[i]);
if (pheader->skinheight > MAX_LBM_HEIGHT)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has a skin taller than %d", mod->name,
__func__, MAX_LBM_HEIGHT);
}
if (pheader->num_xyz <= 0)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has no vertices",
__func__, mod->name);
}
if (pheader->num_xyz > MAX_VERTS)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has too many vertices",
__func__, mod->name);
}
if (pheader->num_st <= 0)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has no st vertices",
__func__, mod->name);
}
if (pheader->num_tris <= 0)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has no triangles",
__func__, mod->name);
}
if (pheader->num_frames <= 0)
{
ri.Sys_Error(ERR_DROP, "%s: model %s has no frames",
__func__, mod->name);
}
//
// load base s and t vertices (not used in gl version)
//
pinst = (dstvert_t *) ((byte *)pinmodel + pheader->ofs_st);
poutst = (dstvert_t *) ((byte *)pheader + pheader->ofs_st);
for (i=0 ; i<pheader->num_st ; i++)
{
poutst[i].s = LittleShort (pinst[i].s);
poutst[i].t = LittleShort (pinst[i].t);
}
//
// load triangle lists
//
pintri = (dtriangle_t *) ((byte *)pinmodel + pheader->ofs_tris);
pouttri = (dtriangle_t *) ((byte *)pheader + pheader->ofs_tris);
for (i=0 ; i<pheader->num_tris ; i++)
{
for (j=0 ; j<3 ; j++)
{
pouttri[i].index_xyz[j] = LittleShort (pintri[i].index_xyz[j]);
pouttri[i].index_st[j] = LittleShort (pintri[i].index_st[j]);
}
}
//
// load the frames
//
for (i=0 ; i<pheader->num_frames ; i++)
{
daliasframe_t *pinframe, *poutframe;
pinframe = (daliasframe_t *) ((byte *)pinmodel
+ pheader->ofs_frames + i * pheader->framesize);
poutframe = (daliasframe_t *) ((byte *)pheader
+ pheader->ofs_frames + i * pheader->framesize);
memcpy (poutframe->name, pinframe->name, sizeof(poutframe->name));
for (j=0 ; j<3 ; j++)
{
poutframe->scale[j] = LittleFloat (pinframe->scale[j]);
poutframe->translate[j] = LittleFloat (pinframe->translate[j]);
}
// verts are all 8 bit, so no swapping needed
memcpy (poutframe->verts, pinframe->verts,
pheader->num_xyz*sizeof(dtrivertx_t));
}
mod->type = mod_alias;
//
// load the glcmds
//
pincmd = (int *) ((byte *)pinmodel + pheader->ofs_glcmds);
poutcmd = (int *) ((byte *)pheader + pheader->ofs_glcmds);
for (i=0 ; i<pheader->num_glcmds ; i++)
{
poutcmd[i] = LittleLong (pincmd[i]);
}
if (poutcmd[pheader->num_glcmds-1] != 0)
{
R_Printf(PRINT_ALL, "%s: Entity %s has possible last element issues with %d verts.\n",
__func__,
mod->name,
poutcmd[pheader->num_glcmds-1]);
}
// register all skins
memcpy ((char *)pheader + pheader->ofs_skins, (char *)pinmodel + pheader->ofs_skins,
pheader->num_skins*MAX_SKINNAME);
for (i=0 ; i<pheader->num_skins ; i++)
{
mod->skins[i] = R_FindImage ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
}
}
/*
==============================================================================
SPRITE MODELS
==============================================================================
*/
/*
=================
Mod_LoadSpriteModel
support for .sp2 sprites
=================
*/
static void
Mod_LoadSpriteModel(model_t *mod, void *buffer, int modfilelen)
{
dsprite_t *sprin, *sprout;
int i;
sprin = (dsprite_t *)buffer;
mod->extradata = Hunk_Begin(modfilelen);
sprout = Hunk_Alloc(modfilelen);
sprout->ident = LittleLong (sprin->ident);
sprout->version = LittleLong (sprin->version);
sprout->numframes = LittleLong (sprin->numframes);
if (sprout->version != SPRITE_VERSION)
{
ri.Sys_Error(ERR_DROP, "%s: %s has wrong version number (%i should be %i)",
__func__, mod->name, sprout->version, SPRITE_VERSION);
}
if (sprout->numframes > MAX_MD2SKINS)
{
ri.Sys_Error(ERR_DROP, "%s: %s has too many frames (%i > %i)",
__func__, mod->name, sprout->numframes, MAX_MD2SKINS);
}
// byte swap everything
for (i=0 ; i<sprout->numframes ; i++)
{
sprout->frames[i].width = LittleLong (sprin->frames[i].width);
sprout->frames[i].height = LittleLong (sprin->frames[i].height);
sprout->frames[i].origin_x = LittleLong (sprin->frames[i].origin_x);
sprout->frames[i].origin_y = LittleLong (sprin->frames[i].origin_y);
memcpy (sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
mod->skins[i] = R_FindImage (sprout->frames[i].name, it_sprite);
}
mod->type = mod_sprite;
}
//=============================================================================
/*