Index: ps/trunk/source/graphics/MapWriter.cpp =================================================================== --- ps/trunk/source/graphics/MapWriter.cpp +++ ps/trunk/source/graphics/MapWriter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -189,124 +189,121 @@ CPostprocManager* pPostproc, CSimulation2* pSimulation2) { - XML_Start(); - + XMLWriter_File xmlMapFile; { - XML_Element("Scenario"); - XML_Attribute("version", (int)FILE_VERSION); + XMLWriter_Element scenarioTag(xmlMapFile, "Scenario"); + scenarioTag.Attribute("version", static_cast(FILE_VERSION)); ENSURE(pSimulation2); CSimulation2& sim = *pSimulation2; if (!sim.GetStartupScript().empty()) { - XML_Element("Script"); - XML_CDATA(sim.GetStartupScript().c_str()); + XMLWriter_Element scriptTag(xmlMapFile, "Script"); + scriptTag.Text(sim.GetStartupScript().c_str(), true); } { - XML_Element("Environment"); - - XML_Setting("SkySet", pSkyMan->GetSkySet()); + XMLWriter_Element environmentTag(xmlMapFile, "Environment"); + environmentTag.Setting("SkySet", pSkyMan->GetSkySet()); { - XML_Element("SunColor"); - XML_Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z... - XML_Attribute("g", pLightEnv->m_SunColor.Y); - XML_Attribute("b", pLightEnv->m_SunColor.Z); + XMLWriter_Element sunColorTag(xmlMapFile, "SunColor"); + sunColorTag.Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z... + sunColorTag.Attribute("g", pLightEnv->m_SunColor.Y); + sunColorTag.Attribute("b", pLightEnv->m_SunColor.Z); } { - XML_Element("SunElevation"); - XML_Attribute("angle", pLightEnv->m_Elevation); + XMLWriter_Element SunElevationTag(xmlMapFile, "SunElevation"); + SunElevationTag.Attribute("angle", pLightEnv->m_Elevation); } { - XML_Element("SunRotation"); - XML_Attribute("angle", pLightEnv->m_Rotation); + XMLWriter_Element sunRotationTag(xmlMapFile, "SunRotation"); + sunRotationTag.Attribute("angle", pLightEnv->m_Rotation); } { - XML_Element("TerrainAmbientColor"); - XML_Attribute("r", pLightEnv->m_TerrainAmbientColor.X); - XML_Attribute("g", pLightEnv->m_TerrainAmbientColor.Y); - XML_Attribute("b", pLightEnv->m_TerrainAmbientColor.Z); + XMLWriter_Element terrainAmbientColorTag(xmlMapFile, "TerrainAmbientColor"); + terrainAmbientColorTag.Attribute("r", pLightEnv->m_TerrainAmbientColor.X); + terrainAmbientColorTag.Attribute("g", pLightEnv->m_TerrainAmbientColor.Y); + terrainAmbientColorTag.Attribute("b", pLightEnv->m_TerrainAmbientColor.Z); } { - XML_Element("UnitsAmbientColor"); - XML_Attribute("r", pLightEnv->m_UnitsAmbientColor.X); - XML_Attribute("g", pLightEnv->m_UnitsAmbientColor.Y); - XML_Attribute("b", pLightEnv->m_UnitsAmbientColor.Z); + XMLWriter_Element unitsAmbientColorTag(xmlMapFile, "UnitsAmbientColor"); + unitsAmbientColorTag.Attribute("r", pLightEnv->m_UnitsAmbientColor.X); + unitsAmbientColorTag.Attribute("g", pLightEnv->m_UnitsAmbientColor.Y); + unitsAmbientColorTag.Attribute("b", pLightEnv->m_UnitsAmbientColor.Z); } { - XML_Element("Fog"); - XML_Setting("FogFactor", pLightEnv->m_FogFactor); - XML_Setting("FogThickness", pLightEnv->m_FogMax); + XMLWriter_Element fogTag(xmlMapFile, "Fog"); + fogTag.Setting("FogFactor", pLightEnv->m_FogFactor); + fogTag.Setting("FogThickness", pLightEnv->m_FogMax); { - XML_Element("FogColor"); - XML_Attribute("r", pLightEnv->m_FogColor.X); - XML_Attribute("g", pLightEnv->m_FogColor.Y); - XML_Attribute("b", pLightEnv->m_FogColor.Z); + XMLWriter_Element fogColorTag(xmlMapFile, "FogColor"); + fogColorTag.Attribute("r", pLightEnv->m_FogColor.X); + fogColorTag.Attribute("g", pLightEnv->m_FogColor.Y); + fogColorTag.Attribute("b", pLightEnv->m_FogColor.Z); } } { - XML_Element("Water"); + XMLWriter_Element waterTag(xmlMapFile, "Water"); { - XML_Element("WaterBody"); + XMLWriter_Element waterBodyTag(xmlMapFile, "WaterBody"); CmpPtr cmpWaterManager(sim, SYSTEM_ENTITY); ENSURE(cmpWaterManager); - XML_Setting("Type", pWaterMan->m_WaterType); + waterBodyTag.Setting("Type", pWaterMan->m_WaterType); { - XML_Element("Color"); - XML_Attribute("r", pWaterMan->m_WaterColor.r); - XML_Attribute("g", pWaterMan->m_WaterColor.g); - XML_Attribute("b", pWaterMan->m_WaterColor.b); + XMLWriter_Element colorTag(xmlMapFile, "Color"); + colorTag.Attribute("r", pWaterMan->m_WaterColor.r); + colorTag.Attribute("g", pWaterMan->m_WaterColor.g); + colorTag.Attribute("b", pWaterMan->m_WaterColor.b); } { - XML_Element("Tint"); - XML_Attribute("r", pWaterMan->m_WaterTint.r); - XML_Attribute("g", pWaterMan->m_WaterTint.g); - XML_Attribute("b", pWaterMan->m_WaterTint.b); + XMLWriter_Element tintTag(xmlMapFile, "Tint"); + tintTag.Attribute("r", pWaterMan->m_WaterTint.r); + tintTag.Attribute("g", pWaterMan->m_WaterTint.g); + tintTag.Attribute("b", pWaterMan->m_WaterTint.b); } - XML_Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0)); - XML_Setting("Waviness", pWaterMan->m_Waviness); - XML_Setting("Murkiness", pWaterMan->m_Murkiness); - XML_Setting("WindAngle", pWaterMan->m_WindAngle); + waterBodyTag.Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0)); + waterBodyTag.Setting("Waviness", pWaterMan->m_Waviness); + waterBodyTag.Setting("Murkiness", pWaterMan->m_Murkiness); + waterBodyTag.Setting("WindAngle", pWaterMan->m_WindAngle); } } { - XML_Element("Postproc"); + XMLWriter_Element postProcTag(xmlMapFile, "Postproc"); { - XML_Setting("Brightness", pLightEnv->m_Brightness); - XML_Setting("Contrast", pLightEnv->m_Contrast); - XML_Setting("Saturation", pLightEnv->m_Saturation); - XML_Setting("Bloom", pLightEnv->m_Bloom); - XML_Setting("PostEffect", pPostproc->GetPostEffect()); + postProcTag.Setting("Brightness", pLightEnv->m_Brightness); + postProcTag.Setting("Contrast", pLightEnv->m_Contrast); + postProcTag.Setting("Saturation", pLightEnv->m_Saturation); + postProcTag.Setting("Bloom", pLightEnv->m_Bloom); + postProcTag.Setting("PostEffect", pPostproc->GetPostEffect()); } } } { - XML_Element("Camera"); - + XMLWriter_Element cameraTag(xmlMapFile, "Camera"); { - XML_Element("Position"); + XMLWriter_Element positionTag(xmlMapFile, "Position"); CVector3D pos = pCamera->m_Orientation.GetTranslation(); - XML_Attribute("x", pos.X); - XML_Attribute("y", pos.Y); - XML_Attribute("z", pos.Z); + positionTag.Attribute("x", pos.X); + positionTag.Attribute("y", pos.Y); + positionTag.Attribute("z", pos.Z); } CVector3D in = pCamera->m_Orientation.GetIn(); // Convert to spherical coordinates float rotation = atan2(in.X, in.Z); - float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - (float)M_PI/2; + float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - static_cast(M_PI / 2); { - XML_Element("Rotation"); - XML_Attribute("angle", rotation); + XMLWriter_Element rotationTag(xmlMapFile, "Rotation"); + rotationTag.Attribute("angle", rotation); } { - XML_Element("Declination"); - XML_Attribute("angle", declination); + XMLWriter_Element declinationTag(xmlMapFile, "Declination"); + declinationTag.Attribute("angle", declination); } } @@ -314,14 +311,13 @@ std::string settings = sim.GetMapSettingsString(); if (!settings.empty()) { - XML_Element("ScriptSettings"); - XML_CDATA(("\n" + settings + "\n").c_str()); + XMLWriter_Element scriptSettingsTag(xmlMapFile, "ScriptSettings"); + scriptSettingsTag.Text(("\n" + settings + "\n").c_str(), true); } } { - XML_Element("Entities"); - + XMLWriter_Element entitiesTag(xmlMapFile, "Entities"); CmpPtr cmpTemplateManager(sim, SYSTEM_ENTITY); ENSURE(cmpTemplateManager); @@ -336,14 +332,14 @@ if (ENTITY_IS_LOCAL(ent)) continue; - XML_Element("Entity"); - XML_Attribute("uid", ent); + XMLWriter_Element entityTag(xmlMapFile, "Entity"); + entityTag.Attribute("uid", ent); - XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent)); + entityTag.Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent)); CmpPtr cmpOwnership(sim, ent); if (cmpOwnership) - XML_Setting("Player", (int)cmpOwnership->GetOwner()); + entityTag.Setting("Player", static_cast(cmpOwnership->GetOwner())); CmpPtr cmpPosition(sim, ent); if (cmpPosition) @@ -354,14 +350,14 @@ CFixedVector3D rot = cmpPosition->GetRotation(); { - XML_Element("Position"); - XML_Attribute("x", pos.X); - XML_Attribute("z", pos.Z); + XMLWriter_Element positionTag(xmlMapFile, "Position"); + positionTag.Attribute("x", pos.X); + positionTag.Attribute("z", pos.Z); // TODO: height offset etc } { - XML_Element("Orientation"); - XML_Attribute("y", rot.Y); + XMLWriter_Element orientationTag(xmlMapFile, "Orientation"); + orientationTag.Attribute("y", rot.Y); // TODO: X, Z maybe } } @@ -379,22 +375,22 @@ // Don't waste space writing the default control groups. if (group != ent || group2 != INVALID_ENTITY) { - XML_Element("Obstruction"); + XMLWriter_Element obstructionTag(xmlMapFile, "Obstruction"); if (group != ent) - XML_Attribute("group", group); + obstructionTag.Attribute("group", group); if (group2 != INVALID_ENTITY) - XML_Attribute("group2", group2); + obstructionTag.Attribute("group2", group2); } } CmpPtr cmpVisual(sim, ent); if (cmpVisual) { - u32 seed = cmpVisual->GetActorSeed(); - if (seed != (u32)ent) + entity_id_t seed = static_cast(cmpVisual->GetActorSeed()); + if (seed != ent) { - XML_Element("Actor"); - XML_Attribute("seed", seed); + XMLWriter_Element actorTag(xmlMapFile, "Actor"); + actorTag.Attribute("seed",seed); } // TODO: variation/selection strings } @@ -407,7 +403,7 @@ { const std::map& paths = cmpCinemaManager->GetPaths(); std::map::const_iterator it = paths.begin(); - XML_Element("Paths"); + XMLWriter_Element pathsTag(xmlMapFile, "Paths"); for ( ; it != paths.end(); ++it ) { @@ -416,12 +412,12 @@ const std::vector& target_nodes = it->second.GetTargetSpline().GetAllNodes(); const CCinemaData* data = it->second.GetData(); - XML_Element("Path"); - XML_Attribute("name", data->m_Name); - XML_Attribute("timescale", timescale); - XML_Attribute("orientation", data->m_Orientation); - XML_Attribute("mode", data->m_Mode); - XML_Attribute("style", data->m_Style); + XMLWriter_Element pathTag(xmlMapFile, "Path"); + pathTag.Attribute("name", data->m_Name); + pathTag.Attribute("timescale", timescale); + pathTag.Attribute("orientation", data->m_Orientation); + pathTag.Attribute("mode", data->m_Mode); + pathTag.Attribute("style", data->m_Style); struct SEvent { @@ -460,23 +456,23 @@ std::sort(events.begin(), events.end()); for (size_t i = 0; i < events.size();) { - XML_Element("Node"); + XMLWriter_Element nodeTag(xmlMapFile, "Node"); fixed deltatime = i > 0 ? (events[i].time - events[i - 1].time) : fixed::Zero(); - XML_Attribute("deltatime", deltatime); + nodeTag.Attribute("deltatime", deltatime); size_t j = i; for (; j < events.size() && events[j].time == events[i].time; ++j) { // Types: Position/Rotation/Target - XML_Element(events[j].type); - XML_Attribute("x", events[j].value.X); - XML_Attribute("y", events[j].value.Y); - XML_Attribute("z", events[j].value.Z); + XMLWriter_Element eventTypeTag(xmlMapFile, events[j].type); + eventTypeTag.Attribute("x", events[j].value.X); + eventTypeTag.Attribute("y", events[j].value.Y); + eventTypeTag.Attribute("z", events[j].value.Z); } i = j; } } } } - if (!XML_StoreVFS(g_VFS, filename)) + if (!xmlMapFile.StoreVFS(g_VFS, filename)) LOGERROR("Failed to write map '%s'", filename.string8()); } Index: ps/trunk/source/graphics/ShaderManager.cpp =================================================================== --- ps/trunk/source/graphics/ShaderManager.cpp +++ ps/trunk/source/graphics/ShaderManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -128,10 +128,10 @@ TIMER_ACCRUE(tc_ShaderValidation); // Serialize the XMB data and pass it to the validator - XML_Start(); - XML_SetPrettyPrint(false); - XML_WriteXMB(XeroFile); - bool ok = CXeromyces::ValidateEncoded("shader", wstring_from_utf8(name), XML_GetOutput()); + XMLWriter_File shaderFile; + shaderFile.SetPrettyPrint(false); + shaderFile.XMB(XeroFile); + bool ok = CXeromyces::ValidateEncoded("shader", wstring_from_utf8(name), shaderFile.GetOutput()); if (!ok) return false; } Index: ps/trunk/source/ps/XML/XMLWriter.h =================================================================== --- ps/trunk/source/ps/XML/XMLWriter.h +++ ps/trunk/source/ps/XML/XMLWriter.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,88 +19,47 @@ #define INCLUDED_XMLWRITER /* - -System for writing simple XML files, with human-readable formatting. - -Example usage: - - XML_Start(); - - { - XML_Element("Scenario"); - { - XML_Element("Entities"); - for (...) - { - XML_Element("Entity"); - - { - XML_Element("Template"); - XML_Text(entity.name); - } - // Or equivalently: - XML_Setting("Template", entity.name); - - { - XML_Element("Position"); - XML_Attribute("x", entity.x); - XML_Attribute("y", entity.y); - XML_Attribute("z", entity.z); - } - - { - XML_Element("Orientation"); - XML_Attribute("angle", entity.angle); - } - } - } - } - - Handle h = vfs_open("/test.xml", FILE_WRITE|FILE_NO_AIO); - XML_StoreVFS(h); - -In general, "{ XML_Element(name); ... }" means " ... " -- the -scoping braces are important to indicate where an element ends. - -XML_Attribute/XML_Setting are templated. To support more types, alter the -end of XMLWriter.cpp. - -*/ - -// Starts generating a new XML file. -#define XML_Start() XMLWriter_File xml_file_ - -// Set pretty printing (newlines, tabs). Defaults to true. -#define XML_SetPrettyPrint(enabled) xml_file_.SetPrettyPrint(false) - -// Add a comment to the XML file: -#define XML_Comment(text) xml_file_.Comment(text) - -// Start a new element: -#define XML_Element(name) XMLWriter_Element xml_element_ (xml_file_, name) - -// Add text to the interior of the current element: <...>text -#define XML_Text(text) xml_element_.Text(text, false) - -// Add CDATA-escaped text to the interior of the current element: <...> -#define XML_CDATA(text) xml_element_.Text(text, true) - -// Add an attribute to the current element: <... name="value" ...> -#define XML_Attribute(name, value) xml_element_.Attribute(name, value) - -// Add a 'setting': value -#define XML_Setting(name, value) xml_element_.Setting(name, value) - -#define XML_WriteXMB(xero) xml_file_.XMB(xero) - -// Create a VFS file from the XML data. -// Returns true on success, false (and logs an error) on failure. -#define XML_StoreVFS(vfs, pathname) xml_file_.StoreVFS(vfs, pathname) - -// Returns the contents of the XML file as a UTF-8 byte stream in a const CStr& -// string. (Use CStr::FromUTF8 to get a Unicode string back.) -#define XML_GetOutput() xml_file_.GetOutput() - + * + *System for writing simple XML files, with human-readable formatting. + * + *Example usage: + * + * XMLWriter_File exampleFile; + * { + * XMLWriter_Element scenarioTag (exampleFile,"Scenario"); + * { + * XMLWriter_Element entitiesTag (exampleFile,"Entities"); + * for (...) + * { + * XMLWriter_Element entityTag (exampleFile,"Entity"); + * { + * XMLWriter_Element templateTag (exampleFile,"Template"); + * templateTag.Text(entity.name); + * } + * // Or equivalently: + * templateTag.Setting("Template", entity.name); + * { + * XMLWriter_Element positionTag (exampleFile,"Position"); + * positionTag.Attribute("x", entity.x); + * positionTag.Attribute("y", entity.y); + * positionTag.Attribute("z", entity.z); + * } + * { + * XMLWriter_Element orientationTag (exampleFile,"Orientation"); + * orientationTag.Attribute("angle", entity.angle); + * } + * } + * } + * } + * exampleFile.StoreVFS(g_VFS, "/test.xml"); + * + * In general, "{ XML_Element(name); ... }" means " ... " -- the + * scoping braces are important to indicate where an element ends. If you don't put + * them the tag won't be closed until the object's destructor is called, usually + * when it goes out of scope. + * xml_element_.Attribute/xml_element_.Setting are templated. To support more types, alter the + * end of XMLWriter.cpp. + */ #include "ps/CStr.h" #include "lib/file/vfs/vfs.h" Index: ps/trunk/source/ps/XML/tests/test_XMLWriter.h =================================================================== --- ps/trunk/source/ps/XML/tests/test_XMLWriter.h +++ ps/trunk/source/ps/XML/tests/test_XMLWriter.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,42 +24,41 @@ public: void test1() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Root"); + XMLWriter_Element rootTag(testFile, "Root"); { - XML_Comment("Comment test."); - XML_Comment("Comment test again."); + testFile.Comment("Comment test."); + testFile.Comment("Comment test again."); { - XML_Element("a"); - XML_Attribute("one", 1); - XML_Attribute("two", "TWO"); - XML_Text("b"); - XML_Text(" (etc)"); + XMLWriter_Element testTag1(testFile, "a"); + testTag1.Attribute("one", 1); + testTag1.Attribute("two", "TWO"); + testTag1.Text("b", false); + testTag1.Text(" (etc)", false); } { - XML_Element("c"); - XML_Text("d"); + XMLWriter_Element testTag2(testFile, "c"); + testTag2.Text("d", false); } - XML_Setting("c2", "d2"); + rootTag.Setting("c2", "d2"); { - XML_Element("e"); + XMLWriter_Element testTag3(testFile, "e"); { { - XML_Element("f"); - XML_Text("g"); + XMLWriter_Element testTag4(testFile, "f"); + testTag4.Text("g", false); } { - XML_Element("h"); + XMLWriter_Element testTag5(testFile, "h"); } { - XML_Element("i"); - XML_Attribute("j", 1.23); + XMLWriter_Element testTag6(testFile, "i"); + testTag6.Attribute("j", 1.23); { - XML_Element("k"); - XML_Attribute("l", 2.34); - XML_Text("m"); + XMLWriter_Element testTag7(testFile, "k"); + testTag7.Attribute("l", 2.34); + testTag7.Text("m", false); } } } @@ -67,7 +66,7 @@ } } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" @@ -85,25 +84,24 @@ "\t\t\n" "\t\n" "" - ); + ); } void test_basic() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); + XMLWriter_Element testTag1(testFile, "Test"); { - XML_Element("example"); + XMLWriter_Element testTag2(testFile, "example"); { - XML_Element("content"); - XML_Text("text"); + XMLWriter_Element testTag3(testFile, "content"); + testTag3.Text("text", false); } } } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" @@ -112,133 +110,126 @@ "\t\ttext\n" "\t\n" "" - ); + ); } void test_nonpretty() { - XML_Start(); - XML_SetPrettyPrint(false); - + XMLWriter_File testFile; + testFile.SetPrettyPrint(false); { - XML_Element("Test"); + XMLWriter_Element testTag1(testFile, "Test"); { - XML_Element("example"); + XMLWriter_Element testTag2(testFile, "example"); { - XML_Element("content"); - XML_Text("text"); + XMLWriter_Element testTag3(testFile, "content"); + testTag3.Text("text", false); } } } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "text" - ); + ); } void test_text() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); - XML_Text("a"); - XML_Text("b"); + XMLWriter_Element rootTag(testFile, "Test"); + rootTag.Text("a", false); + rootTag.Text("b", false); } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" "ab" - ); + ); } void test_utf8() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); + XMLWriter_Element rootTag(testFile, "Test"); { const wchar_t text[] = { 0x0251, 0 }; - XML_Text(text); + rootTag.Text(text, false); } } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "\xC9\x91" - ); + ); } void test_attr_escape() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); - XML_Attribute("example", "abc > ]]> < & \"\" "); + XMLWriter_Element rootTag(testFile, "Test"); + rootTag.Attribute("example", "abc > ]]> < & \"\" "); } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" " ]]> < & "" \"/>" - ); + ); } void test_chardata_escape() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); - XML_Text("abc > ]]> < & \"\" "); + XMLWriter_Element rootTag(testFile, "Test"); + rootTag.Text("abc > ]]> < & \"\" ", false); } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "abc > ]]> < & \"\" " - ); + ); } void test_cdata_escape() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); - XML_CDATA("abc > ]]> < & \"\" "); + XMLWriter_Element rootTag(testFile, "Test"); + rootTag.Text("abc > ]]> < & \"\" ", true); } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" " ]]>]]>" - ); + ); } void test_comment_escape() { - XML_Start(); - + XMLWriter_File testFile; { - XML_Element("Test"); - XML_Comment("test - -- --- ---- test"); + XMLWriter_Element rootTag(testFile, "Test"); + testFile.Comment("test - -- --- ---- test"); } - CStr output = XML_GetOutput(); + CStr output = testFile.GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "\n" "\t\n" "" - ); + ); } }; Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -254,21 +254,21 @@ CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpTemplateManager); - XML_Start(); + XMLWriter_File exampleFile; { - XML_Element("Entities"); + XMLWriter_Element entitiesTag(exampleFile, "Entities"); { for (entity_id_t id : ids) { - XML_Element("Entity"); + XMLWriter_Element entityTag(exampleFile, "Entity"); { //Template name - XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id)); + entityTag.Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id)); //Player CmpPtr cmpOwnership(*g_Game->GetSimulation2(), id); if (cmpOwnership) - XML_Setting("Player", (int)cmpOwnership->GetOwner()); + entityTag.Setting("Player", static_cast(cmpOwnership->GetOwner())); //Adding position to make some relative position later CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); @@ -277,29 +277,28 @@ CFixedVector3D pos = cmpPosition->GetPosition(); CFixedVector3D rot = cmpPosition->GetRotation(); { - XML_Element("Position"); - XML_Attribute("x", pos.X); - XML_Attribute("z", pos.Z); + XMLWriter_Element positionTag(exampleFile, "Position"); + positionTag.Attribute("x", pos.X); + positionTag.Attribute("z", pos.Z); // TODO: height offset etc } { - XML_Element("Orientation"); - XML_Attribute("y", rot.Y); - // TODO: X, Z maybe + XMLWriter_Element orientationTag(exampleFile, "Orientation"); + orientationTag.Attribute("y", rot.Y); + // TODO: X, Z maybe } } // Adding actor seed CmpPtr cmpVisual(*g_Game->GetSimulation2(), id); if (cmpVisual) - XML_Setting("ActorSeed", (unsigned int)cmpVisual->GetActorSeed()); - + entityTag.Setting("ActorSeed", static_cast(cmpVisual->GetActorSeed())); } } } } - const CStr& data = XML_GetOutput(); + const CStr& data = exampleFile.GetOutput(); msg->xmldata = std::wstring(data.begin(), data.end()); }