fix worldMapModule

avinationmerge
UbitUmarov 2015-08-22 11:56:01 +01:00
parent e3d82ad706
commit 5b03a04fb0
2 changed files with 124 additions and 49 deletions

View File

@ -34,6 +34,8 @@ using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.Imaging; using OpenMetaverse.Imaging;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.World.LegacyMap namespace OpenSim.Region.CoreModules.World.LegacyMap
@ -271,7 +273,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
// the heigthfield might have some jumps in values. Rendered land is smooth, though, // the heigthfield might have some jumps in values. Rendered land is smooth, though,
// as a slope is rendered at that place. So average 4 neighbour values to emulate that. // as a slope is rendered at that place. So average 4 neighbour values to emulate that.
private float getHeight(double[,] hm, int x, int y) { private float getHeight(ITerrainChannel hm, int x, int y)
{
if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1))
return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112);
else else
@ -284,6 +287,14 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
int tc = Environment.TickCount; int tc = Environment.TickCount;
m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain"); m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain");
ITerrainChannel hm = m_scene.Heightmap;
if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height)
{
m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>",
"[TEXTURED MAP TILE RENDERER]", mapbmp.Width, mapbmp.Height, hm.Width, hm.Height);
}
// These textures should be in the AssetCache anyway, as every client conneting to this // These textures should be in the AssetCache anyway, as every client conneting to this
// region needs them. Except on start, when the map is recreated (before anyone connected), // region needs them. Except on start, when the map is recreated (before anyone connected),
// and on change of the estate settings (textures and terrain values), when the map should // and on change of the estate settings (textures and terrain values), when the map should
@ -310,19 +321,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
float waterHeight = (float)settings.WaterHeight; float waterHeight = (float)settings.WaterHeight;
double[,] hm = m_scene.Heightmap.GetDoubles(); for (int x = 0; x < hm.Width; x++)
for (int x = 0; x < (int)Constants.RegionSize; x++)
{ {
float columnRatio = x / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation float columnRatio = x / (hm.Width - 1); // 0 - 1, for interpolation
for (int y = 0; y < (int)Constants.RegionSize; y++) for (int y = 0; y < hm.Height; y++)
{ {
float rowRatio = y / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation float rowRatio = y / (hm.Height - 1); // 0 - 1, for interpolation
// Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left
int yr = ((int)Constants.RegionSize - 1) - y; int yr = (hm.Height - 1) - y;
float heightvalue = getHeight(hm, x, y); float heightvalue = getHeight(m_scene.Heightmap, x, y);
if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
heightvalue = 0; heightvalue = 0;
@ -366,15 +375,15 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
// first, rescale h to 0.0 - 1.0 // first, rescale h to 0.0 - 1.0
hmod = (hmod - low) / (high - low); hmod = (hmod - low) / (high - low);
// now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4 // now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4
if (hmod < 1f/3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod * 3f); if (hmod < 1f / 3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod * 3f);
else if (hmod < 2f/3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod * 3f) - 1f); else if (hmod < 2f / 3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod * 3f) - 1f);
else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod * 3f) - 2f); else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod * 3f) - 2f);
} }
// Shade the terrain for shadows // Shade the terrain for shadows
if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) if (x < (hm.Width - 1) && y < (hm.Height - 1))
{ {
float hfvaluecompare = getHeight(hm, x + 1, y + 1); // light from north-east => look at land height there float hfvaluecompare = getHeight(m_scene.Heightmap, x + 1, y + 1); // light from north-east => look at land height there
if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare))
hfvaluecompare = 0f; hfvaluecompare = 0f;

View File

@ -325,8 +325,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
protected static OSDMapLayer GetOSDMapLayerResponse() protected static OSDMapLayer GetOSDMapLayerResponse()
{ {
OSDMapLayer mapLayer = new OSDMapLayer(); OSDMapLayer mapLayer = new OSDMapLayer();
mapLayer.Right = 2048; // mapLayer.Right = 2048;
mapLayer.Top = 2048; mapLayer.Right = 5000;
// mapLayer.Top = 2048;
mapLayer.Top = 5000;
mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006"); mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006");
return mapLayer; return mapLayer;
@ -438,7 +440,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
} }
uint xstart = 0; uint xstart = 0;
uint ystart = 0; uint ystart = 0;
Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out xstart, out ystart); Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
if (itemtype == 6) // Service 6 right now (MAP_ITEM_AGENTS_LOCATION; green dots) if (itemtype == 6) // Service 6 right now (MAP_ITEM_AGENTS_LOCATION; green dots)
{ {
if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
@ -450,8 +453,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (m_scene.GetRootAgentCount() <= 1) if (m_scene.GetRootAgentCount() <= 1)
{ {
mapitem = new mapItemReply(); mapitem = new mapItemReply();
mapitem.x = (uint)(xstart + 1); mapitem.x = xstart + 1;
mapitem.y = (uint)(ystart + 1); mapitem.y = ystart + 1;
mapitem.id = UUID.Zero; mapitem.id = UUID.Zero;
mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString());
mapitem.Extra = 0; mapitem.Extra = 0;
@ -466,8 +469,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (sp.UUID != remoteClient.AgentId) if (sp.UUID != remoteClient.AgentId)
{ {
mapitem = new mapItemReply(); mapitem = new mapItemReply();
mapitem.x = (uint)(xstart + sp.AbsolutePosition.X); mapitem.x = xstart + (uint)sp.AbsolutePosition.X;
mapitem.y = (uint)(ystart + sp.AbsolutePosition.Y); mapitem.y = ystart + (uint)sp.AbsolutePosition.Y;
mapitem.id = UUID.Zero; mapitem.id = UUID.Zero;
mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString());
mapitem.Extra = 1; mapitem.Extra = 1;
@ -517,8 +520,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
float y = (min.Y+max.Y)/2; float y = (min.Y+max.Y)/2;
mapitem = new mapItemReply(); mapitem = new mapItemReply();
mapitem.x = (uint)(xstart + x); mapitem.x = xstart + (uint)x;
mapitem.y = (uint)(ystart + y); mapitem.y = ystart +(uint)y;
// mapitem.z = (uint)m_scene.GetGroundHeight(x,y); // mapitem.z = (uint)m_scene.GetGroundHeight(x,y);
mapitem.id = parcel.GlobalID; mapitem.id = parcel.GlobalID;
mapitem.name = parcel.Name; mapitem.name = parcel.Name;
@ -549,8 +552,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (sog != null) if (sog != null)
{ {
mapitem = new mapItemReply(); mapitem = new mapItemReply();
mapitem.x = (uint)(xstart + sog.AbsolutePosition.X); mapitem.x = xstart + (uint)sog.AbsolutePosition.X;
mapitem.y = (uint)(ystart + sog.AbsolutePosition.Y); mapitem.y = ystart + (uint)sog.AbsolutePosition.Y;
mapitem.id = UUID.Zero; mapitem.id = UUID.Zero;
mapitem.name = sog.Name; mapitem.name = sog.Name;
mapitem.Extra = 0; // color (not used) mapitem.Extra = 0; // color (not used)
@ -721,7 +724,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (httpserver.Length == 0) if (httpserver.Length == 0)
{ {
uint x = 0, y = 0; uint x = 0, y = 0;
Utils.LongToUInts(regionhandle, out x, out y); Util.RegionHandleToWorldLoc(regionhandle, out x, out y);
GridRegion mreg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); GridRegion mreg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
if (mreg != null) if (mreg != null)
@ -801,6 +804,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
catch (WebException ex) catch (WebException ex)
{ {
m_log.WarnFormat("[WORLD MAP]: Bad send on GetMapItems {0}", ex.Message); m_log.WarnFormat("[WORLD MAP]: Bad send on GetMapItems {0}", ex.Message);
responseMap["connect"] = OSD.FromBoolean(false);
lock (m_blacklistedurls) lock (m_blacklistedurls)
{ {
if (!m_blacklistedurls.ContainsKey(httpserver)) if (!m_blacklistedurls.ContainsKey(httpserver))
@ -842,7 +846,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
} }
} }
catch (WebException) catch (WebException)
{ {
lock (m_blacklistedurls) lock (m_blacklistedurls)
{ {
if (!m_blacklistedurls.ContainsKey(httpserver)) if (!m_blacklistedurls.ContainsKey(httpserver))
@ -996,22 +1000,27 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
// on an unloaded square. // on an unloaded square.
// But make sure: Look whether the one we requested is in there // But make sure: Look whether the one we requested is in there
List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID,
minX * (int)Constants.RegionSize, (int)Util.RegionToWorldLoc((uint)minX),
maxX * (int)Constants.RegionSize, (int)Util.RegionToWorldLoc((uint)maxX),
minY * (int)Constants.RegionSize, (int)Util.RegionToWorldLoc((uint)minY),
maxY * (int)Constants.RegionSize); (int)Util.RegionToWorldLoc((uint)maxY) );
if (regions != null) if (regions != null)
{ {
foreach (GridRegion r in regions) foreach (GridRegion r in regions)
{ {
if ((r.RegionLocX == minX * (int)Constants.RegionSize) && if (r.RegionLocX == Util.RegionToWorldLoc((uint)minX) &&
(r.RegionLocY == minY * (int)Constants.RegionSize)) r.RegionLocY == Util.RegionToWorldLoc((uint)minY))
{ {
// found it => add it to response // found it => add it to response
MapBlockData block = new MapBlockData(); MapBlockData block = new MapBlockData();
MapBlockFromGridRegion(block, r, flag); if ((flag & 2) == 2)
response.Add(block); response.AddRange(Map2BlockFromGridRegion(r, flag));
else
{
MapBlockFromGridRegion(block, r, flag);
response.Add(block);
}
break; break;
} }
} }
@ -1023,7 +1032,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
MapBlockData block = new MapBlockData(); MapBlockData block = new MapBlockData();
block.X = (ushort)minX; block.X = (ushort)minX;
block.Y = (ushort)minY; block.Y = (ushort)minY;
block.Access = 254; // means 'simulator is offline' block.Access = (byte)SimAccess.Down; // means 'simulator is offline'
response.Add(block); response.Add(block);
} }
// The lower 16 bits are an unsigned int16 // The lower 16 bits are an unsigned int16
@ -1109,9 +1118,18 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
foreach (GridRegion r in regions) foreach (GridRegion r in regions)
{ {
MapBlockData block = new MapBlockData(); MapBlockData block = new MapBlockData();
MapBlockFromGridRegion(block, r, flag); if ((flag & 2) == 2)
mapBlocks.Add(block); {
allBlocks.Add(block); List<MapBlockData> blocks = Map2BlockFromGridRegion(r, flag);
mapBlocks.AddRange(blocks);
allBlocks.AddRange(blocks);
}
else
{
MapBlockFromGridRegion(block, r, flag);
mapBlocks.Add(block);
allBlocks.Add(block);
}
if (mapBlocks.Count >= 10) if (mapBlocks.Count >= 10)
{ {
remoteClient.SendMapBlock(mapBlocks, flag & 0xffff); remoteClient.SendMapBlock(mapBlocks, flag & 0xffff);
@ -1147,6 +1165,41 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
block.SizeY = (ushort)r.RegionSizeY; block.SizeY = (ushort)r.RegionSizeY;
} }
public List<MapBlockData> Map2BlockFromGridRegion(GridRegion r, uint flag)
{
List<MapBlockData> blocks = new List<MapBlockData>();
MapBlockData block = new MapBlockData();
if (r == null)
{
block.Access = (byte)SimAccess.Down;
block.MapImageId = UUID.Zero;
blocks.Add(block);
}
else
{
block.Access = r.Access;
switch (flag & 0xffff)
{
case 0:
block.MapImageId = r.TerrainImage;
break;
case 2:
block.MapImageId = r.ParcelImage;
break;
default:
block.MapImageId = UUID.Zero;
break;
}
block.Name = r.RegionName;
block.X = (ushort)(r.RegionLocX / Constants.RegionSize);
block.Y = (ushort)(r.RegionLocY / Constants.RegionSize);
block.SizeX = (ushort)r.RegionSizeX;
block.SizeY = (ushort)r.RegionSizeY;
blocks.Add(block);
}
return blocks;
}
public Hashtable OnHTTPThrottled(Hashtable keysvals) public Hashtable OnHTTPThrottled(Hashtable keysvals)
{ {
Hashtable reply = new Hashtable(); Hashtable reply = new Hashtable();
@ -1166,7 +1219,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (myMapImageJPEG.Length == 0) if (myMapImageJPEG.Length == 0)
{ {
MemoryStream imgstream = new MemoryStream(); MemoryStream imgstream = null;
Bitmap mapTexture = new Bitmap(1,1); Bitmap mapTexture = new Bitmap(1,1);
ManagedImage managedImage; ManagedImage managedImage;
Image image = (Image)mapTexture; Image image = (Image)mapTexture;
@ -1346,7 +1399,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
uint xstart = 0; uint xstart = 0;
uint ystart = 0; uint ystart = 0;
Utils.LongToUInts(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);
// Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots) // Service 6 (MAP_ITEM_AGENTS_LOCATION; green dots)
@ -1578,12 +1631,20 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private Byte[] GenerateOverlay() private Byte[] GenerateOverlay()
{ {
using (Bitmap overlay = new Bitmap(256, 256)) // These need to be ints for bitmap generation
int regionSizeX = (int)m_scene.RegionInfo.RegionSizeX;
int regionSizeY = (int)m_scene.RegionInfo.RegionSizeY;
int landTileSize = LandManagementModule.landUnit;
int regionLandTilesX = regionSizeX / landTileSize;
int regionLandTilesY = regionSizeY / landTileSize;
using (Bitmap overlay = new Bitmap(regionSizeX, regionSizeY))
{ {
bool[,] saleBitmap = new bool[64, 64]; bool[,] saleBitmap = new bool[regionLandTilesX, regionLandTilesY];
for (int x = 0 ; x < 64 ; x++) for (int x = 0; x < regionLandTilesX; x++)
{ {
for (int y = 0 ; y < 64 ; y++) for (int y = 0; y < regionLandTilesY; y++)
saleBitmap[x, y] = false; saleBitmap[x, y] = false;
} }
@ -1596,7 +1657,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
using (Graphics g = Graphics.FromImage(overlay)) using (Graphics g = Graphics.FromImage(overlay))
{ {
using (SolidBrush transparent = new SolidBrush(background)) using (SolidBrush transparent = new SolidBrush(background))
g.FillRectangle(transparent, 0, 0, 256, 256); g.FillRectangle(transparent, 0, 0, regionSizeX, regionSizeY);
foreach (ILandObject land in parcels) foreach (ILandObject land in parcels)
@ -1620,12 +1681,17 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9))) using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)))
{ {
for (int x = 0 ; x < 64 ; x++) for (int x = 0; x < regionLandTilesX ; x++)
{ {
for (int y = 0 ; y < 64 ; y++) for (int y = 0; y < regionLandTilesY ; y++)
{ {
if (saleBitmap[x, y]) if (saleBitmap[x, y])
g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4); g.FillRectangle(
yellow,
x * landTileSize,
regionSizeX - landTileSize - (y * landTileSize),
landTileSize,
landTileSize);
} }
} }
} }