Add a behavior tree to the enemy
Add the Beehave addon. Make the enemy do the same thing as before but with a behavior tree.
This commit is contained in:
parent
09f6925a00
commit
1aed988149
92 changed files with 4025 additions and 25 deletions
54
addons/beehave/metrics/beehave_global_metrics.gd
Normal file
54
addons/beehave/metrics/beehave_global_metrics.gd
Normal file
|
@ -0,0 +1,54 @@
|
|||
extends Node
|
||||
|
||||
var _tree_count: int = 0
|
||||
var _active_tree_count: int = 0
|
||||
var _registered_trees: Array[BeehaveTree] = []
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
Performance.add_custom_monitor("beehave/total_trees", _get_total_trees)
|
||||
Performance.add_custom_monitor("beehave/total_enabled_trees", _get_total_enabled_trees)
|
||||
|
||||
|
||||
func register_tree(tree: BeehaveTree) -> void:
|
||||
if _registered_trees.has(tree):
|
||||
return
|
||||
|
||||
_registered_trees.append(tree)
|
||||
_tree_count += 1
|
||||
|
||||
if tree.enabled:
|
||||
_active_tree_count += 1
|
||||
|
||||
tree.tree_enabled.connect(_on_tree_enabled)
|
||||
tree.tree_disabled.connect(_on_tree_disabled)
|
||||
|
||||
|
||||
func unregister_tree(tree: BeehaveTree) -> void:
|
||||
if not _registered_trees.has(tree):
|
||||
return
|
||||
|
||||
_registered_trees.erase(tree)
|
||||
_tree_count -= 1
|
||||
|
||||
if tree.enabled:
|
||||
_active_tree_count -= 1
|
||||
|
||||
tree.tree_enabled.disconnect(_on_tree_enabled)
|
||||
tree.tree_disabled.disconnect(_on_tree_disabled)
|
||||
|
||||
|
||||
func _get_total_trees() -> int:
|
||||
return _tree_count
|
||||
|
||||
|
||||
func _get_total_enabled_trees() -> int:
|
||||
return _active_tree_count
|
||||
|
||||
|
||||
func _on_tree_enabled() -> void:
|
||||
_active_tree_count += 1
|
||||
|
||||
|
||||
func _on_tree_disabled() -> void:
|
||||
_active_tree_count -= 1
|
Loading…
Add table
Add a link
Reference in a new issue