improve debug manager

This commit is contained in:
2024-10-16 14:25:56 +10:00
parent 460581ce12
commit fc7cb75b23
4 changed files with 57 additions and 40 deletions

View File

@@ -11,10 +11,10 @@ var enabled: bool = false
var _control: Control = Control.new() var _control: Control = Control.new()
var _label: RichTextLabel = RichTextLabel.new() var _label: RichTextLabel = RichTextLabel.new()
var _vectors_to_draw: Array[Dictionary] = [] var _vectors_to_draw: Dictionary = {}
var _markers_to_draw: Array[Dictionary] = [] var _markers_to_draw: Dictionary = {}
var _circles_to_draw: Array[Dictionary] = [] var _circles_to_draw: Dictionary = {}
var _text_to_draw: PackedStringArray = [] var _text_to_draw: Dictionary = {}
func _ready() -> void: func _ready() -> void:
@@ -35,34 +35,39 @@ func _process(_delta: float) -> void:
return return
_control.queue_redraw() _control.queue_redraw()
text("fps: " + str(Performance.get_monitor(Performance.TIME_FPS))) text("fps", str(Engine.get_frames_per_second()))
text("draw calls: " + str(Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME))) text("draw calls", str(Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME)))
text("camera anim step: " + str(StaticNodesManager.main_camera.advance_anim_step)) text("camera anim step", str(StaticNodesManager.main_camera.advance_anim_step))
text("select anim step: " + str(SelectionManager.advance_anim_step)) text("select anim step", str(SelectionManager.advance_anim_step))
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_debug"): if event.is_action_pressed("toggle_debug"):
enabled = not enabled enabled = not enabled
visible = enabled visible = enabled
_vectors_to_draw.clear()
func text(body: String) -> void: func text(key: String, value: String) -> void:
if not enabled: if not enabled:
return return
_text_to_draw.append(body) _text_to_draw[key] = value
func vector(from: Vector3, to: Vector3, color: Color = DEFAULT_COLOR) -> void: func vector(
key: String,
from: Vector3,
to: Vector3,
color: Color = DEFAULT_COLOR,
) -> void:
if not enabled: if not enabled:
return return
_vectors_to_draw.append({"from": from, "to": to, "color": color}) _vectors_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
func marker( func marker(
key: String,
pos: Vector3, pos: Vector3,
radius: float = MARKER_RADIUS, radius: float = MARKER_RADIUS,
color: Color = DEFAULT_COLOR, color: Color = DEFAULT_COLOR,
@@ -70,22 +75,26 @@ func marker(
if not enabled: if not enabled:
return return
_markers_to_draw.append({"pos": pos, "radius": radius, "color": color}) _markers_to_draw[key] = {"pos": pos, "radius": radius, "color": color, "on": true}
func circle(pos: Vector3, color: Color = DEFAULT_COLOR) -> void: func circle(
key: String,
pos: Vector3,
color: Color = DEFAULT_COLOR,
) -> void:
if not enabled: if not enabled:
return return
_circles_to_draw.append({"pos": pos, "color": color}) _circles_to_draw[key] = {"pos": pos, "color": color, "on": true}
func _unproject(pos: Vector3) -> Vector2: func _unproject(pos: Vector3) -> Vector2:
return StaticNodesManager.main_camera.unproject_position(pos) return StaticNodesManager.main_camera.unproject_position(pos)
func _draw_text() -> void: func _draw_text(key: String, value: String) -> void:
_label.text = "\n".join(_text_to_draw) _label.text += key + ": " + value + "\n"
func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void: func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
@@ -131,25 +140,30 @@ func _on_control_draw() -> void:
if not enabled: if not enabled:
return return
for v in _vectors_to_draw: for v: Dictionary in _vectors_to_draw.values():
_draw_vector( if v["on"]:
v["from"] as Vector3, _draw_vector(
v["to"] as Vector3, v["from"] as Vector3,
v["color"] as Color, v["to"] as Vector3,
) v["color"] as Color,
_vectors_to_draw.clear() )
v["on"] = false
for v in _markers_to_draw: for v: Dictionary in _markers_to_draw.values():
_draw_marker( if v["on"]:
v["pos"] as Vector3, _draw_marker(
v["radius"] as float, v["pos"] as Vector3,
v["color"] as Color, v["radius"] as float,
) v["color"] as Color,
_markers_to_draw.clear() )
v["on"] = false
for v in _circles_to_draw: for v: Dictionary in _circles_to_draw.values():
_draw_circle(v["pos"] as Vector3, v["color"] as Color) if v["on"]:
_circles_to_draw.clear() _draw_circle(v["pos"] as Vector3, v["color"] as Color)
v["on"] = false
_draw_text() _label.text = ""
_text_to_draw.clear() for k: String in _text_to_draw.keys():
var v: String = _text_to_draw[k]
_draw_text(k, v)

View File

@@ -86,8 +86,8 @@ func _process(delta: float) -> void:
listener.global_position = _target_position + (Vector3.UP * distance) listener.global_position = _target_position + (Vector3.UP * distance)
listener.global_rotation = global_rotation listener.global_rotation = global_rotation
DebugManager.marker(_target_position, 0.05) DebugManager.marker("mc_target", _target_position, 0.05)
DebugManager.marker(listener.global_position, 0.05, Color.GREEN) DebugManager.marker("mc_listener", listener.global_position, 0.05, Color.GREEN)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:

View File

@@ -85,6 +85,9 @@ func _handle_navigation() -> void:
var new_velocity := direction * _move_speed var new_velocity := direction * _move_speed
nav_agent.set_velocity(new_velocity) nav_agent.set_velocity(new_velocity)
if visibility_notifier.is_on_screen():
DebugManager.vector("nav" + str(get_instance_id()), global_position, next_pos, Color.BLUE)
func _handle_animation(delta: float) -> void: func _handle_animation(delta: float) -> void:
if not visibility_notifier.is_on_screen(): if not visibility_notifier.is_on_screen():

View File

@@ -59,7 +59,7 @@ func _process(_delta: float) -> void:
) )
if _target != null: if _target != null:
DebugManager.circle(_target.global_position) DebugManager.circle("gather_targ", _target.global_position)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void: