From 115ef63f573a76d3a7167ff18a2ecbd6a6381e9c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 23 Nov 2011 19:12:06 +0000 Subject: [PATCH] - hardened code for standalone mods --- source/glest_game/global/core_data.cpp | 32 +++--- source/glest_game/main/intro.cpp | 109 +++++++++++++-------- source/glest_game/main/main.cpp | 2 +- source/glest_game/menu/menu_background.cpp | 10 +- 4 files changed, 95 insertions(+), 58 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 9087f381..b19163be 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -269,26 +269,32 @@ void CoreData::load() { loadFonts(); //sounds + clickSoundA.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_a.wav")); + clickSoundB.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_b.wav")); + clickSoundC.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_c.wav")); + attentionSound.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/attention.wav")); + highlightSound.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/highlight.wav")); + XmlTree xmlTree; //string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); xmlTree.load(getGameCustomCoreDataPath(data_path, "data/core/menu/menu.xml"),Properties::getTagReplacementValues()); const XmlNode *menuNode= xmlTree.getRootNode(); - const XmlNode *introNode= menuNode->getChild("intro"); - clickSoundA.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_a.wav")); - clickSoundB.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_b.wav")); - clickSoundC.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/click_c.wav")); - attentionSound.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/attention.wav")); - highlightSound.load(getGameCustomCoreDataPath(data_path, "data/core/menu/sound/highlight.wav")); + string menuMusicPath = "/menu/music/"; + string menuIntroMusicFile = "intro_music.ogg"; + string menuMusicFile = "menu_music.ogg"; - // intro info - const XmlNode *menuPathNode= introNode->getChild("menu-music-path"); - string menuMusicPath = menuPathNode->getAttribute("value")->getRestrictedValue(); - const XmlNode *menuIntroMusicNode= introNode->getChild("menu-intro-music"); - string menuIntroMusicFile = menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); - const XmlNode *menuMusicNode= introNode->getChild("menu-music"); - string menuMusicFile = menuMusicNode->getAttribute("value")->getRestrictedValue(); + if(menuNode->hasChild("intro") == true) { + const XmlNode *introNode= menuNode->getChild("intro"); + // intro info + const XmlNode *menuPathNode= introNode->getChild("menu-music-path"); + menuMusicPath = menuPathNode->getAttribute("value")->getRestrictedValue(); + const XmlNode *menuIntroMusicNode= introNode->getChild("menu-intro-music"); + menuIntroMusicFile = menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); + const XmlNode *menuMusicNode= introNode->getChild("menu-music"); + menuMusicFile = menuMusicNode->getAttribute("value")->getRestrictedValue(); + } introMusic.open(getGameCustomCoreDataPath(data_path, "data/core/" + menuMusicPath + menuIntroMusicFile)); introMusic.setNext(&menuMusic); menuMusic.open(getGameCustomCoreDataPath(data_path, "data/core/" + menuMusicPath + menuMusicFile)); diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index 52cc6452..82d4b15e 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -103,58 +103,87 @@ Intro::Intro(Program *program): renderer.initMenu(NULL); fade= 0.f; anim= 0.f; - - XmlTree xmlTree; - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - xmlTree.load(getGameCustomCoreDataPath(data_path, "data/core/menu/menu.xml"),Properties::getTagReplacementValues()); - const XmlNode *menuNode= xmlTree.getRootNode(); - const XmlNode *introNode= menuNode->getChild("intro"); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); - targetCamera= NULL; t= 0.f; - //camera - const XmlNode *cameraNode= introNode->getChild("camera"); - - //position - const XmlNode *positionNode= cameraNode->getChild("start-position"); - startPosition.x= positionNode->getAttribute("x")->getFloatValue(); - startPosition.y= positionNode->getAttribute("y")->getFloatValue(); - startPosition.z= positionNode->getAttribute("z")->getFloatValue(); + startPosition.x= 5;; + startPosition.y= 10; + startPosition.z= 40; 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(); + startRotation.x= 0; + startRotation.y= 0; + startRotation.z= 0; + camera.setOrientation(Quaternion(EulerAngles( degToRad(startRotation.x), degToRad(startRotation.y), degToRad(startRotation.z)))); - // intro info - const XmlNode *introTimeNode= introNode->getChild("intro-time"); - Intro::introTime = introTimeNode->getAttribute("value")->getIntValue(); - const XmlNode *appearTimeNode= introNode->getChild("appear-time"); - Intro::appearTime = appearTimeNode->getAttribute("value")->getIntValue(); - const XmlNode *showTimeNode= introNode->getChild("show-time"); - Intro::showTime = showTimeNode->getAttribute("value")->getIntValue(); - const XmlNode *disappearTimeNode= introNode->getChild("disappear-time"); - Intro::disapearTime = disappearTimeNode->getAttribute("value")->getIntValue(); - const XmlNode *showIntroPicturesNode= introNode->getChild("show-intro-pictures"); - int showIntroPics = showIntroPicturesNode->getAttribute("value")->getIntValue(); - int showIntroPicsTime = showIntroPicturesNode->getAttribute("time")->getIntValue(); - bool showIntroPicsRandom = showIntroPicturesNode->getAttribute("random")->getBoolValue(); + Intro::introTime = 3000; + Intro::appearTime = 500; + Intro::showTime = 500; + Intro::disapearTime = 500; + int showIntroPics = 0; + int showIntroPicsTime = 0; + bool showIntroPicsRandom = false; + bool showIntroModels = false; + bool showIntroModelsRandom = false; + modelMinAnimSpeed = 0; + modelMaxAnimSpeed = 0; - const XmlNode *showIntroModelsNode= introNode->getChild("show-intro-models"); - bool showIntroModels = showIntroModelsNode->getAttribute("value")->getBoolValue(); - bool showIntroModelsRandom = showIntroModelsNode->getAttribute("random")->getBoolValue(); - modelMinAnimSpeed = showIntroModelsNode->getAttribute("min-anim-speed")->getFloatValue(); - modelMaxAnimSpeed = showIntroModelsNode->getAttribute("max-anim-speed")->getFloatValue(); + XmlTree xmlTree; + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + xmlTree.load(getGameCustomCoreDataPath(data_path, "data/core/menu/menu.xml"),Properties::getTagReplacementValues()); + const XmlNode *menuNode= xmlTree.getRootNode(); + + if(menuNode->hasChild("intro") == true) { + const XmlNode *introNode= menuNode->getChild("intro"); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + + //camera + const XmlNode *cameraNode= introNode->getChild("camera"); + + //position + const XmlNode *positionNode= cameraNode->getChild("start-position"); + 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)))); + + // intro info + const XmlNode *introTimeNode= introNode->getChild("intro-time"); + Intro::introTime = introTimeNode->getAttribute("value")->getIntValue(); + const XmlNode *appearTimeNode= introNode->getChild("appear-time"); + Intro::appearTime = appearTimeNode->getAttribute("value")->getIntValue(); + const XmlNode *showTimeNode= introNode->getChild("show-time"); + Intro::showTime = showTimeNode->getAttribute("value")->getIntValue(); + const XmlNode *disappearTimeNode= introNode->getChild("disappear-time"); + Intro::disapearTime = disappearTimeNode->getAttribute("value")->getIntValue(); + const XmlNode *showIntroPicturesNode= introNode->getChild("show-intro-pictures"); + int showIntroPics = showIntroPicturesNode->getAttribute("value")->getIntValue(); + int showIntroPicsTime = showIntroPicturesNode->getAttribute("time")->getIntValue(); + bool showIntroPicsRandom = showIntroPicturesNode->getAttribute("random")->getBoolValue(); + + const XmlNode *showIntroModelsNode= introNode->getChild("show-intro-models"); + showIntroModels = showIntroModelsNode->getAttribute("value")->getBoolValue(); + showIntroModelsRandom = showIntroModelsNode->getAttribute("random")->getBoolValue(); + modelMinAnimSpeed = showIntroModelsNode->getAttribute("min-anim-speed")->getFloatValue(); + modelMaxAnimSpeed = showIntroModelsNode->getAttribute("max-anim-speed")->getFloatValue(); + } //load main model modelIndex = 0; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 169ba10d..64b2ee2d 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -646,7 +646,7 @@ void handleSIGSEGV(int sig) { printf("%s",szBuf); //abort(); - //ExceptionHandler::handleRuntimeError(szBuf); + ExceptionHandler::handleRuntimeError(szBuf); } #endif diff --git a/source/glest_game/menu/menu_background.cpp b/source/glest_game/menu/menu_background.cpp index 47daa7de..89dcea98 100644 --- a/source/glest_game/menu/menu_background.cpp +++ b/source/glest_game/menu/menu_background.cpp @@ -107,10 +107,12 @@ MenuBackground::MenuBackground(){ //load main model mainModel= renderer.newModel(rsMenu); if(mainModel) { - //mainModel->load(data_path + "data/core/menu/main_model/menu_main.g3d"); - const XmlNode *mainMenuModelNode= menuNode->getChild("menu-background-model"); - string mainModelFile = mainMenuModelNode->getAttribute("value")->getRestrictedValue(); - + 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)); }