ajout d'une animation de recharge et réparation du crash au chargement de chunk

This commit is contained in:
2026-01-16 12:28:36 +01:00
parent 74d2d0de3a
commit ff4feacea3
25 changed files with 431 additions and 236 deletions

View File

@@ -1,16 +1,15 @@
[gd_scene load_steps=13 format=3 uid="uid://bjs67nvh61otf"]
[gd_scene load_steps=12 format=3 uid="uid://bjs67nvh61otf"]
[ext_resource type="Script" uid="uid://bmb4beevw5r40" path="res://stages/region_selection/scripts/region_selection.gd" id="1_gqvix"]
[ext_resource type="PackedScene" uid="uid://cm5b7w7j6527f" path="res://stages/title_screen/planet_3d.tscn" id="5_bi8m0"]
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/hud.tres" id="5_twywe"]
[ext_resource type="Script" uid="uid://dqj1qh7xcmnhc" path="res://stages/region_selection/scripts/region_selection_camera.gd" id="6_gcxbq"]
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="6_gqvix"]
[ext_resource type="Shader" uid="uid://bv2rghn44mrrf" path="res://stages/title_screen/resources/shaders/stars.gdshader" id="7_2ywd4"]
[ext_resource type="PackedScene" uid="uid://rxao2rluuwqq" path="res://gui/game/screen/screen.tscn" id="7_gqvix"]
[ext_resource type="Script" path="res://stages/region_selection/scripts/region_selection_travel_validation.gd" id="8_jxqjc"]
[ext_resource type="Script" uid="uid://bmb4beevw5r40" path="res://stages/region_selection/scripts/region_selection.gd" id="8_jxqjc"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_twywe"]
seed = 172208034
[sub_resource type="FastNoiseLite" id="FastNoiseLite_gqvix"]
seed = 1021033283
frequency = 1.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ee13y"]
@@ -48,12 +47,12 @@ adjustment_contrast = 1.2
adjustment_saturation = 0.88
[node name="RegionSelectionScreen" type="Node3D"]
script = ExtResource("1_gqvix")
script = ExtResource("8_jxqjc")
[node name="Planet3d" parent="." instance=ExtResource("5_bi8m0")]
unique_name_in_owner = true
transform = Transform3D(0.17364822, 0, -0.9848077, 0, 1, 0, 0.9848077, 0, 0.17364822, 0.0020446777, 0, 0)
noise = SubResource("FastNoiseLite_twywe")
noise = SubResource("FastNoiseLite_gqvix")
[node name="RegionPointContainer" type="Node3D" parent="Planet3d"]
unique_name_in_owner = true
@@ -98,6 +97,7 @@ text = "RETURN"
[node name="TravelValidation" parent="Hud" instance=ExtResource("7_gqvix")]
unique_name_in_owner = true
visible = false
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
@@ -111,7 +111,6 @@ grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
script = ExtResource("8_jxqjc")
[node name="TravelValidationContainer" type="VBoxContainer" parent="Hud/TravelValidation/ScreenContainer" index="0"]
layout_mode = 2

View File

@@ -2,7 +2,7 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://c3t26nlbnkxg7"
uid="uid://ex35g5nvtsy0"
path="res://.godot/imported/garden_decontamined_background_texture_old.png-df017d633ed63644def49f2ef3a9d5b3.ctex"
metadata={
"vram_texture": false

View File

@@ -1,8 +1,9 @@
[gd_scene load_steps=8 format=3 uid="uid://tsi5j1uxppa4"]
[gd_scene load_steps=9 format=3 uid="uid://tsi5j1uxppa4"]
[ext_resource type="Script" uid="uid://d1mp5sguc0b6u" path="res://stages/terrain/planet/scripts/planet.gd" id="1_y7d8a"]
[ext_resource type="PackedScene" uid="uid://dt6mptqg80dew" path="res://gui/game/tutorial/tutorial.tscn" id="2_0wx6t"]
[ext_resource type="PackedScene" uid="uid://12nak7amd1uq" path="res://gui/game/game_gui.tscn" id="2_02xai"]
[ext_resource type="PackedScene" uid="uid://yk78ubpu5ghq" path="res://gui/game/pass_day/pass_day.tscn" id="3_0wx6t"]
[ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="3_6qoee"]
[ext_resource type="PackedScene" uid="uid://bgvbgeq46wee2" path="res://entities/player/player.tscn" id="4_hyapw"]
[ext_resource type="PackedScene" uid="uid://cg1visg52i21a" path="res://entities/interactables/truck/ladder/truck_ladder.tscn" id="5_yjoqs"]
@@ -13,11 +14,15 @@ script = ExtResource("1_y7d8a")
entity_container = NodePath("Entities")
[node name="PlanetGui" type="CanvasLayer" parent="."]
layer = 2
[node name="Tutorial" parent="PlanetGui" node_paths=PackedStringArray("player", "planet") instance=ExtResource("2_0wx6t")]
player = NodePath("../../Entities/Player")
planet = NodePath("../..")
[node name="PassDay" parent="PlanetGui" instance=ExtResource("3_0wx6t")]
unique_name_in_owner = true
[node name="GameGui" parent="." instance=ExtResource("2_02xai")]
[node name="Entities" type="Node2D" parent="."]
@@ -34,3 +39,6 @@ position = Vector2(-85, -165)
[node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_6qoee")]
position = Vector2(573, 324)
following = NodePath("../Entities/Player")
[connection signal="pass_day_ended" from="." to="GameGui" method="_on_planet_pass_day_ended"]
[connection signal="pass_day_started" from="." to="GameGui" method="_on_planet_pass_day_started"]

View File

@@ -6,8 +6,8 @@ signal generated
var planet : Planet
var planet_seed : int
var wall_threshold = 0.6
var decontamination_threshold = 0.8
var wall_threshold = 0.3
var decontamination_threshold = 0.
var cristal_threshold = 0.08
var rock_noise_image : Noise = null
var decontamination_noise_image : Noise = null
@@ -23,9 +23,6 @@ const GENERATION_NUMBER = 4
const NOISE_IMAGE_SIZE := 150
const LOOT_NUMBER : Array[int] = [2,3,4]
const LOOT_ITEM_NUMBER : Array[int] = [1,2]
const ROCK_NOISE_FREQUENCY := 0.01
const DECONTAMINATION_NOISE_FREQUENCY := 0.01
@@ -66,13 +63,13 @@ func unload():
planet.decontamination_layer.erase_cell(global_coord)
# Debug
func _draw():
draw_rect(
Rect2(Vector2.ZERO, Vector2.ONE * Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE),
Color.WHITE,
false,
3
)
# func _draw():
# draw_rect(
# Rect2(Vector2.ZERO, Vector2.ONE * Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE),
# Color.WHITE,
# false,
# 3
# )
# for x in range(NOISE_IMAGE_SIZE):
# for y in range(NOISE_IMAGE_SIZE):

View File

@@ -5,20 +5,20 @@ signal pass_day_started(planet : Planet)
signal pass_day_proceeded(planet : Planet)
signal pass_day_ended(planet : Planet)
const PASS_DAY_ANIMATION_TIME : float = 1.5
const MIN_PASS_DAY_ANIMATION_TIME : float = PassDay.TIME_MARGIN * 2
const TILE_SET : TileSet = preload("res://stages/terrain/planet/resources/moss_biome.tres")
const TILE_SCALE = 1
const TILE_SIZE : int = roundi(TILE_SET.tile_size.x * TILE_SCALE)
const GROUND_TILE_MAP_MATERIAL : Material = preload("res://stages/terrain/planet/resources/materials/ground_planet_tilemap.tres")
const CONTAMINATION_TILE_MAP_MATERIAL : Material = preload("res://stages/terrain/planet/resources/materials/contamination_planet_tilemap.tres")
const ORIGIN_CHUNK_HOLE_RADIUS = 5
const START_ROCK_HOLE_RADIUS = 5
const START_DECONTAMINATION_HOLE_RADIUS = 3
const CHUNK_TILE_SIZE : int = 20
const CHUNK_SIZE = CHUNK_TILE_SIZE * TILE_SIZE
const CHUNK_LOAD_DISTANCE : int = 1
const CHUNK_UNLOAD_DISTANCE : int = 2
@export_group("Loot")
@export var first_loot_number : int = 3
@export var loot_item_number : Array[int] = [1,2]
@@ -36,11 +36,15 @@ var garden : Garden = null
var tile_set = Planet.TILE_SET
var generated_chunks : Dictionary[String,Chunk] = {}
var generation_semaphore: Semaphore
func _init():
data = GameInfo.game_data.current_planet_data
func _ready():
generation_semaphore = Semaphore.new()
generation_semaphore.post()
entity_container.position = TILE_SIZE * CHUNK_TILE_SIZE * Vector2.ONE / 2
load_entities(data.entities_saved_data)
@@ -63,6 +67,10 @@ func _ready():
decontamination_layer = DecontaminationLayer.new(self)
add_child(decontamination_layer)
generate_near_chunks(player)
edit_map_origin()
func _process(_d):
if player:
generate_near_chunks(player)
@@ -116,8 +124,7 @@ func remove_far_chunks(p : Player):
func generate_chunk(coord : Vector2i):
var chunk_data := data.get_or_create_chunk_data(coord)
if coord == Vector2i(0,0):
create_hole_in_chunk(chunk_data, ORIGIN_CHUNK_HOLE_RADIUS)
var chunk_key = get_chunk_key(coord)
if not generated_chunks.has(chunk_key):
var new_chunk = Chunk.new(
@@ -129,16 +136,21 @@ func generate_chunk(coord : Vector2i):
data.generated_chunk_entities.append(coord)
new_chunk.generate()
func create_hole_in_chunk(chunk_data : ChunkData, hole_radius : int):
var hole_center = Vector2i.ONE * floori(CHUNK_TILE_SIZE/2.)
func edit_map_origin():
# Dig a hole in map origin
var chunk_center = Vector2i.ONE * floori(CHUNK_TILE_SIZE/2.)
var hole_tiles : Array[Vector2i] = []
var decontamination_tiles : Array[Vector2i] = []
for x in range(CHUNK_TILE_SIZE):
for y in range(CHUNK_TILE_SIZE):
var coord = Vector2i(x,y)
if coord.distance_to(hole_center) < hole_radius:
chunk_data.update_rock_tile_diff(
coord,
ChunkData.TileDiff.ABSENT
)
if coord.distance_to(chunk_center) < START_ROCK_HOLE_RADIUS:
hole_tiles.append(coord)
if coord.distance_to(chunk_center) < START_DECONTAMINATION_HOLE_RADIUS:
decontamination_tiles.append(coord)
rock_layer.remove_rocks(hole_tiles, true)
decontamination_layer.place_decontaminations(decontamination_tiles, true)
func remove_chunk(chunk : Chunk):
generated_chunks.erase(get_chunk_key(chunk.data.chunk_coord))
@@ -181,11 +193,13 @@ func plant(
return true
func pass_day():
%PassDay.pass_day_animation()
for e : Node2D in entity_container.get_children():
if e.has_method("_start_pass_day"):
e._start_pass_day()
pass_day_started.emit(self)
await get_tree().create_timer(PASS_DAY_ANIMATION_TIME/2.).timeout
if not %PassDay.is_animation_appeared:
await %PassDay.animation_appeared
pass_day_proceeded.emit(self)
data.day += 1
@@ -194,7 +208,8 @@ func pass_day():
e._pass_day()
pass_day_ended.emit(self)
await get_tree().create_timer(PASS_DAY_ANIMATION_TIME/2.).timeout
if not %PassDay.is_animation_disappeared:
await %PassDay.animation_disappeared
for e : Node2D in entity_container.get_children():
if e.has_method("_end_pass_day"):
e._end_pass_day()

View File

@@ -29,7 +29,6 @@ func _init(
charges = parameter.charges
objective = parameter.objective
planet_seed = parameter.planet_seed
print(planet_seed)
#region ------------------ Chunks ------------------

View File

@@ -11,7 +11,7 @@ func setup():
func place_decontamination(coord : Vector2i, save = false):
place_decontaminations([coord], save)
func place_decontaminations(coords : Array[Vector2i], save = false, on_finished : Callable = (func(): pass)):
func place_decontaminations(coords : Array[Vector2i], save := false, on_finished : Callable = (func(): pass)):
async_place_terrain_cells(
coords,
DECONTAMINATION_TILE_TERRAIN_SET,

View File

@@ -5,7 +5,6 @@ class_name PlanetLayer
var threads : Array[Thread] = []
var is_generated = false
var planet : Planet
@onready var semaphore : Semaphore = Semaphore.new()
func _init(
_planet : Planet = null
@@ -16,7 +15,6 @@ func _ready():
tile_set = planet.tile_set
scale = Vector2.ONE * Planet.TILE_SCALE
navigation_enabled = false
semaphore.post()
setup()
func setup():
@@ -43,8 +41,6 @@ func async_place_terrain_cells(
tile_terrain : int = 0,
on_finished : Callable = (func(): pass)
):
var nb = randi()
print("async place cells %d" % nb)
var thread = Thread.new()
threads.append(thread)
thread.start(
@@ -54,7 +50,6 @@ func async_place_terrain_cells(
tile_terrain_set,
tile_terrain
)
print("finish cells %d" % nb)
on_finished.call_deferred()
)
@@ -63,13 +58,13 @@ func place_terrain_cells(
tile_terrain_set : int = 0,
tile_terrain : int = 0
):
semaphore.wait()
planet.generation_semaphore.wait()
set_cells_terrain_connect(
coords,
tile_terrain_set,
tile_terrain
)
semaphore.post()
planet.generation_semaphore.post()
func _exit_tree():
for t in threads:

View File

@@ -1,4 +1,4 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://c26wmvhmhpqw7"]
[gd_resource type="StandardMaterial3D" load_steps=0 format=3 uid="uid://c26wmvhmhpqw7"]
[resource]
transparency = 1