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. --- OpenSim/Region/Environment/Scenes/Scene.cs | 6 +- .../MonoSqliteDataStore.cs | 6 +- .../Region/Terrain.BasicTerrain/TerrainEngine.cs | 92 +++++++++++----------- .../libTerrainBSD/Channel/Editing/Flatten.cs | 2 +- .../libTerrainBSD/Channel/Generators/Fracture.cs | 10 +-- .../libTerrainBSD/Channel/Grid.cs | 4 +- .../libTerrainBSD/Tools/Tools.cs | 8 +- 7 files changed, 66 insertions(+), 62 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 7381930..8ad8147 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -354,7 +354,7 @@ namespace OpenSim.Region.Environment.Scenes private void UpdateTerrain() { - if (Terrain.Tainted()) + if (Terrain.Tainted() && !Terrain.StillEditing()) { CreateTerrainTexture(); @@ -466,7 +466,7 @@ namespace OpenSim.Region.Environment.Scenes { if (string.IsNullOrEmpty(m_regInfo.estateSettings.terrainFile)) { - Console.WriteLine("No default terrain, procedurally generating..."); + MainLog.Instance.Verbose("TERRAIN", "No default terrain. Generating a new terrain."); Terrain.HillsGenerator(); storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); @@ -480,7 +480,7 @@ namespace OpenSim.Region.Environment.Scenes } catch { - Console.WriteLine("Unable to load default terrain, procedurally generating instead..."); + MainLog.Instance.Verbose("TERRAIN","No terrain found in database or default. Generating a new terrain."); Terrain.HillsGenerator(); } storageManager.DataStore.StoreTerrain(Terrain.GetHeights2DD()); diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index a0d2399..d2bb106 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -141,8 +141,8 @@ namespace OpenSim.DataStore.MonoSqlite prim.Shape = buildShape(shapeRow); } else - { - Console.WriteLine("No shape found for prim in storage, so setting default box shape"); + { + MainLog.Instance.Notice("No shape found for prim in storage, so setting default box shape"); prim.Shape = BoxShape.Default; } group.AddPart(prim); @@ -161,7 +161,7 @@ namespace OpenSim.DataStore.MonoSqlite } else { - Console.WriteLine("No shape found for prim in storage, so setting default box shape"); + MainLog.Instance.Notice("No shape found for prim in storage, so setting default box shape"); prim.Shape = BoxShape.Default; } createdObjects[new LLUUID(objID)].AddPart(prim); 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; + } + } } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs index 8e894ab..45bb06b 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs @@ -115,7 +115,7 @@ namespace libTerrain if (z < 0) z = 0; - Set(x, y, Tools.linearInterpolate(map[x, y], height, z)); + Set(x, y, Tools.LinearInterpolate(map[x, y], height, z)); } } } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs index 3e88aa9..3a9b7f7 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs @@ -100,7 +100,7 @@ namespace libTerrain { for (int y = 0; y < h; y++) { - double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); + double miny = Tools.LinearInterpolate(a[1], b[1], (double)x / (double)w); if (v >= 0.5) { @@ -108,14 +108,14 @@ namespace libTerrain { if (y > miny) { - map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); } } else { if (y < miny) { - map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); } } } @@ -125,14 +125,14 @@ namespace libTerrain { if (x > miny) { - map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); } } else { if (x < miny) { - map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); + map[x, y] += Tools.LinearInterpolate(scalemin, scalemax, z); } } } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs index 0930a36..0155791 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs @@ -341,7 +341,7 @@ namespace libTerrain { for (y = 0; y < h; y++) { - Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount)); + Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount)); } } return this; @@ -354,7 +354,7 @@ namespace libTerrain { for (y = 0; y < h; y++) { - Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); + Set(x, y, Tools.LinearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); } } return this; diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs index 60dbf62..13338a2 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Tools.cs @@ -37,17 +37,19 @@ namespace libTerrain { class Tools { - public static double linearInterpolate(double a, double b, double amount) + public static double LinearInterpolate(double a, double b, double amount) { return a + ((b - a) * amount); } - public static double exponentialInterpolate(double a, double b, double amount) + + public static double ExponentialInterpolate(double a, double b, double amount) { a = Math.Pow(a, amount); b = Math.Pow(b - a, 1.0 - amount); return a+b; } - public static int powerOf2Log2(int n) { + + public static int PowerOf2Log2(int n) { for (int i = 0; i < 31; i++) { if ((n & 1) == 1) { return i; -- cgit v1.1