From 6702b0373371fd2a546a580ad82f5cc175fa29e0 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Wed, 19 Dec 2007 08:44:25 +0000
Subject: Misc. cleanup: * added Util.Clip(value, min, max) * modified asset
cache's numPackets calculation to use max packet size (600) instead of 1000 *
removed a few magic numbers
---
.../RemoteController/RemoteAdminPlugin.cs | 4 +-
.../Framework/Communications/Cache/AssetCache.cs | 60 ++++-----------
OpenSim/Framework/Data.DB4o/DB4oUserData.cs | 2 +-
OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 4 +-
OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 4 +-
OpenSim/Framework/Data.SQLite/SQLiteUserData.cs | 2 +-
OpenSim/Framework/Data/GridData.cs | 4 +-
OpenSim/Framework/Remoting.cs | 2 +-
OpenSim/Framework/Util.cs | 10 +++
OpenSim/Region/ClientStack/ClientView.cs | 29 ++-----
.../Region/Environment/Scenes/AvatarAppearance.cs | 4 +-
OpenSim/Region/Environment/Scenes/ScenePresence.cs | 36 ++++++---
.../BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 13 ++--
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 88 +++++++++++-----------
OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 7 +-
OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 22 ++++--
16 files changed, 136 insertions(+), 155 deletions(-)
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 2205683..8122b8a 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -122,7 +122,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
{
- MainLog.Instance.Verbose("RADMIN", "Recieved Shutdown Administrator Request");
+ MainLog.Instance.Verbose("RADMIN", "Received Shutdown Administrator Request");
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
@@ -170,7 +170,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
{
- MainLog.Instance.Verbose("RADMIN", "Recieved Create Region Administrator Request");
+ MainLog.Instance.Verbose("RADMIN", "Received Create Region Administrator Request");
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index abaea23..99356c2 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -36,7 +36,6 @@ using OpenSim.Framework.Console;
namespace OpenSim.Framework.Communications.Cache
{
-
public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
///
@@ -77,7 +76,6 @@ namespace OpenSim.Framework.Communications.Cache
m_assetCacheThread.IsBackground = true;
m_assetCacheThread.Start();
-
m_log = log;
}
@@ -100,7 +98,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
-
public AssetBase GetAsset(LLUUID assetID)
{
AssetBase asset = null;
@@ -154,7 +151,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
-
public AssetBase GetAsset(LLUUID assetID, bool isTexture)
{
AssetBase asset = GetAsset(assetID);
@@ -236,8 +232,6 @@ namespace OpenSim.Framework.Communications.Cache
return asset;
}
-
-
public void AssetReceived(AssetBase asset, bool IsTexture)
{
if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
@@ -249,7 +243,7 @@ namespace OpenSim.Framework.Communications.Cache
if (IsTexture)
{
- //Console.WriteLine("asset recieved from asset server");
+ //Console.WriteLine("asset received from asset server");
TextureImage image = new TextureImage(asset);
if (!Textures.ContainsKey(image.FullID))
@@ -260,7 +254,7 @@ namespace OpenSim.Framework.Communications.Cache
AssetRequest req = RequestedTextures[image.FullID];
req.ImageInfo = image;
- req.NumPackets = CalculateNumPackets(image.Data.Length);
+ req.NumPackets = CalculateNumPackets(image.Data);
RequestedTextures.Remove(image.FullID);
TextureRequests.Add(req);
@@ -277,15 +271,7 @@ namespace OpenSim.Framework.Communications.Cache
{
AssetRequest req = RequestedAssets[assetInf.FullID];
req.AssetInf = assetInf;
- if (assetInf.Data.LongLength > 600)
- {
- //over 600 bytes so split up file
- req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000;
- }
- else
- {
- req.NumPackets = 1;
- }
+ req.NumPackets = CalculateNumPackets(assetInf.Data);
RequestedAssets.Remove(assetInf.FullID);
AssetRequests.Add(req);
}
@@ -326,16 +312,17 @@ namespace OpenSim.Framework.Communications.Cache
//}
}
- private int CalculateNumPackets(int length)
+ private int CalculateNumPackets(byte[] data)
{
+ const uint m_maxPacketSize = 600;
int numPackets = 1;
- if (length > 600)
+ if (data.LongLength > m_maxPacketSize)
{
- //over 600 bytes so split up file
- int restData = (length - 600);
- int restPackets = ((restData + 999) / 1000);
- numPackets = 1 + restPackets;
+ // over max number of bytes so split up file
+ long restData = data.LongLength - m_maxPacketSize;
+ int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
+ numPackets += restPackets;
}
return numPackets;
@@ -385,8 +372,7 @@ namespace OpenSim.Framework.Communications.Cache
//it is in our cache
AssetInfo asset = Assets[requestID];
- //work out how many packets it should be sent in
- // and add to the AssetRequests list
+ // add to the AssetRequests list
AssetRequest req = new AssetRequest();
req.RequestUser = userInfo;
req.RequestAssetID = requestID;
@@ -394,17 +380,7 @@ namespace OpenSim.Framework.Communications.Cache
req.AssetRequestSource = source;
req.Params = transferRequest.TransferInfo.Params;
req.AssetInf = asset;
-
- if (asset.Data.LongLength > 600)
- {
- //over 600 bytes so split up file
- req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000;
- }
- else
- {
- req.NumPackets = 1;
- }
-
+ req.NumPackets = CalculateNumPackets(asset.Data);
AssetRequests.Add(req);
}
@@ -419,17 +395,9 @@ namespace OpenSim.Framework.Communications.Cache
//no requests waiting
return;
}
- int num;
+ // if less than 5, do all of them
+ int num = Math.Min(5, AssetRequests.Count);
- if (AssetRequests.Count < 5)
- {
- //lower than 5 so do all of them
- num = AssetRequests.Count;
- }
- else
- {
- num = 5;
- }
AssetRequest req;
for (int i = 0; i < num; i++)
{
diff --git a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
index 9e5a679..383bfbe 100644
--- a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
+++ b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
@@ -199,7 +199,7 @@ namespace OpenSim.Framework.Data.DB4o
///
/// Move to inventory server
/// Senders account
- /// Recievers account
+ /// Receivers account
/// Inventory item
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
index 80b65c1..ccab57b 100644
--- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
+++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
@@ -387,7 +387,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// Performs a money transfer request between two accounts
///
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The amount to transfer
/// Success?
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -400,7 +400,7 @@ namespace OpenSim.Framework.Data.MSSQL
///
/// TODO: Move to inventory server
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The item to transfer
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
index 6a7cf49..05e5127 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -363,7 +363,7 @@ namespace OpenSim.Framework.Data.MySQL
/// Performs a money transfer request between two accounts
///
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The amount to transfer
/// Success?
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -376,7 +376,7 @@ namespace OpenSim.Framework.Data.MySQL
///
/// TODO: Move to inventory server
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The item to transfer
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
index 346febc..99121be 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
@@ -320,7 +320,7 @@ namespace OpenSim.Framework.Data.SQLite
///
/// Move to inventory server
/// Senders account
- /// Recievers account
+ /// Receivers account
/// Inventory item
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data/GridData.cs b/OpenSim/Framework/Data/GridData.cs
index 1aebbda..7864dda 100644
--- a/OpenSim/Framework/Data/GridData.cs
+++ b/OpenSim/Framework/Data/GridData.cs
@@ -79,12 +79,12 @@ namespace OpenSim.Framework.Data
List GeneratePickerResults(LLUUID queryID, string query);
///
- /// Authenticates a sim by use of it's recv key.
+ /// Authenticates a sim by use of its recv key.
/// WARNING: Insecure
///
/// The UUID sent by the sim
/// The regionhandle sent by the sim
- /// The recieving key sent by the sim
+ /// The receiving key sent by the sim
/// Whether the sim has been authenticated
bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey);
diff --git a/OpenSim/Framework/Remoting.cs b/OpenSim/Framework/Remoting.cs
index aa7e947..9cf0d11 100644
--- a/OpenSim/Framework/Remoting.cs
+++ b/OpenSim/Framework/Remoting.cs
@@ -38,7 +38,7 @@ namespace OpenSim.Framework
/// Suggested implementation
/// Store two digests for each foreign host. A local copy of the local hash using the local challenge (when issued), and a local copy of the remote hash using the remote challenge.
/// When sending data to the foreign host - run 'Sign' on the data and affix the returned byte[] to the message.
- /// When recieving data from the foreign host - run 'Authenticate' against the data and the attached byte[].
+ /// When receiving data from the foreign host - run 'Authenticate' against the data and the attached byte[].
/// Both hosts should be performing these operations for this to be effective.
///
internal class RemoteDigest
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index a8eef51..740f527 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -373,5 +373,15 @@ namespace OpenSim.Framework
config.Configs[(string) row[0]].Set(row.Table.Columns[i].ColumnName, row[i]);
}
}
+
+ 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);
+ }
}
}
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
index 3c35270..75c4187 100644
--- a/OpenSim/Region/ClientStack/ClientView.cs
+++ b/OpenSim/Region/ClientStack/ClientView.cs
@@ -102,7 +102,6 @@ namespace OpenSim.Region.ClientStack
protected LLVector3 m_startpos;
protected EndPoint m_userEndPoint;
-
/* Properties */
public LLUUID SecureSessionId
{
@@ -181,7 +180,7 @@ namespace OpenSim.Region.ClientStack
// While working on this, the BlockingQueue had me fooled for a bit.
// The Blocking queue causes the thread to stop until there's something
- // in it to process. it's an on-purpose threadlock though because
+ // in it to process. It's an on-purpose threadlock though because
// without it, the clientloop will suck up all sim resources.
m_packetQueue = new PacketQueue();
@@ -193,7 +192,6 @@ namespace OpenSim.Region.ClientStack
m_clientThread.Start();
}
-
public void SetDebug(int newDebug)
{
m_debug = newDebug;
@@ -236,10 +234,8 @@ namespace OpenSim.Region.ClientStack
public void Kick(string message)
{
KickUserPacket kupack = new KickUserPacket();
-
kupack.UserInfo.AgentID = AgentId;
kupack.UserInfo.SessionID = SessionId;
-
kupack.TargetBlock.TargetIP = (uint)0;
kupack.TargetBlock.TargetPort = (ushort)0;
kupack.UserInfo.Reason = Helpers.StringToField(message);
@@ -345,7 +341,6 @@ namespace OpenSim.Region.ClientStack
QueItem nextPacket = m_packetQueue.Dequeue();
if (nextPacket.Incoming)
{
- //is a incoming packet
if (nextPacket.Packet.Type != PacketType.AgentUpdate)
{
m_packetsReceived++;
@@ -532,7 +527,6 @@ namespace OpenSim.Region.ClientStack
public event RegionInfoRequest OnRegionInfoRequest;
public event EstateCovenantRequest OnEstateCovenantRequest;
-
#region Scene/Avatar to Client
///
@@ -611,7 +605,6 @@ namespace OpenSim.Region.ClientStack
SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID);
}
-
public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
{
ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
@@ -666,7 +659,7 @@ namespace OpenSim.Region.ClientStack
for (int y = 0; y < 16; y++)
{
- for (int x = 0; x < 16; x = x + 4)
+ for (int x = 0; x < 16; x += 4)
{
patches[0] = x + 0 + y*16;
patches[1] = x + 1 + y*16;
@@ -766,7 +759,6 @@ namespace OpenSim.Region.ClientStack
newSimPack.Info = new CrossedRegionPacket.InfoBlock();
newSimPack.Info.Position = pos;
newSimPack.Info.LookAt = look;
- // new LLVector3(0.0f, 0.0f, 0.0f); // copied from Avatar.cs - SHOULD BE DYNAMIC!!!!!!!!!!
newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
newSimPack.RegionData.RegionHandle = newRegionHandle;
byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
@@ -775,7 +767,6 @@ namespace OpenSim.Region.ClientStack
newSimPack.RegionData.SimIP += (uint) byteIP[1] << 8;
newSimPack.RegionData.SimIP += (uint) byteIP[0];
newSimPack.RegionData.SimPort = (ushort) externalIPEndPoint.Port;
- //newSimPack.RegionData.SeedCapability = new byte[0];
newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL);
OutPacket(newSimPack, ThrottleOutPacketType.Task);
@@ -823,7 +814,6 @@ namespace OpenSim.Region.ClientStack
teleport.Info.SimAccess = simAccess;
teleport.Info.SeedCapability = Helpers.StringToField(capsURL);
- //teleport.Info.SeedCapability = new byte[0];
IPAddress oIP = newRegionEndPoint.Address;
byte[] byteIP = oIP.GetAddressBytes();
@@ -847,7 +837,6 @@ namespace OpenSim.Region.ClientStack
TeleportFailedPacket tpFailed = new TeleportFailedPacket();
tpFailed.Info.AgentID = this.AgentId;
tpFailed.Info.Reason = Helpers.StringToField("unknown failure of teleport");
-
OutPacket(tpFailed, ThrottleOutPacketType.Task);
}
@@ -946,7 +935,6 @@ namespace OpenSim.Region.ClientStack
descend.ItemData[i].SaleType = 0;
descend.ItemData[i].Type = (sbyte)item.assetType;
descend.ItemData[i].CRC =
-
Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
descend.ItemData[i].InvType, descend.ItemData[i].Type,
descend.ItemData[i].AssetID, descend.ItemData[i].GroupID, descend.ItemData[i].SalePrice,
@@ -1228,7 +1216,7 @@ namespace OpenSim.Region.ClientStack
Console.WriteLine("SunPhase: {0}", phase);
SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
//viewertime.TimeInfo.SecPerDay = 86400;
- // viewertime.TimeInfo.SecPerYear = 31536000;
+ //viewertime.TimeInfo.SecPerYear = 31536000;
viewertime.TimeInfo.SecPerDay = 1000;
viewertime.TimeInfo.SecPerYear = 365000;
viewertime.TimeInfo.SunPhase = 1;
@@ -1252,14 +1240,9 @@ namespace OpenSim.Region.ClientStack
{
yValue = yValue - 1.2f;
}
- if (yValue > 1)
- {
- yValue = 1;
- }
- if (yValue < 0)
- {
- yValue = 0;
- }
+
+ yValue = Util.Clip(yValue, 0, 1);
+
if (sunPhase < 14)
{
yValue = 1 - yValue;
diff --git a/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs b/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs
index b027845..2ec4dbe 100644
--- a/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs
+++ b/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs
@@ -88,7 +88,6 @@ namespace OpenSim.Region.Environment.Scenes
m_textureEntry = GetDefaultTextureEntry();
}
-
///
///
///
@@ -109,7 +108,6 @@ namespace OpenSim.Region.Environment.Scenes
// (float)m_visualParams[125] = LegLength
m_avatarHeight = (1.50856f + (((float)m_visualParams[25] / 255.0f) * (2.525506f - 1.50856f)))
+ (((float)m_visualParams[125] / 255.0f) / 1.5f);
-
}
///
@@ -119,7 +117,7 @@ namespace OpenSim.Region.Environment.Scenes
public void SendAppearanceToOtherAgent(ScenePresence avatar)
{
avatar.ControllingClient.SendAppearance(m_scenePresenceID, m_visualParams,
- m_textureEntry.ToBytes());
+ m_textureEntry.ToBytes());
}
public void SetWearable(IClientAPI client, int wearableId, AvatarWearable wearable)
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index 91b6463..89701d7 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -1233,25 +1233,37 @@ namespace OpenSim.Region.Environment.Scenes
uint neighbourx = m_regionInfo.RegionLocX;
uint neighboury = m_regionInfo.RegionLocY;
- if (pos.X < 1.7F)
+ // distance to edge that will trigger crossing
+ const float boundaryDistance = 1.7f;
+
+ // distance into new region to place avatar
+ const float enterDistance = 0.1f;
+
+ // region size
+ // TODO: this should be hard-coded in some common place
+ const float regionWidth = 256;
+ const float regionHeight = 256;
+
+ if (pos.X < boundaryDistance)
{
- neighbourx -= 1;
- newpos.X = 255.9F;
+ neighbourx--;
+ newpos.X = regionWidth - enterDistance;
}
- if (pos.X > 254.3F)
+ else if (pos.X > regionWidth - boundaryDistance)
{
- neighbourx += 1;
- newpos.X = 0.1F;
+ neighbourx++;
+ newpos.X = enterDistance;
}
- if (pos.Y < 1.7F)
+
+ if (pos.Y < boundaryDistance)
{
- neighboury -= 1;
- newpos.Y = 255.9F;
+ neighboury--;
+ newpos.Y = regionHeight - enterDistance;
}
- if (pos.Y > 254.3F)
+ else if (pos.Y > regionHeight - boundaryDistance)
{
- neighboury += 1;
- newpos.Y = 0.1F;
+ neighboury++;
+ newpos.Y = enterDistance;
}
LLVector3 vel = m_velocity;
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
index df3ebb9..545f461 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
@@ -125,8 +125,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
{
BasicActor actor = _actors[i];
- actor.Position.X = actor.Position.X + (actor.Velocity.X*timeStep);
- actor.Position.Y = actor.Position.Y + (actor.Velocity.Y*timeStep);
+ actor.Position.X += actor.Velocity.X * timeStep;
+ actor.Position.Y += actor.Velocity.Y * timeStep;
+
if (actor.Position.Y < 0)
{
actor.Position.Y = 0.1F;
@@ -145,18 +146,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
actor.Position.X = 255.9F;
}
- float height = _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 1.0f;
+ float height = _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 1.0f;
if (actor.Flying)
{
- if (actor.Position.Z + (actor.Velocity.Z*timeStep) <
- _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 2)
+ if (actor.Position.Z + (actor.Velocity.Z * timeStep) <
+ _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 2)
{
actor.Position.Z = height;
actor.Velocity.Z = 0;
}
else
{
- actor.Position.Z = actor.Position.Z + (actor.Velocity.Z*timeStep);
+ actor.Position.Z += actor.Velocity.Z * timeStep;
}
}
else
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0cbd4d6..305a930 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -75,6 +75,10 @@ namespace OpenSim.Region.Physics.OdePlugin
public class OdeScene : PhysicsScene
{
+ // TODO: this should be hard-coded in some common place
+ private const uint m_regionWidth = 256;
+ private const uint m_regionHeight = 256;
+
private static float ODE_STEPSIZE = 0.004f;
private static bool RENDER_FLAG = false;
private static float metersInSpace = 29.9f;
@@ -167,12 +171,9 @@ namespace OpenSim.Region.Physics.OdePlugin
}
-
-
public override void Initialise(IMesher meshmerizer)
{
mesher = meshmerizer;
-
}
public string whichspaceamIin(PhysicsVector pos)
@@ -196,7 +197,6 @@ namespace OpenSim.Region.Physics.OdePlugin
//Collide all geoms in each space..
//if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback);
//if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback);
-
}
else
{
@@ -206,14 +206,12 @@ namespace OpenSim.Region.Physics.OdePlugin
IntPtr b1 = d.GeomGetBody(g1);
IntPtr b2 = d.GeomGetBody(g2);
-
if (g1 == g2)
return; // Can't collide with yourself
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return;
-
d.GeomClassID id = d.GeomGetClass(g1);
String name1 = null;
@@ -230,8 +228,6 @@ namespace OpenSim.Region.Physics.OdePlugin
if (id == d.GeomClassID.TriMeshClass)
{
-
-
// MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
//System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
}
@@ -297,8 +293,6 @@ namespace OpenSim.Region.Physics.OdePlugin
TerrainContact.geom = contacts[i];
joint = d.JointCreateContact(world, contactgroup, ref TerrainContact);
}
-
-
}
else
{
@@ -311,9 +305,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
contact.geom = contacts[i];
joint = d.JointCreateContact(world, contactgroup, ref contact);
-
}
-
}
@@ -333,17 +325,12 @@ namespace OpenSim.Region.Physics.OdePlugin
private void collision_optimized(float timeStep)
{
-
foreach (OdeCharacter chr in _characters)
{
-
-
chr.IsColliding = false;
chr.CollidingGround = false;
chr.CollidingObj = false;
d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
-
-
}
// If the sim is running slow this frame,
// don't process collision for prim!
@@ -422,11 +409,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
+
public void RemovePrimThreadLocked(OdePrim prim)
{
lock (OdeLock)
{
-
if (prim.IsPhysical)
{
prim.disableBody();
@@ -479,6 +466,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+
public void resetSpaceArrayItemToZero(IntPtr space)
{
for (int x = 0; x < staticPrimspace.GetLength(0); x++)
@@ -490,6 +478,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
+
public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY)
{
staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
@@ -524,6 +513,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (!(sGeomIsIn.Equals(null)))
{
if (sGeomIsIn != (IntPtr)0)
+ {
if (d.GeomIsSpace(currentspace))
{
d.SpaceRemove(sGeomIsIn, geom);
@@ -532,6 +522,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString());
}
+ }
}
}
@@ -586,7 +577,6 @@ namespace OpenSim.Region.Physics.OdePlugin
else
{
MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString());
-
}
}
}
@@ -625,6 +615,7 @@ namespace OpenSim.Region.Physics.OdePlugin
//locationbasedspace = space;
return locationbasedspace;
}
+
public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos)
{
int[] returnint = new int[2];
@@ -682,7 +673,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
public void addActivePrim(OdePrim activatePrim)
- {
+ {
// adds active prim.. (ones that should be iterated over in collisions_optimized
_activeprims.Add(activatePrim);
@@ -902,17 +893,18 @@ namespace OpenSim.Region.Physics.OdePlugin
get { return (false); // for now we won't be multithreaded
}
}
+
public float[] ResizeTerrain512(float[] heightMap)
{
float[] returnarr = new float[262144];
- float[,] resultarr = new float[256, 256];
+ float[,] resultarr = new float[m_regionWidth, m_regionHeight];
// Filling out the array into it's multi-dimentional components
- for (int y = 0; y < 256; y++)
+ for (int y = 0; y < m_regionHeight; y++)
{
- for (int x = 0; x < 256; x++)
+ for (int x = 0; x < m_regionWidth; x++)
{
- resultarr[y,x] = heightMap[y * 256 + x];
+ resultarr[y,x] = heightMap[y * m_regionWidth + x];
}
}
@@ -976,17 +968,17 @@ namespace OpenSim.Region.Physics.OdePlugin
// on single loop.
float[,] resultarr2 = new float[512, 512];
- for (int y = 0; y < 256; y++)
+ for (int y = 0; y < m_regionHeight; y++)
{
- for (int x = 0; x < 256; x++)
+ for (int x = 0; x < m_regionWidth; x++)
{
resultarr2[y*2,x*2] = resultarr[y,x];
- if (y < 256)
+ if (y < m_regionHeight)
{
- if (y + 1 < 256)
+ if (y + 1 < m_regionHeight)
{
- if (x + 1 < 256)
+ if (x + 1 < m_regionWidth)
{
resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4);
}
@@ -1000,11 +992,11 @@ namespace OpenSim.Region.Physics.OdePlugin
resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x];
}
}
- if (x < 256)
+ if (x < m_regionWidth)
{
- if (x + 1 < 256)
+ if (x + 1 < m_regionWidth)
{
- if (y + 1 < 256)
+ if (y + 1 < m_regionHeight)
{
resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4);
}
@@ -1018,9 +1010,9 @@ namespace OpenSim.Region.Physics.OdePlugin
resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x];
}
}
- if (x < 256 && y < 256)
+ if (x < m_regionWidth && y < m_regionHeight)
{
- if ((x + 1 < 256) && (y + 1 < 256))
+ if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight))
{
resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4);
}
@@ -1052,21 +1044,26 @@ namespace OpenSim.Region.Physics.OdePlugin
// dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
// also, creating a buffer zone of one extra sample all around
+ const uint heightmapWidth = m_regionWidth + 2;
+ const uint heightmapHeight = m_regionHeight + 2;
+ const uint heightmapWidthSamples = 2 * m_regionWidth + 2;
+ const uint heightmapHeightSamples = 2 * m_regionHeight + 2;
+ const float scale = 1.0f;
+ const float offset = 0.0f;
+ const float thickness = 2.0f;
+ const int wrap = 0;
+
//Double resolution
heightMap = ResizeTerrain512(heightMap);
- for (int x = 0; x < 514; x++)
+ for (int x = 0; x < heightmapWidthSamples; x++)
{
- for (int y = 0; y < 514; y++)
+ for (int y = 0; y < heightmapHeightSamples; y++)
{
- int xx = x - 1;
- if (xx < 0) xx = 0;
- if (xx > 511) xx = 511;
- int yy = y - 1;
- if (yy < 0) yy = 0;
- if (yy > 511) yy = 511;
+ int xx = Util.Clip(x - 1, 0, 511);
+ int yy = Util.Clip(y - 1, 0, 511);
double val = (double) heightMap[yy*512 + xx];
- _heightmap[x*514 + y] = val;
+ _heightmap[x*heightmapHeightSamples + y] = val;
}
}
@@ -1077,8 +1074,9 @@ namespace OpenSim.Region.Physics.OdePlugin
d.SpaceRemove(space, LandGeom);
}
IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
- d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 514, 514, 1.0f, 0.0f, 2.0f, 0);
- d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
+ d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight,
+ (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, offset, thickness, wrap);
+ d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
geom_name_map[LandGeom] = "Terrain";
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
index efc30fe..a565598 100644
--- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
+++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
@@ -166,7 +166,6 @@ namespace OpenSim.Region.Physics.POSPlugin
public override void AddPhysicsActorTaint(PhysicsActor prim)
{
-
}
public override float Simulate(float timeStep)
@@ -187,8 +186,8 @@ namespace OpenSim.Region.Physics.POSPlugin
}
bool forcedZ = false;
- character.Position.X = character.Position.X + (character._target_velocity.X * timeStep);
- character.Position.Y = character.Position.Y + (character._target_velocity.Y * timeStep);
+ character.Position.X += character._target_velocity.X * timeStep;
+ character.Position.Y += character._target_velocity.Y * timeStep;
if (character.Position.Y < 0)
{
@@ -216,7 +215,7 @@ namespace OpenSim.Region.Physics.POSPlugin
}
else
{
- character.Position.Z = character.Position.Z + (character._target_velocity.Z * timeStep);
+ character.Position.Z += character._target_velocity.Z * timeStep;
}
/// this is it -- the magic you've all been waiting for! Ladies and gentlemen --
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 136b613..3a0b8ed 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -60,20 +60,22 @@ namespace OpenSim.Region.ScriptEngine.Common
{
return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">";
}
+
public static bool operator ==(Vector3 lhs, Vector3 rhs)
{
return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
}
+
public static bool operator !=(Vector3 lhs, Vector3 rhs)
{
return !(lhs == rhs);
}
+
public override int GetHashCode()
{
return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode());
}
-
public override bool Equals(object o)
{
if (!(o is Vector3)) return false;
@@ -91,10 +93,12 @@ namespace OpenSim.Region.ScriptEngine.Common
{
return new Vector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
}
+
public static Vector3 operator -(Vector3 lhs, Vector3 rhs)
{
return new Vector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
}
+
public static Vector3 operator *(Vector3 lhs, Vector3 rhs)
{
return new Vector3(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z);
@@ -145,6 +149,7 @@ namespace OpenSim.Region.ScriptEngine.Common
return new Vector3(result.x, result.y, result.z);
}
+
// I *think* this is how it works....
public static Vector3 operator /(Vector3 vec, Quaternion quat)
{
@@ -163,6 +168,7 @@ namespace OpenSim.Region.ScriptEngine.Common
{
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
}
+
public static Vector3 Cross(Vector3 v1, Vector3 v2)
{
return new Vector3
@@ -172,10 +178,12 @@ namespace OpenSim.Region.ScriptEngine.Common
v1.x * v2.y - v1.y * v2.x
);
}
+
public static float Mag(Vector3 v)
{
return (float)Math.Sqrt(v.x * v.y + v.y * v.y + v.z * v.z);
}
+
public static Vector3 Norm(Vector3 vector)
{
float mag = Mag(vector);
@@ -215,7 +223,6 @@ namespace OpenSim.Region.ScriptEngine.Common
return (x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode() ^ s.GetHashCode());
}
-
public override bool Equals(object o)
{
if (!(o is Quaternion)) return false;
@@ -224,6 +231,7 @@ namespace OpenSim.Region.ScriptEngine.Common
return x == quaternion.x && y == quaternion.y && z == quaternion.z && s == quaternion.s;
}
+
public override string ToString()
{
return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + s.ToString() + ">";
@@ -257,19 +265,23 @@ namespace OpenSim.Region.ScriptEngine.Common
public class list
{
private object[] m_data;
+
public list(params object[] args)
{
m_data = new object[args.Length];
m_data = args;
}
+
public int Length
{
get { return m_data.Length; }
}
+
public object[] Data
{
get { return m_data; }
}
+
public static list operator +(list a, list b)
{
object[] tmp;
@@ -278,6 +290,7 @@ namespace OpenSim.Region.ScriptEngine.Common
b.Data.CopyTo(tmp, a.Length);
return new list(tmp);
}
+
public list GetSublist(int start, int end)
{
Console.WriteLine("GetSublist(" + start.ToString() + "," + end.ToString() + ")");
@@ -292,8 +305,7 @@ namespace OpenSim.Region.ScriptEngine.Common
end = m_data.Length + end;
}
- // Case start < end
-
+ // Case start <= end
if (start <= end)
{
if (start >= m_data.Length)
@@ -350,6 +362,7 @@ namespace OpenSim.Region.ScriptEngine.Common
output = output + "]";
return output;
}
+
public override string ToString()
{
string output;
@@ -366,5 +379,4 @@ namespace OpenSim.Region.ScriptEngine.Common
}
}
}
-
}
--
cgit v1.1