예제 #1
0
        void EntityRenderer::validateBounds(RenderContext& context) {
            delete m_boundsVertexArray;
            m_boundsVertexArray = NULL;

            Model::EntityList entities;
            Model::EntitySet::iterator entityIt, entityEnd;
            for (entityIt = m_entities.begin(), entityEnd = m_entities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity* entity = *entityIt;
                if (context.filter().entityVisible(*entity))
                    entities.push_back(entity);
            }

            if (entities.empty())
                return;

            SetVboState mapVbo(m_boundsVbo, Vbo::VboMapped);

            if (m_overrideBoundsColor) {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f());
                writeBounds(context, entities);
            } else {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f(),
                                                      Attribute::color4f());
                writeColoredBounds(context, entities);
            }

            m_boundsValid = true;
        }
예제 #2
0
        void EntityRenderer::writeColoredBounds(RenderContext& context, const Model::EntityList& entities) {
            if (entities.empty())
                return;

            Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences();
            Vec3f::List vertices(24);

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const BBoxf& bounds = entity->bounds();
                const Model::EntityDefinition* definition = entity->definition();
                Color entityColor;
                if (definition != NULL) {
                    entityColor = definition->color();
                    entityColor[3] = prefs.getColor(Preferences::EntityBoundsColor).a();
                } else {
                    entityColor = prefs.getColor(Preferences::EntityBoundsColor);
                }

                bounds.vertices(vertices);
                for (unsigned int j = 0; j < vertices.size(); j++) {
                    m_boundsVertexArray->addAttribute(vertices[j]);
                    m_boundsVertexArray->addAttribute(entityColor);
                }
            }
        }
예제 #3
0
        void EntityRenderer::removeEntities(const Model::EntityList& entities) {
            if (entities.empty())
                return;

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                m_modelRenderers.erase(entity);
                m_classnameRenderer->removeString(entity);
                m_entities.erase(entity);
            }
            m_boundsValid = false;
        }
예제 #4
0
 bool MapParser::parseEntities(const BBox& worldBounds, Model::EntityList& entities) {
     size_t oldSize = entities.size();
     try {
         Model::Entity* entity = NULL;
         while ((entity = parseEntity(worldBounds, NULL)) != NULL)
             entities.push_back(entity);
         return !entities.empty();
     } catch (MapParserException e) {
         Utility::deleteAll(entities, oldSize);
         m_tokenizer.reset();
         return false;
     }
 }
예제 #5
0
        void MapWriter::writeObjectsToStream(const Model::EntityList& pointEntities, const Model::BrushList& brushes, std::ostream& stream) {
            assert(stream.good());
            stream.unsetf(std::ios::floatfield);

            Model::Entity* worldspawn = NULL;
            
            // group the brushes by their containing entities
            typedef std::map<Model::Entity*, Model::BrushList> EntityBrushMap;
            EntityBrushMap entityToBrushes;
            
            Model::BrushList::const_iterator brushIt, brushEnd;
            for (brushIt = brushes.begin(), brushEnd = brushes.end(); brushIt != brushEnd; ++brushIt) {
                Model::Brush& brush = **brushIt;
                Model::Entity& entity = *brush.entity();
                entityToBrushes[&entity].push_back(&brush);
                if (entity.worldspawn())
                    worldspawn = &entity;
            }
            
            // write worldspawn first
            if (worldspawn != NULL) {
                Model::BrushList& brushList = entityToBrushes[worldspawn];
                writeEntityHeader(*worldspawn, stream);
                for (brushIt = brushList.begin(), brushEnd = brushList.end(); brushIt != brushEnd; ++brushIt) {
                    writeBrush(**brushIt, stream);
                }
                writeEntityFooter(stream);
            }
            
            // now write the point entities
            Model::EntityList::const_iterator entityIt, entityEnd;
            for (entityIt = pointEntities.begin(), entityEnd = pointEntities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity& entity = **entityIt;
                writeEntity(entity, stream);
            }

            // finally write the brush entities
            EntityBrushMap::iterator it, end;
            for (it = entityToBrushes.begin(), end = entityToBrushes.end(); it != end; ++it) {
                Model::Entity* entity = it->first;
                if (entity != worldspawn) {
                    Model::BrushList& brushList = it->second;
                    writeEntityHeader(*entity, stream);
                    for (brushIt = brushList.begin(), brushEnd = brushList.end(); brushIt != brushEnd; ++brushIt) {
                        writeBrush(**brushIt, stream);
                    }
                    writeEntityFooter(stream);
                }
            }
        }
예제 #6
0
        void EntityRenderer::writeBounds(RenderContext& context, const Model::EntityList& entities) {
            if (entities.empty())
                return;

            Vec3f::List vertices(24);
            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const BBoxf& bounds = entity->bounds();
                bounds.vertices(vertices);

                for (unsigned int j = 0; j < vertices.size(); j++)
                    m_boundsVertexArray->addAttribute(vertices[j]);
            }
        }
 void SnapshotCommand::restoreSnapshots(const Model::EntityList& entities) {
     assert(m_entities.size() == entities.size());
     
     if (entities.empty())
         return;
     
     Model::EntityDefinitionManager& definitionManager = document().definitionManager();
     
     for (unsigned int i = 0; i < entities.size(); i++) {
         Model::Entity& entity = *entities[i];
         EntitySnapshot& snapshot = *m_entities[entity.uniqueId()];
         snapshot.restore(entity);
         
         const Model::PropertyValue* classname = entity.classname();
         if (classname != NULL)
             entity.setDefinition(definitionManager.definition(*classname));
     }
 }
 bool ReparentBrushesCommand::performUndo() {
     Model::EntityList entities;
     if (!m_newParent.worldspawn())
         entities.push_back(&m_newParent);
     
     Model::BrushList::const_iterator it, end;
     for (it = m_brushes.begin(), end = m_brushes.end(); it != end; ++it) {
         Model::Brush* brush = *it;
         Model::Entity* oldParent = m_oldParents[brush];
         if (oldParent != NULL &&
             !oldParent->worldspawn() &&
             std::find(entities.begin(), entities.end(), oldParent) == entities.end())
             entities.push_back(oldParent);
     }
     
     document().entitiesWillChange(entities);
     for (it = m_brushes.begin(), end = m_brushes.end(); it != end; ++it) {
         Model::Brush& brush = **it;
         Model::Entity* oldParent = m_oldParents[&brush];
         m_newParent.removeBrush(brush);
         if (oldParent != NULL)
             oldParent->addBrush(brush);
     }
     document().entitiesDidChange(entities);
     
     return true;
 }
예제 #9
0
        void EntityRenderer::addEntities(const Model::EntityList& entities) {
            if (entities.empty())
                return;

            EntityModelRendererManager& modelRendererManager = m_document.sharedResources().modelRendererManager();

            for (unsigned int i = 0; i < entities.size(); i++) {
                Model::Entity* entity = entities[i];
                const String* classname = entity->classname();
                if (classname == NULL)
                    classname = &Model::Entity::NoClassnameValue;
                if (classname != NULL) {
                    EntityModelRenderer* renderer = modelRendererManager.modelRenderer(*entity, m_document.searchPaths());
                    if (renderer != NULL)
                        m_modelRenderers[entity] = CachedEntityModelRenderer(renderer, *classname);

                    m_classnameRenderer->addString(entity, *classname, Text::TextAnchor::Ptr(new EntityClassnameAnchor(*entity, renderer)));
                }
            }

            m_entities.insert(entities.begin(), entities.end());
            m_boundsValid = false;
        }
 ChangeEditStateCommand* ChangeEditStateCommand::select(Model::MapDocument& document, Model::Entity& entity) {
     Model::EntityList entities;
     entities.push_back(&entity);
     return select(document, entities);
 }
 MoveObjectsCommand* MoveObjectsCommand::moveEntity(Model::MapDocument& document, Model::Entity& entity, const Vec3f& delta, bool lockTextures) {
     Model::EntityList entities;
     entities.push_back(&entity);
     return moveObjects(document, entities, Model::EmptyBrushList, delta, lockTextures);
 }
 void SnapshotCommand::makeSnapshots(const Model::EntityList& entities) {
     for (unsigned int i = 0; i < entities.size(); i++) {
         Model::Entity& entity = *entities[i];
         m_entities[entity.uniqueId()] = new EntitySnapshot(entity);
     }
 }