2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-11-21 19:13:53 +00:00
|
|
|
sw_model_alias.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-25 14:25:38 +00:00
|
|
|
alias model loading and caching for the software renderer
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2001-08-25 02:47:11 +00:00
|
|
|
# include <string.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-08-25 02:47:11 +00:00
|
|
|
# include <strings.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 06:55:28 +00:00
|
|
|
#include "QF/model.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-31 18:11:05 +00:00
|
|
|
#include "compat.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
#include "d_iface.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// a pose is a single set of vertexes. a frame may be
|
|
|
|
// an animating sequence of poses
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void *
|
2001-11-21 19:13:53 +00:00
|
|
|
Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum,
|
|
|
|
qboolean group, maliasskindesc_t *skindesc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 14:25:38 +00:00
|
|
|
byte *pskin;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
pskin = Hunk_AllocName (skinsize, loadname);
|
2001-11-21 08:14:05 +00:00
|
|
|
skindesc->skin = (byte *) pskin - (byte *) pheader;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
memcpy (pskin, skin, skinsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
return skin + skinsize;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-08-25 14:25:38 +00:00
|
|
|
Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s,
|
|
|
|
int extra)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 14:25:38 +00:00
|
|
|
int i, j;
|
|
|
|
int numv = hdr->mdl.numverts, numt = hdr->mdl.numtris;
|
|
|
|
stvert_t *pstverts;
|
2001-02-19 21:15:25 +00:00
|
|
|
mtriangle_t *ptri;
|
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
pstverts = (stvert_t *) Hunk_AllocName (numv * sizeof (stvert_t),
|
|
|
|
loadname);
|
|
|
|
ptri = (mtriangle_t *) Hunk_AllocName (numt * sizeof (mtriangle_t),
|
|
|
|
loadname);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
hdr->stverts = (byte *) pstverts - (byte *) hdr;
|
|
|
|
hdr->triangles = (byte *) ptri - (byte *) hdr;
|
|
|
|
|
|
|
|
for (i = 0; i < numv; i++) {
|
|
|
|
pstverts[i].onseam = stverts[i].onseam;
|
|
|
|
pstverts[i].s = stverts[i].s << 16;
|
|
|
|
pstverts[i].t = stverts[i].t << 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numt; i++) {
|
|
|
|
ptri[i].facesfront = triangles[i].facesfront;
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
ptri[i].vertindex[j] = triangles[i].vertindex[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2002-08-25 14:25:38 +00:00
|
|
|
Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame,
|
|
|
|
int extra)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 14:25:38 +00:00
|
|
|
daliasframe_t *pdaliasframe;
|
|
|
|
int i, j;
|
|
|
|
trivertx_t *pframe, *pinframe;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pdaliasframe = (daliasframe_t *) pin;
|
|
|
|
|
|
|
|
strcpy (frame->name, pdaliasframe->name);
|
|
|
|
|
2001-05-10 15:29:29 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
// byte values, don't worry about endianness
|
2001-02-19 21:15:25 +00:00
|
|
|
frame->bboxmin.v[i] = pdaliasframe->bboxmin.v[i];
|
|
|
|
frame->bboxmax.v[i] = pdaliasframe->bboxmax.v[i];
|
2002-06-14 09:33:37 +00:00
|
|
|
|
|
|
|
aliasbboxmins[i] = min (frame->bboxmin.v[i], aliasbboxmins[i]);
|
|
|
|
aliasbboxmaxs[i] = max (frame->bboxmax.v[i], aliasbboxmaxs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pinframe = (trivertx_t *) (pdaliasframe + 1);
|
2001-12-30 02:30:26 +00:00
|
|
|
|
|
|
|
if (extra)
|
|
|
|
pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe) * 2,
|
|
|
|
loadname);
|
|
|
|
else
|
|
|
|
pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe),
|
2001-08-25 02:47:11 +00:00
|
|
|
loadname);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
frame->frame = (byte *) pframe - (byte *) pheader;
|
|
|
|
|
|
|
|
for (j = 0; j < pheader->mdl.numverts; j++) {
|
2002-08-25 14:25:38 +00:00
|
|
|
int k;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// these are all byte values, so no need to deal with endianness
|
|
|
|
pframe[j].lightnormalindex = pinframe[j].lightnormalindex;
|
|
|
|
|
|
|
|
for (k = 0; k < 3; k++) {
|
|
|
|
pframe[j].v[k] = pinframe[j].v[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-30 02:30:26 +00:00
|
|
|
if (extra)
|
|
|
|
{
|
|
|
|
for (j = pheader->mdl.numverts; j < pheader->mdl.numverts * 2; j++)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < 3; k++)
|
|
|
|
pframe[j].v[k] = pinframe[j].v[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra)
|
|
|
|
pinframe += pheader->mdl.numverts * 2;
|
|
|
|
else
|
|
|
|
pinframe += pheader->mdl.numverts;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return (void *) pinframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2002-08-25 14:25:38 +00:00
|
|
|
Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame,
|
|
|
|
int extra)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 14:25:38 +00:00
|
|
|
daliasgroup_t *pingroup;
|
2001-02-19 21:15:25 +00:00
|
|
|
daliasinterval_t *pin_intervals;
|
2002-08-25 14:25:38 +00:00
|
|
|
float *poutintervals;
|
|
|
|
int i, numframes;
|
|
|
|
maliasgroup_t *paliasgroup;
|
|
|
|
void *ptemp;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pingroup = (daliasgroup_t *) pin;
|
|
|
|
|
|
|
|
numframes = LittleLong (pingroup->numframes);
|
|
|
|
|
2001-05-31 18:11:05 +00:00
|
|
|
paliasgroup = Hunk_AllocName (field_offset (maliasgroup_t,
|
|
|
|
frames[numframes]), loadname);
|
2001-02-19 21:15:25 +00:00
|
|
|
paliasgroup->numframes = numframes;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
// these are byte values, so we don't have to worry about endianness
|
|
|
|
frame->bboxmin.v[i] = pingroup->bboxmin.v[i];
|
|
|
|
frame->bboxmax.v[i] = pingroup->bboxmax.v[i];
|
2002-06-14 09:33:37 +00:00
|
|
|
|
|
|
|
aliasbboxmins[i] = min (frame->bboxmin.v[i], aliasbboxmins[i]);
|
|
|
|
aliasbboxmaxs[i] = max (frame->bboxmax.v[i], aliasbboxmaxs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame->frame = (byte *) paliasgroup - (byte *) pheader;
|
|
|
|
|
|
|
|
pin_intervals = (daliasinterval_t *) (pingroup + 1);
|
|
|
|
|
|
|
|
poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
|
|
|
|
|
|
|
|
paliasgroup->intervals = (byte *) poutintervals - (byte *) pheader;
|
|
|
|
|
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
*poutintervals = LittleFloat (pin_intervals->interval);
|
|
|
|
if (*poutintervals <= 0.0)
|
2001-05-10 06:01:11 +00:00
|
|
|
Sys_Error ("Mod_LoadAliasGroup: interval<=0");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
poutintervals++;
|
|
|
|
pin_intervals++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptemp = (void *) pin_intervals;
|
|
|
|
|
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
maliasframedesc_t temp_frame;
|
2001-12-30 02:30:26 +00:00
|
|
|
ptemp = Mod_LoadAliasFrame (ptemp, &i, &temp_frame, extra);
|
2001-02-19 21:15:25 +00:00
|
|
|
memcpy (&paliasgroup->frames[i], &temp_frame,
|
|
|
|
sizeof(paliasgroup->frames[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptemp;
|
|
|
|
}
|
2001-11-20 08:02:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
|
|
|
|
{
|
|
|
|
}
|
2002-01-16 20:32:39 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Mod_LoadExternalSkins (model_t *mod)
|
|
|
|
{
|
|
|
|
}
|