From d89c10ba6846ea36560848cb37bd4a403293df03 Mon Sep 17 00:00:00 2001 From: Thorwin Vogt Date: Thu, 19 Sep 2019 16:46:57 +0200 Subject: [PATCH] Changed asteroid handling --- .../Asteroids/IMyCompositionInfoProvider.cs | 5 - .../Asteroids/MyCompositeShapeProvider.cs | 3 +- .../Generator/Asteroids/MyCompositeShapes.cs | 98 ++++++++++--------- .../ProceduralGen/EntityExtension.cs | 5 +- .../ProceduralAsteroidsRingModule.cs | 86 ++++++++++++++-- .../ProceduralGen/ProceduralGenerator.cs | 2 + .../ProceduralGen/ProceduralModule.cs | 1 + SEWorldGenPlugin/Generator/SystemGenerator.cs | 4 +- SEWorldGenPlugin/Startup.cs | 1 + 9 files changed, 138 insertions(+), 67 deletions(-) diff --git a/SEWorldGenPlugin/Generator/Asteroids/IMyCompositionInfoProvider.cs b/SEWorldGenPlugin/Generator/Asteroids/IMyCompositionInfoProvider.cs index 5e34cbb..96f4d58 100644 --- a/SEWorldGenPlugin/Generator/Asteroids/IMyCompositionInfoProvider.cs +++ b/SEWorldGenPlugin/Generator/Asteroids/IMyCompositionInfoProvider.cs @@ -1,9 +1,4 @@ using Sandbox.Game.World.Generator; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using VRage.Game; /* diff --git a/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapeProvider.cs b/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapeProvider.cs index 0d561c2..b58d451 100644 --- a/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapeProvider.cs +++ b/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapeProvider.cs @@ -8,7 +8,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; using VRage.Game; using VRage.Noise; using VRage.Utils; @@ -21,7 +20,7 @@ */ namespace SEWorldGenPlugin.Generator.Asteroids { - [MyStorageDataProvider(10004)] + [MyStorageDataProvider(10003)] internal sealed class MyCompositeShapeProvider : IMyStorageDataProvider { public class MyCombinedCompositeInfoProvider : MyProceduralCompositeInfoProvider, IMyCompositionInfoProvider diff --git a/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapes.cs b/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapes.cs index d7831bd..29ea216 100644 --- a/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapes.cs +++ b/SEWorldGenPlugin/Generator/Asteroids/MyCompositeShapes.cs @@ -1,5 +1,6 @@ using Sandbox.Definitions; using Sandbox.Engine.Voxels; +using Sandbox.Game.World; using Sandbox.Game.World.Generator; using System; using System.Collections.Generic; @@ -48,29 +49,27 @@ static MyCompositeShapes() 3, 4 }; - AsteroidGenerators = (from x in source - select MyTuple.Create(x, arg2: false)).Concat(from x in source2 - select MyTuple.Create(x, arg2: true)).Select((Func, MyCompositeShapeGeneratorDelegate>)delegate (MyTuple info) - { - int version = info.Item1; - bool combined = info.Item2; - return delegate (int generatorSeed, int seed, float size) - { - if (size == 0f) - { - size = MyUtils.GetRandomFloat(128f, 512f); - } - MyCompositeShapes myCompositeShapes = new MyCompositeShapes(generatorSeed, seed, version); - using (MyRandom.Instance.PushSeed(seed)) - { - if (combined) - { - return myCompositeShapes.CombinedGenerator(version, seed, size); - } - return myCompositeShapes.ProceduralGenerator(version, seed, size); - } - }; - }).ToArray(); + AsteroidGenerators = (from x in source select MyTuple.Create(x, arg2: false)).Concat(from x in source2 select MyTuple.Create(x, arg2: true)).Select((Func, MyCompositeShapeGeneratorDelegate>)delegate (MyTuple info) + { + int version = info.Item1; + bool combined = info.Item2; + return delegate (int generatorSeed, int seed, float size) + { + if (size == 0f) + { + size = MyUtils.GetRandomFloat(128f, 512f); + } + MyCompositeShapes myCompositeShapes = new MyCompositeShapes(generatorSeed, seed, version); + using (MyRandom.Instance.PushSeed(seed)) + { + if (combined) + { + return myCompositeShapes.CombinedGenerator(version, seed, size); + } + return myCompositeShapes.ProceduralGenerator(version, seed, size); + } + }; + }).ToArray(); } private MyCompositeShapes(int generatorSeed, int asteroidSeed, int version) @@ -120,7 +119,7 @@ private IMyCompositionInfoProvider CombinedGenerator(int version, int seed, floa data.Deposits = Array.Empty(); data.FilledShapes = new MyCsgShapeBase[num]; IMyCompositeShape[] array = new IMyCompositeShape[6]; - FillSpan(instance, size, array.Span(0, 1), MyDefinitionManager.Static.GetVoxelMapStorageDefinitionsForProceduralPrimaryAdditions(), prefferOnlyBestFittingSize: true); + FillSpan(instance, size, new Span(array, 0, 1), MyDefinitionManager.Static.GetVoxelMapStorageDefinitionsForProceduralPrimaryAdditions(), prefferOnlyBestFittingSize: true); size = ((MyOctreeStorage)array[0]).Size.AbsMax(); float idealSize = size / 2f; float idealSize2 = size / 2f; @@ -136,7 +135,7 @@ private IMyCompositionInfoProvider CombinedGenerator(int version, int seed, floa FillSpan(instance, idealSize2, array, MyDefinitionManager.Static.GetVoxelMapStorageDefinitionsForProceduralAdditions()); FillSpan(instance, idealSize, array2, MyDefinitionManager.Static.GetVoxelMapStorageDefinitionsForProceduralRemovals()); TranslateShapes(array2, size, instance); - TranslateShapes(array.Span(1), size, instance); + TranslateShapes(new Span(array, 1, array.Length - 1), size, instance); if (size > 512f) { size /= 2f; @@ -415,14 +414,14 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh } Action> action = delegate (List list) { - int num9 = list.Count; - while (num9 > 1) + int num10 = list.Count; + while (num10 > 1) { - int index = random.Next() % num9; - num9--; + int index = random.Next() % num10; + num10--; MyVoxelMaterialDefinition value = list[index]; - list[index] = list[num9]; - list[num9] = value; + list[index] = list[num10]; + list[num10] = value; } }; action(m_depositMaterials); @@ -444,7 +443,9 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh int val; if (flag) { - val = ((size <= 64f) ? 2 : ((size <= 128f) ? 4 : ((size <= 256f) ? 6 : ((!(size <= 512f)) ? 10 : 8)))); + int num = 0; + num = ((size <= 64f) ? 1 : ((size <= 128f) ? 2 : ((size <= 256f) ? 3 : ((!(size <= 512f)) ? 5 : 4)))); + val = (int)(MySession.Static.Settings.DepositsCountCoefficient * (float)num); if (m_depositMaterials.Count == 0) { val = 0; @@ -456,9 +457,10 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh } val = Math.Max(val, filledShapes.Length); deposits = new MyCompositeShapeOreDeposit[val]; - float num = (!flag) ? (size / 10f) : (size / 30f + 8f); + float depositSizeDenominator = MySession.Static.Settings.DepositSizeDenominator; + float num2 = (!flag || !(depositSizeDenominator > 0f)) ? (size / 10f) : (size / depositSizeDenominator + 8f); MyVoxelMaterialDefinition material = defaultMaterial; - int num2 = 0; + int num3 = 0; for (int i = 0; i < filledShapes.Length; i++) { if (i == 0) @@ -474,7 +476,7 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh } else { - material = m_depositMaterials[num2++]; + material = m_depositMaterials[num3++]; } } else @@ -491,30 +493,30 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh } else { - material = m_depositMaterials[num2++]; + material = m_depositMaterials[num3++]; } deposits[i] = new MyCompositeShapeOreDeposit(filledShapes[i].DeepCopy(), material); deposits[i].Shape.ShrinkTo(random.NextFloat() * (flag ? 0.6f : 0.15f) + (flag ? 0.1f : 0.6f)); - if (num2 == m_depositMaterials.Count) + if (num3 == m_depositMaterials.Count) { - num2 = 0; + num3 = 0; action(m_depositMaterials); } } for (int j = filledShapes.Length; j < val; j++) { - float num5 = 0f; + float num6 = 0f; Vector3 vector = Vector3.Zero; for (int k = 0; k < 10; k++) { vector = CreateRandomPointInBox(random, size * (flag ? 0.6f : 0.7f)) + storageOffset + size * 0.15f; - num5 = random.NextFloat() * num + (flag ? 5f : 8f); + num6 = random.NextFloat() * num2 + (flag ? 5f : 8f); if (shapeInfo == null) { break; } - double num6 = Math.Sqrt(num5 * num5 / 2f) * 0.5; - Vector3I b = new Vector3I((int)num6); + double num7 = Math.Sqrt(num6 * num6 / 2f) * 0.5; + Vector3I b = new Vector3I((int)num7); BoundingBoxI box = new BoundingBoxI((Vector3I)vector - b, (Vector3I)vector + b); if (MyCompositeShapeProvider.Intersect(shapeInfo, box, 0) != 0) { @@ -523,20 +525,20 @@ private void GenerateMaterials(int version, float size, MyRandom random, MyCsgSh } random.NextFloat(); random.NextFloat(); - MyCsgShapeBase shape = new MyCsgSphere(vector, num5); - material = ((m_depositMaterials.Count != 0) ? m_depositMaterials[num2++] : m_surfaceMaterials[num2++]); + MyCsgShapeBase shape = new MyCsgSphere(vector, num6); + material = ((m_depositMaterials.Count != 0) ? m_depositMaterials[num3++] : m_surfaceMaterials[num3++]); deposits[j] = new MyCompositeShapeOreDeposit(shape, material); if (m_depositMaterials.Count == 0) { - if (num2 == m_surfaceMaterials.Count) + if (num3 == m_surfaceMaterials.Count) { - num2 = 0; + num3 = 0; action(m_surfaceMaterials); } } - else if (num2 == m_depositMaterials.Count) + else if (num3 == m_depositMaterials.Count) { - num2 = 0; + num3 = 0; action(m_depositMaterials); } } diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/EntityExtension.cs b/SEWorldGenPlugin/Generator/ProceduralGen/EntityExtension.cs index 50a1252..2bef390 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/EntityExtension.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/EntityExtension.cs @@ -1,4 +1,5 @@ -using VRage.Game.Entity; +using Sandbox.Game.Entities; +using VRage.Game.Entity; using VRage.Utils; namespace SEWorldGenPlugin.Generator.ProceduralGen @@ -8,10 +9,10 @@ public static class EntityExtension public static void ProceduralGeneratorTracking(this MyEntity thisEntity) { + if (thisEntity is MyVoxelBase) return; if(ProceduralGenerator.Static != null) { ProceduralGenerator.Static.TrackEntity(thisEntity); - MyLog.Default.WriteLine("Tracking Entity" + thisEntity.DisplayName); } } diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs index 08bdfbf..1d27651 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralAsteroidsRingModule.cs @@ -1,4 +1,8 @@ -using Sandbox.Engine.Voxels; +using Sandbox; +using Sandbox.Definitions; +using Sandbox.Engine.Multiplayer; +using Sandbox.Engine.Voxels; +using Sandbox.Game; using Sandbox.Game.Entities; using Sandbox.Game.Multiplayer; using Sandbox.Game.World; @@ -27,8 +31,22 @@ public class ProceduralAsteroidsRingModule : ProceduralModule private const int SUBCELL_SIZE = OBJECT_SIZE_MAX * 3; private const int SUBCELLS = 6; + private HashSet m_NotSavedMaps; + private bool m_saving; + private MyAsteroidGeneratorDefinition m_data; + public ProceduralAsteroidsRingModule(int seed) : base(seed, SUBCELLS * SUBCELL_SIZE) { + m_NotSavedMaps = new HashSet(); + MySession.Static.OnSavingCheckpoint += delegate + { + foreach(var map in m_NotSavedMaps) + { + map.Save = false; + } + m_saving = true; + }; + m_data = GetData(); } public override ProceduralCell GenerateCell(ref Vector3I id) @@ -61,7 +79,7 @@ public override ProceduralCell GenerateCell(ref Vector3I id) minSize = ((MySystemBeltItem)obj).RoidSize; if (obj.Type == SystemObjectType.RING) - minSize = ((MyPlanetRingItem)obj).RoidSize; + minSize = ((MyPlanetRingItem)obj).RoidSize; var cellObject = new CellObject(cell, position, MyRandom.Instance.Next(Math.Min(OBJECT_SIZE_MAX, minSize), OBJECT_SIZE_MAX)); cellObject.Params.Type = MyObjectSeedType.Asteroid; @@ -108,23 +126,28 @@ public override void GenerateObjects(List objects, HashSet voxelGeneratorVersion && (myAsteroidGeneratorDefinition.Version < voxelGeneratorVersion || value2.Version < myAsteroidGeneratorDefinition.Version))) + { + myAsteroidGeneratorDefinition = value2; + } + } + return myAsteroidGeneratorDefinition; + } + } + return myAsteroidGeneratorDefinition; + } + } } diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs index 0176eb9..32bc9d7 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralGenerator.cs @@ -89,6 +89,8 @@ public override void UpdateBeforeSimulation() if (asteroidModule == null) return; asteroidModule.UnloadCells(); + + asteroidModule.UpdateObjects(); } protected override void UnloadData() diff --git a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralModule.cs b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralModule.cs index 3a82d55..38d404c 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGen/ProceduralModule.cs @@ -55,6 +55,7 @@ public void GetObjectsInSphere(BoundingSphereD sphere, List outObjec } public abstract void GenerateObjects(List objects, HashSet existingObjectSeeds); + public abstract void UpdateObjects(); protected void GenerateObjectsData(ref BoundingSphereD sphere) { diff --git a/SEWorldGenPlugin/Generator/SystemGenerator.cs b/SEWorldGenPlugin/Generator/SystemGenerator.cs index dcd9c92..dc2aa90 100644 --- a/SEWorldGenPlugin/Generator/SystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/SystemGenerator.cs @@ -20,7 +20,7 @@ namespace SEWorldGenPlugin.Generator [MySessionComponentDescriptor(MyUpdateOrder.NoUpdate, 600)] public class SystemGenerator : MySessionComponentBase { - private string[] greek_letters = new string[10] {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa"}; + private string[] greek_letters = new string[] {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "My", "Ny", "Xi", "Omikron", "Pi", "Rho", "Sigma", "Tau", "Ypsilon", "Phi", "Chi", "Psi", "Omega"}; private const string STORAGE_FILE = "SystemData.xml"; @@ -122,7 +122,7 @@ private void GenerateBelt(long distance, ref int beltIndex) { MySystemBeltItem belt = new MySystemBeltItem(); - belt.DisplayName = "Belt " + greek_letters[beltIndex++]; + belt.DisplayName = "Belt " + greek_letters[beltIndex++ % greek_letters.Length]; belt.Type = SystemObjectType.BELT; belt.Height = MyRandom.Instance.Next(settings.BeltSettings.MinBeltHeight, settings.BeltSettings.MaxBeltHeight); belt.Radius = distance; diff --git a/SEWorldGenPlugin/Startup.cs b/SEWorldGenPlugin/Startup.cs index fc4e61d..a8a15ac 100644 --- a/SEWorldGenPlugin/Startup.cs +++ b/SEWorldGenPlugin/Startup.cs @@ -6,6 +6,7 @@ using SEWorldGenPlugin.Generator.ProceduralGen; using SEWorldGenPlugin.GUI; using VRage.Game.Entity; +using VRage.Network; using VRage.Plugins; namespace SEWorldGenPlugin