Skip to content

Commit

Permalink
Optimizations (#710)
Browse files Browse the repository at this point in the history
<!-- A new module or something else important -->
## Major features
-

<!-- A new parameter added to a module, or API feature -->
## Minor features
-

<!-- Some improvement that requires no action on the part of add-on
creators i.e., improved star graphics -->
## Improvements
- Cached more stuff to improve loading times. Implements #683 
- Cleaned up how planets are destroyed. Should make load screens faster.
Implements #573

<!-- Be sure to reference the existing issue if it exists -->
## Bug fixes
- Fixes Bramble colours at a distance. Fixes #372
  • Loading branch information
xen-42 committed Aug 26, 2023
2 parents 8a9c5b1 + 2d452fe commit 6596c7c
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 220 deletions.
2 changes: 2 additions & 0 deletions NewHorizons/Builder/Props/Audio/SignalBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public static void Init()

Initialized = true;

SceneManager.sceneUnloaded -= OnSceneUnloaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
Main.Instance.OnStarSystemLoaded.RemoveListener(OnStarSystemLoaded);
Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded);
}

Expand Down
17 changes: 13 additions & 4 deletions NewHorizons/Builder/Props/BrambleNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,17 @@ public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo conf
// Default size is 70
var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere");
fog.transform.localScale = Vector3.one * config.scale * 70f;
var fogMaterial = fog.GetComponent<MeshRenderer>().material;
fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale);
fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale);

// Copy shared material to not be shared
var fogRenderer = fog.GetComponent<MeshRenderer>();
fogRenderer.material = new Material(fogRenderer.sharedMaterial);
fogRenderer.material.SetFloat("_Radius", fogRenderer.material.GetFloat("_Radius") * config.scale);
fogRenderer.material.SetFloat("_Density", fogRenderer.material.GetFloat("_Density") / config.scale);
// Fixes bramble nodes being a weird colour until you approach the first time #372
if (config.fogTint != null)
{
fog.GetComponent<OWRenderer>().SetColor(config.fogTint.ToColor());
}
}

// Set colors
Expand Down Expand Up @@ -393,7 +401,8 @@ public static GameObject Make(GameObject go, Sector sector, BrambleNodeInfo conf
}
}

StreamingHandler.SetUpStreaming(brambleNode, sector);
// If the outer fog warp volume is null we're exposed to the solar system so treat it as a keepLoaded type prop
StreamingHandler.SetUpStreaming(brambleNode, outerFogWarpVolume == null ? null : sector);

// Done!
brambleNode.SetActive(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ internal static GameObject MakeArc(NomaiTextArcInfo arcInfo, GameObject conversa
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlPath);
XmlNode rootNode = xmlDocument.SelectSingleNode("NomaiObject");

if (rootNode == null)
{
NHLogger.LogError($"Couldn't find NomaiObject in [{xmlPath}]");
return dict;
}

foreach (object obj in rootNode.SelectNodes("TextBlock"))
{
Expand Down
26 changes: 22 additions & 4 deletions NewHorizons/Handlers/PlanetCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,20 @@ public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = fal
}
catch (Exception)
{
if (body?.Config?.name == null) NHLogger.LogError($"How is there no name for {body}");
else existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
if (body?.Config?.name == null)
{
NHLogger.LogError($"How is there no name for {body}");
}
else
{
existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
}
}

if (existingPlanet == null && body.Config.destroy)
{
NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found");
return false;
}

if (existingPlanet != null)
Expand All @@ -169,8 +181,14 @@ public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = fal
if (body.Config.destroy)
{
var ao = existingPlanet.GetComponent<AstroObject>();
if (ao != null) Delay.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2);
else Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableBody(existingPlanet, false), 2);
if (ao != null)
{
Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableAstroObject(ao), 2);
}
else
{
Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableGameObject(existingPlanet), 2);
}
}
else if (body.Config.isQuantumState)
{
Expand Down
Loading

0 comments on commit 6596c7c

Please sign in to comment.