本文整理汇总了C++中XmlTree::getRootNode方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlTree::getRootNode方法的具体用法?C++ XmlTree::getRootNode怎么用?C++ XmlTree::getRootNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTree
的用法示例。
在下文中一共展示了XmlTree::getRootNode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
Checksum Scenario::load(const string &path) {
Checksum scenarioChecksum;
try {
scenarioChecksum.addFile(path);
checksumValue.addFile(path);
string name= cutLastExt(lastDir(path));
Logger::getInstance().add("Scenario: " + formatString(name), true);
//parse xml
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *scenarioNode= xmlTree.getRootNode();
const XmlNode *scriptsNode= scenarioNode->getChild("scripts");
for(int i= 0; i<scriptsNode->getChildCount(); ++i){
const XmlNode *scriptNode = scriptsNode->getChild(i);
scripts.push_back(Script(getFunctionName(scriptNode), scriptNode->getText()));
}
}
//Exception handling (conversions and so on);
catch(const exception &e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error: " + path + "\n" + e.what());
}
return scenarioChecksum;
}
示例2: load
void UnitParticleSystemType::load(const XmlNode *particleFileNode, const string &dir, const string &path,
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
string parentLoader, string techtreePath) {
try{
XmlTree xmlTree;
std::map<string,string> mapExtraTagReplacementValues;
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/";
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
loadedFileList[path].push_back(make_pair(parentLoader,parentLoader));
const XmlNode *particleSystemNode= xmlTree.getRootNode();
if(particleFileNode){
// immediate children in the particleFileNode will override the particleSystemNode
particleFileNode->setSuper(particleSystemNode);
particleSystemNode= particleFileNode;
}
UnitParticleSystemType::load(particleSystemNode, dir, renderer,
loadedFileList, parentLoader, techtreePath);
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw megaglest_runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
}
}
示例3: loadObjectFromFile
Object* ObjectLoader::loadObjectFromFile(const char* filename){
Object* object = NULL;
//Leo el archivo y lo parseo en un arbol
XmlTree* xmlTree = XmlParser::parse(string(WindowConnector::getBaseApplicationPath() + filename).c_str());
//***Transformo el arbol en un Object***
XmlTreeNode* root = xmlTree->getRootNode();
//Primiero busco la etiqueta de Object
XmlTreeNode* objectNode = NULL;
for(unsigned int i=0; i < root->getChildNodes().size(); i++){
objectNode = root->getChildNodes()[i];
if(objectNode->getName().compare("Object")==0){
//Cargo el mesh y le seteo los valores del xml
object = initObject(objectNode);
break;
}
}
if(object == NULL){
if(xmlTree != NULL){ delete xmlTree; }
return NULL; //Error
}
//Busco las etiquetas de Mesh y reemplazo los valores del xml
Mesh* mesh = object->getMesh();
if(mesh->getChilds()->size() > 0){
loadMesh(mesh, objectNode);
}
//Busco las etiquetas de Light y las agrego a las luces del objeto
loadLights(object, objectNode);
//Guardo el path en el object
object->setFilename(filename);
delete xmlTree;
return object;
}
示例4: animationsToXmlTree
XmlTree* ScaenaAnimationWriter::animationsToXmlTree(list<AnimationDataTransfer*>* animations){
XmlTree* xmlTree = new XmlTree();
XmlTreeNode* rootNode = xmlTree->getRootNode();
// Agrego el tag inicial
XmlTreeNode* safNode = new XmlTreeNode("ScaenaAnimationFile", rootNode);
rootNode->addChild(safNode);
// Agrego todas las animaciones
list<AnimationDataTransfer*>::iterator animIt = animations->begin();
while( animIt != animations->end() ){
// Agrego el tag de animacion
XmlTreeNode* animationNode = new XmlTreeNode("Animation", safNode);
safNode->addChild(animationNode);
// Agrego como atributo el nombre de la animacion
AnimationDataTransfer* animationDataTransfer = *animIt;
animationNode->addAttribute(new XmlNodeAttribute("Name", animationDataTransfer->name));
// Agrego cada uno de los keyframes
list<KeyFrameDataTransfer*>::iterator keyIt = animationDataTransfer->keyframes->begin();
while(keyIt != animationDataTransfer->keyframes->end()){
keyFrameToXmlTree(animationNode, *keyIt);
++keyIt;
}
++animIt;
}
return xmlTree;
}
示例5: processScaenaAnimationFile
bool GenerationProcessor::processScaenaAnimationFile(string& inAnimationFile, string& outAnimationFile, string& keyFrameFBXFile, string& animationName, float keyDuration){
//Parseo el archivo de modelo
FbxModelLoader* fbxLoader = new FbxModelLoader();
ModelDataTransfer* modelDataTransfer = fbxLoader->loadModel(keyFrameFBXFile.c_str());
KeyFrameDataTransfer* keyframe = getKeyFrameData(modelDataTransfer, 0);
keyframe->animationTime = keyDuration;
delete fbxLoader;
// Si tengo SAF de entrada, lo cargo para agregarle la nueva animacion o keyframe
if(!inAnimationFile.empty()){
Logger::getInstance()->logInfo(new Log("Procesando el SAF de salida..."));
//Leo el archivo y lo parseo en un arbol
XmlTree* xmlTree = XmlParser::parse(inAnimationFile.c_str());
XmlTreeNode* rootNode = xmlTree->getRootNode();
// Busco el nodo de archivo SAF
XmlTreeNode* safNode = rootNode->searchDirectChild("ScaenaAnimationFile", 0);
if(safNode != NULL){
// Busco si alguna animacion tiene el mismo nombre que la indicada, si no creo una nueva
XmlTreeNode* animationNode = searchForAnimation(safNode, animationName);
if(animationNode == NULL){
animationNode = new XmlTreeNode("Animation", safNode);
animationNode->addAttribute(new XmlNodeAttribute("Name", animationName));
safNode->addChild(animationNode);
}
// Agrego el keyframe
XmlTreeNode* keyFrameNode = new XmlTreeNode("KeyFrame", animationNode);
keyFrameNode->addAttribute(new XmlNodeAttribute("DurationInSeconds", StringUtils::toString(keyframe->animationTime)));
ScaenaAnimationWriter::skeletonToXmlTree(keyFrameNode, keyframe->getRootSkeleton());
animationNode->addChild(keyFrameNode);
// Grabo en el archivo SAF (REVIEW: podria dejar de escribir cada cambio en disco)
XmlParser::writeXmlToFile(outAnimationFile.c_str(), xmlTree);
}
else{
throw new AnimationLoadException("No se puede procesar el SAF de entrada");
}
}
// Si no tengo SAF de entrada, creo la estructura de cero
else{
list<AnimationDataTransfer*> animations;
AnimationDataTransfer* animation = new AnimationDataTransfer();
animation->name = animationName;
animation->keyframes->push_back(keyframe);
animations.push_back(animation);
// Escribo el SAF e indico que ahora tengo archivo de entrada
ScaenaAnimationWriter::writeAnimation(outAnimationFile, &animations);
inAnimationFile = outAnimationFile;
}
delete modelDataTransfer;
delete keyframe;
return true;
}
示例6: load
void UnitParticleSystemType::load(const string &dir, const string &path, RendererInterface *renderer){
try{
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
UnitParticleSystemType::load(particleSystemNode, dir, renderer);
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
}
}
示例7: objectToXlmTree
XmlTree* ObjectLoader::objectToXlmTree(Object* object){
XmlTree* xmlTree = new XmlTree();
XmlTreeNode* node = xmlTree->getRootNode();
XmlTreeNode* objectNode = new XmlTreeNode("Object", node);
node->addChild(objectNode);
objectNode->createAttribute("id", object->getId());
objectNode->createAttribute("class", "Object");
objectNode->createAttribute("meshPath", object->getMesh()->getFilePath());
//Escribo el mesh asociado en nodos
writeFullMeshToNodes(objectNode, object->getMesh());
//Escribo las luces asociadas al objeto
writeAllLightsToNodes(objectNode, object->getAttachedLights());
return xmlTree;
}
示例8: load
void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
random.init(time(NULL));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string name= lastDir(dir);
tileset_name = name;
string currentPath = dir;
endPathWithSlash(currentPath);
string path= currentPath + name + ".xml";
string sourceXMLFile = path;
checksum->addFile(path);
tilesetChecksum->addFile(path);
checksumValue.addFile(path);
try {
char szBuf[8096]="";
snprintf(szBuf,8096,Lang::getInstance().get("LogScreenGameLoadingTileset","",true).c_str(),formatString(name).c_str());
Logger::getInstance().add(szBuf, true);
Renderer &renderer= Renderer::getInstance();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("About to load tileset [%s]\n",path.c_str());
//parse xml
XmlTree xmlTree;
xmlTree.load(path,Properties::getTagReplacementValues());
loadedFileList[path].push_back(make_pair(currentPath,currentPath));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
const XmlNode *tilesetNode= xmlTree.getRootNode();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//surfaces
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
int partsize= 0;
for(int i=0; i < surfCount; ++i) {
const XmlNode *surfaceNode;
if(surfacesNode->hasChildAtIndex("surface",i)){
surfaceNode= surfacesNode->getChild("surface", i);
}
else {
// cliff texture does not exist, use texture 2 instead
surfaceNode= surfacesNode->getChild("surface", 2);
}
if(surfaceNode->hasAttribute("partsize")){
partsize=surfaceNode->getAttribute("partsize",true)->getIntValue();
}
else{
partsize=0;
}
if(partsize==0){
int childCount= surfaceNode->getChildCount();
surfPixmaps[i].resize(childCount);
surfProbs[i].resize(childCount);
for(int j = 0; j < childCount; ++j) {
surfPixmaps[i][j] = NULL;
}
for(int j = 0; j < childCount; ++j) {
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
surfPixmaps[i][j] = new Pixmap2D();
surfPixmaps[i][j]->init(3);
surfPixmaps[i][j]->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
}
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
}
}
else {
// read single big texture and cut it into pieces
const XmlNode *textureNode= surfaceNode->getChild("texture", 0);
Pixmap2D *pixmap=new Pixmap2D();
pixmap->init(3);
pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
int width=pixmap->getW();
int heith=pixmap->getW();
assert(width==heith);
assert(width%64==0);
assert(width%partsize==0);
int parts=width/partsize;
int numberOfPieces=parts*parts;
partsArray[i]=parts;
surfPixmaps[i].resize(numberOfPieces);
surfProbs[i].resize(numberOfPieces);
int j=0;
//.........这里部分代码省略.........
示例9: rps
MenuBackground::MenuBackground() : rps(NULL) {
Renderer &renderer= Renderer::getInstance();
//load data
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
XmlTree xmlTree;
xmlTree.load(getGameCustomCoreDataPath(data_path, "data/core/menu/menu.xml"),Properties::getTagReplacementValues());
const XmlNode *menuNode= xmlTree.getRootNode();
//water
const XmlNode *waterNode= menuNode->getChild("water");
water= waterNode->getAttribute("value")->getBoolValue();
if(water){
waterHeight= waterNode->getAttribute("height")->getFloatValue();
//water texture
waterTexture= renderer.newTexture2D(rsMenu);
if(waterTexture) {
waterTexture->getPixmap()->init(4);
waterTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/water.tga"));
}
}
//fog
const XmlNode *fogNode= menuNode->getChild("fog");
fog= fogNode->getAttribute("value")->getBoolValue();
if(fog){
fogDensity= fogNode->getAttribute("density")->getFloatValue();
}
//rain
bool withRainEffect = Config::getInstance().getBool("RainEffectMenu","true");
if(withRainEffect == true) {
rain= menuNode->getChild("rain")->getAttribute("value")->getBoolValue();
if(rain) {
createRainParticleSystem();
}
}
else {
rain = false;
}
//camera
const XmlNode *cameraNode= menuNode->getChild("camera");
//position
const XmlNode *positionNode= cameraNode->getChild("start-position");
Vec3f startPosition;
startPosition.x= positionNode->getAttribute("x")->getFloatValue();
startPosition.y= positionNode->getAttribute("y")->getFloatValue();
startPosition.z= positionNode->getAttribute("z")->getFloatValue();
camera.setPosition(startPosition);
//rotation
const XmlNode *rotationNode= cameraNode->getChild("start-rotation");
Vec3f startRotation;
startRotation.x= rotationNode->getAttribute("x")->getFloatValue();
startRotation.y= rotationNode->getAttribute("y")->getFloatValue();
startRotation.z= rotationNode->getAttribute("z")->getFloatValue();
camera.setOrientation(Quaternion(EulerAngles(
degToRad(startRotation.x),
degToRad(startRotation.y),
degToRad(startRotation.z))));
//load main model
mainModel= renderer.newModel(rsMenu);
if(mainModel) {
string mainModelFile = "data/core/menu/main_model/menu_main.g3d";
if(menuNode->hasChild("menu-background-model") == true) {
//mainModel->load(data_path + "data/core/menu/main_model/menu_main.g3d");
const XmlNode *mainMenuModelNode= menuNode->getChild("menu-background-model");
mainModelFile = mainMenuModelNode->getAttribute("value")->getRestrictedValue();
}
mainModel->load(getGameCustomCoreDataPath(data_path, mainModelFile));
}
//models
for(int i=0; i<5; ++i){
characterModels[i]= renderer.newModel(rsMenu);
if(characterModels[i]) {
characterModels[i]->load(getGameCustomCoreDataPath(data_path, "data/core/menu/about_models/character"+intToStr(i)+".g3d"));
}
}
//about position
positionNode= cameraNode->getChild("about-position");
aboutPosition.x= positionNode->getAttribute("x")->getFloatValue();
aboutPosition.y= positionNode->getAttribute("y")->getFloatValue();
aboutPosition.z= positionNode->getAttribute("z")->getFloatValue();
rotationNode= cameraNode->getChild("about-rotation");
targetCamera= NULL;
t= 0.f;
fade= 0.f;
anim= 0.f;
}
示例10: RainParticleSystem
MenuBackground::MenuBackground(){
Renderer &renderer= Renderer::getInstance();
//load data
XmlTree xmlTree;
xmlTree.load("data/core/menu/menu.xml");
const XmlNode *menuNode= xmlTree.getRootNode();
//water
const XmlNode *waterNode= menuNode->getChild("water");
water= waterNode->getAttribute("value")->getBoolValue();
if(water){
waterHeight= waterNode->getAttribute("height")->getFloatValue();
//water texture
waterTexture= renderer.newTexture2D(ResourceScope::MENU);
waterTexture->getPixmap()->init(4);
waterTexture->getPixmap()->load("data/core/menu/textures/water.tga");
}
//fog
const XmlNode *fogNode= menuNode->getChild("fog");
fog= fogNode->getAttribute("value")->getBoolValue();
if(fog){
fogDensity= fogNode->getAttribute("density")->getFloatValue();
}
// rain
rain = menuNode->getChild("rain")->getAttribute("value")->getBoolValue();
if(rain){
RainParticleSystem *rps= new RainParticleSystem();
rps->setSpeed(12.f / WORLD_FPS);
rps->setEmissionRate(25.f);
rps->setWindSpeed2(-90.f, 4.f / WORLD_FPS);
rps->setPos(Vec3f(0.f, 25.f, 0.f));
rps->setColor(Vec4f(1.f, 1.f, 1.f, 0.2f));
rps->setRadius(30.f);
renderer.manageParticleSystem(rps, ResourceScope::MENU);
for(int i=0; i<raindropCount; ++i){
raindropStates[i]= random.randRange(0.f, 1.f);
raindropPos[i]= computeRaindropPos();
}
} else if (menuNode->getOptionalBoolValue("snow")) {
SnowParticleSystem *sps = new SnowParticleSystem(1200);
sps->setSpeed(1.5f / WORLD_FPS);
sps->setEmissionRate(2.f);
sps->setWindSpeed2(-90.f, 0.5f / WORLD_FPS);
sps->setPos(Vec3f(0.f, 25.f, 0.f));
sps->setRadius(30.f);
sps->setTexture(g_coreData.getSnowTexture());
renderer.manageParticleSystem(sps, ResourceScope::MENU);
}
//camera
const XmlNode *cameraNode= menuNode->getChild("camera");
//position
const XmlNode *positionNode= cameraNode->getChild("start-position");
Vec3f startPosition;
startPosition.x= positionNode->getAttribute("x")->getFloatValue();
startPosition.y= positionNode->getAttribute("y")->getFloatValue();
startPosition.z= positionNode->getAttribute("z")->getFloatValue();
camera.setPosition(startPosition);
//rotation
const XmlNode *rotationNode= cameraNode->getChild("start-rotation");
Vec3f startRotation;
startRotation.x= rotationNode->getAttribute("x")->getFloatValue();
startRotation.y= rotationNode->getAttribute("y")->getFloatValue();
startRotation.z= rotationNode->getAttribute("z")->getFloatValue();
camera.setOrientation(Quaternion(EulerAngles(
degToRad(startRotation.x),
degToRad(startRotation.y),
degToRad(startRotation.z))));
// load main model
mainModel= renderer.newModel(ResourceScope::MENU);
mainModel->load("data/core/menu/main_model/menu_main.g3d", 2, 2);
// models
for(int i=0; i<5; ++i){
characterModels[i]= renderer.newModel(ResourceScope::MENU);
try {
characterModels[i]->load("data/core/menu/about_models/character"+intToStr(i)+".g3d", 2, 2);
} catch (runtime_error &e) {
g_logger.logError(e.what());
}
}
// about position
positionNode= cameraNode->getChild("about-position");
aboutPosition.x= positionNode->getAttribute("x")->getFloatValue();
aboutPosition.y= positionNode->getAttribute("y")->getFloatValue();
aboutPosition.z= positionNode->getAttribute("z")->getFloatValue();
rotationNode= cameraNode->getChild("about-rotation");
targetCamera = 0;
//.........这里部分代码省略.........
示例11: load
void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
this->id= id;
string path;
try{
Logger::getInstance().add("Unit type: " + formatString(name), true);
//file load
path= dir+"/"+name+".xml";
checksum->addFile(path);
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters");
//size
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
//height
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
//maxHp
maxHp= parametersNode->getChild("max-hp")->getAttribute("value")->getIntValue();
//hpRegeneration
hpRegeneration= parametersNode->getChild("max-hp")->getAttribute("regeneration")->getIntValue();
//maxEp
maxEp= parametersNode->getChild("max-ep")->getAttribute("value")->getIntValue();
if(maxEp!=0){
//wpRegeneration
epRegeneration= parametersNode->getChild("max-ep")->getAttribute("regeneration")->getIntValue();
}
//armor
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
//armor type string
string armorTypeName= parametersNode->getChild("armor-type")->getAttribute("value")->getRestrictedValue();
armorType= techTree->getArmorType(armorTypeName);
//sight
sight= parametersNode->getChild("sight")->getAttribute("value")->getIntValue();
//prod time
productionTime= parametersNode->getChild("time")->getAttribute("value")->getIntValue();
//multi selection
multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue();
//cellmap
const XmlNode *cellMapNode= parametersNode->getChild("cellmap");
bool hasCellMap= cellMapNode->getAttribute("value")->getBoolValue();
if(hasCellMap){
cellMap= new bool[size*size];
for(int i=0; i<size; ++i){
const XmlNode *rowNode= cellMapNode->getChild("row", i);
string row= rowNode->getAttribute("value")->getRestrictedValue();
if(row.size()!=size){
throw runtime_error("Cellmap row has not the same length as unit size");
}
for(int j=0; j<row.size(); ++j){
cellMap[i*size+j]= row[j]=='0'? false: true;
}
}
}
//levels
const XmlNode *levelsNode= parametersNode->getChild("levels");
levels.resize(levelsNode->getChildCount());
for(int i=0; i<levels.size(); ++i){
const XmlNode *levelNode= levelsNode->getChild("level", i);
levels[i].init(
levelNode->getAttribute("name")->getRestrictedValue(),
levelNode->getAttribute("kills")->getIntValue());
}
//fields
const XmlNode *fieldsNode= parametersNode->getChild("fields");
for(int i=0; i<fieldsNode->getChildCount(); ++i){
const XmlNode *fieldNode= fieldsNode->getChild("field", i);
string fieldName= fieldNode->getAttribute("value")->getRestrictedValue();
if(fieldName=="land"){
fields[fLand]= true;
}
else if(fieldName=="air"){
fields[fAir]= true;
}
else{
throw runtime_error("Not a valid field: "+fieldName+": "+ path);
}
}
//properties
//.........这里部分代码省略.........
示例12: load
bool Modification::load(const string &dir) {
g_logger.logProgramEvent("Modification: " + dir, true);
bool loadOk = true;
string path = dir + "/" + m_name + ".xml";
name = m_name;
XmlTree xmlTree;
try { xmlTree.load(path); }
catch (runtime_error e) {
g_logger.logXmlError(path, e.what());
g_logger.logError("Fatal Error: could not load " + path);
return false;
}
const XmlNode *modificationNode;
try { modificationNode = xmlTree.getRootNode(); }
catch (runtime_error e) {
g_logger.logXmlError(path, e.what());
return false;
}
const XmlNode *parametersNode;
try { parametersNode = modificationNode->getChild("parameters"); }
catch (runtime_error e) {
g_logger.logXmlError(path, e.what());
return false;
}
if (!RequirableType::load(parametersNode, dir)) {
loadOk = false;
}
try {
const XmlNode *serviceNode = parametersNode->getChild("service");
service = serviceNode->getAttribute("scope")->getRestrictedValue();
} catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
try {
const XmlNode *equipmentNode = parametersNode->getChild("equipment-types", 0, false);
if(equipmentNode) {
for(int i = 0; i < equipmentNode->getChildCount(); ++i) {
try {
const XmlNode *typeNode = equipmentNode->getChild("equipment-type", i);
string ename = typeNode->getAttribute("name")->getRestrictedValue();
equipment.push_back(ename);
} catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
}
}
} catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
try {
const XmlNode *resourceRequirementsNode = parametersNode->getChild("resource-requirements", 0, false);
if(resourceRequirementsNode) {
costs.resize(resourceRequirementsNode->getChildCount());
for(int i = 0; i < costs.size(); ++i) {
try {
const XmlNode *resourceNode = resourceRequirementsNode->getChild("resource", i);
string rname = resourceNode->getAttribute("name")->getRestrictedValue();
int amount = resourceNode->getAttribute("amount")->getIntValue();
int amount_plus = resourceNode->getAttribute("plus")->getIntValue();
fixed amount_multiply = resourceNode->getAttribute("multiply")->getFixedValue();
costs[i].init(g_world.getTechTree()->getResourceType(rname), amount, amount_plus, amount_multiply);
} catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
}
}
} catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
try {
const XmlNode *statisticsNode = parametersNode->getChild("statistics", 0, false);
if (statisticsNode) {
if (!statistics.load(statisticsNode, dir)) {
loadOk = false;
}
}
}
catch (runtime_error e) {
g_logger.logXmlError(dir, e.what());
loadOk = false;
}
const XmlNode *effectsNode = parametersNode->getChild("effects", 0, false);
if (effectsNode) {
effectTypes.resize(effectsNode->getChildCount());
for(int i=0; i < effectsNode->getChildCount(); ++i) {
const XmlNode *effectNode = effectsNode->getChild("effect", i);
EffectType *effectType = new EffectType();
effectType->load(effectNode, dir);
effectTypes[i] = effectType;
}
}
//.........这里部分代码省略.........
示例13: load
void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
random.init(time(NULL));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string name= lastDir(dir);
string path= dir + "/" + name + ".xml";
checksum->addFile(path);
tilesetChecksum->addFile(path);
checksumValue.addFile(path);
try {
Logger::getInstance().add("Tileset: "+formatString(name), true);
Renderer &renderer= Renderer::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//parse xml
XmlTree xmlTree;
xmlTree.load(path);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
const XmlNode *tilesetNode= xmlTree.getRootNode();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//surfaces
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
for(int i=0; i<surfCount; ++i){
const XmlNode *surfaceNode= surfacesNode->getChild("surface", i);
int childCount= surfaceNode->getChildCount();
surfPixmaps[i].resize(childCount);
surfProbs[i].resize(childCount);
for(int j=0; j<childCount; ++j){
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
surfPixmaps[i][j].init(3);
surfPixmaps[i][j].load(dir +"/"+textureNode->getAttribute("path")->getRestrictedValue());
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//object models
const XmlNode *objectsNode= tilesetNode->getChild("objects");
for(int i=0; i<objCount; ++i){
const XmlNode *objectNode= objectsNode->getChild("object", i);
int childCount= objectNode->getChildCount();
int objectHeight = 0;
bool walkable = objectNode->getAttribute("walkable")->getBoolValue();
if(walkable == false) {
const XmlAttribute *heightAttribute = objectNode->getAttribute("height",false);
if(heightAttribute != NULL) {
objectHeight = heightAttribute->getIntValue();
}
}
objectTypes[i].init(childCount, i, walkable,objectHeight);
for(int j=0; j<childCount; ++j) {
const XmlNode *modelNode= objectNode->getChild("model", j);
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
}
}
// Now free up the pixmap memory
for(int i=0; i<objCount; ++i){
objectTypes[i].deletePixels();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//ambient sounds
ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds"));
//parameters
const XmlNode *parametersNode= tilesetNode->getChild("parameters");
//water
const XmlNode *waterNode= parametersNode->getChild("water");
waterTex= renderer.newTexture3D(rsGame);
waterTex->setMipmap(false);
waterTex->setWrapMode(Texture::wmRepeat);
waterEffects= waterNode->getAttribute("effects")->getBoolValue();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
int waterFrameCount= waterNode->getChildCount();
waterTex->getPixmap()->init(waterFrameCount, 4);
for(int i=0; i<waterFrameCount; ++i){
const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
waterTex->getPixmap()->loadSlice(dir +"/"+ waterFrameNode->getAttribute("path")->getRestrictedValue(), i);
}
//.........这里部分代码省略.........
示例14: writeKeyFrameToFileSystem
void ScaenaAnimationFileWriter::writeKeyFrameToFileSystem(string filename, SkinnedAnimationKeyFrame* keyframe){
XmlTree* xmlTree = new XmlTree();
XmlTreeNode* node = xmlTree->getRootNode();
this->keyFrameToXmlTree(node, keyframe);
XmlParser::writeXmlToFile((WindowConnector::getBaseApplicationPath() + string(filename)).c_str(), xmlTree);
}