Skip to content

Commit 1c5d014

Browse files
committed
Refactor animationcurve loader, add some more sun params
@Pingopete, take note! :) You can add a sunBrightnessCurve {} node to REALSOLARSYSTEMSETTINGS with a series of keys, and sunAU = foo for the new AU scalar. The originals are (time, value, in, out, mode): **DUMP** Sun AU: 13599840256 Key -0.01573471, 0.217353, 1.706627,1.706627 : mode 0 Key 5.084181, 3.997075, -0.001802375,-0.001802375 : mode 0 Key 38.56295, 1.82142, 0.0001713,0.0001713 : mode 0 so you can do sunBrightnessCurve { key = 0 100000 0 0 key 153000000 1 0 0 etc } }
1 parent 96f6440 commit 1c5d014

5 files changed

Lines changed: 73 additions & 45 deletions

File tree

512 Bytes
Binary file not shown.

Source/LightShifter.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ void Start() {
150150
} else {
151151
print("*RSS* LightShifter: Couldn't find DynamicAmbientLight");
152152
}
153+
Sun sun = Sun.Instance;
154+
if (sun != null)
155+
{
156+
if (RSSSettings.HasValue("dumpBrightnessCurve"))
157+
{
158+
print("**DUMP** Sun AU: " + sun.AU);
159+
for (int i = 0; i < sun.brightnessCurve.keys.Length; i++)
160+
{
161+
Keyframe k = sun.brightnessCurve.keys[i];
162+
print("Key " + k.time + ", " + k.value + ", " + k.inTangent + "," + k.outTangent + " : mode " + k.tangentMode);
163+
}
164+
}
165+
if (RSSSettings.HasNode("sunBrightnessCurve"))
166+
{
167+
AnimationCurve newCurve = Utils.LoadAnimationCurve(RSSSettings.GetNode("sunBrightnessCurve"));
168+
}
169+
RSSSettings.TryGetValue("sunAU", ref sun.AU);
170+
171+
}
153172
}
154173
}
155174
}

Source/RealSolarSystem.cs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -252,45 +252,6 @@ public static void GravParamToOthers(CelestialBody body)
252252

253253
public static bool done = false;
254254

255-
public AnimationCurve loadAnimationCurve(string[] curveData)
256-
{
257-
char[] cParams = new char[] { ' ', ',', ';', '\t' };
258-
AnimationCurve animationCurve = new AnimationCurve();
259-
try
260-
{
261-
for (int i = 0; i < curveData.Length; i++)
262-
{
263-
string[] keyTmp = curveData[i].Split(cParams, StringSplitOptions.RemoveEmptyEntries);
264-
if (keyTmp.Length == 4)
265-
{
266-
Keyframe key = new Keyframe();
267-
key.time = float.Parse(keyTmp[0]);
268-
key.value = float.Parse(keyTmp[1]);
269-
key.inTangent = float.Parse(keyTmp[2]);
270-
key.outTangent = float.Parse(keyTmp[3]);
271-
animationCurve.AddKey(key);
272-
}
273-
else if (keyTmp.Length == 2)
274-
{
275-
Keyframe key = new Keyframe();
276-
key.time = float.Parse(keyTmp[0]);
277-
key.value = float.Parse(keyTmp[1]);
278-
animationCurve.AddKey(key);
279-
}
280-
else
281-
{
282-
MonoBehaviour.print("*RSS* Invalid animationCurve data: animationCurve data must have exactly two or four parameters!");
283-
}
284-
}
285-
return animationCurve;
286-
}
287-
catch (Exception e)
288-
{
289-
print("Caught exception while parsing animationcurve: " + e.Message);
290-
return null;
291-
}
292-
}
293-
294255
public static RSSLoadInfo loadInfo = null;
295256

296257
// Constants
@@ -344,10 +305,9 @@ private IEnumerator<YieldInstruction> LoadCB(ConfigNode node, CelestialBody body
344305
ConfigNode PCnode = node.GetNode("pressureCurve");
345306
if (PCnode != null)
346307
{
347-
string[] curve = PCnode.GetValues("key");
348308
body.altitudeMultiplier = 1f;
349309
body.pressureMultiplier = 1f;
350-
AnimationCurve pressureCurve = loadAnimationCurve(curve);
310+
AnimationCurve pressureCurve = Utils.LoadAnimationCurve(PCnode);
351311
if (pressureCurve != null)
352312
body.pressureCurve = pressureCurve;
353313
else
@@ -367,8 +327,7 @@ private IEnumerator<YieldInstruction> LoadCB(ConfigNode node, CelestialBody body
367327
ConfigNode TCnode = node.GetNode("temperatureCurve");
368328
if (TCnode != null)
369329
{
370-
string[] curve = TCnode.GetValues("key");
371-
AnimationCurve temperatureCurve = loadAnimationCurve(curve);
330+
AnimationCurve temperatureCurve = Utils.LoadAnimationCurve(TCnode);
372331
if (temperatureCurve != null)
373332
{
374333
body.temperatureCurve = temperatureCurve;

Source/Utils.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@ namespace RealSolarSystem
1010
{
1111
public class Utils : MonoBehaviour
1212
{
13+
public static AnimationCurve LoadAnimationCurve(ConfigNode node)
14+
{
15+
string[] curve = node.GetValues("key");
16+
return LoadAnimationCurve(curve);
17+
}
18+
19+
public static AnimationCurve LoadAnimationCurve(string[] curveData)
20+
{
21+
char[] cParams = new char[] { ' ', ',', ';', '\t' };
22+
AnimationCurve animationCurve = new AnimationCurve();
23+
try
24+
{
25+
for (int i = 0; i < curveData.Length; i++)
26+
{
27+
string[] keyTmp = curveData[i].Split(cParams, StringSplitOptions.RemoveEmptyEntries);
28+
if (keyTmp.Length == 4)
29+
{
30+
Keyframe key = new Keyframe();
31+
key.time = float.Parse(keyTmp[0]);
32+
key.value = float.Parse(keyTmp[1]);
33+
key.inTangent = float.Parse(keyTmp[2]);
34+
key.outTangent = float.Parse(keyTmp[3]);
35+
animationCurve.AddKey(key);
36+
}
37+
else if (keyTmp.Length == 2)
38+
{
39+
Keyframe key = new Keyframe();
40+
key.time = float.Parse(keyTmp[0]);
41+
key.value = float.Parse(keyTmp[1]);
42+
animationCurve.AddKey(key);
43+
}
44+
else
45+
{
46+
MonoBehaviour.print("*RSS* Invalid animationCurve data: animationCurve data must have exactly two or four parameters!");
47+
}
48+
}
49+
return animationCurve;
50+
}
51+
catch (Exception e)
52+
{
53+
print("Caught exception while parsing animationcurve: " + e.Message);
54+
return null;
55+
}
56+
}
1357
public static void ScaleVerts(Mesh mesh, float scaleFactor)
1458
{
1559
ProfileTimer.Push("ScaleVerts");
@@ -88,7 +132,7 @@ public static bool LoadTexture(string path, ref Texture2D map, bool compress, bo
88132
}
89133
catch (Exception e)
90134
{
91-
Debug.Log("*RSS* *ERROR* failed to load " + path);
135+
Debug.Log("*RSS* *ERROR* failed to load " + path + " with exception " + e.Message);
92136
}
93137
}
94138
else

Source/Watchdogs.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace RealSolarSystem
1010
{
1111
// Checks to make sure useLegacyAtmosphere didn't get munged with
1212
// Could become a general place to prevent RSS changes from being reverted when our back is turned.
13-
[KSPAddon(KSPAddon.Startup.Flight, false)]
13+
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
1414
public class RSSWatchDog : MonoBehaviour
1515
{
1616
ConfigNode RSSSettings = null;
@@ -24,6 +24,8 @@ public void Start()
2424
isCompatible = false;
2525
return;
2626
}
27+
if (!(HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER))
28+
return;
2729
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("REALSOLARSYSTEM"))
2830
RSSSettings = node;
2931

@@ -48,6 +50,8 @@ public void Update()
4850
{
4951
if (!isCompatible)
5052
return;
53+
if (!(HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER))
54+
return;
5155

5256
if(!useKeypressClip && updateCount > 22)
5357
return;
@@ -114,6 +118,8 @@ public void FixedUpdate()
114118
{
115119
if (!isCompatible)
116120
return;
121+
if (!(HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER))
122+
return;
117123

118124
if (!dumpOrbits)
119125
return;

0 commit comments

Comments
 (0)