Skip to content

Commit

Permalink
Merge pull request #75 from nikkorn/#74
Browse files Browse the repository at this point in the history
#74 The 'random' function behaviour tree option is used for wait node duration selection and added indefinite waits
  • Loading branch information
nikkorn committed May 10, 2023
2 parents d1bf549 + 12177fe commit d4cc971
Show file tree
Hide file tree
Showing 45 changed files with 505 additions and 295 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The `BehaviourTree` constructor can take an options object as an argument, the p
| Option |Type | Description |
| :--------------------|:- |:- |
| getDeltaTime |() => number| A function returning a delta time in seconds that is used to calculate the elapsed duration of any `wait` nodes. If this function is not defined then `Date().getTime()` is used instead by default. |
| random |() => number| A function returning a floating-point number between 0 (inclusive) and 1 (exclusive). If defined, this function is used to source a pseudo-random number to use in the selection of active children for any `lotto` nodes. If not defined then `Math.random` will be used instead by default. This function can be useful in seeding all random numbers used in the running of a tree instance to make any behaviour completely deterministic. |
| random |() => number| A function returning a floating-point number between 0 (inclusive) and 1 (exclusive). If defined, this function is used to source a pseudo-random number to use in operations such as the selection of active children for any `lotto` nodes and the selection of durations for `wait` nodes when minimum and maximum durations are defined. If not defined then `Math.random` will be used instead by default. This function can be useful in seeding all random numbers used in the running of a tree instance to make any behaviour completely deterministic. |

# Nodes

Expand Down Expand Up @@ -442,7 +442,7 @@ root {
In the above example, we are using a wait node to wait 2 seconds between each run of the **FireWeapon** action.

The duration to wait in milliseconds can also be selected at random within a lower and upper bound if these are defined as two integer node arguments. In the example below, we would run the **PickUpProjectile** action and then wait for 2 to 8 seconds before running the **ThrowProjectile** action.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=wait-one-to-five-seconds)
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=wait)

```
root {
Expand All @@ -454,6 +454,15 @@ root {
}
```

If no node arguments are defined then the wait node will remain in the running state indefinitely until it is aborted.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=wait)

```
root {
wait
}
```

### Branch
Named root nodes can be referenced using the **branch** node. This node acts as a placeholder that will be replaced by the child node of the referenced root node. The two definitions below are synonymous.

Expand Down Expand Up @@ -531,14 +540,14 @@ root {
```

## Guards
A guard defines a condition that must be met in order for the node to remain active. Any running nodes will have their guard condition evaluated for each leaf node update, and will move to a failed state if the guard condition is not met.
A guard defines a condition that must be met in order for the associated node to remain active. Any running nodes will have their guard condition evaluated for each leaf node update, and will move to a failed state if the guard condition is not met.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=guards)

This functionality is useful as a means of aborting long running actions or branches that span across multiple steps of the tree.

```
root {
wait [10000] while(CanWait)
wait while(CanWait)
}
```

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export type ConditionAstNode = LeafAstNode<Condition> & {
export type WaitAstNode = LeafAstNode<Wait> & {
type: "wait";
duration: number | null;
longestDuration: number | null;
durationMin: number | null;
durationMax: number | null;
};
export type AnyAstNode = BranchAstNode | CompositeAstNode | LottoAstNode | DecoratorAstNode | RootAstNode | IterableAstNode | LeafAstNode | ActionAstNode | ConditionAstNode | WaitAstNode;
/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions dist/attributes/guards/timeout.d.ts

This file was deleted.

82 changes: 54 additions & 28 deletions dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/bundle.js.map

Large diffs are not rendered by default.

82 changes: 54 additions & 28 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions dist/nodes/leaf/wait.d.ts → dist/nodes/leaf/Wait.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { BehaviourTreeOptions } from "../../BehaviourTreeOptions";
*/
export default class Wait extends Leaf {
private duration;
private longestDuration;
private durationMin;
private durationMax;
/**
* @param attributes The node attributes.
* @param duration The duration that this node will wait to succeed in milliseconds, or the earliest if longestDuration is defined.
* @param longestDuration The longest possible duration in milliseconds that this node will wait to succeed.
* @param durationMin The minimum possible duration in milliseconds that this node will wait to succeed.
* @param durationMax The maximum possible duration in milliseconds that this node will wait to succeed.
*/
constructor(attributes: Attribute[], duration: number, longestDuration: number);
constructor(attributes: Attribute[], duration: number | null, durationMin: number | null, durationMax: number | null);
/**
* The time in milliseconds at which this node was first updated.
*/
Expand Down
Loading

0 comments on commit d4cc971

Please sign in to comment.