//------------------------------------------------------------------------ void CGameRulesHoldObjectiveBase::RadiusEffectPulse(EntityId entityId, eRadiusPulseType pulseType, float fScale) { IEntity* pEntity = gEnv->pEntitySystem->GetEntity(entityId); Vec3 entityPos(0.0f,0.0f,0.0f); if(pEntity) { entityPos = pEntity->GetPos(); entityPos.z += 0.5f; } if (m_effectData.pParticleEffect) { float particleEffectScale = fScale*m_effectData.particleEffectScale; IParticleEmitter* pEmitter = m_effectData.pParticleEffect->Spawn(false, IParticleEffect::ParticleLoc(entityPos, Vec3(0.f, 0.f, 1.f), particleEffectScale)); if(pEmitter) { SpawnParams spawnParams; pEmitter->GetSpawnParams(spawnParams); spawnParams.fStrength = m_effectData.particleColorLerp.GetValue(); pEmitter->SetSpawnParams(spawnParams); } } #ifndef _RELEASE if(g_pGameCVars->g_holdObjectiveDebug == eHOB_Debug_Fade_Ring_With_Pulse) { m_effectData.alphaLerp.Set(0.0f,0.0f,1.0f); } #endif // Start ring geom fade-in if(m_effectData.alphaLerp.GetValue() == 0.0f) { m_effectData.alphaLerp.Set(0.0f,1.0f,0.0f); m_effectData.alphaFadeInDelay = m_effectData.alphaFadeInDelayDuration; IEntity *pRingEntity = gEnv->pEntitySystem->GetEntity(m_effectData.ringEntityID); if(pRingEntity) { float ringGeomScale = fScale * m_effectData.ringGeomScale; pRingEntity->SetPos(entityPos); pRingEntity->SetScale(Vec3(ringGeomScale,ringGeomScale,1.0f)); #ifndef _RELEASE if(g_pGameCVars->g_holdObjectiveDebug == eHOB_Debug_Fade_Ring_With_Pulse) { pRingEntity->Hide(true); SetRingAlpha(pRingEntity,0.0f); } #endif } } }
bool LevelLoader::LoadLevel(std::string filename) { string filePath("resource/data/levels/"); filePath += filename + ".xml"; xml_document doc; if(!LoadXMLFile(doc,filePath)) return false; bool anythingLoaded = false; for(xml_node entityNode = doc.child("entity"); entityNode; entityNode = entityNode.next_sibling("entity")) { Entity* entity = nullptr; // Get the number of components unsigned int componentCount = std::distance(entityNode.children("component").begin(), entityNode.children("component").end()); // Throws on bad allocation and if we pass something wrong to it try { entity = new Entity(m_nextEntityID++,entityNode.attribute("name").as_string(), componentCount); } catch(std::invalid_argument& ia) { LOG("A new entity could not be allocated. invalid_argument caught: " << ia.what()); continue; } catch(std::bad_alloc& ba) { LOG("A new entity could not be allocated. bad_alloc caught: " << ba.what()); continue; } entity->IsActive(entityNode.attribute("active").as_bool()); entity->SetHP(entityNode.attribute("hp").as_int()); entity->SetLayer(entityNode.attribute("layer").as_int()); vec3<float> entityPos(entityNode.attribute("posX").as_float(), entityNode.attribute("posY").as_float(), 0.0f); vec3<float> entityVel(entityNode.attribute("velX").as_float(), entityNode.attribute("velY").as_float(), 0.0f); entity->SetPosition(entityPos); entity->SetVelocity(entityVel); for(xml_node componentNode = entityNode.child("component"); componentNode; componentNode = componentNode.next_sibling("component")) { ComponentAttribute compAt; std::string componentName = componentNode.attribute("type").as_string(); if(componentName == "") { LOG("Tried to load invalid component type on Entity: " << entityNode.attribute("name").as_string() << " Invalid Component Type: " << componentNode.attribute("type").as_string()); continue; } // Grab all attributes for this component and give to the component factory to construct // Iteration is starting at second attribute since first is type and we already have that xml_attribute attributeNode = componentNode.first_attribute(); attributeNode = attributeNode.next_attribute(); std::vector<xml_attribute> compAttributes; for(; attributeNode; attributeNode = attributeNode.next_attribute()) { compAttributes.push_back(attributeNode); } ComponentFactory::GetInstance().AddComponentToEntity(entity, componentName, &compAttributes); } entity->RegisterForMessages(); m_worldMan->AddEntity(entity); anythingLoaded = true; } if(!anythingLoaded) { LOG("No valid entities to load in : " << filePath); return false; } return true; }
void ScreenWidget::loadPressed() { QString fileName = QFileDialog::getOpenFileName(this, tr("Load Scene"), "",tr("DSS XML Scene File (*.xml);;All Files (*)")); if (fileName.isEmpty()) { return; } else { QDomDocument doc("loadedscene"); QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } if (!doc.setContent(&file)) { file.close(); return; } file.close(); QDomElement scene = doc.documentElement(); qDebug()<<scene.text(); QDomNode field=scene.firstChildElement("field"); if (field.isElement()) { this->scene->addField(field.firstChildElement("width").text().toUInt(),field.firstChildElement("height").text().toUInt()); } QDomNode targetEntity = scene.firstChildElement("targetEntity"); if (targetEntity.isElement()) { TargetEntity* newTargetEntity = new TargetEntity(); Point2i targetPos(targetEntity.firstChildElement("x").text().toInt(),targetEntity.firstChildElement("y").text().toInt()); this->scene->setTargetEntity(newTargetEntity,targetPos); } QDomNode entities = scene.firstChildElement("entities"); if (entities.isElement()) { QDomNodeList entityList =entities.toElement().elementsByTagName("entity"); for(int i=0;i<entityList.count();i++) { QDomElement entity = entityList.at(i).toElement(); int type = entity.firstChildElement("type").text().toInt(); Point2i entityPos(entity.firstChildElement("x").text().toInt(),entity.firstChildElement("y").text().toInt()); this->scene->addEntityAtPosition(type,entityPos); } } /* for(int i=0;i<fieldList.count();i++) { QDomElement field = fieldList.at(i).toElement(); qDebug()<<field.attribute("width"); qDebug()<<field.attribute("height"); QDomNodeList lll=e1.elementsByTagName("a"); qDebug(QString::number(lll.count()).toAscii()); for(int j=0;j<lll.count();j++) { QDomElement e2 = lll.at(j).toElement(); qDebug(e2.tagName().toAscii()+" "+e2.attribute("ITEM").toAscii()); QDomNodeList llll=e2.elementsByTagName("b"); for(int k=0;k<llll.count();k++) { QDomElement e3 = llll.at(k).toElement(); qDebug(e3.tagName().toAscii()+" "+e3.text().toAscii()); } } } */ } }