#include "dxstdafx.h" #include ".\gamesceneloader.h" #include "GameManager.h" #include "UserPlayer.h" #include "Weapon.h" #include "SimpleWeapon.h" #include "SimpleBullet.h" #include "Terrain.h" #include "HUD.h" #include "Ocean.h" #include "SkyBox.h" #include "Object3d.h" #include "NxActorDesc.h" #include "NxMaterialDesc.h" #include "NxMaterial.h" #include "Goodie.h" #include "UserContactReport.h" #include "UniversalWeapon.h" #include "ParticleEmitter.h" #include "ParticleGroup.h" #include "Sprite.h" GameSceneLoader::GameSceneLoader(void) { //XML Stuff ::CoInitialize(NULL); HRESULT hr = sceneDomDocument.CreateInstance(MSXML::CLSID_DOMDocument); if (FAILED(hr)) { //MessageBox(NULL,"Unable to create XML instance!", "Wuermer DEBUG",MB_OK|MB_ICONQUESTION); this->scene->manager->printToConsole("Unable to create XML instance!"); exit(0); } } GameSceneLoader::~GameSceneLoader(void) { } bool GameSceneLoader::loadGameScene(GameScene &_scene, std::string filename, GameManager *_manager) { this->scene = &_scene; // specify xml file name variant_t vResult; vResult = sceneDomDocument->load(filename.c_str()); if (((bool)vResult) == TRUE) { sceneDocRoot = sceneDomDocument->documentElement; } else { this->scene->manager->printToConsole(filename); this->scene->manager->printToConsole("Loading GameScene failed!"); MessageBox(NULL, L"Maybe the file is not a valid xml!", L"Error loading .xml file!", MB_ICONERROR); return false; } //Clear existing gamescene /*if (this->loadAgain) { this->scene->clearScene(); } else { this->loadAgain = true; }*/ //BuildGame _bstr_t tmpName("name"); _bstr_t tmpMode("mode"); _bstr_t tmpTime("time"); _bstr_t tmpSun("sun"); _bstr_t tmpDimension("dimension"); _bstr_t tmpTerrain("terrain"); _bstr_t tmpOcean("ocean"); _bstr_t tmpSkyBox("skybox"); _bstr_t tmpBullet("bullet"); _bstr_t tmpWeapon("weapon"); _bstr_t tmpPlayer("player"); _bstr_t tmpGoodies("goodies"); _bstr_t tmpPMaterial("pmaterial"); _bstr_t tmpHud("hud"); _bstr_t tmpParticleEmitter("particleEmitter"); _bstr_t tmpSoundFile("soundfile"); _bstr_t tmpSoundVolume("soundvolume"); _bstr_t tmpEnvObject("envObject"); _bstr_t tmpDescription("description"); _bstr_t tmpDescriptionDuration("descduration"); _bstr_t tmpMaxEnemyCount("maxenemycount"); std::string description; bool descSet = false; float descTime = 3; int maxEnemyCount = 1; Vector dimension; //NOTE: this is a hack to ensure that the scene has constant size (==>watermap!) dimension.addXYZ(320, 40, 320); this->scene->setWidth(dimension.x); this->scene->setHeight(dimension.y); this->scene->setDepth(dimension.z); for (MSXML::IXMLDOMNodePtr pChild = sceneDocRoot->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpName) { this->scene->gameName = pChild->firstChild->text; //GameScene Name } else if(pChild->nodeName == tmpMode) { this->scene->gameMode = atoi(pChild->firstChild->text); //Game Mode } else if(pChild->nodeName == tmpTime) { this->scene->gameDuration = (float)atoi(pChild->firstChild->text); //Game Time } /*else if (pChild->nodeName == tmpDimension) { dimension = this->tracePosition(pChild); //Dimension of level this->scene->setWidth(dimension.x); this->scene->setHeight(dimension.y); this->scene->setDepth(dimension.z); }*/ else if(pChild->nodeName == tmpTerrain) { this->traceTerrain(pChild); //Terrain } else if(pChild->nodeName == tmpOcean) { this->traceOcean(pChild); //Ocean //TODO EINFUEGEN!!! this->scene->manager->printToConsole("Uncomment this->traceOcean(...) in GameSceneLoader!!"); } else if(pChild->nodeName == tmpSkyBox) { this->traceSkyBox(pChild); //SkyBox } else if(pChild->nodeName == tmpBullet) { this->traceBullet(pChild); //Bullet } else if(pChild->nodeName == tmpWeapon) { this->traceWeapon(pChild); //Weapon } else if(pChild->nodeName == tmpPlayer) { this->tracePlayer(pChild); //Player } else if(pChild->nodeName == tmpGoodies) { this->traceGoodies(pChild); //Goodies } else if(pChild->nodeName == tmpSun) { this->traceSun(pChild); //Sun } else if(pChild->nodeName == tmpHud) { this->traceHud(pChild); //HUD } else if(pChild->nodeName == tmpParticleEmitter) { this->traceParticleEmitter(pChild); //ParticleEmitter } else if(pChild->nodeName == tmpSoundFile) { std::string soundFile = pChild->firstChild->text; this->scene->setBackgroundSound(soundFile); //BackgroundSound } else if(pChild->nodeName == tmpSoundVolume) { this->scene->setBackgroundSoundVolume((FLOAT)atof(pChild->firstChild->text)); //SoundVolume } else if(pChild->nodeName == tmpEnvObject) { this->traceEnvironmentObject(pChild); //Environment Object } else if(pChild->nodeName == tmpPMaterial) { this->tracePMaterial(pChild); } else if(pChild->nodeName == tmpDescription) { description = pChild->firstChild->text; descSet = true; } else if(pChild->nodeName == tmpDescriptionDuration) { descTime = (FLOAT) atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpMaxEnemyCount) { maxEnemyCount = (INT) atoi(pChild->firstChild->text); this->scene->setMaxEnemyCount(maxEnemyCount); } } } if(descSet) { this->scene->setChallengeDescription(description, descTime); } return true; } void GameSceneLoader::traceSun(MSXML::IXMLDOMNodePtr sunNode) { Vector direction; _bstr_t tmpDirection("direction"); for (MSXML::IXMLDOMNodePtr pChild = sunNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpDirection) { direction = tracePosition(pChild); } } } direction = direction*(-1); //Use direction vector this->scene->setLight(direction); } Vector GameSceneLoader::tracePosition(MSXML::IXMLDOMNodePtr positionNode) { _bstr_t tmpX("x"); _bstr_t tmpY("y"); _bstr_t tmpZ("z"); Vector position; for (MSXML::IXMLDOMNodePtr pChild = positionNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpX) { position.x = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpY) { position.y = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpZ) { position.z = (FLOAT)atof(pChild->firstChild->text); } } } return position; } void GameSceneLoader::traceBullet(MSXML::IXMLDOMNodePtr bulletNode) { /* 0 4000 150000 */ _bstr_t tmpType("type"); _bstr_t tmpSpeed("speed"); _bstr_t tmpImpactForce("impactForce"); _bstr_t tmpXFile("xfile"); _bstr_t tmpFlySound("flySound"); _bstr_t tmpImpactSound("impactSound"); _bstr_t tmpParticleEmitter("particleEmitter"); //_bstr_t tmpPActor("pactor"); //MSXML::IXMLDOMNodePtr pActorNode; //bool pActorInside = false; int type=0; float speed=0; float impactForce=0; std::string flySound = ""; std::string impactSound = ""; std::string xfile = ""; std::vector partEmitt; for (MSXML::IXMLDOMNodePtr pChild = bulletNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpSpeed) { speed = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpImpactForce) { impactForce = (FLOAT)atof(pChild->firstChild->text); //float between 0...16!! } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; } else if(pChild->nodeName == tmpFlySound) { flySound = pChild->firstChild->text; } else if(pChild->nodeName == tmpImpactSound) { impactSound = pChild->firstChild->text; } else if(pChild->nodeName == tmpParticleEmitter) { //Particle Emitter for Bullet! ParticleEmitter* tempEmitt = this->traceParticleEmitter(pChild); partEmitt.push_back(tempEmitt); } /*else if(pChild->nodeName == tmpPActor) { pActorNode = pChild; pActorInside = true; }*/ } } if(type<3) { SimpleBullet *bullet = (SimpleBullet *) this->scene->createReferenceNode(this->scene->NODE_SIMPLEBULLET, true); bullet->setBulletType(type); if(speed!=0) bullet->setSpeed(speed); if(impactForce!=0) bullet->setImpactForce(impactForce); bullet->setXFile(xfile); bullet->setFlySound(flySound); bullet->setImpactSound(impactSound); for(UINT i = 0; iscene->manager->printToConsole("ist nullllllllllllllllllllllllllllllllll!"); } bullet->addParticleEmitter(partEmitt[i]); } } //else if... /*Bullet *bullet = (Bullet *) this->scene->createReferenceNode(this->scene->NODE_BULLET, true); bullet->setType(type); bullet->setSpeed(speed); bullet->setImpactForce(impactForce); bullet->setFilename(mdlObject.c_str()); if(pActorInside) this->tracePActor(pActorNode, *bullet);*/ } void GameSceneLoader::traceWeapon(MSXML::IXMLDOMNodePtr weaponNode) { /* 0 0 500 .. .. .. */ _bstr_t tmpType("type"); _bstr_t tmpBulletType("bulletType"); _bstr_t tmpReboundForce("reboundForce"); _bstr_t tmpIdleSound("idleSound"); _bstr_t tmpPreloadTime("preloadTime"); _bstr_t tmpPreloadSound("preloadSound"); _bstr_t tmpFireTime("fireTime"); _bstr_t tmpFireSound("fireSound"); _bstr_t tmpPostloadTime("postloadTime"); _bstr_t tmpPostloadSound("postloadSound"); _bstr_t tmpEmptySound("emptySound"); _bstr_t tmpXFile("xfile"); int type=0; int bulletType=0; float reboundForce=0; std::string idleSound; float preloadTime=0; std::string preloadSound; float fireTime=0; std::string fireSound; float postloadTime=0; std::string postloadSound; std::string emptySound; std::string xfile; for (MSXML::IXMLDOMNodePtr pChild = weaponNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); //WeaponType } else if(pChild->nodeName == tmpBulletType) { bulletType = atoi(pChild->firstChild->text); //BulletType } else if(pChild->nodeName == tmpReboundForce) { reboundForce = (FLOAT)atof(pChild->firstChild->text); //ReboundForce } else if(pChild->nodeName == tmpIdleSound) { idleSound = pChild->firstChild->text; //IdleSound } else if(pChild->nodeName == tmpPreloadTime) { preloadTime = (FLOAT)atof(pChild->firstChild->text); //PreloadTime } else if(pChild->nodeName == tmpPreloadSound) { preloadSound = pChild->firstChild->text; //PreloadSound } else if(pChild->nodeName == tmpFireTime) { fireTime = (FLOAT)atof(pChild->firstChild->text); //FireTime } else if(pChild->nodeName == tmpFireSound) { fireSound = pChild->firstChild->text; //FireSound } else if(pChild->nodeName == tmpPostloadTime) { postloadTime = (FLOAT)atof(pChild->firstChild->text); //PostloadTime } else if(pChild->nodeName == tmpPostloadSound) { postloadSound = pChild->firstChild->text; //PostloadSound } else if(pChild->nodeName == tmpEmptySound) { emptySound = pChild->firstChild->text; //EmptySound } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; //XFile } } } if(type <= 4) { //All simpleWeapons SimpleWeapon *weapon = (SimpleWeapon *) this->scene->createReferenceNode(this->scene->NODE_SIMPLEWEAPON, true); weapon->setWeaponType(type); } else { //Yet, only these Types are supported! UniversalWeapon *weapon = (UniversalWeapon*) this->scene->createReferenceNode(GameScene::NODE_UNIVERSALWEAPON, true); weapon->setWeaponType(type); weapon->setBulletType(bulletType); weapon->setReboundForce(reboundForce); weapon->setStateSound(Weapon::STATE_IDLE, idleSound); weapon->setStateTime(Weapon::STATE_PRELOAD, preloadTime); weapon->setStateSound(Weapon::STATE_PRELOAD, preloadSound); weapon->setStateTime(Weapon::STATE_FIRE, fireTime); weapon->setStateSound(Weapon::STATE_FIRE, fireSound); weapon->setStateTime(Weapon::STATE_POSTLOAD, postloadTime); weapon->setStateSound(Weapon::STATE_POSTLOAD, postloadSound); weapon->setStateSound(Weapon::STATE_EMPTY, emptySound); weapon->setXFile(xfile); weapon->setStandBy(true); } //else if... /*Weapon *weapon = (Weapon *) this->scene->createReferenceNode(this->scene->NODE_WEAPON, true); weapon->setType(type); weapon->setBulletType(bulletType); weapon->setReboundForce(reboundForce); weapon->setLeftWeapon(mdlObject.c_str()); weapon->setRightWeapon(mdlObject.c_str()); weapon->setReboundTime(reboundTime); weapon->setReloadTime(reloadTime);*/ } void GameSceneLoader::tracePlayer(MSXML::IXMLDOMNodePtr playerNode) { Vector position; int type; int team = 0; std::string avatar = ""; _bstr_t tmpType("type"); _bstr_t tmpPosition("position"); _bstr_t tmpWeapon("weapon"); _bstr_t tmpTeam("team"); _bstr_t tmpAvatar("xfile"); bool aiPlayer = false; Player *player = NULL; for (MSXML::IXMLDOMNodePtr pChild = playerNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); switch(type) { case 0: this->scene->manager->printToConsole("Creating UserPlayer"); player = (Player *) this->scene->createNode(this->scene->NODE_USERPLAYER, false); break; case 1: this->scene->manager->printToConsole("Creating AIPlayer"); player = (Player *) this->scene->createNode(this->scene->NODE_AIPLAYER, false); aiPlayer = true; break; } } else if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); player->initPlayer(position.x, position.y, position.z); } else if(pChild->nodeName == tmpWeapon) { this->addWeapon(pChild, *player); } else if(pChild->nodeName == tmpTeam) { team = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpAvatar) { avatar = pChild->firstChild->text; player->setAvatareFileName(avatar); } } } if(aiPlayer) { this->scene->enemyModel = avatar; } //player->initPlayer(position.x, position.y, position.z); player->setTeam(team); player->setActiveWeapon(0); } void GameSceneLoader::addWeapon(MSXML::IXMLDOMNodePtr playerWeaponNode, Player &player) { //Addweapon and munition /* 0 100 */ _bstr_t tmpType("type"); _bstr_t tmpAmount("amount"); int type=0; int amount=0; for (MSXML::IXMLDOMNodePtr pChild = playerWeaponNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpAmount) { amount = atoi(pChild->firstChild->text); } } } if(type<=4) { //this->scene->manager->printToConsole(" adding Weapon Type<=3"); SimpleWeapon *weapon = (SimpleWeapon *) this->scene->createNode(this->scene->NODE_SIMPLEWEAPON, *player.schale, true); weapon->setWeaponType(type); weapon->addMunition(amount); weapon->initWeapon(); player.addWeapon(*weapon); return; } else { player.addWeapon(*this->scene->cloneWeaponFromReference(type)); } /*Weapon *refWeapon = NULL; //Find Reference Weapon for(unsigned int i=0;iscene->refWeaponList.size();i++) { refWeapon = (Weapon *) this->scene->refWeaponList.at(i).get(); if(refWeapon->getWeaponType()==type) break; }*/ //Add Weapon to Player //Weapon *weapon = player.sMgr->createWeapon(*player.schale); /*Weapon *weapon = (Weapon *) this->scene->createNode(this->scene->NODE_WEAPON, *player.schale, true); weapon->setType(refWeapon->getType()); weapon->setBulletType(refWeapon->getBulletType()); weapon->setReboundForce(refWeapon->getReboundForceLength()); weapon->setLeftWeapon(refWeapon->getLeftWeaponFilename()); weapon->setRightWeapon(refWeapon->getRightWeaponFilename()); weapon->setReboundTime(refWeapon->getReboundTime()); weapon->setReloadTime(refWeapon->getReloadTime()); weapon->initWeapon(); player.addWeapon(*weapon); player.addMunition(refWeapon->getBulletType(), amount);*/ } void GameSceneLoader::traceSkyBox(MSXML::IXMLDOMNodePtr skyBoxNode) { /* ./media/sky.x */ _bstr_t tmpCube("xfile"); /*_bstr_t tmpTexture0("skytexture0"); _bstr_t tmpTexture1("skytexture1"); _bstr_t tmpTexture2("skytexture2"); _bstr_t tmpTexture3("skytexture3"); _bstr_t tmpTexture4("skytexture4"); _bstr_t tmpTexture5("skytexture5"); _bstr_t tmpTexture6("skytexture6"); _bstr_t tmpTexture7("skytexture7"); _bstr_t tmpTexture8("skytexture8");*/ std::string skyname; /*std::string texture0; std::string texture1; std::string texture2; std::string texture3; std::string texture4; std::string texture5; std::string texture6; std::string texture7; std::string texture8;*/ std::string skyTexture; for (MSXML::IXMLDOMNodePtr pChild = skyBoxNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpCube) { skyname = pChild->firstChild->text; } /*if(pChild->nodeName == tmpTexture0) { texture0 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture1) { texture1 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture2) { texture2 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture3) { texture3 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture4) { texture4 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture5) { texture5 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture6) { texture6 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture7) { texture7 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture8) { texture8 = pChild->firstChild->text; }*/ } } //SkyBox erzeugen & entsprechende Texture laden /*this->scene->createSkybox();*/ SkyBox *skybox = (SkyBox *) this->scene->createNode(this->scene->NODE_SKYBOX, *this->scene->getRoot(), false); skybox->generateSkyBox(skyname); //skybox->generateSkyBox("./media/models/skybox1.x"); /*this->scene->getSkybox()->setTexture0(texture0); this->scene->getSkybox()->setTexture1(texture1); this->scene->getSkybox()->setTexture2(texture2); this->scene->getSkybox()->setTexture3(texture3); this->scene->getSkybox()->setTexture4(texture4); this->scene->getSkybox()->setTexture5(texture5); this->scene->getSkybox()->setTexture6(texture6); this->scene->getSkybox()->setTexture7(texture7); this->scene->getSkybox()->setTexture8(texture8); this->scene->getSkybox()->generateSkybox(this->scene->getSunDirecetion()); this->scene->getSkybox()->setSize(this->scene->getTerrain()->getSize());*/ } void GameSceneLoader::traceTerrain(MSXML::IXMLDOMNodePtr terrainNode) { _bstr_t tmpHeightMap("heightmap"); _bstr_t tmpTexture0("texture0"); _bstr_t tmpTexture1("texture1"); _bstr_t tmpTexture2("texture2"); std::string heightMap; std::string texture0; std::string texture1; std::string texture2; for (MSXML::IXMLDOMNodePtr pChild = terrainNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpHeightMap) { heightMap = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture0) { texture0 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture1) { texture1 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture2) { texture2 = pChild->firstChild->text; } } } Terrain *terrain = (Terrain *) this->scene->createNode(this->scene->NODE_TERRAIN, *this->scene->getRoot(), false); terrain->setTextures(texture0, texture1, texture2); terrain->generateTerrain(heightMap, 129, 129); } void GameSceneLoader::traceOcean(MSXML::IXMLDOMNodePtr oceanNode) { _bstr_t tmpTexture0("texture0"); _bstr_t tmpTexture1("texture1"); _bstr_t tmpWatermap("watermap"); _bstr_t tmpShallowColorR("shallowColorR"); _bstr_t tmpShallowColorG("shallowColorG"); _bstr_t tmpShallowColorB("shallowColorB"); _bstr_t tmpDeepColorR("deepColorR"); _bstr_t tmpDeepColorG("deepColorG"); _bstr_t tmpDeepColorB("deepColorB"); std::string texture0; std::string texture1; std::string watermap; float shallowColor [] = {0.0f, 0.0f, 0.0f, 0.0f}; float deepColor [] = {0.0f, 0.0f, 0.0f, 0.0f}; for (MSXML::IXMLDOMNodePtr pChild = oceanNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpTexture0) { texture0 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture1) { texture1 = pChild->firstChild->text; } else if(pChild->nodeName == tmpShallowColorR) { shallowColor[0] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpShallowColorG) { shallowColor[1] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpShallowColorB) { shallowColor[2] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpDeepColorR) { deepColor[0] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpDeepColorG) { deepColor[1] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpDeepColorB) { deepColor[2] = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpWatermap) { watermap = pChild->firstChild->text; } } } Ocean *ocean = (Ocean *) this->scene->createNode(this->scene->NODE_OCEAN, *this->scene->getRoot(), false); ocean->setTextures(texture0, texture1, watermap); ocean->generateOcean(deepColor, shallowColor); } void GameSceneLoader::traceGoodies(MSXML::IXMLDOMNodePtr goodiesNode) { /* */ _bstr_t tmpHealthPackage("healthpackage"); _bstr_t tmpWeapon("weaponpackage"); _bstr_t tmpAmo("amopackage"); //_bstr_t tmpPActor("pactor"); MSXML::IXMLDOMNodePtr pActorNode; bool pActorInside = false; for (MSXML::IXMLDOMNodePtr pChild = goodiesNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpHealthPackage) { traceHealthPackage(pChild); } else if(pChild->nodeName == tmpWeapon) { traceWeaponPackage(pChild); } else if(pChild->nodeName == tmpAmo) { traceAmoPackage(pChild); }/* else if(pChild->nodeName == tmpAmo) { pActorNode = pChild; pActorInside = true; }*/ } } } void GameSceneLoader::traceWeaponPackage(MSXML::IXMLDOMNodePtr weaponNode) { /* 1200 450 1300 0 1000 20000 */ _bstr_t tmpPosition("position"); _bstr_t tmpType("type"); _bstr_t tmpAmount("amount"); _bstr_t tmpArrivalTime("arrivaltime"); _bstr_t tmpVariation("timevariation"); _bstr_t tmpPhysic("pactor"); _bstr_t tmpRenderer("renderer"); _bstr_t tmpXFile("xfile"); int type = 0; int amo = 0; float arrivalTime = 0; float arrivalVariation = 0; Vector position; MSXML::IXMLDOMNodePtr physicChild; bool hasPActor = false; MSXML::IXMLDOMNodePtr rendererChild; bool hasRenderer = false; std::string xfile; for (MSXML::IXMLDOMNodePtr pChild = weaponNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpAmount) { amo = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpArrivalTime) { arrivalTime = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVariation) { arrivalVariation = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpPhysic) { physicChild = pChild; hasPActor = true; } else if(pChild->nodeName == tmpRenderer) { rendererChild = pChild; hasRenderer = true; } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; } } } //TODO zufallssachen machen, goodie registrieren /*if(position.x = 0 && position.y = 0 && position.z = 0) { //Generate random coodinates float w = this->scene->getWidth(); float y = this->scene->getHeight(); }*/ //Register WeaponPackage in ChallengeManager!! //this->cMgr->registerWeaponPackage(position, type, amo, arrivalTime); //this->scene->registerWeaponPackage(position, type, amo, arrivalTime, arrivalVariation); Goodie* wp; if(!hasRenderer) { wp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, true); } else { wp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, false); this->traceRenderer(rendererChild, *wp); } wp->setXFile(xfile); wp->setPosition(position); wp->setGoodieType(wp->GOODIE_WEAPON); wp->setWeaponType(type); wp->setArmorAmount(amo); wp->setStandBy(true); wp->loadGoodieMesh(); if(hasPActor) { this->tracePActor(physicChild, *wp); wp->setColDetGroup(UserContactReport::COLGROUP_GOODIE); } wp->init(); this->scene->setTrigger(this->scene->TRIGGER_UNSETSTANDBY, wp, this->scene->getRandomTime(arrivalTime, arrivalVariation)); } void GameSceneLoader::traceHealthPackage(MSXML::IXMLDOMNodePtr healthNode) { /* 300 450 900 100 20000 */ _bstr_t tmpPosition("position"); _bstr_t tmpHealth("healthamount"); _bstr_t tmpArrivaltime("arrivaltime"); _bstr_t tmpVariation("timevariation"); _bstr_t tmpPhysic("pactor"); _bstr_t tmpRenderer("renderer"); _bstr_t tmpXFile("xfile"); Vector position; float health = 0; float arrivalTime = 0; float arrivalVariation = 0; MSXML::IXMLDOMNodePtr physicChild; bool hasPActor = false; MSXML::IXMLDOMNodePtr rendererChild; bool hasRenderer = false; std::string xfile = ""; for (MSXML::IXMLDOMNodePtr pChild = healthNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpHealth) { health = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpArrivaltime) { arrivalTime = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVariation) { arrivalVariation = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpPhysic) { physicChild = pChild; hasPActor = true; } else if(pChild->nodeName == tmpRenderer) { rendererChild = pChild; hasRenderer = true; } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; } } } Goodie* hp; if(!hasRenderer) { hp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, true); } else { hp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, false); this->traceRenderer(rendererChild, *hp); } hp->setXFile(xfile); hp->setPosition(position); hp->setGoodieType(hp->GOODIE_HEALTH); hp->setHealthAmount(health); hp->setStandBy(true); hp->loadGoodieMesh(); if(hasPActor) { this->tracePActor(physicChild, *hp); hp->setColDetGroup(UserContactReport::COLGROUP_GOODIE); } //if use phyics //hp->generatePhysicMesh(obj->COL_CONVEX); //hp->setBehaveAs(obj->RIGIDBODY); hp->init(); this->scene->setTrigger(this->scene->TRIGGER_UNSETSTANDBY, hp, this->scene->getRandomTime(arrivalTime, arrivalVariation)); //Register HealthPackage in ChallengeManager!! //TODO this->cMgr->registerHealthPackage(position, health, arrivalTime); //this->scene->registerHealthPackage(position, health, arrivalTime, arrivalVariation); } void GameSceneLoader::traceAmoPackage(MSXML::IXMLDOMNodePtr amoNode) { /* 1300 450 1300 0 1000 20000 */ _bstr_t tmpPosition("position"); _bstr_t tmpType("type"); _bstr_t tmpAmount("amount"); _bstr_t tmpArrivalTime("arrivaltime"); _bstr_t tmpVariation("timevariation"); _bstr_t tmpPhysic("pactor"); _bstr_t tmpRenderer("renderer"); _bstr_t tmpXFile("xfile"); Vector position; int type = 0; int amount = 0; float arrivalTime = 0; float arrivalVariation = 0; MSXML::IXMLDOMNodePtr physicChild; bool hasPActor = false; MSXML::IXMLDOMNodePtr rendererChild; bool hasRenderer = false; std::string xfile = ""; for (MSXML::IXMLDOMNodePtr pChild = amoNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpAmount) { amount = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpArrivalTime) { arrivalTime = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVariation) { arrivalVariation = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpPhysic) { physicChild = pChild; hasPActor = true; } else if(pChild->nodeName == tmpRenderer) { rendererChild = pChild; hasRenderer = true; } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; } } } Goodie* mp; if(!hasRenderer) { mp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, true); } else { mp = (Goodie*) this->scene->createNode(this->scene->NODE_GOODIE, false); this->traceRenderer(rendererChild, *mp); } mp->setXFile(xfile); mp->setPosition(position); mp->setGoodieType(mp->GOODIE_AMO); mp->setWeaponType(type); mp->setArmorAmount(amount); mp->setStandBy(true); mp->loadGoodieMesh(); if(hasPActor) { this->tracePActor(physicChild, *mp); mp->setColDetGroup(UserContactReport::COLGROUP_GOODIE); } mp->init(); this->scene->setTrigger(this->scene->TRIGGER_UNSETSTANDBY, mp, this->scene->getRandomTime(arrivalTime, arrivalVariation)); } void GameSceneLoader::traceHud(MSXML::IXMLDOMNodePtr terrainNode) { _bstr_t tmpCrosshair("crosshair"); _bstr_t tmpCrosshairX("crosshairscaleX"); _bstr_t tmpCrosshairY("crosshairscaleY"); _bstr_t tmpRadar("radar"); _bstr_t tmpRadarX("radarscaleX"); _bstr_t tmpRadarY("radarscaleY"); _bstr_t tmpRadarOffsetX("radaroffsetX"); _bstr_t tmpRadarOffsetY("radaroffsetY"); _bstr_t tmpUserPlayer("userplayerscale"); _bstr_t tmpAIPlayer("aiplayerscale"); _bstr_t tmpTexture0("texture0"); _bstr_t tmpTexture1("texture1"); _bstr_t tmpTexture2("texture2"); _bstr_t tmpTexture3("texture3"); _bstr_t tmpTexture4("texture4"); std::string crosshair; float CrosshairScaleX = 1.0f; float CrosshairScaleY = 1.0f; std::string radar; float RadarScaleX = 1.0f; float RadarScaleY = 1.0f; float RadarOffsetX = 20.0f; float RadarOffsetY = 20.0f; float scaleUserPlayer = 1.0f; float scaleAIPlayer = 1.0f; std::string texture0; std::string texture1; std::string texture2; std::string texture3; std::string texture4; for (MSXML::IXMLDOMNodePtr pChild = terrainNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpCrosshair) { crosshair = pChild->firstChild->text; } else if(pChild->nodeName == tmpCrosshairX) { CrosshairScaleX = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpCrosshairY) { CrosshairScaleY = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRadar) { radar = pChild->firstChild->text; } else if(pChild->nodeName == tmpRadarX) { RadarScaleX = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRadarY) { RadarScaleY = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRadarOffsetX) { RadarOffsetX = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRadarOffsetY) { RadarOffsetY = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpUserPlayer) { scaleUserPlayer = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpAIPlayer) { scaleAIPlayer = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpTexture0) { texture0 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture1) { texture1 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture2) { texture2 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture3) { texture3 = pChild->firstChild->text; } else if(pChild->nodeName == tmpTexture4) { texture4 = pChild->firstChild->text; } } } //instanciate hud HUD *hud = (HUD*) this->scene->createNode(this->scene->NODE_HUD, *this->scene->getRoot(), false); hud->setCrosshair(crosshair, CrosshairScaleX, CrosshairScaleY); hud->setRadar(radar, RadarScaleX, RadarScaleY, RadarOffsetX, RadarOffsetY); hud->setTextures(texture0, texture1, texture2, texture3, texture4, scaleUserPlayer, scaleAIPlayer); hud->generateHUD(); } void GameSceneLoader::tracePActor(MSXML::IXMLDOMNodePtr actorNode, Object3d &obj) { /* 0 0 - NORMAL, 1 - STATIC, 2 - KINEMATIC, 3 - RIGIDBODY 1 0 - MESH, 1 - HEIGHTFIELD, 2 - CONVEX, 3 - PMAP 10.2 index */ _bstr_t tmpColMode("colmode"); _bstr_t tmpBehaveAs("behaveas"); _bstr_t tmpDensity("density"); _bstr_t tmpMaterial("material"); _bstr_t tmpColGroup("colgroup"); int colmode = 0; int behaveas = 0; float density = 10; int material = 0; int colgroup = UserContactReport::COLGROUP_OTHER; for (MSXML::IXMLDOMNodePtr pChild = actorNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpColMode) { colmode = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpBehaveAs) { behaveas = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpDensity) { density = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpMaterial) { material = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpColGroup) { colgroup = atoi(pChild->firstChild->text); } } } NxActorDesc* ad = obj.getActorDescriptor(); ad->density = density; obj.getBodyDescriptor()->mass = 0; obj.generatePhysicMesh(colmode); obj.setBehaveAs(behaveas); obj.setColDetGroup(colgroup); obj.setPMaterial(this->scene->getPhysicMaterialId(material)); } void GameSceneLoader::tracePMaterial(MSXML::IXMLDOMNodePtr materialNode) { /* 0 0.7 0.5 0.5 */ _bstr_t tmpMaterial("materialid"); _bstr_t tmpRestitution("restitution"); _bstr_t tmpStaticFriction("staticfriction"); _bstr_t tmpDynamicFriction("dynamicfriction"); int materialid = 0; float restitution = 0.7f; float staticFriction = 0.5f; float dynamicFriction = 0.5f; for (MSXML::IXMLDOMNodePtr pChild = materialNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpMaterial) { materialid = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpRestitution) { restitution = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpStaticFriction) { staticFriction = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpDynamicFriction) { dynamicFriction = (FLOAT)atof(pChild->firstChild->text); } } } NxMaterialDesc md; md.restitution = restitution; md.staticFriction = staticFriction; md.dynamicFriction = dynamicFriction; NxMaterial* m = this->scene->pScene->createMaterial(md); this->scene->connectMaterialIds(m->getMaterialIndex(), materialid); } void GameSceneLoader::traceRenderer(MSXML::IXMLDOMNodePtr rendererNode, Node &node) { /* 0 0 - RAYTRACE ....other renderer parameter.... */ _bstr_t tmpType("type"); int type = 0; for (MSXML::IXMLDOMNodePtr pChild = rendererNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpType) { type = atoi(pChild->firstChild->text); } } } switch(type) { case 0: //RaytraceRenderer this->traceRaytraceRenderer(rendererNode, node); break; case 1: //ParticleRenderer SPTR renderer(new ParticleRenderer); //ParticleRenderer *r = (ParticleRenderer*) renderer.get(); this->scene->connectNodeAndRenderer(node, renderer); break; } } void GameSceneLoader::traceRaytraceRenderer(MSXML::IXMLDOMNodePtr rendererNode, Node &node) { /* 1.0 0.95 */ _bstr_t tmpFresnel("fresnel"); _bstr_t tmpRefraction("refraction"); _bstr_t tmpIteration("iterations"); float fresnel = 0; float refraction = 0; int nbIteration = 10; for (MSXML::IXMLDOMNodePtr pChild = rendererNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpFresnel) { fresnel = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRefraction) { refraction = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpIteration) { nbIteration = atoi(pChild->firstChild->text); } } } SPTR renderer(new RaytraceRenderer); RaytraceRenderer *r = (RaytraceRenderer*) renderer.get(); r->setFresnelFactor(fresnel); r->setRefractionIndex(refraction); r->setNumberOfIterations(nbIteration); this->scene->connectNodeAndRenderer(node, renderer); } ParticleEmitter* GameSceneLoader::traceParticleEmitter(MSXML::IXMLDOMNodePtr emitterNode) { /* 1000 200 1000); -90 0 0 -20 20 0 600 10 0.2 0.2 0 0 10 100*/ _bstr_t tmpPosition("position"); _bstr_t tmpRotation("rotation"); _bstr_t tmpDimension("dimension"); _bstr_t tmpVelocity("velocity"); _bstr_t tmpDuration("duration"); _bstr_t tmpHDegree("horizontalDegree"); _bstr_t tmpVDegree("verticalDegree"); _bstr_t tmpRDegree("rotationalDegree"); _bstr_t tmpBirthRate("birthRate"); _bstr_t tmpSprite("sprite"); _bstr_t tmpEnvObject("envObject"); _bstr_t tmpTimeToLive("timetolive"); _bstr_t tmpColGroup("colGroup"); _bstr_t tmpRenderer("renderer"); _bstr_t tmpHeatHaze("heathaze"); _bstr_t tmpSound("sound"); _bstr_t tmpGravity("gravity"); bool usingSprites = true; bool addRenderer = false; bool useGravity = true; MSXML::IXMLDOMNodePtr renderNode; float velocity; float duration; float horizontalDegree; float verticalDegree; float birthRate; float timetolive; int colGroup; int heathaze = 0; SoundNode* sound = NULL; Vector position; Vector rotation; Vector dimension; Vector rotationalDegree; std::vector objectVector; std::vector spriteVector; for (MSXML::IXMLDOMNodePtr pChild = emitterNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpRotation) { rotation = tracePosition(pChild); } else if(pChild->nodeName == tmpDimension) { dimension = tracePosition(pChild); } else if(pChild->nodeName == tmpVelocity) { velocity = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpDuration) { duration = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpTimeToLive) { timetolive = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpHDegree) { horizontalDegree = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVDegree) { verticalDegree = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpRDegree) { rotationalDegree = tracePosition(pChild); } else if(pChild->nodeName == tmpBirthRate) { birthRate = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpSprite) { Sprite* sprite = traceSprite(pChild); sprite->generatePhysicMesh(Object3d::COL_CONVEX); usingSprites = true; spriteVector.push_back(sprite); //pe->addRefNode(*sprite); } else if(pChild->nodeName == tmpEnvObject) { Object3d* obj = this->traceEnvironmentObject(pChild); usingSprites = false; objectVector.push_back(obj); //pe->addRefNode(*obj); } else if(pChild->nodeName == tmpColGroup) { colGroup = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpRenderer) { //this->traceRenderer(pChild, *pg);//pChild->firstChild->text); renderNode = pChild; addRenderer = true; } else if(pChild->nodeName == tmpHeatHaze) { heathaze = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpSound) { sound = this->traceSound(pChild->firstChild); } else if(pChild->nodeName == tmpGravity) { useGravity = (atoi(pChild->firstChild->text)==1); } } } ParticleEmitter *pe = (ParticleEmitter*) this->scene->createNode(GameScene::NODE_PARTICLEEMITTER); ParticleGroup *pg; pg = (ParticleGroup*) this->scene->createNode(Scene::NODE_PARTICLEGROUP, usingSprites); SPTR spe = this->scene->getSmartPointer(pe); if(addRenderer) { this->traceRenderer(renderNode, *pg); }/* else if(!usingSprites) { //Standardmaessig haben Object3ds eh einen renderer SPTR renderer(new SimpleMeshRenderer); this->scene->connectNodeAndRenderer(node, renderer); }*/ if(sound) { pe->addEmittingSound(sound); } if(usingSprites) { for(UINT i=0;iaddRefNode(*spriteVector.at(i)); } } else { for(UINT i=0;iaddRefNode(*objectVector.at(i)); } } rotation = rotation*D3DX_PI/180; horizontalDegree*=(D3DX_PI/180); verticalDegree*=(D3DX_PI/180); //rotationalDegree = rotationalDegree*D3DX_PI/180; pe->setUseHeatHaze(heathaze==1); pe->setPosition(position); pe->setRotation(rotation); pe->setDimensions(dimension.x, dimension.y, dimension.z); pe->setEMParticleVelocity(velocity); pe->setEMEmissionDuration(duration); pe->setEMHorizontalDegree(horizontalDegree); pe->setEMVerticalDegree(verticalDegree); pe->setEMRotationalDegree(rotationalDegree.x, rotationalDegree.y, rotationalDegree.z); pe->setEMBirthRate(birthRate); pe->setEMParticleLifeTime(timetolive); pe->setColDetGroup(colGroup); pg->useGravity(useGravity); pg->addParticleEmitter(spe); return pe; } Object3d* GameSceneLoader::traceEnvironmentObject(MSXML::IXMLDOMNodePtr envNode) { /* ... ... asdf.x... 10 5 ... */ _bstr_t tmpPosition("position"); _bstr_t tmpRotation("rotation"); _bstr_t tmpArrivaltime("arrivaltime"); _bstr_t tmpVariation("timevariation"); _bstr_t tmpPhysic("pactor"); _bstr_t tmpRenderer("renderer"); _bstr_t tmpXFile("xfile"); _bstr_t tmpSoftKill("softkill"); Vector position; Vector rotation; float arrivalTime = 0; float arrivalVariation = 0; float softKill=0; MSXML::IXMLDOMNodePtr physicChild; bool hasPActor = false; MSXML::IXMLDOMNodePtr rendererChild; bool hasRenderer = false; std::string xfile = ""; for (MSXML::IXMLDOMNodePtr pChild = envNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpRotation) { rotation = tracePosition(pChild); }else if(pChild->nodeName == tmpArrivaltime) { arrivalTime = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVariation) { arrivalVariation = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpPhysic) { physicChild = pChild; hasPActor = true; } else if(pChild->nodeName == tmpRenderer) { rendererChild = pChild; hasRenderer = true; } else if(pChild->nodeName == tmpXFile) { xfile = pChild->firstChild->text; } else if(pChild->nodeName == tmpSoftKill) { softKill = (FLOAT)atof(pChild->firstChild->text); } } } rotation = rotation*D3DX_PI/180; Object3d* obj = (Object3d*) this->scene->createNode(GameScene::NODE_OBJECT3D, !hasRenderer); if(hasRenderer) { this->traceRenderer(rendererChild, *obj); } obj->setPosition(position); obj->setRotation(rotation); obj->loadMeshFromFile(xfile); if(softKill!=0) { obj->setSoftKill(true, softKill); } if(hasPActor) { this->tracePActor(physicChild, *obj); } if(arrivalTime!=0 /*&& arrivalVariation!=0*/) { obj->setStandBy(true); this->scene->setTrigger(GameScene::TRIGGER_UNSETSTANDBY, obj, this->scene->getRandomTime(arrivalTime, arrivalVariation)); } return obj; } Sprite* GameSceneLoader::traceSprite(MSXML::IXMLDOMNodePtr spriteNode) { /* -50 50 0 ./media/textures/explosion1.bmp 1 */ _bstr_t tmpDimension("dimension"); _bstr_t tmpTexture0("texture0"); _bstr_t tmpLookAtCamera("lookAtCamera"); _bstr_t tmpAnimation("animation"); _bstr_t tmpFps("fps"); _bstr_t tmpFrameCount("framecount"); _bstr_t tmpRowcount("rowcount"); _bstr_t tmpColumncount("columncount"); _bstr_t tmpLoopanimation("loopanimation"); _bstr_t tmpKey1("key_start"); _bstr_t tmpKey2("key_middle"); _bstr_t tmpKey3("key_end"); _bstr_t tmpAlpha("alpha"); _bstr_t tmpRed("red"); _bstr_t tmpGreen("green"); _bstr_t tmpBlue("blue"); _bstr_t tmpWidth("width"); _bstr_t tmpHeight("height"); _bstr_t tmpTime("time"); std::string texture0; int lookAtCamera; Vector dimension; bool hasAnimation = false; int FPS = 1; int FrameCount = 1; int RowCount = 1; int ColumnCount = 1; bool loop = true; bool hasKey1 = false; bool hasKey2 = false; bool hasKey3 = false; float alpha[3] = {0.0f, 0.0f, 0.0f}; float red[3] = {0.0f, 0.0f, 0.0f}; float green[3] = {0.0f, 0.0f, 0.0f}; float blue[3] = {0.0f, 0.0f, 0.0f}; float width[3] = {0.0f, 0.0f, 0.0f}; float height[3] = {0.0f, 0.0f, 0.0f}; float time[3] = {0.0f, 0.0f, 1.0f}; Sprite* sp = (Sprite*) this->scene->createNode(GameScene::NODE_SPRITE); for (MSXML::IXMLDOMNodePtr pChild = spriteNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpDimension) { dimension = tracePosition(pChild); } else if(pChild->nodeName == tmpTexture0) { texture0 = pChild->firstChild->text; } else if(pChild->nodeName == tmpLookAtCamera) { lookAtCamera = atoi(pChild->firstChild->text); } else if(pChild->nodeName == tmpAnimation) { hasAnimation = true; for (MSXML::IXMLDOMNodePtr pChildAnimation = pChild->firstChild;NULL != pChildAnimation;pChildAnimation = pChildAnimation->nextSibling) { if(pChildAnimation->nodeName == tmpFps) { FPS = atoi(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpFrameCount) { FrameCount = atoi(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpRowcount) { RowCount = atoi(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpColumncount) { ColumnCount = atoi(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpFrameCount) { FrameCount = atoi(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpLoopanimation) { if(atoi(pChildAnimation->firstChild->text) != 1) { loop = false; } } } } else if(pChild->nodeName == tmpKey1) { hasKey1 = true; for (MSXML::IXMLDOMNodePtr pChildAnimation = pChild->firstChild;NULL != pChildAnimation;pChildAnimation = pChildAnimation->nextSibling) { if(pChildAnimation->nodeName == tmpAlpha) { alpha[0] = (FLOAT)atof(pChild->firstChild->text); } else if(pChildAnimation->nodeName == tmpRed) { red[0] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpGreen) { green[0] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpBlue) { blue[0] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpWidth) { width[0] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpHeight) { height[0] = (FLOAT)atof(pChildAnimation->firstChild->text); } } } else if(pChild->nodeName == tmpKey2) { hasKey2 = true; for (MSXML::IXMLDOMNodePtr pChildAnimation = pChild->firstChild;NULL != pChildAnimation;pChildAnimation = pChildAnimation->nextSibling) { if(pChildAnimation->nodeName == tmpAlpha) { alpha[1] = (FLOAT)atof(pChild->firstChild->text); } else if(pChildAnimation->nodeName == tmpRed) { red[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpGreen) { green[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpBlue) { blue[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpWidth) { width[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpHeight) { height[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpTime) { time[1] = (FLOAT)atof(pChildAnimation->firstChild->text); } } } else if(pChild->nodeName == tmpKey3) { hasKey3 = true; for (MSXML::IXMLDOMNodePtr pChildAnimation = pChild->firstChild;NULL != pChildAnimation;pChildAnimation = pChildAnimation->nextSibling) { if(pChildAnimation->nodeName == tmpAlpha) { alpha[2] = (FLOAT)atof(pChild->firstChild->text); } else if(pChildAnimation->nodeName == tmpRed) { red[2] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpGreen) { green[2] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpBlue) { blue[2] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpWidth) { width[2] = (FLOAT)atof(pChildAnimation->firstChild->text); } else if(pChildAnimation->nodeName == tmpHeight) { height[2] = (FLOAT)atof(pChildAnimation->firstChild->text); } } } } } sp->setDimension(dimension.x, dimension.y); sp->setTexture(texture0); sp->setLookAtCamera(lookAtCamera==1); if(hasAnimation) { sp->setFPS(FPS); sp->setFrameCount(FrameCount); sp->setRowColumnCount(RowCount, ColumnCount); sp->setLoopAnimation(true); // there's a bug if i set this to false } if(hasKey1 && hasKey2 && hasKey3) { sp->setKeyFrame(Sprite::KEY_START, alpha[0], red[0], green[0], blue[0], width[0], height[0], time[0]); sp->setKeyFrame(Sprite::KEY_MIDDLE, alpha[1], red[1], green[1], blue[1], width[1], height[1], time[1]); sp->setKeyFrame(Sprite::KEY_END, alpha[2], red[2], green[2], blue[2], width[2], height[2], time[2]); } return sp; } SoundNode* GameSceneLoader::traceSound(MSXML::IXMLDOMNodePtr soundNode) { _bstr_t tmpPosition("position"); _bstr_t tmpArrivaltime("arrivaltime"); _bstr_t tmpVariation("timevariation"); _bstr_t tmpSoundfile("soundfile"); _bstr_t tmpSoundVolume("volume"); _bstr_t tmpKillAfterPlayed("killafterplayed"); _bstr_t tmpLoop("loop"); Vector position; float arrivalTime = 0; float arrivalVariation = 0; std::string soundfile; float volume = 1; bool killAfterPlayed; bool loop; for (MSXML::IXMLDOMNodePtr pChild = soundNode->firstChild;NULL != pChild;pChild = pChild->nextSibling) { if(pChild->nodeType == MSXML::NODE_ELEMENT) { if(pChild->nodeName == tmpPosition) { position = tracePosition(pChild); } else if(pChild->nodeName == tmpArrivaltime) { arrivalTime = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpVariation) { arrivalVariation = (FLOAT)atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpSoundfile) { soundfile = pChild->firstChild->text; } else if(pChild->nodeName == tmpSoundVolume) { volume = (FLOAT) atof(pChild->firstChild->text); } else if(pChild->nodeName == tmpKillAfterPlayed) { killAfterPlayed = ((INT)atoi(pChild->firstChild->text)==1); } else if(pChild->nodeName == tmpLoop) { loop = ((INT)atoi(pChild->firstChild->text)==1); } } } SoundNode* sound; sound = (SoundNode*) this->scene->createNode(Scene::NODE_SOUND); sound->loadFile(soundfile, loop); sound->setVolume(volume); sound->setKillSoundNodeAfterPlayed(killAfterPlayed); if(arrivalTime!=0) { sound->setStandBy(true); this->scene->setTrigger(GameScene::TRIGGER_UNSETSTANDBY, sound, this->scene->getRandomTime(arrivalTime, arrivalVariation)); } else { sound->play(); } return sound; }