From 36f2dcb5226ae07461529ed87c7de644bd71185e Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Tue, 11 Feb 2020 13:36:06 -0600 Subject: [PATCH] Handle all warnings in GSAI* classes and demos --- CHANGELOG.md | 4 ++++ project/demos/AvoidCollisions/Avoider.gd | 4 ++-- project/demos/DemoPickerUI.gd | 3 +++ project/demos/DemoSelector.tscn | 3 +++ project/demos/Demos.gd | 2 ++ project/demos/Face/FaceDemo.gd | 1 - project/demos/Face/Player.gd | 2 +- project/demos/PopulateItemList.gd | 1 + project/demos/PursueSeek/BoundaryManager.gd | 2 +- project/demos/PursueSeek/Player.gd | 10 +++++----- project/demos/SeekFlee/Player.gd | 3 ++- project/project.godot | 4 ---- project/src/Agents/GSAIKinematicBody2DAgent.gd | 12 +++++++----- project/src/Agents/GSAIKinematicBody3DAgent.gd | 14 ++++++++------ project/src/Agents/GSAIRigidBody2DAgent.gd | 11 ++++++----- project/src/Agents/GSAIRigidBody3DAgent.gd | 14 ++++++++------ project/src/Behaviors/GSAIArrive.gd | 4 ++-- project/src/Behaviors/GSAIFollowPath.gd | 12 ++++++------ project/src/Behaviors/GSAIMatchOrientation.gd | 4 ++-- project/src/Behaviors/GSAIPriority.gd | 4 ++-- project/src/Behaviors/GSAIPursue.gd | 8 ++++---- project/src/Behaviors/GSAISeek.gd | 4 ++-- project/src/Behaviors/GSAISeparation.gd | 1 + project/src/GSAIGroupBehavior.gd | 4 ++-- project/src/GSAIPath.gd | 12 ++++++------ project/src/Proximities/GSAIProximity.gd | 6 +++--- project/src/Proximities/GSAIRadiusProximity.gd | 4 ++-- 27 files changed, 85 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68cc1f8..ccdc033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ We decided to make this change as soon as possible, as the framework was release - There is now a main scene with a demo picker, so you can select and play any demo on the fly. - The demo projects now support resizing and toggling fullscreen with F11. +### Improvements ### + +- We handled all warnings in the framework, so using it won't add warnings to your projects. + ### Changes ### - Renamed all classes from `GST*` (Godot Steering Toolkit) to `GSAI*` (Godot Steering AI). diff --git a/project/demos/AvoidCollisions/Avoider.gd b/project/demos/AvoidCollisions/Avoider.gd index c47ff2b..77ce65f 100644 --- a/project/demos/AvoidCollisions/Avoider.gd +++ b/project/demos/AvoidCollisions/Avoider.gd @@ -40,7 +40,7 @@ func setup( proximity_radius: float, boundary_right: float, boundary_bottom: float, - draw_proximity: bool, + _draw_proximity: bool, rng: RandomNumberGenerator ) -> void: rng.randomize() @@ -58,7 +58,7 @@ func setup( agent.linear_drag_percentage = _drag - self.draw_proximity = draw_proximity + self.draw_proximity = _draw_proximity priority.add(avoid) priority.add(seek) diff --git a/project/demos/DemoPickerUI.gd b/project/demos/DemoPickerUI.gd index 1de7ac3..ec98ec4 100644 --- a/project/demos/DemoPickerUI.gd +++ b/project/demos/DemoPickerUI.gd @@ -12,8 +12,11 @@ onready var button: Button = $VBoxContainer/Button func _ready() -> void: + # warning-ignore:return_value_discarded list.connect("demo_selected", self, "set_demo_path") + # warning-ignore:return_value_discarded list.connect("item_activated", self, "emit_signal", ["demo_requested"]) + # warning-ignore:return_value_discarded button.connect("pressed", self, "emit_signal", ["demo_requested"]) demo_path = list.file_paths[0] diff --git a/project/demos/DemoSelector.tscn b/project/demos/DemoSelector.tscn index d918c18..c2c03dc 100644 --- a/project/demos/DemoSelector.tscn +++ b/project/demos/DemoSelector.tscn @@ -18,6 +18,9 @@ anchor_right = 1.0 anchor_bottom = 1.0 theme = ExtResource( 2 ) script = ExtResource( 4 ) +__meta__ = { +"_edit_use_anchors_": false +} [node name="TextureRect" type="TextureRect" parent="DemoPickerUI"] anchor_right = 1.0 diff --git a/project/demos/Demos.gd b/project/demos/Demos.gd index d8d8f89..c46e081 100644 --- a/project/demos/Demos.gd +++ b/project/demos/Demos.gd @@ -7,7 +7,9 @@ onready var button_go_back: Button = $ButtonGoBack func _ready() -> void: + # warning-ignore:return_value_discarded demo_picker.connect("demo_requested", self, "_on_DemoPickerUI_demo_requested") + # warning-ignore:return_value_discarded button_go_back.connect("pressed", self, "_on_ButtonGoBack_pressed") diff --git a/project/demos/Face/FaceDemo.gd b/project/demos/Face/FaceDemo.gd index e426ca7..a3ae399 100644 --- a/project/demos/Face/FaceDemo.gd +++ b/project/demos/Face/FaceDemo.gd @@ -8,7 +8,6 @@ export(int, 0, 359, 2) var deceleration_radius := 45 setget set_deceleration_rad export(float, 0, 1000, 40) var player_speed := 600.0 setget set_player_speed onready var player := $Player -onready var gui := $GUI onready var turret := $Turret diff --git a/project/demos/Face/Player.gd b/project/demos/Face/Player.gd index 09d4576..9620299 100644 --- a/project/demos/Face/Player.gd +++ b/project/demos/Face/Player.gd @@ -6,7 +6,7 @@ var speed: float onready var agent := GSAIAgentLocation.new() -func _physics_process(delta: float) -> void: +func _physics_process(_delta: float) -> void: var movement := _get_movement() move_and_slide(movement * speed) agent.position = Vector3(global_position.x, global_position.y, 0) diff --git a/project/demos/PopulateItemList.gd b/project/demos/PopulateItemList.gd index 6029aa5..2f92cc4 100644 --- a/project/demos/PopulateItemList.gd +++ b/project/demos/PopulateItemList.gd @@ -7,6 +7,7 @@ var file_paths := PoolStringArray() func _ready() -> void: + # warning-ignore:return_value_discarded self.connect("item_selected", self, "_on_item_selected") var this_directory: String = get_tree().current_scene.filename.rsplit("/", false, 1)[0] diff --git a/project/demos/PursueSeek/BoundaryManager.gd b/project/demos/PursueSeek/BoundaryManager.gd index 1887f39..311a195 100644 --- a/project/demos/PursueSeek/BoundaryManager.gd +++ b/project/demos/PursueSeek/BoundaryManager.gd @@ -12,6 +12,6 @@ func _ready() -> void: ) -func _physics_process(delta: float) -> void: +func _physics_process(_delta: float) -> void: for ship in get_children(): ship.position = ship.position.posmodv(_world_bounds) diff --git a/project/demos/PursueSeek/Player.gd b/project/demos/PursueSeek/Player.gd index a401e1c..9a52e82 100644 --- a/project/demos/PursueSeek/Player.gd +++ b/project/demos/PursueSeek/Player.gd @@ -44,15 +44,15 @@ func _physics_process(delta: float) -> void: func _calculate_angular_velocity( horizontal_movement: float, current_velocity: float, - thruster_strength: float, - velocity_max: float, + _thruster_strength: float, + _velocity_max: float, ship_drag: float, delta: float ) -> float: var velocity := clamp( - current_velocity + thruster_strength * horizontal_movement * delta, - -velocity_max, - velocity_max + current_velocity + _thruster_strength * horizontal_movement * delta, + -_velocity_max, + _velocity_max ) velocity = lerp(velocity, 0, ship_drag) diff --git a/project/demos/SeekFlee/Player.gd b/project/demos/SeekFlee/Player.gd index 4ee19a2..ad96016 100644 --- a/project/demos/SeekFlee/Player.gd +++ b/project/demos/SeekFlee/Player.gd @@ -10,11 +10,12 @@ func _ready() -> void: agent.position = GSAIUtils.to_vector3(global_position) -func _physics_process(delta: float) -> void: +func _physics_process(_delta: float) -> void: var movement := _get_movement() if movement.length_squared() < 0.01: return + # warning-ignore:return_value_discarded move_and_slide(movement * speed) agent.position = GSAIUtils.to_vector3(global_position) diff --git a/project/project.godot b/project/project.godot index 5c94b38..d8b307e 100644 --- a/project/project.godot +++ b/project/project.godot @@ -198,10 +198,6 @@ config/name="SteeringToolkit" run/main_scene="res://demos/DemoSelector.tscn" config/icon="res://icon.png" -[debug] - -gdscript/warnings/return_value_discarded=false - [display] window/size/width=1920 diff --git a/project/src/Agents/GSAIKinematicBody2DAgent.gd b/project/src/Agents/GSAIKinematicBody2DAgent.gd index 80500fa..4f4c270 100644 --- a/project/src/Agents/GSAIKinematicBody2DAgent.gd +++ b/project/src/Agents/GSAIKinematicBody2DAgent.gd @@ -19,13 +19,14 @@ var movement_type: int var _last_position: Vector2 -func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> void: - if not body.is_inside_tree(): - yield(body, "ready") +func _init(_body: KinematicBody2D, _movement_type: int = MovementType.SLIDE) -> void: + if not _body.is_inside_tree(): + yield(_body, "ready") - self.body = body - self.movement_type = movement_type + self.body = _body + self.movement_type = _movement_type + # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") @@ -60,6 +61,7 @@ func _apply_collide_steering(accel: Vector3, delta: float) -> void: Vector3.ZERO, linear_drag_percentage ) + # warning-ignore:return_value_discarded body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta) if calculate_velocities: linear_velocity = velocity diff --git a/project/src/Agents/GSAIKinematicBody3DAgent.gd b/project/src/Agents/GSAIKinematicBody3DAgent.gd index 6782a64..f696e93 100644 --- a/project/src/Agents/GSAIKinematicBody3DAgent.gd +++ b/project/src/Agents/GSAIKinematicBody3DAgent.gd @@ -18,14 +18,15 @@ var movement_type: int var _last_position: Vector3 -func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void: - if not body.is_inside_tree(): - yield(body, "ready") +func _init(_body: KinematicBody, _movement_type: int = MovementType.SLIDE) -> void: + if not _body.is_inside_tree(): + yield(_body, "ready") - self.body = body - self.movement_type = movement_type + self.body = _body + self.movement_type = _movement_type - body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") + # warning-ignore:return_value_discarded + self.body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") # Moves the agent's `body` by target `acceleration`. @@ -59,6 +60,7 @@ func _apply_collide_steering(accel: Vector3, delta: float) -> void: Vector3.ZERO, linear_drag_percentage ) + # warning-ignore:return_value_discarded body.move_and_collide(velocity * delta) if calculate_velocities: linear_velocity = velocity diff --git a/project/src/Agents/GSAIRigidBody2DAgent.gd b/project/src/Agents/GSAIRigidBody2DAgent.gd index 890ffb1..9d2cc49 100644 --- a/project/src/Agents/GSAIRigidBody2DAgent.gd +++ b/project/src/Agents/GSAIRigidBody2DAgent.gd @@ -10,16 +10,16 @@ var body: RigidBody2D setget _set_body var _last_position: Vector2 -func _init(body: RigidBody2D) -> void: - if not body.is_inside_tree(): - yield(body, "ready") +func _init(_body: RigidBody2D) -> void: + if not _body.is_inside_tree(): + yield(_body, "ready") - self.body = body + self.body = _body # Moves the agent's `body` by target `acceleration`. # tags: virtual -func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void: _applied_steering = true body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear)) body.apply_torque_impulse(acceleration.angular) @@ -39,6 +39,7 @@ func _set_body(value: RigidBody2D) -> void: func _on_body_ready() -> void: + # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") _set_body(body) diff --git a/project/src/Agents/GSAIRigidBody3DAgent.gd b/project/src/Agents/GSAIRigidBody3DAgent.gd index fb7f4e8..6b776c9 100644 --- a/project/src/Agents/GSAIRigidBody3DAgent.gd +++ b/project/src/Agents/GSAIRigidBody3DAgent.gd @@ -10,18 +10,19 @@ var body: RigidBody setget _set_body var _last_position: Vector3 -func _init(body: RigidBody) -> void: - if not body.is_inside_tree(): - yield(body, "ready") +func _init(_body: RigidBody) -> void: + if not _body.is_inside_tree(): + yield(_body, "ready") - self.body = body - body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") + self.body = _body + # warning-ignore:return_value_discarded + self.body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") # Moves the agent's `body` by target `acceleration`. # tags: virtual -func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void: _applied_steering = true body.apply_central_impulse(acceleration.linear) body.apply_torque_impulse(Vector3.UP * acceleration.angular) @@ -41,6 +42,7 @@ func _set_body(value: RigidBody) -> void: func _on_body_ready() -> void: + # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") _set_body(body) diff --git a/project/src/Behaviors/GSAIArrive.gd b/project/src/Behaviors/GSAIArrive.gd index f171068..26c4db5 100644 --- a/project/src/Behaviors/GSAIArrive.gd +++ b/project/src/Behaviors/GSAIArrive.gd @@ -15,8 +15,8 @@ var deceleration_radius: float var time_to_reach := 0.1 -func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: - self.target = target +func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void: + self.target = _target func _arrive(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void: diff --git a/project/src/Behaviors/GSAIFollowPath.gd b/project/src/Behaviors/GSAIFollowPath.gd index 21206e0..75f630e 100644 --- a/project/src/Behaviors/GSAIFollowPath.gd +++ b/project/src/Behaviors/GSAIFollowPath.gd @@ -17,12 +17,12 @@ var prediction_time := 0.0 func _init( agent: GSAISteeringAgent, - path: GSAIPath, - path_offset := 0.0, - prediction_time := 0.0).(agent, null) -> void: - self.path = path - self.path_offset = path_offset - self.prediction_time = prediction_time + _path: GSAIPath, + _path_offset := 0.0, + _prediction_time := 0.0).(agent, null) -> void: + self.path = _path + self.path_offset = _path_offset + self.prediction_time = _prediction_time func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: diff --git a/project/src/Behaviors/GSAIMatchOrientation.gd b/project/src/Behaviors/GSAIMatchOrientation.gd index 0a151f8..d6c90fe 100644 --- a/project/src/Behaviors/GSAIMatchOrientation.gd +++ b/project/src/Behaviors/GSAIMatchOrientation.gd @@ -16,8 +16,8 @@ var deceleration_radius: float var time_to_reach: float = 0.1 -func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: - self.target = target +func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void: + self.target = _target func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientation: float) -> void: diff --git a/project/src/Behaviors/GSAIPriority.gd b/project/src/Behaviors/GSAIPriority.gd index 144f6ce..52472b2 100644 --- a/project/src/Behaviors/GSAIPriority.gd +++ b/project/src/Behaviors/GSAIPriority.gd @@ -13,8 +13,8 @@ var last_selected_index: int var zero_threshold: float -func _init(agent: GSAISteeringAgent, zero_threshold := 0.001).(agent) -> void: - self.zero_threshold = zero_threshold +func _init(agent: GSAISteeringAgent, _zero_threshold := 0.001).(agent) -> void: + self.zero_threshold = _zero_threshold # Appends a steering behavior as a child of this container. diff --git a/project/src/Behaviors/GSAIPursue.gd b/project/src/Behaviors/GSAIPursue.gd index 2018b14..4363a4b 100644 --- a/project/src/Behaviors/GSAIPursue.gd +++ b/project/src/Behaviors/GSAIPursue.gd @@ -13,10 +13,10 @@ var predict_time_max: float func _init( agent: GSAISteeringAgent, - target: GSAISteeringAgent, - predict_time_max := 1.0).(agent) -> void: - self.target = target - self.predict_time_max = predict_time_max + _target: GSAISteeringAgent, + _predict_time_max := 1.0).(agent) -> void: + self.target = _target + self.predict_time_max = _predict_time_max func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: diff --git a/project/src/Behaviors/GSAISeek.gd b/project/src/Behaviors/GSAISeek.gd index e958d9e..7588e8f 100644 --- a/project/src/Behaviors/GSAISeek.gd +++ b/project/src/Behaviors/GSAISeek.gd @@ -8,8 +8,8 @@ extends GSAISteeringBehavior var target: GSAIAgentLocation -func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: - self.target = target +func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void: + self.target = _target func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: diff --git a/project/src/Behaviors/GSAISeparation.gd b/project/src/Behaviors/GSAISeparation.gd index a919a6e..829e050 100644 --- a/project/src/Behaviors/GSAISeparation.gd +++ b/project/src/Behaviors/GSAISeparation.gd @@ -21,6 +21,7 @@ func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: acceleration.set_zero() self._acceleration = acceleration + # warning-ignore:return_value_discarded proximity._find_neighbors(_callback) diff --git a/project/src/GSAIGroupBehavior.gd b/project/src/GSAIGroupBehavior.gd index 705fe07..974cd4b 100644 --- a/project/src/GSAIGroupBehavior.gd +++ b/project/src/GSAIGroupBehavior.gd @@ -9,8 +9,8 @@ var proximity: GSAIProximity var _callback := funcref(self, "_report_neighbor") -func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent) -> void: - self.proximity = proximity +func _init(agent: GSAISteeringAgent, _proximity: GSAIProximity).(agent) -> void: + self.proximity = _proximity # Internal callback for the behavior to define whether or not a member is diff --git a/project/src/GSAIPath.gd b/project/src/GSAIPath.gd index d29c159..b0f3402 100644 --- a/project/src/GSAIPath.gd +++ b/project/src/GSAIPath.gd @@ -15,8 +15,8 @@ var _nearest_point_on_segment: Vector3 var _nearest_point_on_path: Vector3 -func _init(waypoints: Array, is_open := false) -> void: - self.is_open = is_open +func _init(waypoints: Array, _is_open := false) -> void: + self.is_open = _is_open create_path(waypoints) _nearest_point_on_segment = waypoints[0] _nearest_point_on_path = waypoints[0] @@ -128,7 +128,7 @@ class GSAISegment: var cumulative_length: float - func _init(begin: Vector3, end: Vector3) -> void: - self.begin = begin - self.end = end - length = begin.distance_to(end) + func _init(_begin: Vector3, _end: Vector3) -> void: + self.begin = _begin + self.end = _end + length = _begin.distance_to(_end) diff --git a/project/src/Proximities/GSAIProximity.gd b/project/src/Proximities/GSAIProximity.gd index a820e3a..52f28a3 100644 --- a/project/src/Proximities/GSAIProximity.gd +++ b/project/src/Proximities/GSAIProximity.gd @@ -9,9 +9,9 @@ var agent: GSAISteeringAgent var agents := [] -func _init(agent: GSAISteeringAgent, agents: Array) -> void: - self.agent = agent - self.agents = agents +func _init(_agent: GSAISteeringAgent, _agents: Array) -> void: + self.agent = _agent + self.agents = _agents # Returns a number of neighbors based on a `callback` function. diff --git a/project/src/Proximities/GSAIRadiusProximity.gd b/project/src/Proximities/GSAIRadiusProximity.gd index 348e205..23b3747 100644 --- a/project/src/Proximities/GSAIRadiusProximity.gd +++ b/project/src/Proximities/GSAIRadiusProximity.gd @@ -11,8 +11,8 @@ var _last_frame := 0 var _scene_tree: SceneTree -func _init(agent: GSAISteeringAgent, agents: Array, radius: float).(agent, agents) -> void: - self.radius = radius +func _init(agent: GSAISteeringAgent, agents: Array, _radius: float).(agent, agents) -> void: + self.radius = _radius _scene_tree = Engine.get_main_loop()