]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/eclass.cpp
fix homedir version
[xonotic/netradiant.git] / radiant / eclass.cpp
index 991e9b87f176323996e37583d964eef3690b50c9..ea9828e510857749ebe09e3a0eacee48f19f1c2a 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-#include "stdafx.h"\r
-#include <sys/stat.h>\r
-#if defined (__linux__) || defined (__APPLE__)\r
-#include <dirent.h>\r
-#endif\r
-#include "assert.h"\r
-\r
-eclass_t       *eclass = NULL;\r
-eclass_t       *eclass_bad = NULL;\r
-const vec3_t smallbox[2] = {{-8,-8,-8},{8,8,8}};\r
-char           eclass_directory[1024];\r
-\r
-qboolean parsing_single = false;\r
-eclass_t *eclass_e;\r
-\r
-/*!\r
-implementation of the EClass manager API\r
-*/\r
-eclass_t** Get_EClass_E()\r
-{\r
-  return &eclass_e;\r
-}\r
-\r
-void Set_Eclass_Found(qboolean b)\r
-{\r
-  eclass_found = b;\r
-}\r
-\r
-qboolean Get_Parsing_Single()\r
-{\r
-  return parsing_single;\r
-}\r
-\r
-\r
-// md3 cache for misc_models\r
-//eclass_t *g_md3Cache = NULL;\r
-\r
-/*\r
-\r
-the classname, color triple, and bounding box are parsed out of comments\r
-A ? size means take the exact brush size.\r
-\r
-/ *QUAKED <classname> (0 0 0) ?\r
-/ *QUAKED <classname> (0 0 0) (-8 -8 -8) (8 8 8)\r
-\r
-Flag names can follow the size description:\r
-\r
-/ *QUAKED func_door (0 .5 .8) ? START_OPEN STONE_SOUND DOOR_DONT_LINK GOLD_KEY SILVER_KEY\r
-\r
-*/\r
-\r
-void CleanEntityList(eclass_t *&pList)\r
-{\r
-  while (pList)\r
-  {\r
-    eclass_t* pTemp = pList->next;\r
-\r
-    entitymodel *model = pList->model;\r
-    while (model != NULL)\r
-    {\r
-      delete []model->pTriList;\r
-      if (model->strSkin)\r
-        g_string_free( (GString *)model->strSkin, TRUE );\r
-      model->strSkin = NULL;\r
-      model = model->pNext;\r
-    }\r
-    \r
-    if (pList->modelpath) {\r
-      free(pList->modelpath);\r
-      pList->modelpath = NULL;\r
-    }\r
-    if (pList->skinpath) {\r
-      free(pList->skinpath);\r
-      pList->skinpath = NULL;\r
-    }\r
-    \r
-    free(pList->name);\r
-    free(pList->comments);\r
-    free(pList);\r
-    pList = pTemp;\r
-  }\r
-\r
-  pList = NULL;\r
-\r
-}\r
-\r
-\r
-void CleanUpEntities()\r
-{\r
-  // NOTE: maybe some leak checks needed .. older versions of Radiant looked like they were freezing more stuff\r
-  CleanEntityList(eclass);\r
-  //CleanEntityList(g_md3Cache);\r
-  if (eclass_bad)\r
-  {\r
-    free(eclass_bad->name);\r
-    free(eclass_bad->comments);\r
-    free(eclass_bad);\r
-    eclass_bad = NULL;\r
-  }\r
-}\r
-\r
-void EClass_InsertSortedList(eclass_t *&pList, eclass_t *e)\r
-{\r
-       eclass_t        *s;\r
-       \r
-       if (!pList)\r
-       {\r
-               pList = e;\r
-               return;\r
-       }\r
-\r
-\r
-       s = pList;\r
-       if (stricmp (e->name, s->name) < 0)\r
-       {\r
-               e->next = s;\r
-               pList = e;\r
-               return;\r
-       }\r
-\r
-       do\r
-       {\r
-               if (!s->next || stricmp (e->name, s->next->name) < 0)\r
-               {\r
-                       e->next = s->next;\r
-                       s->next = e;\r
-                       return;\r
-               }\r
-               s=s->next;\r
-       } while (1);\r
-}\r
-\r
-/*\r
-=================\r
-Eclass_InsertAlphabetized\r
-=================\r
-*/\r
-void Eclass_InsertAlphabetized (eclass_t *e)\r
-{\r
-#if 1\r
-  EClass_InsertSortedList(eclass, e);\r
-#else\r
-       eclass_t        *s;\r
-       \r
-       if (!eclass)\r
-       {\r
-               eclass = e;\r
-               return;\r
-       }\r
-\r
-\r
-       s = eclass;\r
-       if (stricmp (e->name, s->name) < 0)\r
-       {\r
-               e->next = s;\r
-               eclass = e;\r
-               return;\r
-       }\r
-\r
-       do\r
-       {\r
-               if (!s->next || stricmp (e->name, s->next->name) < 0)\r
-               {\r
-                       e->next = s->next;\r
-                       s->next = e;\r
-                       return;\r
-               }\r
-               s=s->next;\r
-       } while (1);\r
-#endif\r
-}\r
-\r
-/*!\r
-This looks at each eclass_t, if it has a "modelpath" set then it leaves it alone\r
-if it's not set it checks to see if a file called "sprites/<eclassname>.*" exists, and\r
-if it does exist then it sets the "modelpath" to "sprites/<eclassname>.spr"\r
-*/\r
-void Eclass_CreateSpriteModelPaths()\r
-{\r
-  int Counts[4] = { 0, 0, 0, 0 };\r
-  char filename[512]; // should be big enough, ExtractFileBase doesn't take a buffer size...\r
-  eclass_t *e;\r
-\r
-  // get a list of all sprite/*>* files in all sprite/ directories\r
-  Sys_Printf("Searching VFS for files in sprites/*.* that match entity names...\n");\r
-  GSList *pFiles = vfsGetFileList("sprites", NULL);\r
-  GSList *pFile;\r
-\r
-  if (pFiles)\r
-  {\r
-  \r
-    // find an eclass without a modelpath.\r
-    for (e=eclass ; e ; e=e->next)\r
-    {\r
-      Counts[0]++;\r
-      if (e->modelpath)\r
-      {\r
-#ifdef _DEBUG\r
-        Sys_Printf("Ignoring sprite for entity %s (modelpath: \"%s\")\n",e->name,e->modelpath);\r
-#endif\r
-        Counts[1]++;\r
-        continue;  // ignore this eclass, it's already got a model\r
-      }\r
-\r
-      // TODO: remove this check when we can have sprites for non-fixed size entities.\r
-      if (!e->fixedsize)\r
-      {\r
-#ifdef _DEBUG\r
-        Sys_Printf("Ignoring sprite for non-fixed-size entity %s\n",e->name);\r
-#endif\r
-        Counts[2]++;\r
-        continue;  // can't have sprites for non-fixed size entities (yet!)\r
-      }\r
-\r
-\r
-      Sys_Printf("Searching for sprite for fixed-size entity %s...",e->name);\r
-\r
-      pFile = pFiles; // point to start of list\r
-\r
-      // look for a file that has the same name, with any extension.\r
-      bool Found = FALSE;\r
-      while (pFile)\r
-      {\r
-\r
-        // strip the path/ and the .extension.\r
-        ExtractFileBase((char *)pFile->data,filename);\r
-\r
-        // does the eclass name match the filename?\r
-        if (stricmp(e->name,filename) == 0)\r
-        {\r
-          // yes, so generate a sprite filename using the all-encompasing .spr extension\r
-          // so that the model wrapper knows the sprite model plugin will be the model\r
-          // plugin used to render it.\r
-          CString strSpriteName;\r
-          strSpriteName.Format("sprites/%s.spr",e->name);\r
-          e->modelpath = strdup(strSpriteName.GetBuffer());\r
-          Sys_Printf("Found! (\"%s\")\n",(char *)pFile->data);\r
-          Counts[3]++;\r
-          Found = TRUE;\r
-        }\r
-        pFile = pFile->next;\r
-      }\r
-\r
-      if (!Found)\r
-        Sys_Printf("not found\n");\r
-\r
-    }\r
-\r
-    vfsClearFileDirList(&pFiles);\r
-  }\r
-  Sys_Printf("%d entities were scanned\n"\r
-             "%d entities that already had models/sprites were ignored\n"\r
-             "%d non-fixed-size entities were ignored\n"\r
-             "%d entities did not have matching sprite files\n"\r
-             "%d entities had sprite files and have been attached\n",\r
-             Counts[0],Counts[1],Counts[2],Counts[0]-Counts[3],Counts[3]);\r
-\r
-}\r
-\r
-void EClass_InitForFileList(GSList *pFiles, _EClassTable *pTable)\r
-{\r
-  GSList *pFile = pFiles;\r
-  while (pFile)\r
-  {\r
-    // for a given name, we grab the first .def in the vfs\r
-    // this allows to override baseq3/scripts/entities.def for instance\r
-    char relPath[PATH_MAX];\r
-    strcpy(relPath, "scripts/");\r
-    strcat(relPath, (char*)pFile->data);\r
-    // FIXME TTimo http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=130\r
-    if (!vfsGetFullPath(relPath, 0, 0))\r
-    {\r
-      Sys_FPrintf(SYS_ERR, "Failed to find the full path for '%s' in the VFS\n", relPath);\r
-      Sys_FPrintf(SYS_ERR, "did you hit bug http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=130 ?\n");\r
-    }\r
-    else\r
-      pTable->m_pfnScanFile(vfsGetFullPath(relPath, 0, 0));\r
-    pFile = pFile->next;\r
-  }\r
-}\r
-\r
-/*!\r
-Manually create an eclass_t, for when no modules exist.\r
-this replaces and centralizes the eclass_t allocation\r
-*/\r
-eclass_t * EClass_Create( const char *name, float col1, float col2, float col3, const vec3_t *mins, const vec3_t *maxs, const char *comments )\r
-{\r
-  eclass_t *e;\r
-       char    color[128];\r
-\r
-  e = (eclass_t*)malloc(sizeof(*e));\r
-       memset (e, 0, sizeof(*e));\r
-\r
-  e->name = strdup(name);\r
-\r
-  // grab the color, reformat as texture name\r
-       e->color[0] = col1;\r
-  e->color[1] = col2;\r
-  e->color[2] = col3;\r
-       sprintf (color, "(%f %f %f)", e->color[0], e->color[1], e->color[2]);\r
-       e->texdef.SetName(color);\r
-\r
-  // supplied size ?\r
-  if (mins && maxs)\r
-  {\r
-    // Hydra:\r
-    // If we set worldspawn to be a fixed-size all the textures are\r
-    // displayed as flat-shaded.  This is a KLUDGE now that we have\r
-    // multiple game support as the worldspawn entity is game specific.\r
-    // Note that this is only ever fixed for the user if a definition\r
-    // for the worldspawn entity was not loaded, this can happen for\r
-    // several reasons:\r
-    // a) no entity definition plugin exists\r
-    // b) no entity definition files were found\r
-    // c) no entity definition file contained an entry for worldspawn.\r
-\r
-    if (stricmp(name,"worldspawn") != 0) e->fixedsize = true;\r
-\r
-    // copy the sizes..\r
-    memcpy(e->mins,mins,sizeof(vec3_t));\r
-    memcpy(e->maxs,maxs,sizeof(vec3_t));\r
-  }\r
-\r
-  if (comments)\r
-    e->comments = strdup(comments);\r
-  else\r
-  {\r
-    e->comments = (char*)malloc(1);\r
-    e->comments[0] = '\0';\r
-  }\r
-\r
-  return e;\r
-}\r
-\r
-void Eclass_Init ()\r
-{\r
-  GSList *pFiles;\r
-\r
-  // start by creating the default unknown eclass\r
-  eclass_bad = EClass_Create("UNKNOWN_CLASS" , 0, 0.5, 0,NULL,NULL,NULL);\r
-  \r
-  // now scan the definitions\r
-  _EClassTable *pTable = &g_EClassDefTable;\r
-  while (pTable)\r
-  {\r
-    // read in all scripts/*.<extension>\r
-    pFiles = vfsGetFileList("scripts", pTable->m_pfnGetExtension());\r
-    if (pFiles)\r
-    {\r
-      GSList *pFile = pFiles;\r
-      while (pFile)\r
-      {\r
-        /*!\r
-        \todo the MP/SP filtering rules need to be CLEANED UP and SANITIZED\r
-        */\r
-        // HACK\r
-        // JKII SP/MP mapping mode\r
-        if (g_pGameDescription->mGameFile == "jk2.game" || g_pGameDescription->mGameFile == "ja.game")\r
-        {\r
-          if (!strcmp(ValueForKey(g_qeglobals.d_project_entity, "gamemode"), "sp"))\r
-          {\r
-            // SP mapping, ignore mp_*.def\r
-            char *name = (char *)pFile->data;\r
-            if (name[0]=='m' && name[1]=='p' && name[2]=='_')\r
-            {\r
-              Sys_Printf("Single Player mapping mode. Ignoring '%s'\n", name);\r
-              pFile = pFile->next;\r
-              continue;\r
-            }\r
-          }\r
-          else\r
-          {\r
-            // MP mapping, ignore sp_*.def\r
-            char *name = (char *)pFile->data;\r
-            if (name[0]=='s' && name[1]=='p' && name[2]=='_')\r
-            {\r
-              Sys_Printf("Multiplayer mapping mode. Ignoring '%s'\n", name);\r
-              pFile = pFile->next;\r
-              continue;\r
-            }\r
-          }\r
-        }\r
-        // RIANT\r
-        // STVEF SP/MP mapping mode\r
-        else if (g_pGameDescription->mGameFile == "stvef.game")\r
-        {\r
-          if (!strcmp(ValueForKey(g_qeglobals.d_project_entity, "gamemode"), "sp"))\r
-          {\r
-            // SP mapping, ignore mp_*.def\r
-            char *name = (char *)pFile->data;\r
-            if (name[0]=='m' && name[1]=='p' && name[2]=='_')\r
-            {\r
-              Sys_Printf("Single Player mapping mode. Ignoring '%s'\n", name);\r
-              pFile = pFile->next;\r
-              continue;\r
-            }\r
-          }\r
-          else\r
-          {\r
-            // HM mapping, ignore sp_*.def\r
-            char *name = (char *)pFile->data;\r
-            if (name[0]=='h' && name[1]=='m' && name[2]=='_')\r
-            {\r
-              Sys_Printf("HoloMatch mapping mode. Ignoring '%s'\n", name);\r
-              pFile = pFile->next;\r
-              continue;\r
-            }\r
-          }\r
-        }\r
-        // for a given name, we grab the first .def in the vfs\r
-        // this allows to override baseq3/scripts/entities.def for instance\r
-        char relPath[PATH_MAX];\r
-        strcpy(relPath, "scripts/");\r
-        strcat(relPath, (char*)pFile->data);\r
-        // FIXME TTimo http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=130\r
-        char *fullpath = vfsGetFullPath(relPath, 0, 0);\r
-        if (!fullpath)\r
-        {\r
-          Sys_FPrintf(SYS_ERR, "Failed to find the full path for \"%s\" in the VFS\n", relPath);\r
-          Sys_FPrintf(SYS_ERR, "did you hit bug http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=130 ?\n");\r
-        }\r
-        else\r
-          pTable->m_pfnScanFile(fullpath);\r
-        if (g_pGameDescription->mEClassSingleLoad)\r
-          break;\r
-        pFile = pFile->next;\r
-      }\r
-      vfsClearFileDirList(&pFiles);\r
-      pFiles = NULL;\r
-    }\r
-    else\r
-      Sys_FPrintf(SYS_ERR, "Didn't find any scripts/*.%s files to load EClass information\n", pTable->m_pfnGetExtension());\r
-    \r
-    // we deal with two formats max, if the other table exists, loop again\r
-    if (g_bHaveEClassExt && pTable == &g_EClassDefTable)\r
-      pTable = &g_EClassExtTable;\r
-    else\r
-      pTable = NULL; // done, exit\r
-  }\r
-  Eclass_CreateSpriteModelPaths();\r
-}\r
-\r
-eclass_t *Eclass_ForName (const char *name, qboolean has_brushes)\r
-{\r
-       eclass_t        *e;\r
-\r
-  if (!name || *name == '\0')\r
-    return eclass_bad;\r
-\r
-#ifdef _DEBUG\r
-  // grouping stuff, not an eclass\r
-  if (strcmp(name, "group_info")==0)\r
-    Sys_Printf("WARNING: unexpected group_info entity in Eclass_ForName\n");\r
-#endif\r
-\r
-       if (!name)\r
-               return eclass_bad;\r
-\r
-       for (e=eclass ; e ; e=e->next)\r
-               if (!strcmp (name, e->name))\r
-                       return e;\r
-\r
-       // create a new class for it\r
-       if (has_brushes)\r
-       {\r
-    e = EClass_Create(name , 0, 0.5, 0,NULL,NULL,"Not found in source.");\r
-       }\r
-       else\r
-       {\r
-    e = EClass_Create(name , 0, 0.5, 0,&smallbox[0],&smallbox[1],"Not found in source.");\r
-       }\r
-\r
-       Eclass_InsertAlphabetized (e);\r
-\r
-       return e;\r
-}\r
+/*
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+   This file is part of GtkRadiant.
+
+   GtkRadiant 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.
+
+   GtkRadiant 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 GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "eclass.h"
+
+#include "debugging/debugging.h"
+
+#include <map>
+
+#include "ifilesystem.h"
+
+#include "string/string.h"
+#include "eclasslib.h"
+#include "os/path.h"
+#include "os/dir.h"
+#include "stream/stringstream.h"
+#include "moduleobservers.h"
+
+#include "cmdlib.h"
+
+#include "preferences.h"
+#include "mainframe.h"
+
+
+namespace
+{
+typedef std::map<const char*, EntityClass*, RawStringLessNoCase> EntityClasses;
+EntityClasses g_entityClasses;
+EntityClass   *eclass_bad = 0;
+char eclass_directory[1024];
+typedef std::map<CopiedString, ListAttributeType> ListAttributeTypes;
+ListAttributeTypes g_listTypes;
+}
+
+EClassModules& EntityClassManager_getEClassModules();
+
+/*!
+   implementation of the EClass manager API
+ */
+
+void CleanEntityList( EntityClasses& entityClasses ){
+       for ( EntityClasses::iterator i = entityClasses.begin(); i != entityClasses.end(); ++i )
+       {
+               ( *i ).second->free( ( *i ).second );
+       }
+       entityClasses.clear();
+}
+
+void Eclass_Clear(){
+       CleanEntityList( g_entityClasses );
+       g_listTypes.clear();
+}
+
+EntityClass* EClass_InsertSortedList( EntityClasses& entityClasses, EntityClass *entityClass ){
+       std::pair<EntityClasses::iterator, bool> result = entityClasses.insert( EntityClasses::value_type( entityClass->name(), entityClass ) );
+       if ( !result.second ) {
+               entityClass->free( entityClass );
+       }
+       return ( *result.first ).second;
+}
+
+EntityClass* Eclass_InsertAlphabetized( EntityClass *e ){
+       return EClass_InsertSortedList( g_entityClasses, e );
+}
+
+void Eclass_forEach( EntityClassVisitor& visitor ){
+       for ( EntityClasses::iterator i = g_entityClasses.begin(); i != g_entityClasses.end(); ++i )
+       {
+               visitor.visit( ( *i ).second );
+       }
+}
+
+
+class RadiantEclassCollector : public EntityClassCollector
+{
+public:
+void insert( EntityClass* eclass ){
+       Eclass_InsertAlphabetized( eclass );
+}
+void insert( const char* name, const ListAttributeType& list ){
+       g_listTypes.insert( ListAttributeTypes::value_type( name, list ) );
+}
+};
+
+RadiantEclassCollector g_collector;
+
+const ListAttributeType* EntityClass_findListType( const char* name ){
+       ListAttributeTypes::iterator i = g_listTypes.find( name );
+       if ( i != g_listTypes.end() ) {
+               return &( *i ).second;
+       }
+       return 0;
+}
+
+
+class EntityClassFilterMode
+{
+public:
+bool filter_mp_sp;
+const char* mp_ignore_prefix;
+const char* sp_ignore_prefix;
+
+EntityClassFilterMode() :
+       filter_mp_sp( !string_empty( g_pGameDescription->getKeyValue( "eclass_filter_gamemode" ) ) ),
+       mp_ignore_prefix( g_pGameDescription->getKeyValue( "eclass_sp_prefix" ) ),
+       sp_ignore_prefix( g_pGameDescription->getKeyValue( "eclass_mp_prefix" ) ){
+       if ( string_empty( mp_ignore_prefix ) ) {
+               mp_ignore_prefix = "sp_";
+       }
+       if ( string_empty( sp_ignore_prefix ) ) {
+               sp_ignore_prefix = "mp_";
+       }
+}
+};
+
+class EntityClassesLoadFile
+{
+const EntityClassScanner& scanner;
+const char* m_directory;
+public:
+EntityClassesLoadFile( const EntityClassScanner& scanner, const char* directory ) : scanner( scanner ), m_directory( directory ){
+}
+void operator()( const char* name ) const {
+       EntityClassFilterMode filterMode;
+
+       if ( filterMode.filter_mp_sp ) {
+               if ( string_empty( GlobalRadiant().getGameMode() ) || string_equal( GlobalRadiant().getGameMode(), "sp" ) ) {
+                       if ( string_equal_n( name, filterMode.sp_ignore_prefix, strlen( filterMode.sp_ignore_prefix ) ) ) {
+                               globalOutputStream() << "Ignoring '" << name << "'\n";
+                               return;
+                       }
+               }
+               else
+               {
+                       if ( string_equal_n( name, filterMode.mp_ignore_prefix, strlen( filterMode.mp_ignore_prefix ) ) ) {
+                               globalOutputStream() << "Ignoring '" << name << "'\n";
+                               return;
+                       }
+               }
+       }
+
+       // for a given name, we grab the first .def in the vfs
+       // this allows to override baseq3/scripts/entities.def for instance
+       StringOutputStream relPath( 256 );
+       relPath << m_directory << name;
+
+       scanner.scanFile( g_collector, relPath.c_str() );
+}
+};
+
+struct PathLess
+{
+       bool operator()( const CopiedString& path, const CopiedString& other ) const {
+               return path_less( path.c_str(), other.c_str() );
+       }
+};
+
+typedef std::map<CopiedString, const char*, PathLess> Paths;
+
+class PathsInsert
+{
+Paths& m_paths;
+const char* m_directory;
+public:
+PathsInsert( Paths& paths, const char* directory ) : m_paths( paths ), m_directory( directory ){
+}
+void operator()( const char* name ) const {
+       m_paths.insert( Paths::value_type( name, m_directory ) );
+}
+};
+
+
+void EntityClassQuake3_constructDirectory( const char* directory, const char* extension, Paths& paths ){
+       globalOutputStream() << "EntityClass: searching " << makeQuoted( directory ) << " for *." << extension << '\n';
+       Directory_forEach( directory, matchFileExtension( extension, PathsInsert( paths, directory ) ) );
+}
+
+
+void EntityClassQuake3_Construct(){
+       StringOutputStream baseDirectory( 256 );
+       StringOutputStream gameDirectory( 256 );
+       const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+       const char* gamename = GlobalRadiant().getGameName();
+       baseDirectory << GlobalRadiant().getGameToolsPath() << basegame << '/';
+       gameDirectory << GlobalRadiant().getGameToolsPath() << gamename << '/';
+
+       class LoadEntityDefinitionsVisitor : public EClassModules::Visitor
+       {
+       const char* baseDirectory;
+       const char* gameDirectory;
+public:
+       LoadEntityDefinitionsVisitor( const char* baseDirectory, const char* gameDirectory )
+               : baseDirectory( baseDirectory ), gameDirectory( gameDirectory ){
+       }
+       void visit( const char* name, const EntityClassScanner& table ) const {
+               Paths paths;
+               EntityClassQuake3_constructDirectory( baseDirectory, table.getExtension(), paths );
+               if ( !string_equal( baseDirectory, gameDirectory ) ) {
+                       EntityClassQuake3_constructDirectory( gameDirectory, table.getExtension(), paths );
+               }
+
+               for ( Paths::iterator i = paths.begin(); i != paths.end(); ++i )
+               {
+                       EntityClassesLoadFile( table, ( *i ).second ) ( ( *i ).first.c_str() );
+               }
+       }
+       };
+
+       EntityClassManager_getEClassModules().foreachModule( LoadEntityDefinitionsVisitor( baseDirectory.c_str(), gameDirectory.c_str() ) );
+}
+
+EntityClass *Eclass_ForName( const char *name, bool has_brushes ){
+       ASSERT_NOTNULL( name );
+
+       if ( string_empty( name ) ) {
+               return eclass_bad;
+       }
+
+       EntityClasses::iterator i = g_entityClasses.find( name );
+       if ( i != g_entityClasses.end() && string_equal( ( *i ).first, name ) ) {
+               return ( *i ).second;
+       }
+
+       EntityClass* e = EntityClass_Create_Default( name, has_brushes );
+       return Eclass_InsertAlphabetized( e );
+}
+
+class EntityClassQuake3 : public ModuleObserver
+{
+std::size_t m_unrealised;
+ModuleObservers m_observers;
+public:
+EntityClassQuake3() : m_unrealised( 4 ){
+}
+void realise(){
+       if ( --m_unrealised == 0 ) {
+               //globalOutputStream() << "Entity Classes: realise\n";
+               EntityClassQuake3_Construct();
+               m_observers.realise();
+       }
+}
+void unrealise(){
+       if ( ++m_unrealised == 1 ) {
+               m_observers.unrealise();
+               //globalOutputStream() << "Entity Classes: unrealise\n";
+               Eclass_Clear();
+       }
+}
+void attach( ModuleObserver& observer ){
+       m_observers.attach( observer );
+}
+void detach( ModuleObserver& observer ){
+       m_observers.detach( observer );
+}
+};
+
+EntityClassQuake3 g_EntityClassQuake3;
+
+void EntityClass_attach( ModuleObserver& observer ){
+       g_EntityClassQuake3.attach( observer );
+}
+void EntityClass_detach( ModuleObserver& observer ){
+       g_EntityClassQuake3.detach( observer );
+}
+
+void EntityClass_realise(){
+       g_EntityClassQuake3.realise();
+}
+void EntityClass_unrealise(){
+       g_EntityClassQuake3.unrealise();
+}
+
+void EntityClassQuake3_construct(){
+       // start by creating the default unknown eclass
+       eclass_bad = EClass_Create( "UNKNOWN_CLASS", Vector3( 0.0f, 0.5f, 0.0f ), "" );
+
+       EntityClass_realise();
+}
+
+void EntityClassQuake3_destroy(){
+       EntityClass_unrealise();
+
+       eclass_bad->free( eclass_bad );
+}
+
+#include "modulesystem/modulesmap.h"
+
+class EntityClassQuake3Dependencies :
+       public GlobalRadiantModuleRef,
+       public GlobalFileSystemModuleRef,
+       public GlobalShaderCacheModuleRef
+{
+EClassModulesRef m_eclass_modules;
+public:
+EntityClassQuake3Dependencies() :
+       m_eclass_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclasstype" ) ){
+}
+EClassModules& getEClassModules(){
+       return m_eclass_modules.get();
+}
+};
+
+class EclassManagerAPI
+{
+EntityClassManager m_eclassmanager;
+public:
+typedef EntityClassManager Type;
+STRING_CONSTANT( Name, "quake3" );
+
+EclassManagerAPI(){
+       EntityClassQuake3_construct();
+
+       m_eclassmanager.findOrInsert = &Eclass_ForName;
+       m_eclassmanager.findListType = &EntityClass_findListType;
+       m_eclassmanager.forEach = &Eclass_forEach;
+       m_eclassmanager.attach = &EntityClass_attach;
+       m_eclassmanager.detach = &EntityClass_detach;
+       m_eclassmanager.realise = &EntityClass_realise;
+       m_eclassmanager.unrealise = &EntityClass_unrealise;
+
+       Radiant_attachGameToolsPathObserver( g_EntityClassQuake3 );
+       Radiant_attachGameModeObserver( g_EntityClassQuake3 );
+       Radiant_attachGameNameObserver( g_EntityClassQuake3 );
+}
+~EclassManagerAPI(){
+       Radiant_detachGameNameObserver( g_EntityClassQuake3 );
+       Radiant_detachGameModeObserver( g_EntityClassQuake3 );
+       Radiant_detachGameToolsPathObserver( g_EntityClassQuake3 );
+
+       EntityClassQuake3_destroy();
+}
+EntityClassManager* getTable(){
+       return &m_eclassmanager;
+}
+};
+
+#include "modulesystem/singletonmodule.h"
+#include "modulesystem/moduleregistry.h"
+
+typedef SingletonModule<EclassManagerAPI, EntityClassQuake3Dependencies> EclassManagerModule;
+typedef Static<EclassManagerModule> StaticEclassManagerModule;
+StaticRegisterModule staticRegisterEclassManager( StaticEclassManagerModule::instance() );
+
+EClassModules& EntityClassManager_getEClassModules(){
+       return StaticEclassManagerModule::instance().getDependencies().getEClassModules();
+}