Skip to content

Commit 13b656c

Browse files
authored
Add blackboard debugging (#368)
1 parent 9259e55 commit 13b656c

25 files changed

+154
-36
lines changed

addons/beehave/blackboard.gd

+3
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ func has_value(key: Variant, blackboard_name: String = DEFAULT) -> bool:
4949
func erase_value(key: Variant, blackboard_name: String = DEFAULT) -> void:
5050
if _data.has(blackboard_name):
5151
_data[blackboard_name][key] = null
52+
53+
func get_debug_data() -> Dictionary:
54+
return _data

addons/beehave/debug/debugger.gd

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func _capture(message: String, data: Array, session_id: int) -> bool:
2525
debugger_tab.unregister_tree(data[0])
2626
return true
2727
if message == "beehave:process_tick":
28-
debugger_tab.graph.process_tick(data[0], data[1])
28+
debugger_tab.graph.process_tick(data[0], data[1], data[2])
2929
return true
3030
if message == "beehave:process_begin":
31-
debugger_tab.graph.process_begin(data[0])
31+
debugger_tab.graph.process_begin(data[0], data[1])
3232
return true
3333
if message == "beehave:process_end":
34-
debugger_tab.graph.process_end(data[0])
34+
debugger_tab.graph.process_end(data[0], data[1])
3535
return true
3636
return false
3737

addons/beehave/debug/debugger_messages.gd

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ static func unregister_tree(instance_id: int) -> void:
1515
EngineDebugger.send_message("beehave:unregister_tree", [instance_id])
1616

1717

18-
static func process_tick(instance_id: int, status: int) -> void:
18+
static func process_tick(instance_id: int, status: int, blackboard: Dictionary = {}) -> void:
1919
if can_send_message():
20-
EngineDebugger.send_message("beehave:process_tick", [instance_id, status])
20+
EngineDebugger.send_message("beehave:process_tick", [instance_id, status, blackboard])
2121

2222

23-
static func process_begin(instance_id: int) -> void:
23+
static func process_begin(instance_id: int, blackboard: Dictionary = {}) -> void:
2424
if can_send_message():
25-
EngineDebugger.send_message("beehave:process_begin", [instance_id])
25+
EngineDebugger.send_message("beehave:process_begin", [instance_id, blackboard])
2626

2727

28-
static func process_end(instance_id: int) -> void:
28+
static func process_end(instance_id: int, blackboard: Dictionary = {}) -> void:
2929
if can_send_message():
30-
EngineDebugger.send_message("beehave:process_end", [instance_id])
30+
EngineDebugger.send_message("beehave:process_end", [instance_id, blackboard])

addons/beehave/debug/debugger_tab.gd

+33-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ signal make_floating
77

88
const OldBeehaveGraphEdit := preload("old_graph_edit.gd")
99
const NewBeehaveGraphEdit := preload("new_graph_edit.gd")
10+
const NewNodeBlackBoard := preload("new_node_blackboard.gd")
1011

1112
const TREE_ICON := preload("../icons/tree.svg")
1213

1314
var graph
1415
var container: HSplitContainer
16+
var graph_container: HSplitContainer
1517
var item_list: ItemList
18+
var blackboard_vbox: VBoxContainer
1619
var message: Label
1720

1821
var active_trees: Dictionary
@@ -28,12 +31,25 @@ func _ready() -> void:
2831
item_list.custom_minimum_size = Vector2(200, 0)
2932
item_list.item_selected.connect(_on_item_selected)
3033
container.add_child(item_list)
34+
35+
graph_container = HSplitContainer.new()
36+
graph_container.split_offset = 1920
37+
graph_container.set_anchors_preset(Control.PRESET_FULL_RECT)
38+
container.add_child(graph_container)
39+
3140
if Engine.get_version_info().minor >= 2:
3241
graph = NewBeehaveGraphEdit.new(BeehaveUtils.get_frames())
3342
else:
3443
graph = OldBeehaveGraphEdit.new(BeehaveUtils.get_frames())
3544

36-
container.add_child(graph)
45+
graph.node_selected.connect(_on_graph_node_selected)
46+
graph.node_deselected.connect(_on_graph_node_deselected)
47+
graph_container.add_child(graph)
48+
49+
blackboard_vbox = VBoxContainer.new()
50+
blackboard_vbox.custom_minimum_size = Vector2(200, 0)
51+
blackboard_vbox.set_anchors_preset(Control.PRESET_FULL_RECT)
52+
graph_container.add_child(blackboard_vbox)
3753

3854
message = Label.new()
3955
message.text = "Run Project for debugging"
@@ -115,10 +131,26 @@ func _on_item_selected(idx: int) -> void:
115131
var id: StringName = item_list.get_item_metadata(idx)
116132
graph.beehave_tree = active_trees.get(id, {})
117133

134+
# Clear our any loaded blackboards
135+
for child in blackboard_vbox.get_children():
136+
child.free()
137+
118138
active_tree_id = id.to_int()
119139
if session != null:
120140
session.send_message("beehave:activate_tree", [active_tree_id])
121141

142+
func _on_graph_node_selected(node: GraphNode) -> void:
143+
var node_blackboard: VBoxContainer = NewNodeBlackBoard.new(BeehaveUtils.get_frames(), node)
144+
blackboard_vbox.add_child(node_blackboard)
145+
146+
func _on_graph_node_deselected(node: GraphNode) -> void:
147+
var matches: Array = blackboard_vbox\
148+
.get_children()\
149+
.filter(func (child): return child.name == node.name)
150+
151+
for child in matches:
152+
child.free()
153+
122154

123155
func _on_visibility_changed() -> void:
124156
if session != null:

addons/beehave/debug/new_graph_edit.gd

+4-3
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,27 @@ func get_status(status: int) -> String:
150150
return "RUNNING"
151151

152152

153-
func process_begin(instance_id: int) -> void:
153+
func process_begin(instance_id: int, blackboard = null) -> void:
154154
if not _is_same_tree(instance_id):
155155
return
156156

157157
for child in _get_child_nodes():
158158
child.set_meta("status", -1)
159159

160160

161-
func process_tick(instance_id: int, status: int) -> void:
161+
func process_tick(instance_id: int, status: int, blackboard = null) -> void:
162162
var node := get_node_or_null(str(instance_id))
163163
if node:
164164
node.text = "Status: %s" % get_status(status)
165165
node.set_status(status)
166166
node.set_meta("status", status)
167+
node.blackboard = blackboard
167168
if status == BeehaveNode.SUCCESS or status == BeehaveNode.RUNNING:
168169
if not active_nodes.has(node.name):
169170
active_nodes.push_back(node.name)
170171

171172

172-
func process_end(instance_id: int) -> void:
173+
func process_end(instance_id: int, blackboard = null) -> void:
173174
if not _is_same_tree(instance_id):
174175
return
175176

addons/beehave/debug/new_graph_node.gd

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@tool
22
extends GraphNode
33

4+
signal blackboard_updated
45

56
const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd")
67

@@ -28,6 +29,11 @@ const PORT_RIGHT_ICON := preload("icons/port_right.svg")
2829
if icon_rect:
2930
icon_rect.texture = value
3031

32+
@export var blackboard: Dictionary:
33+
set(value):
34+
blackboard = value
35+
blackboard_updated.emit()
36+
3137
var layout_size: float:
3238
get:
3339
return size.y if horizontal else size.x
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
extends VBoxContainer
2+
3+
var frames: RefCounted
4+
var graph_node: GraphNode
5+
6+
var item_tree: Tree
7+
8+
func _init(frames: RefCounted, node: GraphNode) -> void:
9+
self.frames = frames
10+
graph_node = node
11+
12+
graph_node.blackboard_updated.connect(_update_list)
13+
14+
func _ready() -> void:
15+
name = graph_node.name
16+
17+
set_anchors_preset(Control.PRESET_FULL_RECT)
18+
19+
var title_panel: Panel = Panel.new()
20+
title_panel.set_anchors_preset(Control.PRESET_FULL_RECT)
21+
title_panel.custom_minimum_size = Vector2(200, 50)
22+
add_child(title_panel)
23+
var title_hbox: HBoxContainer = HBoxContainer.new()
24+
title_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
25+
title_hbox.set_anchors_preset(Control.PRESET_FULL_RECT)
26+
title_panel.add_child(title_hbox)
27+
28+
var icon_rect: TextureRect = TextureRect.new()
29+
icon_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
30+
icon_rect.texture = graph_node.icon
31+
icon_rect.set_size(Vector2(20, 20))
32+
title_hbox.add_child(icon_rect)
33+
34+
var title: Label = Label.new()
35+
title.text = graph_node.title_text
36+
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
37+
title.set_anchors_preset(Control.PRESET_FULL_RECT)
38+
title_hbox.add_child(title)
39+
40+
item_tree = Tree.new()
41+
item_tree.custom_minimum_size = Vector2(200, 400)
42+
item_tree.hide_root = true
43+
item_tree.allow_search = false
44+
item_tree.columns = 2
45+
add_child(item_tree)
46+
47+
_update_list()
48+
49+
func _update_list() -> void:
50+
item_tree.clear()
51+
52+
var root: TreeItem = item_tree.create_item()
53+
54+
if graph_node.blackboard.size() == 0:
55+
var no_bb_message: TreeItem = item_tree.create_item(root)
56+
no_bb_message.set_text(0, "No blackboard data")
57+
return
58+
59+
for bb_name in graph_node.blackboard:
60+
var bb_name_branch: TreeItem = item_tree.create_item(root)
61+
bb_name_branch.set_text(0, bb_name)
62+
63+
#print(graph_node.blackboard.get(bb_name))
64+
for key in graph_node.blackboard.get(bb_name):
65+
var bb_kv_leaf: TreeItem = item_tree.create_item(bb_name_branch)
66+
bb_kv_leaf.set_text(0, str(key))
67+
bb_kv_leaf.set_text(1, str(graph_node.blackboard.get(bb_name).get(key)))
68+
69+
func _get_icon(type: StringName) -> Texture2D:
70+
var classes := ProjectSettings.get_global_class_list()
71+
for c in classes:
72+
if c["class"] == type:
73+
var icon_path := c.get("icon", String())
74+
if not icon_path.is_empty():
75+
return load(icon_path)
76+
return null

addons/beehave/nodes/beehave_tree.gd

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ func _process_internally() -> void:
189189
blackboard.set_value("can_send_message", _can_send_message)
190190

191191
if _can_send_message:
192-
BeehaveDebuggerMessages.process_begin(get_instance_id())
192+
BeehaveDebuggerMessages.process_begin(get_instance_id(), blackboard.get_debug_data())
193193

194194
if self.get_child_count() == 1:
195195
tick()
196196

197197
if _can_send_message:
198-
BeehaveDebuggerMessages.process_end(get_instance_id())
198+
BeehaveDebuggerMessages.process_end(get_instance_id(), blackboard.get_debug_data())
199199

200200
# Check the cost for this frame and save it for metric report
201201
_process_time_metric_value = Time.get_ticks_usec() - start_time
@@ -210,8 +210,8 @@ func tick() -> int:
210210

211211
status = child.tick(actor, blackboard)
212212
if _can_send_message:
213-
BeehaveDebuggerMessages.process_tick(child.get_instance_id(), status)
214-
BeehaveDebuggerMessages.process_tick(get_instance_id(), status)
213+
BeehaveDebuggerMessages.process_tick(child.get_instance_id(), status, blackboard.get_debug_data())
214+
BeehaveDebuggerMessages.process_tick(get_instance_id(), status, blackboard.get_debug_data())
215215

216216
# Clear running action if nothing is running
217217
if status != RUNNING:

addons/beehave/nodes/composites/selector.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2020

2121
var response: int = c.tick(actor, blackboard)
2222
if can_send_message(blackboard):
23-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
23+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
2424

2525
if c is ConditionLeaf:
2626
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/selector_random.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
3030

3131
var response: int = c.tick(actor, blackboard)
3232
if can_send_message(blackboard):
33-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
33+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
3434

3535
if c is ConditionLeaf:
3636
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/selector_reactive.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
1515

1616
var response: int = c.tick(actor, blackboard)
1717
if can_send_message(blackboard):
18-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
18+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
1919

2020
if c is ConditionLeaf:
2121
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/sequence.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2121

2222
var response: int = c.tick(actor, blackboard)
2323
if can_send_message(blackboard):
24-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
24+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
2525

2626
if c is ConditionLeaf:
2727
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/sequence_random.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
3838

3939
var response: int = c.tick(actor, blackboard)
4040
if can_send_message(blackboard):
41-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
41+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
4242

4343
if c is ConditionLeaf:
4444
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/sequence_reactive.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2121

2222
var response: int = c.tick(actor, blackboard)
2323
if can_send_message(blackboard):
24-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
24+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
2525

2626
if c is ConditionLeaf:
2727
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/sequence_star.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2121

2222
var response: int = c.tick(actor, blackboard)
2323
if can_send_message(blackboard):
24-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
24+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
2525

2626
if c is ConditionLeaf:
2727
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/composites/simple_parallel.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func tick(actor, blackboard: Blackboard):
4646

4747
var response: int = c.tick(actor, blackboard)
4848
if can_send_message(blackboard):
49-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
49+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
5050

5151
delayed_result = response
5252
match response:

addons/beehave/nodes/decorators/cooldown.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2828
blackboard.set_value(cache_key, remaining_time, str(actor.get_instance_id()))
2929

3030
if can_send_message(blackboard):
31-
BeehaveDebuggerMessages.process_tick(self.get_instance_id(), response)
31+
BeehaveDebuggerMessages.process_tick(self.get_instance_id(), response, blackboard.get_debug_data())
3232
else:
3333
response = c.tick(actor, blackboard)
3434

3535
if can_send_message(blackboard):
36-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
36+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
3737

3838
if c is ConditionLeaf:
3939
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/decorators/delayer.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
2828
blackboard.set_value(cache_key, total_time, str(actor.get_instance_id()))
2929

3030
if can_send_message(blackboard):
31-
BeehaveDebuggerMessages.process_tick(self.get_instance_id(), response)
31+
BeehaveDebuggerMessages.process_tick(self.get_instance_id(), response, blackboard.get_debug_data())
3232
else:
3333
response = c.tick(actor, blackboard)
3434

3535
if can_send_message(blackboard):
36-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
36+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
3737

3838
if c is ConditionLeaf:
3939
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/decorators/failer.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
1313

1414
var response: int = c.tick(actor, blackboard)
1515
if can_send_message(blackboard):
16-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
16+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
1717

1818
if c is ConditionLeaf:
1919
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

addons/beehave/nodes/decorators/inverter.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func tick(actor: Node, blackboard: Blackboard) -> int:
1414

1515
var response: int = c.tick(actor, blackboard)
1616
if can_send_message(blackboard):
17-
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response)
17+
BeehaveDebuggerMessages.process_tick(c.get_instance_id(), response, blackboard.get_debug_data())
1818

1919
if c is ConditionLeaf:
2020
blackboard.set_value("last_condition", c, str(actor.get_instance_id()))

0 commit comments

Comments
 (0)