bool scene::load (const std::string& Scene) { // try opening scene TiXmlDocument xml_shader(Scene.c_str()); if (!xml_shader.LoadFile()) { log() << error << "couldn't load shader " << Scene << ", is it a valid XML file?" << std::endl; return false; } // start parsing basic shader information std::string scene_name (""); std::string scene_description (""); std::string scene_authors (""); TiXmlNode* network_xml_node = 0; for (TiXmlAttribute* a = xml_shader.FirstChild()->ToElement()->FirstAttribute(); a; a = a->Next()) { // parse attributes const std::string name (a->Name()); if (name == "name") { scene_name = a->Value(); } else if (name == "authors") { scene_authors = a->Value(); } else { log() << error << "unhandled shader attribute : '" << name << "'" << std::endl; } } for (TiXmlNode* c = xml_shader.FirstChild()->FirstChild(); c; c = c->NextSibling()) { // parse child nodes const std::string element (c->Value()); if(element == "about") { if (c->FirstChild()) { scene_description = c->FirstChild()->ToText()->Value(); } } else if(element == "network") { network_xml_node = c; } else { log() << error << "unknown shader element '" << element << "' in " << Scene << std::endl; } } if (!network_xml_node) { log() << error << "no network block found in '" << Scene << "'." << std::endl; return false; } // scene could be loaded, initialize empty_scene(); // start loading content m_name = scene_name; set_description (scene_description); m_authors = scene_authors; log() << aspect << "loading shader '" << m_name << "'" << std::endl; // load blocks for (TiXmlNode* e = network_xml_node->FirstChild(); e; e = e->NextSibling()) { const std::string element (e->Value()); if(element == "block") { xml::attributes_t attributes; xml::get_attributes (*e->ToElement(), attributes); std::string id; if (!xml::get_attribute (*e->ToElement(), "id", id)) { log() << error << "block has undefined 'id' attribute." << std::endl; continue; } bool root_block = false; std::string root_value (""); if (xml::get_attribute (*e->ToElement(), "root", root_value)) { root_block = true; } bool rolled_block = false; std::string rolled_value (""); if (xml::get_attribute (*e->ToElement(), "rolled", rolled_value)) { rolled_block = true; } std::string position_sx; std::string position_sy; xml::get_attribute (*e->ToElement(), "position_x", position_sx); xml::get_attribute (*e->ToElement(), "position_y", position_sy); double position_x = 0; double position_y = 0; std::istringstream stream_x (position_sx.c_str()); stream_x >> position_x; std::istringstream stream_y (position_sy.c_str()); stream_y >> position_y; // create block shader_block* new_block = 0; if (!root_block) { new_block = new shader_block (id, ""); } else { //if (root_value == "RIB") { m_rib_root_block = new rib_root_block (id, this, m_system_functions, preferences); new_block = m_rib_root_block; for (TiXmlNode* c = e->FirstChild(); c; c = c->NextSibling()) { const std::string element (c->Value()); if (element == "rib_statements") { if (c->FirstChild()) { const std::string statements = c->FirstChild()->ToText()->Value(); m_rib_root_block->set_general_statements (trim (statements) + "\n"); } } else if (element == "imager_statement") { if (c->FirstChild()) { const std::string statement = c->FirstChild()->ToText()->Value(); m_rib_root_block->set_imager_statement (trim (statement)); } } /* else if (element == "AOV_preview") { if (c->FirstChild()) { const std::string AOV_preview = a->Value(); m_rib_root_block->set_AOV (!state.empty()); } } */ } //} } add_block (id, "", new_block); new_block->set_name (id); new_block->set_position (position_x, position_y); if (rolled_block) { set_block_rolled_state (new_block, true); } // load input and output properties if (!root_block) { new_block->load_from_xml (*e); } } else if (element == "group") {
void UserSettings::save() { //initInputCodeMap(); TiXmlDocument doc; { TiXmlElement xml_version("Version"); { xml_version.SetAttribute("settingsVersion", VERSION_USERSETTINGS); } doc.InsertEndChild(xml_version); TiXmlElement xml_system("System"); { TiXmlElement xml_debugLog("DebugLog"); { xml_debugLog.SetAttribute("on", system.debugLogOn); } xml_system.InsertEndChild(xml_debugLog); TiXmlElement xml_locale("Locale"); { xml_locale.SetAttribute("name", system.locale); } xml_system.InsertEndChild(xml_locale); } doc.InsertEndChild(xml_system); TiXmlElement xml_audio("Audio"); { TiXmlElement xml_microphone("Mic"); { xml_microphone.SetAttribute("on", audio.micOn); xml_microphone.SetAttribute("octave", audio.octave); } xml_audio.InsertEndChild(xml_microphone); TiXmlElement xml_volume("Volume"); { xml_volume.SetDoubleAttribute("sfx", double(audio.sfxvol)); xml_volume.SetDoubleAttribute("vox", double(audio.voxvol)); xml_volume.SetDoubleAttribute("mus", double(audio.musvol)); xml_volume.SetAttribute("subs", audio.subtitles); } xml_audio.InsertEndChild(xml_volume); TiXmlElement xml_device("Device"); { xml_device.SetAttribute("name", audio.deviceName); } xml_audio.InsertEndChild(xml_device); TiXmlElement xml_prebuf("Prebuffer"); { xml_prebuf.SetAttribute("on", audio.prebuffer); } xml_audio.InsertEndChild(xml_prebuf); } doc.InsertEndChild(xml_audio); TiXmlElement xml_video("Video"); { TiXmlElement xml_shader("Shader"); { xml_shader.SetAttribute("num", video.shader); } xml_video.InsertEndChild(xml_shader); TiXmlElement xml_blur("Blur"); { xml_blur.SetAttribute("on", video.blur); } xml_video.InsertEndChild(xml_blur); TiXmlElement xml_noteEffects("NoteEffects"); { xml_noteEffects.SetAttribute("on", video.noteEffects); } xml_video.InsertEndChild(xml_noteEffects); TiXmlElement xml_fpsSmoothing("FpsSmoothing"); { xml_fpsSmoothing.SetAttribute("v", video.fpsSmoothing); } xml_video.InsertEndChild(xml_fpsSmoothing); TiXmlElement xml_parallax("Parallax"); std::ostringstream os; os << video.parallaxOn0 << " " << video.parallaxOn1 << " " << video.parallaxOn2; xml_parallax.SetAttribute("on", os.str()); xml_video.InsertEndChild(xml_parallax); TiXmlElement xml_numParticles("NumParticles"); xml_numParticles.SetAttribute("v", video.numParticles); xml_video.InsertEndChild(xml_numParticles); TiXmlElement xml_screenMode("ScreenMode"); { xml_screenMode.SetAttribute("resx", video.resx); xml_screenMode.SetAttribute("resy", video.resy); xml_screenMode.SetAttribute("bits", video.bits); xml_screenMode.SetAttribute("fbuffer", video.fbuffer); xml_screenMode.SetAttribute("full", video.full); xml_screenMode.SetAttribute("vsync", video.vsync); xml_screenMode.SetAttribute("darkfbuffer", video.darkfbuffer); xml_screenMode.SetAttribute("darkbuffersize", video.darkbuffersize); xml_screenMode.SetAttribute("displaylists", video.displaylists); } xml_video.InsertEndChild(xml_screenMode); TiXmlElement xml_saveSlotScreens("SaveSlotScreens"); { xml_saveSlotScreens.SetAttribute("on", video.saveSlotScreens); } xml_video.InsertEndChild(xml_saveSlotScreens); TiXmlElement xml_worldMap("WorldMap"); { xml_worldMap.SetAttribute("revealMethod", video.worldMapRevealMethod); } xml_video.InsertEndChild(xml_worldMap); } doc.InsertEndChild(xml_video); TiXmlElement xml_control("Control"); { TiXmlElement xml_toolTipsOn("ToolTipsOn"); { xml_toolTipsOn.SetAttribute("on", control.toolTipsOn); } xml_control.InsertEndChild(xml_toolTipsOn); TiXmlElement xml_joystickEnabled("JoystickEnabled"); { xml_joystickEnabled.SetAttribute("on", control.joystickEnabled); } xml_control.InsertEndChild(xml_joystickEnabled); TiXmlElement xml_autoAim("AutoAim"); { xml_autoAim.SetAttribute("on", control.autoAim); } xml_control.InsertEndChild(xml_autoAim); TiXmlElement xml_targeting("Targeting"); { xml_targeting.SetAttribute("on", control.targeting); } xml_control.InsertEndChild(xml_targeting); TiXmlElement xml_joyCursorSpeed("JoyCursorSpeed"); { xml_joyCursorSpeed.SetDoubleAttribute("v", double(control.joyCursorSpeed)); } xml_control.InsertEndChild(xml_joyCursorSpeed); TiXmlElement xml_joyAxes("JoyAxes"); { xml_joyAxes.SetAttribute("s1ax", control.s1ax); xml_joyAxes.SetAttribute("s1ay", control.s1ay); xml_joyAxes.SetAttribute("s2ax", control.s2ax); xml_joyAxes.SetAttribute("s2ay", control.s2ay); xml_joyAxes.SetDoubleAttribute("s1dead", double(control.s1dead)); xml_joyAxes.SetDoubleAttribute("s2dead", double(control.s2dead)); } xml_control.InsertEndChild(xml_joyAxes); TiXmlElement xml_actionSet("ActionSet"); { for (int i = 0; i < control.actionSet.inputSet.size(); i++) { TiXmlElement xml_action("Action"); ActionInput *actionInput = &control.actionSet.inputSet[i]; xml_action.SetAttribute("name", actionInput->name); xml_action.SetAttribute("input", actionInput->toString()); xml_actionSet.InsertEndChild(xml_action); } } xml_control.InsertEndChild(xml_actionSet); } doc.InsertEndChild(xml_control); TiXmlElement xml_demo("Demo"); { TiXmlElement xml_warpKeys("WarpKeys"); { xml_warpKeys.SetAttribute("on", demo.warpKeys); } xml_demo.InsertEndChild(xml_warpKeys); TiXmlElement xml_intro("Intro2"); { xml_intro.SetAttribute("on", demo.intro); } xml_demo.InsertEndChild(xml_intro); TiXmlElement xml_shortLogos("ShortLogos"); { xml_shortLogos.SetAttribute("on", demo.shortLogos); } xml_demo.InsertEndChild(xml_shortLogos); } doc.InsertEndChild(xml_demo); TiXmlElement xml_data("Data"); { xml_data.SetAttribute("savePage", data.savePage); xml_data.SetAttribute("saveSlot", data.saveSlot); std::ostringstream ss; for (std::set<std::string>::iterator it = dsq->activePatches.begin(); it != dsq->activePatches.end(); ++it) ss << *it << " "; xml_data.SetAttribute("activePatches", ss.str()); } doc.InsertEndChild(xml_data); TiXmlElement xml_net("Network"); { xml_net.SetAttribute("masterServer", network.masterServer); } doc.InsertEndChild(xml_net); } #if defined(BBGE_BUILD_UNIX) doc.SaveFile(dsq->getPreferencesFolder() + "/" + userSettingsFilename); #elif defined(BBGE_BUILD_WINDOWS) doc.SaveFile(userSettingsFilename); #endif //clearInputCodeMap(); }