Broke signal propagation before, fixed it

This commit is contained in:
Nick 2022-07-21 22:25:46 -04:00
parent e9bc02b54d
commit 007ff3fa1b
3 changed files with 16 additions and 23 deletions

View File

@ -1,5 +1,6 @@
using NewHorizons.Builder.Body; using NewHorizons.Builder.Body;
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.External.Configs;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
@ -30,14 +31,14 @@ namespace NewHorizons.Builder.Props
private static string _brambleSeedPrefabPath = "DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)"; private static string _brambleSeedPrefabPath = "DB_PioneerDimension_Body/Sector_PioneerDimension/Interactables_PioneerDimension/SeedWarp_ToPioneer (1)";
private static string _brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster"; private static string _brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster";
public static void Init() public static void Init(PlanetConfig[] dimensionConfigs)
{ {
_unpairedNodes.Clear(); _unpairedNodes.Clear();
_propagatedSignals.Clear(); _propagatedSignals.Clear();
namedNodes.Clear(); namedNodes.Clear();
builtBrambleNodes.Clear(); builtBrambleNodes.Clear();
PropagateSignals(); PropagateSignals(dimensionConfigs);
} }
public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null) public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null)
@ -75,23 +76,21 @@ namespace NewHorizons.Builder.Props
// Makes signals inside dimensions appear on the nodes as well // Makes signals inside dimensions appear on the nodes as well
// Runs Floyd-Warshall algorithm on dimensions and nodes. // Runs Floyd-Warshall algorithm on dimensions and nodes.
private static void PropagateSignals() private static void PropagateSignals(PlanetConfig[] dimensionConfigs)
{ {
var allDimensions = PlanetCreationHandler.Bodies.Where(body => body?.Config?.Bramble?.dimension != null).Select(body => body.Config).ToList();
// Access will be our final answer - if access[i, j], then nodes linking to dimension i should display all of dimension j's signals // Access will be our final answer - if access[i, j], then nodes linking to dimension i should display all of dimension j's signals
var access = new bool[allDimensions.Count(), allDimensions.Count()]; var access = new bool[dimensionConfigs.Count(), dimensionConfigs.Count()];
var dimensionNameToIndex = new Dictionary<string, int>(); var dimensionNameToIndex = new Dictionary<string, int>();
for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++)
{ {
dimensionNameToIndex[allDimensions[dimensionIndex].name] = dimensionIndex; dimensionNameToIndex[dimensionConfigs[dimensionIndex].name] = dimensionIndex;
} }
// Set up the direct links (ie, if dimension 0 contains a node that links to dimension 3, set access[0, 3] = true) // Set up the direct links (ie, if dimension 0 contains a node that links to dimension 3, set access[0, 3] = true)
for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++)
{ {
var dimension = allDimensions[dimensionIndex]; var dimension = dimensionConfigs[dimensionIndex];
if (dimension.Bramble.nodes == null) continue; if (dimension.Bramble.nodes == null) continue;
foreach (var node in dimension.Bramble.nodes) foreach (var node in dimension.Bramble.nodes)
{ {
@ -102,27 +101,27 @@ namespace NewHorizons.Builder.Props
// A node that links to dimension A should display all of dimension A's signals, so for the purposes of our function, // A node that links to dimension A should display all of dimension A's signals, so for the purposes of our function,
// we need to say that dimension A links to dimension A // we need to say that dimension A links to dimension A
for (int dimensionIndex = 0; dimensionIndex < allDimensions.Count(); dimensionIndex++) for (int dimensionIndex = 0; dimensionIndex < dimensionConfigs.Count(); dimensionIndex++)
{ {
access[dimensionIndex, dimensionIndex] = true; access[dimensionIndex, dimensionIndex] = true;
} }
// The actual Floyd-Warshall - determine whether each pair of dimensions link indirectly (eg if A->B->C, // The actual Floyd-Warshall - determine whether each pair of dimensions link indirectly (eg if A->B->C,
// then after this step, access[A, C] = true) // then after this step, access[A, C] = true)
for (int k = 0; k < allDimensions.Count(); k++) for (int k = 0; k < dimensionConfigs.Count(); k++)
for (int i = 0; i < allDimensions.Count(); i++) for (int i = 0; i < dimensionConfigs.Count(); i++)
for (int j = 0; j < allDimensions.Count(); j++) for (int j = 0; j < dimensionConfigs.Count(); j++)
if (access[i, k] && access[k, j]) if (access[i, k] && access[k, j])
access[i, j] = true; access[i, j] = true;
// This dictionary lists all the signals a given node should have, depending on the dimension it links to // This dictionary lists all the signals a given node should have, depending on the dimension it links to
// ie, if a node links to "dimension1", then that node should spawn all of the signals in the list propagatedSignals["dimension1"] // ie, if a node links to "dimension1", then that node should spawn all of the signals in the list propagatedSignals["dimension1"]
foreach (var dimension in allDimensions) foreach (var dimension in dimensionConfigs)
{ {
_propagatedSignals[dimension.name] = new(); _propagatedSignals[dimension.name] = new();
var dimensionIndex = dimensionNameToIndex[dimension.name]; var dimensionIndex = dimensionNameToIndex[dimension.name];
foreach (var destinationDimension in allDimensions) foreach (var destinationDimension in dimensionConfigs)
{ {
if (destinationDimension.Props?.signals == null) continue; if (destinationDimension.Props?.signals == null) continue;

View File

@ -17,8 +17,6 @@ namespace NewHorizons.Handlers
{ {
public static class PlanetCreationHandler public static class PlanetCreationHandler
{ {
public static List<NewHorizonsBody> Bodies { get; private set; }
private static List<NewHorizonsBody> _nextPassBodies = new List<NewHorizonsBody>(); private static List<NewHorizonsBody> _nextPassBodies = new List<NewHorizonsBody>();
// Stock bodies being updated // Stock bodies being updated
@ -34,8 +32,6 @@ namespace NewHorizons.Handlers
_existingBodyDict = new(); _existingBodyDict = new();
_customBodyDict = new(); _customBodyDict = new();
Bodies = bodies;
// Set up stars // Set up stars
// Need to manage this when there are multiple stars // Need to manage this when there are multiple stars
var sun = SearchUtilities.Find("Sun_Body"); var sun = SearchUtilities.Find("Sun_Body");

View File

@ -273,12 +273,10 @@ namespace NewHorizons
AstroObjectLocator.Init(); AstroObjectLocator.Init();
StreamingHandler.Init(); StreamingHandler.Init();
AudioTypeHandler.Init(); AudioTypeHandler.Init();
BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray());
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
// Relies on the list of bodies from PlanetCreationHandler so it must run after
BrambleNodeBuilder.Init();
VesselWarpHandler.LoadVessel(); VesselWarpHandler.LoadVessel();
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]); SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);
LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this); LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this);