2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "r_local.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/checksum.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *loadmodel;
|
|
|
|
char loadname[32]; // for hunk tags
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void Mod_LoadSpriteModel (model_t *mod, void *buffer);
|
|
|
|
void Mod_LoadBrushModel (model_t *mod, void *buffer);
|
|
|
|
void Mod_LoadAliasModel (model_t *mod, void *buffer);
|
|
|
|
model_t *Mod_LoadModel (model_t *mod, qboolean crash);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte mod_novis[MAX_MAP_LEAFS / 8];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MAX_MOD_KNOWN 512
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t mod_known[MAX_MOD_KNOWN];
|
|
|
|
int mod_numknown;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned *model_checksum;
|
|
|
|
texture_t *r_notexture_mip;
|
|
|
|
cvar_t *gl_subdivide_size;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Mod_Init
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Mod_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
gl_subdivide_size =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("gl_subdivide_size", "128", CVAR_ARCHIVE, NULL, "None");
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (mod_novis, 0xff, sizeof (mod_novis));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
Mod_ClearAll
|
|
|
|
===================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Mod_ClearAll (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mod->type != mod_alias)
|
|
|
|
mod->needload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Mod_FindName
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *
|
|
|
|
Mod_FindName (char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!name[0])
|
|
|
|
Sys_Error ("Mod_FindName: NULL name");
|
|
|
|
|
|
|
|
//
|
|
|
|
// search the currently loaded models
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
|
|
|
|
if (!strcmp (mod->name, name))
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i == mod_numknown) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mod_numknown == MAX_MOD_KNOWN)
|
|
|
|
Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
|
|
|
|
strcpy (mod->name, name);
|
|
|
|
mod->needload = true;
|
|
|
|
mod_numknown++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Mod_LoadModel
|
|
|
|
|
|
|
|
Loads a model into the cache
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *
|
|
|
|
Mod_LoadModel (model_t *mod, qboolean crash)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
void *d;
|
|
|
|
unsigned *buf;
|
|
|
|
byte stackbuf[1024]; // avoid dirtying the cache heap
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!mod->needload) {
|
|
|
|
if (mod->type == mod_alias) {
|
2001-02-19 21:15:25 +00:00
|
|
|
d = Cache_Check (&mod->cache);
|
|
|
|
if (d)
|
|
|
|
return mod;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
|
|
|
return mod; // not cached at all
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// load the file
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
buf =
|
|
|
|
(unsigned *) COM_LoadStackFile (mod->name, stackbuf, sizeof (stackbuf));
|
|
|
|
if (!buf) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (crash)
|
|
|
|
Sys_Error ("Mod_LoadModel: %s not found", mod->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// allocate a new model
|
|
|
|
//
|
|
|
|
COM_FileBase (mod->name, loadname);
|
|
|
|
|
|
|
|
loadmodel = mod;
|
|
|
|
|
|
|
|
//
|
|
|
|
// fill it in
|
|
|
|
//
|
|
|
|
|
|
|
|
// call the apropriate loader
|
|
|
|
mod->needload = false;
|
|
|
|
mod->hasfullbrights = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (LittleLong (*(unsigned *) buf)) {
|
|
|
|
case IDPOLYHEADER:
|
2001-02-19 21:15:25 +00:00
|
|
|
Mod_LoadAliasModel (mod, buf);
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
case IDSPRITEHEADER:
|
2001-02-19 21:15:25 +00:00
|
|
|
Mod_LoadSpriteModel (mod, buf);
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
default:
|
2001-02-19 21:15:25 +00:00
|
|
|
Mod_LoadBrushModel (mod, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Mod_ForName
|
|
|
|
|
|
|
|
Loads in a model for the given name
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *
|
|
|
|
Mod_ForName (char *name, qboolean crash)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *mod;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
mod = Mod_FindName (name);
|
|
|
|
|
|
|
|
return Mod_LoadModel (mod, crash);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Mod_Extradata
|
|
|
|
|
|
|
|
Caches the data if needed
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void *
|
|
|
|
Mod_Extradata (model_t *mod)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
void *r;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r = Cache_Check (&mod->cache);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
Mod_LoadModel (mod, true);
|
|
|
|
|
|
|
|
if (!mod->cache.data)
|
|
|
|
Sys_Error ("Mod_Extradata: caching failed");
|
|
|
|
return mod->cache.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Mod_TouchModel
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Mod_TouchModel (char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *mod;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
mod = Mod_FindName (name);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!mod->needload) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mod->type == mod_alias)
|
|
|
|
Cache_Check (&mod->cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Mod_Print
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Mod_Print (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
model_t *mod;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Con_Printf ("Cached models:\n");
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) {
|
|
|
|
Con_Printf ("%8p : %s\n", mod->cache.data, mod->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|