From d498eb592d9fc89f93f3fc7ba03cfc56963b5f91 Mon Sep 17 00:00:00 2001 From: spog Date: Sat, 22 Jul 2006 16:30:32 +0000 Subject: [PATCH] added support for both ent and def files at the same time git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@95 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- CHANGES | 1 + include/ieclass.h | 16 ++++---- include/modulesystem.h | 8 ++-- libs/modulesystem/modulesmap.h | 4 +- radiant/eclass.cpp | 72 +++++++++++++++++++++------------- radiant/image.cpp | 6 +-- radiant/pluginmanager.cpp | 2 +- radiant/plugintoolbar.cpp | 2 +- radiant/server.cpp | 2 +- radiant/texwindow.cpp | 7 +--- 10 files changed, 67 insertions(+), 53 deletions(-) diff --git a/CHANGES b/CHANGES index 71adb846..9917b215 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ SPoG - Fixed title of wait-dialog when loading a model. - Fixed doom3 func_static with blank 'model' key being invisible. - Changed doom3 func_static model creation to replace selected models. +- Added support for loading both .ent and .def files at the same time. 09/07/2006 Shaderman diff --git a/include/ieclass.h b/include/ieclass.h index 21081094..89b86ca9 100644 --- a/include/ieclass.h +++ b/include/ieclass.h @@ -63,17 +63,17 @@ struct EntityClassScanner #include "modulesystem.h" template -class GlobalModule; -typedef GlobalModule GlobalEClassModule; +class ModuleRef; +typedef ModuleRef EClassModuleRef; template -class GlobalModuleRef; -typedef GlobalModuleRef GlobalEClassModuleRef; +class Modules; +typedef Modules EClassModules; + +template +class ModulesRef; +typedef ModulesRef EClassModulesRef; -inline EntityClassScanner& GlobalEClassLoader() -{ - return GlobalEClassModule::getTable(); -} diff --git a/include/modulesystem.h b/include/modulesystem.h index 4c5495d2..dd7c59ad 100644 --- a/include/modulesystem.h +++ b/include/modulesystem.h @@ -54,7 +54,7 @@ public: class Visitor { public: - virtual void visit(const char* name, Module& module) = 0; + virtual void visit(const char* name, Module& module) const = 0; }; virtual void setError(bool error) = 0; @@ -66,7 +66,7 @@ public: virtual void registerModule(const char* type, int version, const char* name, Module& module) = 0; virtual Module* findModule(const char* type, int version, const char* name) const = 0; - virtual void foreachModule(const char* type, int version, Visitor& visitor) = 0; + virtual void foreachModule(const char* type, int version, const Visitor& visitor) = 0; }; class ModuleServerHolder @@ -112,11 +112,11 @@ public: class Visitor { public: - virtual void visit(const char* name, const Type& table) = 0; + virtual void visit(const char* name, const Type& table) const = 0; }; virtual Type* findModule(const char* name) = 0; - virtual void foreachModule(Visitor& visitor) = 0; + virtual void foreachModule(const Visitor& visitor) = 0; }; #include "debugging/debugging.h" diff --git a/libs/modulesystem/modulesmap.h b/libs/modulesystem/modulesmap.h index 44b62bdb..dfc2ea45 100644 --- a/libs/modulesystem/modulesmap.h +++ b/libs/modulesystem/modulesmap.h @@ -80,7 +80,7 @@ public: { return find(name); } - void foreachModule(typename Modules::Visitor& visitor) + void foreachModule(const typename Modules::Visitor& visitor) { for(modules_t::iterator i = m_modules.begin(); i != m_modules.end(); ++i) { @@ -98,7 +98,7 @@ public: : m_modules(modules) { } - void visit(const char* name, Module& module) + void visit(const char* name, Module& module) const { m_modules.insert(name, module); } diff --git a/radiant/eclass.cpp b/radiant/eclass.cpp index 9a2a4388..edbf4156 100644 --- a/radiant/eclass.cpp +++ b/radiant/eclass.cpp @@ -50,6 +50,8 @@ namespace ListAttributeTypes g_listTypes; } +EClassModules& EntityClassManager_getEClassModules(); + /*! implementation of the EClass manager API */ @@ -144,9 +146,10 @@ public: class EntityClassesLoadFile { + const EntityClassScanner& scanner; const char* m_directory; public: - EntityClassesLoadFile(const char* directory) : m_directory(directory) + EntityClassesLoadFile(const EntityClassScanner& scanner, const char* directory) : scanner(scanner), m_directory(directory) { } void operator()(const char* name) const @@ -178,7 +181,7 @@ public: StringOutputStream relPath(256); relPath << m_directory << name; - GlobalEClassLoader().scanFile(g_collector, relPath.c_str()); + scanner.scanFile(g_collector, relPath.c_str()); } }; @@ -206,23 +209,16 @@ public: } }; -#if 0 -void EntityClassQuake3_constructDirectory(const char* directory, const char* extension) -{ - globalOutputStream() << "EntityClass: searching " << makeQuoted(directory) << " for *." << extension << '\n'; - Directory_forEach(directory, matchFileExtension(extension, EntityClassesLoadFile(directory))); -} -#else + 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))); } -#endif + void EntityClassQuake3_Construct() { -#if 1 StringOutputStream baseDirectory(256); StringOutputStream gameDirectory(256); const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue("basegame"); @@ -230,22 +226,32 @@ void EntityClassQuake3_Construct() baseDirectory << GlobalRadiant().getGameToolsPath() << basegame << '/'; gameDirectory << GlobalRadiant().getGameToolsPath() << gamename << '/'; - Paths paths; - EntityClassQuake3_constructDirectory(baseDirectory.c_str(), GlobalEClassLoader().getExtension(), paths); - if(!string_equal(basegame, gamename)) + class LoadEntityDefinitionsVisitor : public EClassModules::Visitor { - EntityClassQuake3_constructDirectory(gameDirectory.c_str(), GlobalEClassLoader().getExtension(), paths); - } + 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((*i).second)((*i).first.c_str()); - } -#else - StringOutputStream directory(256); - directory << GlobalRadiant().getGameToolsPath() << GlobalRadiant().getGameName() << '/'; - EntityClassQuake3_constructDirectory(directory.c_str(), GlobalEClassLoader().getExtension()); -#endif + 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) @@ -338,16 +344,22 @@ void EntityClassQuake3_destroy() eclass_bad->free(eclass_bad); } +#include "modulesystem/modulesmap.h" + class EntityClassQuake3Dependencies : public GlobalRadiantModuleRef, public GlobalFileSystemModuleRef, - public GlobalShaderCacheModuleRef, - public GlobalEClassModuleRef + public GlobalShaderCacheModuleRef { + EClassModulesRef m_eclass_modules; public: EntityClassQuake3Dependencies() : - GlobalEClassModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclasstype")) + m_eclass_modules(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclasstype")) + { + } + EClassModules& getEClassModules() { + return m_eclass_modules.get(); } }; @@ -395,4 +407,8 @@ typedef SingletonModule EclassM typedef Static StaticEclassManagerModule; StaticRegisterModule staticRegisterEclassManager(StaticEclassManagerModule::instance()); +EClassModules& EntityClassManager_getEClassModules() +{ + return StaticEclassManagerModule::instance().getDependencies().getEClassModules(); +} diff --git a/radiant/image.cpp b/radiant/image.cpp index 7375efbc..7495db68 100644 --- a/radiant/image.cpp +++ b/radiant/image.cpp @@ -47,7 +47,7 @@ Image* QERApp_LoadImage(void* environment, const char* name) : m_name(name), m_image(image) { } - void visit(const char* name, const _QERPlugImageTable& table) + void visit(const char* name, const _QERPlugImageTable& table) const { if(m_image == 0) { @@ -61,9 +61,9 @@ Image* QERApp_LoadImage(void* environment, const char* name) } } } - } visitor(name, image); + }; - Textures_getImageModules().foreachModule(visitor); + Textures_getImageModules().foreachModule(LoadImageVisitor(name, image)); return image; } diff --git a/radiant/pluginmanager.cpp b/radiant/pluginmanager.cpp index d9ed04ab..35933014 100644 --- a/radiant/pluginmanager.cpp +++ b/radiant/pluginmanager.cpp @@ -214,7 +214,7 @@ void FillPluginSlots(CPluginSlots& slots, GtkWidget* main_window) : m_slots(slots), m_main_window(main_window) { } - void visit(const char* name, const _QERPluginTable& table) + void visit(const char* name, const _QERPluginTable& table) const { m_slots.AddPluginSlot(m_main_window, name, table); } diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index d471565a..4612fbd4 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -113,7 +113,7 @@ void PluginToolbar_populate() : m_toolbar(toolbar) { } - void visit(const char* name, const _QERPlugToolbarTable& table) + void visit(const char* name, const _QERPlugToolbarTable& table) const { const std::size_t count = table.m_pfnToolbarButtonCount(); for(std::size_t i=0;i