Skip to content

Commit

Permalink
Release-177, ringshader fixes and auto-select multistar mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
R-T-B committed Jul 31, 2023
1 parent f159a70 commit 0299f04
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 27 deletions.
8 changes: 4 additions & 4 deletions 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:

Expand Down
Expand Up @@ -8,7 +8,7 @@
"MAJOR": 1,
"MINOR": 12,
"PATCH": 1,
"BUILD": 176
"BUILD": 177
},
"KSP_VERSION_MIN":
{
Expand Down
12 changes: 6 additions & 6 deletions src/Kopernicus/Components/KopernicusSolarPanel.cs
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
17 changes: 13 additions & 4 deletions src/Kopernicus/Components/KopernicusStar.cs
Expand Up @@ -100,12 +100,17 @@ public class KopernicusStar : Sun
/// </summary>
public string StarName;

/// <summary>
/// A cache of base.name to avoid string allocations
/// </summary>
public static bool UseMultiStarLogic = false;

/// <summary>
/// Returns the brightest star near the given body.
/// </summary>
public static KopernicusStar GetBrightest(CelestialBody body)
{
if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic)
if (Stars.Count > 1)
{
double greatestLuminosity = 0;
KopernicusStar BrightestStar = null;
Expand All @@ -131,7 +136,7 @@ public static KopernicusStar GetBrightest(CelestialBody body)
}
else
{
return KopernicusStar.Stars.First();
return KopernicusStar.Current;
}
}

Expand All @@ -152,6 +157,10 @@ protected override void Awake()
}

Stars.Add(this);
if ((Stars.Count > 1) && (!UseMultiStarLogic))
{
UseMultiStarLogic = true;
}
DontDestroyOnLoad(this);
light = gameObject.GetComponent<Light>();

Expand Down Expand Up @@ -510,7 +519,7 @@ private static void CalculatePhysics()
/// </summary>
public static CelestialBody GetLocalStar(CelestialBody body)
{
if (RuntimeUtility.RuntimeUtility.KopernicusConfig.UseMultiStarLogic)
if (UseMultiStarLogic)
{
while (body?.orbit?.referenceBody != null)
{
Expand All @@ -526,7 +535,7 @@ public static CelestialBody GetLocalStar(CelestialBody body)
}
else
{
return Sun.Instance.sun;
return KopernicusStar.Current.sun;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kopernicus/Constants/CompatibilityChecker.cs
Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Kopernicus/Constants/Version.cs
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kopernicus/Properties/AssemblyInfo.cs
Expand Up @@ -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")]
13 changes: 6 additions & 7 deletions src/Kopernicus/RuntimeUtility/RuntimeUtility.cs
Expand Up @@ -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
Expand Down Expand Up @@ -245,6 +244,7 @@ private void OnLevelLoaded(GameScenes scene)
PatchContracts();
shadowsFixed = false;
}

private static void FixShadows()
{
try
Expand All @@ -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))
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1061,7 +1062,7 @@ private static void PatchTimeOfDayAnimation()
TimeOfDayAnimation[] animations = Resources.FindObjectsOfTypeAll<TimeOfDayAnimation>();
for (Int32 i = 0; i < animations.Length; i++)
{
if (KopernicusConfig.UseMultiStarLogic)
if (KopernicusStar.UseMultiStarLogic)
{
animations[i].target = KopernicusStar.GetBrightest(FlightGlobals.GetHomeBody()).gameObject.transform;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand Down
1 change: 0 additions & 1 deletion src/Kopernicus/UI/ToolbarButton.cs
Expand Up @@ -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);
Expand Down

0 comments on commit 0299f04

Please sign in to comment.