diff --git a/map.png b/map.png deleted file mode 100644 index 6aa2e53..0000000 Binary files a/map.png and /dev/null differ diff --git a/map.png.import b/map.png.import deleted file mode 100644 index 1a95dd4..0000000 --- a/map.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/map.png-9eea34967fae34f4388f4a32a16da936.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://map.png" -dest_files=[ "res://.import/map.png-9eea34967fae34f4388f4a32a16da936.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/menu/LoadWorld.gd b/menu/LoadWorld.gd index 23cdbda..57ce9fd 100644 --- a/menu/LoadWorld.gd +++ b/menu/LoadWorld.gd @@ -10,9 +10,13 @@ func _ready(): $VBoxContainer/ScrollContainer/WorldList.add_child(button) func _on_CancelButton_pressed(): - get_tree().change_scene("res://menu/MainMenu.tscn") + var error = get_tree().change_scene("res://menu/MainMenu.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) func _button_pressed(name): Global.terrain_name = name - get_tree().change_scene("res://menu/LoadingScreen.tscn") + var error = get_tree().change_scene("res://menu/LoadingScreen.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) diff --git a/menu/LoadingScreen.gd b/menu/LoadingScreen.gd index 3ec7eeb..800df01 100644 --- a/menu/LoadingScreen.gd +++ b/menu/LoadingScreen.gd @@ -14,11 +14,14 @@ func _process(_delta): if Global.loadings["world_creation"].get_current_phase(): $VBoxContainer/HBoxContainer/Phase.text = Global.loadings["world_creation"].get_current_phase().get_label() if Global.loadings["world_creation"].is_finished: + Global.terrain.reset_temp_data() for phase in Global.loadings["world_creation"].get_phases(): Global.print_debug("%s : %f seconds" % [phase.get_label(), phase.get_elapsed_time("s")]) Global.print_debug("Elapsed time : %f seconds" % Global.loadings["world_creation"].get_elapsed_time("s")) - get_tree().change_scene("res://world/game.tscn") + var error = get_tree().change_scene("res://world/game.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) func _exit_tree(): thread.wait_to_finish() diff --git a/menu/MainMenu.gd b/menu/MainMenu.gd index b34cc0d..65d897a 100644 --- a/menu/MainMenu.gd +++ b/menu/MainMenu.gd @@ -6,12 +6,15 @@ func _ready(): func _on_NewButton_pressed(): - get_tree().change_scene("res://menu/NewWorld.tscn") + var error = get_tree().change_scene("res://menu/NewWorld.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) func _on_LoadButton_pressed(): - get_tree().change_scene("res://menu/LoadWorld.tscn") - + var error = get_tree().change_scene("res://menu/LoadWorld.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) func _on_QuitButton_pressed(): get_tree().quit() diff --git a/menu/NewWorld.gd b/menu/NewWorld.gd index f7e9108..1a601e3 100644 --- a/menu/NewWorld.gd +++ b/menu/NewWorld.gd @@ -6,9 +6,13 @@ func _ready(): func _on_CancelButton_pressed(): - get_tree().change_scene("res://menu/MainMenu.tscn") + var error = get_tree().change_scene("res://menu/MainMenu.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) func _on_CreateButton_pressed(): Global.terrain_name = $VBoxContainer/LineEdit.text - get_tree().change_scene("res://menu/LoadingScreen.tscn") + var error = get_tree().change_scene("res://menu/LoadingScreen.tscn") + if error != 0: + Global.print_debug("Error : %d" % (error)) diff --git a/ui/map/map.gd b/ui/map/map.gd index e7e1d7e..c133f2d 100644 --- a/ui/map/map.gd +++ b/ui/map/map.gd @@ -3,7 +3,7 @@ extends TextureRect signal map_clicked func _ready(): - var file_name = 'user://terrain/%s/map.png' % (Global.terrain_name) + var file_name = 'user://terrain/%s/biome_map.png' % (Global.terrain_name) var image = Image.new() var err = image.load(file_name) if err != OK: diff --git a/utils/Global.gd b/utils/Global.gd index 9eb42ff..63897e1 100644 --- a/utils/Global.gd +++ b/utils/Global.gd @@ -2,7 +2,7 @@ extends Node var debug = true var terrain_name = "" -var terrain_mesh: Mesh +var array_mesh var terrain = Terrain.new() var map = Map.new(terrain) # var loading = LoadingHelper.new() diff --git a/utils/camera/CamBase.gd b/utils/camera/CamBase.gd index 111b695..2474567 100644 --- a/utils/camera/CamBase.gd +++ b/utils/camera/CamBase.gd @@ -11,7 +11,7 @@ var selected_units = [] onready var selection_box = $SelectionBox var start_sel_pos = Vector2() -func _process(delta): +func _process(_delta): var m_pos = get_viewport().get_mouse_position() # calc_move(m_pos, delta) if Input.is_action_just_pressed("main_command"): @@ -94,5 +94,5 @@ func raycast_from_mouse(m_pos, collision_mask): return space_state.intersect_ray(ray_start, ray_end, [], collision_mask) -func _on_Camera_camera_moved(new_location): +func _on_Camera_camera_moved(_new_location): pass # Replace with function body. diff --git a/utils/camera/CameraController.gd b/utils/camera/CameraController.gd index fff62f3..54e04de 100644 --- a/utils/camera/CameraController.gd +++ b/utils/camera/CameraController.gd @@ -8,8 +8,8 @@ enum CAMERA_ACTIONS{ ROTATING_VIEW, } -export(float,1,100) var movement_speed = 48 -export(float, 100, 10000) var up_speed = 800 +export(float,1,100) var movement_speed = 48.0 +export(float, 100, 10000) var up_speed = 800.0 export(float,0.01,0.99) var movement_damping = 0.74 export(float,0.01, 3.1415) var max_rotation = 1.2 export(float,0.01, 3.1415) var min_rotation = 0.5 @@ -19,8 +19,8 @@ export(float,0.01, 3.1415) var min_rotation = 0.5 export(float, 0.0,1.0) var edge_size = 0.0 #EDIT HERE--->**,***<--- ZOOM MIN AND MAX LIMITS -export(float, 10,100) var min_zoom = 10 -export(float, 10,100) var max_zoom = 100 +export(float, 10,100) var min_zoom = 10.0 +export(float, 10,100) var max_zoom = 100.0 export(float, 1,3) var zoom_sensibility = 1.4 diff --git a/utils/camera/CameraInput.gd b/utils/camera/CameraInput.gd index 466da10..f1cae30 100644 --- a/utils/camera/CameraInput.gd +++ b/utils/camera/CameraInput.gd @@ -22,7 +22,9 @@ var touch_count : int = 0 var swipe_start : Vector2 func _ready(): - connect("on_change_action",self,"change_action") + var error = connect("on_change_action",self,"change_action") + if error != 0: + Global.print_debug("Error : %d" % (error)) emit_signal("on_change_action",CameraController.CAMERA_ACTIONS.MOVING) func change_action(action): diff --git a/utils/camera/SelectionBox.gd b/utils/camera/SelectionBox.gd index 7efffc1..8dc8b5a 100644 --- a/utils/camera/SelectionBox.gd +++ b/utils/camera/SelectionBox.gd @@ -13,5 +13,5 @@ func _draw(): draw_line(m_pos, Vector2(m_pos.x, start_sel_pos.y), sel_box_col, sel_box_line_width) draw_line(m_pos, Vector2(start_sel_pos.x, m_pos.y), sel_box_col, sel_box_line_width) -func _process(delta): +func _process(_delta): update() diff --git a/utils/map/map.gd b/utils/map/map.gd index 9454c16..b0c13fa 100644 --- a/utils/map/map.gd +++ b/utils/map/map.gd @@ -1,33 +1,222 @@ extends Reference -# Build terrain from delaunay graph +# Build Height map, Biome map, Temperature map and Moisture map + class_name Map -var image +var data = {} var terrain # Called when the node enters the scene tree for the first time. func _init(a_terrain): + var texture_colors = {} + var height_gradient + var temperature_gradient + var moisture_gradient self.terrain = a_terrain a_terrain.set_data("map",self) + + # Read texture colors + var file = File.new() + file.open("res://world/texture_colors.json", File.READ) + var json_data = JSON.parse(file.get_as_text()).result + file.close() + + for key in json_data: + print("Texture color : %s" % (key)) + texture_colors[key] = Color( + json_data[key]["r"], + json_data[key]["g"], + json_data[key]["b"]) + + # read gradients + file.open("res://world/maps.json", File.READ) + json_data = JSON.parse(file.get_as_text()).result + file.close() + + height_gradient = Gradient.new() + for gradient_point in json_data["gradients"]["height"]: + height_gradient.add_point(gradient_point["offset"], Color( + gradient_point["color"]["r"], + gradient_point["color"]["g"], + gradient_point["color"]["b"])) + + temperature_gradient = Gradient.new() + for gradient_point in json_data["gradients"]["temperature"]: + temperature_gradient.add_point(gradient_point["offset"], Color( + gradient_point["color"]["r"], + gradient_point["color"]["g"], + gradient_point["color"]["b"])) + + moisture_gradient = Gradient.new() + for gradient_point in json_data["gradients"]["moisture"]: + moisture_gradient.add_point(gradient_point["offset"], Color( + gradient_point["color"]["r"], + gradient_point["color"]["g"], + gradient_point["color"]["b"])) + + terrain.set_temp_data("texture_colors", texture_colors) + terrain.set_temp_data("height_gradient", height_gradient) + terrain.set_temp_data("temperature_gradient", temperature_gradient) + terrain.set_temp_data("moisture_gradient", moisture_gradient) func gen_map(): - Global.loadings["world_creation"].new_phase("Generation de la carte...", terrain._points.size()) - image = Image.new() - image.create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) - image.lock() - image.fill(Color('#5aa6ca')) - image.unlock() - var file_name = "user://terrain/%s/map.png" % (terrain.get_name()) + + var max_elevation = null + var min_elevation = null + var max_temperature = null + var min_temperature = null + var max_moisture = null + var min_moisture = null + + var texture_colors = terrain.get_temp_data("texture_colors") + var height_gradient = terrain.get_temp_data("height_gradient") + var temperature_gradient = terrain.get_temp_data("temperature_gradient") + var moisture_gradient = terrain.get_temp_data("moisture_gradient") + + Global.loadings["world_creation"].new_phase("Generation des cartes...", terrain._points.size()) + + Global.print_debug("Init data") + data["height"] = {} + data["biome"] = {} + data["temperature"] = {} + data["moisture"] = {} + + Global.print_debug("Create images objects") + data["height"]["image"] = Image.new() + data["biome"]["image"] = Image.new() + data["temperature"]["image"] = Image.new() + data["moisture"]["image"] = Image.new() + + Global.print_debug("Create images") + data["height"]["image"].create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) + data["biome"]["image"].create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) + data["temperature"]["image"].create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) + data["moisture"]["image"].create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) + + Global.print_debug("Lock images") + data["height"]["image"].lock() + data["biome"]["image"].lock() + data["temperature"]["image"].lock() + data["moisture"]["image"].lock() + + Global.print_debug("Fill height map oceans") + data["height"]["image"].fill(texture_colors["ocean"]) + + Global.print_debug("Fill biome map oceans") + data["biome"]["image"].fill(texture_colors["ocean"]) + Global.print_debug("Fill temperature map oceans") + data["temperature"]["image"].fill(texture_colors["ocean"]) + + Global.print_debug("Fill moisture map oceans") + data["moisture"]["image"].fill(texture_colors["ocean"]) + + Global.print_debug("Unlock images") + data["height"]["image"].unlock() + data["biome"]["image"].unlock() + data["temperature"]["image"].unlock() + data["moisture"]["image"].unlock() + + Global.print_debug("Init paths") + data["height"]["file_name"] = "user://terrain/%s/height_map.png" % (terrain.get_name()) + data["biome"]["file_name"] = "user://terrain/%s/biome_map.png" % (terrain.get_name()) + data["temperature"]["file_name"] = "user://terrain/%s/temperature_map.png" % (terrain.get_name()) + data["moisture"]["file_name"] = "user://terrain/%s/moisture_map.png" % (terrain.get_name()) + + Global.print_debug("For centers ...") for center in terrain.get_centers(): if not center.get_data("water"): var voronoi = center.get_data("voronoi") var voronoi_bounding_box = center.get_data("voronoi_bounding_box") -# print_debug("Creat voronoi image") - var voronoi_image = Image.new() - voronoi_image.create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) - voronoi_image.lock() + + var voronoi_image = {} + + var color = {} + + var elevation = center.get_elevation() + if max_elevation == null: + max_elevation = elevation + min_elevation = elevation + else: + if elevation > max_elevation: + max_elevation = elevation + if elevation < min_elevation: + min_elevation = elevation + + var temperature = center.get_data("temperature") + if max_temperature == null: + max_temperature = temperature + min_temperature = temperature + else: + if temperature > max_temperature: + max_temperature = temperature + if temperature < min_temperature: + min_temperature = temperature + + var moisture = center.get_data("moisture") + if max_moisture == null: + max_moisture = moisture + min_moisture = moisture + else: + if moisture > max_moisture: + max_moisture = moisture + if moisture < min_moisture: + min_moisture = moisture + +# Global.print_debug("Elevation : %f" % (elevation)) +# Global.print_debug("Temperature : %f" % (temperature)) +# Global.print_debug("Moisture : %f" % (moisture)) + + voronoi_image["height"] = Image.new() + voronoi_image["biome"] = Image.new() + voronoi_image["temperature"] = Image.new() + voronoi_image["moisture"] = Image.new() + + voronoi_image["height"].create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) + voronoi_image["biome"].create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) + voronoi_image["temperature"].create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) + voronoi_image["moisture"].create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) + + voronoi_image["height"].lock() + voronoi_image["biome"].lock() + voronoi_image["temperature"].lock() + voronoi_image["moisture"].lock() + + # Height map +# Global.print_debug("Height map") + color["height"] = height_gradient.interpolate(elevation) + + # Biome map +# Global.print_debug("Biome map") + if center.get_data("coast"): + # Coast color + color["biome"] = texture_colors["sand"] + + elif center.get_data("snow"): + # Snow color + color["biome"] = texture_colors["snow"] + + elif center.get_data("river"): + # River color + color["biome"] = texture_colors["river"] + + elif center.get_data("mountain"): + # Montain color + color["biome"] = texture_colors["stone"] + + else: + # Grass color + color["biome"] = texture_colors["grass"] + + # Temperature map +# Global.print_debug("Temperature map") + color["temperature"] = temperature_gradient.interpolate(range_lerp(temperature,-80.0,50.0,0.001,0.999)) + + # Moisture map +# Global.print_debug("Moisture map") + color["moisture"] = moisture_gradient.interpolate(range_lerp(moisture,-0.7,0.7,0.001,0.999)) + for x in int(voronoi_bounding_box.size.x): for y in int(voronoi_bounding_box.size.y): var pixel = [] @@ -35,17 +224,54 @@ func gen_map(): pixel.append(Vector2(voronoi_bounding_box.position.x + x + 1, voronoi_bounding_box.position.y + y)) pixel.append(Vector2(voronoi_bounding_box.position.x + x + 1, voronoi_bounding_box.position.y + y + 1)) pixel.append(Vector2(voronoi_bounding_box.position.x + x, voronoi_bounding_box.position.y + y + 1)) + var alpha = Global.pixel_area(voronoi, pixel) -# print_debug("Alpha : %f" % (alpha)) - var color - if center.get_data("coast"): - color = Color(0.708, 0.646, 0.138, alpha) - else: - color = Color(0.253, 0.621, 0.229, alpha) - voronoi_image.set_pixel(x,y,color) - image.lock() - image.blend_rect(voronoi_image,Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) - image.unlock() - voronoi_image.unlock() + + color["height"].a = alpha + color["biome"].a = alpha + color["temperature"].a = alpha + color["moisture"].a = alpha + + voronoi_image["height"].set_pixel(x,y,color["height"]) + voronoi_image["biome"].set_pixel(x,y,color["biome"]) + voronoi_image["temperature"].set_pixel(x,y,color["temperature"]) + voronoi_image["moisture"].set_pixel(x,y,color["moisture"]) + +# Global.print_debug("Lock image") + data["height"]["image"].lock() + data["biome"]["image"].lock() + data["temperature"]["image"].lock() + data["moisture"]["image"].lock() + +# Global.print_debug("Blend image") + data["height"]["image"].blend_rect(voronoi_image["height"],Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) + data["biome"]["image"].blend_rect(voronoi_image["biome"],Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) + data["temperature"]["image"].blend_rect(voronoi_image["temperature"],Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) + data["moisture"]["image"].blend_rect(voronoi_image["moisture"],Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) + +# Global.print_debug("Unlock image") + data["height"]["image"].unlock() + data["biome"]["image"].unlock() + data["temperature"]["image"].unlock() + data["moisture"]["image"].unlock() + + voronoi_image["height"].unlock() + voronoi_image["biome"].unlock() + voronoi_image["temperature"].unlock() + voronoi_image["moisture"].unlock() + Global.loadings["world_creation"].increment_step() - image.save_png(file_name) + + Global.print_debug("Max elevation : %f" % (max_elevation)) + Global.print_debug("Min elevation : %f" % (min_elevation)) + Global.print_debug("Max temperature : %f" % (max_temperature)) + Global.print_debug("Min temperature : %f" % (min_temperature)) + Global.print_debug("Max moisture : %f" % (max_moisture)) + Global.print_debug("Min moisture : %f" % (min_moisture)) + + data["height"]["image"].save_png(data["height"]["file_name"]) + data["biome"]["image"].save_png(data["biome"]["file_name"]) + data["temperature"]["image"].save_png(data["temperature"]["file_name"]) + data["moisture"]["image"].save_png(data["moisture"]["file_name"]) + + Global.print_debug("Sauvegarde map") diff --git a/utils/terrain/Terrain.gd b/utils/terrain/Terrain.gd index f5a062c..1e79e3f 100644 --- a/utils/terrain/Terrain.gd +++ b/utils/terrain/Terrain.gd @@ -1,5 +1,5 @@ extends Reference -# test + # Build terrain from delaunay graph class_name Terrain @@ -586,9 +586,6 @@ func _init(): var directory_name = "" var path = "" var parameter = {} - var parameter_file_name = "" - var graph_file_name = "" - var data_file_name = "" # Get list terrain directory.open("user://") @@ -670,7 +667,7 @@ func _create_find_point_table(): var point_index = point.get_index() find_point[point.find_index()].append(point_index) - var center = point.to_center() +# var center = point.to_center() set_data("find_point",find_point) @@ -701,8 +698,11 @@ func get_name(): func get_temp_data(key): if _temp_data.has(key): return _temp_data[key] + else: + Global.print_debug("Temp data has no key : %s" % (key)) func reset_temp_data(): + Global.print_debug("reset_temp_data") _temp_data = {} # Reset _points_data diff --git a/utils/terrain_mesh/TerrainMesh.gd b/utils/terrain_mesh/TerrainMesh.gd index f8a552d..ac8b448 100644 --- a/utils/terrain_mesh/TerrainMesh.gd +++ b/utils/terrain_mesh/TerrainMesh.gd @@ -72,7 +72,7 @@ func create_mesh(): # var terrain_mesh = TerrainMesh.new() var mesh = ArrayMesh.new() - mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, array_mesh) + mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, array_mesh, [], Mesh.ARRAY_COMPRESS_DEFAULT ^ Mesh.ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) mesh.surface_set_material(0, load("res://world/materials/world.material")) save_mesh(array_mesh) diff --git a/utils/world_generation/WorldGeneration.gd b/utils/world_generation/WorldGeneration.gd index ecd570a..5e231c4 100644 --- a/utils/world_generation/WorldGeneration.gd +++ b/utils/world_generation/WorldGeneration.gd @@ -7,7 +7,7 @@ export(int) var height = 2048 export(int) var spacing = 5 export(int, 1, 9) var octaves = 5 export(int, 1, 30) var wavelength = 8 -export(int) var border_width = 200 +#export(int) var border_width = 200 export(int) var terraces = 100 export(int) var terrace_height = 5 export(float) var mountain_height = 0.3 @@ -26,32 +26,41 @@ func _init(): Global.loadings["world_creation"].start(coeffs, "Chargement...", 100) Global.terrain.load(Global.terrain_name) else: - var coeffs = [0, 1, 2, 2, 2, 2, 2, 8, 8] + var coeffs = [0, 1, 2, 2, 2, 2, 2, 2, 8, 8] Global.loadings["world_creation"].start(coeffs, "Start", 100) Global.terrain.create(width,height,spacing,Global.terrain_name) if Global.terrain.is_created(): init_data() - Global.terrain.reset_temp_data() Global.terrain.save() var terrain_mesh = TerrainMesh.new() - Global.terrain.set_temp_data("mesh", terrain_mesh.create_mesh()) + Global.array_mesh = terrain_mesh.create_mesh() Global.map.gen_map() if Global.terrain.is_loaded(): var terrain_mesh = TerrainMesh.new() - Global.terrain.set_temp_data("mesh", terrain_mesh.load_mesh()) + Global.array_mesh = terrain_mesh.load_mesh() Global.loadings["world_creation"].stop() func init_data(): Global.loadings["world_creation"].new_phase("Generation des continents...", Global.terrain.get_centers().size()) + + # Génération des contients for center in Global.terrain.get_centers(): - center.set_elevation(find_elevation(center.point2d())) - center.set_data("temperature", find_temperature(center)) - center.set_data("moisture", find_moisture(center.point2d())) - if center.get_data("temperature") > 0.5: + var elevation = find_elevation(center.point2d()) + center.set_elevation(elevation) + + var temperature = find_temperature(center) + center.set_data("temperature", temperature) + + var moisture = find_moisture(center.point2d()) + center.set_data("moisture", moisture) + + if temperature < 0.0 and moisture > 0.0: center.set_data("snow", true) + else : + center.set_data("snow", false) if center.get_elevation() <= 0.0: center.set_data("water", true) if center.get_elevation() >= mountain_height: @@ -60,10 +69,28 @@ func init_data(): Global.loadings["world_creation"].increment_step() Global.loadings["world_creation"].new_phase("Remplissage des oceans...", 1) + + # Génération des océants fill_oceans() remove_holes() - + + Global.loadings["world_creation"].new_phase("Generation des rivières...", Global.terrain.get_centers().size()) + + # Génération des rivières + for center in Global.terrain.get_centers(): + if point_is_river(center.to_point()): + print("Rivière") + center.set_data("river", true) + set_river_path(center.to_point()) + else: + center.set_data("river", false) + + Global.loadings["world_creation"].increment_step() + + Global.loadings["world_creation"].new_phase("Generation des biomes...", Global.terrain.get_centers().size()) + + # Génération des biomes for center in Global.terrain.get_centers(): center.set_data("coast", is_coast(center.to_point())) # if center.get_data("ocean"): @@ -74,6 +101,9 @@ func init_data(): center.set_data("material", "stone") if center.get_data("coast"): center.set_data("material", "sand") + if center.get_data("river"): + center.set_data("material", "river") + if ( not center.get_data("coast") @@ -91,13 +121,11 @@ func init_data(): Global.loadings["world_creation"].increment_step() - - # for point in Global.terrain.get_points(): - # point.set_elevation(point_find_elevation(point.point2d())) - # point.set_data("water", point_is_water(point)) - # point.set_data("mountain", point_is_mountain(point)) - # point.set_data("river", point_is_river(point)) + # point.set_elevation(point_find_elevation(point.point2d())) + # point.set_data("water", point_is_water(point)) + # point.set_data("mountain", point_is_mountain(point)) + # point.set_data("river", point_is_river(point)) # fill_oceans() @@ -133,8 +161,6 @@ func init_data(): # edge.set_data("coast", edge_is_coast(edge)) # edge.set_data("river", edge_is_river(edge)) - - func set_river_path(point): #TODO #2 fix rivers var start_elevation = point.get_elevation() @@ -223,16 +249,6 @@ func edge_is_river(edge): return true return false - - - - - - - - - - func find_elevation(point): # var border = border_width + rng.randf_range(-20.0, 20.0) @@ -259,16 +275,16 @@ func find_elevation(point): return elevation func find_moisture(point): - var elevation = noise.get_noise_2d((point.x + 100) / wavelength * 2, (point.y + 100) / wavelength * 2) - return elevation + var moisture = noise.get_noise_2d((point.x + 100) / wavelength * 2, (point.y + 100) / wavelength * 2) + return moisture func find_temperature(center): - - var poles = 4 - var equator = -4 + var poles = 80.0 + var equator = -40.0 var elevation = center.get_elevation() +# Global.print_debug("Elevation : %f" % (elevation)) var latitude = sin(PI * (float(center.point2d().y) / float(Global.terrain.get_parameters()["height"]))) - var temperature = 40*elevation*elevation + poles + (equator-poles) * latitude + var temperature = (150.0 * elevation * elevation + poles + (equator-poles) * latitude) * -1.0 return temperature func fill_oceans(): @@ -299,37 +315,3 @@ func is_coast(point): if neighbour.get_data("ocean"): return true return false - - - - -# Enregistrement de la map + intégration dans la génération du monde #32 - -# func create_map(): -# print("oui") -# var viewport = Viewport.new() -# viewport.size = Vector2(width, height) -# var canvas = Node2D.new() -# viewport.add_child(canvas) -# canvas.draw_line(Vector2(0.0, 0.0), Vector2(1000.0, 1000.0), [Color("#5e4fa2")) -# for center in Global.terrain.get_centers(): -# var colors = Gradient.new() -# colors.add_point(0.999, Color("#9e0142")) # red -# colors.add_point(0.5, Color("#dc865d")) # orange -# colors.add_point(0.25, Color("#fbf8b0")) # yellow -# colors.add_point(0.0, Color("#89cfa5")) # green -# colors.add_point(-0.999, Color("#5e4fa2")) # blue -# var color = colors.interpolate(min(center.get_elevation() + 0.001, 0.999)) -# # color = Color.green -# if center.get_data("water"): -# # var factor = pow((center.get_elevation()+1.001), 10) / 5.0 -# color = Color("#5e4fa2") -# if center.polygon().size() > 2: -# canvas.draw_polygon(center.polygon(), PoolColorArray([color])) -# Global.loading.increment_step() - -# var img = viewport.get_texture().get_data() -# img.flip_y() -# var err = img.save_png("user://terrain/heightmap.png") -# print(err) -# # print("non") diff --git a/world/World3d.gd b/world/World3d.gd index 2489860..2c0b169 100644 --- a/world/World3d.gd +++ b/world/World3d.gd @@ -8,12 +8,16 @@ var unready_chunks = {} var thread func _ready(): + Global.print_debug("On ajoute le monde") add_world() + Global.print_debug("On ajoute les arbres") add_trees() + Global.print_debug("Le monde est prêt") func add_world(): var terrain_mesh = TerrainMesh.new() - terrain_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, Global.terrain.get_temp_data("mesh")) + terrain_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, Global.array_mesh, [], Mesh.ARRAY_COMPRESS_DEFAULT ^ Mesh.ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) + terrain_mesh.surface_set_material(0, load("res://world/materials/world.material")) var mi := MeshInstance.new() @@ -21,7 +25,6 @@ func add_world(): mi.create_trimesh_collision() add_child(mi) - Global.terrain.reset_temp_data() func add_trees(): rng.randomize() diff --git a/world/maps.json b/world/maps.json new file mode 100644 index 0000000..12515d6 --- /dev/null +++ b/world/maps.json @@ -0,0 +1,98 @@ +{ + "gradients": { + "height": [ + { + "offset": 0.999, + "color": { + "r": 0.62, + "g": 0.004, + "b": 0.259 + } + }, + { + "offset": 0.5, + "color": { + "r": 0.863, + "g": 0.525, + "b": 0.365 + } + }, + { + "offset": 0.25, + "color": { + "r": 0.984, + "g": 0.973, + "b": 0.69 + } + }, + { + "offset": 0.0, + "color": { + "r": 0.537, + "g": 0.812, + "b": 0.647 + } + } + ], + "temperature": [ + { + "offset": 0.999, + "color": { + "r": 0.62, + "g": 0.004, + "b": 0.259 + } + }, + { + "offset": 0.9, + "color": { + "r": 0.863, + "g": 0.525, + "b": 0.365 + } + }, + { + "offset": 0.8, + "color": { + "r": 0.984, + "g": 0.973, + "b": 0.69 + } + }, + { + "offset": 0.5, + "color": { + "r": 0.537, + "g": 0.812, + "b": 0.647 + } + }, + { + "offset": 0.0, + "color": { + "r": 0.369, + "g": 0.31, + "b": 0.635 + } + } + ], + "moisture": [ + { + "offset": 0.999, + "color": { + "r": 0.984, + "g": 0.973, + "b": 0.69 + } + }, + { + "offset": 0.0, + "color": { + "r": 0.537, + "g": 0.812, + "b": 0.647 + } + }, + ] + } +} diff --git a/world/materials/colors.png b/world/materials/colors.png index 150e083..a28a9f0 100644 Binary files a/world/materials/colors.png and b/world/materials/colors.png differ diff --git a/world/materials/materials.json b/world/materials/materials.json index 9e1aa31..8cf9dd8 100644 --- a/world/materials/materials.json +++ b/world/materials/materials.json @@ -2,5 +2,6 @@ "grass": 0, "stone": 1, "sand": 2, - "snow": 3 + "snow": 3, + "river": 4 } diff --git a/world/texture_colors.json b/world/texture_colors.json new file mode 100644 index 0000000..114c0e2 --- /dev/null +++ b/world/texture_colors.json @@ -0,0 +1,32 @@ +{ + "ocean": { + "r": 0.353, + "g": 0.651, + "b": 0.792 + }, + "grass": { + "r": 0.725, + "g": 0.749, + "b": 0.016 + }, + "stone": { + "r": 0.741, + "g": 0.69, + "b": 0.69 + }, + "sand": { + "r": 0.902, + "g": 0.886, + "b": 0.522 + }, + "snow": { + "r": 1.0, + "g": 1.0, + "b": 1.0 + }, + "river": { + "r": 0.584, + "g": 0.769, + "b": 0.847 + } +}