Ejemplo n.º 1
0
 void EntityDefinitionManager::load(const String& path) {
     Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences();
     const Color& defaultColor = prefs.getColor(Preferences::EntityBoundsColor);
     EntityDefinitionMap newDefinitions;
     
     IO::FileManager fileManager;
     IO::MappedFile::Ptr file = fileManager.mapFile(path);
     if (file.get() != NULL) {
         try {
             const String extension = fileManager.pathExtension(path);
             if (Utility::equalsString(extension, "def", false)) {
                 IO::DefParser parser(file->begin(), file->end(), defaultColor);
                 
                 EntityDefinition* definition = NULL;
                 while ((definition = parser.nextDefinition()) != NULL)
                     Utility::insertOrReplace(newDefinitions, definition->name(), definition);
             } else if (Utility::equalsString(extension, "fgd", false)) {
                 IO::FgdParser parser(file->begin(), file->end(), defaultColor);
                 
                 EntityDefinition* definition = NULL;
                 while ((definition = parser.nextDefinition()) != NULL)
                     Utility::insertOrReplace(newDefinitions, definition->name(), definition);
             }
             
             clear();
             m_entityDefinitions = newDefinitions;
             m_path = path;
         } catch (IO::ParserException e) {
             Utility::deleteAll(newDefinitions);
             m_console.error(e.what());
         }
     } else {
         m_console.error("Unable to open entity definition file %s", path.c_str());
     }
 }
        EntityModelRenderer* EntityModelRendererManager::modelRenderer(const Model::ModelDefinition& modelDefinition, const StringList& searchPaths) {
            assert(m_palette != NULL);
            IO::FileManager fileManager;
            
            if (!m_valid) {
                clear();
                m_valid = true;
            }
            
            const String key = modelRendererKey(modelDefinition, searchPaths);
            MismatchCache::iterator mismatchIt = m_mismatches.find(key);
            if (mismatchIt != m_mismatches.end())
                return NULL;
            
            EntityModelRendererCache::iterator rendererIt = m_modelRenderers.find(key);
            if (rendererIt != m_modelRenderers.end())
                return rendererIt->second;

            String modelName = Utility::toLower(modelDefinition.name().substr(1));
            String ext = Utility::toLower(fileManager.pathExtension(modelName));
            if (ext == "mdl") {
                unsigned int skinIndex = modelDefinition.skinIndex();
                unsigned int frameIndex = modelDefinition.frameIndex();

                Model::AliasManager& aliasManager = *Model::AliasManager::sharedManager;
                const Model::Alias* alias = aliasManager.alias(modelName, searchPaths, m_console);

                if (alias != NULL && skinIndex < alias->skins().size() && frameIndex < alias->frames().size()) {
                    Renderer::EntityModelRenderer* renderer = new AliasModelRenderer(*alias, frameIndex, skinIndex, *m_vbo, *m_palette);
                    m_modelRenderers[key] = renderer;
                    return renderer;
                }
            } else if (ext == "bsp") {
                Model::BspManager& bspManager = *Model::BspManager::sharedManager;
                const Model::Bsp* bsp = bspManager.bsp(modelName, searchPaths, m_console);
                if (bsp != NULL) {
                    Renderer::EntityModelRenderer* renderer = new BspModelRenderer(*bsp, *m_vbo, *m_palette);
                    m_modelRenderers[key] = renderer;
                    return renderer;
                }
            } else {
                m_console.warn("Unknown model type '%s'", ext.c_str());
            }

            m_mismatches.insert(key);
            return NULL;
        }