Skip to content

Commit

Permalink
ResourceGraphs - Execution - working
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 11, 2024
1 parent 118b9a0 commit 27d890e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
32 changes: 27 additions & 5 deletions Engine/Source/Fyrion/Resource/ResourceGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Fyrion

for (auto& data : m_resourceGraph->m_data)
{
if (data.defaultValue == nullptr && data.typeHandler && data.offset != U32_MAX)
if (data.defaultValue == nullptr && data.typeHandler && data.offset != U32_MAX)
{
data.typeHandler->Construct(&m_instanceData[data.offset]);
}
Expand Down Expand Up @@ -59,8 +59,10 @@ namespace Fyrion
}
else if (node->m_outputOffset != U32_MAX && node->m_typeHandler != nullptr)
{
//type constructor
node->m_typeHandler->Construct(&m_instanceData[node->m_outputOffset]);

//publish output.
auto it = m_outputs.Find(node->m_typeHandler->GetTypeInfo().typeId);
if (it == m_outputs.end())
{
Expand All @@ -77,9 +79,21 @@ namespace Fyrion
for (int n = 0; n < m_resourceGraph->m_nodes.Size(); ++n)
{
const auto& node = m_resourceGraph->m_nodes[n];
if (node->m_valid && node->m_functionHandler)
if (node->m_valid)
{
node->m_functionHandler->Invoke(nullptr, nullptr, m_nodeParams[n].Data());
if (node->m_functionHandler)
{
node->m_functionHandler->Invoke(nullptr, nullptr, m_nodeParams[n].Data());
}
else if (node->m_typeHandler)
{
//copy links to type.
for(auto& itOffset: node->m_offsets)
{
auto& data = m_resourceGraph->m_data[itOffset.second];
data.typeHandler->Copy(&m_instanceData[data.copyOffset], &m_instanceData[data.offset]);
}
}
}
}
}
Expand Down Expand Up @@ -236,10 +250,18 @@ namespace Fyrion
node->m_offsets.Insert(fieldHandler->GetName(), m_data.Size());

//TODO don't need to c construct.
m_data.EmplaceBack(ResourceGraphNodeParamData{
auto& data = m_data.EmplaceBack(ResourceGraphNodeParamData{
.offset = node->m_outputOffset + (u32)fieldInfo.offsetOf,
.typeHandler = fieldType
.typeHandler = fieldType,
});

if (auto it = node->m_inputLinks.Find(fieldHandler->GetName()))
{
if (auto itOffset = m_nodes[it->second.outputNodeId]->m_offsets.Find(it->second.outputPin))
{
data.copyOffset = m_data[itOffset->second].offset;
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Fyrion/Resource/ResourceGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace Fyrion
u32 offset = U32_MAX;
TypeHandler* typeHandler;
VoidPtr defaultValue;
u32 copyOffset = U32_MAX;
};

class FY_API ResourceGraphNodeData
Expand Down
6 changes: 3 additions & 3 deletions Engine/Test/Fyrion/Resource/ResourceGraphTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace

TEST_CASE("Resource::ResourceGraphBasics")
{
String vl = "default";
String vl = "value";

Engine::Init();
{
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace
CHECK(graphNodes[2]->GetId() == 2);

ResourceGraphInstance* instance = resourceGraph.CreateInstance();
String vl = "value-";
String vl = "default-";
instance->SetInputValue("inputValue", &vl);

instance->Execute();
Expand All @@ -204,7 +204,7 @@ namespace
REQUIRE(outputs[0]);

const TestOutputNode* testOutputNode = static_cast<const TestOutputNode*>(outputs[0]);
// CHECK(testOutputNode->stringValue == "value-value-");
CHECK(testOutputNode->stringValue == "default-value");

instance->Destroy();
}
Expand Down

0 comments on commit 27d890e

Please sign in to comment.