Added support for terrain map to be serialised to xml(as base64 binary). useful for places that the terrain map is needed in a serialised form. Also could add console commands to save and load from files, which should be faster than .raw files (these load/save commands are not included/implemented)

Add util functions to compress and uncompress strings. 
Fixed a couple of modules so they use SceneCommunicationService rather than directly call functions on the CommsManager.
0.6.0-stable
MW 2008-06-25 19:33:19 +00:00
parent 5158aad662
commit 7a9922af27
7 changed files with 127 additions and 5 deletions

View File

@ -28,6 +28,7 @@
using System; using System;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Reflection; using System.Reflection;
@ -618,6 +619,47 @@ namespace OpenSim.Framework
return ret; return ret;
} }
public static string Compress(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
MemoryStream memory = new MemoryStream();
using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
{
compressor.Write(buffer, 0, buffer.Length);
}
memory.Position = 0;
MemoryStream outStream = new MemoryStream();
byte[] compressed = new byte[memory.Length];
memory.Read(compressed, 0, compressed.Length);
byte[] compressedBuffer = new byte[compressed.Length + 4];
System.Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
return Convert.ToBase64String(compressedBuffer);
}
public static string Decompress(string compressedText)
{
byte[] compressedBuffer = Convert.FromBase64String(compressedText);
using (MemoryStream memory = new MemoryStream())
{
int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
byte[] buffer = new byte[msgLength];
memory.Position = 0;
using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
{
decompressor.Read(buffer, 0, buffer.Length);
}
return Encoding.UTF8.GetString(buffer);
}
}
public static string[] ParseStartLocationRequest(string startLocationRequest) public static string[] ParseStartLocationRequest(string startLocationRequest)
{ {
string[] returnstring = new string[4]; string[] returnstring = new string[4];

View File

@ -36,5 +36,7 @@ namespace OpenSim.Region.Environment.Interfaces
double[,] GetDoubles(); double[,] GetDoubles();
bool Tainted(int x, int y); bool Tainted(int x, int y);
ITerrainChannel MakeCopy(); ITerrainChannel MakeCopy();
string SaveToXmlString();
void LoadFromXmlString(string data);
} }
} }

View File

@ -523,7 +523,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
{ {
if (upd.AgentOnline) if (upd.AgentOnline)
{ {
RegionInfo reginfo = m_scenes[0].CommsManager.GridService.RequestNeighbourInfo(upd.Handle); RegionInfo reginfo = m_scenes[0].SceneGridService.RequestNeighbouringRegionInfo(upd.Handle);
if (reginfo != null) if (reginfo != null)
{ {
GridInstantMessage msg = new GridInstantMessage(); GridInstantMessage msg = new GridInstantMessage();

View File

@ -950,8 +950,6 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions
return true; return true;
} }
} }
} }

View File

@ -27,6 +27,11 @@
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Interfaces;
using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
namespace OpenSim.Region.Environment.Modules.World.Terrain namespace OpenSim.Region.Environment.Modules.World.Terrain
{ {
@ -151,5 +156,75 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
return copy; return copy;
} }
public string SaveToXmlString()
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (StringWriter sw = new StringWriter())
{
using (XmlWriter writer = XmlWriter.Create(sw, settings))
{
WriteXml(writer);
}
string output = sw.ToString();
return output;
}
}
private void WriteXml(XmlWriter writer)
{
writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
ToXml(writer);
writer.WriteEndElement();
}
public void LoadFromXmlString(string data)
{
StringReader sr = new StringReader(data);
XmlTextReader reader = new XmlTextReader(sr);
reader.Read();
ReadXml(reader);
reader.Close();
sr.Close();
}
private void ReadXml(XmlReader reader)
{
reader.ReadStartElement("TerrainMap");
FromXml(reader);
}
private void ToXml(XmlWriter xmlWriter)
{
float[] mapData = GetFloatsSerialised();
byte[] buffer = new byte[mapData.Length * 4];
for (int i = 0; i < mapData.Length; i++)
{
byte[] value = BitConverter.GetBytes(mapData[i]);
Array.Copy(value, 0, buffer, (i * 4), 4);
}
XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
serializer.Serialize(xmlWriter, buffer);
}
private void FromXml(XmlReader xmlReader)
{
XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
int index = 0;
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
float value;
value = BitConverter.ToSingle(dataArray, index);
index += 4;
this[x, y] = (double)value;
}
}
}
} }
} }

View File

@ -166,7 +166,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
{ {
List<MapBlockData> mapBlocks; List<MapBlockData> mapBlocks;
mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks((int)m_scene.RegionInfo.RegionLocX - 8, (int)m_scene.RegionInfo.RegionLocY - 8, (int)m_scene.RegionInfo.RegionLocX + 8, (int)m_scene.RegionInfo.RegionLocY + 8); mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks((int)m_scene.RegionInfo.RegionLocX - 8, (int)m_scene.RegionInfo.RegionLocY - 8, (int)m_scene.RegionInfo.RegionLocX + 8, (int)m_scene.RegionInfo.RegionLocY + 8);
avatarPresence.ControllingClient.SendMapBlock(mapBlocks); avatarPresence.ControllingClient.SendMapBlock(mapBlocks);
lock (cachedMapBlocks) lock (cachedMapBlocks)
@ -244,7 +244,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
{ {
List<MapBlockData> mapBlocks; List<MapBlockData> mapBlocks;
mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4); mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4);
remoteClient.SendMapBlock(mapBlocks); remoteClient.SendMapBlock(mapBlocks);
} }
public Hashtable OnHTTPGetMapImage(Hashtable keysvals) public Hashtable OnHTTPGetMapImage(Hashtable keysvals)

View File

@ -101,6 +101,11 @@ namespace OpenSim.Region.Environment.Scenes
protected SceneCommunicationService m_sceneGridService; protected SceneCommunicationService m_sceneGridService;
public SceneCommunicationService SceneGridService
{
get { return m_sceneGridService; }
}
/// <summary> /// <summary>
/// Each agent has its own capabilities handler. /// Each agent has its own capabilities handler.
/// </summary> /// </summary>