2000-09-20 22:11:17 +00:00
|
|
|
/*
|
|
|
|
gl_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-10-16 15:34:53 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "cl_main.h"
|
|
|
|
#include "client.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "crc.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "info.h"
|
|
|
|
#include "model.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "msg.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "qendian.h"
|
|
|
|
#include "quakefs.h"
|
|
|
|
#include "r_local.h"
|
|
|
|
#include "server.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
extern char loadname[];
|
|
|
|
extern model_t *loadmodel;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype,
|
|
|
|
|
|
|
|
int *pskinindex);
|
|
|
|
void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
ALIAS MODELS
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
aliashdr_t *pheader;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
stvert_t stverts[MAXALIASVERTS];
|
|
|
|
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
|
|
|
trivertx_t *poseverts[MAXALIASFRAMES];
|
|
|
|
int posenum = 0;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void *Mod_LoadAliasFrame (void *pin, maliasframedesc_t *frame);
|
|
|
|
void *Mod_LoadAliasGroup (void *pin, maliasframedesc_t *frame);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Mod_LoadAliasModel
|
|
|
|
=================
|
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadAliasModel (model_t *mod, void *buffer)
|
2000-09-20 22:11:17 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
mdl_t *pinmodel, *pmodel;
|
|
|
|
stvert_t *pinstverts;
|
|
|
|
dtriangle_t *pintriangles;
|
|
|
|
int version, numframes;
|
|
|
|
int size;
|
|
|
|
daliasframetype_t *pframetype;
|
|
|
|
daliasskintype_t *pskintype;
|
|
|
|
int start, end, total;
|
|
|
|
|
|
|
|
if (!strcmp (loadmodel->name, "progs/player.mdl") ||
|
|
|
|
!strcmp (loadmodel->name, "progs/eyes.mdl")) {
|
2000-09-20 22:11:17 +00:00
|
|
|
unsigned short crc;
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *p;
|
|
|
|
int len;
|
|
|
|
char st[40];
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
CRC_Init (&crc);
|
2000-09-20 22:11:17 +00:00
|
|
|
for (len = com_filesize, p = buffer; len; len--, p++)
|
2000-12-08 06:51:37 +00:00
|
|
|
CRC_ProcessByte (&crc, *p);
|
|
|
|
|
|
|
|
snprintf (st, sizeof (st), "%d", (int) crc);
|
|
|
|
Info_SetValueForKey (cls.userinfo,
|
|
|
|
!strcmp (loadmodel->name,
|
|
|
|
"progs/player.mdl") ? pmodel_name :
|
|
|
|
emodel_name, st, MAX_INFO_STRING);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
if (cls.state >= ca_connected) {
|
|
|
|
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (st, sizeof (st), "setinfo %s %d",
|
|
|
|
!strcmp (loadmodel->name,
|
|
|
|
"progs/player.mdl") ? pmodel_name : emodel_name,
|
|
|
|
(int) crc);
|
2000-09-20 22:11:17 +00:00
|
|
|
SZ_Print (&cls.netchan.message, st);
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
start = Hunk_LowMark ();
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pinmodel = (mdl_t *) buffer;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
version = LittleLong (pinmodel->version);
|
|
|
|
if (version != ALIAS_VERSION)
|
|
|
|
SV_Error ("%s has wrong version number (%i should be %i)",
|
2000-12-08 06:51:37 +00:00
|
|
|
mod->name, version, ALIAS_VERSION);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// allocate space for a working header, plus all the data except the frames,
|
|
|
|
// skin and group info
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
size = (int) &((aliashdr_t *) 0)->frames[LittleLong (pinmodel->numframes)];
|
2000-09-20 22:11:17 +00:00
|
|
|
pheader = Hunk_AllocName (size, loadname);
|
2000-12-08 06:51:37 +00:00
|
|
|
memset (pheader, 0, size);
|
2000-09-20 22:11:17 +00:00
|
|
|
pmodel = &pheader->mdl;
|
2000-12-08 06:51:37 +00:00
|
|
|
pheader->model = (byte *) pmodel - (byte *) pheader;
|
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
mod->flags = LittleLong (pinmodel->flags);
|
|
|
|
|
|
|
|
//
|
|
|
|
// endian-adjust and copy the data, starting with the alias model header
|
|
|
|
//
|
|
|
|
pmodel->boundingradius = LittleFloat (pinmodel->boundingradius);
|
|
|
|
pmodel->numskins = LittleLong (pinmodel->numskins);
|
|
|
|
pmodel->skinwidth = LittleLong (pinmodel->skinwidth);
|
|
|
|
pmodel->skinheight = LittleLong (pinmodel->skinheight);
|
|
|
|
|
|
|
|
if (pmodel->skinheight > MAX_LBM_HEIGHT)
|
|
|
|
SV_Error ("model %s has a skin taller than %d", mod->name,
|
2000-12-08 06:51:37 +00:00
|
|
|
MAX_LBM_HEIGHT);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
pmodel->numverts = LittleLong (pinmodel->numverts);
|
|
|
|
|
|
|
|
if (pmodel->numverts <= 0)
|
|
|
|
SV_Error ("model %s has no vertices", mod->name);
|
|
|
|
|
|
|
|
if (pmodel->numverts > MAXALIASVERTS)
|
|
|
|
SV_Error ("model %s has too many vertices", mod->name);
|
|
|
|
|
|
|
|
pmodel->numtris = LittleLong (pinmodel->numtris);
|
|
|
|
|
|
|
|
if (pmodel->numtris <= 0)
|
|
|
|
SV_Error ("model %s has no triangles", mod->name);
|
|
|
|
|
|
|
|
pmodel->numframes = LittleLong (pinmodel->numframes);
|
|
|
|
numframes = pmodel->numframes;
|
|
|
|
if (numframes < 1)
|
|
|
|
SV_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);
|
|
|
|
|
|
|
|
pmodel->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
|
|
|
|
mod->synctype = LittleLong (pinmodel->synctype);
|
|
|
|
mod->numframes = pmodel->numframes;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
pmodel->scale[i] = LittleFloat (pinmodel->scale[i]);
|
|
|
|
pmodel->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
|
|
|
|
pmodel->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// load the skins
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
pskintype = (daliasskintype_t *) &pinmodel[1];
|
|
|
|
pskintype =
|
|
|
|
Mod_LoadAllSkins (pheader->mdl.numskins, pskintype, &pheader->skindesc);
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// load base s and t vertices
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
pinstverts = (stvert_t *) pskintype;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < pheader->mdl.numverts; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
stverts[i].onseam = LittleLong (pinstverts[i].onseam);
|
|
|
|
stverts[i].s = LittleLong (pinstverts[i].s);
|
|
|
|
stverts[i].t = LittleLong (pinstverts[i].t);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// load triangle lists
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
pintriangles = (dtriangle_t *) &pinstverts[pheader->mdl.numverts];
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < pheader->mdl.numtris; i++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
triangles[i].facesfront = LittleLong (pintriangles[i].facesfront);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2000-09-20 22:11:17 +00:00
|
|
|
triangles[i].vertindex[j] =
|
2000-12-08 06:51:37 +00:00
|
|
|
LittleLong (pintriangles[i].vertindex[j]);
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// load the frames
|
|
|
|
//
|
|
|
|
posenum = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
pframetype = (daliasframetype_t *) &pintriangles[pheader->mdl.numtris];
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
aliasframetype_t frametype;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
|
|
|
frametype = LittleLong (pframetype->type);
|
|
|
|
pheader->frames[i].type = frametype;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (frametype == ALIAS_SINGLE) {
|
2000-09-20 22:11:17 +00:00
|
|
|
pframetype = (daliasframetype_t *)
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadAliasFrame (pframetype + 1, &pheader->frames[i]);
|
|
|
|
} else {
|
2000-09-20 22:11:17 +00:00
|
|
|
pframetype = (daliasframetype_t *)
|
2000-12-08 06:51:37 +00:00
|
|
|
Mod_LoadAliasGroup (pframetype + 1, &pheader->frames[i]);
|
2000-09-20 22:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pheader->numposes = posenum;
|
|
|
|
|
|
|
|
mod->type = mod_alias;
|
|
|
|
|
|
|
|
// FIXME: do this right
|
|
|
|
mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
|
|
|
|
mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
//
|
2000-09-20 22:11:17 +00:00
|
|
|
// build the draw lists
|
2000-12-08 06:51:37 +00:00
|
|
|
//
|
2000-09-20 22:11:17 +00:00
|
|
|
GL_MakeAliasModelDisplayLists (mod, pheader);
|
|
|
|
|
|
|
|
//
|
|
|
|
// move the complete, relocatable alias model to the cache
|
2000-12-08 06:51:37 +00:00
|
|
|
//
|
2000-09-20 22:11:17 +00:00
|
|
|
end = Hunk_LowMark ();
|
|
|
|
total = end - start;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
Cache_Alloc (&mod->cache, total, loadname);
|
|
|
|
if (!mod->cache.data)
|
|
|
|
return;
|
|
|
|
memcpy (mod->cache.data, pheader, total);
|
|
|
|
|
|
|
|
Hunk_FreeToLowMark (start);
|
|
|
|
}
|