From 87b313792821cb842fd54b568302b6877c4e53f8 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Sat, 3 May 2008 20:00:35 +0000
Subject: * Cleaned up code in Terrain, Tree and Map modules. * Fixed a bug
with Terragen loader where it would do bad things on a non 256x256 sized
terrain. Now loads the array correctly. * Moved MapImageModule.cs to
Modules/World/WorldMap * Changed Location.RegionHandle to use
Helpers.GetUlong instead of doing it ourselves.
---
.../Environment/Modules/World/Sun/SunModule.cs | 61 +-------
.../Modules/World/Terrain/Effects/CookieCutter.cs | 8 +-
.../Terrain/FileLoaders/GenericSystemDrawing.cs | 9 +-
.../Modules/World/Terrain/FileLoaders/JPEG.cs | 2 +-
.../Modules/World/Terrain/FileLoaders/LLRAW.cs | 30 ++--
.../Modules/World/Terrain/FileLoaders/RAW32.cs | 12 +-
.../Modules/World/Terrain/FileLoaders/Terragen.cs | 15 +-
.../World/Terrain/FloodBrushes/FlattenArea.cs | 3 +-
.../World/Terrain/FloodBrushes/NoiseArea.cs | 3 +-
.../World/Terrain/FloodBrushes/RaiseArea.cs | 3 +-
.../World/Terrain/FloodBrushes/RevertArea.cs | 3 +-
.../World/Terrain/FloodBrushes/SmoothArea.cs | 2 +-
.../Modules/World/Terrain/MapImageModule.cs | 168 ---------------------
.../World/Terrain/PaintBrushes/ErodeSphere.cs | 19 ++-
.../World/Terrain/PaintBrushes/FlattenSphere.cs | 17 +--
.../World/Terrain/PaintBrushes/LowerSphere.cs | 3 +-
.../World/Terrain/PaintBrushes/NoiseSphere.cs | 5 +-
.../World/Terrain/PaintBrushes/OlsenSphere.cs | 28 ++--
.../World/Terrain/PaintBrushes/RaiseSphere.cs | 3 +-
.../World/Terrain/PaintBrushes/RevertSphere.cs | 5 +-
.../World/Terrain/PaintBrushes/SmoothSphere.cs | 3 +-
.../World/Terrain/PaintBrushes/WeatherSphere.cs | 16 +-
.../Modules/World/Terrain/TerrainChannel.cs | 7 +-
.../Modules/World/Terrain/TerrainException.cs | 2 +-
.../Modules/World/Terrain/TerrainModule.cs | 6 +-
.../Modules/World/Terrain/TerrainUtil.cs | 8 +-
.../World/TreePopulator/TreePopulatorModule.cs | 9 +-
.../Modules/World/WorldMap/MapImageModule.cs | 167 ++++++++++++++++++++
28 files changed, 272 insertions(+), 345 deletions(-)
delete mode 100644 OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
create mode 100644 OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
index 47ce258..7d9bdd9 100644
--- a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
@@ -127,10 +127,10 @@ namespace OpenSim.Region.Environment.Modules.World.Sun
{
long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation;
DateTime dt = new DateTime(m_start + m_addticks);
- return (double) dt.Hour + ((double) dt.Minute / 60.0);
+ return dt.Hour + (dt.Minute / 60.0);
}
- private LLVector3 SunPos(double hour)
+ private static LLVector3 SunPos(double hour)
{
// now we have our radian position
double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0);
@@ -138,62 +138,5 @@ namespace OpenSim.Region.Environment.Modules.World.Sun
double x = Math.Cos(rad);
return new LLVector3((float) x, 0f, (float) z);
}
-
- // TODO: clear this out. This is here so that I remember to
- // figure out if we need those other packet fields that I've
- // left out so far
- //
- // public void SendViewerTime(int phase)
- // {
- // Console.WriteLine("SunPhase: {0}", phase);
- // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
- // //viewertime.TimeInfo.SecPerDay = 86400;
- // // viewertime.TimeInfo.SecPerYear = 31536000;
- // viewertime.TimeInfo.SecPerDay = 1000;
- // viewertime.TimeInfo.SecPerYear = 365000;
- // viewertime.TimeInfo.SunPhase = 1;
- // int sunPhase = (phase + 2)/2;
- // if ((sunPhase < 6) || (sunPhase > 36))
- // {
- // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
- // Console.WriteLine("sending night");
- // }
- // else
- // {
- // if (sunPhase < 12)
- // {
- // sunPhase = 12;
- // }
- // sunPhase = sunPhase - 12;
- //
- // float yValue = 0.1f*(sunPhase);
- // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
- // if (yValue > 1.2f)
- // {
- // yValue = yValue - 1.2f;
- // }
- // if (yValue > 1)
- // {
- // yValue = 1;
- // }
- // if (yValue < 0)
- // {
- // yValue = 0;
- // }
- // if (sunPhase < 14)
- // {
- // yValue = 1 - yValue;
- // }
- // if (sunPhase < 12)
- // {
- // yValue *= -1;
- // }
- // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
- // Console.WriteLine("sending sun update " + yValue);
- // }
- // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
- // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
- // // OutPacket(viewertime);
- // }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
index a2e0c40..399287d 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
@@ -26,7 +26,6 @@
*/
using System;
using OpenSim.Region.Environment.Interfaces;
-using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes;
using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes;
namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
@@ -37,7 +36,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
public void RunEffect(ITerrainChannel map)
{
- SmoothArea smooth = new SmoothArea();
ITerrainPaintableEffect eroder = new WeatherSphere();
bool[,] cliffMask = new bool[map.Width,map.Height];
@@ -60,9 +58,9 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
// Add a little height. (terrain should now be above water, mostly.)
map[x, y] += 20;
- int channelsX = 4;
+ const int channelsX = 4;
int channelWidth = (map.Width / channelsX / 4);
- int channelsY = 4;
+ const int channelsY = 4;
int channelHeight = (map.Height / channelsY / 4);
SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x);
@@ -78,7 +76,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
{
for (y = 0; y < map.Height; y++)
{
- if (cliffMask[x, y] == true)
+ if (cliffMask[x, y])
eroder.PaintEffect(map, x, y, 4, 0.1);
}
}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index 9730b16..484bb89 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -61,9 +61,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
ITerrainChannel retval = new TerrainChannel(file.Width, file.Height);
- int x, y;
+ int x;
for (x = 0; x < file.Width; x++)
{
+ int y;
for (y = 0; y < file.Height; y++)
{
retval[x, y] = file.GetPixel(x, y).GetBrightness() * 128;
@@ -103,11 +104,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
///
/// The terrain channel to export to bitmap
/// A System.Drawing.Bitmap containing a grayscale image
- protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
+ protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
{
Bitmap bmp = new Bitmap(map.Width, map.Height);
- int pallete = 256;
+ const int pallete = 256;
Color[] grays = new Color[pallete];
for (int i = 0; i < grays.Length; i++)
@@ -138,7 +139,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
///
/// The terrain channel to export to bitmap
/// A System.Drawing.Bitmap containing a coloured image
- protected Bitmap CreateBitmapFromMap(ITerrainChannel map)
+ protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
index d58926e..628c201 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
return "JPEG";
}
- private Bitmap CreateBitmapFromMap(ITerrainChannel map)
+ private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
index 5d6723f..1f6208c 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
@@ -42,12 +42,13 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
FileInfo file = new FileInfo(filename);
FileStream s = file.Open(FileMode.Open, FileAccess.Read);
BinaryReader bs = new BinaryReader(s);
- int x, y;
+ int y;
for (y = 0; y < retval.Height; y++)
{
+ int x;
for (x = 0; x < retval.Width; x++)
{
- retval[x, y] = (double) bs.ReadByte() * ((double) bs.ReadByte() / 127.0);
+ retval[x, y] = bs.ReadByte() * (bs.ReadByte() / 127.0);
bs.ReadBytes(11); // Advance the stream to next bytes.
}
}
@@ -71,18 +72,21 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
// Generate a smegging big lookup table to speed the operation up (it needs it)
double[] lookupHeightTable = new double[65536];
- int i, j, x, y;
+ int i;
+ int y;
for (i = 0; i < 256; i++)
{
+ int j;
for (j = 0; j < 256; j++)
{
- lookupHeightTable[i + (j * 256)] = ((double) i * ((double) j / 127.0));
+ lookupHeightTable[i + (j * 256)] = (i * (j / 127.0));
}
}
// Output the calculated raw
for (y = 0; y < map.Height; y++)
{
+ int x;
for (x = 0; x < map.Width; x++)
{
double t = map[x, y];
@@ -100,15 +104,15 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
byte red = (byte) (index & 0xFF);
byte green = (byte) ((index >> 8) & 0xFF);
- byte blue = 20;
- byte alpha1 = 0; // Land Parcels
- byte alpha2 = 0; // For Sale Land
- byte alpha3 = 0; // Public Edit Object
- byte alpha4 = 0; // Public Edit Land
- byte alpha5 = 255; // Safe Land
- byte alpha6 = 255; // Flying Allowed
- byte alpha7 = 255; // Create Landmark
- byte alpha8 = 255; // Outside Scripts
+ const byte blue = 20;
+ const byte alpha1 = 0;
+ const byte alpha2 = 0;
+ const byte alpha3 = 0;
+ const byte alpha4 = 0;
+ const byte alpha5 = 255;
+ const byte alpha6 = 255;
+ const byte alpha7 = 255;
+ const byte alpha8 = 255;
byte alpha9 = red;
byte alpha10 = green;
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
index fd2136c..689abcf 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
@@ -46,9 +46,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
FileInfo file = new FileInfo(filename);
FileStream s = file.Open(FileMode.Open, FileAccess.Read);
BinaryReader bs = new BinaryReader(s);
- int x, y;
+ int y;
for (y = 0; y < retval.Height; y++)
{
+ int x;
for (x = 0; x < retval.Width; x++)
{
retval[x, y] = bs.ReadSingle();
@@ -69,7 +70,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
FileStream s = file.Open(FileMode.Open, FileAccess.Read);
BinaryReader bs = new BinaryReader(s);
- int currFileXOffset = 0;
int currFileYOffset = 0;
// if our region isn't on the first Y section of the areas to be landscaped, then
@@ -84,11 +84,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
// got to the Y start offset within the file of our region
// so read the file bits associated with our region
- int x, y;
+ int y;
// for each Y within our Y offset
for (y = 0; y < sectionHeight; y++)
{
- currFileXOffset = 0;
+ int currFileXOffset = 0;
// if our region isn't the first X section of the areas to be landscaped, then
// advance the stream to the X start pos of our section in the file
@@ -100,6 +100,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
}
// got to our X offset, so write our regions X line
+ int x;
for (x = 0; x < sectionWidth; x++)
{
// Read a strip and continue
@@ -130,9 +131,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
FileStream s = file.Open(FileMode.Create, FileAccess.Write);
BinaryWriter bs = new BinaryWriter(s);
- int x, y;
+ int y;
for (y = 0; y < map.Height; y++)
{
+ int x;
for (x = 0; x < map.Width; x++)
{
bs.Write((float) map[x, y]);
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
index 7cb4b00..fe36cf7 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
@@ -50,14 +50,15 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
BinaryReader bs = new BinaryReader(s);
bool eof = false;
- if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
+ if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
{
+ int w = 256;
+ int h = 256;
+
// Terragen file
while (eof == false)
{
- int w = 256;
- int h = 256;
- string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4));
+ string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4));
switch (tmp)
{
case "SIZE":
@@ -79,12 +80,13 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
Int16 heightScale = bs.ReadInt16();
Int16 baseHeight = bs.ReadInt16();
retval = new TerrainChannel(w, h);
- int x, y;
+ int x;
for (x = 0; x < w; x++)
{
+ int y;
for (y = 0; y < h; y++)
{
- retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0;
+ retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0;
}
}
break;
@@ -103,7 +105,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
public void SaveFile(string filename, ITerrainChannel map)
{
- char[] header = "TERRAGENTERRAIN".ToCharArray();
throw new NotImplementedException();
}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
index 496da63..f3c8a13 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
@@ -37,7 +37,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
{
double sum = 0.0;
double steps = 0.0;
- double avg;
int x, y;
for (x = 0; x < map.Width; x++)
@@ -52,7 +51,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
}
}
- avg = sum / steps;
+ double avg = sum / steps;
double str = 0.1 * strength; // == 0.2 in the default client
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
index 6c8e76e..f7c4893 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
@@ -36,9 +36,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
{
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
+ int y;
for (y = 0; y < map.Height; y++)
{
if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
index 5cb236c..5eff3d6 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
@@ -35,9 +35,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
{
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
+ int y;
for (y = 0; y < map.Height; y++)
{
if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
index f1d9ce6..bebcae5 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
@@ -42,9 +42,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
{
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
+ int y;
for (y = 0; y < map.Height; y++)
{
if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
index d17d9cb..8fd805e 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
if (y < 0.0)
y = 0.0;
- int stepSize = 1;
+ const int stepSize = 1;
double h00 = map[(int) x, (int) y];
double h10 = map[(int) x + stepSize, (int) y];
double h01 = map[(int) x, (int) y + stepSize];
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
deleted file mode 100644
index fe26902..0000000
--- a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-using System;
-using System.Drawing;
-using Nini.Config;
-using OpenJPEGNet;
-using OpenSim.Region.Environment.Interfaces;
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Environment.Modules.World.Terrain
-{
- internal class MapImageModule : IMapImageGenerator, IRegionModule
- {
- private Scene m_scene;
-
- #region IMapImageGenerator Members
-
- public byte[] WriteJpeg2000Image(string gradientmap)
- {
- byte[] imageData = null;
-
- Bitmap bmp = TerrainToBitmap(gradientmap);
-
- try
- {
- imageData = OpenJPEG.EncodeFromImage(bmp, true);
- }
- catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
- {
- Console.WriteLine("Failed generating terrain map: " + e);
- }
-
- return imageData;
- }
-
- #endregion
-
- #region IRegionModule Members
-
- public void Initialise(Scene scene, IConfigSource source)
- {
- m_scene = scene;
- m_scene.RegisterModuleInterface(this);
- }
-
- public void PostInitialise()
- {
- }
-
- public void Close()
- {
- }
-
- public string Name
- {
- get { return "MapImageModule"; }
- }
-
- public bool IsSharedModule
- {
- get { return false; }
- }
-
- #endregion
-
- private void ShadeBuildings(ref Bitmap map)
- {
- lock (map)
- {
- lock (m_scene.Entities)
- {
- foreach (EntityBase entity in m_scene.Entities.Values)
- {
- if (entity is SceneObjectGroup)
- {
- SceneObjectGroup sog = (SceneObjectGroup) entity;
-
- foreach (SceneObjectPart primitive in sog.Children.Values)
- {
- int x, y, w, h;
- x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
- y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
- w = (int) primitive.Scale.X;
- h = (int) primitive.Scale.Y;
-
- int dx;
- for (dx = x; dx < x + w; dx++)
- {
- int dy;
- for (dy = y; dy < y + h; dy++)
- {
- if (x < 0 || y < 0)
- continue;
- if (x >= map.Width || y >= map.Height)
- continue;
-
- map.SetPixel(dx, dy, Color.DarkGray);
- }
- }
- }
- }
- }
- }
- }
- }
-
- private Bitmap TerrainToBitmap(string gradientmap)
- {
- Bitmap gradientmapLd = new Bitmap(gradientmap);
-
- int pallete = gradientmapLd.Height;
-
- Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height);
- Color[] colours = new Color[pallete];
-
- for (int i = 0; i < pallete; i++)
- {
- colours[i] = gradientmapLd.GetPixel(0, i);
- }
-
- lock (m_scene.Heightmap)
- {
- ITerrainChannel copy = m_scene.Heightmap;
- for (int y = 0; y < copy.Height; y++)
- {
- for (int x = 0; x < copy.Width; x++)
- {
- // 512 is the largest possible height before colours clamp
- int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
-
- // Handle error conditions
- if (colorindex > pallete - 1 || colorindex < 0)
- bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
- else
- bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
- }
- }
- ShadeBuildings(ref bmp);
- return bmp;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
index e036988..dae4cf8 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
@@ -35,20 +35,20 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
///
public class ErodeSphere : ITerrainPaintableEffect
{
- private double rainHeight = 0.2;
- private int rounds = 10;
- private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
- private double waterSaturation = 0.30; // Can carry 1% of water in height
+ private const double rainHeight = 0.2;
+ private const int rounds = 10;
+ private const NeighbourSystem type = NeighbourSystem.Moore;
+ private const double waterSaturation = 0.30;
#region Supporting Functions
- private int[] Neighbours(NeighbourSystem type, int index)
+ private static int[] Neighbours(NeighbourSystem neighbourType, int index)
{
int[] coord = new int[2];
index++;
- switch (type)
+ switch (neighbourType)
{
case NeighbourSystem.Moore:
switch (index)
@@ -173,7 +173,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
for (y = 0; y < water.Height; y++)
{
- double solConst = (1.0 / rounds);
+ const double solConst = (1.0 / rounds);
double sedDelta = water[x, y] * solConst;
map[x, y] -= sedDelta;
sediment[x, y] += sedDelta;
@@ -194,9 +194,8 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
double altitudeTotal = 0.0;
double altitudeMe = map[x, y] + water[x, y];
- int NEIGHBOUR_ME = 4;
-
- int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
+ const int NEIGHBOUR_ME = 4;
+ const int NEIGHBOUR_MAX = 9;
for (int j = 0; j < NEIGHBOUR_MAX; j++)
{
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
index dee455f..0c4e3de 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
@@ -39,21 +39,16 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
strength = TerrainUtil.MetersToSphericalStrength(strength);
int x, y;
- double[,] tweak = new double[map.Width,map.Height];
-
- double area = strength;
- double step = strength / 4.0;
double sum = 0.0;
double step2 = 0.0;
- double avg = 0.0;
// compute delta map
for (x = 0; x < map.Width; x++)
{
for (y = 0; y < map.Height; y++)
{
- double z = SphericalFactor(x, y, rx, ry, strength);
+ double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
if (z > 0) // add in non-zero amount
{
@@ -63,14 +58,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
}
}
- avg = sum / step2;
+ double avg = sum / step2;
// blend in map
for (x = 0; x < map.Width; x++)
{
for (y = 0; y < map.Height; y++)
{
- double z = SphericalFactor(x, y, rx, ry, strength) * duration;
+ double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration;
if (z > 0) // add in non-zero amount
{
@@ -84,11 +79,5 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
}
#endregion
-
- private double SphericalFactor(double x, double y, double rx, double ry, double size)
- {
- double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
- return z;
- }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
index 092bd29..202ab3b 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
@@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
strength = TerrainUtil.MetersToSphericalStrength(strength);
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
// Skip everything unlikely to be affected
if (Math.Abs(x - rx) > strength * 1.1)
continue;
+ int y;
for (y = 0; y < map.Height; y++)
{
// Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
index 8ae583e..0824efd 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
@@ -39,13 +39,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
strength = TerrainUtil.MetersToSphericalStrength(strength);
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
// Skip everything unlikely to be affected
if (Math.Abs(x - rx) > strength * 1.1)
continue;
+ int y;
for (y = 0; y < map.Height; y++)
{
// Skip everything unlikely to be affected
@@ -57,7 +58,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
z *= z;
z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
- double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0);
+ double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0);
if (z > 0.0)
map[x, y] += noise * z * duration;
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
index ba01a01..f2a1800 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
@@ -38,18 +38,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
///
public class OlsenSphere : ITerrainPaintableEffect
{
- private double nConst = 1024.0;
- private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
+ private const double nConst = 1024.0;
+ private const NeighbourSystem type = NeighbourSystem.Moore;
#region Supporting Functions
- private int[] Neighbours(NeighbourSystem type, int index)
+ private static int[] Neighbours(NeighbourSystem neighbourType, int index)
{
int[] coord = new int[2];
index++;
- switch (type)
+ switch (neighbourType)
{
case NeighbourSystem.Moore:
switch (index)
@@ -141,12 +141,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
return coord;
}
- private double SphericalFactor(double x, double y, double rx, double ry, double size)
- {
- double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
- return z;
- }
-
private enum NeighbourSystem
{
Moore,
@@ -161,22 +155,22 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
strength = TerrainUtil.MetersToSphericalStrength(strength);
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
+ int y;
for (y = 0; y < map.Height; y++)
{
- double z = SphericalFactor(x, y, rx, ry, strength);
+ double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
if (z > 0) // add in non-zero amount
{
- int NEIGHBOUR_ME = 4;
- int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
+ const int NEIGHBOUR_ME = 4;
+ const int NEIGHBOUR_MAX = 9;
double max = Double.MinValue;
int loc = 0;
- double cellmax = 0;
for (int j = 0; j < NEIGHBOUR_MAX; j++)
@@ -197,7 +191,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
if (coords[1] < 0)
continue;
- cellmax = map[x, y] - map[coords[0], coords[1]];
+ double cellmax = map[x, y] - map[coords[0], coords[1]];
if (cellmax > max)
{
max = cellmax;
@@ -206,7 +200,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
}
}
- double T = nConst / ((map.Width + map.Height) / 2);
+ double T = nConst / ((map.Width + map.Height) / 2.0);
// Apply results
if (0 < max && max <= T)
{
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
index 5d6f093..f5344a0 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
@@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
strength = TerrainUtil.MetersToSphericalStrength(strength);
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
// Skip everything unlikely to be affected
if (Math.Abs(x - rx) > strength * 1.1)
continue;
+ int y;
for (y = 0; y < map.Height; y++)
{
// Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
index b47e041..3deb458 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
public class RevertSphere : ITerrainPaintableEffect
{
- private ITerrainChannel m_revertmap;
+ private readonly ITerrainChannel m_revertmap;
public RevertSphere(ITerrainChannel revertmap)
{
@@ -50,13 +50,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
if (duration < 0)
return;
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
// Skip everything unlikely to be affected
if (Math.Abs(x - rx) > strength * 1.1)
continue;
+ int y;
for (y = 0; y < map.Height; y++)
{
// Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
index 51d5f0e..49946fd 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
@@ -40,7 +40,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
int x, y;
double[,] tweak = new double[map.Width,map.Height];
- double n, l;
double area = strength;
double step = strength / 4.0;
@@ -56,8 +55,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
double average = 0.0;
int avgsteps = 0;
+ double n;
for (n = 0.0 - area; n < area; n += step)
{
+ double l;
for (l = 0.0 - area; l < area; l += step)
{
avgsteps++;
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
index b48beb8..753d171 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
@@ -34,18 +34,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
///
public class WeatherSphere : ITerrainPaintableEffect
{
- private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required.
- private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
+ private const double talus = 0.2;
+ private const NeighbourSystem type = NeighbourSystem.Moore;
#region Supporting Functions
- private int[] Neighbours(NeighbourSystem type, int index)
+ private static int[] Neighbours(NeighbourSystem neighbourType, int index)
{
int[] coord = new int[2];
index++;
- switch (type)
+ switch (neighbourType)
{
case NeighbourSystem.Moore:
switch (index)
@@ -151,19 +151,19 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
{
strength = TerrainUtil.MetersToSphericalStrength(strength);
- int x, y;
+ int x;
for (x = 0; x < map.Width; x++)
{
+ int y;
for (y = 0; y < map.Height; y++)
{
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
if (z > 0) // add in non-zero amount
{
- int NEIGHBOUR_ME = 4;
-
- int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
+ const int NEIGHBOUR_ME = 4;
+ const int NEIGHBOUR_MAX = 9;
for (int j = 0; j < NEIGHBOUR_MAX; j++)
{
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
index 4f7d20c..305818f 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
for (y = 0; y < Constants.RegionSize; y++)
{
map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
- double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01;
+ double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2.0, Constants.RegionSize / 2.0, 50) * 0.01;
if (map[x, y] < spherFac)
{
map[x, y] = spherFac;
@@ -138,10 +138,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
taint[x / 16, y / 16] = false;
return true;
}
- else
- {
- return false;
- }
+ return false;
}
#endregion
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
index f5c0fe4..2411de0 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
@@ -31,7 +31,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
{
public class TerrainException : Exception
{
- public TerrainException() : base()
+ public TerrainException()
{
}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
index eff6159..3076b52 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
@@ -79,11 +79,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
new Dictionary();
private ITerrainChannel m_channel;
- private Dictionary m_channels;
private Dictionary m_plugineffects;
private ITerrainChannel m_revert;
private Scene m_scene;
- private bool m_tainted = false;
+ private bool m_tainted;
#region ICommandableModule Members
@@ -581,7 +580,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
{
double max = Double.MinValue;
double min = double.MaxValue;
- double avg;
double sum = 0;
int x;
@@ -598,7 +596,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
}
}
- avg = sum / (m_channel.Height * m_channel.Width);
+ double avg = sum / (m_channel.Height * m_channel.Width);
m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height);
m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum);
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
index daef6bd..4cb828e 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
if (y < 0.0)
y = 0.0;
- int stepSize = 1;
+ const int stepSize = 1;
double h00 = map[(int) x, (int) y];
double h10 = map[(int) x + stepSize, (int) y];
double h01 = map[(int) x, (int) y + stepSize];
@@ -116,14 +116,12 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
public static double PerlinNoise2D(double x, double y, int octaves, double persistence)
{
- double frequency = 0.0;
- double amplitude = 0.0;
double total = 0.0;
for (int i = 0; i < octaves; i++)
{
- frequency = Math.Pow(2, i);
- amplitude = Math.Pow(persistence, i);
+ double frequency = Math.Pow(2, i);
+ double amplitude = Math.Pow(persistence, i);
total += InterpolatedNoise(x * frequency, y * frequency) * amplitude;
}
diff --git a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
index 4b22700..a62b78a 100644
--- a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
@@ -66,10 +66,10 @@ namespace OpenSim.Region.Environment.Modules.World.TreePopulator
m_trees = new List();
m_scene = scene;
- m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole);
+ m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
Timer CalculateTrees = new Timer(m_tree_updates);
- CalculateTrees.Elapsed += new ElapsedEventHandler(CalculateTrees_Elapsed);
+ CalculateTrees.Elapsed += CalculateTrees_Elapsed;
CalculateTrees.Start();
m_log.Debug("[TREES]: Initialised tree module");
}
@@ -190,10 +190,7 @@ namespace OpenSim.Region.Environment.Modules.World.TreePopulator
break;
}
- else
- {
- selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0);
- }
+ selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0);
}
else
{
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
new file mode 100644
index 0000000..8ebe33e
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Drawing;
+using Nini.Config;
+using OpenJPEGNet;
+using OpenSim.Region.Environment.Interfaces;
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Environment.Modules.World.WorldMap
+{
+ internal class MapImageModule : IMapImageGenerator, IRegionModule
+ {
+ private Scene m_scene;
+
+ #region IMapImageGenerator Members
+
+ public byte[] WriteJpeg2000Image(string gradientmap)
+ {
+ byte[] imageData = null;
+
+ Bitmap bmp = TerrainToBitmap(gradientmap);
+
+ try
+ {
+ imageData = OpenJPEG.EncodeFromImage(bmp, true);
+ }
+ catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
+ {
+ Console.WriteLine("Failed generating terrain map: " + e);
+ }
+
+ return imageData;
+ }
+
+ #endregion
+
+ #region IRegionModule Members
+
+ public void Initialise(Scene scene, IConfigSource source)
+ {
+ m_scene = scene;
+ m_scene.RegisterModuleInterface(this);
+ }
+
+ public void PostInitialise()
+ {
+ }
+
+ public void Close()
+ {
+ }
+
+ public string Name
+ {
+ get { return "MapImageModule"; }
+ }
+
+ public bool IsSharedModule
+ {
+ get { return false; }
+ }
+
+ #endregion
+
+ private void ShadeBuildings(Bitmap map)
+ {
+ lock (map)
+ {
+ lock (m_scene.Entities)
+ {
+ foreach (EntityBase entity in m_scene.Entities.Values)
+ {
+ if (entity is SceneObjectGroup)
+ {
+ SceneObjectGroup sog = (SceneObjectGroup) entity;
+
+ foreach (SceneObjectPart primitive in sog.Children.Values)
+ {
+ int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
+ int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
+ int w = (int) primitive.Scale.X;
+ int h = (int) primitive.Scale.Y;
+
+ int dx;
+ for (dx = x; dx < x + w; dx++)
+ {
+ int dy;
+ for (dy = y; dy < y + h; dy++)
+ {
+ if (x < 0 || y < 0)
+ continue;
+ if (x >= map.Width || y >= map.Height)
+ continue;
+
+ map.SetPixel(dx, dy, Color.DarkGray);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private Bitmap TerrainToBitmap(string gradientmap)
+ {
+ Bitmap gradientmapLd = new Bitmap(gradientmap);
+
+ int pallete = gradientmapLd.Height;
+
+ Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height);
+ Color[] colours = new Color[pallete];
+
+ for (int i = 0; i < pallete; i++)
+ {
+ colours[i] = gradientmapLd.GetPixel(0, i);
+ }
+
+ lock (m_scene.Heightmap)
+ {
+ ITerrainChannel copy = m_scene.Heightmap;
+ for (int y = 0; y < copy.Height; y++)
+ {
+ for (int x = 0; x < copy.Width; x++)
+ {
+ // 512 is the largest possible height before colours clamp
+ int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
+
+ // Handle error conditions
+ if (colorindex > pallete - 1 || colorindex < 0)
+ bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
+ else
+ bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
+ }
+ }
+ ShadeBuildings(bmp);
+ return bmp;
+ }
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.1