mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Started on a better load order
This commit is contained in:
parent
f1da2e3be8
commit
dae09dc8e5
@ -20,7 +20,6 @@ namespace NewHorizons.Handlers
|
|||||||
public static class PlanetCreationHandler
|
public static class PlanetCreationHandler
|
||||||
{
|
{
|
||||||
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
|
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
|
||||||
private static List<NewHorizonsBody> ToLoad;
|
|
||||||
private static Dictionary<AstroObject, NewHorizonsBody> ExistingAOConfigs;
|
private static Dictionary<AstroObject, NewHorizonsBody> ExistingAOConfigs;
|
||||||
|
|
||||||
public static void Init(List<NewHorizonsBody> bodies)
|
public static void Init(List<NewHorizonsBody> bodies)
|
||||||
@ -57,49 +56,30 @@ namespace NewHorizons.Handlers
|
|||||||
|
|
||||||
starLightGO.SetActive(true);
|
starLightGO.SetActive(true);
|
||||||
|
|
||||||
// Order by stars then planets then moons (not necessary but probably speeds things up, maybe) ALSO only include current star system
|
var planetGraph = new PlanetGraphHandler(bodies.OrderBy(b => b.Config?.BuildPriority ?? 0));
|
||||||
ToLoad = bodies
|
|
||||||
.OrderBy(b =>
|
|
||||||
(b.Config.BuildPriority != -1 ? b.Config.BuildPriority :
|
|
||||||
(b.Config.FocalPoint != null ? 0 :
|
|
||||||
(b.Config.Star != null) ? 0 :
|
|
||||||
(b.Config.Orbit.IsMoon ? 2 : 1)
|
|
||||||
))).ToList();
|
|
||||||
|
|
||||||
var passCount = 0;
|
foreach (var node in planetGraph)
|
||||||
while (ToLoad.Count != 0)
|
|
||||||
{
|
{
|
||||||
Logger.Log($"Starting body loading pass #{++passCount}");
|
LoadBody(node.body);
|
||||||
var flagNoneLoadedThisPass = true;
|
if (node is PlanetGraphHandler.FocalPointNode focal)
|
||||||
foreach (var body in ToLoad)
|
|
||||||
{
|
{
|
||||||
if (LoadBody(body)) flagNoneLoadedThisPass = false;
|
LoadBody(focal.primary.body);
|
||||||
}
|
LoadBody(focal.secondary.body);
|
||||||
if (flagNoneLoadedThisPass)
|
|
||||||
{
|
|
||||||
Logger.LogWarning("No objects were loaded this pass");
|
|
||||||
// Try again but default to sun
|
|
||||||
foreach (var body in ToLoad)
|
|
||||||
{
|
|
||||||
if (LoadBody(body, true)) flagNoneLoadedThisPass = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flagNoneLoadedThisPass)
|
|
||||||
{
|
|
||||||
// Give up
|
|
||||||
Logger.Log($"Couldn't finish adding bodies.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ToLoad = NextPassBodies;
|
var nextPassLoad = NextPassBodies.Select(x => x).ToList();
|
||||||
|
|
||||||
|
Logger.Log("Loading Deferred Bodies");
|
||||||
|
|
||||||
|
while (NextPassBodies.Count != 0)
|
||||||
|
{
|
||||||
|
foreach (var body in nextPassLoad)
|
||||||
|
{
|
||||||
|
LoadBody(body, true);
|
||||||
|
}
|
||||||
|
nextPassLoad = NextPassBodies;
|
||||||
NextPassBodies = new List<NewHorizonsBody>();
|
NextPassBodies = new List<NewHorizonsBody>();
|
||||||
|
|
||||||
// Infinite loop failsafe
|
|
||||||
if (passCount > 10)
|
|
||||||
{
|
|
||||||
Logger.Log("Something went wrong");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log("Done loading bodies");
|
Logger.Log("Done loading bodies");
|
||||||
|
|||||||
126
NewHorizons/Handlers/PlanetGraphHandler.cs
Normal file
126
NewHorizons/Handlers/PlanetGraphHandler.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using NewHorizons.External.Configs;
|
||||||
|
using NewHorizons.Utility;
|
||||||
|
|
||||||
|
namespace NewHorizons.Handlers
|
||||||
|
{
|
||||||
|
public class PlanetGraphHandler : IEnumerable<PlanetGraphHandler.PlanetNode>
|
||||||
|
{
|
||||||
|
public class PlanetNode
|
||||||
|
{
|
||||||
|
public NewHorizonsBody body;
|
||||||
|
public IEnumerable<PlanetNode> children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FocalPointNode : PlanetNode
|
||||||
|
{
|
||||||
|
public PlanetNode primary;
|
||||||
|
public PlanetNode secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlanetNode _rootNode;
|
||||||
|
|
||||||
|
public PlanetGraphHandler(IEnumerable<NewHorizonsBody> iBodies)
|
||||||
|
{
|
||||||
|
var bodies = iBodies.ToArray();
|
||||||
|
var centers = bodies.Where(b => b.Config.Base.CenterOfSolarSystem).ToArray();
|
||||||
|
if (centers.Length == 1)
|
||||||
|
{
|
||||||
|
_rootNode = ConstructGraph(centers[0], bodies);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (centers.Length == 0 && Main.Instance.CurrentStarSystem == "SolarSystem")
|
||||||
|
{
|
||||||
|
var SunConfig = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{"name", "Sun"}
|
||||||
|
};
|
||||||
|
_rootNode = ConstructGraph(new NewHorizonsBody(new PlanetConfig(SunConfig), Main.Instance), bodies);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.LogError("There must be one and only one centerOfSolarSystem!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool DetermineIfChildOfFocal(NewHorizonsBody body, FocalPointNode node)
|
||||||
|
{
|
||||||
|
var name = body.Config.Name.ToLower();
|
||||||
|
var primary = (body.Config.Orbit?.PrimaryBody ?? "").ToLower();
|
||||||
|
var primaryName = node.primary.body.Config.Name.ToLower();
|
||||||
|
var secondaryName = node.secondary.body.Config.Name.ToLower();
|
||||||
|
return name != primaryName && name != secondaryName && (primary == node.body.Config.Name.ToLower() || primary == primaryName || primary == secondaryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static PlanetNode ConstructGraph(NewHorizonsBody body, NewHorizonsBody[] bodies)
|
||||||
|
{
|
||||||
|
if (body.Config.FocalPoint == null)
|
||||||
|
{
|
||||||
|
return new PlanetNode
|
||||||
|
{
|
||||||
|
body = body,
|
||||||
|
children = bodies
|
||||||
|
.Where(b => string.Equals(b.Config.Orbit.PrimaryBody, body.Config.Name, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
.Select(b => ConstructGraph(b, bodies))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var newNode = new FocalPointNode
|
||||||
|
{
|
||||||
|
body = body
|
||||||
|
};
|
||||||
|
foreach (var child in bodies)
|
||||||
|
{
|
||||||
|
if (string.Equals(child.Config.Name, body.Config.FocalPoint.Primary, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
newNode.primary = new PlanetNode
|
||||||
|
{
|
||||||
|
body = child,
|
||||||
|
children = new List<PlanetNode>()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (string.Equals(child.Config.Name, body.Config.FocalPoint.Secondary, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
newNode.secondary = new PlanetNode
|
||||||
|
{
|
||||||
|
body = child,
|
||||||
|
children = new List<PlanetNode>()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newNode.children = bodies
|
||||||
|
.Where(b => DetermineIfChildOfFocal(b, newNode))
|
||||||
|
.Select(b => ConstructGraph(b, bodies));
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<PlanetNode> GetEnumerator()
|
||||||
|
{
|
||||||
|
yield return _rootNode;
|
||||||
|
var queue = new Queue<PlanetNode>(_rootNode.children);
|
||||||
|
while (queue.Count != 0)
|
||||||
|
{
|
||||||
|
var node = queue.Dequeue();
|
||||||
|
yield return node;
|
||||||
|
foreach (var child in node.children)
|
||||||
|
{
|
||||||
|
queue.Enqueue(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -91,7 +91,7 @@ namespace NewHorizons.Patches
|
|||||||
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")]
|
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")]
|
||||||
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
|
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
|
||||||
{
|
{
|
||||||
if (!__instance._alignmentFluid is NHFluidVolume) return true;
|
// if (!__instance._alignmentFluid is NHFluidVolume) return true;
|
||||||
|
|
||||||
// Mostly copy pasting from the AlignWithDirection class
|
// Mostly copy pasting from the AlignWithDirection class
|
||||||
AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
|
AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user