Skip to content

Commit

Permalink
Merge pull request #30 from Sigma88/Development
Browse files Browse the repository at this point in the history
v0.7.3
  • Loading branch information
Sigma88 committed Dec 10, 2016
2 parents a9fed1a + a653bc9 commit fd943b8
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 23 deletions.
10 changes: 10 additions & 0 deletions Changelog.txt
@@ -1,4 +1,14 @@
**v0.7.3**

- Time warp limits and other parameters now account for atmoTopLayer
- Added the possibility to define groups of PQSCity and PQSCity2
(allows to keep groups of buildings together when resizing a planet)
- Improved the debug options
(still completely useless, see v0.7.1)


**v0.7.2**

- Fixed resize of Kopernicus feature SpaceCenter


Expand Down
Expand Up @@ -111,6 +111,7 @@
@AerialPerspectiveMaterial,*
{
@atmosphereDepth *= #$../../../SigmaDimensions/Atmosphere$
@atmosphereDepth *= #$../../../SigmaDimensions/atmoTopLayer$
}
@VertexHeightMap,*
{
Expand Down
Expand Up @@ -6,6 +6,9 @@
{
@timewarpAltitudeLimits,0[*, ] *= #$../SigmaDimensions/Atmosphere$
@inverseRotThresholdAltitude *= #$../SigmaDimensions/Atmosphere$

@timewarpAltitudeLimits,0[*, ] *= #$../SigmaDimensions/atmoTopLayer$
@inverseRotThresholdAltitude *= #$../SigmaDimensions/atmoTopLayer$
}
}
@Body:HAS[!Atmosphere]
Expand Down
2 changes: 1 addition & 1 deletion GameData/Sigma/Dimensions/Configs/Sigma-Dimensions.version
Expand Up @@ -13,7 +13,7 @@
{
"MAJOR": 0,
"MINOR": 7,
"PATCH": 2,
"PATCH": 3,
"BUILD": 0
},
"KSP_VERSION":
Expand Down
Binary file modified GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll
Binary file not shown.
Binary file modified [Source]/Distribution/SigmaDimensions.dll
Binary file not shown.
24 changes: 11 additions & 13 deletions [Source]/SigmaDimensions/AtmosphereTopLayer.cs
Expand Up @@ -17,8 +17,8 @@ void Start()
foreach (CelestialBody body in FlightGlobals.Bodies.FindAll(b => b.atmosphere && b.Has("atmoTopLayer")))
{
// Debug
debug = body.Has("debug") ? body.Get<bool>("debug") : false;
if (debug) PrintCurve(body, "Original Curves");
Debug.debug = body.Has("debug") ? body.Get<bool>("debug") : false;
PrintCurve(body, "Original Curves");

Normalize(body, body.atmosphereDepth);

Expand All @@ -31,13 +31,13 @@ void Start()
Normalize(body, 1 / body.atmosphereDepth);

// Debug
if (debug) PrintCurve(body, "Final Curves");
PrintCurve(body, "Final Curves");
}
}

void FixPressure(FloatCurve curve, double topLayer)
{
List<double[]> list = ReadCurve(curve); /* Avoid Bad Curves ==> */ if (list.Count < 2) { Debug.Log("SigmaLog: This pressure curve has " + (list.Count == 0 ? "no keys" : "just one key") + ". I don't know what you expect me to do with that."); return; }
List<double[]> list = ReadCurve(curve); /* Avoid Bad Curves ==> */ if (list.Count < 2) { UnityEngine.Debug.Log("SigmaLog: This pressure curve has " + (list.Count == 0 ? "no keys" : "just one key") + ". I don't know what you expect me to do with that."); return; }

double maxAltitude = list.Last()[0];

Expand Down Expand Up @@ -68,7 +68,7 @@ void QuickFix(FloatCurve curve, double topLayer)
{
if (topLayer > curve.maxTime)
{
List<double[]> list = ReadCurve(curve); /* Avoid Bad Curves ==> */ if (list.Count == 0) { Debug.Log("SigmaLog: RETURN"); return; }
List<double[]> list = ReadCurve(curve); /* Avoid Bad Curves ==> */ if (list.Count == 0) { UnityEngine.Debug.Log("SigmaLog: This curve is pointless."); return; }
list.Last()[3] = 0;
list.Add(new double[] { topLayer, list.Last()[1], 0, 0 });
curve.Load(WriteCurve(list));
Expand Down Expand Up @@ -106,7 +106,7 @@ void Extend(List<double[]> list, double topLayer)
}

// Debug
if (debug) PrintCurve(list, "Extend");
PrintCurve(list, "Extend");
}

void Trim(List<double[]> list, double topLayer)
Expand All @@ -125,7 +125,7 @@ void Trim(List<double[]> list, double topLayer)
list.Add(lastKey);

// Debug
if (debug) PrintCurve(list, "Trim");
PrintCurve(list, "Trim");
}

void Smooth(List<double[]> list, double smoothRange)
Expand All @@ -148,7 +148,7 @@ void Smooth(List<double[]> list, double smoothRange)
list.Add(lastKey);

// Debug
if (debug) PrintCurve(list, "Smooth");
PrintCurve(list, "Smooth");
}

// Normalizers
Expand Down Expand Up @@ -279,11 +279,9 @@ enum Ktype

// DEBUG

bool debug = false;

void PrintCurve(CelestialBody body, string name)
{
Debug.Log("SigmaLog: " + name + " for body " + body.name);
Debug.Log(name + " for body " + body.name);
PrintCurve(body.atmospherePressureCurve, "pressureCurve");
PrintCurve(body.atmosphereTemperatureCurve, "temperatureCurve");
PrintCurve(body.atmosphereTemperatureSunMultCurve, "temperatureSunMultCurve");
Expand All @@ -305,10 +303,10 @@ void PrintCurve(FloatCurve curve, string name)
{
ConfigNode config = new ConfigNode();
curve.Save(config);
Debug.Log("SigmaLog: " + name);
Debug.Log(name);
foreach (string key in config.GetValues("key"))
{
Debug.Log("SigmaLog: key = " + key);
Debug.Log("key = " + key);
}
}
}
Expand Down
87 changes: 87 additions & 0 deletions [Source]/SigmaDimensions/PQSCityGroupsLoader.cs
@@ -0,0 +1,87 @@
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using Kopernicus;


namespace SigmaDimensionsPlugin
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class PQSCityGroupsLoader : MonoBehaviour
{
public static Dictionary<string, ConfigNode> GroupList = new Dictionary<string, ConfigNode>();

void Start()
{
foreach (ConfigNode GroupLoader in GameDatabase.Instance.GetConfigNodes("PQSCity_Groups"))
{
PQSCityGroups.AddGroups(GroupLoader.GetNodes("Group"));
}
PQSCityGroups.SaveGroups();
}
}

public static class PQSCityGroups
{
public static void AddGroups(ConfigNode[] Groups)
{
foreach (ConfigNode Group in Groups)
{
string name = Group.GetValue("name");
if (string.IsNullOrEmpty(name)) continue;
if (PQSCityGroupsLoader.GroupList.ContainsKey(name))
PQSCityGroupsLoader.GroupList[name].AddData(Group);
else
PQSCityGroupsLoader.GroupList.Add(name, Group);
}
}

public static void SaveGroups()
{
foreach (ConfigNode Group in PQSCityGroupsLoader.GroupList.Values)
{
string name = Group.GetValue("name");
CelestialBody body = FlightGlobals.Bodies.First(b => b.transform.name == Group.GetValue("body"));
if (string.IsNullOrEmpty(name) || body == null) continue;

Vector3Parser center = new Vector3Parser();
if (Group.HasValue("CentralPQSCity"))
center = body.GetComponentsInChildren<PQSCity>(true).FirstOrDefault(p => p.name == Group.GetValue("CentralPQSCity")).repositionRadial;
else if (Group.HasValue("CentralPQSCity2"))
{
PQSCity2 city2 = body.GetComponentsInChildren<PQSCity2>(true).First(p => p.name == Group.GetValue("CentralPQSCity2"));
center = Utility.LLAtoECEF(city2.lat, city2.lon, 1, 1);
}
else if (Group.HasValue("CentralPosition"))
center.SetFromString(Group.GetValue("CentralPosition"));
else if (Group.HasValue("CentralLAT") && Group.HasValue("CentralLON"))
{
EnumParser<double> LAT = new EnumParser<double>();
EnumParser<double> LON = new EnumParser<double>();
LAT.SetFromString(Group.GetValue("CentralLAT"));
LON.SetFromString(Group.GetValue("CentralLON"));
center = Utility.LLAtoECEF(LAT, LON, 1, 1);
}
else continue;

if (!body.Has("PQSCityGroups"))
body.Set("PQSCityGroups", new Dictionary<object, Vector3>());
Dictionary<object, Vector3> PQSList = body.Get<Dictionary<object, Vector3>>("PQSCityGroups");

foreach (string pqs in Group.GetValues("PQSCity"))
{
PQSCity mod = body.GetComponentsInChildren<PQSCity>(true).First(m => m.name == pqs);
if (mod != null && !PQSList.ContainsKey(mod))
PQSList.Add(mod, center);
}
foreach (string pqs in Group.GetValues("PQSCity2"))
{
PQSCity2 mod = body.GetComponentsInChildren<PQSCity2>(true).First(m => m.name == pqs);
if (mod != null && !PQSList.ContainsKey(mod))
PQSList.Add(mod, center);
}
body.Set("PQSCityGroups", PQSList);
}
}
}
}
12 changes: 12 additions & 0 deletions [Source]/SigmaDimensions/SigmaDebugLogger.cs
@@ -0,0 +1,12 @@
namespace SigmaDimensionsPlugin
{
public static class Debug
{
public static bool debug = false;

public static void Log(string s)
{
if (debug) UnityEngine.Debug.Log("SigmaLog: " + s);
}
}
}
26 changes: 17 additions & 9 deletions [Source]/SigmaDimensions/SigmaDimensions.cs
@@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Kopernicus;
using Kopernicus.Configuration;
using SigmaDimensionsPlugin;


namespace SigmaDimensionsPlugin
Expand Down Expand Up @@ -67,19 +71,23 @@ void CityFixer(PQSCity pqs)

pqs.transform.localScale *= (float)resizeBuildings;
}
if (pqs.name == "KerbinSide/CoreAssets/ksidehangars1(Clone)")
if (body.Has("PQSCityGroups"))
{
Vector3 vector = pqs.repositionRadial;
Debug.Log("SigmaDimensionsLog: vector = " + vector);
Vector3 REFvector = Array.Find(body.GetComponentsInChildren<PQSCity>(), m => m.name == "KSC").repositionRadial;
Debug.Log("SigmaDimensionsLog: REFvector = " + vector);
Vector3 newVector = Vector3.LerpUnclamped((REFvector * 100).normalized, vector.normalized, (float)(resizeBuildings / resize));
Debug.Log("SigmaDimensionsLog: newVector = " + vector);
pqs.repositionRadial = newVector;
Debug.Log("SigmaDimensionsLog: pqs.repositionRadial = " + pqs.repositionRadial);
Dictionary<object, Vector3> PQSList = body.Get<Dictionary<object, Vector3>>("PQSCityGroups");
if (PQSList.ContainsKey(pqs))
{
GroupFixer(pqs, PQSList[pqs].normalized);
}
}
}

void GroupFixer(PQSCity pqs, Vector3 REFvector)
{
Vector3 PQSvector = pqs.repositionRadial.normalized;
Vector3 NEWvector = Vector3.LerpUnclamped(REFvector, PQSvector, (float)(resizeBuildings / resize));
pqs.repositionRadial = NEWvector;
}

void City2Fixer(PQSCity2 pqs)
{
double groundLevel = body.pqsController.GetSurfaceHeight(pqs.PlanetRelativePosition) - body.Radius;
Expand Down
2 changes: 2 additions & 0 deletions [Source]/SigmaDimensions/SigmaDimensions.csproj
Expand Up @@ -32,6 +32,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AtmosphereTopLayer.cs" />
<Compile Include="PQSCityGroupsLoader.cs" />
<Compile Include="SigmaDebugLogger.cs" />
<Compile Include="SpaceCenterFixer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SigmaDimensions.cs" />
Expand Down

0 comments on commit fd943b8

Please sign in to comment.