mirror of
https://github.com/godotengine/godot-benchmarks.git
synced 2026-09-03 18:14:28 +03:00
Tests were arranging objects in window rather than viewport coordinates. This was causing performance changes based on window scale.
66 lines
1.7 KiB
GDScript
66 lines
1.7 KiB
GDScript
extends Benchmark
|
|
|
|
const SPEED := 300.0
|
|
const JUMP_VELOCITY := -400.0
|
|
|
|
|
|
class TestScene:
|
|
extends Node2D
|
|
|
|
var tile_map_scene := preload("res://supplemental/tilemap_scene.tscn")
|
|
var tile_map_node: Node2D
|
|
var n_of_character_bodies: int
|
|
var character_bodies: Array[CharacterBody2D] = []
|
|
var capsule_mesh := CapsuleMesh.new()
|
|
var viewport_size: Vector2
|
|
|
|
func _init(_n_of_character_bodies: int) -> void:
|
|
n_of_character_bodies = _n_of_character_bodies
|
|
capsule_mesh.radius = 10.0
|
|
capsule_mesh.height = 28.0
|
|
|
|
func _ready() -> void:
|
|
viewport_size = get_viewport_rect().size
|
|
tile_map_node = tile_map_scene.instantiate()
|
|
add_child(tile_map_node)
|
|
for i in n_of_character_bodies:
|
|
var body := CharacterBody2D.new()
|
|
body.position = Vector2(
|
|
randf_range(0.0, viewport_size.x), randf_range(0.0, viewport_size.y)
|
|
)
|
|
var collision_shape := CollisionShape2D.new()
|
|
collision_shape.shape = CapsuleShape2D.new()
|
|
body.add_child(collision_shape)
|
|
if Manager.visualize:
|
|
var mesh_instance := MeshInstance2D.new()
|
|
mesh_instance.mesh = capsule_mesh
|
|
body.add_child(mesh_instance)
|
|
tile_map_node.add_child(body)
|
|
character_bodies.append(body)
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
for body in character_bodies:
|
|
if not body.is_on_floor():
|
|
body.velocity += body.get_gravity() * delta
|
|
|
|
if body.is_on_floor():
|
|
body.velocity.y = JUMP_VELOCITY
|
|
|
|
var direction := randf_range(-1.0, 1.0)
|
|
if direction:
|
|
body.velocity.x = direction * SPEED
|
|
else:
|
|
body.velocity.x = move_toward(body.velocity.x, 0, SPEED)
|
|
|
|
body.move_and_slide()
|
|
|
|
|
|
func _init() -> void:
|
|
benchmark_time = 10e6
|
|
test_physics = true
|
|
test_idle = true
|
|
|
|
|
|
func benchmark_1000_character_bodies_2d() -> TestScene:
|
|
return TestScene.new(1000)
|