From f0e2d67c8ad4d1e5b571cf78f80578bbc08dbacc Mon Sep 17 00:00:00 2001
From: leper <leper@wildfiregames.com>
Date: Mon, 14 Nov 2016 06:13:03 +0100
Subject: [PATCH] Reset ParamNode's script cache in a few edge cases. Fixes
#4316.
The cache was not reset in case only attributes change, or if the value of a
child changed, but it had no children that needed to be parsed.
---
.../_test.sim/simulation/templates/inherit_a.xml | 6 ++++++
.../_test.sim/simulation/templates/inherit_b.xml | 6 ++++++
.../_test.sim/simulation/templates/inherit_c.xml | 6 ++++++
.../_test.sim/simulation/templates/inherit_d.xml | 4 ++++
.../templates/structures/rome_temple_vesta.xml | 8 +-------
source/simulation2/system/ParamNode.cpp | 4 ++++
source/simulation2/tests/test_CmpTemplateManager.h | 22 ++++++++++++++++++++++
7 files changed, 49 insertions(+), 7 deletions(-)
create mode 100644 binaries/data/mods/_test.sim/simulation/templates/inherit_a.xml
create mode 100644 binaries/data/mods/_test.sim/simulation/templates/inherit_b.xml
create mode 100644 binaries/data/mods/_test.sim/simulation/templates/inherit_c.xml
create mode 100644 binaries/data/mods/_test.sim/simulation/templates/inherit_d.xml
diff --git a/binaries/data/mods/_test.sim/simulation/templates/inherit_a.xml b/binaries/data/mods/_test.sim/simulation/templates/inherit_a.xml
new file mode 100644
index 0000000..2adabfc
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <Entity> |
| 3 | <Test2A datatype="tokens"> |
| 4 | a b c |
| 5 | </Test2A> |
| 6 | </Entity> |
diff --git a/binaries/data/mods/_test.sim/simulation/templates/inherit_b.xml b/binaries/data/mods/_test.sim/simulation/templates/inherit_b.xml
new file mode 100644
index 0000000..15d5b16
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <Entity parent="inherit_a"> |
| 3 | <Test2A datatype="tokens"> |
| 4 | d |
| 5 | </Test2A> |
| 6 | </Entity> |
diff --git a/binaries/data/mods/_test.sim/simulation/templates/inherit_c.xml b/binaries/data/mods/_test.sim/simulation/templates/inherit_c.xml
new file mode 100644
index 0000000..b296a40
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <Entity> |
| 3 | <Test2A a="b"> |
| 4 | a b c |
| 5 | </Test2A> |
| 6 | </Entity> |
diff --git a/binaries/data/mods/_test.sim/simulation/templates/inherit_d.xml b/binaries/data/mods/_test.sim/simulation/templates/inherit_d.xml
new file mode 100644
index 0000000..972d56e
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <Entity parent="inherit_c"> |
| 3 | <Test2A c="d"/> |
| 4 | </Entity> |
diff --git a/binaries/data/mods/public/simulation/templates/structures/rome_temple_vesta.xml b/binaries/data/mods/public/simulation/templates/structures/rome_temple_vesta.xml
index eda3471..49bcdd2 100644
a
|
b
|
|
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | | <Entity parent="template_structure_civic_temple"> |
| 2 | <Entity parent="structures/rome_temple"> |
3 | 3 | <Auras datatype="tokens">loyalty_regen</Auras> |
4 | 4 | <BuildRestrictions> |
5 | 5 | <Category>UniqueBuilding</Category> |
… |
… |
|
12 | 12 | <SpawnEntityOnDeath>rubble/rubble_3x3</SpawnEntityOnDeath> |
13 | 13 | </Health> |
14 | 14 | <Identity> |
15 | | <Civ>rome</Civ> |
16 | 15 | <GenericName>Temple of Vesta</GenericName> |
17 | 16 | <Icon>structures/temple_vesta.png</Icon> |
18 | 17 | <SpecificName>Aedes Vestae</SpecificName> |
… |
… |
|
20 | 19 | <Obstruction> |
21 | 20 | <Static width="19.0" depth="19.0"/> |
22 | 21 | </Obstruction> |
23 | | <ProductionQueue> |
24 | | <Technologies datatype="tokens"> |
25 | | romans/vision_sibylline |
26 | | </Technologies> |
27 | | </ProductionQueue> |
28 | 22 | <VisualActor> |
29 | 23 | <Actor>structures/romans/temple_vesta.xml</Actor> |
30 | 24 | <FoundationActor>structures/fndn_3x3.xml</FoundationActor> |
diff --git a/source/simulation2/system/ParamNode.cpp b/source/simulation2/system/ParamNode.cpp
index 26f09a1..0a04495 100644
a
|
b
|
void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const
|
171 | 171 | if (!hasSetValue) |
172 | 172 | node.m_Value = value; |
173 | 173 | |
| 174 | // We also need to reset node's script val, even if it has no children |
| 175 | // or if the attributes change. |
| 176 | node.ResetScriptVal(); |
| 177 | |
174 | 178 | // Recurse through the element's children |
175 | 179 | XERO_ITER_EL(element, child) |
176 | 180 | { |
diff --git a/source/simulation2/tests/test_CmpTemplateManager.h b/source/simulation2/tests/test_CmpTemplateManager.h
index 8103254..6784860 100644
a
|
b
|
public:
|
120 | 120 | const CParamNode* foundation = tempMan->LoadTemplate(ent2, "foundation|actor|example1", -1); |
121 | 121 | ScriptInterface::ToJSVal(cx, &val, &foundation->GetChild("VisualActor")); |
122 | 122 | TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({Actor:\"example1\", ActorOnly:(void 0), Foundation:(void 0), SilhouetteDisplay:\"false\", SilhouetteOccluder:\"false\", VisibleInAtlasOnly:\"false\"})"); |
| 123 | |
| 124 | #define GET_FIRST_ELEMENT(n, templateName) \ |
| 125 | const CParamNode* n = tempMan->LoadTemplate(ent2, templateName, -1); \ |
| 126 | for (CParamNode::ChildrenMap::const_iterator it = n->GetChildren().begin(); it != n->GetChildren().end(); ++it) \ |
| 127 | { \ |
| 128 | if (it->first[0] == '@') \ |
| 129 | continue; \ |
| 130 | ScriptInterface::ToJSVal(cx, &val, it->second); \ |
| 131 | break; \ |
| 132 | } |
| 133 | |
| 134 | GET_FIRST_ELEMENT(n1, "inherit_a"); |
| 135 | TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({'@datatype':\"tokens\", _string:\"a b c\"})"); |
| 136 | GET_FIRST_ELEMENT(n2, "inherit_b"); |
| 137 | TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({'@datatype':\"tokens\", _string:\"a b c d\"})"); |
| 138 | |
| 139 | GET_FIRST_ELEMENT(n3, "inherit_c"); |
| 140 | TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({'@a':\"b\", _string:\"a b c\"})"); |
| 141 | GET_FIRST_ELEMENT(n4, "inherit_d"); |
| 142 | TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({'@a':\"b\", '@c':\"d\"})"); |
| 143 | |
| 144 | #undef GET_FIRST_ELEMENT |
123 | 145 | } |
124 | 146 | |
125 | 147 | void test_LoadTemplate_errors() |