Update broadphase performance test in physics tests

Start logging physics tick one frame earlier for each operation
Disable debug collision to avoid rendering bottleneck
Fixes in adding/removing bodies to avoid bottlenecks outside of physics
2D: Increase message queue size to allow adding more objects at once
3D: Remove camera to disable rendering altogether
3D: Fix error with create_rigidbody_box missing default value
This commit is contained in:
PouleyKetchoupp
2021-01-20 09:44:21 -07:00
parent 5618c2b45a
commit 1c1ad17b43
8 changed files with 66 additions and 34 deletions

View File

@@ -73,6 +73,10 @@ toggle_pause={
]
}
[memory]
limits/message_queue/max_size_kb=10240
[rendering]
quality/driver/driver_name="GLES2"

View File

@@ -4,6 +4,8 @@ extends Node2D
signal wait_done()
export var _enable_debug_collision = true
var _timer
var _timer_started = false
@@ -21,6 +23,11 @@ class Circle2D:
var _drawn_nodes = []
func _enter_tree():
if not _enable_debug_collision:
get_tree().debug_collisions_hint = false
func _physics_process(_delta):
if _wait_physics_ticks_counter > 0:
_wait_physics_ticks_counter -= 1

View File

@@ -15,9 +15,14 @@ var _log_physics_time_start = 0
func _ready():
_create_objects()
yield(start_timer(1.0), "timeout")
if is_timer_canceled():
return
_log_physics_start()
_create_objects()
yield(wait_for_physics_ticks(5), "wait_done")
_log_physics_stop()
@@ -25,9 +30,10 @@ func _ready():
if is_timer_canceled():
return
_log_physics_start()
_add_objects()
_log_physics_start()
yield(wait_for_physics_ticks(5), "wait_done")
_log_physics_stop()
@@ -35,9 +41,10 @@ func _ready():
if is_timer_canceled():
return
_log_physics_start()
_move_objects()
_log_physics_start()
yield(wait_for_physics_ticks(5), "wait_done")
_log_physics_stop()
@@ -45,9 +52,10 @@ func _ready():
if is_timer_canceled():
return
_log_physics_start()
_remove_objects()
_log_physics_start()
yield(wait_for_physics_ticks(5), "wait_done")
_log_physics_stop()
@@ -85,9 +93,6 @@ func _log_physics_stop():
func _create_objects():
_objects.clear()
var template_body = create_rigidbody_box(BOX_SIZE)
template_body.gravity_scale = 0.0
Log.print_log("* Creating objects...")
var timer = OS.get_ticks_usec()
@@ -97,9 +102,10 @@ func _create_objects():
var pos_y = -0.5 * (column_size - 1) * BOX_SPACE.y
for column in column_size:
var box = template_body.duplicate()
# Create a new object and shape every time to avoid the overhead of connecting many bodies to the same shape.
var box = create_rigidbody_box(BOX_SIZE)
box.gravity_scale = 0.0
box.position = Vector2(pos_x, pos_y)
box.name = "Box%03d" % (row * column + 1)
_objects.push_back(box)
pos_y += BOX_SPACE.y
@@ -109,8 +115,6 @@ func _create_objects():
timer = OS.get_ticks_usec() - timer
Log.print_log(" Create Time: %.3f ms" % (0.001 * timer))
template_body.queue_free()
func _add_objects():
var root_node = $Objects
@@ -142,8 +146,10 @@ func _remove_objects():
Log.print_log("* Removing objects...")
var timer = OS.get_ticks_usec()
for object in _objects:
root_node.remove_child(object)
# Remove objects in reversed order to avoid the overhead of changing children index in parent.
var object_count = _objects.size()
for object_index in object_count:
root_node.remove_child(_objects[object_count - object_index - 1])
timer = OS.get_ticks_usec() - timer
Log.print_log(" Remove Time: %.3f ms" % (0.001 * timer))

View File

@@ -4,6 +4,9 @@
[node name="Test" type="Node2D"]
script = ExtResource( 1 )
_enable_debug_collision = false
row_size = 300
column_size = 300
[node name="Objects" type="Node2D" parent="."]
position = Vector2( 512, 300 )