Huge amount of updates
This commit is contained in:
@ -72,7 +72,35 @@ func _on_load_map(map_name: String) -> void:
|
||||
if scene.can_instantiate():
|
||||
var node: Node3D = scene.instantiate()
|
||||
logger.info("loading map: " + map_name)
|
||||
level_root.add_child(node)
|
||||
$LevelLoader/MultiplayerSpawner.spawn_function = _map_spawn_function
|
||||
$LevelLoader/MultiplayerSpawner.spawn(map_name)
|
||||
#level_root.add_child(node)
|
||||
else:
|
||||
logger.error("Can't initialize")
|
||||
|
||||
var thread: Thread
|
||||
var map_node: Node
|
||||
var mutex: Mutex
|
||||
|
||||
func _load_the_map_in_thread(map_name):
|
||||
var path_tmpl := "res://scenes/maps/maps/%s"
|
||||
var path := path_tmpl % map_name
|
||||
|
||||
if not ResourceLoader.exists(path):
|
||||
logger.error("map " + map_name + " doesn't exist")
|
||||
mutex.lock()
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
if scene.can_instantiate():
|
||||
map_node = scene.instantiate()
|
||||
mutex.unlock()
|
||||
|
||||
func _map_spawn_function(map_name: Variant) -> Node:
|
||||
thread = Thread.new()
|
||||
mutex = Mutex.new()
|
||||
thread.start(Callable(self, "_load_the_map_in_thread").bind(map_name))
|
||||
await thread.wait_to_finish()
|
||||
mutex.lock()
|
||||
var result = map_node
|
||||
mutex.unlock()
|
||||
return result
|
||||
|
||||
|
@ -6,13 +6,4 @@
|
||||
editor_description = "This node serves a starting point for the game. When the game is running as a dedicated server it's supposed to read the config file and start the server, when the game is running in a default mode, it should render the main menu"
|
||||
script = ExtResource("1_eb14f")
|
||||
|
||||
[node name="LevelLoader" type="Node" parent="."]
|
||||
editor_description = "This node is supposed to make it possible to sync the server data across all the possible players"
|
||||
|
||||
[node name="Level" type="Node3D" parent="LevelLoader"]
|
||||
|
||||
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="LevelLoader"]
|
||||
_spawnable_scenes = PackedStringArray("res://scenes/maps/maps/lowpoly_tdm_1.tscn")
|
||||
spawn_path = NodePath("../Level")
|
||||
|
||||
[connection signal="load_map" from="." to="." method="_on_load_map"]
|
||||
|
Reference in New Issue
Block a user