-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 fix limiter node behaviour #250
Changes from 2 commits
3a1c228
f993891
81c2ca0
b8e0763
319eb1e
3822aed
c8b2960
1cb45b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ class_name LimiterDecorator extends Decorator | |
@export var max_count : float = 0 | ||
|
||
func tick(actor: Node, blackboard: Blackboard) -> int: | ||
var child = self.get_child(0) | ||
if not get_child_count(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if for whatever reason there is no child node added to this node, we should skip this behaviour (and show a configuration warning) |
||
return FAILURE | ||
|
||
var child = get_child(0) | ||
var current_count = blackboard.get_value(cache_key, 0, str(actor.get_instance_id())) | ||
|
||
if current_count == 0: | ||
|
@@ -29,9 +32,13 @@ func tick(actor: Node, blackboard: Blackboard) -> int: | |
if child is ActionLeaf and response == RUNNING: | ||
running_child = child | ||
blackboard.set_value("running_action", child, str(actor.get_instance_id())) | ||
|
||
|
||
if response != RUNNING: | ||
child.after_run(actor, blackboard) | ||
|
||
return response | ||
else: | ||
interrupt(actor, blackboard) | ||
child.after_run(actor, blackboard) | ||
return FAILURE | ||
|
||
|
@@ -40,3 +47,9 @@ func get_class_name() -> Array[StringName]: | |
var classes := super() | ||
classes.push_back(&"LimiterDecorator") | ||
return classes | ||
|
||
|
||
func _get_configuration_warnings() -> PackedStringArray: | ||
if not get_child_count(): | ||
return ["Requires at least one child node"] | ||
return [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,22 @@ class_name TimeLimiterDecorator extends Decorator | |
|
||
@export var wait_time: = 0.0 | ||
|
||
var time_left: = 0.0 | ||
|
||
@onready var child: BeehaveNode = get_child(0) | ||
@onready var cache_key = 'time_limiter_%s' % self.get_instance_id() | ||
|
||
|
||
func tick(actor: Node, blackboard: Blackboard) -> int: | ||
if not get_child_count(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if for whatever reason there is no child node added to this node, we should skip this behaviour (and show a configuration warning) |
||
return FAILURE | ||
|
||
var child = self.get_child(0) | ||
var time_left = blackboard.get_value(cache_key, 0.0, str(actor.get_instance_id())) | ||
|
||
if time_left == 0.0 and get_child_count() > 0: | ||
get_child(0).before_run(actor, blackboard) | ||
|
||
if time_left < wait_time: | ||
time_left += get_physics_process_delta_time() | ||
blackboard.set_value(cache_key, time_left, str(actor.get_instance_id())) | ||
var response = child.tick(actor, blackboard) | ||
if can_send_message(blackboard): | ||
BeehaveDebuggerMessages.process_tick(child.get_instance_id(), response) | ||
|
@@ -28,20 +36,22 @@ func tick(actor: Node, blackboard: Blackboard) -> int: | |
running_child = child | ||
if child is ActionLeaf: | ||
blackboard.set_value("running_action", child, str(actor.get_instance_id())) | ||
|
||
else: | ||
child.after_run(actor, blackboard) | ||
return response | ||
else: | ||
child.after_run(actor, blackboard) | ||
interrupt(actor, blackboard) | ||
child.after_run(actor, blackboard) | ||
return FAILURE | ||
|
||
|
||
func before_run(actor: Node, blackboard: Blackboard) -> void: | ||
bitbrain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
time_left = 0.0 | ||
child.before_run(actor, blackboard) | ||
|
||
|
||
func get_class_name() -> Array[StringName]: | ||
var classes := super() | ||
classes.push_back(&"TimeLimiterDecorator") | ||
return classes | ||
|
||
|
||
func _get_configuration_warnings() -> PackedStringArray: | ||
if not get_child_count(): | ||
return ["Requires at least one child node"] | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was a scenario where you can set a
null
actor on a behaviour tree. In this case, the tree should not break the game but show a configuration warning.