Add TaskGraphSystem.RemoveDependency and automatically cleanup dependencies on system destroy

This commit is contained in:
Wojtek Figat
2023-04-05 22:43:05 +02:00
parent d8f996ddc7
commit 0c167f38b7
2 changed files with 29 additions and 0 deletions

View File

@@ -18,11 +18,31 @@ TaskGraphSystem::TaskGraphSystem(const SpawnParams& params)
{
}
TaskGraphSystem::~TaskGraphSystem()
{
// Cleanup any outstanding dependencies
for (auto* e : _reverseDependencies)
e->_dependencies.Remove(this);
}
void TaskGraphSystem::AddDependency(TaskGraphSystem* system)
{
CHECK(system);
if (_dependencies.Contains(system))
return;
system->_reverseDependencies.Add(this);
_dependencies.Add(system);
}
void TaskGraphSystem::RemoveDependency(TaskGraphSystem* system)
{
CHECK(system);
if (!_dependencies.Contains(system))
return;
system->_reverseDependencies.Remove(this);
_dependencies.Remove(system);
}
void TaskGraphSystem::PreExecute(TaskGraph* graph)
{
}

View File

@@ -16,6 +16,7 @@ DECLARE_SCRIPTING_TYPE(TaskGraphSystem);
friend TaskGraph;
private:
Array<TaskGraphSystem*, InlinedAllocation<16>> _dependencies;
Array<TaskGraphSystem*, InlinedAllocation<16>> _reverseDependencies;
public:
/// <summary>
@@ -24,12 +25,20 @@ public:
API_FIELD() int32 Order = 0;
public:
~TaskGraphSystem();
/// <summary>
/// Adds the dependency on the system execution. Before this system can be executed the given dependant system has to be executed first.
/// </summary>
/// <param name="system">The system to depend on.</param>
API_FUNCTION() void AddDependency(TaskGraphSystem* system);
/// <summary>
/// Removes the dependency on the system execution.
/// </summary>
/// <param name="system">The system to not depend on anymore.</param>
API_FUNCTION() void RemoveDependency(TaskGraphSystem* system);
/// <summary>
/// Called before executing any systems of the graph. Can be used to initialize data (synchronous).
/// </summary>