Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into 69-cam…
Browse files Browse the repository at this point in the history
…era-endpoint
  • Loading branch information
Thomas Cannon committed Mar 23, 2017
2 parents 9aaabf6 + 48691aa commit 30e6ea7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 37 deletions.
7 changes: 1 addition & 6 deletions Telemachus/Telemachus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="Assembly-CSharp">
<HintPath>..\ksp-telemachus-dev\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="KSPUtil, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ksp-telemachus-dev\KSP_Data\Managed\KSPUtil.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Expand Down
6 changes: 3 additions & 3 deletions Telemachus/src/DataLinkFormatters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override object prepareForSerialization(object input)
{
return SumResources((List<PartResource>)input,
x => x.amount,
x => x.part.inStageIndex == StageManager.CurrentStage);
x => x.part.inStageIndex == x.part.vessel.currentStage);
}
}

Expand All @@ -163,7 +163,7 @@ public class ActiveResourceListJSONFormatter : ResourceListJSONFormatter
{
public override object prepareForSerialization(object input)
{
return SumResources((List<Vessel.ActiveResource>)input,
return SumResources((List<SimplifiedResource>)input,
x => x.amount);
}
}
Expand All @@ -172,7 +172,7 @@ public class ActiveResourceTotalListJSONFormatter : ResourceListJSONFormatter
{
public override object prepareForSerialization(object input)
{
return SumResources((List<Vessel.ActiveResource>)input,
return SumResources((List<SimplifiedResource>)input,
x => x.maxAmount);
}
}
Expand Down
92 changes: 65 additions & 27 deletions Telemachus/src/DataLinkHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections;
using UnityEngine;
using KSP.UI.Screens;
using KSP.UI.Util;

namespace Telemachus
{
Expand Down Expand Up @@ -1525,23 +1526,23 @@ public NavBallDataLinkHandler(FormatterProvider formatters)
registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return result.eulerAngles.y;
},
"n.heading2", "Heading", formatters.Default, APIEntry.UnitType.DEG));

registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return (result.eulerAngles.x > 180) ? (360.0 - result.eulerAngles.x) : -result.eulerAngles.x;
},
"n.pitch2", "Pitch", formatters.Default, APIEntry.UnitType.DEG));

registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return (result.eulerAngles.z > 180) ?
(result.eulerAngles.z - 360.0) : result.eulerAngles.z;
},
Expand All @@ -1550,23 +1551,23 @@ public NavBallDataLinkHandler(FormatterProvider formatters)
registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return result.eulerAngles.y;
},
"n.rawheading2", "Raw Heading", formatters.Default, APIEntry.UnitType.DEG));

registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return result.eulerAngles.x;
},
"n.rawpitch2", "Raw Pitch", formatters.Default, APIEntry.UnitType.DEG));

registerAPI(new PlotableAPIEntry(
dataSources =>
{
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.findWorldCenterOfMass());
Quaternion result = updateHeadingPitchRollField(dataSources.vessel, dataSources.vessel.CoM);
return result.eulerAngles.z;
},
"n.rawroll2", "Raw Roll", formatters.Default, APIEntry.UnitType.DEG));
Expand Down Expand Up @@ -1967,6 +1968,19 @@ public ResourceDataLinkHandler(VesselChangeDetector vesselChangeDetector, Format
dataSources => { return getsResourceValues(dataSources); },
"r.resourceMax", "Max Resource Information [string resource type]",
formatters.MaxResourceList, APIEntry.UnitType.UNITLESS));
registerAPI(new APIEntry(
dataSources => {
List<String> names = new List<String>();
PartResourceDefinitionList resourceDefinitionList = PartResourceLibrary.Instance.resourceDefinitions;
foreach (PartResourceDefinition resourceDefinition in resourceDefinitionList)
{
names.Add(resourceDefinition.name);
}
return names;
},
"r.resourceNameList", "List of resource names",
formatters.StringArray, APIEntry.UnitType.UNITLESS));
}

#endregion
Expand All @@ -1979,7 +1993,7 @@ protected List<PartResource> getsResourceValues(DataSources datasources)
return resourceCache.get(datasources);
}

protected List<Vessel.ActiveResource> getsActiveResourceValues(DataSources datasources)
protected List<SimplifiedResource> getsActiveResourceValues(DataSources datasources)
{
activeResourceCache.vessel = datasources.vessel;
return activeResourceCache.get(datasources);
Expand Down Expand Up @@ -2025,7 +2039,7 @@ public Vessel vessel

public List<T> get(DataSources dataSources)
{
string ID = dataSources.args[0];
string ID = dataSources.args[0].ToLowerInvariant();
List<T> avail = null, ret = null;

lock (cacheLock)
Expand All @@ -2050,7 +2064,19 @@ public List<T> get(DataSources dataSources)
#endregion
}

public class ActiveResourceCache : ModuleCache<Vessel.ActiveResource>
public class SimplifiedResource
{
public double amount { get; set; }
public double maxAmount { get; set; }

public SimplifiedResource(double amount, double maxAmount)
{
this.amount = amount;
this.maxAmount = maxAmount;
}
}

public class ActiveResourceCache : ModuleCache<SimplifiedResource>
{
#region ModuleCache

Expand All @@ -2075,23 +2101,34 @@ protected override void refresh(Vessel vessel)
try
{
partModules.Clear();

foreach (Part part in vessel.parts)
HashSet<Part> activeParts = new HashSet<Part>();
foreach(Part part in vessel.GetActiveParts())
{
if (part.Resources.Count > 0)
if (part.inverseStage == vessel.currentStage)
{
foreach (Vessel.ActiveResource resource in vessel.GetActiveResources())
{
List<Vessel.ActiveResource> list = null;
if (list == null)
{
list = new List<Vessel.ActiveResource>();
partModules[resource.info.name] = list;
}
activeParts.Add(part);
activeParts.UnionWith(part.crossfeedPartSet.GetParts());
}
}

list.Add(resource);
}
PartSet activePartSet = new PartSet(activeParts);
PartResourceDefinitionList resourceDefinitionList = PartResourceLibrary.Instance.resourceDefinitions;

foreach(PartResourceDefinition resourceDefinition in resourceDefinitionList)
{
String key = resourceDefinition.name.ToString().ToLowerInvariant();
double amount = 0;
double maxAmount = 0;
bool pulling = true;

activePartSet.GetConnectedResourceTotals(resourceDefinition.id, out amount, out maxAmount, pulling);

if(!partModules.ContainsKey(key)){
partModules[key] = new List<SimplifiedResource>();
}

partModules[key].Add(new SimplifiedResource(amount, maxAmount));
PluginLogger.debug("SIZE OF " + key + " " + partModules[key].Count + " " + amount );
}
}
catch (Exception e)
Expand Down Expand Up @@ -2136,12 +2173,13 @@ protected override void refresh(Vessel vessel)

foreach (PartResource partResource in part.Resources)
{
String key = partResource.resourceName.ToLowerInvariant();
List<PartResource> list = null;
partModules.TryGetValue(partResource.resourceName, out list);
partModules.TryGetValue(key, out list);
if (list == null)
{
list = new List<PartResource>();
partModules[partResource.resourceName] = list;
partModules[key] = list;

}

Expand Down Expand Up @@ -2191,11 +2229,11 @@ protected override void refresh(Vessel vessel)
{
foreach (var module in part.Modules.OfType<ModuleEnviroSensor>())
{
if (!partModules.ContainsKey(module.sensorType))
if (!partModules.ContainsKey(module.sensorType.ToString()))
{
partModules[module.sensorType] = new List<ModuleEnviroSensor>();
partModules[module.sensorType.ToString()] = new List<ModuleEnviroSensor>();
}
partModules[module.sensorType].Add(module);
partModules[module.sensorType.ToString()].Add(module);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Readme

[Building](https://github.com/richardbunt/Telemachus/wiki/Building)

[KSP Forum Thread](http://forum.kerbalspaceprogram.com/threads/24594)
[KSP Forum Thread](http://forum.kerbalspaceprogram.com/index.php?/topic/144482-113-2016-07-24-telemachus-telemetry-and-flight-control-in-the-web-browser/)

[Installation](https://github.com/richardbunt/Telemachus/wiki/Installation)

Expand Down

0 comments on commit 30e6ea7

Please sign in to comment.