From 9ba79d9dc4bd812c277735461d5279c976a656a9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 31 Aug 2021 00:40:45 +0200 Subject: [PATCH] More work on fixing networking. Also updated ESS to get the fixes from it too. --- HEADS | 2 +- game/player/bs_entity_spawner.gd | 80 ++++++++++++++++++++++++-------- 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/HEADS b/HEADS index b34f2e71..eda17d2f 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "94a0fc47f7b4e90f8973f9adbfd3312579ed2825", "master": "8c73e813134001e575b6f59e3b0100471c007410", "3.x": "17e61fa0aff88f843b89e9769b81861c1954ef8a"}, "world_generator": {"master": "260c430f11b0b591eaf4714516419aa327d2842c"}, "entity_spell_system": {"master": "71dc15650adaeac2df0e113e398abb253c6d4926"}, "ui_extensions": {"master": "f82273f54cb1ab87d458c91af9554acec5c10831"}, "voxelman": {"master": "9253cc53c6fbbd78b5e4268eb498ef55b4dd0181"}, "texture_packer": {"master": "a0786956813a85b5a82093a081b90c2f8a000e6c"}, "fastnoise": {"master": "d447fd5364e9ab5a6b14184483eab23cd3fe820b"}, "mesh_data_resource": {"master": "4830687056297c432bfbfd1a2c1572546daf8e7d"}, "procedural_animations": {"master": "f8aae42bf06b3936cc6bd24cb18e1c3ec9f78f4f"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "props": {"master": "2afd6eff45f9a921bdf4090ff3029def86df5cb5"}, "mesh_utils": {"master": "92b6066d026ba8bfec62282063c372f5ec76dea4"}, "broken_seals_module": {"master": "2afea56eba66beeb543934edf5a38a8aa63fc79b"}, "thread_pool": {"master": "b2e8c815392052947e7386f722913a12eea543a4"}, "terraman": {"master": "86de26c2c7a15185658680ae79c39a0c8bb159ce"}} \ No newline at end of file +{"engine": {"3.2": "94a0fc47f7b4e90f8973f9adbfd3312579ed2825", "master": "8c73e813134001e575b6f59e3b0100471c007410", "3.x": "17e61fa0aff88f843b89e9769b81861c1954ef8a"}, "world_generator": {"master": "260c430f11b0b591eaf4714516419aa327d2842c"}, "entity_spell_system": {"master": "cc9dc30b8377552df79ee4d53e1ed6d51cb87408"}, "ui_extensions": {"master": "f82273f54cb1ab87d458c91af9554acec5c10831"}, "voxelman": {"master": "9253cc53c6fbbd78b5e4268eb498ef55b4dd0181"}, "texture_packer": {"master": "a0786956813a85b5a82093a081b90c2f8a000e6c"}, "fastnoise": {"master": "d447fd5364e9ab5a6b14184483eab23cd3fe820b"}, "mesh_data_resource": {"master": "4830687056297c432bfbfd1a2c1572546daf8e7d"}, "procedural_animations": {"master": "f8aae42bf06b3936cc6bd24cb18e1c3ec9f78f4f"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "props": {"master": "2afd6eff45f9a921bdf4090ff3029def86df5cb5"}, "mesh_utils": {"master": "92b6066d026ba8bfec62282063c372f5ec76dea4"}, "broken_seals_module": {"master": "2afea56eba66beeb543934edf5a38a8aa63fc79b"}, "thread_pool": {"master": "b2e8c815392052947e7386f722913a12eea543a4"}, "terraman": {"master": "86de26c2c7a15185658680ae79c39a0c8bb159ce"}} \ No newline at end of file diff --git a/game/player/bs_entity_spawner.gd b/game/player/bs_entity_spawner.gd index 9bbec2dd..aba39926 100644 --- a/game/player/bs_entity_spawner.gd +++ b/game/player/bs_entity_spawner.gd @@ -31,6 +31,8 @@ var _spawn_parent : Node = null var _next_entity_guid : int = 0 +var _debug : bool = false + func _ready(): # get_scene_tree().multiplayer.connect("network_peer_packet", self, "on_network_peer_packet") @@ -52,18 +54,29 @@ func on_network_peer_packet(id : int, packet : PoolByteArray) ->void: func spawn_for(player : Entity, target: Entity) -> void: Logger.info("spawnfor " + target.name) - print("spawnfor " + target.name) + + if _debug: + print("spawnfor " + player.name + " - " + target.name) + + if player == target: + if _debug: + print("spawn_for: player == target!") + return + rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.get_transform_3d().origin) func despawn_for(player : Entity, target: Entity) -> void: Logger.info("despawnfor " + target.name) - print("despawnfor " + target.name) + + if _debug: + print("despawnfor " + target.name) + rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path()) remote func creceive_spawn_for(data: String, global_name : String, position: Vector3) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() - createinfo.player_name = global_name + createinfo.node_name = global_name createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_NETWORKED createinfo.serialized_data = parse_json(data) @@ -73,6 +86,9 @@ remote func creceive_spawn_for(data: String, global_name : String, position: Vec Logger.info("Player spawned ") + if _debug: + print("creceive_spawn_for " + global_name) + return createinfo.created_entity remote func creceive_despawn_for(path : NodePath) -> void: @@ -85,8 +101,9 @@ remote func creceive_despawn_for(path : NodePath) -> void: remote func spawn_owned_player(data : String, position : Vector3) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() - createinfo.guid = _next_entity_guid - _next_entity_guid += 1 + #createinfo.guid = _next_entity_guid + #_next_entity_guid += 1 + #createinfo.node_name = global_name createinfo.network_owner = multiplayer.get_network_unique_id() # createinfo.player_name = "" createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER @@ -96,8 +113,11 @@ remote func spawn_owned_player(data : String, position : Vector3) -> Entity: ESS.request_entity_spawn(createinfo) var e : Entity = createinfo.created_entity - e.set_network_master(createinfo.network_owner) + #e.set_network_master(multiplayer.get_network_unique_id()) + if _debug: + print("spawn_owned_player " + e.name) + Logger.info("Player spawned ") return e @@ -105,8 +125,8 @@ remote func spawn_owned_player(data : String, position : Vector3) -> Entity: func load_player(file_name : String, position : Vector3, network_owner : int) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() - createinfo.guid = _next_entity_guid - _next_entity_guid += 1 + #createinfo.guid = _next_entity_guid + #_next_entity_guid += 1 createinfo.network_owner = network_owner # createinfo.player_name = name createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER @@ -116,14 +136,22 @@ func load_player(file_name : String, position : Vector3, network_owner : int) -> createinfo.networked = false Logger.info("Player spawned ") ESS.request_entity_spawn(createinfo) + + if _debug: + print("load_player " + file_name) return createinfo.created_entity func load_uploaded_character(data : String, position : Vector3, network_owner : int) -> Entity: + if _debug: + print("load_uploaded_character ") + + rpc_id(network_owner, "spawn_owned_player", data, position) + var createinfo : EntityCreateInfo = EntityCreateInfo.new() - createinfo.guid = _next_entity_guid - _next_entity_guid += 1 + #createinfo.guid = _next_entity_guid + #_next_entity_guid += 1 createinfo.network_owner = network_owner # createinfo.player_name = name createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER @@ -134,8 +162,9 @@ func load_uploaded_character(data : String, position : Vector3, network_owner : Logger.info("Player spawned ") ESS.request_entity_spawn(createinfo) var e : Entity = createinfo.created_entity - e.set_network_master(network_owner) - rpc_id(network_owner, "spawn_owned_player", data, position) + + #e.set_network_master(network_owner) + #e.centity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER return e @@ -169,8 +198,8 @@ func spawn_player_for_menu(class_id : int, name : String, parent : Node) -> Enti func spawn_display_player(file_name : String, node_path : NodePath) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() - createinfo.guid = _next_entity_guid - _next_entity_guid += 1 + #createinfo.guid = _next_entity_guid + #_next_entity_guid += 1 # createinfo.player_name = name createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY @@ -195,7 +224,7 @@ func spawn_networked_player(class_id : int, position : Vector3, name : String, createinfo.class_id = class_id createinfo.entity_data = cls - createinfo.player_name = name + createinfo.node_name = node_name createinfo.level = 1 # createinfo.class_level = level createinfo.xp = 0 @@ -225,7 +254,7 @@ func spawn_player(class_id : int, position : Vector3, name : String, node_name createinfo.class_id = class_id createinfo.entity_data = cls - createinfo.player_name = name + createinfo.node_name = node_name createinfo.level = 1 # createinfo.class_level = level createinfo.xp = 0 @@ -250,7 +279,7 @@ func spawn_mob(class_id : int, level : int, position : Vector3) -> void: createinfo.class_id = class_id createinfo.entity_data = cls - createinfo.player_name = "Mob" + #createinfo.node_name = "Mob" createinfo.level = level # createinfo.class_level = level createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_AI @@ -283,7 +312,7 @@ func _request_entity_spawn(createinfo : EntityCreateInfo): return null entity_node.set_transform_3d(createinfo.transform) - + if (createinfo.parent_path == ""): if _spawn_parent == null: _spawn_parent = get_tree().root.get_node(spawn_parent_path) @@ -294,7 +323,20 @@ func _request_entity_spawn(createinfo : EntityCreateInfo): spawn_parent.add_child(entity_node) else: get_tree().root.get_node(createinfo.parent_path).add_child(entity_node) - + + #print(entity_node.name) + + if createinfo.network_owner == 0: + if createinfo.node_name == "": + entity_node.name = "Entity_" + str(_next_entity_guid) + _next_entity_guid += 1 + else: + entity_node.name = createinfo.node_name + else: + entity_node.name = "Player_" + str(createinfo.network_owner) + + #print(entity_node.name) + entity_node.setup(createinfo) createinfo.created_entity = entity_node