Skip to content

Commit

Permalink
Update map data source; support localized resource conc limits
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Aug 15, 2020
1 parent 2e8e9f7 commit 9d54451
Showing 1 changed file with 11 additions and 34 deletions.
45 changes: 11 additions & 34 deletions SCANsat/SCAN_Map/SCANmap.cs
Expand Up @@ -575,6 +575,8 @@ private double fixUnscale(double value, int size)
private float customMin;
private float customMax;
private float customRange;
private float customResourceMin;
private float customResourceMax;
private bool useCustomRange;
private bool colorMap;
private bool terminator;
Expand All @@ -590,7 +592,6 @@ public void setBody(CelestialBody b)
{
SCANcontroller.controller.UnloadVisualMapTexture(body, mSource);
body = b;
data = SCANUtil.getData(body);
SCANcontroller.controller.loadOnDemandScaledSpace(body, mSource);
SCANcontroller.controller.LoadVisualMapTexture(body, mSource);
}
Expand All @@ -600,6 +601,8 @@ public void setBody(CelestialBody b)
SCANcontroller.controller.LoadVisualMapTexture(body, mSource);
}

data = SCANUtil.getData(body);

SCANcontroller.controller.loadPQS(body, mSource);
pqs = body.pqsController != null;
biomeMap = body.BiomeMap != null;
Expand All @@ -614,50 +617,21 @@ public void setBody(CelestialBody b)
}
}


if (SCANconfigLoader.GlobalResource)
{
if (resource != null)
resource.CurrentBodyConfig(body.bodyName);
}
}

private Texture2D readableTexture(Texture tex, Material mat, bool useMat)
{
if (tex == null)
return null;

Texture2D readable = new Texture2D(tex.width, tex.height);

var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB, 1);

if (useMat)
Graphics.Blit(tex, rt, mat);
else
Graphics.Blit(tex, rt);

RenderTexture.active = rt;

readable.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

RenderTexture.active = null;
RenderTexture.ReleaseTemporary(rt);

rt = null;

readable.Apply();

tex = null;

return readable;
}

public void setCustomRange(float min, float max)
public void setCustomRange(float min, float max, float rMin, float rMax)
{
useCustomRange = true;
customMin = min;
customMax = max;
customRange = max - min;
customResourceMin = rMin;
customResourceMax = rMax;
}

internal bool isMapComplete()
Expand Down Expand Up @@ -1169,7 +1143,10 @@ internal Texture2D getPartialMap(bool apply = true)
abundance = resourceCache[Mathf.RoundToInt(i * (resourceMapWidth / mapwidth)), Mathf.RoundToInt(mapstep * (resourceMapWidth / mapwidth))];
break;
}
baseColor = SCANuiUtil.resourceToColor32(baseColor, resource, abundance, data, lon, lat);
if (useCustomRange)
baseColor = SCANuiUtil.resourceToColor32(baseColor, resource, customResourceMin, customResourceMax, abundance, data, lon, lat);
else
baseColor = SCANuiUtil.resourceToColor32(baseColor, resource, resource.CurrentBody.MinValue, resource.CurrentBody.MaxValue, abundance, data, lon, lat);
}

if (terminator)
Expand Down

0 comments on commit 9d54451

Please sign in to comment.