30 using System.Reflection;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Interfaces;
35 using OpenSim.Region.Framework.Scenes;
37 namespace OpenSim.
Region.CoreModules.
World.LegacyMap
41 private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95);
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private static readonly
string LogHeader =
"[SHADED MAPTILE RENDERER]";
46 private Scene m_scene;
57 m_log.DebugFormat(
"{0} Generating Maptile Step 1: Terrain", LogHeader);
58 int tc = Environment.TickCount;
62 if (mapbmp.Width != hm.
Width || mapbmp.Height != hm.
Height)
64 m_log.ErrorFormat(
"{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>",
65 LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
68 bool ShadowDebugContinue =
true;
70 bool terraincorruptedwarningsaid =
false;
74 for (
int x = 0; x < hm.Width; x++)
76 for (
int y = 0; y < hm.Height; y++)
78 float hmval = (float)hm[x, y];
86 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
88 for (
int x = 0; x < hm.Width; x++)
90 for (
int y = 0; y < hm.Height; y++)
93 int yr = ((int)hm.
Height - 1) - y;
95 float heightvalue = (float)hm[x, y];
97 if (heightvalue > waterHeight)
103 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
105 else if (heightvalue > 255f)
107 else if (heightvalue < 0f)
110 Color color = Color.FromArgb((int)heightvalue, 100, (
int)heightvalue);
112 mapbmp.SetPixel(x, yr, color);
120 if (x < (hm.
Width - 1) && yr < (hm.Height - 1))
122 float hfvalue = (float)hm[x, y];
123 float hfvaluecompare = 0f;
125 if ((x + 1 < hm.
Width) && (y + 1 < hm.Height))
127 hfvaluecompare = (float)hm[x + 1, y + 1];
129 if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue))
132 if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare))
135 float hfdiff = hfvalue - hfvaluecompare;
138 int hfdiffihighlight = 0;
139 float highlightfactor = 0.18f;
144 hfdiffi = Math.Abs((int)(hfdiff * 4.5f)) + 1;
145 if (hfdiff % 1f != 0)
148 hfdiffi = hfdiffi + Math.Abs((int)((hfdiff % 1f) * 5f) - 1);
151 hfdiffihighlight = Math.Abs((int)((hfdiff * highlightfactor) * 4.5f)) + 1;
152 if (hfdiff % 1f != 0)
155 hfdiffihighlight = hfdiffihighlight + Math.Abs((int)(((hfdiff * highlightfactor) % 1f) * 5f) - 1);
158 catch (OverflowException)
160 m_log.Debug(
"[MAPTILE]: Shadow failed at value: " + hfdiff.ToString());
161 ShadowDebugContinue =
false;
171 if (ShadowDebugContinue)
176 color = Color.FromArgb((r + hfdiffihighlight < 255) ? r + hfdiffihighlight : 255,
177 (g + hfdiffihighlight < 255) ? g + hfdiffihighlight : 255,
178 (b + hfdiffihighlight < 255) ? b + hfdiffihighlight : 255);
181 else if (hfdiff < -0.3f)
188 if (ShadowDebugContinue)
190 if ((x - 1 > 0) && (yr + 1 < hm.
Height))
192 color = mapbmp.GetPixel(x - 1, yr + 1);
196 color = Color.FromArgb((r - hfdiffi > 0) ? r - hfdiffi : 0,
197 (g - hfdiffi > 0) ? g - hfdiffi : 0,
198 (b - hfdiffi > 0) ? b - hfdiffi : 0);
200 mapbmp.SetPixel(x-1, yr+1, color);
206 catch (ArgumentException)
208 if (!terraincorruptedwarningsaid)
210 m_log.WarnFormat(
"[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName);
211 terraincorruptedwarningsaid =
true;
214 mapbmp.SetPixel(x, yr, color);
222 heightvalue = waterHeight - heightvalue;
223 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
225 else if (heightvalue > 19f)
227 else if (heightvalue < 0f)
230 heightvalue = 100f - (heightvalue * 100f) / 19f;
234 mapbmp.SetPixel(x, yr, WATER_COLOR);
236 catch (ArgumentException)
238 if (!terraincorruptedwarningsaid)
240 m_log.WarnFormat(
"[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName);
241 terraincorruptedwarningsaid =
true;
243 Color black = Color.Black;
244 mapbmp.SetPixel(x, (hm.Width - y) - 1, black);
250 m_log.Debug(
"[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) +
" ms");
void TerrainToBitmap(Bitmap mapbmp)
void Initialise(Scene scene, IConfigSource config)