Skip to content

Commit

Permalink
Remove EvaluateSingleInputSlot. Now every node have to call EvaluateI…
Browse files Browse the repository at this point in the history
…nputSlot and it will return a normal or a list value based on the output slot evaluation.
  • Loading branch information
kovacsv committed Jan 26, 2019
1 parent 79facca commit 3febebc
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Sources/BuiltInNodes/BI_ArithmeticUINodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void BinaryOperationNode::Initialize ()

NE::ValueConstPtr BinaryOperationNode::Calculate (NE::EvaluationEnv& env) const
{
NE::ValueConstPtr aValue = EvaluateSingleInputSlot (NE::SlotId ("a"), env);
NE::ValueConstPtr bValue = EvaluateSingleInputSlot (NE::SlotId ("b"), env);
NE::ValueConstPtr aValue = EvaluateInputSlot (NE::SlotId ("a"), env);
NE::ValueConstPtr bValue = EvaluateInputSlot (NE::SlotId ("b"), env);
if (!NE::IsComplexType<NE::NumberValue> (aValue) || !NE::IsComplexType<NE::NumberValue> (bValue)) {
return nullptr;
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/BuiltInNodes/BI_InputUINodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ void IntegerRangeNode::Initialize ()

NE::ValueConstPtr IntegerRangeNode::Calculate (NE::EvaluationEnv& env) const
{
NE::ValueConstPtr start = EvaluateSingleInputSlot (NE::SlotId ("start"), env);
NE::ValueConstPtr step = EvaluateSingleInputSlot (NE::SlotId ("step"), env);
NE::ValueConstPtr count = EvaluateSingleInputSlot (NE::SlotId ("count"), env);
NE::ValueConstPtr start = EvaluateInputSlot (NE::SlotId ("start"), env);
NE::ValueConstPtr step = EvaluateInputSlot (NE::SlotId ("step"), env);
NE::ValueConstPtr count = EvaluateInputSlot (NE::SlotId ("count"), env);
if (!NE::IsSingleType<NE::NumberValue> (start) || !NE::IsSingleType<NE::NumberValue> (step) || !NE::IsSingleType<NE::NumberValue> (count)) {
return nullptr;
}
Expand Down Expand Up @@ -609,9 +609,9 @@ void DoubleRangeNode::Initialize ()

NE::ValueConstPtr DoubleRangeNode::Calculate (NE::EvaluationEnv& env) const
{
NE::ValueConstPtr start = EvaluateSingleInputSlot (NE::SlotId ("start"), env);
NE::ValueConstPtr step = EvaluateSingleInputSlot (NE::SlotId ("step"), env);
NE::ValueConstPtr count = EvaluateSingleInputSlot (NE::SlotId ("count"), env);
NE::ValueConstPtr start = EvaluateInputSlot (NE::SlotId ("start"), env);
NE::ValueConstPtr step = EvaluateInputSlot (NE::SlotId ("step"), env);
NE::ValueConstPtr count = EvaluateInputSlot (NE::SlotId ("count"), env);
if (!NE::IsSingleType<NE::NumberValue> (start) || !NE::IsSingleType<NE::NumberValue> (step) || !NE::IsSingleType<NE::NumberValue> (count)) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BuiltInNodes/BI_ViewerUINodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void MultiLineViewerNode::Initialize ()

NE::ValueConstPtr MultiLineViewerNode::Calculate (NE::EvaluationEnv& env) const
{
return EvaluateSingleInputSlot (NE::SlotId ("in"), env);
return EvaluateInputSlot (NE::SlotId ("in"), env);
}

void MultiLineViewerNode::RegisterParameters (NUIE::NodeParameterList& parameterList) const
Expand Down
51 changes: 20 additions & 31 deletions Sources/NodeEngine/NE_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,31 +275,7 @@ bool Node::RegisterOutputSlot (const OutputSlotPtr& newOutputSlot)
return true;
}

ValueConstPtr Node::EvaluateSingleInputSlot (const SlotId& slotId, EvaluationEnv& env) const
{
if (DBGERROR (!HasInputSlot (slotId))) {
return nullptr;
}

InputSlotConstPtr inputSlot = GetInputSlot (slotId);
if (DBGERROR (inputSlot == nullptr)) {
return nullptr;
}

OutputSlotConnectionMode outputSlotConnectionMode = inputSlot->GetOutputSlotConnectionMode ();
if (DBGERROR (outputSlotConnectionMode == OutputSlotConnectionMode::Multiple)) {
return nullptr;
}

ListValueConstPtr result = EvaluateInputSlot (inputSlot, env);
if (DBGERROR (result->GetSize () != 1)) {
return nullptr;
}

return result->GetValue (0);
}

ListValueConstPtr Node::EvaluateInputSlot (const SlotId& slotId, EvaluationEnv& env) const
ValueConstPtr Node::EvaluateInputSlot (const SlotId& slotId, EvaluationEnv& env) const
{
if (DBGERROR (!HasInputSlot (slotId))) {
return nullptr;
Expand All @@ -323,22 +299,35 @@ void Node::ProcessValue (const ValueConstPtr&, EvaluationEnv&) const

}

ListValueConstPtr Node::EvaluateInputSlot (const InputSlotConstPtr& inputSlot, EvaluationEnv& env) const
ValueConstPtr Node::EvaluateInputSlot (const InputSlotConstPtr& inputSlot, EvaluationEnv& env) const
{
if (DBGERROR (nodeEvaluator == nullptr)) {
return nullptr;
}

ListValuePtr result (new ListValue ());
if (!nodeEvaluator->HasConnectedOutputSlots (inputSlot)) {
result->Push (inputSlot->GetDefaultValue ());
return result;
return inputSlot->GetDefaultValue ();
}

std::vector<OutputSlotConstPtr> connectedOutputSlots;
nodeEvaluator->EnumerateConnectedOutputSlots (inputSlot, [&] (const OutputSlotConstPtr& outputSlot) {
result->Push (outputSlot->Evaluate (env));
connectedOutputSlots.push_back (outputSlot);
});
return result;

OutputSlotConnectionMode outputSlotConnectionMode = inputSlot->GetOutputSlotConnectionMode ();
if (outputSlotConnectionMode == OutputSlotConnectionMode::Single) {
DBGASSERT (connectedOutputSlots.size () == 1);
return connectedOutputSlots[0]->Evaluate (env);
} else if (inputSlot->GetOutputSlotConnectionMode () == OutputSlotConnectionMode::Multiple) {
ListValuePtr result (new ListValue ());
for (const OutputSlotConstPtr& outputSlot : connectedOutputSlots) {
result->Push (outputSlot->Evaluate (env));
}
return result;
}

DBGBREAK ();
return nullptr;
}

NodePtr Node::Clone (const NodeConstPtr& node)
Expand Down
6 changes: 2 additions & 4 deletions Sources/NodeEngine/NE_Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ class Node : public DynamicSerializable
protected:
virtual bool RegisterInputSlot (const InputSlotPtr& newInputSlot);
virtual bool RegisterOutputSlot (const OutputSlotPtr& newOutputSlot);

ValueConstPtr EvaluateSingleInputSlot (const SlotId& slotId, EvaluationEnv& env) const;
ListValueConstPtr EvaluateInputSlot (const SlotId& slotId, EvaluationEnv& env) const;
ValueConstPtr EvaluateInputSlot (const SlotId& slotId, EvaluationEnv& env) const;

private:
virtual void Initialize () = 0;
Expand All @@ -140,7 +138,7 @@ class Node : public DynamicSerializable
virtual bool IsForceCalculated () const;
virtual void ProcessValue (const ValueConstPtr& value, EvaluationEnv& env) const;

ListValueConstPtr EvaluateInputSlot (const InputSlotConstPtr& inputSlot, EvaluationEnv& env) const;
ValueConstPtr EvaluateInputSlot (const InputSlotConstPtr& inputSlot, EvaluationEnv& env) const;

NodeId nodeId;
NodeEvaluatorConstPtr nodeEvaluator;
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/EnableDisableFeatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class TestNode : public SerializableTestUINode

virtual ValueConstPtr Calculate (EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("in2"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("in2"), env);
int result = IntValue::Get (a) + IntValue::Get (b);
return ValuePtr (new IntValue (result));
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/ListValueNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ListSummer : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
NE::ValueConstPtr val = EvaluateSingleInputSlot (SlotId ("in"), env);
NE::ValueConstPtr val = EvaluateInputSlot (SlotId ("in"), env);
int result = 0;
if (IsComplexType<NumberValue> (val)) {
NE::FlatEnumerate (val, [&] (const NE::ValueConstPtr& value) {
Expand All @@ -94,7 +94,7 @@ TEST (ListValueNodeTest_Node)

{
ValueConstPtr result = listMakerNode->Evaluate (NE::EmptyEvaluationEnv);
ASSERT (Value::IsType<ListValue> (result));
ASSERT (result == nullptr);
}

{
Expand Down
2 changes: 1 addition & 1 deletion Sources/NodeEngineTest/MultiInputSlotTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FlattenerNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ListValueConstPtr val = EvaluateInputSlot (SlotId ("in"), env);
ValueConstPtr val = EvaluateInputSlot (SlotId ("in"), env);
ListValuePtr result (new ListValue ());
FlatEnumerate (val, [&] (const ValueConstPtr& flatVal) {
result->Push (flatVal->Clone ());
Expand Down
14 changes: 7 additions & 7 deletions Sources/NodeEngineTest/NodeConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class AdditionNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr firstResult = EvaluateSingleInputSlot (SlotId ("first"), env);
ValueConstPtr secondResult = EvaluateSingleInputSlot (SlotId ("second"), env);
ValueConstPtr firstResult = EvaluateInputSlot (SlotId ("first"), env);
ValueConstPtr secondResult = EvaluateInputSlot (SlotId ("second"), env);
return ValuePtr (new IntValue (IntValue::Get (firstResult) + IntValue::Get (secondResult)));
}
};
Expand All @@ -166,9 +166,9 @@ class MultiAdditionNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ListValueConstPtr result = EvaluateInputSlot (SlotId ("in"), env);
ValueConstPtr result = EvaluateInputSlot (SlotId ("in"), env);
int sum = 0;
result->Enumerate ([&] (const ValueConstPtr& val) {
FlatEnumerate (result, [&] (const ValueConstPtr& val) {
sum += IntValue::Get (val);
});
return ValuePtr (new IntValue (sum));
Expand All @@ -193,8 +193,8 @@ class DisabledAdditionNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr firstResult = EvaluateSingleInputSlot (SlotId ("first"), env);
ValueConstPtr secondResult = EvaluateSingleInputSlot (SlotId ("second"), env);
ValueConstPtr firstResult = EvaluateInputSlot (SlotId ("first"), env);
ValueConstPtr secondResult = EvaluateInputSlot (SlotId ("second"), env);
return ValuePtr (new IntValue (IntValue::Get (firstResult) + IntValue::Get (secondResult)));
}
};
Expand All @@ -217,7 +217,7 @@ class AdderInputOutputNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr inputVal = EvaluateSingleInputSlot (SlotId ("in"), env);
ValueConstPtr inputVal = EvaluateInputSlot (SlotId ("in"), env);
return ValuePtr (new IntValue (IntValue::Get (inputVal) + toAdd));
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/NodeManagerManualUpdateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class IncreaseNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr in = EvaluateSingleInputSlot (SlotId ("in"), env);
ValueConstPtr in = EvaluateInputSlot (SlotId ("in"), env);
return ValuePtr (new IntValue (IntValue::Get (in) + 1));
}
};
Expand All @@ -85,7 +85,7 @@ class IncreaseForceCalculatedNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr in = EvaluateSingleInputSlot (SlotId ("in"), env);
ValueConstPtr in = EvaluateInputSlot (SlotId ("in"), env);
if (in == nullptr) {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/NodeManagerMergeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TestNode : public Node

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("a"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("b"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("a"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("b"), env);
int result = IntValue::Get (a) + IntValue::Get (b);
return ValuePtr (new IntValue (result));
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/NodeManagerSerializationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TestNode : public Node

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr firstResult = EvaluateSingleInputSlot (SlotId ("a"), env);
ValueConstPtr secondResult = EvaluateSingleInputSlot (SlotId ("b"), env);
ValueConstPtr firstResult = EvaluateInputSlot (SlotId ("a"), env);
ValueConstPtr secondResult = EvaluateInputSlot (SlotId ("b"), env);
return ValueConstPtr (new IntValue (val + IntValue::Get (firstResult) + IntValue::Get (secondResult)));
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NodeEngineTest/NodeRecalculationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestNode : public SerializableTestNode
virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
calculationCounter++;
ValueConstPtr in = EvaluateSingleInputSlot (SlotId ("in"), env);
ValueConstPtr in = EvaluateInputSlot (SlotId ("in"), env);
return ValuePtr (new IntValue (IntValue::Get (in) + 1));
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NodeEngineTest/NodeValueCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class InputOutputNode : public SerializableTestNode
virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
calculationCount++;
ValueConstPtr in = EvaluateSingleInputSlot (SlotId ("in"), env);
ValueConstPtr in = EvaluateInputSlot (SlotId ("in"), env);
return ValuePtr (new IntValue (IntValue::Get (in) + 1));
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/NodeValueCombinationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TestNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
NE::ValueConstPtr a = EvaluateSingleInputSlot (NE::SlotId ("a"), env);
NE::ValueConstPtr b = EvaluateSingleInputSlot (NE::SlotId ("b"), env);
NE::ValueConstPtr a = EvaluateInputSlot (NE::SlotId ("a"), env);
NE::ValueConstPtr b = EvaluateInputSlot (NE::SlotId ("b"), env);
if (!NE::IsComplexType<NE::IntValue> (a) || !NE::IsComplexType<NE::IntValue> (b)) {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/NumberTypeNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class NumberAdderNode : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("first"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("second"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("first"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("second"), env);
double result = NumberValue::ToDouble (a) + NumberValue::ToDouble (b);
return ValuePtr (new DoubleValue (result));
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NodeEngineTest/TypeHandlingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class OutputNodeA : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
return EvaluateSingleInputSlot (SlotId ("inA"), env);
return EvaluateInputSlot (SlotId ("inA"), env);
}
};

Expand Down Expand Up @@ -234,7 +234,7 @@ class OutputNodeB : public SerializableTestNode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
return EvaluateSingleInputSlot (SlotId ("inB"), env);
return EvaluateInputSlot (SlotId ("inB"), env);
}
};

Expand Down
12 changes: 6 additions & 6 deletions Sources/NodeEngineTest/UINodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class TestNode : public SerializableTestUINode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("in2"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("in2"), env);
int result = IntValue::Get (a) + IntValue::Get (b);
return ValuePtr (new IntValue (result));
}
Expand Down Expand Up @@ -80,8 +80,8 @@ class TestNode2 : public SerializableTestUINode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("in2"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("in2"), env);
int result = IntValue::Get (a) + IntValue::Get (b);
return ValuePtr (new IntValue (result));
}
Expand Down Expand Up @@ -134,8 +134,8 @@ class EnumerationParamTestNode : public SerializableTestUINode

virtual ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
ValueConstPtr a = EvaluateSingleInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateSingleInputSlot (SlotId ("in2"), env);
ValueConstPtr a = EvaluateInputSlot (SlotId ("in1"), env);
ValueConstPtr b = EvaluateInputSlot (SlotId ("in2"), env);
int result = IntValue::Get (a) + IntValue::Get (b);
return ValuePtr (new IntValue (result));
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NodeEngineTest/VisualTestFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IncreaseNode : public BI::BasicUINode

NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override
{
NE::ValueConstPtr inValue = EvaluateSingleInputSlot (NE::SlotId ("in"), env);
NE::ValueConstPtr inValue = EvaluateInputSlot (NE::SlotId ("in"), env);
if (!IsSingleType<NE::IntValue> (inValue)) {
return nullptr;
}
Expand Down
Loading

0 comments on commit 3febebc

Please sign in to comment.