**BREAKING CHANGE** Changing the way terrain is stored and used internally.

0.1-prestable
Adam Frisby 2007-04-06 18:48:23 +00:00
parent df4df07c39
commit fb0dffbf13
23 changed files with 299 additions and 76 deletions

View File

@ -0,0 +1,5 @@
..\..\bin\OpenSim.Config.SimConfigDb4o.dll
..\..\bin\OpenSim.Config.SimConfigDb4o.pdb
obj\Debug\ResolveAssemblyReference.cache
obj\Debug\OpenSim.Config.SimConfigDb4o.dll
obj\Debug\OpenSim.Config.SimConfigDb4o.pdb

View File

@ -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();
}

View File

@ -49,7 +49,7 @@ namespace OpenSim.Physics.Manager
public abstract void GetResults();
public abstract void SetTerrain(float[] heightMap);
public abstract void SetTerrain(float[,] heightMap);
public abstract void DeleteTerrain();
@ -87,7 +87,7 @@ namespace OpenSim.Physics.Manager
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("NullPhysicsScene : GetResults()");
}
public override void SetTerrain(float[] heightMap)
public override void SetTerrain(float[,] heightMap)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("NullPhysicsScene : SetTerrain({0} items)", heightMap.Length);
}

View File

@ -173,7 +173,7 @@ namespace OpenSim.Physics.OdePlugin
}
}
public override void SetTerrain(float[] heightMap)
public override void SetTerrain(float[,] heightMap)
{
for (int i = 0; i < 65536; i++)
{

View File

@ -173,7 +173,7 @@ namespace OpenSim.Physics.PhysXPlugin
}
}
public override void SetTerrain(float[] heightMap)
public override void SetTerrain(float[,] heightMap)
{
if (this._heightMap != null)
{

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion>
@ -6,7 +6,8 @@
<ProjectGuid>{632E1BFD-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon></ApplicationIcon>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>OpenSim.RegionServer</AssemblyName>
@ -15,9 +16,11 @@
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<AppDesignerFolder></AppDesignerFolder>
<AppDesignerFolder>
</AppDesignerFolder>
<RootNamespace>OpenSim.RegionServer</RootNamespace>
<StartupObject></StartupObject>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
@ -28,7 +31,8 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
@ -37,7 +41,8 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
<NoWarn>
</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -46,7 +51,8 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
@ -55,7 +61,8 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
<NoWarn>
</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
@ -104,6 +111,10 @@
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\OpenSim.Terrain.BasicTerrain\OpenSim.Terrain.BasicTerrain.csproj">
<Project>{FFD5951C-4002-4ACA-9ADF-68852357B94A}</Project>
<Name>OpenSim.Terrain.BasicTerrain</Name>
</ProjectReference>
<ProjectReference Include="..\Servers\OpenSim.Servers.csproj">
<Name>OpenSim.Servers</Name>
<Project>{8BB20F0A-0000-0000-0000-000000000000}</Project>

View File

@ -156,7 +156,7 @@ namespace OpenSim
m_console.WriteLine("Main.cs:Startup() - Starting up messaging system");
LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this.m_physicsEngine); //should be reading from the config file what physics engine to use
LocalWorld.PhysScene.SetTerrain(LocalWorld.LandMap);
LocalWorld.PhysScene.SetTerrain(LocalWorld.Terrain.map);
//should be passing a IGenericConfig object to these so they can read the config data they want from it
GridServers.AssetServer.SetServerInfo(regionData.AssetURL, regionData.AssetSendKey);

View File

@ -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.LandMap[(int)Pos.Y * 256 + (int)Pos.X] + 1);
Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain.map[(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, this.m_world.LandMap[(int)Pos.Y * 256 + (int)Pos.X] + 50);
Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain.map[(int)Pos.X, (int)Pos.Y] + 50.0f);
}
}

View File

@ -14,6 +14,7 @@ using OpenSim.Assets;
using OpenSim.world.scripting;
using OpenSim.RegionServer.world.scripting;
using OpenSim.RegionServer.world.scripting.Scripts;
using OpenSim.Terrain;
namespace OpenSim.world
{
@ -23,8 +24,9 @@ namespace OpenSim.world
public Dictionary<libsecondlife.LLUUID, Entity> Entities;
public Dictionary<libsecondlife.LLUUID, Avatar> Avatars;
public Dictionary<libsecondlife.LLUUID, Primitive> Prims;
public float[] LandMap;
// public float[] LandMap;
public ScriptEngine Scripts;
public TerrainEngine Terrain; //TODO: Replace TerrainManager with this.
public uint _localNumber = 0;
private PhysicsScene phyScene;
private float timeStep = 0.1f;
@ -189,13 +191,13 @@ namespace OpenSim.world
public void RegenerateTerrain()
{
HeightmapGenHills hills = new HeightmapGenHills();
this.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
Terrain.hills();
lock (this.LockPhysicsEngine)
{
this.phyScene.SetTerrain(this.LandMap);
this.phyScene.SetTerrain(Terrain.map);
}
this.localStorage.SaveMap(this.LandMap);
this.localStorage.SaveMap(this.Terrain.map);
foreach (SimClient client in m_clientThreads.Values)
{
@ -208,14 +210,14 @@ namespace OpenSim.world
}
}
public void RegenerateTerrain(float[] newMap)
public void RegenerateTerrain(float[,] newMap)
{
this.LandMap = newMap;
this.Terrain.map = newMap;
lock (this.LockPhysicsEngine)
{
this.phyScene.SetTerrain(this.LandMap);
this.phyScene.SetTerrain(this.Terrain.map);
}
this.localStorage.SaveMap(this.LandMap);
this.localStorage.SaveMap(this.Terrain.map);
foreach (SimClient client in m_clientThreads.Values)
{
@ -234,9 +236,9 @@ namespace OpenSim.world
{
lock (this.LockPhysicsEngine)
{
this.phyScene.SetTerrain(this.LandMap);
this.phyScene.SetTerrain(this.Terrain.map);
}
this.localStorage.SaveMap(this.LandMap);
this.localStorage.SaveMap(this.Terrain.map);
foreach (SimClient client in m_clientThreads.Values)
{
@ -249,7 +251,7 @@ namespace OpenSim.world
public void LoadWorldMap()
{
LandMap = this.localStorage.LoadWorld();
Terrain.map = this.localStorage.LoadWorld();
}
public void LoadPrimsFromStorage()
@ -288,7 +290,7 @@ namespace OpenSim.world
patches[2] = x + 2 + y * 16;
patches[3] = x + 3 + y * 16;
Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
Packet layerpack = TerrainManager.CreateLandPacket(Terrain.map, patches);
RemoteClient.OutPacket(layerpack);
}
}
@ -310,7 +312,7 @@ namespace OpenSim.world
//patches[2] = patchx + 2 + patchy * 16;
//patches[3] = patchx + 3 + patchy * 16;
Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
Packet layerpack = TerrainManager.CreateLandPacket(Terrain.map, patches);
RemoteClient.OutPacket(layerpack);
}

View File

@ -24,34 +24,16 @@ namespace OpenSim.world
// raise terrain
if (modify.ParcelData.Length > 0)
{
int mody = (int)modify.ParcelData[0].North;
int modx = (int)modify.ParcelData[0].West;
lock (LandMap)
{
LandMap[(mody * 256) + modx - 1] += 0.05f;
LandMap[(mody * 256) + modx] += 0.1f;
LandMap[(mody * 256) + modx + 1] += 0.05f;
LandMap[((mody + 1) * 256) + modx] += 0.05f;
LandMap[((mody - 1) * 256) + modx] += 0.05f;
}
RegenerateTerrain(true, modx, mody);
Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
}
break;
case 2:
//lower terrain
if (modify.ParcelData.Length > 0)
{
int mody = (int)modify.ParcelData[0].North;
int modx = (int)modify.ParcelData[0].West;
lock (LandMap)
{
LandMap[(mody * 256) + modx - 1] -= 0.05f;
LandMap[(mody * 256) + modx] -= 0.1f;
LandMap[(mody * 256) + modx + 1] -= 0.05f;
LandMap[((mody + 1) * 256) + modx] -= 0.05f;
LandMap[((mody - 1) * 256) + modx] -= 0.05f;
}
RegenerateTerrain(true, modx, mody);
Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
}
break;
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Terrain.BasicTerrain
{
static class Hills
{
/// <summary>
/// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh.
/// </summary>
/// <remarks>3-Clause BSD Licensed</remarks>
/// <param name="number">The number of hills to generate</param>
/// <param name="scale_min">The minimum size of each hill</param>
/// <param name="scale_range">The maximum size of each hill</param>
/// <param name="island">Whether to bias hills towards the center of the map</param>
/// <param name="additive">Whether to add hills together or to pick the largest value</param>
/// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
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);
}
}
}
}
}
}
}

View File

@ -33,7 +33,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="TerrainManager.cs" />
<Compile Include="Hills.cs" />
<Compile Include="RaiseLower.cs" />
<Compile Include="TerrainEngine.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Terrain.BasicTerrain
{
static class RaiseLower
{
/// <summary>
/// Raises land around the selection
/// </summary>
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
/// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
/// <param name="size">The radius of the dimple</param>
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
public static void raise(float[,] map, double rx, double ry, double size, double amount)
{
raiseSphere(map, rx, ry, size, amount);
}
/// <summary>
/// Raises land in a sphere around the selection
/// </summary>
/// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
/// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
/// <param name="size">The radius of the sphere dimple</param>
/// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
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);
}
}
}
/// <summary>
/// Lowers land in a sphere around the selection
/// </summary>
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
/// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
/// <param name="size">The radius of the sphere dimple</param>
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
public static void lower(float[,] map, double rx, double ry, double size, double amount)
{
lowerSphere(map, rx, ry, size, amount);
}
/// <summary>
/// Lowers land in a sphere around the selection
/// </summary>
/// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
/// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
/// <param name="size">The radius of the sphere dimple</param>
/// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
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);
}
}
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Terrain.BasicTerrain;
namespace OpenSim.Terrain
{
public class TerrainEngine
{
public float[,] map;
public float[,] water;
int w, h;
public TerrainEngine()
{
w = 256;
h = 256;
map = new float[w, h];
water = new float[w, h];
}
/// <summary>
/// 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.
/// </summary>
public void swapWaterBuffer()
{
float[,] temp = map;
map = water;
water = temp;
}
/// <summary>
/// Raises land in a sphere around the specified coordinates
/// </summary>
/// <param name="rx">Center of the sphere on the X axis</param>
/// <param name="ry">Center of the sphere on the Y axis</param>
/// <param name="size">The radius of the sphere</param>
/// <param name="amount">Scale the height of the sphere by this amount (recommended 0..2)</param>
public void raise(double rx, double ry, double size, double amount)
{
lock (map)
{
RaiseLower.raiseSphere(this.map, rx, ry, size, amount);
}
}
public void lower(double rx, double ry, double size, double amount)
{
lock (map)
{
RaiseLower.lowerSphere(this.map, rx, ry, size, amount);
}
}
public void hills()
{
lock (map)
{
Hills.hillsSpheres(this.map, 1337, 200, 20, 40, true, true, false);
}
}
}
}

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Terrain
{
public class TerrainManager
{
}
}

View File

@ -0,0 +1,5 @@
bin\Debug\OpenSim.Terrain.BasicTerrain.dll
bin\Debug\OpenSim.Terrain.BasicTerrain.pdb
obj\Debug\ResolveAssemblyReference.cache
obj\Debug\OpenSim.Terrain.BasicTerrain.dll
obj\Debug\OpenSim.Terrain.BasicTerrain.pdb

Binary file not shown.