2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // models.c -- model loading and caching
22 // models are the only shared resource between a client and server running
23 // on the same machine.
28 char loadname[32]; // for hunk tags
30 // LordHavoc: increased from 512 to 2048
31 #define MAX_MOD_KNOWN 2048
32 model_t mod_known[MAX_MOD_KNOWN];
51 Caches the data if needed
54 void *Mod_Extradata (model_t *mod)
58 r = Cache_Check (&mod->cache);
62 Mod_LoadModel (mod, true);
65 Host_Error ("Mod_Extradata: caching failed");
66 return mod->cache.data;
74 void Mod_ClearAll (void)
79 for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
90 model_t *Mod_FindName (char *name)
96 Host_Error ("Mod_ForName: NULL name");
99 // search the currently loaded models
101 for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
102 if (!strcmp (mod->name, name) )
105 if (i == mod_numknown)
107 if (mod_numknown == MAX_MOD_KNOWN)
108 Host_Error ("mod_numknown == MAX_MOD_KNOWN");
109 strcpy (mod->name, name);
110 mod->needload = true;
123 void Mod_TouchModel (char *name)
127 mod = Mod_FindName (name);
131 Cache_Check (&mod->cache);
138 Loads a model into the cache
141 model_t *Mod_LoadModel (model_t *mod, qboolean crash)
150 d = Cache_Check (&mod->cache);
155 return mod; // not cached at all
158 Con_DPrintf("loading model %s\n", mod->name);
161 buf = (unsigned *)COM_LoadMallocFile (mod->name, false);
165 Host_Error ("Mod_NumForName: %s not found", mod->name); // LordHavoc: Sys_Error was *ANNOYING*
169 // allocate a new model
170 // COM_FileBase (mod->name, loadname);
171 strcpy(loadname, mod->name);
175 // call the apropriate loader
176 mod->needload = false;
178 switch (LittleLong(*(unsigned *)buf))
181 Mod_LoadAliasModel (mod, buf);
184 case MD2IDALIASHEADER: // LordHavoc: added Quake2 model support
185 Mod_LoadQ2AliasModel (mod, buf);
188 case (('O'<<24)+('M'<<16)+('Y'<<8)+'Z'):
189 Mod_LoadZymoticModel(mod, buf);
193 Mod_LoadSpriteModel (mod, buf);
197 Mod_LoadBrushModel (mod, buf);
209 Loads in a model for the given name
212 model_t *Mod_ForName (char *name, qboolean crash)
216 mod = Mod_FindName (name);
218 return Mod_LoadModel (mod, crash);
228 float RadiusFromBounds (vec3_t mins, vec3_t maxs)
233 for (i=0 ; i<3 ; i++)
234 corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
236 return Length (corner);
239 //=============================================================================
246 void Mod_Print (void)
251 Con_Printf ("Cached models:\n");
252 for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
254 Con_Printf ("%4iK : %8p : %s\n", (mod->cachesize + 1023) / 1024, mod->cache.data, mod->name);