From c690f0f152b1914bcf77640c507445abdcf7e29d Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 11 Jun 2023 12:47:36 +0200 Subject: [PATCH] Explicit function when starting and ending map generation as it happens over multiple frames. --- scenes/TileWorld.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scenes/TileWorld.cs b/scenes/TileWorld.cs index c982483..46d67db 100644 --- a/scenes/TileWorld.cs +++ b/scenes/TileWorld.cs @@ -69,6 +69,8 @@ public class TileWorld : Spatial GenerateNoiseMap(); // GenerateDebugMap(); + + OnHeightMapChanged(); } private void GenerateDebugMap() @@ -92,11 +94,9 @@ public class TileWorld : Spatial } Colormap.SetPixel(Size - 1, Size -1, new Color(1, 1, 1, 1)); - Colormap.Unlock(); - _currentGenerationState = GenerationState.Done;; - EmitSignal("WorldGenerated"); + OnMapGenerationComplete(); } @@ -118,10 +118,21 @@ public class TileWorld : Spatial heightmapTexture.Flags = 0; _heightmapOffscreenTextureRect.Texture = heightmapTexture; Heightmap.CopyFrom(_heightmapOffscreenViewport.GetTexture().GetData()); + + OnHeightMapChanged(); + } + + private void OnHeightMapChanged() + { _currentGenerationState = GenerationState.Heightmap; } + private void OnMapGenerationComplete() + { + _currentGenerationState = GenerationState.Done; + EmitSignal("WorldGenerated"); + } public override void _Process(float delta) { @@ -141,8 +152,8 @@ public class TileWorld : Spatial Heightmap.Lock(); _currentGenerationState = GenerationState.Done; - - EmitSignal("WorldGenerated"); + + OnMapGenerationComplete(); } }