Skip to content

Add Debug2D singleton - #162

Merged
Xrayez merged 29 commits into
gd3from
debug-2d
Dec 5, 2021
Merged

Xrayez merged 29 commits into
gd3from
debug-2d

Conversation

@Xrayez

@Xrayez Xrayez commented Dec 3, 2021 •

Copy link
Copy Markdown
Contributor

See discussion #161, this is meant to resolve godotengine/godot-proposals#112, resolve godotengine/godot-proposals#5196.

Notable features include:

  • Draw outside _draw() calls.
  • Make snapshots of draw commands and play them back (useful for visualization).
  • Inject draw calls to custom objects (can still override _draw() for each node if needed).
  • Call custom draw methods defined via script.

To-do

  • Implement useful draw methods.
  • Rewrite or adapt the drawing API to remove bloat for parameters which are used often like color, line width, filled etc (via draw_set_color(), draw_set_filled()).
  • Add tags in order to filter captured draw commands (?)
  • Add project settings for configuring default draw parameters.

Example

extends Node2D

func _ready():
	Debug2D.draw_circle(32, Vector2(), Color.orange)
	Debug2D.capture()

	Debug2D.canvas_item = $RigidBody2D
	Debug2D.draw_circle(32, Vector2(), Color.orange)
	Debug2D.capture()

	Debug2D.canvas_item = Debug2D.get_base()
	Debug2D.draw("rect", [Rect2(0, 0, 100, 100), Color.steelblue])
    Debug2D.draw_circle(32, Vector2(), Color.orange)
	Debug2D.capture()

func _input(event):
	if event.is_action_pressed("ui_left"):
		Debug2D.get_capture().draw_prev()
	elif event.is_action_pressed("ui_right"):
		Debug2D.get_capture().draw_next()

	if event.is_action_pressed("ui_cancel"):
		Debug2D.get_capture().reset()

Test project
debug_2d.zip

@Xrayez Xrayez added feature 💡 New feature proposal topic:core labels Dec 3, 2021
@Xrayez Xrayez added this to the 1.2-gd3 milestone Dec 3, 2021
Xrayez added 23 commits December 4, 2021 14:08
Less bloat, more clarity. The class may be eventually adapted for `Debug3D` usages as well.
Allows to draw snapshots individually if `accumulate = false`.

Initialize canvas item at constructor, otherwise leads to crashes.
This was used to replicate `accumulate` functionality, not needed anymore.
Allows to submit draw commands to arbitrary objects which extend `CanvasItem`.
Due to this, added `get_base()` in order to reset current canvas with the default one.
There are other methods that could be compiled out, but we have to be careful about assumptions regarding what kind of functions are required in release logic.
Better reflects `CanvasItem` API. But not sure if needed in the first place, because this should rather be not modified for all commands and could lead to confusion.
This is meant to be configured per method call, does not make much sense to override this.

Instead, `draw_set_transform()` will be added.
Disabled by default. May look bad with transparent colors.
No need to instantiate a `Control` node to draw a string with default font...
Added `enabled ` property as well.
The `draw_rect()` method used used to draw regions for the most part. This also makes it consistent with other methods in Goost such as `Random2D.point_in_region()`.

The method is renamed because of `draw_rectangle()` which is going to be implemented to draw rectangular shapes. Again, this would correspond to methods such as `GoostGeometry2D.rectangle()`.
@Xrayez

Xrayez commented Dec 5, 2021

Copy link
Copy Markdown
Contributor Author

Implemented draw_arrow() now.

image

Pushed a snippet in GDScript which I used during prototyping, in case modifications are needed: goostengine/goost-plugins@354d4a0

Works better some use cases, especially when antialiasing is enabled.
@Xrayez
Xrayez marked this pull request as ready for review December 5, 2021 20:04
@Xrayez

Xrayez commented Dec 5, 2021

Copy link
Copy Markdown
Contributor Author

I'm more or less satisfied with current API. Further enhancements and changes are fine to make further down the road because it only affects debug builds.

Things to do:

@Xrayez
Xrayez merged commit ca9d585 into gd3 Dec 5, 2021
@Xrayez
Xrayez deleted the debug-2d branch December 5, 2021 20:08
@Xrayez Xrayez mentioned this pull request Jan 29, 2022
4 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add singletons for 2D and 3D debug drawing Add support for immediate-mode debug drawing

1 participant