Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement adr 245 components (send avatar/player components to scene) #85

Merged
merged 12 commits into from
Nov 15, 2023
16 changes: 8 additions & 8 deletions godot/.godot/global_script_class_cache.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://src/logic/animation_importer.gd"
}, {
"base": &"Node3D",
"base": &"DclAvatar",
"class": &"Avatar",
"icon": "",
"language": &"GDScript",
Expand Down Expand Up @@ -41,6 +41,12 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://src/logic/content_thread.gd"
}, {
"base": &"AvatarScene",
"class": &"CustomAvatarScene",
"icon": "",
"language": &"GDScript",
"path": "res://src/logic/avatar_scene.gd"
}, {
"base": &"MeshInstance3D",
"class": &"DclMeshRenderer",
"icon": "",
Expand All @@ -53,12 +59,6 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://src/logic/camera.gd"
}, {
"base": &"RefCounted",
"class": &"Math",
"icon": "",
"language": &"GDScript",
"path": "res://src/utils/Math.gd"
}, {
"base": &"DclPortableExperienceController",
"class": &"PortableExperienceController",
"icon": "",
Expand All @@ -69,7 +69,7 @@ list=Array[Dictionary]([{
"class": &"Promise",
"icon": "",
"language": &"GDScript",
"path": "res://src/utils/Promise.gd"
"path": "res://src/utils/promise.gd"
}, {
"base": &"DclRealm",
"class": &"Realm",
Expand Down
65 changes: 4 additions & 61 deletions godot/src/decentraland_components/avatar.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Node3D
extends DclAvatar
class_name Avatar

signal avatar_loaded
Expand All @@ -14,20 +14,6 @@ var avatar_name: String = ""
var avatar_id: String = ""
var playing_emote = false

# Parcel Position
var parcel_position: Vector2i = Vector2i.ZERO
var last_parcel_position: Vector2i = Vector2i(Math.INT32_MAX, Math.INT32_MAX) # Vector2i.MAX is coming: https://github.com/godotengine/godot/pull/81741
var scene_id: int = Math.INT32_MIN
var last_scene_id: int = Math.INT32_MAX
signal change_parcel_position(parcel_position: Vector2)
signal change_scene_id(scene_id: Vector2)

# Position Lerp
var last_position: Vector3 = Vector3.ZERO
var target_position: Vector3 = Vector3.ZERO
var t: float = 0.0
var target_distance: float = 0.0

# Wearable requesting
var current_content_url: String = ""

Expand Down Expand Up @@ -131,7 +117,7 @@ func play_emote(emote_id: String):
playing_emote = true


func play_remote_emote(emote_src: String, looping: bool):
func play_remote_emote(_emote_src: String, _looping: bool):
# TODO: Implement downloading emote from the scene content, adding to the avatar and then playing the emote
# Test scene: https://github.com/decentraland/unity-renderer/pull/5501
pass
Expand Down Expand Up @@ -427,52 +413,9 @@ func apply_texture_and_mask(
mesh.mesh.surface_set_material(0, current_material)


func set_target(target: Transform3D) -> void:
target_distance = target_position.distance_to(target.origin)

last_position = target_position
target_position = target.origin

self.global_rotation = target.basis.get_euler()
self.global_position = last_position

t = 0


func _check_parcel_position():
parcel_position = Math.get_parcel_position_by_world_position(self.get_global_position())

if last_parcel_position != parcel_position:
last_parcel_position = parcel_position
change_parcel_position.emit(parcel_position)
scene_id = Global.scene_runner.get_scene_id_by_parcel_position(parcel_position)
if last_scene_id != scene_id:
last_scene_id = scene_id
change_scene_id.emit(scene_id)


func _process(delta):
_check_parcel_position()

if skip_process:
return

if t < 2:
t += 10 * delta
if t < 1:
if t > 1.0:
t = 1.0

self.global_position = last_position.lerp(target_position, t)

if target_distance > 0:
if target_distance > 0.6:
set_running()
else:
set_walking()

elif t > 1.5:
self.set_idle()
# TODO: maybe a gdext crate bug? when process implement the Node3DVirtual, super(delta) doesn't work :/
self.process(delta)


func set_walking():
Expand Down
2 changes: 1 addition & 1 deletion godot/src/decentraland_components/avatar.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ material = SubResource("StandardMaterial3D_6htl0")
radius = 0.1
height = 0.1

[node name="Avatar" type="Node3D"]
[node name="Avatar" type="DclAvatar"]
script = ExtResource("1_kkscc")

[node name="Armature" type="Node3D" parent="."]
Expand Down
3 changes: 2 additions & 1 deletion godot/src/decentraland_components/avatar_modifier_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ extends DclAvatarModifierArea3D

@onready var collision_shape_3d = $CollisionShape3D

var scene_id: int = 0
# Initial value SceneId::INVALID
var scene_id: int = -1


# Called when the node enters the scene tree for the first time.
Expand Down
13 changes: 10 additions & 3 deletions godot/src/decentraland_components/gltf_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ func _on_gltf_loaded():
self.deferred_add_child.call_deferred(gltf_node)


func deferred_add_child(gltf_node):
add_child(gltf_node)
await get_tree().process_frame
func deferred_add_child(new_gltf_node):
# Corner case, when the scene is unloaded before the gltf is loaded
var main_tree = get_tree()
if not is_instance_valid(main_tree):
dcl_gltf_loading_state = GltfContainerLoadingState.FinishedWithError
return

add_child(new_gltf_node)

await main_tree.process_frame

# Colliders and rendering is ensured to be ready at this point
dcl_gltf_loading_state = GltfContainerLoadingState.Finished
Expand Down
5 changes: 4 additions & 1 deletion godot/src/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func _ready():
self.portable_experience_controller = PortableExperienceController.new()
self.portable_experience_controller.set_name("portable_experience_controller")

self.avatars = CustomAvatarScene.new()
self.avatars.set_name("avatar_scene")

get_tree().root.add_child.call_deferred(self.scene_fetcher)
get_tree().root.add_child.call_deferred(self.content_manager)
get_tree().root.add_child.call_deferred(self.scene_runner)
Expand Down Expand Up @@ -86,5 +89,5 @@ func print_node_tree(node: Node, prefix = ""):
print_node_tree(child, prefix + node.name + "/")


func _process(dt: float):
func _process(_dt: float):
http_requester.poll()
8 changes: 6 additions & 2 deletions godot/src/helpers_components/avatar_modifier_area_detector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ var overlapping_areas: Array[Area3D] = []
func _ready():
avatar.change_scene_id.connect(self._on_avatar_change_scene_id)

# Arbitrary order
for area in self.get_overlapping_areas():
_on_area_entered(area)


func _on_tree_exiting():
avatar.change_scene_id.disconnect(self._on_avatar_change_scene_id)


func _on_avatar_change_scene_id(new_scene_id: int):
func _on_avatar_change_scene_id(_new_scene_id: int, _prev_scene_id: int):
check_areas()


Expand All @@ -41,7 +45,7 @@ func get_last_dcl_avatar_modifier_area_3d(areas: Array[Area3D]) -> DclAvatarModi


func check_areas():
var avatar_scene_id = avatar.scene_id
var avatar_scene_id = avatar.current_parcel_scene_id

# only areas that have the same scene id than the player...
var areas = overlapping_areas.filter(func(area): return area.scene_id == avatar_scene_id)
Expand Down
8 changes: 4 additions & 4 deletions godot/src/helpers_components/force_global_scale_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ extends Node3D
@export var target: Node3D


func _process(dt):
var global_scale = target.get_global_transform().basis.get_scale()
func _process(_dt):
var current_global_scale = target.get_global_transform().basis.get_scale()
# If the global scale is not 1,1,1, adjust it
if global_scale != Vector3.ONE:
target.scale = target.scale / global_scale
if current_global_scale != Vector3.ONE:
target.scale = target.scale / current_global_scale
5 changes: 3 additions & 2 deletions godot/src/helpers_components/on_active_scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ extends Node3D

signal on_scene_active(active: bool)

var _my_scene_id: int = 0
# Initial value SceneId::INVALID
var _my_scene_id: int = -1


func _ready():
Expand All @@ -17,5 +18,5 @@ func _ready():
Global.scene_runner.on_change_scene_id.connect(self._on_change_scene_id)


func _on_change_scene_id(scene_id: int):
func _on_change_scene_id(scene_id: int, _prev_scene_id: int):
on_scene_active.emit(scene_id == _my_scene_id)
8 changes: 8 additions & 0 deletions godot/src/logic/avatar_scene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends AvatarScene
class_name CustomAvatarScene #workaround


# TODO: when 4.2 is used, this could be removed
# It's not possible to bind a custom callable to a signal in Rust before 4.2
func _temp_get_custom_callable_on_avatar_changed(avatar_entity_id):
return self.on_avatar_changed_scene.bind(avatar_entity_id)
6 changes: 3 additions & 3 deletions godot/src/logic/content_thread.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func content_processing_count():
return _pending_content.size()


func _init(id: int, thread: Thread):
self.thread = thread
self.id = id
func _init(param_id: int, param_thread: Thread):
self.thread = param_thread
self.id = param_id
leanmendoza marked this conversation as resolved.
Show resolved Hide resolved


func process(content_cache_map: Dictionary): # not a coroutine
Expand Down
15 changes: 9 additions & 6 deletions godot/src/logic/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var stored_camera_mode_before_block: Global.CameraMode

func _on_camera_mode_area_detector_block_camera_mode(forced_mode):
if !camera_mode_change_blocked: # if it's already blocked, we don't store the state again...
stored_camera_mode_before_block = camera.get_camera_mode()
stored_camera_mode_before_block = camera.get_camera_mode() as Global.CameraMode
camera_mode_change_blocked = true

set_camera_mode(forced_mode, false)
Expand Down Expand Up @@ -173,11 +173,14 @@ func _physics_process(delta: float) -> void:


func avatar_look_at(target_position: Vector3):
var direction = target_position - get_global_position()
direction = direction.normalized()

var y_rot = atan2(direction.x, direction.z)
var x_rot = atan2(direction.y, sqrt(direction.x * direction.x + direction.z * direction.z))
var target_direction = target_position - get_global_position()
target_direction = direction.normalized()

var y_rot = atan2(target_direction.x, target_direction.z)
var x_rot = atan2(
target_direction.y,
sqrt(target_direction.x * target_direction.x + target_direction.z * target_direction.z)
)

rotation.y = y_rot + PI
avatar.set_rotation(Vector3(0, 0, 0))
Expand Down
2 changes: 1 addition & 1 deletion godot/src/logic/portable_experience_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _ready():
Global.scene_runner.scene_spawned.connect(self._on_scene_spawned)


func _process(delta):
func _process(_delta):
var to_spawn := self.consume_requested_spawn()
if not to_spawn.is_empty():
spawn_many_portables(to_spawn)
Expand Down
12 changes: 7 additions & 5 deletions godot/src/logic/realm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static func parse_urn(urn: String):

func set_realm(new_realm_string: String) -> void:
realm_string = new_realm_string
realm_url = ensure_ends_with_slash(resolve_realm_url(realm_string))
realm_url = ensure_starts_with_https(realm_url)
realm_url = Realm.ensure_ends_with_slash(Realm.resolve_realm_url(realm_string))
realm_url = Realm.ensure_starts_with_https(realm_url)
var promise: Promise = http_requester.request_json(
realm_url + "about", HTTPClient.METHOD_GET, "", []
)
Expand Down Expand Up @@ -102,21 +102,23 @@ func set_realm(new_realm_string: String) -> void:

realm_scene_urns.clear()
for urn in configuration.get("scenesUrn", []):
var parsed_urn = parse_urn(urn)
var parsed_urn = Realm.parse_urn(urn)
if parsed_urn != null:
realm_scene_urns.push_back(parsed_urn)

realm_global_scene_urns.clear()
for urn in configuration.get("globalScenesUrn", []):
var parsed_urn = parse_urn(urn)
var parsed_urn = Realm.parse_urn(urn)
if parsed_urn != null:
realm_global_scene_urns.push_back(parsed_urn)

realm_city_loader_content_base_url = configuration.get("cityLoaderContentServer", "")

realm_name = configuration.get("realmName", "no_realm_name")

content_base_url = ensure_ends_with_slash(realm_about.get("content", {}).get("publicUrl"))
content_base_url = Realm.ensure_ends_with_slash(
realm_about.get("content", {}).get("publicUrl")
)

Global.config.last_realm_joined = realm_url
Global.config.save_to_settings_file()
Expand Down
3 changes: 1 addition & 2 deletions godot/src/logic/scene_fetcher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func _ready():
Global.scene_runner.scene_killed.connect(self.on_scene_killed)


func on_scene_killed(killed_scene_id, entity_id):
func on_scene_killed(killed_scene_id, _entity_id):
for scene_id in loaded_scenes.keys():
var scene = loaded_scenes[scene_id]
var scene_number_id: int = scene.get("scene_number_id", -1)
Expand Down Expand Up @@ -211,7 +211,6 @@ func load_scene(scene_entity_id: String, entity: Dictionary):
}

var is_sdk7 = metadata.get("runtimeVersion", null) == "7"
var main_js_request_id := -1
var local_main_js_path = ""

if is_sdk7:
Expand Down
4 changes: 2 additions & 2 deletions godot/src/test/avatar/spawn_and_move.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func _process(dt):
var alias = 10000 + spawning_i
Global.avatars.add_avatar(alias, "")
Global.avatars.update_avatar_profile(alias, avatar_data)
Global.avatars.update_avatar_transform(alias, transform)
Global.avatars.update_avatar_transform_with_godot_transform(alias, transform)

spawning_position.append(initial_position)

Expand All @@ -91,4 +91,4 @@ func _process(dt):

spawning_position[i] = target_position
var alias = 10000 + i
Global.avatars.update_avatar_transform(alias, transform)
Global.avatars.update_avatar_transform_with_godot_transform(alias, transform)
2 changes: 1 addition & 1 deletion godot/src/ui/components/backpack/backpack.gd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func _on_wearable_button_filter_type(type):
skin_color_picker.show()


func _on_wearable_button_clear_filter(type):
func _on_wearable_button_clear_filter(_type):
filtered_data = []
show_wearables()

Expand Down
4 changes: 2 additions & 2 deletions godot/src/ui/components/chat/chat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const ACK: String = "␆"
func _on_chats_arrived(chats: Array):
for chat in chats:
var address: String = chat[0]
var profile_name: StringName = chat[1]
var timestamp: float = chat[2]
var _profile_name: StringName = chat[1]
var _timestamp: float = chat[2]
var message: StringName = chat[3]
var avatar = Global.avatars.get_avatar_by_address(address)

Expand Down
Loading
Loading