]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Changes ParallaxGenerator to use FastNoiseLite (#36214)
authorJ <billsmith116@gmail.com>
Mon, 14 Apr 2025 04:03:49 +0000 (04:03 +0000)
committerGitHub <noreply@github.com>
Mon, 14 Apr 2025 04:03:49 +0000 (14:03 +1000)
Instead of the NoiseGenerator we use FastNoiseLite
If I'm correct, after this we'll be able to remove NoiseGenerator and FastNoise from the codebase entirely!

Content.Client/Parallax/ParallaxGenerator.cs

index 4fed1fc933ac779cf75241e7217f482ddfa4b0be..0337de30d1c60bd97e20c7fc98dd21a126679e22 100644 (file)
@@ -131,7 +131,7 @@ namespace Content.Client.Parallax
         {
             private readonly Color InnerColor = Color.White;
             private readonly Color OuterColor = Color.Black;
-            private readonly NoiseGenerator.NoiseType NoiseType = NoiseGenerator.NoiseType.Fbm;
+            private readonly FastNoiseLite.FractalType NoiseType = FastNoiseLite.FractalType.FBm;
             private readonly uint Seed = 1234;
             private readonly float Persistence = 0.5f;
             private readonly float Lacunarity = (float) (Math.PI / 3);
@@ -204,10 +204,10 @@ namespace Content.Client.Parallax
                     switch (((TomlValue<string>) tomlObject).Value)
                     {
                         case "fbm":
-                            NoiseType = NoiseGenerator.NoiseType.Fbm;
+                            NoiseType = FastNoiseLite.FractalType.FBm;
                             break;
                         case "ridged":
-                            NoiseType = NoiseGenerator.NoiseType.Ridged;
+                            NoiseType = FastNoiseLite.FractalType.Ridged;
                             break;
                         default:
                             throw new InvalidOperationException();
@@ -217,14 +217,11 @@ namespace Content.Client.Parallax
 
             public override void Apply(Image<Rgba32> bitmap)
             {
-                var noise = new NoiseGenerator(NoiseType);
-                noise.SetSeed(Seed);
+                var noise = new FastNoiseLite((int)Seed);
+                noise.SetFractalType(NoiseType);
                 noise.SetFrequency(Frequency);
-                noise.SetPersistence(Persistence);
-                noise.SetLacunarity(Lacunarity);
-                noise.SetOctaves(Octaves);
-                noise.SetPeriodX(bitmap.Width);
-                noise.SetPeriodY(bitmap.Height);
+                noise.SetFractalLacunarity(Lacunarity);
+                noise.SetFractalOctaves((int)Octaves);
                 var threshVal = 1 / (1 - Threshold);
                 var powFactor = 1 / Power;
 
@@ -268,7 +265,7 @@ namespace Content.Client.Parallax
 
             // Noise mask stuff.
             private readonly bool Masked;
-            private readonly NoiseGenerator.NoiseType MaskNoiseType = NoiseGenerator.NoiseType.Fbm;
+            private readonly FastNoiseLite.FractalType MaskNoiseType = FastNoiseLite.FractalType.FBm;
             private readonly uint MaskSeed = 1234;
             private readonly float MaskPersistence = 0.5f;
             private readonly float MaskLacunarity = (float) (Math.PI * 2 / 3);
@@ -357,10 +354,10 @@ namespace Content.Client.Parallax
                     switch (((TomlValue<string>) tomlObject).Value)
                     {
                         case "fbm":
-                            MaskNoiseType = NoiseGenerator.NoiseType.Fbm;
+                            MaskNoiseType = FastNoiseLite.FractalType.FBm;
                             break;
                         case "ridged":
-                            MaskNoiseType = NoiseGenerator.NoiseType.Ridged;
+                            MaskNoiseType = FastNoiseLite.FractalType.Ridged;
                             break;
                         default:
                             throw new InvalidOperationException();
@@ -439,14 +436,10 @@ namespace Content.Client.Parallax
             {
                 var o = PointSize - 1;
                 var random = new Random(Seed);
-                var noise = new NoiseGenerator(MaskNoiseType);
-                noise.SetSeed(MaskSeed);
-                noise.SetFrequency(MaskFrequency);
-                noise.SetPersistence(MaskPersistence);
-                noise.SetLacunarity(MaskLacunarity);
-                noise.SetOctaves(MaskOctaves);
-                noise.SetPeriodX(buffer.Width);
-                noise.SetPeriodY(buffer.Height);
+                var noise = new FastNoiseLite((int)MaskSeed);
+                noise.SetFractalType(MaskNoiseType);
+                noise.SetFractalLacunarity(MaskLacunarity);
+                noise.SetFractalOctaves((int)MaskOctaves);
 
                 var threshVal = 1 / (1 - MaskThreshold);
                 var powFactor = 1 / MaskPower;