void XmlPropertyReader::parseGameObjectFile(Ogre::DataStreamPtr &stream, const Ogre::String &groupName) { initializeXml(); XERCES_CPP_NAMESPACE::DOMDocument* doc = loadDocument(stream); DOMNodeList* godefsXml = doc->getDocumentElement()->getElementsByTagName(AutoXMLCh("gameobjectclass").data()); for (unsigned int idx = 0; idx < godefsXml->getLength(); idx++) { PropertyRecordPtr ps(new PropertyRecord()); DOMElement* curNode = static_cast<DOMElement*>(godefsXml->item(idx)); const DOMNamedNodeMap* godefAttrs = curNode->getAttributes(); for (XMLSize_t attrIdx = 0; attrIdx < godefAttrs->getLength(); attrIdx++) { PropertyEntry entry = processProperty(static_cast<DOMAttr*>(godefAttrs->item(attrIdx))); if (entry.first != "") { ps->setProperty(entry.first, entry.second); } } DOMNodeList* godefChildren = curNode->getChildNodes(); for (XMLSize_t childIdx = 0; childIdx < godefChildren->getLength(); childIdx++) { DOMNode* curChild = godefChildren->item(childIdx); if (curChild->getNodeType() == DOMNode::ELEMENT_NODE) { PropertyEntry entry = processProperty(static_cast<DOMElement*>(curChild)); if (entry.first != "") { ps->setProperty(entry.first, entry.second); } } } mPropertyRecords.push_back(ps); } shutdownXml(); }
PropertyRecordPtr XmlPropertyReader::getPropertiesAsRecord(DOMElement *parent) { PropertyRecordPtr ps(new PropertyRecord()); DOMNodeList* propertyDefChildren = parent->getChildNodes(); for (XMLSize_t childIdx = 0; childIdx < propertyDefChildren->getLength(); childIdx++) { DOMNode* curChild = propertyDefChildren->item(childIdx); if (curChild->getNodeType() == DOMNode::ELEMENT_NODE) { PropertyEntry entry = processProperty(static_cast<DOMElement*>(curChild)); if (entry.first != "") { ps->setProperty(entry.first, entry.second); } } } return ps; }
bool AgentInitializer::parsePropertySpec( TiXmlElement * node ) { if ( node->ValueStr() == "Property" ) { const char * cName = node->Attribute( "name" ); if ( cName == 0x0 ) { logger << Logger::ERR_MSG << "AgentSet Property tag specified on line " << node->Row() << " without a \"name\" attribute."; return false; } ::std::string propName( cName ); return processProperty( propName, node ) != FAILURE; } else if ( VERBOSE ) { logger << Logger::WARN_MSG << "Unexpected tag when looking for a property of an AgentSet parameter set: " << node->ValueStr() << "\n"; TiXmlAttribute * attr; for ( attr = node->FirstAttribute(); attr; attr = attr->Next() ) { if ( setFromXMLAttribute( attr->Name(), attr->ValueStr() ) == FAILURE ) { return false; } } } // Unexpected tags are ignored return true; }
CIMInstance ObjectNormalizer::processInstance( const CIMInstance& cimInstance) const { // pre-checks if (!_enableNormalization || _cimClass.isUninitialized()) { // do nothing return cimInstance; } /* // ATTN: moving similar logic to the response handlers because this // type of error should be checked regardless with or without // normalization enabled. if (cimInstance.isUninitialized()) { throw CIMException(CIM_ERR_FAILED, "unintialized instance object."); } */ CIMInstance normalizedInstance(_cimClass.getClassName()); // proces object path normalizedInstance.setPath( processInstanceObjectPath(cimInstance.getPath())); // process instance qualifiers if (_includeQualifiers) { // propagate class qualifiers for (Uint32 i = 0, n = _cimClass.getQualifierCount(); i < n; i++) { CIMConstQualifier referenceQualifier = _cimClass.getQualifier(i); Uint32 pos = cimInstance.findQualifier(referenceQualifier.getName()); // update value if qualifier is present in the specified property if (pos != PEG_NOT_FOUND) { CIMConstQualifier cimQualifier = cimInstance.getQualifier(pos); CIMQualifier normalizedQualifier = _processQualifier( referenceQualifier, cimQualifier); normalizedInstance.addQualifier(normalizedQualifier); } else { normalizedInstance.addQualifier(referenceQualifier.clone()); } } } // check property names and types. any properties in the class but not // in the instance are implicitly dropped. for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++) { CIMConstProperty instProperty = cimInstance.getProperty(i); Uint32 pos = _cimClass.findProperty(instProperty.getName()); if (pos != PEG_NOT_FOUND) { CIMConstProperty cimProperty = _cimClass.getProperty(pos); CIMProperty normalizedProperty = processProperty( cimProperty, instProperty, _includeQualifiers, _includeClassOrigin, _context.get(), _nameSpace); normalizedInstance.addProperty(normalizedProperty); } } return normalizedInstance; }
bool ZoneProcessor::processNode(const TiXmlElement* zonesElem, const Ogre::String& resourceGroup, bool loadGameObjects) { if (zonesElem == NULL) { return false; // no zones } for (const TiXmlNode* cur = zonesElem->FirstChild(); cur != NULL; cur = cur->NextSibling()) { if (cur->Type() == TiXmlNode::ELEMENT && hasNodeName(cur, "zone")) { const TiXmlElement* curZoneElem = cur->ToElement(); if (hasAttribute(curZoneElem, "name")) { Ogre::String name = getAttributeValueAsStdString(curZoneElem, "name"); Zone* zone = NULL; if (name == "default") { zone = ZoneManager::getSingleton().getDefaultZone(); } else { // get the zone with that name or create one zone = ZoneManager::getSingleton().getZone(name); if (!zone) { zone = ZoneManager::getSingleton().createZone(name, false); } // multiple areas for (const TiXmlNode* curArea = cur->FirstChild(); curArea != NULL; curArea = curArea->NextSibling()) { if (curArea->Type() == TiXmlNode::ELEMENT && hasNodeName(curArea, "area")) { const TiXmlElement *curAreaElem = curArea->ToElement(); if (hasAttribute(curAreaElem, "type")) { // type Ogre::String type; type = getAttributeValueAsStdString(curAreaElem, "type"); // add or subtract? bool subtract = false; if (hasAttribute(curAreaElem, "subtract")) { subtract = getAttributeValueAsBool(curAreaElem, "subtract"); } // position Vector3 position = Vector3::ZERO; const TiXmlElement* positionElem = getChildNamed(curAreaElem, "position"); if (positionElem) { position = getValueAsVector3(positionElem); } //scale, rotation, offset Vector3 scale = Vector3::UNIT_SCALE; const TiXmlElement* scaleElem = getChildNamed(curAreaElem, "scale"); if (!scaleElem) { scaleElem = getChildNamed(curAreaElem, "size"); } if (scaleElem) { scale = getValueAsVector3(scaleElem); } Vector3 offset = Vector3::ZERO; const TiXmlElement* offsetElem = getChildNamed(curAreaElem, "offset"); if (offsetElem) { offset = getValueAsVector3(offsetElem); } Quaternion rotation = Quaternion::IDENTITY; const TiXmlElement* rotationElem = getChildNamed(curAreaElem, "rotation"); if (rotationElem) { rotation = getValueAsQuaternion(rotationElem); } //transition distance Real transitionDistance = 0; const TiXmlElement* transitionElem = getChildNamed(curAreaElem, "transition_distance"); if (transitionElem) { transitionDistance = getValueAsReal(transitionElem); } if (type == "mesh") { Ogre::String meshName; if (hasAttribute(curAreaElem, "meshfile")) { meshName = getAttributeValueAsStdString(curAreaElem, "meshfile"); if (subtract) { ZoneManager::getSingleton().subtractMeshAreaFromZone(name, meshName, GT_CONVEXHULL, position, scale, offset, rotation, transitionDistance, QUERYFLAG_PLAYER); } else { ZoneManager::getSingleton().addMeshAreaToZone(name, meshName, GT_CONVEXHULL, position, scale, offset, rotation, transitionDistance, QUERYFLAG_PLAYER); } } else { LOG_ERROR(Logger::SCRIPT, "an <area> element with type=\"mesh\" must have attribute 'meshfile'"); } } else { GeometryType geom = GT_NONE; if (type == "sphere") { geom = GT_SPHERE; } else if (type == "box") { geom = GT_BOX; } else if (type == "ellipsoid") { geom = GT_ELLIPSOID; } else if (type == "pyramid") { geom = GT_PYRAMID; } else if (type == "capsule") { geom = GT_CAPSULE; } else { LOG_ERROR(Logger::SCRIPT, "Unknown area type '" + type + "' !"); } if ( geom != GT_NONE) { Ogre::AxisAlignedBox aabb; aabb.setMinimum( - scale / 2.0f); aabb.setMaximum( + scale / 2.0f); if (subtract) ZoneManager::getSingleton().subtractAreaFromZone(name, aabb, geom, position, offset, rotation, transitionDistance, QUERYFLAG_PLAYER); else ZoneManager::getSingleton().addAreaToZone(name, aabb, geom, position, offset, rotation, transitionDistance, QUERYFLAG_PLAYER); } } } else { LOG_ERROR(Logger::SCRIPT, "<area> elemt must have attribute 'type'"); } } } } if (zone) { for (const TiXmlNode* cur = curZoneElem->FirstChild(); cur != NULL; cur = cur->NextSibling()) { if (cur->Type() == TiXmlNode::ELEMENT) { const TiXmlElement* curElem = cur->ToElement(); if (hasNodeName(curElem, "light")) { Ogre::String name = getAttributeValueAsStdString(curElem, "name"); zone->addLight(ActorManager::getSingleton().getActor(name)); } else if (hasNodeName(curElem, "sound")) { Ogre::String name = getAttributeValueAsStdString(curElem, "name"); zone->addSound(name); } else if (hasNodeName(curElem, "trigger")) { Ogre::String classname = getAttributeValueAsStdString(curElem, "classname"); Ogre::String name = getAttributeValueAsStdString(curElem, "name"); Trigger* trigger = ScriptSubsystem::getSingleton().getTriggerFactory() ->createTrigger(classname, name); // add trigger properties for (const TiXmlNode* curProperty = cur->FirstChild(); curProperty != NULL; curProperty = curProperty->NextSibling()) { if (hasNodeName(curProperty, "property")) { PropertyEntry propEntry = processProperty(curProperty->ToElement()); if (propEntry.first != "") { trigger->setProperty(propEntry.first, propEntry.second); } } } zone->addTrigger(trigger); } else if (hasNodeName(curElem, "eaxpreset")) { Ogre::String name = getAttributeValueAsStdString(curElem, "name"); zone->setEaxPreset(name); } } } } else { LOG_ERROR(Logger::SCRIPT, "Zone named '"+name+"' could not be processes."); } } else { LOG_ERROR(Logger::SCRIPT, "<zone> element must have attribute 'name'."); } } } ZoneManager::getSingleton().update(); return true; }
PropertyEntry XmlPropertyReader::processProperty(XERCES_CPP_NAMESPACE::DOMElement* domElem) const { if (!hasAttribute(domElem, "type")) { return std::make_pair("", Property(0)); } Ogre::String key = ""; if (hasAttribute(domElem, "name")) { key = getAttributeValueAsStdString(domElem, "name"); } Ogre::String type = getAttributeValueAsStdString(domElem, "type"); CeGuiString value = ""; if (hasAttribute(domElem, "data")) { value = getAttributeValueAsString(domElem, "data"); } Property prop; if (type == "STRING") { prop = Property(value); } else if (type == "INT") { const int intVal = CEGUI::PropertyHelper::stringToInt(value); prop = Property(intVal); } else if (type == "REAL" || type == "FLOAT") { const Ogre::Real realVal = CEGUI::PropertyHelper::stringToFloat(value); prop = Property(realVal); } else if (type == "VECTOR3") { CeGuiString::size_type comma1 = value.find(","); CeGuiString::size_type comma2 = value.find(",", comma1 + 1); Ogre::Vector3 vec(Ogre::Vector3::ZERO); if (comma1 != CeGuiString::npos && comma2 != CeGuiString::npos) { vec.x = CEGUI::PropertyHelper::stringToFloat(value.substr(0, comma1)); vec.y = CEGUI::PropertyHelper::stringToFloat(value.substr(comma1 + 1, comma2 - comma1 - 1)); vec.z = CEGUI::PropertyHelper::stringToFloat(value.substr(comma2 + 1)); } prop = Property(vec); } else if (type == "QUATERNION") { CeGuiString::size_type comma1 = value.find(","); CeGuiString::size_type comma2 = value.find(",", comma1 + 1); CeGuiString::size_type comma3 = value.find(",", comma2 + 1); Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY); if (comma1 != CeGuiString::npos && comma2 != CeGuiString::npos && comma3 != CeGuiString::npos) { quat.w = CEGUI::PropertyHelper::stringToFloat(value.substr(0, comma1)); quat.x = CEGUI::PropertyHelper::stringToFloat(value.substr(comma1 + 1, comma2 - comma1 - 1)); quat.y = CEGUI::PropertyHelper::stringToFloat(value.substr(comma2 + 1, comma3 - comma2 - 1)); quat.z = CEGUI::PropertyHelper::stringToFloat(value.substr(comma3 + 1)); } else if (comma1 != CeGuiString::npos && comma2 != CeGuiString::npos && comma3 == CeGuiString::npos) { Quaternion rotX, rotY, rotZ; rotX.FromAngleAxis( Ogre::Degree(CEGUI::PropertyHelper::stringToFloat(value.substr(0, comma1))), Ogre::Vector3::UNIT_X); rotY.FromAngleAxis( Ogre::Degree(CEGUI::PropertyHelper::stringToFloat(value.substr(comma1 + 1, comma2 - comma1 - 1))), Ogre::Vector3::UNIT_Y); rotZ.FromAngleAxis( Ogre::Degree(CEGUI::PropertyHelper::stringToFloat(value.substr(comma2 + 1))), Ogre::Vector3::UNIT_Z); quat = rotX * rotY * rotZ; } prop = Property(quat); } else if (type == "BOOL") { const bool boolVal = CEGUI::PropertyHelper::stringToBool(value); prop = Property(boolVal); } else if (type == "ARRAY") { std::vector<Property> vecVal; for (DOMNode* curChild = domElem->getFirstChild(); curChild != NULL; curChild = curChild->getNextSibling()) { if (curChild->getNodeType() == DOMNode::ELEMENT_NODE) { PropertyEntry entry = processProperty(static_cast<DOMElement*>(curChild)); vecVal.push_back(entry.second); } } prop = Property(vecVal); } else if (type == "INTPAIR") { CeGuiString::size_type comma1 = value.find(","); std::pair<int,int> intpairVal = std::make_pair(0, 0); if (comma1 != CeGuiString::npos) { intpairVal = std::make_pair( CEGUI::PropertyHelper::stringToInt(value.substr(0, comma1)), CEGUI::PropertyHelper::stringToInt(value.substr(comma1 + 1))); } prop = Property(intpairVal); } else if (type == "INTTRIPLE") { CeGuiString::size_type comma1 = value.find(","); CeGuiString::size_type comma2 = value.find(",", comma1 + 1); Tripel<int> intTripel(0,0,0); if (comma1 != CeGuiString::npos && comma2 != CeGuiString::npos) { intTripel.first = CEGUI::PropertyHelper::stringToFloat(value.substr(0, comma1)); intTripel.second = CEGUI::PropertyHelper::stringToFloat(value.substr(comma1 + 1, comma2 - comma1 - 1)); intTripel.third = CEGUI::PropertyHelper::stringToFloat(value.substr(comma2 + 1)); } prop = Property(intTripel); } else if (type == "MAP") { PropertyMap mapVal; for (DOMNode* curChild = domElem->getFirstChild(); curChild != NULL; curChild = curChild->getNextSibling()) { if (curChild->getNodeType() == DOMNode::ELEMENT_NODE) { DOMElement* curElem = static_cast<DOMElement*>(curChild); CeGuiString key = getAttributeValueAsString(curElem, "name"); PropertyEntry entry = processProperty(curElem); mapVal[key] = entry.second; } } prop = Property(mapVal); } return std::make_pair(key, prop); }