Ticket #4316: 0001-Reset-ParamNode-s-script-cache-in-a-few-edge-cases.-.patch

File 0001-Reset-ParamNode-s-script-cache-in-a-few-edge-cases.-.patch, 6.2 KB (added by leper, 7 years ago)
  • new file inaries/data/mods/_test.sim/simulation/templates/inherit_a.xml

    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>
  • new file inaries/data/mods/_test.sim/simulation/templates/inherit_b.xml

    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>
  • new file inaries/data/mods/_test.sim/simulation/templates/inherit_c.xml

    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>
  • new file inaries/data/mods/_test.sim/simulation/templates/inherit_d.xml

    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>
  • binaries/data/mods/public/simulation/templates/structures/rome_temple_vesta.xml

    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  
    11<?xml version="1.0" encoding="utf-8"?>
    2 <Entity parent="template_structure_civic_temple">
     2<Entity parent="structures/rome_temple">
    33  <Auras datatype="tokens">loyalty_regen</Auras>
    44  <BuildRestrictions>
    55    <Category>UniqueBuilding</Category>
     
    1212    <SpawnEntityOnDeath>rubble/rubble_3x3</SpawnEntityOnDeath>
    1313  </Health>
    1414  <Identity>
    15     <Civ>rome</Civ>
    1615    <GenericName>Temple of Vesta</GenericName>
    1716    <Icon>structures/temple_vesta.png</Icon>
    1817    <SpecificName>Aedes Vestae</SpecificName>
     
    2019  <Obstruction>
    2120    <Static width="19.0" depth="19.0"/>
    2221  </Obstruction>
    23   <ProductionQueue>
    24     <Technologies datatype="tokens">
    25       romans/vision_sibylline
    26     </Technologies>
    27   </ProductionQueue>
    2822  <VisualActor>
    2923    <Actor>structures/romans/temple_vesta.xml</Actor>
    3024    <FoundationActor>structures/fndn_3x3.xml</FoundationActor>
  • source/simulation2/system/ParamNode.cpp

    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  
    171171    if (!hasSetValue)
    172172        node.m_Value = value;
    173173
     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
    174178    // Recurse through the element's children
    175179    XERO_ITER_EL(element, child)
    176180    {
  • source/simulation2/tests/test_CmpTemplateManager.h

    diff --git a/source/simulation2/tests/test_CmpTemplateManager.h b/source/simulation2/tests/test_CmpTemplateManager.h
    index 8103254..6784860 100644
    a b public:  
    120120        const CParamNode* foundation = tempMan->LoadTemplate(ent2, "foundation|actor|example1", -1);
    121121        ScriptInterface::ToJSVal(cx, &val, &foundation->GetChild("VisualActor"));
    122122        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
    123145    }
    124146
    125147    void test_LoadTemplate_errors()