Improve style in many demos (#1263)

This commit is contained in:
Aaron Franke
2025-10-11 05:03:59 -07:00
committed by GitHub
parent 0ae09b7e5a
commit 520b4a7870
197 changed files with 904 additions and 766 deletions

View File

@@ -96,10 +96,10 @@ character_jump={
[physics]
3d/physics_engine="Jolt Physics"
jolt_physics_3d/limits/temporary_memory_buffer_size=128
jolt_physics_3d/limits/temporary_memory_buffer_size=256
jolt_physics_3d/limits/max_bodies=262144
jolt_physics_3d/limits/max_body_pairs=262144
jolt_physics_3d/limits/max_contact_constraints=262144
jolt_physics_3d/limits/max_contact_constraints=524288
common/physics_interpolation=true
[rendering]

View File

@@ -1,17 +1,19 @@
class_name Test
extends Node
signal wait_done()
@export var _enable_debug_collision := true
@export var _enable_debug_collision: bool = true
var _timer: Timer
var _timer_started := false
var _timer_started: bool = false
var _wait_physics_ticks_counter := 0
var _wait_physics_ticks_counter: int = 0
var _drawn_nodes: Array[Node3D] = []
func _enter_tree() -> void:
if not _enable_debug_collision:
get_tree().debug_collisions_hint = false

View File

@@ -1,5 +1,6 @@
extends Test
const OPTION_TYPE_BOX = "Collision type/Box (1)"
const OPTION_TYPE_SPHERE = "Collision type/Sphere (2)"
const OPTION_TYPE_CAPSULE = "Collision type/Capsule (3)"
@@ -17,10 +18,11 @@ const OFFSET_RANGE = 3.0
@export var offset := Vector3.ZERO
var _update_collision := false
var _collision_test_index := 0
var _update_collision: bool = false
var _collision_test_index: int = 0
var _collision_shapes: Array[Shape3D] = []
func _ready() -> void:
_initialize_collision_shapes()
@@ -47,17 +49,17 @@ func _ready() -> void:
_update_collision = true
func _input(event: InputEvent) -> void:
if event is InputEventKey and event.pressed:
if event.keycode == KEY_1:
func _input(input_event: InputEvent) -> void:
if input_event is InputEventKey and input_event.pressed:
if input_event.keycode == KEY_1:
_on_option_selected(OPTION_TYPE_BOX)
elif event.keycode == KEY_2:
elif input_event.keycode == KEY_2:
_on_option_selected(OPTION_TYPE_SPHERE)
elif event.keycode == KEY_3:
elif input_event.keycode == KEY_3:
_on_option_selected(OPTION_TYPE_CAPSULE)
elif event.keycode == KEY_4:
elif input_event.keycode == KEY_4:
_on_option_selected(OPTION_TYPE_CYLINDER)
elif event.keycode == KEY_5:
elif input_event.keycode == KEY_5:
_on_option_selected(OPTION_TYPE_CONVEX_POLYGON)

View File

@@ -1,5 +1,6 @@
extends Test
const OPTION_JOINT_TYPE = "Joint Type/%s Joint (%d)"
const OPTION_TEST_CASE_BODIES_COLLIDE = "Test case/Attached bodies collide"
@@ -10,27 +11,28 @@ const OPTION_TEST_CASE_CHANGE_POSITIONS = "Test case/Set body positions after ad
const BOX_SIZE = Vector3(1.0, 1.0, 1.0)
var _update_joint := false
var _update_joint: bool = false
var _selected_joint: Joint3D
var _bodies_collide := false
var _world_attachement := false
var _dynamic_attachement := false
var _destroy_body := false
var _change_positions := false
var _bodies_collide: bool = false
var _world_attachement: bool = false
var _dynamic_attachement: bool = false
var _destroy_body: bool = false
var _change_positions: bool = false
var _joint_types: Dictionary[String, Joint3D] = {}
var _joint_types := {}
func _ready() -> void:
var options: OptionMenu = $Options
var joints: Node3D = $Joints
for joint_index in joints.get_child_count():
var joint_node := joints.get_child(joint_index)
var joint_node: Joint3D = joints.get_child(joint_index)
joint_node.visible = false
var joint_name := String(joint_node.name)
var joint_short := joint_name.substr(0, joint_name.length() - 5)
var option_name := OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
var joint_short: String = joint_name.substr(0, joint_name.length() - 5)
var option_name: String = OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
options.add_menu_item(option_name)
_joint_types[option_name] = joint_node
@@ -54,9 +56,9 @@ func _process(_delta: float) -> void:
$LabelJointType.text = "Joint Type: " + String(_selected_joint.name)
func _input(event: InputEvent) -> void:
if event is InputEventKey and event.pressed:
var joint_index: int = event.keycode - KEY_1
func _input(input_event: InputEvent) -> void:
if input_event is InputEventKey and input_event.pressed:
var joint_index: int = input_event.keycode - KEY_1
if joint_index >= 0 and joint_index < _joint_types.size():
_selected_joint = _joint_types.values()[joint_index]
_update_joint = true

View File

@@ -1,5 +1,6 @@
extends Test
const OPTION_BODY_TYPE = "Body Type/%s (%d)"
const OPTION_SLOPE = "Physics options/Stop on slope (Character only)"
@@ -14,21 +15,22 @@ const SHAPE_CYLINDER = "Collision shapes/Cylinder"
const SHAPE_SPHERE = "Collision shapes/Sphere"
const SHAPE_CONVEX = "Collision shapes/Convex"
var _slope := false
var _snap := false
var _friction := false
var _rough := false
var _animation_physics := false
var _slope: bool = false
var _snap: bool = false
var _friction: bool = false
var _rough: bool = false
var _animation_physics: bool = false
var _body_scene := {}
var _key_list := []
var _current_body_index := 0
var _current_body_key := ""
var _current_body_key: String = ""
var _current_body: PhysicsBody3D = null
var _body_type := ["CharacterBody3D", "RigidBody"]
var _shapes := {}
var _current_shape := ""
var _current_shape: String = ""
func _ready() -> void:
var options: OptionMenu = $Options
@@ -66,9 +68,9 @@ func _ready() -> void:
spawn_body_index(_current_body_index)
func _input(event: InputEvent) -> void:
if event is InputEventKey and not event.pressed:
var _index: int = event.keycode - KEY_1
func _input(input_event: InputEvent) -> void:
if input_event is InputEventKey and not input_event.pressed:
var _index: int = input_event.keycode - KEY_1
if _index >= 0 and _index < _key_list.size():
spawn_body_index(_index)

View File

@@ -1,11 +1,13 @@
extends Test
@export_range(1, 100) var height := 10
@export_range(1, 100) var width_max := 100
@export_range(1, 100) var depth_max := 1
@export_range(1, 100) var height: int = 10
@export_range(1, 100) var width_max: int = 100
@export_range(1, 100) var depth_max: int = 1
@export var box_size := Vector3(1.0, 1.0, 1.0)
@export var box_spacing := Vector3(0.0, 0.0, 0.0)
func _ready() -> void:
_create_pyramid()

View File

@@ -1,9 +1,10 @@
extends Test
const OPTION_TEST_CASE_HIT_FROM_INSIDE = "Test case/Hit from inside"
var _hit_from_inside := false
var _do_raycasts := false
var _hit_from_inside: bool = false
var _do_raycasts: bool = false
@onready var _raycast_visuals := ImmediateMesh.new()
@onready var _material := StandardMaterial3D.new()

View File

@@ -1,5 +1,6 @@
extends Test
const OPTION_BIG = "Floor options/Big"
const OPTION_SMALL = "Floor options/Small"
@@ -8,13 +9,14 @@ const SHAPE_CONVEX = "Collision shapes/Convex"
const SHAPE_BOX = "Collision shapes/Box"
var _dynamic_shapes_scene: PackedScene
var _floor_shapes := {}
var _floor_size := "Small"
var _floor_shapes: Dictionary[String, PackedScene] = {}
var _floor_size: String = "Small"
var _current_floor_name := SHAPE_CONCAVE
var _current_bodies: Node3D
var _current_floor: Node3D
func _ready() -> void:
var options: OptionMenu = $Options
_dynamic_shapes_scene = get_packed_scene($DynamicShapes/Bodies)

View File

@@ -1,11 +1,13 @@
extends Test
@export_range(1, 100) var height := 10
@export_range(1, 100) var width := 1
@export_range(1, 100) var depth := 1
@export_range(1, 100) var height: int = 10
@export_range(1, 100) var width: int = 1
@export_range(1, 100) var depth: int = 1
@export var box_size := Vector3(1.0, 1.0, 1.0)
@export var box_spacing := Vector3(0.0, 0.0, 0.0)
func _ready() -> void:
_create_stack()

View File

@@ -1,17 +1,19 @@
extends Test
const BOX_SIZE = Vector3(0.8, 0.8, 0.8)
const BOX_SPACE = Vector3(1.0, 1.0, 1.0)
@export_range(1, 1000) var row_size := 20
@export_range(1, 1000) var column_size := 20
@export_range(1, 1000) var depth_size := 20
@export_range(1, 1000) var row_size: int = 20
@export_range(1, 1000) var column_size: int = 20
@export_range(1, 1000) var depth_size: int = 20
var _objects: Array[Node3D] = []
var _log_physics := false
var _log_physics_time := 0
var _log_physics_time_start := 0
var _log_physics: bool = false
var _log_physics_time_usec: int = 0
var _log_physics_time_usec_start: int = 0
func _ready() -> void:
await start_timer(1.0).timeout
@@ -75,16 +77,16 @@ func _physics_process(delta: float) -> void:
if _log_physics:
var time := Time.get_ticks_usec()
var time_delta := time - _log_physics_time
var time_total := time - _log_physics_time_start
_log_physics_time = time
var time_delta := time - _log_physics_time_usec
var time_total := time - _log_physics_time_usec_start
_log_physics_time_usec = time
Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total])
func _log_physics_start() -> void:
_log_physics = true
_log_physics_time_start = Time.get_ticks_usec()
_log_physics_time = _log_physics_time_start
_log_physics_time_usec_start = Time.get_ticks_usec()
_log_physics_time_usec = _log_physics_time_usec_start
func _log_physics_stop() -> void:

View File

@@ -8,14 +8,14 @@ const OPTION_TYPE_CYLINDER = "Shape type/Cylinder"
const OPTION_TYPE_CONVEX = "Shape type/Convex"
@export var spawns: Array[NodePath] = []
@export var spawn_count := 100
@export var spawn_count: int = 100
@export var spawn_randomize := Vector3.ZERO
var _object_templates: Array[Node3D] = []
var _log_physics := false
var _log_physics_time := 0
var _log_physics_time_start := 0
var _log_physics: bool = false
var _log_physics_time_usec: int = 0
var _log_physics_time_usec_start: int = 0
func _ready() -> void:
await start_timer(0.5).timeout
@@ -48,16 +48,16 @@ func _physics_process(delta: float) -> void:
if _log_physics:
var time := Time.get_ticks_usec()
var time_delta := time - _log_physics_time
var time_total := time - _log_physics_time_start
_log_physics_time = time
var time_delta := time - _log_physics_time_usec
var time_total := time - _log_physics_time_usec_start
_log_physics_time_usec = time
Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total])
func _log_physics_start() -> void:
_log_physics = true
_log_physics_time_start = Time.get_ticks_usec()
_log_physics_time = _log_physics_time_start
_log_physics_time_usec_start = Time.get_ticks_usec()
_log_physics_time_usec = _log_physics_time_usec_start
func _log_physics_stop() -> void:

View File

@@ -2,8 +2,8 @@ extends OptionMenu
class TestData:
var id := ""
var scene_path := ""
var id: String = ""
var scene_path: String = ""
var _test_list: Array[TestData] = []

View File

@@ -1,26 +1,28 @@
extends Camera3D
const ROTATION_COEFF = 0.02
var _rotation_enabled := false
var _rotation_enabled: bool = false
var _rotation_pivot: Node3D
func _ready() -> void:
_initialize_pivot.call_deferred()
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_RIGHT:
_rotation_enabled = event.pressed
func _unhandled_input(input_event: InputEvent) -> void:
if input_event is InputEventMouseButton:
if input_event.button_index == MOUSE_BUTTON_RIGHT:
_rotation_enabled = input_event.pressed
return
if not _rotation_enabled:
return
if event is InputEventMouseMotion:
var rotation_delta: float = event.screen_relative.x
if input_event is InputEventMouseMotion:
var rotation_delta: float = input_event.screen_relative.x
_rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF)

View File

@@ -1,9 +1,11 @@
extends CharacterBody3D
@export var _stop_on_slopes := false
@export var use_snap := false
var _gravity := 20.0
@export var _stop_on_slopes: bool = false
@export var use_snap: bool = false
var _gravity: float = 20.0
func _physics_process(delta: float) -> void:
if is_on_floor():

View File

@@ -1,5 +1,6 @@
extends Control
const MAX_ENTRIES = 100
var _entry_template: Label

View File

@@ -1,10 +1,12 @@
extends Control
@export var world_offset := Vector3.ZERO
var _pos_offset: Vector2
var _attachment: Node3D
func _ready() -> void:
_pos_offset = position
_attachment = get_parent()

View File

@@ -1,7 +1,8 @@
extends Label
func _ready() -> void:
var engine_name := ""
var engine_name: String = ""
match System.get_physics_engine():
System.PhysicsEngine.GODOT_PHYSICS:
engine_name = "GodotPhysics 3D"

View File

@@ -1,4 +1,5 @@
extends Label
func _process(_delta: float) -> void:
text = "%d FPS (%.2f mspf)" % [Engine.get_frames_per_second(), 1000.0 / Engine.get_frames_per_second()]

View File

@@ -1,4 +1,5 @@
extends Label
func _process(_delta: float) -> void:
visible = get_tree().paused

View File

@@ -1,6 +1,7 @@
extends Label
var test_name := "":
var test_name: String = "":
set(value):
if (test_name != value):
return

View File

@@ -1,4 +1,5 @@
extends Label
func _process(_delta: float) -> void:
set_text("Godot Version: %s" % Engine.get_version_info().string)

View File

@@ -1,15 +1,17 @@
class_name OptionMenu
extends MenuButton
signal option_selected(item_path: String)
signal option_changed(item_path: String, checked: bool)
func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = false) -> void:
var path_elements := item_path.split("/", false)
var path_element_count := path_elements.size()
assert(path_element_count > 0)
var path := ""
var path: String = ""
var popup := get_popup()
for element_index in path_element_count - 1:
var popup_label := path_elements[element_index]

View File

@@ -1,15 +1,17 @@
extends RigidBody3D
var _dir := 1.0
var _distance := 10.0
var _walk_spd := 100.0
var _acceleration := 22.0
var _is_on_floor := false
var _dir: float = 1.0 # -1.0 or 1.0
var _distance: float = 10.0
var _walk_spd: float = 100.0
var _acceleration: float = 22.0
var _is_on_floor: bool = false
@onready var _forward := -transform.basis.z
@onready var _collision_shape := $CollisionShape
@onready var _material: StandardMaterial3D = $CollisionShape/MeshInstance3D.get_active_material(0)
func _ready() -> void:
if not _material:
_material = StandardMaterial3D.new()
@@ -24,20 +26,20 @@ func _process(_delta: float) -> void:
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
var delta := state.step
var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
var delta: float = state.step
var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
state.linear_velocity = state.linear_velocity.move_toward(velocity, _acceleration * delta)
if state.transform.origin.z < -_distance:
_dir = -1
_dir = -1.0
if state.transform.origin.z > _distance:
_dir = 1
_dir = 1.0
ground_check()
func ground_check() -> void:
var space_state := get_world_3d().direct_space_state
var space_state: PhysicsDirectSpaceState3D = get_world_3d().direct_space_state
var shape := PhysicsShapeQueryParameters3D.new()
shape.transform = _collision_shape.global_transform
shape.shape_rid = _collision_shape.shape.get_rid()

View File

@@ -1,30 +1,32 @@
extends RigidBody3D
const MOUSE_DELTA_COEFFICIENT = 0.01
const CAMERA_DISTANCE_COEFFICIENT = 0.2
var _picked := false
const MOUSE_DELTA_COEFFICIENT: float = 0.01
const CAMERA_DISTANCE_COEFFICIENT: float = 0.2
var _picked: bool = false
var _last_mouse_pos := Vector2.ZERO
var _mouse_pos := Vector2.ZERO
func _ready() -> void:
input_ray_pickable = true
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if not event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
func _input(any_input_event: InputEvent) -> void:
if any_input_event is InputEventMouseButton:
if not any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT:
_picked = false
if event is InputEventMouseMotion:
_mouse_pos = event.position
if any_input_event is InputEventMouseMotion:
_mouse_pos = any_input_event.position
func _input_event(_camera: Camera3D, event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
if event is InputEventMouseButton:
if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
func _input_event(_camera: Camera3D, any_input_event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
if any_input_event is InputEventMouseButton:
if any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT:
_picked = true
_mouse_pos = event.position
_mouse_pos = any_input_event.position
_last_mouse_pos = _mouse_pos

View File

@@ -1,6 +1,8 @@
extends ScrollContainer
@export var auto_scroll := false
@export var auto_scroll: bool = false
func _process(_delta: float) -> void:
if auto_scroll:

View File

@@ -1,5 +1,6 @@
extends Node
enum PhysicsEngine {
GODOT_PHYSICS,
JOLT_PHYSICS,
@@ -8,6 +9,7 @@ enum PhysicsEngine {
var _engine := PhysicsEngine.OTHER
func _enter_tree() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS

View File

@@ -1,5 +1,6 @@
extends Node
enum LogType {
LOG,
ERROR,
@@ -7,6 +8,7 @@ enum LogType {
signal entry_logged(message: String, type: LogType)
func print_log(message: String) -> void:
print(message)
entry_logged.emit(message, LogType.LOG)