Handle all warnings in GSAI* classes and demos

This commit is contained in:
Nathan Lovato 2020-02-11 13:36:06 -06:00
parent 04468a7d60
commit 36f2dcb522
27 changed files with 85 additions and 68 deletions

View File

@ -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. - 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 <kbd>F11</kbd>. - The demo projects now support resizing and toggling fullscreen with <kbd>F11</kbd>.
### Improvements ###
- We handled all warnings in the framework, so using it won't add warnings to your projects.
### Changes ### ### Changes ###
- Renamed all classes from `GST*` (Godot Steering Toolkit) to `GSAI*` (Godot Steering AI). - Renamed all classes from `GST*` (Godot Steering Toolkit) to `GSAI*` (Godot Steering AI).

View File

@ -40,7 +40,7 @@ func setup(
proximity_radius: float, proximity_radius: float,
boundary_right: float, boundary_right: float,
boundary_bottom: float, boundary_bottom: float,
draw_proximity: bool, _draw_proximity: bool,
rng: RandomNumberGenerator rng: RandomNumberGenerator
) -> void: ) -> void:
rng.randomize() rng.randomize()
@ -58,7 +58,7 @@ func setup(
agent.linear_drag_percentage = _drag agent.linear_drag_percentage = _drag
self.draw_proximity = draw_proximity self.draw_proximity = _draw_proximity
priority.add(avoid) priority.add(avoid)
priority.add(seek) priority.add(seek)

View File

@ -12,8 +12,11 @@ onready var button: Button = $VBoxContainer/Button
func _ready() -> void: func _ready() -> void:
# warning-ignore:return_value_discarded
list.connect("demo_selected", self, "set_demo_path") list.connect("demo_selected", self, "set_demo_path")
# warning-ignore:return_value_discarded
list.connect("item_activated", self, "emit_signal", ["demo_requested"]) list.connect("item_activated", self, "emit_signal", ["demo_requested"])
# warning-ignore:return_value_discarded
button.connect("pressed", self, "emit_signal", ["demo_requested"]) button.connect("pressed", self, "emit_signal", ["demo_requested"])
demo_path = list.file_paths[0] demo_path = list.file_paths[0]

View File

@ -18,6 +18,9 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
theme = ExtResource( 2 ) theme = ExtResource( 2 )
script = ExtResource( 4 ) script = ExtResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="DemoPickerUI"] [node name="TextureRect" type="TextureRect" parent="DemoPickerUI"]
anchor_right = 1.0 anchor_right = 1.0

View File

@ -7,7 +7,9 @@ onready var button_go_back: Button = $ButtonGoBack
func _ready() -> void: func _ready() -> void:
# warning-ignore:return_value_discarded
demo_picker.connect("demo_requested", self, "_on_DemoPickerUI_demo_requested") demo_picker.connect("demo_requested", self, "_on_DemoPickerUI_demo_requested")
# warning-ignore:return_value_discarded
button_go_back.connect("pressed", self, "_on_ButtonGoBack_pressed") button_go_back.connect("pressed", self, "_on_ButtonGoBack_pressed")

View File

@ -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 export(float, 0, 1000, 40) var player_speed := 600.0 setget set_player_speed
onready var player := $Player onready var player := $Player
onready var gui := $GUI
onready var turret := $Turret onready var turret := $Turret

View File

@ -6,7 +6,7 @@ var speed: float
onready var agent := GSAIAgentLocation.new() onready var agent := GSAIAgentLocation.new()
func _physics_process(delta: float) -> void: func _physics_process(_delta: float) -> void:
var movement := _get_movement() var movement := _get_movement()
move_and_slide(movement * speed) move_and_slide(movement * speed)
agent.position = Vector3(global_position.x, global_position.y, 0) agent.position = Vector3(global_position.x, global_position.y, 0)

View File

@ -7,6 +7,7 @@ var file_paths := PoolStringArray()
func _ready() -> void: func _ready() -> void:
# warning-ignore:return_value_discarded
self.connect("item_selected", self, "_on_item_selected") self.connect("item_selected", self, "_on_item_selected")
var this_directory: String = get_tree().current_scene.filename.rsplit("/", false, 1)[0] var this_directory: String = get_tree().current_scene.filename.rsplit("/", false, 1)[0]

View File

@ -12,6 +12,6 @@ func _ready() -> void:
) )
func _physics_process(delta: float) -> void: func _physics_process(_delta: float) -> void:
for ship in get_children(): for ship in get_children():
ship.position = ship.position.posmodv(_world_bounds) ship.position = ship.position.posmodv(_world_bounds)

View File

@ -44,15 +44,15 @@ func _physics_process(delta: float) -> void:
func _calculate_angular_velocity( func _calculate_angular_velocity(
horizontal_movement: float, horizontal_movement: float,
current_velocity: float, current_velocity: float,
thruster_strength: float, _thruster_strength: float,
velocity_max: float, _velocity_max: float,
ship_drag: float, ship_drag: float,
delta: float delta: float
) -> float: ) -> float:
var velocity := clamp( var velocity := clamp(
current_velocity + thruster_strength * horizontal_movement * delta, current_velocity + _thruster_strength * horizontal_movement * delta,
-velocity_max, -_velocity_max,
velocity_max _velocity_max
) )
velocity = lerp(velocity, 0, ship_drag) velocity = lerp(velocity, 0, ship_drag)

View File

@ -10,11 +10,12 @@ func _ready() -> void:
agent.position = GSAIUtils.to_vector3(global_position) agent.position = GSAIUtils.to_vector3(global_position)
func _physics_process(delta: float) -> void: func _physics_process(_delta: float) -> void:
var movement := _get_movement() var movement := _get_movement()
if movement.length_squared() < 0.01: if movement.length_squared() < 0.01:
return return
# warning-ignore:return_value_discarded
move_and_slide(movement * speed) move_and_slide(movement * speed)
agent.position = GSAIUtils.to_vector3(global_position) agent.position = GSAIUtils.to_vector3(global_position)

View File

@ -198,10 +198,6 @@ config/name="SteeringToolkit"
run/main_scene="res://demos/DemoSelector.tscn" run/main_scene="res://demos/DemoSelector.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[debug]
gdscript/warnings/return_value_discarded=false
[display] [display]
window/size/width=1920 window/size/width=1920

View File

@ -19,13 +19,14 @@ var movement_type: int
var _last_position: Vector2 var _last_position: Vector2
func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> void: func _init(_body: KinematicBody2D, _movement_type: int = MovementType.SLIDE) -> void:
if not body.is_inside_tree(): if not _body.is_inside_tree():
yield(body, "ready") yield(_body, "ready")
self.body = body self.body = _body
self.movement_type = movement_type self.movement_type = _movement_type
# warning-ignore:return_value_discarded
body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") 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, Vector3.ZERO,
linear_drag_percentage linear_drag_percentage
) )
# warning-ignore:return_value_discarded
body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta) body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta)
if calculate_velocities: if calculate_velocities:
linear_velocity = velocity linear_velocity = velocity

View File

@ -18,14 +18,15 @@ var movement_type: int
var _last_position: Vector3 var _last_position: Vector3
func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void: func _init(_body: KinematicBody, _movement_type: int = MovementType.SLIDE) -> void:
if not body.is_inside_tree(): if not _body.is_inside_tree():
yield(body, "ready") yield(_body, "ready")
self.body = body self.body = _body
self.movement_type = movement_type 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`. # Moves the agent's `body` by target `acceleration`.
@ -59,6 +60,7 @@ func _apply_collide_steering(accel: Vector3, delta: float) -> void:
Vector3.ZERO, Vector3.ZERO,
linear_drag_percentage linear_drag_percentage
) )
# warning-ignore:return_value_discarded
body.move_and_collide(velocity * delta) body.move_and_collide(velocity * delta)
if calculate_velocities: if calculate_velocities:
linear_velocity = velocity linear_velocity = velocity

View File

@ -10,16 +10,16 @@ var body: RigidBody2D setget _set_body
var _last_position: Vector2 var _last_position: Vector2
func _init(body: RigidBody2D) -> void: func _init(_body: RigidBody2D) -> void:
if not body.is_inside_tree(): if not _body.is_inside_tree():
yield(body, "ready") yield(_body, "ready")
self.body = body self.body = _body
# Moves the agent's `body` by target `acceleration`. # Moves the agent's `body` by target `acceleration`.
# tags: virtual # tags: virtual
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void:
_applied_steering = true _applied_steering = true
body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear)) body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear))
body.apply_torque_impulse(acceleration.angular) body.apply_torque_impulse(acceleration.angular)
@ -39,6 +39,7 @@ func _set_body(value: RigidBody2D) -> void:
func _on_body_ready() -> void: func _on_body_ready() -> void:
# warning-ignore:return_value_discarded
body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame")
_set_body(body) _set_body(body)

View File

@ -10,18 +10,19 @@ var body: RigidBody setget _set_body
var _last_position: Vector3 var _last_position: Vector3
func _init(body: RigidBody) -> void: func _init(_body: RigidBody) -> void:
if not body.is_inside_tree(): if not _body.is_inside_tree():
yield(body, "ready") yield(_body, "ready")
self.body = body self.body = _body
body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") # warning-ignore:return_value_discarded
self.body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame")
# Moves the agent's `body` by target `acceleration`. # Moves the agent's `body` by target `acceleration`.
# tags: virtual # tags: virtual
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void:
_applied_steering = true _applied_steering = true
body.apply_central_impulse(acceleration.linear) body.apply_central_impulse(acceleration.linear)
body.apply_torque_impulse(Vector3.UP * acceleration.angular) body.apply_torque_impulse(Vector3.UP * acceleration.angular)
@ -41,6 +42,7 @@ func _set_body(value: RigidBody) -> void:
func _on_body_ready() -> void: func _on_body_ready() -> void:
# warning-ignore:return_value_discarded
body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame")
_set_body(body) _set_body(body)

View File

@ -15,8 +15,8 @@ var deceleration_radius: float
var time_to_reach := 0.1 var time_to_reach := 0.1
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void:
self.target = target self.target = _target
func _arrive(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void: func _arrive(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void:

View File

@ -17,12 +17,12 @@ var prediction_time := 0.0
func _init( func _init(
agent: GSAISteeringAgent, agent: GSAISteeringAgent,
path: GSAIPath, _path: GSAIPath,
path_offset := 0.0, _path_offset := 0.0,
prediction_time := 0.0).(agent, null) -> void: _prediction_time := 0.0).(agent, null) -> void:
self.path = path self.path = _path
self.path_offset = path_offset self.path_offset = _path_offset
self.prediction_time = prediction_time self.prediction_time = _prediction_time
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:

View File

@ -16,8 +16,8 @@ var deceleration_radius: float
var time_to_reach: float = 0.1 var time_to_reach: float = 0.1
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void:
self.target = target self.target = _target
func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientation: float) -> void: func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientation: float) -> void:

View File

@ -13,8 +13,8 @@ var last_selected_index: int
var zero_threshold: float var zero_threshold: float
func _init(agent: GSAISteeringAgent, zero_threshold := 0.001).(agent) -> void: func _init(agent: GSAISteeringAgent, _zero_threshold := 0.001).(agent) -> void:
self.zero_threshold = zero_threshold self.zero_threshold = _zero_threshold
# Appends a steering behavior as a child of this container. # Appends a steering behavior as a child of this container.

View File

@ -13,10 +13,10 @@ var predict_time_max: float
func _init( func _init(
agent: GSAISteeringAgent, agent: GSAISteeringAgent,
target: GSAISteeringAgent, _target: GSAISteeringAgent,
predict_time_max := 1.0).(agent) -> void: _predict_time_max := 1.0).(agent) -> void:
self.target = target self.target = _target
self.predict_time_max = predict_time_max self.predict_time_max = _predict_time_max
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:

View File

@ -8,8 +8,8 @@ extends GSAISteeringBehavior
var target: GSAIAgentLocation var target: GSAIAgentLocation
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void: func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void:
self.target = target self.target = _target
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:

View File

@ -21,6 +21,7 @@ func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
acceleration.set_zero() acceleration.set_zero()
self._acceleration = acceleration self._acceleration = acceleration
# warning-ignore:return_value_discarded
proximity._find_neighbors(_callback) proximity._find_neighbors(_callback)

View File

@ -9,8 +9,8 @@ var proximity: GSAIProximity
var _callback := funcref(self, "_report_neighbor") var _callback := funcref(self, "_report_neighbor")
func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent) -> void: func _init(agent: GSAISteeringAgent, _proximity: GSAIProximity).(agent) -> void:
self.proximity = proximity self.proximity = _proximity
# Internal callback for the behavior to define whether or not a member is # Internal callback for the behavior to define whether or not a member is

View File

@ -15,8 +15,8 @@ var _nearest_point_on_segment: Vector3
var _nearest_point_on_path: Vector3 var _nearest_point_on_path: Vector3
func _init(waypoints: Array, is_open := false) -> void: func _init(waypoints: Array, _is_open := false) -> void:
self.is_open = is_open self.is_open = _is_open
create_path(waypoints) create_path(waypoints)
_nearest_point_on_segment = waypoints[0] _nearest_point_on_segment = waypoints[0]
_nearest_point_on_path = waypoints[0] _nearest_point_on_path = waypoints[0]
@ -128,7 +128,7 @@ class GSAISegment:
var cumulative_length: float var cumulative_length: float
func _init(begin: Vector3, end: Vector3) -> void: func _init(_begin: Vector3, _end: Vector3) -> void:
self.begin = begin self.begin = _begin
self.end = end self.end = _end
length = begin.distance_to(end) length = _begin.distance_to(_end)

View File

@ -9,9 +9,9 @@ var agent: GSAISteeringAgent
var agents := [] var agents := []
func _init(agent: GSAISteeringAgent, agents: Array) -> void: func _init(_agent: GSAISteeringAgent, _agents: Array) -> void:
self.agent = agent self.agent = _agent
self.agents = agents self.agents = _agents
# Returns a number of neighbors based on a `callback` function. # Returns a number of neighbors based on a `callback` function.

View File

@ -11,8 +11,8 @@ var _last_frame := 0
var _scene_tree: SceneTree var _scene_tree: SceneTree
func _init(agent: GSAISteeringAgent, agents: Array, radius: float).(agent, agents) -> void: func _init(agent: GSAISteeringAgent, agents: Array, _radius: float).(agent, agents) -> void:
self.radius = radius self.radius = _radius
_scene_tree = Engine.get_main_loop() _scene_tree = Engine.get_main_loop()