mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
save/load environments to/from oars
This commit is contained in:
@@ -126,7 +126,7 @@ namespace OpenSim.Framework.Serialization
|
||||
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2";
|
||||
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga";
|
||||
ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml";
|
||||
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Settings] = ASSET_EXTENSION_SEPARATOR + "settings.bin";
|
||||
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Settings] = ASSET_EXTENSION_SEPARATOR + "settings.dat";
|
||||
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation;
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart;
|
||||
@@ -148,7 +148,7 @@ namespace OpenSim.Framework.Serialization
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture;
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA;
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material;
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "settings.bin"] = (sbyte)AssetType.Settings;
|
||||
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "settings.dat"] = (sbyte)AssetType.Settings;
|
||||
}
|
||||
|
||||
public static string CreateOarLandDataPath(LandData ld)
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
|
||||
namespace OpenSim.Framework.Serialization.External
|
||||
{
|
||||
@@ -99,6 +97,9 @@ namespace OpenSim.Framework.Serialization.External
|
||||
m_ldProcessors.Add(
|
||||
"ParcelAccessList", ProcessParcelAccessList);
|
||||
|
||||
m_ldProcessors.Add(
|
||||
"Environment", ProcessParcelEnvironment);
|
||||
|
||||
m_ldProcessors.Add(
|
||||
"PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours")));
|
||||
m_ldProcessors.Add(
|
||||
@@ -132,6 +133,13 @@ namespace OpenSim.Framework.Serialization.External
|
||||
);
|
||||
m_laeProcessors.Add(
|
||||
"AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList")));
|
||||
|
||||
}
|
||||
|
||||
public static void ProcessParcelEnvironment(LandData ld, XmlReader xtr)
|
||||
{
|
||||
string senv = xtr.ReadElementString("Environment");
|
||||
ld.Environment = ViewerEnvironment.FromOSDString(senv);
|
||||
}
|
||||
|
||||
public static void ProcessParcelAccessList(LandData ld, XmlReader xtr)
|
||||
@@ -255,6 +263,15 @@ namespace OpenSim.Framework.Serialization.External
|
||||
xtw.WriteElementString("Dwell", "0");
|
||||
xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime));
|
||||
|
||||
if(landData.Environment != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string senv = ViewerEnvironment.ToOSDString(landData.Environment);
|
||||
xtw.WriteElementString("Environment", senv);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Close();
|
||||
|
||||
@@ -46,9 +46,10 @@ namespace OpenSim.Framework.Serialization.External
|
||||
/// <param name="serializedSettings"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.Xml.XmlException"></exception>
|
||||
public static RegionSettings Deserialize(byte[] serializedSettings)
|
||||
public static RegionSettings Deserialize(byte[] serializedSettings, out ViewerEnvironment regionEnv)
|
||||
{
|
||||
return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length));
|
||||
// encoding is wrong. old oars seem to be on utf-16
|
||||
return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length), out regionEnv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,9 +58,10 @@ namespace OpenSim.Framework.Serialization.External
|
||||
/// <param name="serializedSettings"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.Xml.XmlException"></exception>
|
||||
public static RegionSettings Deserialize(string serializedSettings)
|
||||
public static RegionSettings Deserialize(string serializedSettings, out ViewerEnvironment regionEnv)
|
||||
{
|
||||
RegionSettings settings = new RegionSettings();
|
||||
regionEnv = null;
|
||||
|
||||
StringReader sr = new StringReader(serializedSettings);
|
||||
XmlTextReader xtr = new XmlTextReader(sr);
|
||||
@@ -210,13 +212,28 @@ namespace OpenSim.Framework.Serialization.External
|
||||
}
|
||||
}
|
||||
|
||||
if (xtr.IsStartElement("Environment"))
|
||||
{
|
||||
xtr.ReadStartElement("Environment");
|
||||
|
||||
while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
|
||||
{
|
||||
switch (xtr.Name)
|
||||
{
|
||||
case "data":
|
||||
regionEnv = ViewerEnvironment.FromOSDString(xtr.ReadElementContentAsString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xtr.Close();
|
||||
sr.Close();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static string Serialize(RegionSettings settings)
|
||||
public static string Serialize(RegionSettings settings, ViewerEnvironment RegionEnv)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlTextWriter xtw = new XmlTextWriter(sw);
|
||||
@@ -263,8 +280,6 @@ namespace OpenSim.Framework.Serialization.External
|
||||
xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString());
|
||||
xtw.WriteElementString("FixedSun", settings.FixedSun.ToString());
|
||||
xtw.WriteElementString("SunPosition", settings.SunPosition.ToString());
|
||||
// Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which
|
||||
// calculates it automatically according to the date and other factors.
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("Telehub");
|
||||
@@ -276,6 +291,13 @@ namespace OpenSim.Framework.Serialization.External
|
||||
}
|
||||
xtw.WriteEndElement();
|
||||
|
||||
if (RegionEnv != null)
|
||||
{
|
||||
xtw.WriteStartElement("Environment");
|
||||
xtw.WriteElementString("data", ViewerEnvironment.ToOSDString(RegionEnv));
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Close();
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace OpenSim.Framework.Serialization.Tests
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
RegionSettings deserRs = RegionSettingsSerializer.Deserialize(m_serializedRs);
|
||||
RegionSettings deserRs = RegionSettingsSerializer.Deserialize(m_serializedRs, out ViewerEnvironment dummy);
|
||||
Assert.That(deserRs, Is.Not.Null);
|
||||
Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2));
|
||||
Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics));
|
||||
|
||||
@@ -3381,6 +3381,14 @@ namespace OpenSim.Framework
|
||||
return ticks * TimeStampClockPeriodMS;
|
||||
}
|
||||
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
public static void AddToGatheredIds(Dictionary<UUID, sbyte> uuids, UUID id, sbyte type)
|
||||
{
|
||||
if (id == UUID.Zero)
|
||||
return;
|
||||
uuids[id] = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a duration (given in milliseconds).
|
||||
/// </summary>
|
||||
@@ -3976,7 +3984,5 @@ namespace OpenSim.Framework
|
||||
{
|
||||
rng.GetBytes(buff);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,6 +484,16 @@ namespace OpenSim.Framework
|
||||
sunlight_color = otmp;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
|
||||
{
|
||||
Util.AddToGatheredIds(uuids, bloom_id, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, cloud_id, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, halo_id, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, moon_id, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, rainbow_id, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, sun_id, (sbyte)AssetType.Texture);
|
||||
}
|
||||
}
|
||||
|
||||
public class WaterData
|
||||
@@ -599,6 +609,12 @@ namespace OpenSim.Framework
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
|
||||
{
|
||||
Util.AddToGatheredIds(uuids, normalMap, (sbyte)AssetType.Texture);
|
||||
Util.AddToGatheredIds(uuids, transpTexture, (sbyte)AssetType.Texture);
|
||||
}
|
||||
}
|
||||
|
||||
public class DayCycle
|
||||
@@ -889,6 +905,18 @@ namespace OpenSim.Framework
|
||||
|
||||
return cycle;
|
||||
}
|
||||
|
||||
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
|
||||
{
|
||||
foreach (WaterData wd in waterframes.Values)
|
||||
{
|
||||
wd.GatherAssets(uuids);
|
||||
}
|
||||
foreach (SkyData sd in skyframes.Values)
|
||||
{
|
||||
sd.GatherAssets(uuids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewerEnvironment
|
||||
@@ -1216,6 +1244,35 @@ namespace OpenSim.Framework
|
||||
return env;
|
||||
}
|
||||
|
||||
public static ViewerEnvironment FromOSDString(string s)
|
||||
{
|
||||
try
|
||||
{
|
||||
OSD eosd = OSDParser.Deserialize(s);
|
||||
ViewerEnvironment VEnv = new ViewerEnvironment();
|
||||
VEnv.FromOSD(eosd);
|
||||
return VEnv;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string ToOSDString(ViewerEnvironment VEnv, bool xml = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
OSD eosd= VEnv.ToOSD();
|
||||
if(xml)
|
||||
return OSDParser.SerializeLLSDXmlString(eosd);
|
||||
else
|
||||
return OSDParser.SerializeLLSDNotationFull(eosd);
|
||||
}
|
||||
catch {}
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public ViewerEnvironment Clone()
|
||||
{
|
||||
// im lazy need to proper clone later
|
||||
@@ -1398,5 +1455,11 @@ namespace OpenSim.Framework
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
|
||||
{
|
||||
if (Cycle != null)
|
||||
Cycle.GatherAssets(uuids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,14 +285,13 @@ namespace OpenSim.Framework
|
||||
if (tickdiff > LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {7} bytes ({8} uncomp): {9}",
|
||||
"[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4} bytes ({5} uncomp): {6}",
|
||||
reqnum,
|
||||
method,
|
||||
url,
|
||||
tickdiff,
|
||||
compsize,
|
||||
strBuffer != null ? strBuffer.Length : 0,
|
||||
|
||||
strBuffer != null
|
||||
? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
|
||||
: "");
|
||||
|
||||
Reference in New Issue
Block a user