From 738725431425c8f6767d43c1ba1bed449425f3da Mon Sep 17 00:00:00 2001 From: DMagic Date: Sun, 7 Jun 2015 23:08:54 -0400 Subject: [PATCH 01/15] version numbers --- SCANmechjeb/Properties/AssemblyInfo.cs | 6 +++--- SCANsat/Properties/AssemblyInfo.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SCANmechjeb/Properties/AssemblyInfo.cs b/SCANmechjeb/Properties/AssemblyInfo.cs index 3ae449b3c..0eaee800b 100644 --- a/SCANmechjeb/Properties/AssemblyInfo.cs +++ b/SCANmechjeb/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SCANsat/Properties/AssemblyInfo.cs b/SCANsat/Properties/AssemblyInfo.cs index 860401d5b..95cf6df85 100644 --- a/SCANsat/Properties/AssemblyInfo.cs +++ b/SCANsat/Properties/AssemblyInfo.cs @@ -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)] From b7b3f5d0a653e26a6cacede653e27e99f4f78a1e Mon Sep 17 00:00:00 2001 From: DMagic Date: Sun, 7 Jun 2015 23:09:14 -0400 Subject: [PATCH 02/15] Start resource settings menu in space center --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 1 + SCANsat/SCANcontroller.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index f6ac97e70..8c9c55680 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -116,6 +116,7 @@ private void closeBox(int id) Rect r = new Rect(WindowRect.width - 20, 1, 18, 18); if (GUI.Button(r, SCANcontroller.controller.closeBox, SCANskins.SCAN_closeButton)) { + removeControlLocks(); Visible = false; } } diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 47c37bb0f..c99efc6f7 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -785,10 +785,10 @@ private void Start() kscMap = gameObject.AddComponent(); settingsWindow = gameObject.AddComponent(); colorManager = gameObject.AddComponent(); + resourceSettings = gameObject.AddComponent(); if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) { resourceOverlay = gameObject.AddComponent(); - resourceSettings = gameObject.AddComponent(); } } catch (Exception e) From d2a4ccf3629009c8374ebc3c62eb2a17c080e291 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sun, 7 Jun 2015 23:09:22 -0400 Subject: [PATCH 03/15] comments --- SCANsat/SCANutil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 48e74adf1..f286614e0 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -155,19 +155,19 @@ public static bool instantResourceScanEnabled() } /// - /// Are the stock resource scanner functions disabled; prevents orbital resource surveys? + /// Are the stock resource scanner functions disabled? prevents orbital resource surveys /// /// Returns true if stock resource scanning is available public static bool stockResourceScanEnabled() { if (SCANcontroller.controller == null) - return true; + return false; return !SCANcontroller.controller.disableStockResource; } /// - /// Is the stock resource biome lock enabled; reduced resource abundace accuracy if enabled? + /// Is the stock resource biome lock enabled? reduced resource abundace accuracy if enabled /// /// Returns true if the biome lock is enabled public static bool resourceBiomeLockEnabled() From c61daa2f246f4e40806eeb6c066dcdaf2b316091 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sun, 7 Jun 2015 23:09:34 -0400 Subject: [PATCH 04/15] Get correct altitude --- SCANsat/SCAN_PartModules/SCANresourceDisplay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 7f5d5d721..e938485d1 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -155,7 +155,7 @@ private void FixedUpdate() return; } - if (vessel.altitude > MaxAbundanceAltitude) + if (ResourceUtilities.GetAltitude(vessel) > MaxAbundanceAltitude) { tooHigh = true; return; From 08263d18ecbe07d6fbd8b239f916889b82ca6963 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 9 Jun 2015 22:33:04 -0400 Subject: [PATCH 05/15] Only consider first biome of the same name --- SCANsat/SCAN_PartModules/SCANresourceDisplay.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index e938485d1..63bca4899 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -192,7 +192,8 @@ 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() From b64dec842c66c000c14e824ab58c9398e15dd61d Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:06:59 -0400 Subject: [PATCH 06/15] Add resource settings to toolbar menu --- SCANsat/SCAN_Toolbar/SCANtoolbar.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs index 8c56bb6a8..6e1b849eb 100644 --- a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs +++ b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs @@ -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) => { @@ -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; } From 5ca16b4c352d7b9ab7ab972204e149c362653198 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:07:09 -0400 Subject: [PATCH 07/15] Use new zoom map flag --- SCANsat/SCAN_UI/SCANzoomWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_UI/SCANzoomWindow.cs b/SCANsat/SCAN_UI/SCANzoomWindow.cs index 9e8a21f26..ef1e4a5c1 100644 --- a/SCANsat/SCAN_UI/SCANzoomWindow.cs +++ b/SCANsat/SCAN_UI/SCANzoomWindow.cs @@ -81,7 +81,7 @@ private void Startup() } if (spotmap == null) { - spotmap = new SCANmap(); + spotmap = new SCANmap(b, false, true); spotmap.setSize(320, 240); } From b50aa387898c13a4bf0c7478b7ed6041a597d322 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:07:19 -0400 Subject: [PATCH 08/15] formatting --- SCANsat/SCAN_PartModules/SCANresourceScanner.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs index 5010b4540..9c0d9e7a3 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs @@ -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) { @@ -116,9 +116,6 @@ public void Update() forceStart = false; } - if (SCANcontroller.controller == null) - return; - if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) updateEvents(); else From 82d407c9169da9b6b3630c202b746fc5b815c20a Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:07:34 -0400 Subject: [PATCH 09/15] clarify avg. displays --- SCANsat/SCAN_PartModules/SCANresourceDisplay.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 63bca4899..2b60ca773 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -90,7 +90,7 @@ private void Update() if (SCANcontroller.controller == null) return; - if (forceStart && SCANcontroller.controller != null) + if (forceStart) { if (stockScanners != null && SCANcontroller.controller.disableStockResource) { @@ -136,9 +136,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."; } } From aad5e0438fa6faa9ac97c7feae228d2bc7181bf1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:07:54 -0400 Subject: [PATCH 10/15] Fix zoom map resource overlays --- SCANsat/SCAN_Map/SCANmap.cs | 114 ++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 1d52c0bb5..de33399e2 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -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) { @@ -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; @@ -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; @@ -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; } @@ -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 @@ -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 } From 7e4cce5cd3e3b4587affb4776b64224aeae1a8bc Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 15:29:06 -0400 Subject: [PATCH 11/15] Fix memory usage problems with overlays --- SCANsat/SCAN_UI/SCANoverlayController.cs | 7 +++- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 44 +++++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index 70b941616..ac3a44c70 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -25,6 +25,9 @@ class SCANoverlayController : SCAN_MBW private Texture2D mapOverlay; private Texture2D biomeOverlay; + private Color32[] resourcePixels; + private Color32[] biomePixels; + private float[,] abundanceValues; private int mapHeight = 256; private float transparency = 0f; private int interpolationScale = 8; @@ -252,9 +255,9 @@ public void refreshMap(float t, int height, int interp) private void refreshMap() { if (biomeMode) - body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, data, transparency, mapHeight * 2)); + body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, biomePixels, data, transparency, mapHeight * 2)); else - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, mapHeight, data, currentResource, interpolationScale, transparency)); + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, resourcePixels, abundanceValues, mapHeight, data, currentResource, interpolationScale, transparency)); } private void setBody(CelestialBody B) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index baa146f24..6f6e25c33 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1375,16 +1375,24 @@ private static double fixLon(double Lon) return Lon; } - internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) + internal static Texture2D drawResourceTexture(Texture2D map, Color32[] pix, float[,] values, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { int width = height * 2; - float[,] abundanceValues = new float[width, height]; - Color32[] pix = new Color32[width * height]; float scale = height / 180f; - if (map == null || map.height != height) + if (map == null || pix == null || values == null || map.height != height) { map = new Texture2D(width, height, TextureFormat.ARGB32, true); + pix = new Color32[width * height]; + values = new float[width, height]; + } + + for (int i = 0; i < width; i++ ) + { + for (int j = 0; j < height; j++) + { + values[i, j] = 0; + } } System.Random r = new System.Random(ResourceScenario.Instance.gameSettings.Seed); @@ -1396,17 +1404,17 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat double lon = fixLon(i / scale); double lat = (j / scale) - 90; - abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body, SCANcontroller.controller.resourceBiomeLock) * 100; + values[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body, SCANcontroller.controller.resourceBiomeLock) * 100; - pix[j * width + i] = resourceToColor32(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); + pix[j * width + i] = resourceToColor32(palette.Clear, resource, values[i, j], data, lon, lat, transparency); } } for (int i = stepScale / 2; i >= 1; i /= 2) { - interpolate(pix, abundanceValues, height, i, i, i, resource, transparency, data, r); - interpolate(pix, abundanceValues, height, 0, i, i, resource, transparency, data, r); - interpolate(pix, abundanceValues, height, i, 0, i, resource, transparency, data, r); + interpolate(pix, values, height, i, i, i, resource, transparency, data, r); + interpolate(pix, values, height, 0, i, i, resource, transparency, data, r); + interpolate(pix, values, height, i, 0, i, resource, transparency, data, r); } map.SetPixels32(pix); @@ -1415,19 +1423,19 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat return map; } - internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float transparency, int height = 256, bool useStock = false, bool whiteBorder = false) + internal static Texture2D drawBiomeMap(Texture2D map, Color32[] pix, SCANdata data, float transparency, int height = 256, bool useStock = false, bool whiteBorder = false) { if (!useStock && !whiteBorder) - return drawBiomeMap(map, data, transparency, height); + return drawBiomeMap(map, pix, data, transparency, height); int width = height * 2; float scale = (width * 1f) / 360f; double[] mapline = new double[width]; - Color32[] pix = new Color32[height * width]; - if (map == null || map.height != height) + if (map == null || pix == null || map.height != height) { map = new Texture2D(width, height, TextureFormat.ARGB32, true); + pix = new Color32[width * height]; } for (int j = 0; j < height; j++) @@ -1466,17 +1474,17 @@ internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float trans return map; } - private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t, int h) + private static Texture2D drawBiomeMap(Texture2D m, Color32[] p, SCANdata d, float t, int h) { if (d.Body.BiomeMap == null) return null; - if (m == null) + if (m == null || p == null || m.height != h) { m = new Texture2D(h * 2, h, TextureFormat.RGBA32, true); + p = new Color32[m.width * m.height]; } - Color32[] pix = new Color32[m.width * m.height]; float scale = m.width / 360f; for (int j = 0; j < m.height; j++) @@ -1491,11 +1499,11 @@ private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t, int h) if (SCANUtil.isCovered(lon, lat, d, SCANtype.Biome)) c = (Color32)SCANUtil.getBiome(d.Body, lon, lat).mapColor;//, palette.clear, SCANcontroller.controller.biomeTransparency / 100); - pix[j *m.width + i] = c; + p[j *m.width + i] = c; } } - m.SetPixels32(pix); + m.SetPixels32(p); m.Apply(); return m; From 12876dcba3898513f7f2c7de996b9dc9706eec18 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 19:59:35 -0400 Subject: [PATCH 12/15] .version --- SCANassets/SCANsat.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANassets/SCANsat.version b/SCANassets/SCANsat.version index b350f5838..a13908dd1 100644 --- a/SCANassets/SCANsat.version +++ b/SCANassets/SCANsat.version @@ -11,7 +11,7 @@ "MAJOR":1, "MINOR":1, "PATCH":3, - "BUILD":1 + "BUILD":2 }, "KSP_VERSION":{ "MAJOR":1, From 0fdabe33454dc9aa4afec9dc41a2c173c6195811 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 19:59:42 -0400 Subject: [PATCH 13/15] changes --- SCANsat/CHANGELOG.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SCANsat/CHANGELOG.txt b/SCANsat/CHANGELOG.txt index 510511872..9c9566354 100644 --- a/SCANsat/CHANGELOG.txt +++ b/SCANsat/CHANGELOG.txt @@ -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 ------------------------ From 66bde392556c9bd45a7494fa8d09f3ae8d422460 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 20:00:00 -0400 Subject: [PATCH 14/15] Use reference objects; fix memory problems --- SCANsat/SCAN_UI/SCANoverlayController.cs | 4 ++-- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index ac3a44c70..b922ebe0b 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -255,9 +255,9 @@ public void refreshMap(float t, int height, int interp) private void refreshMap() { if (biomeMode) - body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, biomePixels, data, transparency, mapHeight * 2)); + body.SetResourceMap(SCANuiUtil.drawBiomeMap(ref biomeOverlay, ref biomePixels, data, transparency, mapHeight * 2)); else - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, resourcePixels, abundanceValues, mapHeight, data, currentResource, interpolationScale, transparency)); + body.SetResourceMap(SCANuiUtil.drawResourceTexture(ref mapOverlay, ref resourcePixels, ref abundanceValues, mapHeight, data, currentResource, interpolationScale, transparency)); } private void setBody(CelestialBody B) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 6f6e25c33..d93b65072 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1375,7 +1375,7 @@ private static double fixLon(double Lon) return Lon; } - internal static Texture2D drawResourceTexture(Texture2D map, Color32[] pix, float[,] values, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) + internal static Texture2D drawResourceTexture(ref Texture2D map, ref Color32[] pix, ref float[,] values, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { int width = height * 2; float scale = height / 180f; @@ -1423,10 +1423,10 @@ internal static Texture2D drawResourceTexture(Texture2D map, Color32[] pix, floa return map; } - internal static Texture2D drawBiomeMap(Texture2D map, Color32[] pix, SCANdata data, float transparency, int height = 256, bool useStock = false, bool whiteBorder = false) + internal static Texture2D drawBiomeMap(ref Texture2D map, ref Color32[] pix, SCANdata data, float transparency, int height = 256, bool useStock = false, bool whiteBorder = false) { if (!useStock && !whiteBorder) - return drawBiomeMap(map, pix, data, transparency, height); + return drawBiomeMap(ref map, ref pix, data, transparency, height); int width = height * 2; float scale = (width * 1f) / 360f; @@ -1474,7 +1474,7 @@ internal static Texture2D drawBiomeMap(Texture2D map, Color32[] pix, SCANdata da return map; } - private static Texture2D drawBiomeMap(Texture2D m, Color32[] p, SCANdata d, float t, int h) + private static Texture2D drawBiomeMap(ref Texture2D m, ref Color32[] p, SCANdata d, float t, int h) { if (d.Body.BiomeMap == null) return null; From 157b1fcd704d925e8c666c1df549f4cea1a58873 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 11 Jun 2015 20:00:33 -0400 Subject: [PATCH 15/15] Activate and deactivate resource scanners properly --- .../SCAN_PartModules/SCANresourceDisplay.cs | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 2b60ca773..2d3d04161 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -22,11 +22,12 @@ class SCANresourceDisplay : PartModule, IAnimatedModule private float abundanceValue; private List stockScanners; + private ModuleAnimationGroup animGroup; private Dictionary 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) @@ -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()); @@ -54,6 +59,11 @@ private List findScanners() return part.FindModulesImplementing().Where(r => r.ScannerType == 0 && r.ResourceName == ResourceName).ToList(); } + private ModuleAnimationGroup findAnimator() + { + return part.FindModulesImplementing().FirstOrDefault(); + } + private void setupFields(ModuleResourceScanner m) { if (m != null) @@ -90,15 +100,11 @@ private void Update() if (SCANcontroller.controller == null) return; - if (forceStart) + 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) @@ -196,10 +202,9 @@ private void refreshAbundance(int bodyID) 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) { @@ -208,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;