2000-09-20 22:11:17 +00:00
|
|
|
/*
|
|
|
|
cl_model.c
|
|
|
|
|
|
|
|
model loading and caching
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
2000-12-15 23:24:22 +00:00
|
|
|
#include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
#include "checksum.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "d_iface.h"
|
|
|
|
#include "model.h"
|
|
|
|
#include "qendian.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "server.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "sys.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
extern char loadname[];
|
|
|
|
extern model_t *loadmodel;
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
ALIAS MODELS
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
extern aliashdr_t *pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
extern stvert_t stverts[MAXALIASVERTS];
|
|
|
|
extern mtriangle_t triangles[MAXALIASTRIS];
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
// a pose is a single set of vertexes. a frame may be
|
|
|
|
// an animating sequence of poses
|
2000-12-08 06:51:37 +00:00
|
|
|
extern trivertx_t *poseverts[MAXALIASFRAMES];
|
|
|
|
extern int posenum;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-28 06:49:26 +00:00
|
|
|
void *
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadSkin (byte * skin, int skinsize, int *pskinindex, int snum, int gnum)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *pskin;
|
|
|
|
unsigned short *pusskin;
|
|
|
|
int i;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
pskin = Hunk_AllocName (skinsize * r_pixbytes, loadname);
|
2000-12-08 06:51:37 +00:00
|
|
|
*pskinindex = (byte *) pskin - (byte *) pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
switch (r_pixbytes) {
|
2000-12-08 06:51:37 +00:00
|
|
|
case 1:
|
|
|
|
memcpy (pskin, skin, skinsize);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pusskin = (unsigned short *) skin;
|
|
|
|
for (i = 0; i < skinsize; i++)
|
|
|
|
pusskin[i] = d_8to16table[skin[i]];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SV_Error ("Mod_LoadAliasSkin: driver set invalid r_pixbytes: %d\n",
|
|
|
|
r_pixbytes);
|
|
|
|
break;
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
return skin + skinsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Mod_LoadAllSkins
|
|
|
|
===============
|
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
void *
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int snum, gnum, t;
|
|
|
|
int skinsize;
|
|
|
|
byte *skin;
|
|
|
|
int groupskins;
|
|
|
|
daliasskingroup_t *pinskingroup;
|
|
|
|
daliasskininterval_t *pinskinintervals;
|
|
|
|
maliasskindesc_t *pskindesc;
|
|
|
|
maliasskingroup_t *paliasskingroup;
|
|
|
|
float *poutskinintervals;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
if (numskins < 1 || numskins > MAX_SKINS)
|
|
|
|
Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);
|
|
|
|
|
|
|
|
skinsize = pheader->mdl.skinwidth * pheader->mdl.skinheight;
|
2000-12-08 06:51:37 +00:00
|
|
|
pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t), loadname);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pheader->skindesc = (byte *) pskindesc - (byte *) pheader;
|
|
|
|
|
|
|
|
for (snum = 0; snum < numskins; snum++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
if (pskintype->type == ALIAS_SKIN_SINGLE) {
|
2000-12-08 06:51:37 +00:00
|
|
|
skin = (byte *) (pskintype + 1);
|
|
|
|
skin =
|
|
|
|
Mod_LoadSkin (skin, skinsize, &pskindesc[snum].skin, snum, 0);
|
2000-09-20 22:11:17 +00:00
|
|
|
} else {
|
|
|
|
pskintype++;
|
2000-12-08 06:51:37 +00:00
|
|
|
pinskingroup = (daliasskingroup_t *) pskintype;
|
2000-09-20 22:11:17 +00:00
|
|
|
groupskins = LittleLong (pinskingroup->numskins);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
t = (int) &((maliasskingroup_t *) 0)->skindescs[groupskins];
|
2000-09-27 17:01:17 +00:00
|
|
|
paliasskingroup = Hunk_AllocName (t, loadname);
|
2000-09-20 22:11:17 +00:00
|
|
|
paliasskingroup->numskins = groupskins;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
*pskinindex = (byte *) paliasskingroup - (byte *) pheader;
|
|
|
|
|
|
|
|
pinskinintervals = (daliasskininterval_t *) (pinskingroup + 1);
|
|
|
|
poutskinintervals =
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Hunk_AllocName (groupskins * sizeof (float), loadname);
|
|
|
|
paliasskingroup->intervals =
|
|
|
|
(byte *) poutskinintervals - (byte *) pheader;
|
|
|
|
for (gnum = 0; gnum < groupskins; gnum++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
*poutskinintervals = LittleFloat (pinskinintervals->interval);
|
|
|
|
if (*poutskinintervals <= 0)
|
|
|
|
Sys_Error ("Mod_LoadAliasSkinGroup: interval<=0");
|
|
|
|
|
|
|
|
poutskinintervals++;
|
|
|
|
pinskinintervals++;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pskintype = (void *) pinskinintervals;
|
|
|
|
skin = (byte *) pskintype;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (gnum = 0; gnum < groupskins; gnum++) {
|
|
|
|
skin =
|
|
|
|
Mod_LoadSkin (skin, skinsize,
|
|
|
|
&paliasskingroup->skindescs[snum].skin, snum,
|
|
|
|
gnum);
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
pskintype = (daliasskintype_t *) skin;
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
|
2000-09-27 17:01:17 +00:00
|
|
|
return pskintype;
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
2001-01-15 06:50:59 +00:00
|
|
|
GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
stvert_t *pstverts;
|
2000-09-20 22:11:17 +00:00
|
|
|
mtriangle_t *ptri;
|
2000-12-08 06:51:37 +00:00
|
|
|
int numv = hdr->mdl.numverts;
|
|
|
|
int numt = hdr->mdl.numtris;
|
|
|
|
|
|
|
|
pstverts = (stvert_t *) Hunk_AllocName (numv * sizeof (stvert_t), loadname);
|
2000-12-28 06:49:26 +00:00
|
|
|
ptri = (mtriangle_t *) Hunk_AllocName (numt * sizeof (mtriangle_t), loadname);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
hdr->stverts = (byte *) pstverts - (byte *) hdr;
|
|
|
|
hdr->triangles = (byte *) ptri - (byte *) hdr;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < numv; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
pstverts[i].onseam = stverts[i].onseam;
|
|
|
|
pstverts[i].s = stverts[i].s << 16;
|
|
|
|
pstverts[i].t = stverts[i].t << 16;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < numt; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
ptri[i].facesfront = triangles[i].facesfront;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
ptri[i].vertindex[j] = triangles[i].vertindex[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Mod_LoadAliasFrame
|
|
|
|
=================
|
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
void *
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadAliasFrame (void *pin, maliasframedesc_t *frame)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
trivertx_t *pframe, *pinframe;
|
|
|
|
int i, j;
|
|
|
|
daliasframe_t *pdaliasframe;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pdaliasframe = (daliasframe_t *) pin;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
strcpy (frame->name, pdaliasframe->name);
|
|
|
|
|
2000-12-28 06:49:26 +00:00
|
|
|
for (i = 0; i < 3; i++) { // byte values, don't worry about endianness
|
2000-09-20 22:11:17 +00:00
|
|
|
frame->bboxmin.v[i] = pdaliasframe->bboxmin.v[i];
|
|
|
|
frame->bboxmax.v[i] = pdaliasframe->bboxmax.v[i];
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pinframe = (trivertx_t *) (pdaliasframe + 1);
|
2000-12-28 06:49:26 +00:00
|
|
|
pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe), loadname);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
frame->frame = (byte *) pframe - (byte *) pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < pheader->mdl.numverts; j++) {
|
|
|
|
int k;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// these are all byte values, so no need to deal with endianness
|
2000-09-20 22:11:17 +00:00
|
|
|
pframe[j].lightnormalindex = pinframe[j].lightnormalindex;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (k = 0; k < 3; k++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
pframe[j].v[k] = pinframe[j].v[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pinframe += pheader->mdl.numverts;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
return (void *) pinframe;
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Mod_LoadAliasGroup
|
|
|
|
=================
|
|
|
|
*/
|
2000-12-28 06:49:26 +00:00
|
|
|
void *
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadAliasGroup (void *pin, maliasframedesc_t *frame)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
daliasgroup_t *pingroup;
|
|
|
|
maliasgroup_t *paliasgroup;
|
|
|
|
int i, numframes;
|
|
|
|
daliasinterval_t *pin_intervals;
|
|
|
|
float *poutintervals;
|
|
|
|
void *ptemp;
|
|
|
|
|
|
|
|
pingroup = (daliasgroup_t *) pin;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
numframes = LittleLong (pingroup->numframes);
|
|
|
|
|
2000-12-28 06:49:26 +00:00
|
|
|
paliasgroup = Hunk_AllocName (sizeof (maliasgroup_t) + (numframes - 1) * sizeof (paliasgroup->frames[0]), loadname);
|
2000-09-20 22:11:17 +00:00
|
|
|
paliasgroup->numframes = numframes;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
// these are byte values, so we don't have to worry about endianness
|
2000-09-20 22:11:17 +00:00
|
|
|
frame->bboxmin.v[i] = pingroup->bboxmin.v[i];
|
|
|
|
frame->bboxmax.v[i] = pingroup->bboxmax.v[i];
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
frame->frame = (byte *) paliasgroup - (byte *) pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pin_intervals = (daliasinterval_t *) (pingroup + 1);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
paliasgroup->intervals = (byte *) poutintervals - (byte *) pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < numframes; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
*poutintervals = LittleFloat (pin_intervals->interval);
|
|
|
|
if (*poutintervals <= 0.0)
|
|
|
|
SV_Error ("Mod_LoadAliasGroup: interval<=0");
|
|
|
|
|
|
|
|
poutintervals++;
|
|
|
|
pin_intervals++;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
ptemp = (void *) pin_intervals;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < numframes; i++) {
|
2000-12-17 04:27:36 +00:00
|
|
|
maliasframedesc_t temp_frame;
|
|
|
|
ptemp = Mod_LoadAliasFrame (ptemp, &temp_frame);
|
|
|
|
memcpy (&paliasgroup->frames[i], &temp_frame,
|
|
|
|
sizeof(paliasgroup->frames[i]));
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ptemp;
|
|
|
|
}
|