aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs92
1 files changed, 47 insertions, 45 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
index c3c4935..d010a03 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
@@ -81,6 +81,11 @@ namespace OpenSim.Region.Terrain
81 /// </summary> 81 /// </summary>
82 public double minLower = 500.0; 82 public double minLower = 500.0;
83 83
84 /// <summary>
85 /// The last time the terrain was edited
86 /// </summary>
87 public DateTime lastEdit = DateTime.Now;
88
84 89
85 /// <summary> 90 /// <summary>
86 /// Whether or not the terrain has been modified since it was last saved and sent to the Physics engine. 91 /// Whether or not the terrain has been modified since it was last saved and sent to the Physics engine.
@@ -120,6 +125,16 @@ namespace OpenSim.Region.Terrain
120 return (tainted != 0); 125 return (tainted != 0);
121 } 126 }
122 127
128 public bool StillEditing()
129 {
130 TimeSpan gap = DateTime.Now - lastEdit;
131
132 if (gap.TotalSeconds <= 2.0)
133 return true;
134
135 return false;
136 }
137
123 public bool Tainted(int x, int y) 138 public bool Tainted(int x, int y)
124 { 139 {
125 return (heightmap.diff[x / 16, y / 16] != 0); 140 return (heightmap.diff[x / 16, y / 16] != 0);
@@ -197,6 +212,8 @@ namespace OpenSim.Region.Terrain
197 } 212 }
198 } 213 }
199 214
215 lastEdit = DateTime.Now;
216
200 return; 217 return;
201 } 218 }
202 219
@@ -1172,28 +1189,7 @@ namespace OpenSim.Region.Terrain
1172 { 1189 {
1173 try 1190 try
1174 { 1191 {
1175 Bitmap gradientmapLd = new Bitmap(gradientmap); 1192 Bitmap bmp = TerrainToBitmap(gradientmap);
1176
1177 int pallete = gradientmapLd.Height;
1178
1179 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
1180 Color[] colours = new Color[pallete];
1181
1182 for (int i = 0; i < pallete; i++)
1183 {
1184 colours[i] = gradientmapLd.GetPixel(0, i);
1185 }
1186
1187 Channel copy = heightmap.Copy();
1188 for (int y = 0; y < copy.h; y++)
1189 {
1190 for (int x = 0; x < copy.w; x++)
1191 {
1192 // 512 is the largest possible height before colours clamp
1193 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1));
1194 bmp.SetPixel(x, y, colours[colorindex]);
1195 }
1196 }
1197 1193
1198 bmp.Save(filename, ImageFormat.Png); 1194 bmp.Save(filename, ImageFormat.Png);
1199 } 1195 }
@@ -1212,30 +1208,8 @@ namespace OpenSim.Region.Terrain
1212 byte[] imageData = null; 1208 byte[] imageData = null;
1213 try 1209 try
1214 { 1210 {
1215 Bitmap gradientmapLd = new Bitmap(gradientmap); 1211 Bitmap bmp = TerrainToBitmap(gradientmap);
1216
1217 int pallete = gradientmapLd.Height;
1218
1219 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
1220 Color[] colours = new Color[pallete];
1221 1212
1222 for (int i = 0; i < pallete; i++)
1223 {
1224 colours[i] = gradientmapLd.GetPixel(0, i);
1225 }
1226
1227 Channel copy = heightmap.Copy();
1228 for (int y = 0; y < copy.h; y++)
1229 {
1230 for (int x = 0; x < copy.w; x++)
1231 {
1232 // 512 is the largest possible height before colours clamp
1233 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, copy.h - y) / 512.0), 0.0) * (pallete - 1));
1234 bmp.SetPixel(x, y, colours[colorindex]);
1235 }
1236 }
1237
1238 //bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
1239 imageData = OpenJPEG.EncodeFromImage(bmp, true ); 1213 imageData = OpenJPEG.EncodeFromImage(bmp, true );
1240 1214
1241 } 1215 }
@@ -1246,5 +1220,33 @@ namespace OpenSim.Region.Terrain
1246 1220
1247 return imageData; 1221 return imageData;
1248 } 1222 }
1223
1224 private Bitmap TerrainToBitmap(string gradientmap)
1225 {
1226 Bitmap gradientmapLd = new Bitmap(gradientmap);
1227
1228 int pallete = gradientmapLd.Height;
1229
1230 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
1231 Color[] colours = new Color[pallete];
1232
1233 for (int i = 0; i < pallete; i++)
1234 {
1235 colours[i] = gradientmapLd.GetPixel(0, i);
1236 }
1237
1238 Channel copy = heightmap.Copy();
1239 for (int y = 0; y < copy.h; y++)
1240 {
1241 for (int x = 0; x < copy.w; x++)
1242 {
1243 // 512 is the largest possible height before colours clamp
1244 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1));
1245 bmp.SetPixel(x, y, colours[colorindex]);
1246 }
1247 }
1248 return bmp;
1249 }
1250
1249 } 1251 }
1250} 1252}