Skip to content

Commit

Permalink
Remove coroutineHost from TaskBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
lenalinke committed Apr 27, 2024
1 parent de5d3bd commit b80bdaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,23 @@ namespace i5.VirtualAgents
/// </summary>
public class TaskBundle : AgentBaseTask
{
// The coroutine host which is used to start coroutines as TaskBundles are no MonoBehaviours
private MonoBehaviour coroutineHost;
public TaskBundle(MonoBehaviour coroutineHost)
public TaskBundle()
{
this.State = TaskState.Waiting;
TaskQueue = new List<AgentBaseTask>();
this.coroutineHost = coroutineHost;
}

public TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks)
public TaskBundle(List<AgentBaseTask> tasks)
{
this.State = TaskState.Waiting;
TaskQueue = tasks;
this.coroutineHost = coroutineHost;
}

public TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks, List<Func <bool>> preconditions)
public TaskBundle(List<AgentBaseTask> tasks, List<Func <bool>> preconditions)
{
this.State = TaskState.Waiting;
TaskQueue = tasks;
this.Preconditions = preconditions;
this.coroutineHost = coroutineHost;
}

/// <summary>
Expand All @@ -53,14 +48,9 @@ public TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks, List<F
public override void StartExecution(Agent executingAgent)
{
State = TaskState.Running;
if (coroutineHost == null)
{
Debug.LogError("coroutineHost is null");
return;
}
if (CheckPreconditions())
{
coroutineHost.StartCoroutine(ExecuteTasks(executingAgent));
executingAgent.StartCoroutine(ExecuteTasks(executingAgent));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ protected override void Start()

// Create a new TaskBundle with the tasks and preconditions
// This TaskBundle will be executed because the agent is not close to the last waypoint
TaskBundle taskBundleSuccess = new TaskBundle(this, tasks, preconditions);
TaskBundle taskBundleSuccess = new TaskBundle(tasks, preconditions);


// Create a new TaskBundle with the tasks and preconditions
// This TaskBundle will not be executed
// because after executing the taskBundleSuccess the agent is close to the last waypoint
TaskBundle taskBundleFail = new TaskBundle(this, tasks, preconditions);
TaskBundle taskBundleFail = new TaskBundle(tasks, preconditions);

// Schedule the TaskBundles to the taskSystem
taskSystem.ScheduleTask(taskBundleSuccess, 0);
Expand Down
7 changes: 3 additions & 4 deletions Documentation/manual/task-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ Tasks in a TaskBundle are executed back to back in sequence and cannot be interr

# Construct a TaskBundle
The are three TaskBundle constructors, that can be used to create a TaskBundle:
1. `TaskBundle(MonoBehaviour coroutineHost)`
2. `TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks)`
3. `TaskBundle(MonoBehaviour coroutineHost, List<AgentBaseTask> tasks, List<Func <bool>> preconditions)`
1. `TaskBundle()`
2. `TaskBundle(List<AgentBaseTask> tasks)`
3. `TaskBundle(List<AgentBaseTask> tasks, List<Func <bool>> preconditions)`

The `coroutineHost` is the MonoBehaviour that will host the coroutine that executes the TaskBundle.
`tasks` is a list of subtasks. Of note is, that TaskActions cannot be used here, as they would also add the sub-tasks to the regular scheduler.
`preconditions` is a list of boolean functions, so in particular lambda expressions can be used.
Other functions may be evaluated beforehand, so are not suitable for this purpose.
Expand Down

0 comments on commit b80bdaf

Please sign in to comment.