From 3957f155dac5c783130fd1261030e5f03e46e059 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 13 Jan 2023 17:11:52 +0100 Subject: [PATCH] Removed yields from the agents. --- .../Agents/GSAIKinematicBody2DAgent.gd | 11 +++++++---- .../Agents/GSAIKinematicBody3DAgent.gd | 11 +++++++---- .../Agents/GSAIRigidBody2DAgent.gd | 10 +++++++--- .../Agents/GSAIRigidBody3DAgent.gd | 10 +++++++--- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd index bfb807e..5d5f670 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd @@ -24,14 +24,17 @@ var _body_ref : WeakRef func _init(_body: KinematicBody2D, _movement_type: int = MovementType.SLIDE) -> void: - if !_body.is_inside_tree(): - yield(_body, "ready") - self.body = _body self.movement_type = _movement_type + if !_body.is_inside_tree(): + _body.connect("ready", self, "_body_ready") + else: + _body_ready() + +func _body_ready() -> void: # 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") # Moves the agent's `body` by target `acceleration`. diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd index 182df9c..9f8474d 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd @@ -24,14 +24,17 @@ var _body_ref : WeakRef func _init(_body: KinematicBody, _movement_type: int = MovementType.SLIDE) -> void: - if !_body.is_inside_tree(): - yield(_body, "ready") - self.body = _body self.movement_type = _movement_type + if !_body.is_inside_tree(): + _body.connect("ready", self, "_body_ready") + else: + _body_ready() + +func _body_ready() -> void: # 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") # Moves the agent's `body` by target `acceleration`. diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd index 6bd7b52..4eb71bb 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd @@ -12,12 +12,16 @@ var _body_ref : WeakRef func _init(_body : RigidBody2D) -> void: - if not _body.is_inside_tree(): - yield(_body, "ready") self.body = _body + if !_body.is_inside_tree(): + _body.connect("ready", self, "_body_ready") + else: + _body_ready() + +func _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") # Moves the agent's `body` by target `acceleration`. diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd index 10bb639..b5ba8b8 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd @@ -11,12 +11,16 @@ var _last_position: Vector3 var _body_ref: WeakRef func _init(_body: RigidBody) -> void: - if not _body.is_inside_tree(): - yield(_body, "ready") self.body = _body + if !_body.is_inside_tree(): + _body.connect("ready", self, "_body_ready") + else: + _body_ready() + +func _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") # Moves the agent's `body` by target `acceleration`.