From adb56a46f49127911a2df169c86f2cdfde034966 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Wed, 11 Apr 2007 05:19:27 +0000 Subject: Major ass changes to terrain (now uses libTerrain-BSD!) and all-round improvements to code quality. Terrain saving/loading may work now (running through setHeights1D and getHeights1D before DB4o) **WARNING: UNTESTED** --- OpenSim.Framework/ILocalStorage.cs | 4 +- OpenSim.RegionServer/world/Avatar.cs | 4 +- OpenSim.RegionServer/world/World.cs | 12 +-- .../LocalStorageDb4o/Db4LocalStorage.cs | 6 +- OpenSim.Storage/LocalStorageDb4o/MapStorage.cs | 2 +- OpenSim.Terrain.BasicTerrain/Hills.cs | 72 --------------- OpenSim.Terrain.BasicTerrain/Normalise.cs | 102 --------------------- .../OpenSim.Terrain.BasicTerrain.csproj | 4 +- OpenSim.Terrain.BasicTerrain/RaiseLower.cs | 91 ------------------ OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 82 +++++++++++------ .../bin/Debug/OpenSim.Terrain.BasicTerrain.dll | Bin 16384 -> 16384 bytes .../bin/Debug/OpenSim.Terrain.BasicTerrain.pdb | Bin 19968 -> 15872 bytes .../bin/Debug/libTerrain-BSD.dll | Bin 0 -> 32768 bytes .../obj/Debug/OpenSim.Terrain.BasicTerrain.dll | Bin 16384 -> 16384 bytes .../obj/Debug/OpenSim.Terrain.BasicTerrain.pdb | Bin 19968 -> 15872 bytes .../Refactor/OpenSim.Terrain.BasicTerrain.dll | Bin 0 -> 16384 bytes bin/OpenSim.Terrain.BasicTerrain.dll | Bin 7168 -> 16384 bytes bin/libTerrain-BSD.dll | Bin 0 -> 32768 bytes prebuild.xml | 1 + 19 files changed, 70 insertions(+), 310 deletions(-) delete mode 100644 OpenSim.Terrain.BasicTerrain/Hills.cs delete mode 100644 OpenSim.Terrain.BasicTerrain/Normalise.cs delete mode 100644 OpenSim.Terrain.BasicTerrain/RaiseLower.cs create mode 100644 OpenSim.Terrain.BasicTerrain/bin/Debug/libTerrain-BSD.dll create mode 100644 OpenSim.Terrain.BasicTerrain/obj/Debug/Refactor/OpenSim.Terrain.BasicTerrain.dll create mode 100644 bin/libTerrain-BSD.dll diff --git a/OpenSim.Framework/ILocalStorage.cs b/OpenSim.Framework/ILocalStorage.cs index bc11d8f..2c45baa 100644 --- a/OpenSim.Framework/ILocalStorage.cs +++ b/OpenSim.Framework/ILocalStorage.cs @@ -39,8 +39,8 @@ namespace OpenSim.Framework.Interfaces void StorePrim(PrimData prim); void RemovePrim(LLUUID primID); void LoadPrimitives(ILocalStorageReceiver receiver); - float[,] LoadWorld(); - void SaveMap(float[,] heightmap); + float[] LoadWorld(); + void SaveMap(float[] heightmap); void ShutDown(); } diff --git a/OpenSim.RegionServer/world/Avatar.cs b/OpenSim.RegionServer/world/Avatar.cs index f507797..843c3af 100644 --- a/OpenSim.RegionServer/world/Avatar.cs +++ b/OpenSim.RegionServer/world/Avatar.cs @@ -44,7 +44,7 @@ namespace OpenSim.world OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)"); ControllingClient = TheClient; localid = 8880000 + (this.m_world._localNumber++); - Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain.map[(int)Pos.X, (int)Pos.Y] + 1.0f); + Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 1.0f); visualParams = new byte[218]; for (int i = 0; i < 218; i++) { @@ -332,7 +332,7 @@ namespace OpenSim.world public override void LandRenegerated() { - Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain.map[(int)Pos.X, (int)Pos.Y] + 50.0f); + Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f); } } diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 580804a..c7c57d1 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -198,7 +198,7 @@ namespace OpenSim.world { this.phyScene.SetTerrain(Terrain.getHeights1D()); } - this.localStorage.SaveMap(this.Terrain.map); + this.localStorage.SaveMap(this.Terrain.getHeights1D()); foreach (SimClient client in m_clientThreads.Values) { @@ -213,12 +213,12 @@ namespace OpenSim.world public void RegenerateTerrain(float[,] newMap) { - this.Terrain.map = newMap; + this.Terrain.setHeights2D(newMap); lock (this.LockPhysicsEngine) { this.phyScene.SetTerrain(this.Terrain.getHeights1D()); } - this.localStorage.SaveMap(this.Terrain.map); + this.localStorage.SaveMap(this.Terrain.getHeights1D()); foreach (SimClient client in m_clientThreads.Values) { @@ -239,7 +239,7 @@ namespace OpenSim.world { this.phyScene.SetTerrain(this.Terrain.getHeights1D()); } - this.localStorage.SaveMap(this.Terrain.map); + this.localStorage.SaveMap(this.Terrain.getHeights1D()); foreach (SimClient client in m_clientThreads.Values) { @@ -252,7 +252,7 @@ namespace OpenSim.world public void LoadWorldMap() { - float[,] map = this.localStorage.LoadWorld(); + float[] map = this.localStorage.LoadWorld(); if (map == null) { this.Terrain.hills(); @@ -260,7 +260,7 @@ namespace OpenSim.world } else { - this.Terrain.map = map; + this.Terrain.setHeights1D(map); } } diff --git a/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs b/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs index 189ee1a..da77701 100644 --- a/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs +++ b/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs @@ -118,11 +118,11 @@ namespace OpenSim.Storage.LocalStorageDb4o } } - public float[,] LoadWorld() + public float[] LoadWorld() { OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LoadWorld() - Loading world...."); //World blank = new World(); - float[,] heightmap = null; + float[] heightmap = null; OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LoadWorld() - Looking for a heightmap in local DB"); IObjectSet world_result = db.Get(typeof(MapStorage)); if (world_result.Count > 0) @@ -150,7 +150,7 @@ namespace OpenSim.Storage.LocalStorageDb4o return heightmap; } - public void SaveMap(float[,] heightmap) + public void SaveMap(float[] heightmap) { IObjectSet world_result = db.Get(typeof(MapStorage)); if (world_result.Count > 0) diff --git a/OpenSim.Storage/LocalStorageDb4o/MapStorage.cs b/OpenSim.Storage/LocalStorageDb4o/MapStorage.cs index dc5793e..db590ff 100644 --- a/OpenSim.Storage/LocalStorageDb4o/MapStorage.cs +++ b/OpenSim.Storage/LocalStorageDb4o/MapStorage.cs @@ -6,7 +6,7 @@ namespace OpenSim.Storage.LocalStorageDb4o { public class MapStorage { - public float[,] Map; + public float[] Map; public MapStorage() { diff --git a/OpenSim.Terrain.BasicTerrain/Hills.cs b/OpenSim.Terrain.BasicTerrain/Hills.cs deleted file mode 100644 index 40543a9..0000000 --- a/OpenSim.Terrain.BasicTerrain/Hills.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Terrain.BasicTerrain -{ - static class Hills - { - /// - /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. - /// - /// 3-Clause BSD Licensed - /// The number of hills to generate - /// The minimum size of each hill - /// The maximum size of each hill - /// Whether to bias hills towards the center of the map - /// Whether to add hills together or to pick the largest value - /// Generates hill-shaped noise instead of consistent hills - public static void hillsSpheres(float[,] map,int seed, int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) - { - Random random = new Random(seed); - int w = map.GetLength(0); - int h = map.GetLength(1); - int x, y; - int i; - - for (i = 0; i < number; i++) - { - double rx = Math.Min(255.0, random.NextDouble() * w); - double ry = Math.Min(255.0, random.NextDouble() * h); - double rand = random.NextDouble(); - - if (island) - { - // Move everything towards the center - rx -= w / 2; - rx /= 2; - rx += w / 2; - - ry -= h / 2; - ry /= 2; - ry += h / 2; - } - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - if (noisy) - rand = random.NextDouble(); - - double z = (scale_min + (scale_range * rand)); - z *= z; - z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); - - if (z < 0) - z = 0; - - if (additive) - { - map[x, y] += (float)z; - } - else - { - map[x, y] = (float)Math.Max(map[x, y], z); - } - } - } - } - } - } -} diff --git a/OpenSim.Terrain.BasicTerrain/Normalise.cs b/OpenSim.Terrain.BasicTerrain/Normalise.cs deleted file mode 100644 index 0d37f44..0000000 --- a/OpenSim.Terrain.BasicTerrain/Normalise.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Terrain.BasicTerrain -{ - static class Normalise - { - /// - /// Converts the heightmap to values ranging from 0..1 - /// - /// The heightmap to be normalised - public static void normalise(float[,] map) - { - double max = findMax(map); - double min = findMin(map); - int w = map.GetLength(0); - int h = map.GetLength(1); - - int x, y; - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min))); - } - } - } - - /// - /// Converts the heightmap to values ranging from 0.. - /// - /// The heightmap to be normalised - /// The new maximum height value of the map - public static void normalise(float[,] map, double newmax) - { - double max = findMax(map); - double min = findMin(map); - int w = map.GetLength(0); - int h = map.GetLength(1); - - int x, y; - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)) * newmax); - } - } - } - - /// - /// Finds the largest value in the heightmap - /// - /// The heightmap - /// The highest value - public static double findMax(float[,] map) - { - int x, y; - int w = map.GetLength(0); - int h = map.GetLength(1); - double max = double.MinValue; - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - if (map[x, y] > max) - max = map[x, y]; - } - } - - return max; - } - - /// - /// Finds the lowest value in a heightmap - /// - /// The heightmap - /// The minimum value - public static double findMin(float[,] map) - { - int x, y; - int w = map.GetLength(0); - int h = map.GetLength(1); - double min = double.MaxValue; - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - if (map[x, y] < min) - min = map[x, y]; - } - } - - return min; - } - } -} diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj index 328f69d..4c5c04f 100644 --- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj +++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj @@ -28,14 +28,12 @@ 4 + - - - diff --git a/OpenSim.Terrain.BasicTerrain/RaiseLower.cs b/OpenSim.Terrain.BasicTerrain/RaiseLower.cs deleted file mode 100644 index 384bcc0..0000000 --- a/OpenSim.Terrain.BasicTerrain/RaiseLower.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Terrain.BasicTerrain -{ - static class RaiseLower - { - /// - /// Raises land around the selection - /// - /// The center the X coordinate of where you wish to raise the land - /// The center the Y coordinate of where you wish to raise the land - /// The radius of the dimple - /// How much impact to add to the terrain (0..2 usually) - public static void raise(float[,] map, double rx, double ry, double size, double amount) - { - raiseSphere(map, rx, ry, size, amount); - } - - /// - /// Raises land in a sphere around the selection - /// - /// The center the X coordinate of where you wish to raise the land - /// The center the Y coordinate of where you wish to raise the land - /// The radius of the sphere dimple - /// How much impact to add to the terrain (0..2 usually) - public static void raiseSphere(float[,] map, double rx, double ry, double size, double amount) - { - int x, y; - int w = map.GetLength(0); - int h = map.GetLength(1); - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - double z = size; - z *= z; - z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); - - if (z < 0) - z = 0; - - map[x, y] += (float)(z * amount); - } - } - } - - /// - /// Lowers land in a sphere around the selection - /// - /// The center the X coordinate of where you wish to lower the land - /// The center the Y coordinate of where you wish to lower the land - /// The radius of the sphere dimple - /// How much impact to remove from the terrain (0..2 usually) - public static void lower(float[,] map, double rx, double ry, double size, double amount) - { - lowerSphere(map, rx, ry, size, amount); - } - - /// - /// Lowers land in a sphere around the selection - /// - /// The center the X coordinate of where you wish to lower the land - /// The center the Y coordinate of where you wish to lower the land - /// The radius of the sphere dimple - /// How much impact to remove from the terrain (0..2 usually) - public static void lowerSphere(float[,] map, double rx, double ry, double size, double amount) - { - int x, y; - int w = map.GetLength(0); - int h = map.GetLength(1); - - for (x = 0; x < w; x++) - { - for (y = 0; y < h; y++) - { - double z = size; - z *= z; - z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); - - if (z < 0) - z = 0; - - map[x, y] -= (float)(z * amount); - } - } - } - } -} diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs index 87dbf7e..bd4b85f 100644 --- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Text; -using OpenSim.Terrain.BasicTerrain; +using libTerrain; namespace OpenSim.Terrain { @@ -10,11 +10,8 @@ namespace OpenSim.Terrain /// /// A [normally] 256x256 heightmap /// - public float[,] map; - /// - /// A 256x256 heightmap storing water height values - /// - public float[,] water; + public Channel heightmap; + int w, h; /// @@ -24,8 +21,7 @@ namespace OpenSim.Terrain { w = 256; h = 256; - map = new float[w, h]; - water = new float[w, h]; + heightmap = new Channel(w, h); } @@ -38,7 +34,21 @@ namespace OpenSim.Terrain float[] heights = new float[w*h]; int i; for(i=0;i /// Loads a file consisting of 256x256 doubles and imports it as an array into the map. /// + /// TODO: Move this to libTerrain itself /// The filename of the double array to import public void loadFromFileF64(string filename) { @@ -70,22 +94,12 @@ namespace OpenSim.Terrain { for (y = 0; y < h; y++) { - map[x, y] = (float)bs.ReadDouble(); + heightmap.map[x, y] = bs.ReadDouble(); } } } /// - /// Swaps the references between the height and water buffers to allow you to edit the water heightmap. Remember to swap back when you are done. - /// - public void swapWaterBuffer() - { - float[,] temp = map; - map = water; - water = temp; - } - - /// /// Raises land in a sphere around the specified coordinates /// /// Center of the sphere on the X axis @@ -94,9 +108,9 @@ namespace OpenSim.Terrain /// Scale the height of the sphere by this amount (recommended 0..2) public void raise(double rx, double ry, double size, double amount) { - lock (map) + lock (heightmap) { - RaiseLower.raiseSphere(this.map, rx, ry, size, amount); + heightmap.raise(rx, ry, size, amount); } } @@ -109,9 +123,9 @@ namespace OpenSim.Terrain /// Scale the height of the sphere by this amount (recommended 0..2) public void lower(double rx, double ry, double size, double amount) { - lock (map) + lock (heightmap) { - RaiseLower.lowerSphere(this.map, rx, ry, size, amount); + heightmap.lower(rx, ry, size, amount); } } @@ -120,12 +134,24 @@ namespace OpenSim.Terrain /// public void hills() { - lock (map) + lock (heightmap) { - Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false); - Normalise.normalise(this.map,60); + heightmap.hillsSpheres(200, 20, 40, true, true, false); + heightmap.normalise(); + heightmap *= 60.0; // Raise to 60m } } + public float this[int x, int y] + { + get + { + return (float)heightmap.get(x,y); + } + set + { + heightmap.set(x,y,(double)value); + } + } } } diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll index 0cfa595..b2bcf9f 100644 Binary files a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll and b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb index ce440c6..e271888 100644 Binary files a/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb and b/OpenSim.Terrain.BasicTerrain/bin/Debug/OpenSim.Terrain.BasicTerrain.pdb differ diff --git a/OpenSim.Terrain.BasicTerrain/bin/Debug/libTerrain-BSD.dll b/OpenSim.Terrain.BasicTerrain/bin/Debug/libTerrain-BSD.dll new file mode 100644 index 0000000..d9b95fc Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/bin/Debug/libTerrain-BSD.dll differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll index 0cfa595..b2bcf9f 100644 Binary files a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll and b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb index ce440c6..e271888 100644 Binary files a/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb and b/OpenSim.Terrain.BasicTerrain/obj/Debug/OpenSim.Terrain.BasicTerrain.pdb differ diff --git a/OpenSim.Terrain.BasicTerrain/obj/Debug/Refactor/OpenSim.Terrain.BasicTerrain.dll b/OpenSim.Terrain.BasicTerrain/obj/Debug/Refactor/OpenSim.Terrain.BasicTerrain.dll new file mode 100644 index 0000000..f42e7bb Binary files /dev/null and b/OpenSim.Terrain.BasicTerrain/obj/Debug/Refactor/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/bin/OpenSim.Terrain.BasicTerrain.dll b/bin/OpenSim.Terrain.BasicTerrain.dll index c864d89..b2bcf9f 100644 Binary files a/bin/OpenSim.Terrain.BasicTerrain.dll and b/bin/OpenSim.Terrain.BasicTerrain.dll differ diff --git a/bin/libTerrain-BSD.dll b/bin/libTerrain-BSD.dll new file mode 100644 index 0000000..d9b95fc Binary files /dev/null and b/bin/libTerrain-BSD.dll differ diff --git a/prebuild.xml b/prebuild.xml index 49b1563..f1109a6 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -379,6 +379,7 @@ ../bin/ + -- cgit v1.1