From 343066040f64aa0a9564b7a68e673001d4887699 Mon Sep 17 00:00:00 2001 From: leper Date: Tue, 1 Jul 2014 19:00:41 +0000 Subject: [PATCH] Remove inconsistent checks for pSimulation2 when saving maps and ensure that it is set. Remove commented out code writing triggers that has nothing to do with the actual triggers implementation. Free memory that was allocated for error reporting when when fork() fails. Remove dead initialization. This was SVN commit r15477. --- source/graphics/MapWriter.cpp | 126 ++---------------- source/graphics/MapWriter.h | 5 +- source/lib/sysdep/os/unix/unix.cpp | 6 +- .../components/CCmpTerritoryInfluence.cpp | 6 +- 4 files changed, 16 insertions(+), 127 deletions(-) diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index c67cbe8bea..b94e4806b2 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -194,10 +194,13 @@ void CMapWriter::WriteXML(const VfsPath& filename, XML_Element("Scenario"); XML_Attribute("version", (int)FILE_VERSION); - if (pSimulation2 && !pSimulation2->GetStartupScript().empty()) + ENSURE(pSimulation2); + CSimulation2& sim = *pSimulation2; + + if (!sim.GetStartupScript().empty()) { XML_Element("Script"); - XML_CDATA(pSimulation2->GetStartupScript().c_str()); + XML_CDATA(sim.GetStartupScript().c_str()); } { @@ -253,7 +256,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, XML_Attribute("g", pWaterMan->m_WaterColor.g); XML_Attribute("b", pWaterMan->m_WaterColor.b); } - CmpPtr cmpWaterManager(*pSimulation2, SYSTEM_ENTITY); + CmpPtr cmpWaterManager(sim, SYSTEM_ENTITY); ENSURE(cmpWaterManager); XML_Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0)); XML_Setting("Waviness", pWaterMan->m_Waviness); @@ -312,9 +315,8 @@ void CMapWriter::WriteXML(const VfsPath& filename, } } - if (pSimulation2) { - std::string settings = pSimulation2->GetMapSettingsString(); + std::string settings = sim.GetMapSettingsString(); if (!settings.empty()) { XML_Element("ScriptSettings"); @@ -325,8 +327,6 @@ void CMapWriter::WriteXML(const VfsPath& filename, { XML_Element("Entities"); - CSimulation2& sim = *pSimulation2; - CmpPtr cmpTemplateManager(sim, SYSTEM_ENTITY); ENSURE(cmpTemplateManager); @@ -455,113 +455,3 @@ void CMapWriter::WriteXML(const VfsPath& filename, if (!XML_StoreVFS(g_VFS, filename)) LOGERROR(L"Failed to write map '%ls'", filename.string().c_str()); } - -/* -void CMapWriter::WriteTriggerGroup(XMLWriter_File& xml_file_, const MapTriggerGroup& group, const std::list& groupList) -{ - XML_Element("Group"); - XML_Attribute("name", group.name); - - for ( std::list::const_iterator it = group.childGroups.begin(); - it != group.childGroups.end(); ++it ) - { - //Not very efficient... - std::list::const_iterator it2 = std::find(groupList.begin(), groupList.end(), *it); - if ( it2 != groupList.end() ) - WriteTriggerGroup(xml_file_, *it2, groupList); - else - debug_warn(L"Invalid trigger group ID while writing map"); - } - - for ( std::list::const_iterator it = group.triggers.begin(); it != group.triggers.end(); ++it ) - { - WriteTrigger(xml_file_, *it); - } -} - -void CMapWriter::WriteTrigger(XMLWriter_File& xml_file_, const MapTrigger& trigger) -{ - XML_Element("Trigger"); - XML_Attribute("name", trigger.name); - - { - if ( trigger.active ) - XML_Setting("Active", "true"); - else - XML_Setting("Active", "false"); - XML_Setting("MaxRunCount", trigger.maxRunCount); - XML_Setting("Delay", trigger.timeValue); - } - - { - XML_Element("Conditions"); - for ( std::list::const_iterator it2 = trigger.conditions.begin(); - it2 != trigger.conditions.end(); ++it2 ) - { - size_t distance = std::distance( trigger.conditions.begin(), it2 ); - std::set::const_iterator logicIter; - - if ( ( logicIter = trigger.logicBlocks.find(MapTriggerLogicBlock(distance)) ) - != trigger.logicBlocks.end() ) - { - XML_Element("LogicBlock"); - if ( logicIter->negated ) - XML_Attribute("not", "true"); - else - XML_Attribute("not", "false"); - } - - { - XML_Element("Condition"); - XML_Attribute("name", it2->name); - - XML_Attribute("function", it2->functionName); - XML_Attribute("display", it2->displayName); - - if ( it2->negated ) - XML_Attribute("not", "true"); - else - XML_Attribute("not", "false"); - - for ( std::list::const_iterator paramIter = it2->parameters.begin(); - paramIter != it2->parameters.end(); ++paramIter ) - { - CStrW paramString(*paramIter); - //paramString.Replace(L"<", L"<"); - //paramString.Replace(L">", L">"); - XML_Setting("Parameter", paramString); - } - if ( it2->linkLogic == 1 ) - XML_Setting("LinkLogic", "AND"); - else if ( it2->linkLogic == 2 ) - XML_Setting("LinkLogic", "OR"); - - if ( trigger.logicBlockEnds.find(distance) != trigger.logicBlockEnds.end() ) - { - XML_Element("LogicBlockEnd"); - } - } - } //Read all conditions - } //Conditions' scope - - { - XML_Element("Effects"); - for ( std::list::const_iterator it2 = trigger.effects.begin(); - it2 != trigger.effects.end(); ++it2 ) - { - XML_Element("Effect"); - XML_Attribute("name", it2->name); - { - XML_Setting("function", it2->functionName); - XML_Setting("display", it2->displayName); - - for ( std::list::const_iterator paramIter = it2->parameters.begin(); - paramIter != it2->parameters.end(); ++paramIter ) - { - XML_Setting("Parameter", *paramIter); - } - } - } - } //Effects' scope -} -*/ diff --git a/source/graphics/MapWriter.h b/source/graphics/MapWriter.h index c66f390208..0b4dc95154 100644 --- a/source/graphics/MapWriter.h +++ b/source/graphics/MapWriter.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -66,9 +66,6 @@ private: SkyManager* pSkyMan, CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema, CPostprocManager* pPostproc, CSimulation2* pSimulation2); -// void WriteTriggerGroup(XMLWriter_File& xml_file_, const MapTriggerGroup& group, -// const std::list& groupList); -// void WriteTrigger(XMLWriter_File& xml_file_, const MapTrigger& trigger); }; #endif diff --git a/source/lib/sysdep/os/unix/unix.cpp b/source/lib/sysdep/os/unix/unix.cpp index aa4883c5f9..58599abc50 100644 --- a/source/lib/sysdep/os/unix/unix.cpp +++ b/source/lib/sysdep/os/unix/unix.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 Wildfire Games +/* Copyright (c) 2014 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -121,7 +121,11 @@ static ErrorReactionInternal try_gui_display_error(const wchar_t* text, bool man pid_t cpid = fork(); if(cpid == -1) + { + for(char* const* a = argv; *a; ++a) + free(*a); return ERI_NOT_IMPLEMENTED; + } if(cpid == 0) { diff --git a/source/simulation2/components/CCmpTerritoryInfluence.cpp b/source/simulation2/components/CCmpTerritoryInfluence.cpp index fdfde74017..90739746ea 100644 --- a/source/simulation2/components/CCmpTerritoryInfluence.cpp +++ b/source/simulation2/components/CCmpTerritoryInfluence.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -101,10 +101,8 @@ public: virtual u32 GetRadius() { - u32 newRadius = m_Radius; - CmpPtr cmpValueModificationManager(GetSystemEntity()); - newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); + u32 newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); return newRadius; }