From 569ba9eb9acb9f024060a41ee4188a11aafa3fa7 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Tue, 25 Sep 2007 11:48:43 +0000 Subject: Terrain: * Attempted fix for lag/pause when doing lots of updates. * Some naming fixes to libTerrain. * Refactored terrain bitmap generation into a common call for both world map and export. General: * Switched some calls to Console.WriteLine to use MainLog.Warn/Verbose/Notice. --- .../Region/Terrain.BasicTerrain/TerrainEngine.cs | 92 +++++++++++----------- 1 file changed, 47 insertions(+), 45 deletions(-) (limited to 'OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs') 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 /// public double minLower = 500.0; + /// + /// The last time the terrain was edited + /// + public DateTime lastEdit = DateTime.Now; + /// /// 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 return (tainted != 0); } + public bool StillEditing() + { + TimeSpan gap = DateTime.Now - lastEdit; + + if (gap.TotalSeconds <= 2.0) + return true; + + return false; + } + public bool Tainted(int x, int y) { return (heightmap.diff[x / 16, y / 16] != 0); @@ -197,6 +212,8 @@ namespace OpenSim.Region.Terrain } } + lastEdit = DateTime.Now; + return; } @@ -1172,28 +1189,7 @@ namespace OpenSim.Region.Terrain { try { - Bitmap gradientmapLd = new Bitmap(gradientmap); - - int pallete = gradientmapLd.Height; - - Bitmap bmp = new Bitmap(heightmap.w, heightmap.h); - Color[] colours = new Color[pallete]; - - for (int i = 0; i < pallete; i++) - { - colours[i] = gradientmapLd.GetPixel(0, i); - } - - Channel copy = heightmap.Copy(); - for (int y = 0; y < copy.h; y++) - { - for (int x = 0; x < copy.w; x++) - { - // 512 is the largest possible height before colours clamp - int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1)); - bmp.SetPixel(x, y, colours[colorindex]); - } - } + Bitmap bmp = TerrainToBitmap(gradientmap); bmp.Save(filename, ImageFormat.Png); } @@ -1212,30 +1208,8 @@ namespace OpenSim.Region.Terrain byte[] imageData = null; try { - Bitmap gradientmapLd = new Bitmap(gradientmap); - - int pallete = gradientmapLd.Height; - - Bitmap bmp = new Bitmap(heightmap.w, heightmap.h); - Color[] colours = new Color[pallete]; + Bitmap bmp = TerrainToBitmap(gradientmap); - for (int i = 0; i < pallete; i++) - { - colours[i] = gradientmapLd.GetPixel(0, i); - } - - Channel copy = heightmap.Copy(); - for (int y = 0; y < copy.h; y++) - { - for (int x = 0; x < copy.w; x++) - { - // 512 is the largest possible height before colours clamp - int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, copy.h - y) / 512.0), 0.0) * (pallete - 1)); - bmp.SetPixel(x, y, colours[colorindex]); - } - } - - //bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png); imageData = OpenJPEG.EncodeFromImage(bmp, true ); } @@ -1246,5 +1220,33 @@ namespace OpenSim.Region.Terrain return imageData; } + + private Bitmap TerrainToBitmap(string gradientmap) + { + Bitmap gradientmapLd = new Bitmap(gradientmap); + + int pallete = gradientmapLd.Height; + + Bitmap bmp = new Bitmap(heightmap.w, heightmap.h); + Color[] colours = new Color[pallete]; + + for (int i = 0; i < pallete; i++) + { + colours[i] = gradientmapLd.GetPixel(0, i); + } + + Channel copy = heightmap.Copy(); + for (int y = 0; y < copy.h; y++) + { + for (int x = 0; x < copy.w; x++) + { + // 512 is the largest possible height before colours clamp + int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1)); + bmp.SetPixel(x, y, colours[colorindex]); + } + } + return bmp; + } + } } -- cgit v1.1