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; }
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); } } }
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; }