diff --git a/menu/LoadWorld.gd b/menu/LoadWorld.gd index 918f03b..23cdbda 100644 --- a/menu/LoadWorld.gd +++ b/menu/LoadWorld.gd @@ -15,4 +15,4 @@ func _on_CancelButton_pressed(): func _button_pressed(name): Global.terrain_name = name - get_tree().change_scene("res://utils/world_generation/WorldGeneration.tscn") + get_tree().change_scene("res://menu/LoadingScreen.tscn") diff --git a/menu/LoadingScreen.gd b/menu/LoadingScreen.gd new file mode 100644 index 0000000..57858a2 --- /dev/null +++ b/menu/LoadingScreen.gd @@ -0,0 +1,28 @@ +extends Control + +var thread +var world = {} + +func _ready(): + thread = Thread.new() + thread.start(self, "_generate_world") + set_process(true) +# +# while true: +# if "step" in world: +# if world.step >= world.max_step: +# break +# print(world.step) +# $ProgressBar.value = world.step / world.max_step * 100 + +func _process(delta): + if "step" in world: + print(world.step) + if world.step >= 2: + get_tree().change_scene("res://world/game.tscn") + +func _exit_tree(): + thread.wait_to_finish() + +func _generate_world(): + world = WorldGeneration.new() diff --git a/utils/world_generation/WorldGeneration.tscn b/menu/LoadingScreen.tscn similarity index 69% rename from utils/world_generation/WorldGeneration.tscn rename to menu/LoadingScreen.tscn index 5314da0..b4df5ca 100644 --- a/utils/world_generation/WorldGeneration.tscn +++ b/menu/LoadingScreen.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=2 format=2] -[ext_resource path="res://utils/world_generation/WorldGeneration.gd" type="Script" id=1] +[ext_resource path="res://menu/LoadingScreen.gd" type="Script" id=1] -[node name="WorldGeneration" type="Control"] +[node name="LoadingScreen" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 1 ) diff --git a/menu/NewWorld.gd b/menu/NewWorld.gd index d747012..f7e9108 100644 --- a/menu/NewWorld.gd +++ b/menu/NewWorld.gd @@ -11,4 +11,4 @@ func _on_CancelButton_pressed(): func _on_CreateButton_pressed(): Global.terrain_name = $VBoxContainer/LineEdit.text - get_tree().change_scene("res://utils/world_generation/WorldGeneration.tscn") + get_tree().change_scene("res://menu/LoadingScreen.tscn") diff --git a/project.godot b/project.godot index 1a7a8ad..bc1444c 100644 --- a/project.godot +++ b/project.godot @@ -33,13 +33,19 @@ _global_script_classes=[ { "class": "Terrain", "language": "GDScript", "path": "res://utils/terrain/Terrain.gd" +}, { +"base": "Control", +"class": "WorldGeneration", +"language": "GDScript", +"path": "res://utils/world_generation/WorldGeneration.gd" } ] _global_script_class_icons={ "CameraController": "", "CameraOutline": "", "Delaunator": "", "PoissonDiscSampling": "", -"Terrain": "" +"Terrain": "", +"WorldGeneration": "" } [application] diff --git a/utils/world_generation/WorldGeneration.gd b/utils/world_generation/WorldGeneration.gd index a9b8826..bbc5045 100644 --- a/utils/world_generation/WorldGeneration.gd +++ b/utils/world_generation/WorldGeneration.gd @@ -1,5 +1,7 @@ extends Control +class_name WorldGeneration + export(int) var width = 2000 export(int) var height = 2000 export(int) var spacing = 20 @@ -14,16 +16,10 @@ export(int) var river_proba = 200 var rng = RandomNumberGenerator.new() var noise = OpenSimplexNoise.new() -var thread - -func _ready(): - thread = Thread.new() - thread.start(self, "_generate_world") - -func _exit_tree(): - thread.wait_to_finish() +var step = 0 +var max_step = 5 -func _generate_world(): +func _init(): rng.randomize() noise.seed = rng.randi() noise.octaves = octaves @@ -32,7 +28,8 @@ func _generate_world(): Global.terrain.load(Global.terrain_name) else: Global.terrain.create(width,height,spacing,Global.terrain_name) - + + step += 1 if Global.terrain.is_created(): init_data() @@ -40,13 +37,13 @@ func _generate_world(): if Global.terrain.is_created() or Global.terrain.is_loaded(): add_trees() - get_tree().change_scene("res://world/game.tscn") + step += 1 + # get_tree().change_scene("res://world/game.tscn") else: Global.print_debug("Pas de Global.terrain, pas de construction ...") Global.print_debug("Pas de construction ..., pas de palais ...") Global.print_debug("Pas de palais ..., pas de palais.") - func init_data(): # for point in Global.terrain.get_points(): # point.set_elevation(point_find_elevation(point.point2d())) diff --git a/world.mesh b/world.mesh new file mode 100644 index 0000000..d76dd56 Binary files /dev/null and b/world.mesh differ diff --git a/world/World3d.gd b/world/World3d.gd index 9c2e2cd..c9fe61c 100644 --- a/world/World3d.gd +++ b/world/World3d.gd @@ -33,6 +33,9 @@ func draw_world(): st.index() # Commit to a mesh. var mesh = st.commit() + + var file_name = "user://terrain/%s/world.mesh" % (Global.terrain_name) + ResourceSaver.save(file_name, mesh) var mi = MeshInstance.new() mi.mesh = mesh @@ -40,5 +43,4 @@ func draw_world(): mi.set_surface_material(0, material) mi.create_trimesh_collision() mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON - print(mi) add_child(mi)