From 19f600cfa21d0673cdb4fb0001f1d41e4e0ebf69 Mon Sep 17 00:00:00 2001 From: wraitii Date: Wed, 2 Jan 2019 14:46:17 +0000 Subject: [PATCH] Add "mul_round" op to template parsing to support multiplying-then-rounding. This allows using arbitrary 'mul' values with Integer types, instead of having to switch them to Decimal types. The ParamNode is not aware of validation (thus types) so a better solution is incredibly non-trivial. Differential Revision: https://code.wildfiregames.com/D268 This was SVN commit r22003. --- source/simulation2/system/ComponentManager.cpp | 12 ------------ source/simulation2/system/ParamNode.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 989d12e80d..34a5e7094f 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -1104,28 +1104,16 @@ void CComponentManager::SendGlobalMessage(entity_id_t ent, const CMessage& msg) std::string CComponentManager::GenerateSchema() const { - std::string numericOperation = - "" - "" - "" - "add" - "mul" - "" - "" - ""; std::string schema = "" "" "" - + numericOperation + "" "" "0" - + numericOperation + "" "" "0" - + numericOperation + "" "" "" diff --git a/source/simulation2/system/ParamNode.cpp b/source/simulation2/system/ParamNode.cpp index 0fbb4fc7de..715bc08600 100644 --- a/source/simulation2/system/ParamNode.cpp +++ b/source/simulation2/system/ParamNode.cpp @@ -83,7 +83,8 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const enum op { INVALID, ADD, - MUL + MUL, + MUL_ROUND } op = INVALID; bool replacing = false; bool filtering = false; @@ -117,6 +118,8 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const op = ADD; else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul") op = MUL; + else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul_round") + op = MUL_ROUND; else LOGWARNING("Invalid op '%ls'", attr.Value); } @@ -178,7 +181,10 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const node.m_Value = (oldval + mod).ToString().FromUTF8(); break; case MUL: - node.m_Value = (oldval.Multiply(mod)).ToString().FromUTF8(); + node.m_Value = oldval.Multiply(mod).ToString().FromUTF8(); + break; + case MUL_ROUND: + node.m_Value = fixed::FromInt(oldval.Multiply(mod).ToInt_RoundToNearest()).ToString().FromUTF8(); break; } hasSetValue = true;