Skip to content

Commit

Permalink
Implemented harmony patch for issue #26. The patch adds a post to the…
Browse files Browse the repository at this point in the history
… OverlapAllAsteroidSeedsInSphere method of the vanilla procedural world generator, to allow that method to also retreive plugin asteroids
  • Loading branch information
8vogt committed May 3, 2021
1 parent 9497d0c commit 38a8b60
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ public void MarkToLoadCellsInBounds(BoundingSphereD bounds)
m_toLoadCells.ApplyAdditions();
}

/// <summary>
/// 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.
/// </summary>
/// <param name="bounds">Bounds to get seeds from</param>
/// <param name="list">List to put seeds into.</param>
public void GetSeedsInBounds(BoundingSphereD bounds, List<MyObjectSeed> 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);
}
}
}

/// <summary>
/// Gets an iterator for all Vector3I within the bounding box bbox
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using VRage.Game;
using VRage.Game.Components;
using VRage.Game.Entity;
using VRageMath;

namespace SEWorldGenPlugin.Generator.ProceduralGeneration
{
Expand Down Expand Up @@ -221,10 +222,27 @@ private void TrackEntityWithRange(MyEntity entity, double range)
}
}

/// <summary>
/// Untracks entity
/// </summary>
/// <param name="entity"></param>
public void UntrackEntity(MyEntity entity)
{
m_trackedEntities.Remove(entity);
//TODO: Unload all objects loaded by this entity
}

/// <summary>
/// Gets all seeds of cell modules in bounds
/// </summary>
/// <param name="bounds">Bounds to get seeds</param>
/// <param name="list">List for the seeds to be put in</param>
public void GetCellSeedsInBounds(BoundingSphereD bounds, List<MyObjectSeed> list)
{
foreach(var module in m_cellModules)
{
module.GetSeedsInBounds(bounds, list);
}
}
}
}
18 changes: 18 additions & 0 deletions SEWorldGenPlugin/Patches/Patch_OverlapAllAsteroidSeedsInSphere.cs
Original file line number Diff line number Diff line change
@@ -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<MyObjectSeed> list)
{
MyProceduralGeneratorComponent.Static.GetCellSeedsInBounds(area, list);
}
}
}
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
1 change: 1 addition & 0 deletions SEWorldGenPlugin/SEWorldGenPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<Compile Include="ObjectBuilders\MyObjectBuilder_WorldGpsData.cs" />
<Compile Include="ObjectBuilders\MyObjectBuilder_WorldSettings.cs" />
<Compile Include="ObjectBuilders\MySerializableMinMax.cs" />
<Compile Include="Patches\Patch_OverlapAllAsteroidSeedsInSphere.cs" />
<Compile Include="Session\IMyEntityTracker.cs" />
<Compile Include="Session\MyAsteroidObjectsManager.cs" />
<Compile Include="Session\MyEntityTrackerComponent.cs" />
Expand Down
2 changes: 2 additions & 0 deletions SEWorldGenPlugin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38a8b60

Please sign in to comment.