2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
model.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-22 07:10:16 +00:00
|
|
|
model loading and caching
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-10-16 15:34:53 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2001-02-03 07:39:45 +00:00
|
|
|
# include <string.h>
|
2000-10-16 15:34:53 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-02-03 07:39:45 +00:00
|
|
|
# include <strings.h>
|
2000-10-16 15:34:53 +00:00
|
|
|
#endif
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "cvar.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "model.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "qendian.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "quakefs.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "server.h"
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void Mod_LoadAliasModel (model_t *mod, void *buf);
|
|
|
|
void Mod_LoadSpriteModel (model_t *mod, void *buf);
|
|
|
|
void Mod_LoadBrushModel (model_t *mod, void *buf);
|
2000-05-13 05:20:33 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *loadmodel;
|
|
|
|
char loadname[32]; // for hunk tags
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-13 05:20:33 +00:00
|
|
|
#define MAX_MOD_KNOWN 512
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t mod_known[MAX_MOD_KNOWN];
|
|
|
|
int mod_numknown;
|
2000-06-16 09:41:42 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *gl_subdivide_size;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
extern byte mod_novis[MAX_MAP_LEAFS / 8];
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
texture_t *r_notexture_mip;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_Init
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_Init (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
memset (mod_novis, 0xff, sizeof (mod_novis));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_Init_Cvars (void)
|
2000-10-29 15:35:24 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
gl_subdivide_size =
|
2000-12-31 04:46:04 +00:00
|
|
|
Cvar_Get ("gl_subdivide_size", "128", CVAR_ARCHIVE, "Sets the division value for the sky brushes.");
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_ClearAll
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_ClearAll (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
|
|
|
|
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
|
2000-05-10 11:29:38 +00:00
|
|
|
if (mod->type != mod_alias)
|
|
|
|
mod->needload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_FindName
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *
|
|
|
|
Mod_FindName (char *name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
if (!name[0])
|
2000-05-11 22:24:46 +00:00
|
|
|
SV_Error ("Mod_ForName: NULL name");
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
//
|
|
|
|
// search the currently loaded models
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
|
|
|
|
if (!strcmp (mod->name, name))
|
2000-05-10 11:29:38 +00:00
|
|
|
break;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (i == mod_numknown) {
|
2000-05-10 11:29:38 +00:00
|
|
|
if (mod_numknown == MAX_MOD_KNOWN)
|
2000-05-11 22:24:46 +00:00
|
|
|
SV_Error ("mod_numknown == MAX_MOD_KNOWN");
|
2000-05-10 11:29:38 +00:00
|
|
|
strcpy (mod->name, name);
|
|
|
|
mod->needload = true;
|
|
|
|
mod_numknown++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadModel
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Loads a model into the cache
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *
|
|
|
|
Mod_LoadModel (model_t *mod, qboolean crash)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
void *d;
|
2000-09-22 09:08:08 +00:00
|
|
|
unsigned int *buf;
|
2000-12-08 06:51:37 +00:00
|
|
|
byte stackbuf[1024]; // avoid dirtying the cache heap
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!mod->needload) {
|
|
|
|
if (mod->type == mod_alias) {
|
2000-05-10 11:29:38 +00:00
|
|
|
d = Cache_Check (&mod->cache);
|
|
|
|
if (d)
|
|
|
|
return mod;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
|
|
|
return mod; // not cached at all
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// load the file
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
buf =
|
|
|
|
(unsigned int *) COM_LoadStackFile (mod->name, stackbuf,
|
|
|
|
sizeof (stackbuf));
|
|
|
|
if (!buf) {
|
2000-05-10 11:29:38 +00:00
|
|
|
if (crash)
|
2000-05-11 22:24:46 +00:00
|
|
|
SV_Error ("Mod_NumForName: %s not found", mod->name);
|
2000-05-10 11:29:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// allocate a new model
|
|
|
|
//
|
|
|
|
COM_FileBase (mod->name, loadname);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
loadmodel = mod;
|
|
|
|
|
|
|
|
//
|
|
|
|
// fill it in
|
|
|
|
//
|
|
|
|
|
|
|
|
// call the apropriate loader
|
|
|
|
mod->needload = false;
|
2000-09-20 22:11:17 +00:00
|
|
|
mod->hasfullbrights = false;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
switch (LittleLong (*(unsigned int *) buf)) {
|
|
|
|
case IDPOLYHEADER:
|
|
|
|
Mod_LoadAliasModel (mod, buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDSPRITEHEADER:
|
|
|
|
Mod_LoadSpriteModel (mod, buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Mod_LoadBrushModel (mod, buf);
|
|
|
|
break;
|
2000-05-11 08:39:08 +00:00
|
|
|
}
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_ForName
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Loads in a model for the given name
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *
|
|
|
|
Mod_ForName (char *name, qboolean crash)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *mod;
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
mod = Mod_FindName (name);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
Con_DPrintf ("Mod_ForName: %s, %p\n", name, mod);
|
2000-05-10 11:29:38 +00:00
|
|
|
return Mod_LoadModel (mod, crash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_Init
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Caches the data if needed
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void *
|
|
|
|
Mod_Extradata (model_t *mod)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
void *r;
|
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
r = Cache_Check (&mod->cache);
|
|
|
|
if (r)
|
|
|
|
return r;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
Mod_LoadModel (mod, true);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
if (!mod->cache.data)
|
|
|
|
SV_Error ("Mod_Extradata: caching failed");
|
|
|
|
return mod->cache.data;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_TouchModel
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_TouchModel (char *name)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
model_t *mod;
|
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
mod = Mod_FindName (name);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (!mod->needload) {
|
2000-09-20 22:11:17 +00:00
|
|
|
if (mod->type == mod_alias)
|
|
|
|
Cache_Check (&mod->cache);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-11 08:39:08 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_Print
|
2000-05-11 08:39:08 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_Print (void)
|
2000-05-11 08:39:08 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
2000-05-11 08:39:08 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
Con_Printf ("Cached models:\n");
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) {
|
|
|
|
Con_Printf ("%8p : %s\n", mod->cache.data, mod->name);
|
2000-05-11 08:39:08 +00:00
|
|
|
}
|
|
|
|
}
|