From 975534f0d4aff43d0693659ac64427ca4c13fb8a Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Tue, 17 Dec 2024 18:54:24 +0100 Subject: [PATCH 1/4] refactor: remove unused UI --- .../Services/MapGeneratorService.cs | 4 +-- .../MapGenerator/UI/NoiseParametersView.razor | 25 ------------------- .../UI/NoiseParametersView.razor.css | 3 --- .../MapGenerator/UI/TileInfoView.razor | 7 ------ .../MapGenerator/UI/TileInfoView.razor.css | 3 --- .../NoiseGenerator/Models/NoiseParameters.cs | 3 --- 6 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 Server/Modules/MapGenerator/UI/NoiseParametersView.razor delete mode 100644 Server/Modules/MapGenerator/UI/NoiseParametersView.razor.css delete mode 100644 Server/Modules/MapGenerator/UI/TileInfoView.razor delete mode 100644 Server/Modules/MapGenerator/UI/TileInfoView.razor.css diff --git a/Server/Modules/MapGenerator/Services/MapGeneratorService.cs b/Server/Modules/MapGenerator/Services/MapGeneratorService.cs index 27cb84c..e35b725 100644 --- a/Server/Modules/MapGenerator/Services/MapGeneratorService.cs +++ b/Server/Modules/MapGenerator/Services/MapGeneratorService.cs @@ -26,12 +26,10 @@ public async Task GetMap(MapParameters mapParameters) private MapData GenerateMap(MapParameters mapParameters) { var noiseParameters = mapParameters.NoiseParameters; - noiseParameters.Seed = noiseParameters.UseRandomSeed - ? _rnd.Next(-100000, 100000) - : noiseParameters.Seed; int width = 64; int height = 64; bool useFalloff = true; + int _seed = noiseParameters.Seed; var grid = new Node[width, height]; diff --git a/Server/Modules/MapGenerator/UI/NoiseParametersView.razor b/Server/Modules/MapGenerator/UI/NoiseParametersView.razor deleted file mode 100644 index 0ba9f1c..0000000 --- a/Server/Modules/MapGenerator/UI/NoiseParametersView.razor +++ /dev/null @@ -1,25 +0,0 @@ -@using Fracture.Server.Modules.NoiseGenerator.Models -
-
- - - @if (!NoiseParameters.UseRandomSeed) - { -
- - - } -
-
- -@code { - [Parameter] - public NoiseParameters NoiseParameters { get; set; } - [Parameter] - public EventCallback NoiseParametersChanged { get; set; } - - private Task OnNoiseParametersChanged(ChangeEventArgs e) - { - return NoiseParametersChanged.InvokeAsync(NoiseParameters); - } -} diff --git a/Server/Modules/MapGenerator/UI/NoiseParametersView.razor.css b/Server/Modules/MapGenerator/UI/NoiseParametersView.razor.css deleted file mode 100644 index acf6ec1..0000000 --- a/Server/Modules/MapGenerator/UI/NoiseParametersView.razor.css +++ /dev/null @@ -1,3 +0,0 @@ -#content { - background-color: #F4F6F6; -} diff --git a/Server/Modules/MapGenerator/UI/TileInfoView.razor b/Server/Modules/MapGenerator/UI/TileInfoView.razor deleted file mode 100644 index c551503..0000000 --- a/Server/Modules/MapGenerator/UI/TileInfoView.razor +++ /dev/null @@ -1,7 +0,0 @@ -
- Tile information... -
- -@code { - -} diff --git a/Server/Modules/MapGenerator/UI/TileInfoView.razor.css b/Server/Modules/MapGenerator/UI/TileInfoView.razor.css deleted file mode 100644 index acf6ec1..0000000 --- a/Server/Modules/MapGenerator/UI/TileInfoView.razor.css +++ /dev/null @@ -1,3 +0,0 @@ -#content { - background-color: #F4F6F6; -} diff --git a/Server/Modules/NoiseGenerator/Models/NoiseParameters.cs b/Server/Modules/NoiseGenerator/Models/NoiseParameters.cs index 0263cdf..56261dd 100644 --- a/Server/Modules/NoiseGenerator/Models/NoiseParameters.cs +++ b/Server/Modules/NoiseGenerator/Models/NoiseParameters.cs @@ -13,7 +13,4 @@ public class NoiseParameters public float Boost { get; set; } public float Falloff { get; set; } public bool FalloffType { get; set; } - - public bool UseRandomSeed { get; set; } = true; - public bool GenerateNew { get; set; } = true; } From 804dc9c0d89fc946629aff360c35138b6f839576 Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Tue, 17 Dec 2024 18:57:07 +0100 Subject: [PATCH 2/4] refactor: remove nullable seed --- .../NoiseGenerator/Services/CustomPerlin.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Server/Modules/NoiseGenerator/Services/CustomPerlin.cs b/Server/Modules/NoiseGenerator/Services/CustomPerlin.cs index 39848c7..0b4a6e7 100644 --- a/Server/Modules/NoiseGenerator/Services/CustomPerlin.cs +++ b/Server/Modules/NoiseGenerator/Services/CustomPerlin.cs @@ -92,16 +92,13 @@ public static float PerlinOctaves( public static float[,] GenerateNoiseMap( int size, - int? seed = null, + int seed, int octaves = 1, float persistence = 0.5f, float lacunarity = 2.0f, float scale = 1.0f ) { // Noise map generation - // can be called with a seed or without it - int actualSeed = seed ?? new Random().Next(); - float[,] map = new float[size, size]; for (int y = 0; y < size; y++) @@ -110,14 +107,7 @@ public static float PerlinOctaves( { float scaledX = x / (float)Math.PI / scale; float scaledY = y / (float)Math.PI / scale; - map[x, y] = PerlinOctaves( - scaledX, - scaledY, - actualSeed, - octaves, - persistence, - lacunarity - ); + map[x, y] = PerlinOctaves(scaledX, scaledY, seed, octaves, persistence, lacunarity); } } return map; From 9b28bab9e2ca6fe780c4ff505b860c5e1dedf0de Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Tue, 17 Dec 2024 19:09:13 +0100 Subject: [PATCH 3/4] refactor: single noise parameters --- Server/Components/Pages/GamePage.razor | 1 - Server/Program.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/Components/Pages/GamePage.razor b/Server/Components/Pages/GamePage.razor index 97efa57..6f97853 100644 --- a/Server/Components/Pages/GamePage.razor +++ b/Server/Components/Pages/GamePage.razor @@ -148,7 +148,6 @@ private MapDisplayData _mapDisplayData = new(); private MapData? _map; private List? _path { get; set; } - private NoiseParameters _noiseParameters = new(); protected override async Task OnInitializedAsync() { diff --git a/Server/Program.cs b/Server/Program.cs index cb88b59..d1f8023 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -5,6 +5,7 @@ using Fracture.Server.Modules.Items.Models; using Fracture.Server.Modules.Items.Services; using Fracture.Server.Modules.MapGenerator.Services; +using Fracture.Server.Modules.NoiseGenerator.Models; using Fracture.Server.Modules.Shared; using Fracture.Server.Modules.Shared.Configuration; using Fracture.Server.Modules.Shared.NameGenerators; From acc9b2d5c1851ede65e969f1c58e9463f876783d Mon Sep 17 00:00:00 2001 From: Marcin Badurowicz Date: Tue, 17 Dec 2024 19:14:26 +0100 Subject: [PATCH 4/4] refactor: use single seed in item generator --- Server/Modules/Items/Services/ItemGenerator.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/Modules/Items/Services/ItemGenerator.cs b/Server/Modules/Items/Services/ItemGenerator.cs index dd500ba..4fe4c8e 100644 --- a/Server/Modules/Items/Services/ItemGenerator.cs +++ b/Server/Modules/Items/Services/ItemGenerator.cs @@ -1,6 +1,7 @@ using System.Text.Json; using Fracture.Server.Modules.AI.Services; using Fracture.Server.Modules.Items.Models; +using Fracture.Server.Modules.NoiseGenerator.Models; using Fracture.Server.Modules.Shared; using Fracture.Server.Modules.Shared.Configuration; using Microsoft.FeatureManagement; @@ -19,6 +20,7 @@ public class ItemGenerator : IItemGenerator public ItemGenerator( INameGenerator nameGenerator, PrefixesGenerator prefixes, + NoiseParameters noiseParameters, IAIInstructionProvider? ai = null ) { @@ -26,7 +28,7 @@ public ItemGenerator( _prefixes = prefixes; _ai = ai; - _rnd = new Random(); + _rnd = new Random(noiseParameters.Seed); var configData = File.ReadAllText("itemgeneratorconfig.json"); _modifiers = JsonSerializer.Deserialize>(configData)!;