Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        // only find local links
        void EntityLinkDecorator::gatherLinksLocal(Vec4f::List& vList, RenderContext& context, Model::Entity& curEnt) {
            if (!context.filter().entityVisible(curEnt))
                return;

            Model::EntityList::const_iterator it, end;
            const Model::EntityList& targetList = curEnt.linkTargets();

            for (it = targetList.begin(), end = targetList.end(); it != end; ++it) {
                const Model::Entity& targetEnt = **it;

                if (!context.filter().entityVisible(targetEnt))
                    continue;

                addArrowVerts(vList, curEnt.center(), targetEnt.center());
            }

            const Model::EntityList& sourceList = curEnt.linkSources();

            for (it = sourceList.begin(), end = sourceList.end(); it != end; ++it) {
                const Model::Entity& sourceEnt = **it;

                if (!context.filter().entityVisible(sourceEnt))
                    continue;

                addArrowVerts(vList, sourceEnt.center(), curEnt.center());
            }
        }
 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;
 }
Esempio n. 4
0
 Model::Node* NodeReader::onWorldspawn(const Model::EntityAttribute::List& attributes, const ExtraAttributes& extraAttributes) {
     Model::Entity* worldspawn = m_factory->createEntity();
     worldspawn->setAttributes(attributes);
     setExtraAttributes(worldspawn, extraAttributes);
     
     m_nodes.insert(m_nodes.begin(), worldspawn);
     return worldspawn;
 }
Esempio n. 5
0
 size_t MapWriter::writeEntity(Model::Entity& entity, const size_t lineNumber, FILE* stream) {
     size_t lineCount = writeEntityHeader(entity, stream);
     const Model::BrushList& brushes = entity.brushes();
     for (unsigned int i = 0; i < brushes.size(); i++)
         lineCount += writeBrush(*brushes[i], lineNumber + lineCount, stream);
     lineCount += writeEntityFooter(stream);
     entity.setFilePosition(lineNumber, lineCount);
     return lineCount;
 }
Esempio n. 6
0
        void MapReader::createEntity(const size_t line, const Model::EntityAttribute::List& attributes, const ExtraAttributes& extraAttributes) {
            Model::Entity* entity = m_factory->createEntity();
            entity->setAttributes(attributes);
            setExtraAttributes(entity, extraAttributes);

            const ParentInfo::Type parentType = storeNode(entity, attributes);
            stripParentAttributes(entity, parentType);
            
            m_currentNode = entity;
            m_brushParent = entity;
        }
Esempio n. 7
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]);
            }
        }
Esempio n. 8
0
 Model::Entity* MapParser::parseEntity(const BBox& worldBounds, Utility::ProgressIndicator* indicator) {
     Token token = m_tokenizer.nextToken();
     if (token.type() == TokenType::Eof)
         return NULL;
     
     expect(TokenType::OBrace | TokenType::CBrace, token);
     if (token.type() == TokenType::CBrace)
         return NULL;
     
     Model::Entity* entity = new Model::Entity(worldBounds);
     size_t firstLine = token.line();
     
     while ((token = m_tokenizer.nextToken()).type() != TokenType::Eof) {
         switch (token.type()) {
             case TokenType::String: {
                 String key = token.data();
                 expect(TokenType::String, token = m_tokenizer.nextToken());
                 String value = token.data();
                 entity->setProperty(key, value);
                 break;
             }
             case TokenType::OBrace: {
                 m_tokenizer.pushToken(token);
                 bool moreBrushes = true;
                 while (moreBrushes) {
                     Model::Brush* brush = parseBrush(worldBounds, indicator);
                     if (brush != NULL)
                         entity->addBrush(*brush);
                     expect(TokenType::OBrace | TokenType::CBrace, token = m_tokenizer.nextToken());
                     moreBrushes = (token.type() == TokenType::OBrace);
                     m_tokenizer.pushToken(token);
                 }
                 break;
             }
             case TokenType::CBrace: {
                 if (indicator != NULL)
                     indicator->update(static_cast<int>(token.position()));
                 entity->setFilePosition(firstLine, token.line() - firstLine);
                 return entity;
             }
             default:
                 delete entity;
                 throw MapParserException(token, TokenType::String | TokenType::OBrace | TokenType::CBrace);
         }
     }
     
     return entity;
 }
Esempio n. 9
0
 void MapWriter::writeEntity(const Model::Entity& entity, std::ostream& stream) {
     writeEntityHeader(entity, stream);
     const Model::BrushList& brushes = entity.brushes();
     for (unsigned int i = 0; i < brushes.size(); i++)
         writeBrush(*brushes[i], stream);
     writeEntityFooter(stream);
 }
Esempio n. 10
0
        void EntityRenderer::validateModels(RenderContext& context) {
            m_modelRenderers.clear();

            EntityModelRendererManager& modelRendererManager = m_document.sharedResources().modelRendererManager();
            Model::EntitySet::iterator entityIt, entityEnd;
            for (entityIt = m_entities.begin(), entityEnd = m_entities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity* entity = *entityIt;
                const String* classname = entity->classname();
                if (classname != NULL) {
                    EntityModelRenderer* renderer = modelRendererManager.modelRenderer(*entity, m_document.searchPaths());
                    if (renderer != NULL)
                        m_modelRenderers[entity] = CachedEntityModelRenderer(renderer, *classname);
                }
            }

            m_modelRendererCacheValid = true;
        }
Esempio n. 11
0
 void MapWriter::writeEntityHeader(const Model::Entity& entity, std::ostream& stream) {
     stream << "{\n";
     
     const Model::PropertyList& properties = entity.properties();
     Model::PropertyList::const_iterator it, end;
     for (it = properties.begin(), end = properties.end(); it != end; ++it) {
         const Model::Property& property = *it;
         stream << "\"" << property.key() << "\" \"" << property.value() << "\"" << "\n";
     }
 }
Esempio n. 12
0
 size_t MapWriter::writeEntityHeader(Model::Entity& entity, FILE* stream) {
     size_t lineCount = 0;
     std::fprintf(stream, "{\n"); lineCount++;
     
     const Model::PropertyList& properties = entity.properties();
     Model::PropertyList::const_iterator it, end;
     for (it = properties.begin(), end = properties.end(); it != end; ++it) {
         const Model::Property& property = *it;
         std::fprintf(stream, "\"%s\" \"%s\"\n", property.key().c_str(), property.value().c_str()); lineCount++;
     }
     return lineCount;
 }
Esempio n. 13
0
        // find links in a "context"
        void EntityLinkDecorator::gatherLinks(Vec4f::List& vListLocal, Vec4f::List& vListContext, RenderContext& context, Model::Entity& curEnt, Model::EntitySet& visitedEntities) {
            Model::EntitySet::iterator vIt = visitedEntities.lower_bound(&curEnt);

            if (*vIt == &curEnt)
                return;

            visitedEntities.insert(vIt, &curEnt);

            if (!context.filter().entityVisible(curEnt))
                return;

            Model::EntityList::const_iterator it, end;
            const Model::EntityList& targetList = curEnt.linkTargets();

            for (it = targetList.begin(), end = targetList.end(); it != end; ++it) {
                Model::Entity& targetEnt = **it;

                if (!context.filter().entityVisible(targetEnt))
                    continue;

                if (curEnt.selected() || targetEnt.selected())
                    addArrowVerts(vListLocal, curEnt.center(), targetEnt.center());
                else
                    addArrowVerts(vListContext, curEnt.center(), targetEnt.center());

                gatherLinks(vListLocal, vListContext, context, targetEnt, visitedEntities);
            }

            const Model::EntityList& sourceList = curEnt.linkSources();

            for (it = sourceList.begin(), end = sourceList.end(); it != end; ++it) {
                Model::Entity& sourceEnt = **it;

                if (!context.filter().entityVisible(sourceEnt))
                    continue;

                gatherLinks(vListLocal, vListContext, context, sourceEnt, visitedEntities);
            }
        }
Esempio n. 14
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;
        }
Esempio n. 15
0
        void EntityRenderer::addEntity(Model::Entity& entity) {
            if (!m_entities.insert(&entity).second)
                return;

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

            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(&entity);
            m_boundsValid = false;
        }
 void EntitySnapshot::restore(Model::Entity& entity) {
     entity.setProperties(m_properties, true);
 }
Esempio n. 17
0
 void EntityModelRenderer::render(ShaderProgram& shaderProgram, Transformation& transformation, const Model::Entity& entity) {
     render(shaderProgram, transformation, entity.origin(), entity.rotation());
 }
 EntitySnapshot::EntitySnapshot(const Model::Entity& entity) {
     m_uniqueId = entity.uniqueId();
     m_properties = entity.properties();
 }