From 38a8b6040c4fcd638c4d86f6ae3ac344db96d32e Mon Sep 17 00:00:00 2001 From: 8vogt <8vogt@informatik.uni-hamburg.de> Date: Mon, 3 May 2021 15:40:46 +0200 Subject: [PATCH] Implemented harmony patch for issue #26. The patch adds a post to the OverlapAllAsteroidSeedsInSphere method of the vanilla procedural world generator, to allow that method to also retreive plugin asteroids --- .../MyAbstractProceduralCellModule.cs | 24 +++++++++++++++++++ .../MyProceduralGeneratorComponent.cs | 18 ++++++++++++++ .../Patch_OverlapAllAsteroidSeedsInSphere.cs | 18 ++++++++++++++ SEWorldGenPlugin/Properties/AssemblyInfo.cs | 2 +- SEWorldGenPlugin/SEWorldGenPlugin.csproj | 1 + SEWorldGenPlugin/Startup.cs | 2 ++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 SEWorldGenPlugin/Patches/Patch_OverlapAllAsteroidSeedsInSphere.cs diff --git a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyAbstractProceduralCellModule.cs b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyAbstractProceduralCellModule.cs index a0bc350..792ae80 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyAbstractProceduralCellModule.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyAbstractProceduralCellModule.cs @@ -110,6 +110,30 @@ public void MarkToLoadCellsInBounds(BoundingSphereD bounds) m_toLoadCells.ApplyAdditions(); } + /// + /// Gets all seeds within said bounds. + /// If a cell inside the bounds is not loaded, it will generate the seed but wont load the cell. + /// + /// Bounds to get seeds from + /// List to put seeds into. + public void GetSeedsInBounds(BoundingSphereD bounds, List list) + { + BoundingBoxD box = BoundingBoxD.CreateFromSphere(bounds); + Vector3I cellId = Vector3I.Floor(box.Min / m_cellSize); + for (var it = GetCellsIterator(box); it.IsValid(); it.GetNext(out cellId)) + { + if (m_loadedCells.ContainsKey(cellId)) + { + m_loadedCells[cellId].GetAll(list, false); + } + else + { + MyProceduralCell cell = GenerateCellSeeds(cellId); + cell.GetAll(list); + } + } + } + /// /// Gets an iterator for all Vector3I within the bounding box bbox /// diff --git a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralGeneratorComponent.cs b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralGeneratorComponent.cs index 1e553b7..cf22129 100644 --- a/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralGeneratorComponent.cs +++ b/SEWorldGenPlugin/Generator/ProceduralGeneration/MyProceduralGeneratorComponent.cs @@ -8,6 +8,7 @@ using VRage.Game; using VRage.Game.Components; using VRage.Game.Entity; +using VRageMath; namespace SEWorldGenPlugin.Generator.ProceduralGeneration { @@ -221,10 +222,27 @@ private void TrackEntityWithRange(MyEntity entity, double range) } } + /// + /// Untracks entity + /// + /// public void UntrackEntity(MyEntity entity) { m_trackedEntities.Remove(entity); //TODO: Unload all objects loaded by this entity } + + /// + /// Gets all seeds of cell modules in bounds + /// + /// Bounds to get seeds + /// List for the seeds to be put in + public void GetCellSeedsInBounds(BoundingSphereD bounds, List list) + { + foreach(var module in m_cellModules) + { + module.GetSeedsInBounds(bounds, list); + } + } } } diff --git a/SEWorldGenPlugin/Patches/Patch_OverlapAllAsteroidSeedsInSphere.cs b/SEWorldGenPlugin/Patches/Patch_OverlapAllAsteroidSeedsInSphere.cs new file mode 100644 index 0000000..3dc599e --- /dev/null +++ b/SEWorldGenPlugin/Patches/Patch_OverlapAllAsteroidSeedsInSphere.cs @@ -0,0 +1,18 @@ +using HarmonyLib; +using Sandbox.Game.World.Generator; +using SEWorldGenPlugin.Generator.ProceduralGeneration; +using SEWorldGenPlugin.Utilities; +using System.Collections.Generic; +using VRageMath; + +namespace SEWorldGenPlugin.Patches +{ + [HarmonyPatch(typeof(MyProceduralWorldGenerator), "OverlapAllAsteroidSeedsInSphere")] + public static class Patch_OverlapAllAsteroidSeedsInSphere + { + public static void Postfix(BoundingSphereD area, List list) + { + MyProceduralGeneratorComponent.Static.GetCellSeedsInBounds(area, list); + } + } +} diff --git a/SEWorldGenPlugin/Properties/AssemblyInfo.cs b/SEWorldGenPlugin/Properties/AssemblyInfo.cs index e3d6198..b59422d 100644 --- a/SEWorldGenPlugin/Properties/AssemblyInfo.cs +++ b/SEWorldGenPlugin/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.5.3")] +[assembly: AssemblyVersion("2.0.6.0")] [assembly: AssemblyFileVersion("1.0.0")] diff --git a/SEWorldGenPlugin/SEWorldGenPlugin.csproj b/SEWorldGenPlugin/SEWorldGenPlugin.csproj index 298957f..c53923c 100644 --- a/SEWorldGenPlugin/SEWorldGenPlugin.csproj +++ b/SEWorldGenPlugin/SEWorldGenPlugin.csproj @@ -220,6 +220,7 @@ + diff --git a/SEWorldGenPlugin/Startup.cs b/SEWorldGenPlugin/Startup.cs index 1891692..56701d4 100644 --- a/SEWorldGenPlugin/Startup.cs +++ b/SEWorldGenPlugin/Startup.cs @@ -79,7 +79,9 @@ private void TryEnablePatches() { try { + MyPluginLog.Log("Patching..."); Patch(); + MyPluginLog.Log("Patches applied"); }catch(FileNotFoundException) { MyPluginLog.Log("0harmony.dll not found, skipping patching.", LogLevel.WARNING);