E - type of the blackboard object that tasks use to read or modify game statepublic class SemaphoreGuard<E> extends Decorator<E>
SemaphoreGuard decorator allows you to specify how many characters should be allowed to concurrently execute its
child which represents a limited resource used in different behavior trees (note that this does not necessarily involve
multithreading concurrency).
This is a simple mechanism for ensuring that a limited shared resource is not over subscribed. You might have a pool of 5 pathfinders, for example, meaning at most 5 characters can be pathfinding at a time. Or you can associate a semaphore to the player character to ensure that at most 3 enemies can simultaneously attack him.
This decorator fails when it cannot acquire the semaphore. This allows a selector task higher up the tree to find a different action that doesn't involve the contested resource.
Task.Status| Modifier and Type | Field and Description |
|---|---|
String |
name
Mandatory task attribute specifying the semaphore name.
|
| Constructor and Description |
|---|
SemaphoreGuard()
Creates a
SemaphoreGuard decorator with no child. |
SemaphoreGuard(String name)
Creates a
SemaphoreGuard decorator with no child the specified semaphore name. |
SemaphoreGuard(String name,
Task<E> task)
Creates a
SemaphoreGuard decorator with the specified semaphore name and child. |
SemaphoreGuard(Task<E> task)
Creates a
SemaphoreGuard decorator with the given child. |
| Modifier and Type | Method and Description |
|---|---|
protected Task<E> |
copyTo(Task<E> task)
Copies this task to the given task.
|
void |
end()
Releases the semaphore.
|
void |
reset()
Resets this task to make it restart from scratch on next run.
|
void |
run()
Runs its child if the semaphore has been successfully acquired; immediately fails otherwise.
|
void |
start()
Acquires the semaphore.
|
addChildToTask, childFail, childRunning, childSuccess, getChild, getChildCountaddChild, cancel, cancelRunningChildren, checkGuard, cloneTask, fail, getEntity, getGuard, getStatus, running, setControl, setGuard, successpublic String name
public SemaphoreGuard()
SemaphoreGuard decorator with no child.public SemaphoreGuard(Task<E> task)
SemaphoreGuard decorator with the given child.task - the child task to wrappublic SemaphoreGuard(String name)
SemaphoreGuard decorator with no child the specified semaphore name.name - the semaphore namepublic void start()
This method is called when the task is entered.
public void run()
public void end()
This method is called when the task exits.
public void reset()
TaskCopyright © 2018. All rights reserved.