Skip to content

Commit

Permalink
Merge pull request #15 from Malcolmnixon/fix-port-issues
Browse files Browse the repository at this point in the history
Fix numerous issues found during C# port experiment
  • Loading branch information
Malcolmnixon authored Nov 25, 2023
2 parents d99fe82 + ff95eb0 commit 18daffc
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 41 deletions.
3 changes: 0 additions & 3 deletions addons/tiltfive_tools/functions/pointer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ const VALID_MASK := 0b0000_0000_0001_0000_0000_0000_0000_0000

@export_group("Arc")

## Arc length when not colliding
@export_range(0.01, 1.0, 0.01, "or_greater") var not_colliding_distance : float = 0.5

## Bezier strength
@export_range(0.1, 1.0, 0.05) var bezier_strength : float = 0.5

Expand Down
2 changes: 1 addition & 1 deletion addons/tiltfive_tools/functions/visible_toggle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Initial {


## Wand number (0 for default)
@export var wand : int = 2
@export var wand : int = 0

## Toggle button (T5 menu button for default)
@export var toggle_button : String = "button_t5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ func _control_to_global(control : Vector2) -> Vector3:
var vec : Vector3
match control_orientation:
ControlOrientation.VERTICAL:
vec = Vector3(_control.x, 0.0, -_control.y)
vec = Vector3(control.x, 0.0, -control.y)
ControlOrientation.HORIZONTAL:
vec = Vector3(-_control.y, 0.0, -_control.x)
vec = Vector3(-control.y, 0.0, -control.x)

# Translate to reference frame
if control_reference == ControlReference.PLAYER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func _is_on_ground() -> bool:
continue

# Test if moving up relative to the ground
var ground_velocity := collision.get_collider_velocity(0)
var ground_velocity := collision.get_collider_velocity(c)
var relative_velocity := linear_velocity - ground_velocity
if relative_velocity.y > 0.1:
continue
Expand All @@ -199,9 +199,9 @@ func _control_to_global(control : Vector2) -> Vector3:
var vec : Vector3
match control_orientation:
ControlOrientation.VERTICAL:
vec = Vector3(_control.x, 0.0, -_control.y)
vec = Vector3(control.x, 0.0, -control.y)
ControlOrientation.HORIZONTAL:
vec = Vector3(-_control.y, 0.0, -_control.x)
vec = Vector3(-control.y, 0.0, -control.x)

# Translate to reference frame
if control_reference == ControlReference.PLAYER:
Expand Down
4 changes: 2 additions & 2 deletions addons/tiltfive_tools/objects/scene_switch_area.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@tool
class_name SceneSwitchArea
class_name T5ToolsSceneSwitchArea
extends Area3D


Expand All @@ -25,7 +25,7 @@ func _ready() -> void:
func _get_configuration_warnings() -> PackedStringArray:
var warnings := PackedStringArray()

# Verify the controller
# Verify the target scene is specified
if not target_scene:
warnings.append("Target scene must be specified")

Expand Down
22 changes: 21 additions & 1 deletion addons/tiltfive_tools/staging/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,27 @@ extends T5XRRig
@export_flags_3d_render var visible_layers : int = 5 : set = _set_visible_layers

## Player number [0..3] (set by Staging on load)
@export var player_number : int : set = _set_player_number
@export var player_number : int = -1 : set = _set_player_number


## Array of all players (used for player numbering)
static var _players : Array[T5ToolsPlayer] = []


func _enter_tree():
# Assign the next free player number
for n in 4:
if _players.all(func(p : T5ToolsPlayer) -> bool: return p.player_number != n):
player_number = n
break;

# Save as a player
_players.append(self)


func _exit_tree():
# Remove from the list of players
_players.erase(self)


func _ready():
Expand Down
3 changes: 1 addition & 2 deletions addons/tiltfive_tools/staging/scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var characters : Array[T5ToolsCharacter] = []


## Load spawn point
var _load_spawn : Transform3D
var _load_spawn : Transform3D = Transform3D.IDENTITY


func _ready():
Expand All @@ -49,7 +49,6 @@ func _on_scene_loaded(user_data : Variant) -> void:
spawn_position = spawn_position.get_spawn_postion(self)

# Get the spawn transform
var _load_spawn := Transform3D.IDENTITY
match typeof(spawn_position):
TYPE_STRING:
# Name of Node3D to spawn at
Expand Down
40 changes: 16 additions & 24 deletions addons/tiltfive_tools/staging/staging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,43 @@ func _ready() -> void:
if Engine.is_editor_hint():
return

# Connect player events
$T5Manager.glasses_scene_was_added.connect(_on_player_scene_added)
$T5Manager.glasses_scene_will_be_removed.connect(_on_player_scene_removed)

# Start by loading the start scene
do_load_scene(start_scene, null)


# Load a scene
func do_load_scene(p_scene_path : String, user_data : Variant) -> void:
# Log request
print_verbose("StagingBase: Request to load %s" % p_scene_path)
print_verbose("T5ToolsStaging: Request to load %s" % p_scene_path)

# Start background loading of the resource
ResourceLoader.load_threaded_request(p_scene_path)

# Start by unloading the current scene
if current_scene:
# Report about to exit the current scene
print_verbose("StagingBase: Reporting scene_pre_exiting")
print_verbose("T5ToolsStaging: Reporting scene_pre_exiting")
scene_pre_exiting.emit(current_scene, user_data)
current_scene.scene_pre_exiting.emit(user_data)

# Fade to black
print_verbose("StagingBase: Fading out")
print_verbose("T5ToolsStaging: Fading out")
if _fade_tween: _fade_tween.kill()
_fade_tween = get_tree().create_tween()
_fade_tween.tween_method(_set_fade, 0.0, 1.0, 1.0)
await _fade_tween.finished

# Report the exit of the current scene
print_verbose("StagingBase: Reporting scene_exiting")
print_verbose("T5ToolsStaging: Reporting scene_exiting")
scene_exiting.emit(current_scene, user_data)
current_scene.scene_exiting.emit(user_data)

# Discard the current scene
print_verbose("StagingBase: Discarding old scene")
print_verbose("T5ToolsStaging: Discarding old scene")
$Scene.remove_child(current_scene)
current_scene.queue_free()
current_scene = null
Expand All @@ -96,28 +100,28 @@ func do_load_scene(p_scene_path : String, user_data : Variant) -> void:
player.get_player_origin().global_transform = Transform3D.IDENTITY

# Load the new scene
print_verbose("StagingBase: Loading new scene")
print_verbose("T5ToolsStaging: Loading new scene")
var new_scene : PackedScene = ResourceLoader.load_threaded_get(p_scene_path)

# Instantiate the scene
print_verbose("StagingBase: Instantiating new scene")
print_verbose("T5ToolsStaging: Instantiating new scene")
current_scene = new_scene.instantiate()
$Scene.add_child(current_scene)

# Report the new scene is loaded
print_verbose("StagingBase: Reporting scene_loaded")
print_verbose("T5ToolsStaging: Reporting scene_loaded")
current_scene.scene_loaded.emit(user_data)
scene_loaded.emit(current_scene, user_data)

# Fade to visible
print_verbose("StagingBase: Fading in")
print_verbose("T5ToolsStaging: Fading in")
if _fade_tween: _fade_tween.kill()
_fade_tween = get_tree().create_tween()
_fade_tween.tween_method(_set_fade, 1.0, 0.0, 1.0)
await _fade_tween.finished

# Report the new scene is visible
print_verbose("StagingBase: Reporting scene_visible")
print_verbose("T5ToolsStaging: Reporting scene_visible")
current_scene.scene_visible.emit(user_data)
scene_visible.emit(current_scene, user_data)

Expand All @@ -134,30 +138,18 @@ func _set_fade(p_fade : float) -> void:

# Handle player added
func _on_player_scene_added(player : T5ToolsPlayer):
player.player_number = _get_free_player_number()
print_verbose("StagingBase: Player %s added" % player)
print_verbose("T5ToolsStaging: Player %s added" % player)
players.append(player)
player_created.emit(player)


# Handle player removed
func _on_player_scene_removed(player : T5ToolsPlayer):
print_verbose("StagingBase: Player %s removed" % player)
print_verbose("T5ToolsStaging: Player %s removed" % player)
players.erase(player)
player_removed.emit(player)


## Load the requested scene
static func load_scene(p_scene_path : String, user_data : Variant = null) -> void:
instance.do_load_scene(p_scene_path, user_data)


func _get_free_player_number() -> int:
# Check if player numbers 0..3 are available for use
for n in 4:
if not players.any(func(p : T5ToolsPlayer) -> bool: return p.player_number == n):
return n

# Warn and return an invalid player 4
push_warning("Players 0..3 already assigned. No ID for new player")
return -1
3 changes: 0 additions & 3 deletions addons/tiltfive_tools/staging/staging.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,3 @@ script = ExtResource("2_1ijo2")
glasses_scene = ExtResource("3_pw71e")

[node name="Scene" type="Node3D" parent="."]

[connection signal="glasses_scene_was_added" from="T5Manager" to="." method="_on_player_scene_added"]
[connection signal="glasses_scene_will_be_removed" from="T5Manager" to="." method="_on_player_scene_removed"]

0 comments on commit 18daffc

Please sign in to comment.