Skip to content

Commit

Permalink
Merge pull request #149 from DMagic1/dev
Browse files Browse the repository at this point in the history
version 13.2
  • Loading branch information
DMagic1 committed Jun 12, 2015
2 parents dbacc2f + 157b1fc commit c96ebb5
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 105 deletions.
2 changes: 1 addition & 1 deletion SCANassets/SCANsat.version
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"MAJOR":1,
"MINOR":1,
"PATCH":3,
"BUILD":1
"BUILD":2
},
"KSP_VERSION":{
"MAJOR":1,
Expand Down
6 changes: 3 additions & 3 deletions SCANmechjeb/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyInformationalVersion ("v13.1")]
[assembly: AssemblyVersion("1.3.2.0")]
[assembly: AssemblyFileVersion("1.3.2.0")]
[assembly: AssemblyInformationalVersion ("v13.2")]

[assembly: KSPAssembly ("SCANmechjeb", 0, 3)]
[assembly: KSPAssemblyDependency ("SCANsat", 1, 3)]
Expand Down
15 changes: 15 additions & 0 deletions SCANsat/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Version 13.2 - 2015-6-11
------------------------

- Fix planetary overlay memory usage

- Make resource settings window accessible in the Space Center scene and from the toolbar menu

- Fixes for resource abundance scanners
- Correctly calculate height above terrain
- Right-click display fields should activate and deactivate properly

- Fix zoom map resource overlays near the edges of the map and when using polar projection

- Fix Tylo biome scanning bug

Version 13.1 - 2015-6-6
------------------------

Expand Down
6 changes: 3 additions & 3 deletions SCANsat/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.3.1.0")]
[assembly: AssemblyFileVersion ("1.3.1.0")]
[assembly: AssemblyInformationalVersion ("v13.1")]
[assembly: AssemblyVersion ("1.3.2.0")]
[assembly: AssemblyFileVersion ("1.3.2.0")]
[assembly: AssemblyInformationalVersion ("v13.2")]

[assembly: KSPAssembly ("SCANsat", 1, 3)]

Expand Down
114 changes: 69 additions & 45 deletions SCANsat/SCAN_Map/SCANmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ namespace SCANsat.SCAN_Map
{
public class SCANmap
{
internal SCANmap(CelestialBody Body, bool Cache)
internal SCANmap(CelestialBody Body, bool Cache, bool zoomMap = false)
{
body = Body;
pqs = body.pqsController != null;
biomeMap = body.BiomeMap != null;
zoom = zoomMap;
data = SCANUtil.getData(body);
if (data == null)
{
Expand Down Expand Up @@ -412,6 +413,7 @@ private double unScaleLongitude(double lon)
private double unScaleLongitude(double lon, double scale)
{
lon -= lon_offset;
lon = SCANUtil.fixLonShift(lon);
lon += 180;
lon *= scale;
return lon;
Expand All @@ -428,6 +430,7 @@ private double fixUnscale(double value, int size)

/* MAP: internal state */
private mapType mType;
private bool zoom;
private Texture2D map; // refs above: 214,215,216,232, below, and JSISCANsatRPM.
private CelestialBody body; // all refs are below
private SCANresourceGlobal resource;
Expand Down Expand Up @@ -578,16 +581,7 @@ internal Texture2D getPartialMap()
}
else
{
for (int j = 0; j < resourceMapHeight; j += resourceInterpolation)
{
for (int i = 0; i < resourceMapWidth; i += resourceInterpolation)
{
double rLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset;
double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset;

resourceCache[i, j] = SCANUtil.ResourceOverlay(rLat, rLon, resource.Name, body, SCANcontroller.controller.resourceBiomeLock) * 100f;
}
}
generateResourceCache();
mapstep++;
return map;
}
Expand Down Expand Up @@ -791,40 +785,27 @@ internal Texture2D getPartialMap()
if (resourceOn)
{
float abundance = 0;
double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapHeight);
double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapWidth);

//switch (projection)
//{
// case MapProjection.Polar:
// {
// if ((lat <= 6 && lat >= 0) || (lat >= -6 && lat <=0))
// {

// }
// //else if (lat >= 87 || lat <= -87)
// //{

// //}
// else
// {
abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)];
// }
// break;
// }
// default:
// {
// if (lat <= -85 || lat >= 85)
// {

// }
// else
// {
// abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)];
// }
// break;
// }
//}
switch (projection)
{
case MapProjection.Rectangular:
{
abundance = getResoureCache(lo, la);
break;
}
case MapProjection.KavrayskiyVII:
{
abundance = getResoureCache(lon, lat);
break;
}
case MapProjection.Polar:
{
if (zoom)
abundance = resourceCache[Mathf.RoundToInt(i * (resourceMapWidth / mapwidth)), Mathf.RoundToInt(mapstep * (resourceMapWidth / mapwidth))];
else
abundance = getResoureCache(lon, lat);
break;
}
}
pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, abundance, data, lon, lat);
}
else
Expand Down Expand Up @@ -883,6 +864,49 @@ private float terrainElevation(double Lon, double Lat, SCANdata Data, out int Sc
return elevation;
}

private void generateResourceCache()
{
for (int j = 0; j < resourceMapHeight; j += resourceInterpolation)
{
for (int i = 0; i < resourceMapWidth; i += resourceInterpolation)
{
Vector2d coords;
if (zoom && projection == MapProjection.Polar)
{
double rLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset;
double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset;

double la = rLat, lo = rLon;
rLat = unprojectLatitude(lo, la);
rLon = unprojectLongitude(lo, la);

if (double.IsNaN(rLat) || double.IsNaN(rLon) || rLat < -90 || rLat > 90 || rLon < -180 || rLon > 180)
{
resourceCache[i, j] = 0;
continue;
}

coords = new Vector2d(rLon, rLat);
}
else
{
double rLon = SCANUtil.fixLonShift((i * 1.0f / resourceMapScale) - 180f + lon_offset);
double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset;
coords = SCANUtil.fixRetardCoordinates(new Vector2d(rLon, rLat));
}

resourceCache[i, j] = SCANUtil.ResourceOverlay(coords.y, coords.x, resource.Name, body, SCANcontroller.controller.resourceBiomeLock) * 100f;
}
}
}

private float getResoureCache(double Lon, double Lat)
{
double resourceLat = fixUnscale(unScaleLatitude(Lat, resourceMapScale), resourceMapHeight);
double resourceLon = fixUnscale(unScaleLongitude(Lon, resourceMapScale), resourceMapWidth);
return resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)];
}

#endregion

}
Expand Down
63 changes: 41 additions & 22 deletions SCANsat/SCAN_PartModules/SCANresourceDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class SCANresourceDisplay : PartModule, IAnimatedModule
private float abundanceValue;

private List<ModuleResourceScanner> stockScanners;
private ModuleAnimationGroup animGroup;
private Dictionary<string, ResourceCache.AbundanceSummary> abundanceSummary;
private CelestialBody body;
private bool tooHigh;
private bool fuzzy;
private bool forceStart;
private bool refreshState;
private bool activated;

public override void OnStart(PartModule.StartState state)
Expand All @@ -37,11 +38,15 @@ public override void OnStart(PartModule.StartState state)
GameEvents.onVesselSOIChanged.Add(onSOIChange);

part.force_activate();
this.enabled = true;
this.isEnabled = true;
activated = true;
forceStart = true;
refreshState = true;

stockScanners = findScanners();
animGroup = findAnimator();

if (animGroup == null || animGroup.isDeployed)
enableConnectedScanners();

setupFields(stockScanners.FirstOrDefault());

Expand All @@ -54,6 +59,11 @@ private List<ModuleResourceScanner> findScanners()
return part.FindModulesImplementing<ModuleResourceScanner>().Where(r => r.ScannerType == 0 && r.ResourceName == ResourceName).ToList();
}

private ModuleAnimationGroup findAnimator()
{
return part.FindModulesImplementing<ModuleAnimationGroup>().FirstOrDefault();
}

private void setupFields(ModuleResourceScanner m)
{
if (m != null)
Expand Down Expand Up @@ -90,15 +100,11 @@ private void Update()
if (SCANcontroller.controller == null)
return;

if (forceStart && SCANcontroller.controller != null)
if (refreshState)
{
if (stockScanners != null && SCANcontroller.controller.disableStockResource)
{
foreach (ModuleResourceScanner m in stockScanners)
{
m.DisableModule();
}
}
if (SCANcontroller.controller.disableStockResource)
disableConnectedScanners();
refreshState = false;
}

if (!SCANcontroller.controller.disableStockResource)
Expand Down Expand Up @@ -136,9 +142,9 @@ private void Update()
{
float biomeAbundance = abundanceSummary.ContainsKey(biome) ? abundanceSummary[biome].Abundance : 0f;
if (fuzzy)
abundanceField = biomeAbundance.ToString("P0");
abundanceField = biomeAbundance.ToString("P0") + "avg.";
else
abundanceField = biomeAbundance.ToString("P2");
abundanceField = biomeAbundance.ToString("P2") + "avg.";
}
}

Expand All @@ -155,7 +161,7 @@ private void FixedUpdate()
return;
}

if (vessel.altitude > MaxAbundanceAltitude)
if (ResourceUtilities.GetAltitude(vessel) > MaxAbundanceAltitude)
{
tooHigh = true;
return;
Expand Down Expand Up @@ -192,13 +198,13 @@ private void refreshAbundance(int bodyID)

abundanceSummary = ResourceCache.Instance.AbundanceCache.
Where(a => a.ResourceName == ResourceName && a.HarvestType == HarvestTypes.Planetary && a.BodyId == bodyID).
ToDictionary(a => a.BiomeName, a => a);
GroupBy(a => a.BiomeName).
ToDictionary(b => b.Key, b => b.First());
}

public void EnableModule()
private void disableConnectedScanners()
{
activated = true;
if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource)
if (stockScanners != null)
{
foreach (ModuleResourceScanner m in stockScanners)
{
Expand All @@ -207,18 +213,31 @@ public void EnableModule()
}
}

public void DisableModule()
private void enableConnectedScanners()
{
activated = false;
if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource)
if (stockScanners != null)
{
foreach (ModuleResourceScanner m in stockScanners)
{
m.DisableModule();
m.EnableModule();
}
}
}

public void EnableModule()
{
activated = true;
if (SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource)
disableConnectedScanners();
}

public void DisableModule()
{
activated = false;
if (SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource)
disableConnectedScanners();
}

public bool ModuleIsActive()
{
return activated;
Expand Down
9 changes: 3 additions & 6 deletions SCANsat/SCAN_PartModules/SCANresourceScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public void Update()
return;
}

if (!HighLogic.LoadedSceneIsFlight)
if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
return;

if (!FlightGlobals.ready)
if (SCANcontroller.controller == null)
return;

if (forceStart && SCANcontroller.controller != null)
if (forceStart)
{
if (SCANcontroller.controller.disableStockResource)
{
Expand All @@ -116,9 +116,6 @@ public void Update()
forceStart = false;
}

if (SCANcontroller.controller == null)
return;

if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource)
updateEvents();
else
Expand Down
5 changes: 5 additions & 0 deletions SCANsat/SCAN_Toolbar/SCANtoolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void createMenu(IButton menu)
IButton settings = list.AddOption("Settings");
IButton color = list.AddOption("Color Options");
IButton resource = list.AddOption("Planetary Overlay");
IButton resourceSettings = list.AddOption("Resource Settings");

smallMap.OnClick += (e2) =>
{
Expand Down Expand Up @@ -149,6 +150,10 @@ private void createMenu(IButton menu)
{
SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible;
};
resourceSettings.OnClick += (e2) =>
{
SCANcontroller.controller.resourceSettings.Visible = !SCANcontroller.controller.resourceSettings.Visible;
};
list.OnAnyOptionClicked += () => destroyMenu(menu);
menu.Drawable = list;
}
Expand Down
Loading

0 comments on commit c96ebb5

Please sign in to comment.