From 0299f0477bb6094a0fd71c6698af5006eeb76cc5 Mon Sep 17 00:00:00 2001 From: Raymond Beehler <21GunSoftware@comcast.net> Date: Sun, 30 Jul 2023 21:40:05 -0700 Subject: [PATCH] Release-177, ringshader fixes and auto-select multistar mode. --- README.md | 8 ++++---- .../Kopernicus/Plugins/Kopernicus.version | 2 +- .../Components/KopernicusSolarPanel.cs | 12 ++++++------ src/Kopernicus/Components/KopernicusStar.cs | 17 +++++++++++++---- .../Constants/CompatibilityChecker.cs | 2 +- src/Kopernicus/Constants/Version.cs | 4 ++-- src/Kopernicus/Properties/AssemblyInfo.cs | 2 +- src/Kopernicus/RuntimeUtility/RuntimeUtility.cs | 13 ++++++------- src/Kopernicus/UI/ToolbarButton.cs | 1 - 9 files changed, 34 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 575aef90..d6ee5a5d 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ Kopernicus ============================== -June 26th, 2023 +June 30th, 2023 * Created by: BryceSchroeder and Nathaniel R. Lewis (Teknoman117) * Actively maintained by: Prestja and R-T-B. * Formerly maintained by: Thomas P., NathanKell and KillAshley * Additional Content by: Democat3457, Gravitasi, aftokino, KCreator, Padishar, Kragrathea, OvenProofMars, zengei, MrHappyFace, Sigma88, Majiir (CompatibilityChecker), blackrack/LGHassen (shaders/GPL'd scatterer code) * Much thanks to Sarbian for ModuleManager and ModularFlightIntegrator -New in this latest version release-176: +New in this latest version release-177: -1.) A small bugfix for the single-star performance improvements (KSC lights weren't turning on at night). +1.) Multistar mode now activates automatically when more than one star is present, no user intervention needed or required. The old option has been removed entirely. -2.) With this one bugfix, and a few days testing, we now consider this experiment stable and are pushing it to CKAN. +2.) The ringshader light direction was defaulting to singlestar mode regardless of the actual setting status, or amount of stars. This has been fixed. Known Bugs: diff --git a/build/KSP19PLUS/GameData/Kopernicus/Plugins/Kopernicus.version b/build/KSP19PLUS/GameData/Kopernicus/Plugins/Kopernicus.version index a9b4a7a5..9e0e9816 100644 --- a/build/KSP19PLUS/GameData/Kopernicus/Plugins/Kopernicus.version +++ b/build/KSP19PLUS/GameData/Kopernicus/Plugins/Kopernicus.version @@ -8,7 +8,7 @@ "MAJOR": 1, "MINOR": 12, "PATCH": 1, - "BUILD": 176 + "BUILD": 177 }, "KSP_VERSION_MIN": { diff --git a/src/Kopernicus/Components/KopernicusSolarPanel.cs b/src/Kopernicus/Components/KopernicusSolarPanel.cs index f075433a..51a0da4a 100644 --- a/src/Kopernicus/Components/KopernicusSolarPanel.cs +++ b/src/Kopernicus/Components/KopernicusSolarPanel.cs @@ -65,7 +65,7 @@ public class KopernicusSolarPanel : ModuleDeployableSolarPanel public override void FixedUpdate() { base.FixedUpdate(); - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { frameTimer++; if (HighLogic.LoadedSceneIsFlight) @@ -229,7 +229,7 @@ public override void FixedUpdate() public override void PostCalculateTracking(bool trackingLOS, Vector3 trackingDirection) { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { // Calculate sun AOA sunAOA = 0f; @@ -277,7 +277,7 @@ public override void PostCalculateTracking(bool trackingLOS, Vector3 trackingDir void EarlyLateUpdate() { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { if (deployState == ModuleDeployablePart.DeployState.EXTENDED) { @@ -295,7 +295,7 @@ void EarlyLateUpdate() [KSPEvent(active = true, guiActive = false, guiName = "#Kopernicus_UI_SelectBody")] public void ManualTracking() { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { KopernicusStar[] orderedStars = KopernicusStar.Stars .OrderBy(s => Vector3.Distance(vessel.transform.position, s.sun.position)).ToArray(); @@ -332,7 +332,7 @@ public void SetTrackingBody(CelestialBody sun) public override void OnStart(StartState state) { base.OnStart(state); - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { //Setup Floatcurves AtmosphericAttenutationAirMassMultiplier.Add(0f, 1f, 0f, 0f); @@ -393,7 +393,7 @@ public override void OnStart(StartState state) public void OnDestroy() { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { TimingManager.LateUpdateRemove(TimingManager.TimingStage.Early, EarlyLateUpdate); } diff --git a/src/Kopernicus/Components/KopernicusStar.cs b/src/Kopernicus/Components/KopernicusStar.cs index 232233db..3e506815 100755 --- a/src/Kopernicus/Components/KopernicusStar.cs +++ b/src/Kopernicus/Components/KopernicusStar.cs @@ -100,12 +100,17 @@ public class KopernicusStar : Sun /// public string StarName; + /// + /// A cache of base.name to avoid string allocations + /// + public static bool UseMultiStarLogic = false; + /// /// Returns the brightest star near the given body. /// public static KopernicusStar GetBrightest(CelestialBody body) { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (Stars.Count > 1) { double greatestLuminosity = 0; KopernicusStar BrightestStar = null; @@ -131,7 +136,7 @@ public static KopernicusStar GetBrightest(CelestialBody body) } else { - return KopernicusStar.Stars.First(); + return KopernicusStar.Current; } } @@ -152,6 +157,10 @@ protected override void Awake() } Stars.Add(this); + if ((Stars.Count > 1) && (!UseMultiStarLogic)) + { + UseMultiStarLogic = true; + } DontDestroyOnLoad(this); light = gameObject.GetComponent(); @@ -510,7 +519,7 @@ private static void CalculatePhysics() /// public static CelestialBody GetLocalStar(CelestialBody body) { - if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic) + if (UseMultiStarLogic) { while (body?.orbit?.referenceBody != null) { @@ -526,7 +535,7 @@ public static CelestialBody GetLocalStar(CelestialBody body) } else { - return Sun.Instance.sun; + return KopernicusStar.Current.sun; } } diff --git a/src/Kopernicus/Constants/CompatibilityChecker.cs b/src/Kopernicus/Constants/CompatibilityChecker.cs index baa35e3d..cc835380 100755 --- a/src/Kopernicus/Constants/CompatibilityChecker.cs +++ b/src/Kopernicus/Constants/CompatibilityChecker.cs @@ -56,7 +56,7 @@ public class CompatibilityChecker : MonoBehaviour #endif internal const Int32 VERSION_MINOR_LOWER_LIMIT = 8; internal const Int32 REVISION = 1; - internal const Int32 KOPERNICUS = 176; + internal const Int32 KOPERNICUS = 177; public static Boolean IsCompatible() { diff --git a/src/Kopernicus/Constants/Version.cs b/src/Kopernicus/Constants/Version.cs index afffe5c2..01562499 100755 --- a/src/Kopernicus/Constants/Version.cs +++ b/src/Kopernicus/Constants/Version.cs @@ -39,9 +39,9 @@ public static String VersionNumber get { #if (!KSP_VERSION_1_8) - return "Release-176"; + return "Release-177"; #else - return "LEGACY18_Release-176"; + return "LEGACY18_Release-177"; #endif } } diff --git a/src/Kopernicus/Properties/AssemblyInfo.cs b/src/Kopernicus/Properties/AssemblyInfo.cs index cd95d2d1..32ce9d73 100755 --- a/src/Kopernicus/Properties/AssemblyInfo.cs +++ b/src/Kopernicus/Properties/AssemblyInfo.cs @@ -13,7 +13,7 @@ [assembly: KSPAssemblyDependency("Kopernicus.Parser", 1, 0)] [assembly: KSPAssemblyDependency("ModularFlightIntegrator", 1, 0)] [assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("1.12.176.2")] +[assembly: AssemblyFileVersion("1.12.177.0")] [assembly: LogAggregator("GameData/ModuleManager.ConfigCache")] [assembly: LogAggregator("Logs/Kopernicus/")] [assembly: LogAggregator("KSP.log")] diff --git a/src/Kopernicus/RuntimeUtility/RuntimeUtility.cs b/src/Kopernicus/RuntimeUtility/RuntimeUtility.cs index 9da26900..292cdd26 100644 --- a/src/Kopernicus/RuntimeUtility/RuntimeUtility.cs +++ b/src/Kopernicus/RuntimeUtility/RuntimeUtility.cs @@ -97,7 +97,6 @@ public class RuntimeUtility : MonoBehaviour public static PQSCache.PQSPreset pqsHigh; private static bool shadowsFixed = false; - //old mockbody for compat public static CelestialBody mockBody = null; //Plugin Path finding logic @@ -245,6 +244,7 @@ private void OnLevelLoaded(GameScenes scene) PatchContracts(); shadowsFixed = false; } + private static void FixShadows() { try @@ -261,7 +261,7 @@ private static void FixShadows() private void Update() { internalTimer++; - if (internalTimer > 30) + if (internalTimer > 60) { internalTimer = 0; if (HighLogic.LoadedScene.Equals(GameScenes.SETTINGS) || HighLogic.LoadedScene.Equals(GameScenes.MAINMENU)) @@ -842,7 +842,7 @@ private static void ApplyOrbitVisibility(CelestialBody body) // Use the brightest star as the AFG star private void AtmosphereLightPatch(CelestialBody body) { - if ((!body.afg) || (!KopernicusConfig.UseMultiStarLogic)) + if ((!body.afg) || (!KopernicusStar.UseMultiStarLogic)) { return; } @@ -919,6 +919,7 @@ public static void FixCameras() { FloatingOrigin.fetch.ResetOffset(); } + // Get the parental body CelestialBody body = Planetarium.fetch != null ? Planetarium.fetch.Home : FlightGlobals.Bodies.Find(b => b.isHomeWorld); @@ -1061,7 +1062,7 @@ private static void PatchTimeOfDayAnimation() TimeOfDayAnimation[] animations = Resources.FindObjectsOfTypeAll(); for (Int32 i = 0; i < animations.Length; i++) { - if (KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { animations[i].target = KopernicusStar.GetBrightest(FlightGlobals.GetHomeBody()).gameObject.transform; } @@ -1076,7 +1077,7 @@ private static void PatchTimeOfDayAnimation() private static void PatchStarReferences(CelestialBody body) { GameObject star; - if (KopernicusConfig.UseMultiStarLogic) + if (KopernicusStar.UseMultiStarLogic) { star = KopernicusStar.GetBrightest(body).gameObject; } @@ -1185,7 +1186,6 @@ private void WriteConfigIfNoneExists() configFile.WriteLine(" WarnShaders = False //Boolean. Whether or not to warn the user with a message if not using EnforcedShaderLevel."); configFile.WriteLine(" EnforcedShaderLevel = 2 //Integer. A number defining the enforced shader level for the above parameters. 0=Low,1=Medium,2=High,3=Ultra."); configFile.WriteLine(" UseKopernicusAsteroidSystem = True //String with three valid values, True,False, and Stock. True means use the old customizable Kopernicus asteroid generator with no comet support (many packs use this so it's the default). False means don't generate anything, or wait for an external generator. Stock means use the internal games generator, which supports comets, but usually only works well in stock based systems with Dres and Kerbin present."); - configFile.WriteLine(" UseMultiStarLogic = False //Boolean, False means use the old Stock code with support for one star, with better performance. True activates Kopernicus multistar ready code, with a performance hit."); configFile.WriteLine(" SolarRefreshRate = 1 //Integer. A number defining the number of seconds between EC calculations when using the multistar cfg file. Can be used to finetune performance (higher runs faster). Otherwise irrelevant."); configFile.WriteLine(" EnableKopernicusShadowManager = True //Boolean. Whether or not to run the Internal Kopernicus Shadow System. True by default, users using mods that do their own shadows (scatterer etc) may want to disable this to save a small bit of performance."); configFile.WriteLine(" ShadowRangeCap = 50000 //Integer. A number defining the maximum distance at which shadows may be cast. Lower numbers tend to yield less shadow cascading artifacts, but higher numbers cast shadows farther. Default at 50000 is an approximation of stock. Only works if EnableKopernicusShadowManager is true."); @@ -1238,7 +1238,6 @@ private void UpdateConfig() { configFile.WriteLine(" UseKopernicusAsteroidSystem = " + KopernicusConfig.UseKopernicusAsteroidSystem + " //String with three valid values, True,False, and Stock. True means use the old customizable Kopernicus asteroid generator with no comet support (many packs use this so it's the default). False means don't generate anything, or wait for an external generator. Stock means use the internal games generator, which supports comets, but usually only works well in stock based systems with Dres and Kerbin present."); } - configFile.WriteLine(" UseMultiStarLogic = " + KopernicusConfig.UseMultiStarLogic.ToString() + " //Boolean, False means use the old Stock code with support for one star, with better performance. True activates Kopernicus multistar ready code, with a performance hit."); configFile.WriteLine(" SolarRefreshRate = " + KopernicusConfig.SolarRefreshRate.ToString() + " //Integer. A number defining the number of seconds between EC calculations when using the multistar cfg file. Can be used to finetune performance (higher runs faster). Otherwise irrelevant."); configFile.WriteLine(" EnableKopernicusShadowManager = " + KopernicusConfig.EnableKopernicusShadowManager.ToString() + " //Boolean. Whether or not to run the Internal Kopernicus Shadow System. True by default, users using mods that do their own shadows (scatterer etc) may want to disable this to save a small bit of performance."); configFile.WriteLine(" ShadowRangeCap = " + KopernicusConfig.ShadowRangeCap + " //Integer. A number defining the maximum distance at which shadows may be cast. Lower numbers yield less shadow cascading artifacts, but higher numbers cast shadows farther. Default at 50000 is an approximation of stock. Only works if EnableKopernicusShadowManager is true."); diff --git a/src/Kopernicus/UI/ToolbarButton.cs b/src/Kopernicus/UI/ToolbarButton.cs index cc99fb2b..45020cf9 100644 --- a/src/Kopernicus/UI/ToolbarButton.cs +++ b/src/Kopernicus/UI/ToolbarButton.cs @@ -105,7 +105,6 @@ public void DrawKopernicusWindow(int windowId) GUILayout.Label("Kopernicus_Config.cfg Editor", labelStyle); RuntimeUtility.RuntimeUtility.KopernicusConfig.EnforceShaders = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.EnforceShaders, "EnforceShaders: Whether or not to force the user into EnforcedShaderLevel, not allowing them to change settings.", toggleStyle); RuntimeUtility.RuntimeUtility.KopernicusConfig.WarnShaders = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.WarnShaders, "WarnShaders: Whether or not to warn the user with a message if not using EnforcedShaderLevel.", toggleStyle); - RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic, "UseMultiStarLogic: False means use the old Stock code with support for one star, with better performance. True activates Kopernicus multistar ready code, with a performance hit.", toggleStyle); RuntimeUtility.RuntimeUtility.KopernicusConfig.EnableKopernicusShadowManager = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.EnableKopernicusShadowManager, "EnableKopernicusShadowManager: Whether or not to run the Internal Kopernicus Shadow System. True by default.", toggleStyle); RuntimeUtility.RuntimeUtility.KopernicusConfig.DisableMainMenuMunScene = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.DisableMainMenuMunScene, " DisableMainMenuMunScene: Whether or not to disable the Mun main menu scene. Only uncheck this if you actually have a Mun, and want that scene back.", toggleStyle); RuntimeUtility.RuntimeUtility.KopernicusConfig.HandleHomeworldAtmosphericUnitDisplay = GUILayout.Toggle(RuntimeUtility.RuntimeUtility.KopernicusConfig.HandleHomeworldAtmosphericUnitDisplay, "HandleHomeworldAtmosphericUnitDisplay: This is for calculating 1atm unit at home world. Normally should be checked, but mods like PlanetaryInfoPlus may want to change this.", toggleStyle);