1
1
forked from 0ad/0ad

Remove unused parameter from template loading code

Templates should be the same for all players, techs can be used to
provide
different lists of templates if that is needed.

Reviewed By: Itms
Differential Revision: https://code.wildfiregames.com/D25
This was SVN commit r19142.
This commit is contained in:
leper 2017-01-15 18:41:53 +00:00
parent ba76f60c53
commit 3a85d0b3fa
5 changed files with 38 additions and 45 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -100,7 +100,7 @@ public:
m_DisableValidation = true;
}
virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName, int playerID);
virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName);
virtual const CParamNode* GetTemplate(const std::string& templateName);
@ -135,23 +135,16 @@ private:
// Remember the template used by each entity, so we can return them
// again for deserialization.
// TODO: should store player ID etc.
std::map<entity_id_t, std::string> m_LatestTemplates;
};
REGISTER_COMPONENT_TYPE(TemplateManager)
const CParamNode* CCmpTemplateManager::LoadTemplate(entity_id_t ent, const std::string& templateName, int UNUSED(playerID))
const CParamNode* CCmpTemplateManager::LoadTemplate(entity_id_t ent, const std::string& templateName)
{
m_LatestTemplates[ent] = templateName;
const CParamNode* templateRoot = GetTemplate(templateName);
if (!templateRoot)
return NULL;
// TODO: Eventually we need to support techs in here, and return a different template per playerID
return templateRoot;
return GetTemplate(templateName);
}
const CParamNode* CCmpTemplateManager::GetTemplate(const std::string& templateName)
@ -206,7 +199,7 @@ const CParamNode* CCmpTemplateManager::LoadLatestTemplate(entity_id_t ent)
std::map<entity_id_t, std::string>::const_iterator it = m_LatestTemplates.find(ent);
if (it == m_LatestTemplates.end())
return NULL;
return LoadTemplate(ent, it->second, -1);
return LoadTemplate(ent, it->second);
}
std::string CCmpTemplateManager::GetCurrentTemplateName(entity_id_t ent)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -55,7 +55,7 @@ public:
*
* @return NULL on error
*/
virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName, int playerID) = 0;
virtual const CParamNode* LoadTemplate(entity_id_t ent, const std::string& templateName) = 0;
/**
* Loads the template XML file identified by 'templateName' (including inheritance

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -858,7 +858,7 @@ entity_id_t CComponentManager::AddEntity(const std::wstring& templateName, entit
return INVALID_ENTITY;
}
const CParamNode* tmpl = cmpTemplateManager->LoadTemplate(ent, utf8_from_wstring(templateName), -1);
const CParamNode* tmpl = cmpTemplateManager->LoadTemplate(ent, utf8_from_wstring(templateName));
if (!tmpl)
return INVALID_ENTITY; // LoadTemplate will have reported the error

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -64,19 +64,19 @@ public:
ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(ent1, IID_TemplateManager));
TS_ASSERT(tempMan != NULL);
const CParamNode* basic = tempMan->LoadTemplate(ent2, "basic", -1);
const CParamNode* basic = tempMan->LoadTemplate(ent2, "basic");
TS_ASSERT(basic != NULL);
TS_ASSERT_WSTR_EQUALS(basic->ToXML(), L"<Test1A>12345</Test1A>");
const CParamNode* inherit2 = tempMan->LoadTemplate(ent2, "inherit2", -1);
const CParamNode* inherit2 = tempMan->LoadTemplate(ent2, "inherit2");
TS_ASSERT(inherit2 != NULL);
TS_ASSERT_WSTR_EQUALS(inherit2->ToXML(), L"<Test1A a=\"a2\" b=\"b1\" c=\"c1\"><d>d2</d><e>e1</e><f>f1</f><g>g2</g></Test1A>");
const CParamNode* inherit1 = tempMan->LoadTemplate(ent2, "inherit1", -1);
const CParamNode* inherit1 = tempMan->LoadTemplate(ent2, "inherit1");
TS_ASSERT(inherit1 != NULL);
TS_ASSERT_WSTR_EQUALS(inherit1->ToXML(), L"<Test1A a=\"a1\" b=\"b1\" c=\"c1\"><d>d1</d><e>e1</e><f>f1</f></Test1A>");
const CParamNode* actor = tempMan->LoadTemplate(ent2, "actor|example1", -1);
const CParamNode* actor = tempMan->LoadTemplate(ent2, "actor|example1");
TS_ASSERT(actor != NULL);
TS_ASSERT_WSTR_EQUALS(actor->ToXML(),
L"<Footprint><Circle radius=\"2.0\"></Circle><Height>1.0</Height></Footprint><Selectable><EditorOnly></EditorOnly><Overlay><Texture><MainTexture>actor.png</MainTexture><MainTextureMask>actor_mask.png</MainTextureMask></Texture></Overlay></Selectable>"
@ -104,25 +104,25 @@ public:
// This is testing some bugs in the template JS object caching
const CParamNode* inherit1 = tempMan->LoadTemplate(ent2, "inherit1", -1);
const CParamNode* inherit1 = tempMan->LoadTemplate(ent2, "inherit1");
JS::RootedValue val(cx);
ScriptInterface::ToJSVal(cx, &val, inherit1);
TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({Test1A:{'@a':\"a1\", '@b':\"b1\", '@c':\"c1\", d:\"d1\", e:\"e1\", f:\"f1\"}})");
const CParamNode* inherit2 = tempMan->LoadTemplate(ent2, "inherit2", -1);
const CParamNode* inherit2 = tempMan->LoadTemplate(ent2, "inherit2");
ScriptInterface::ToJSVal(cx, &val, inherit2);
TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({'@parent':\"inherit1\", Test1A:{'@a':\"a2\", '@b':\"b1\", '@c':\"c1\", d:\"d2\", e:\"e1\", f:\"f1\", g:\"g2\"}})");
const CParamNode* actor = tempMan->LoadTemplate(ent2, "actor|example1", -1);
const CParamNode* actor = tempMan->LoadTemplate(ent2, "actor|example1");
ScriptInterface::ToJSVal(cx, &val, &actor->GetChild("VisualActor"));
TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({Actor:\"example1\", ActorOnly:(void 0), SilhouetteDisplay:\"false\", SilhouetteOccluder:\"false\", VisibleInAtlasOnly:\"false\"})");
const CParamNode* foundation = tempMan->LoadTemplate(ent2, "foundation|actor|example1", -1);
const CParamNode* foundation = tempMan->LoadTemplate(ent2, "foundation|actor|example1");
ScriptInterface::ToJSVal(cx, &val, &foundation->GetChild("VisualActor"));
TS_ASSERT_STR_EQUALS(man.GetScriptInterface().ToString(&val), "({Actor:\"example1\", ActorOnly:(void 0), Foundation:(void 0), SilhouetteDisplay:\"false\", SilhouetteOccluder:\"false\", VisibleInAtlasOnly:\"false\"})");
#define GET_FIRST_ELEMENT(n, templateName) \
const CParamNode* n = tempMan->LoadTemplate(ent2, templateName, -1); \
const CParamNode* n = tempMan->LoadTemplate(ent2, templateName); \
for (CParamNode::ChildrenMap::const_iterator it = n->GetChildren().begin(); it != n->GetChildren().end(); ++it) \
{ \
if (it->first[0] == '@') \
@ -161,19 +161,19 @@ public:
TestLogger logger;
TS_ASSERT(tempMan->LoadTemplate(ent2, "illformed", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "illformed") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "invalid", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "invalid") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-special", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-special") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "preview|nonexistent", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "preview|nonexistent") == NULL);
}
void test_LoadTemplate_multiple()
@ -191,28 +191,28 @@ public:
ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(ent1, IID_TemplateManager));
TS_ASSERT(tempMan != NULL);
const CParamNode* basicA = tempMan->LoadTemplate(ent2, "basic", -1);
const CParamNode* basicA = tempMan->LoadTemplate(ent2, "basic");
TS_ASSERT(basicA != NULL);
const CParamNode* basicB = tempMan->LoadTemplate(ent2, "basic", -1);
const CParamNode* basicB = tempMan->LoadTemplate(ent2, "basic");
TS_ASSERT(basicA == basicB);
const CParamNode* inherit2A = tempMan->LoadTemplate(ent2, "inherit2", -1);
const CParamNode* inherit2A = tempMan->LoadTemplate(ent2, "inherit2");
TS_ASSERT(inherit2A != NULL);
const CParamNode* inherit2B = tempMan->LoadTemplate(ent2, "inherit2", -1);
const CParamNode* inherit2B = tempMan->LoadTemplate(ent2, "inherit2");
TS_ASSERT(inherit2A == inherit2B);
TestLogger logger;
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "nonexistent") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-loop") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken", -1) == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken") == NULL);
TS_ASSERT(tempMan->LoadTemplate(ent2, "inherit-broken") == NULL);
}
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -837,7 +837,7 @@ entities:\n\
TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam));
ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager));
const CParamNode* testParam = tempMan->LoadTemplate(ent2, "template-serialize", -1);
const CParamNode* testParam = tempMan->LoadTemplate(ent2, "template-serialize");
man.AddComponent(hnd2, man.LookupCID("TestScript1_consts"), testParam->GetChild("TestScript1_consts"));