mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 02:36:00 +08:00
replace util.clip by utils.clamp (from libomv), and a few more cosmetics
This commit is contained in:
@@ -1116,35 +1116,41 @@ namespace OpenSim.Framework
|
||||
return true;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double UnixTimeSinceEpochSecs()
|
||||
{
|
||||
TimeSpan t = DateTime.UtcNow - UnixEpoch;
|
||||
return t.TotalSeconds;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int UnixTimeSinceEpoch()
|
||||
{
|
||||
TimeSpan t = DateTime.UtcNow - UnixEpoch;
|
||||
return (int)t.TotalSeconds;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong UnixTimeSinceEpoch_uS()
|
||||
{
|
||||
TimeSpan t = DateTime.UtcNow - UnixEpoch;
|
||||
return (ulong)(t.TotalMilliseconds * 1000);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ToUnixTime(DateTime stamp)
|
||||
{
|
||||
TimeSpan t = stamp.ToUniversalTime() - UnixEpoch;
|
||||
return (int)t.TotalSeconds;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DateTime ToDateTime(ulong seconds)
|
||||
{
|
||||
return UnixEpoch.AddSeconds(seconds);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DateTime ToDateTime(int seconds)
|
||||
{
|
||||
return UnixEpoch.AddSeconds(seconds);
|
||||
@@ -1155,7 +1161,7 @@ namespace OpenSim.Framework
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string Md5Hash(string data)
|
||||
{
|
||||
return Md5Hash(data, Encoding.Default);
|
||||
@@ -1170,6 +1176,7 @@ namespace OpenSim.Framework
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static byte[] ComputeMD5Hash(string data, Encoding encoding)
|
||||
{
|
||||
using (MD5 md5 = MD5.Create())
|
||||
@@ -1237,11 +1244,13 @@ namespace OpenSim.Framework
|
||||
return new string(chars);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string SHA1Hash(string data, Encoding enc)
|
||||
{
|
||||
return SHA1Hash(enc.GetBytes(data));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string SHA1Hash(string data)
|
||||
{
|
||||
return SHA1Hash(Encoding.Default.GetBytes(data));
|
||||
@@ -1266,6 +1275,7 @@ namespace OpenSim.Framework
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static UUID ComputeSHA1UUID(string src)
|
||||
{
|
||||
return ComputeSHA1UUID(Encoding.Default.GetBytes(src));
|
||||
@@ -1332,6 +1342,7 @@ namespace OpenSim.Framework
|
||||
return false;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string FieldToString(byte[] bytes)
|
||||
{
|
||||
return FieldToString(bytes, String.Empty);
|
||||
@@ -1416,6 +1427,7 @@ namespace OpenSim.Framework
|
||||
/// </summary>
|
||||
/// <param name="url">URL Standard Format</param>
|
||||
/// <returns>A resolved IP Address</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IPAddress GetHostFromURL(string url)
|
||||
{
|
||||
return GetHostFromDNS(url.Split(new char[] { '/', ':' })[3]);
|
||||
@@ -1544,6 +1556,7 @@ namespace OpenSim.Framework
|
||||
return getEndPoint(ia, port);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Uri GetURI(string protocol, string hostname, int port, string path)
|
||||
{
|
||||
return new UriBuilder(protocol, hostname, port, path).Uri;
|
||||
@@ -1553,6 +1566,7 @@ namespace OpenSim.Framework
|
||||
/// Gets a list of all local system IP addresses
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IPAddress[] GetLocalHosts()
|
||||
{
|
||||
return Dns.GetHostAddresses(Dns.GetHostName());
|
||||
@@ -1641,6 +1655,7 @@ namespace OpenSim.Framework
|
||||
/// </summary>
|
||||
/// <param name="path">path</param>
|
||||
/// <returns>safe path</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string SafePath(string path)
|
||||
{
|
||||
return Regex.Replace(path, regexInvalidPathChars, String.Empty);
|
||||
@@ -1651,6 +1666,7 @@ namespace OpenSim.Framework
|
||||
/// </summary>
|
||||
/// <param name="path">filename</param>
|
||||
/// <returns>safe filename</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string SafeFileName(string filename)
|
||||
{
|
||||
return Regex.Replace(filename, regexInvalidFileChars, String.Empty);
|
||||
@@ -1669,21 +1685,25 @@ namespace OpenSim.Framework
|
||||
return temp;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string assetsDir()
|
||||
{
|
||||
return Path.Combine(configDir(), "assets");
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string inventoryDir()
|
||||
{
|
||||
return Path.Combine(configDir(), "inventory");
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string configDir()
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string dataDir()
|
||||
{
|
||||
return ".";
|
||||
@@ -1715,6 +1735,7 @@ namespace OpenSim.Framework
|
||||
return "./OpenSimStats.log";
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string logDir()
|
||||
{
|
||||
return Path.GetDirectoryName(logFile());
|
||||
@@ -1987,22 +2008,6 @@ namespace OpenSim.Framework
|
||||
|
||||
#endregion
|
||||
|
||||
public static float Clip(float x, float min, float max)
|
||||
{
|
||||
return Math.Min(Math.Max(x, min), max);
|
||||
}
|
||||
|
||||
public static int Clip(int x, int min, int max)
|
||||
{
|
||||
return Math.Min(Math.Max(x, min), max);
|
||||
}
|
||||
|
||||
public static Vector3 Clip(Vector3 vec, float min, float max)
|
||||
{
|
||||
return new Vector3(Clip(vec.X, min, max), Clip(vec.Y, min, max),
|
||||
Clip(vec.Z, min, max));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert an UUID to a raw uuid string. Right now this is a string without hyphens.
|
||||
/// </summary>
|
||||
|
||||
@@ -234,10 +234,9 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
|
||||
SceneObjectPart part = s.GetSceneObjectPart(objectID);
|
||||
if (part != null)
|
||||
{
|
||||
ObjectRegionName = s.RegionInfo.RegionName;
|
||||
uint localX = s.RegionInfo.WorldLocX;
|
||||
uint localY = s.RegionInfo.WorldLocY;
|
||||
ObjectRegionName = ObjectRegionName + " (" + localX + ", " + localY + ")";
|
||||
RegionInfo sri = s.RegionInfo;
|
||||
ObjectRegionName = sri.RegionName;
|
||||
ObjectRegionName = ObjectRegionName + " (" + sri.WorldLocX + ", " + sri.WorldLocY + ")";
|
||||
return part;
|
||||
}
|
||||
}
|
||||
@@ -261,13 +260,11 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
|
||||
}
|
||||
|
||||
public static bool smptValidateServerCertificate(object sender, X509Certificate certificate,
|
||||
X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
if ((sslPolicyErrors & m_SMTP_SslPolicyErrorsMask) == SslPolicyErrors.None)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return (sslPolicyErrors & m_SMTP_SslPolicyErrorsMask) == SslPolicyErrors.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendMail function utilized by llEMail
|
||||
/// </summary>
|
||||
@@ -352,15 +349,14 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
|
||||
{
|
||||
// inter object email, keep it in the family
|
||||
Email email = new Email();
|
||||
email.time = ((int)((DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds)).ToString();
|
||||
email.time = Util.UnixTimeSinceEpoch().ToString();
|
||||
email.subject = subject;
|
||||
email.sender = objectID.ToString() + "@" + m_InterObjectHostname;
|
||||
email.message = "Object-Name: " + LastObjectName +
|
||||
"\nRegion: " + LastObjectRegionName + "\nLocal-Position: " +
|
||||
LastObjectPosition + "\n\n" + body;
|
||||
|
||||
string guid = address.Substring(0, address.IndexOf("@"));
|
||||
UUID toID = new UUID(guid);
|
||||
UUID toID = new UUID(mailTo.Name);
|
||||
|
||||
if (IsLocal(toID)) // TODO FIX check to see if it is local
|
||||
{
|
||||
|
||||
@@ -301,7 +301,7 @@ namespace OpenSim.Region.CoreModules.World.Sound
|
||||
if (!m_scene.TryGetSceneObjectPart(objectID, out part))
|
||||
return;
|
||||
|
||||
volume = Util.Clip((float)volume, 0, 1);
|
||||
volume = Utils.Clamp(volume, 0, 1);
|
||||
|
||||
UUID parentID = part.ParentGroup.UUID;
|
||||
|
||||
|
||||
@@ -3807,9 +3807,9 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// <param name="alpha"></param>
|
||||
public void SetFaceColorAlpha(int face, Vector3 color, double ?alpha)
|
||||
{
|
||||
Vector3 clippedColor = Util.Clip(color, 0.0f, 1.0f);
|
||||
Vector3 clippedColor = Vector3.Clamp(color, 0.0f, 1.0f);
|
||||
float clippedAlpha = alpha.HasValue ?
|
||||
Util.Clip((float)alpha.Value, 0.0f, 1.0f) : 0;
|
||||
Utils.Clamp((float)alpha.Value, 0.0f, 1.0f) : 0;
|
||||
|
||||
// The only way to get a deep copy/ If we don't do this, we can
|
||||
// never detect color changes further down.
|
||||
|
||||
@@ -1756,8 +1756,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_X:
|
||||
this.LockedLinearAxis.X = LockedAxis;
|
||||
this.LockedLinearAxisLow.X = Util.Clip(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.X = Util.Clip(high, -linearMax, linearMax);
|
||||
this.LockedLinearAxisLow.X = OMV.Utils.Clamp(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.X = OMV.Utils.Clamp(high, -linearMax, linearMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Y:
|
||||
this.LockedLinearAxis.Y = LockedAxis;
|
||||
@@ -1766,8 +1766,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Y:
|
||||
this.LockedLinearAxis.Y = LockedAxis;
|
||||
this.LockedLinearAxisLow.Y = Util.Clip(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.Y = Util.Clip(high, -linearMax, linearMax);
|
||||
this.LockedLinearAxisLow.Y = OMV.Utils.Clamp(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.Y = OMV.Utils.Clamp(high, -linearMax, linearMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Z:
|
||||
this.LockedLinearAxis.Z = LockedAxis;
|
||||
@@ -1776,8 +1776,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Z:
|
||||
this.LockedLinearAxis.Z = LockedAxis;
|
||||
this.LockedLinearAxisLow.Z = Util.Clip(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.Z = Util.Clip(high, -linearMax, linearMax);
|
||||
this.LockedLinearAxisLow.Z = OMV.Utils.Clamp(low, -linearMax, linearMax);
|
||||
this.LockedLinearAxisHigh.Z = OMV.Utils.Clamp(high, -linearMax, linearMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR:
|
||||
this.LockedAngularAxis = new OMV.Vector3(LockedAxis, LockedAxis, LockedAxis);
|
||||
@@ -1791,8 +1791,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_X:
|
||||
this.LockedAngularAxis.X = LockedAxis;
|
||||
this.LockedAngularAxisLow.X = Util.Clip(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.X = Util.Clip(high, -angularMax, angularMax);
|
||||
this.LockedAngularAxisLow.X = OMV.Utils.Clamp(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.X = OMV.Utils.Clamp(high, -angularMax, angularMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Y:
|
||||
this.LockedAngularAxis.Y = LockedAxis;
|
||||
@@ -1801,8 +1801,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Y:
|
||||
this.LockedAngularAxis.Y = LockedAxis;
|
||||
this.LockedAngularAxisLow.Y = Util.Clip(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.Y = Util.Clip(high, -angularMax, angularMax);
|
||||
this.LockedAngularAxisLow.Y = OMV.Utils.Clamp(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.Y = OMV.Utils.Clamp(high, -angularMax, angularMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Z:
|
||||
this.LockedAngularAxis.Z = LockedAxis;
|
||||
@@ -1811,8 +1811,8 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Z:
|
||||
this.LockedAngularAxis.Z = LockedAxis;
|
||||
this.LockedAngularAxisLow.Z = Util.Clip(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.Z = Util.Clip(high, -angularMax, angularMax);
|
||||
this.LockedAngularAxisLow.Z = OMV.Utils.Clamp(low, -angularMax, angularMax);
|
||||
this.LockedAngularAxisHigh.Z = OMV.Utils.Clamp(high, -angularMax, angularMax);
|
||||
break;
|
||||
case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR:
|
||||
this.LockedLinearAxis = LockedAxisFree;
|
||||
|
||||
@@ -2667,9 +2667,9 @@ Console.WriteLine(" JointCreateFixed");
|
||||
|
||||
SafeNativeMethods.AllocateODEDataForThread(0);
|
||||
|
||||
_position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
|
||||
_position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
|
||||
_position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
|
||||
_position.X = Utils.Clamp(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
|
||||
_position.Y = Utils.Clamp(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
|
||||
_position.Z = Utils.Clamp(_position.Z + 0.2f, -100f, 50000f);
|
||||
|
||||
m_lastposition = _position;
|
||||
_velocity.X = 0;
|
||||
|
||||
@@ -1159,9 +1159,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
m_bodydisablecontrol = 0;
|
||||
|
||||
SafeNativeMethods.Vector3 dtmp = SafeNativeMethods.BodyGetPosition(Body);
|
||||
Vector3 localpos = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
|
||||
|
||||
// the Amotor still lets avatar rotation to drift during colisions
|
||||
// so force it back to identity
|
||||
|
||||
@@ -1172,10 +1169,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
qtmp.Z = m_orientation2D.Z;
|
||||
SafeNativeMethods.BodySetQuaternion(Body,ref qtmp);
|
||||
|
||||
if(m_pidControllerActive == false)
|
||||
{
|
||||
_zeroPosition = localpos;
|
||||
}
|
||||
SafeNativeMethods.Vector3 dtmp = SafeNativeMethods.BodyGetPosition(Body);
|
||||
Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
|
||||
|
||||
// check outbounds forcing to be in world
|
||||
bool fixbody = false;
|
||||
@@ -1220,6 +1215,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
localpos.Z = 128f;
|
||||
}
|
||||
|
||||
if (m_pidControllerActive == false)
|
||||
{
|
||||
_zeroPosition = localpos;
|
||||
}
|
||||
|
||||
if (fixbody)
|
||||
{
|
||||
m_freemove = false;
|
||||
|
||||
@@ -972,9 +972,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (m_outbounds)
|
||||
{
|
||||
_position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
|
||||
_position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
|
||||
_position.Z = Util.Clip(_position.Z + 0.2f, Constants.MinSimulationHeight, Constants.MaxSimulationHeight);
|
||||
_position.X = Utils.Clamp(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
|
||||
_position.Y = Utils.Clamp(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
|
||||
_position.Z = Utils.Clamp(_position.Z + 0.2f, Constants.MinSimulationHeight, Constants.MaxSimulationHeight);
|
||||
|
||||
m_lastposition = _position;
|
||||
_velocity.X = 0;
|
||||
@@ -3815,7 +3815,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
m_outbounds = true;
|
||||
|
||||
lpos.Z = Util.Clip(lpos.Z, -100f, 100000f);
|
||||
lpos.Z = Utils.Clamp(lpos.Z, -100f, 100000f);
|
||||
m_acceleration.X = 0;
|
||||
m_acceleration.Y = 0;
|
||||
m_acceleration.Z = 0;
|
||||
@@ -3845,22 +3845,22 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
if (lpos.X < 0f)
|
||||
{
|
||||
_position.X = Util.Clip(lpos.X, -2f, -0.1f);
|
||||
_position.X = Utils.Clamp(lpos.X, -2f, -0.1f);
|
||||
m_outbounds = true;
|
||||
}
|
||||
else if (lpos.X > _parent_scene.WorldExtents.X)
|
||||
{
|
||||
_position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
|
||||
_position.X = Utils.Clamp(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
|
||||
m_outbounds = true;
|
||||
}
|
||||
if (lpos.Y < 0f)
|
||||
{
|
||||
_position.Y = Util.Clip(lpos.Y, -2f, -0.1f);
|
||||
_position.Y = Utils.Clamp(lpos.Y, -2f, -0.1f);
|
||||
m_outbounds = true;
|
||||
}
|
||||
else if (lpos.Y > _parent_scene.WorldExtents.Y)
|
||||
{
|
||||
_position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
|
||||
_position.Y = Utils.Clamp(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
|
||||
m_outbounds = true;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user