2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #if defined ( __linux__ ) || defined ( __APPLE__ )
29 eclass_t *eclass = NULL;
30 eclass_t *eclass_bad = NULL;
31 const vec3_t smallbox[2] = {{-8,-8,-8},{8,8,8}};
32 char eclass_directory[1024];
34 qboolean parsing_single = false;
38 implementation of the EClass manager API
40 eclass_t** Get_EClass_E(){
44 void Set_Eclass_Found( qboolean b ){
48 qboolean Get_Parsing_Single(){
49 return parsing_single;
53 // md3 cache for misc_models
54 //eclass_t *g_md3Cache = NULL;
58 the classname, color triple, and bounding box are parsed out of comments
59 A ? size means take the exact brush size.
61 / *QUAKED <classname> (0 0 0) ?
62 / *QUAKED <classname> (0 0 0) (-8 -8 -8) (8 8 8)
64 Flag names can follow the size description:
66 / *QUAKED func_door (0 .5 .8) ? START_OPEN STONE_SOUND DOOR_DONT_LINK GOLD_KEY SILVER_KEY
70 void CleanEntityList( eclass_t *&pList ){
73 eclass_t* pTemp = pList->next;
75 entitymodel *model = pList->model;
76 while ( model != NULL )
78 delete []model->pTriList;
79 if ( model->strSkin ) {
80 g_string_free( (GString *)model->strSkin, TRUE );
82 model->strSkin = NULL;
86 if ( pList->modelpath ) {
87 free( pList->modelpath );
88 pList->modelpath = NULL;
90 if ( pList->skinpath ) {
91 free( pList->skinpath );
92 pList->skinpath = NULL;
96 free( pList->comments );
106 void CleanUpEntities(){
107 // NOTE: maybe some leak checks needed .. older versions of Radiant looked like they were freezing more stuff
108 CleanEntityList( eclass );
109 //CleanEntityList(g_md3Cache);
111 free( eclass_bad->name );
112 free( eclass_bad->comments );
118 void EClass_InsertSortedList( eclass_t *&pList, eclass_t *e ){
128 if ( stricmp( e->name, s->name ) < 0 ) {
136 if ( !s->next || stricmp( e->name, s->next->name ) < 0 ) {
147 Eclass_InsertAlphabetized
150 void Eclass_InsertAlphabetized( eclass_t *e ){
152 EClass_InsertSortedList( eclass, e );
163 if ( stricmp( e->name, s->name ) < 0 ) {
171 if ( !s->next || stricmp( e->name, s->next->name ) < 0 ) {
182 This looks at each eclass_t, if it has a "modelpath" set then it leaves it alone
183 if it's not set it checks to see if a file called "sprites/<eclassname>.*" exists, and
184 if it does exist then it sets the "modelpath" to "sprites/<eclassname>.spr"
186 void Eclass_CreateSpriteModelPaths(){
187 int Counts[4] = { 0, 0, 0, 0 };
188 char filename[512]; // should be big enough, ExtractFileBase doesn't take a buffer size...
191 // get a list of all sprite/*>* files in all sprite/ directories
192 Sys_Printf( "Searching VFS for files in sprites/*.* that match entity names...\n" );
193 GSList *pFiles = vfsGetFileList( "sprites", NULL );
198 // find an eclass without a modelpath.
199 for ( e = eclass ; e ; e = e->next )
202 if ( e->modelpath ) {
204 Sys_Printf( "Ignoring sprite for entity %s (modelpath: \"%s\")\n",e->name,e->modelpath );
207 continue; // ignore this eclass, it's already got a model
210 // TODO: remove this check when we can have sprites for non-fixed size entities.
211 if ( !e->fixedsize ) {
213 Sys_Printf( "Ignoring sprite for non-fixed-size entity %s\n",e->name );
216 continue; // can't have sprites for non-fixed size entities (yet!)
220 Sys_Printf( "Searching for sprite for fixed-size entity %s...",e->name );
222 pFile = pFiles; // point to start of list
224 // look for a file that has the same name, with any extension.
229 // strip the path/ and the .extension.
230 ExtractFileBase( (char *)pFile->data,filename );
232 // does the eclass name match the filename?
233 if ( stricmp( e->name,filename ) == 0 ) {
234 // yes, so generate a sprite filename using the all-encompasing .spr extension
235 // so that the model wrapper knows the sprite model plugin will be the model
236 // plugin used to render it.
237 CString strSpriteName;
238 strSpriteName.Format( "sprites/%s.spr",e->name );
239 e->modelpath = strdup( strSpriteName.GetBuffer() );
240 Sys_Printf( "Found! (\"%s\")\n",(char *)pFile->data );
248 Sys_Printf( "not found\n" );
253 vfsClearFileDirList( &pFiles );
255 Sys_Printf( "%d entities were scanned\n"
256 "%d entities that already had models/sprites were ignored\n"
257 "%d non-fixed-size entities were ignored\n"
258 "%d entities did not have matching sprite files\n"
259 "%d entities had sprite files and have been attached\n",
260 Counts[0],Counts[1],Counts[2],Counts[0] - Counts[3],Counts[3] );
264 void EClass_InitForFileList( GSList *pFiles, _EClassTable *pTable ){
265 GSList *pFile = pFiles;
268 // for a given name, we grab the first .def in the vfs
269 // this allows to override baseq3/scripts/entities.def for instance
270 char relPath[PATH_MAX];
271 strcpy( relPath, "scripts/" );
272 strcat( relPath, (char*)pFile->data );
273 if ( !vfsGetFullPath( relPath, 0, 0 ) ) {
274 Sys_FPrintf( SYS_ERR, "Failed to find the full path for '%s' in the VFS\n", relPath );
277 pTable->m_pfnScanFile( vfsGetFullPath( relPath, 0, 0 ) );
284 Manually create an eclass_t, for when no modules exist.
285 this replaces and centralizes the eclass_t allocation
287 eclass_t * EClass_Create( const char *name, float col1, float col2, float col3, const vec3_t *mins, const vec3_t *maxs, const char *comments ){
291 e = (eclass_t*)malloc( sizeof( *e ) );
292 memset( e, 0, sizeof( *e ) );
294 e->name = strdup( name );
296 // grab the color, reformat as texture name
300 sprintf( color, "(%f %f %f)", e->color[0], e->color[1], e->color[2] );
301 e->texdef.SetName( color );
304 if ( mins && maxs ) {
306 // If we set worldspawn to be a fixed-size all the textures are
307 // displayed as flat-shaded. This is a KLUDGE now that we have
308 // multiple game support as the worldspawn entity is game specific.
309 // Note that this is only ever fixed for the user if a definition
310 // for the worldspawn entity was not loaded, this can happen for
312 // a) no entity definition plugin exists
313 // b) no entity definition files were found
314 // c) no entity definition file contained an entry for worldspawn.
316 if ( stricmp( name,"worldspawn" ) != 0 ) {
321 memcpy( e->mins,mins,sizeof( vec3_t ) );
322 memcpy( e->maxs,maxs,sizeof( vec3_t ) );
326 e->comments = strdup( comments );
330 e->comments = (char*)malloc( 1 );
331 e->comments[0] = '\0';
340 // start by creating the default unknown eclass
341 eclass_bad = EClass_Create( "UNKNOWN_CLASS", 0, 0.5, 0,NULL,NULL,NULL );
343 // now scan the definitions
344 _EClassTable *pTable = &g_EClassDefTable;
347 // read in all scripts/*.<extension>
348 pFiles = vfsGetFileList( "scripts", pTable->m_pfnGetExtension() );
350 GSList *pFile = pFiles;
354 \todo the MP/SP filtering rules need to be CLEANED UP and SANITIZED
357 // JKII SP/MP mapping mode
358 if ( g_pGameDescription->mGameFile == "jk2.game" || g_pGameDescription->mGameFile == "ja.game" ) {
359 if ( !strcmp( ValueForKey( g_qeglobals.d_project_entity, "gamemode" ), "sp" ) ) {
360 // SP mapping, ignore mp_*.def
361 char *name = (char *)pFile->data;
362 if ( name[0] == 'm' && name[1] == 'p' && name[2] == '_' ) {
363 Sys_Printf( "Single Player mapping mode. Ignoring '%s'\n", name );
370 // MP mapping, ignore sp_*.def
371 char *name = (char *)pFile->data;
372 if ( name[0] == 's' && name[1] == 'p' && name[2] == '_' ) {
373 Sys_Printf( "Multiplayer mapping mode. Ignoring '%s'\n", name );
380 // STVEF SP/MP mapping mode
381 else if ( g_pGameDescription->mGameFile == "stvef.game" ) {
382 if ( !strcmp( ValueForKey( g_qeglobals.d_project_entity, "gamemode" ), "sp" ) ) {
383 // SP mapping, ignore mp_*.def
384 char *name = (char *)pFile->data;
385 if ( name[0] == 'm' && name[1] == 'p' && name[2] == '_' ) {
386 Sys_Printf( "Single Player mapping mode. Ignoring '%s'\n", name );
393 // HM mapping, ignore sp_*.def
394 char *name = (char *)pFile->data;
395 if ( name[0] == 'h' && name[1] == 'm' && name[2] == '_' ) {
396 Sys_Printf( "HoloMatch mapping mode. Ignoring '%s'\n", name );
402 // for a given name, we grab the first .def in the vfs
403 // this allows to override baseq3/scripts/entities.def for instance
404 char relPath[PATH_MAX];
405 strcpy( relPath, "scripts/" );
406 strcat( relPath, (char*)pFile->data );
407 char *fullpath = vfsGetFullPath( relPath, 0, 0 );
409 Sys_FPrintf( SYS_ERR, "Failed to find the full path for \"%s\" in the VFS\n", relPath );
412 pTable->m_pfnScanFile( fullpath );
414 if ( g_pGameDescription->mEClassSingleLoad ) {
419 vfsClearFileDirList( &pFiles );
423 Sys_FPrintf( SYS_ERR, "Didn't find any scripts/*.%s files to load EClass information\n", pTable->m_pfnGetExtension() );
426 // we deal with two formats max, if the other table exists, loop again
427 if ( g_bHaveEClassExt && pTable == &g_EClassDefTable ) {
428 pTable = &g_EClassExtTable;
431 pTable = NULL; // done, exit
434 Eclass_CreateSpriteModelPaths();
437 eclass_t *Eclass_ForName( const char *name, qboolean has_brushes ){
440 if ( !name || *name == '\0' ) {
445 // grouping stuff, not an eclass
446 if ( strcmp( name, "group_info" ) == 0 ) {
447 Sys_Printf( "WARNING: unexpected group_info entity in Eclass_ForName\n" );
455 for ( e = eclass ; e ; e = e->next )
456 if ( !strcmp( name, e->name ) ) {
460 // create a new class for it
462 e = EClass_Create( name, 0, 0.5, 0,NULL,NULL,"Not found in source." );
466 e = EClass_Create( name, 0, 0.5, 0,&smallbox[0],&smallbox[1],"Not found in source." );
469 Eclass_InsertAlphabetized( e );