From 22f5f7962ccbc420e86f232b46eb6a1d3ce3575d Mon Sep 17 00:00:00 2001 From: "Huaiyu (Kitty) Liu" Date: Fri, 3 Jun 2011 13:17:44 -0700 Subject: [PATCH] Added code so that collision events are only forwarded from PSA to script engines. --- .../SymmetricSync/RegionSyncModule.cs | 78 +++++++++++-------- .../SymmetricSync/ScriptEngineSyncModule.cs | 2 + .../SymmetricSync/SymmetricSyncMessage.cs | 1 + .../SymmetricSync/SyncConnector.cs | 20 ++++- OpenSim/Region/Framework/Scenes/Scene.cs | 17 ++++ 5 files changed, 85 insertions(+), 33 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index d101431635..85a90ff438 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -105,6 +105,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule int syncInfoAgeOutSeconds = m_sysConfig.GetInt("PrimSyncInfoAgeOutSeconds", 300); //unit of seconds TimeSpan tSpan = new TimeSpan(0, 0, syncInfoAgeOutSeconds); m_primSyncInfoManager = new PrimSyncInfoManager(this, tSpan.Ticks); + + //this is temp solution for reducing collision events for country fair demo + m_reportCollisions = m_sysConfig.GetString("ReportCollisions", "All"); } //Called after Initialise() @@ -558,37 +561,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private Dictionary> m_primPropertyUpdates = new Dictionary>(); private int m_sendingPrimPropertyUpdates = 0; - /////////////////////////////////////////////////////////////////////// - // Legacy members for bucket-based sync, - /////////////////////////////////////////////////////////////////////// + string m_reportCollisions = "All"; - private Dictionary m_primUpdateLocks = new Dictionary(); - private Dictionary> m_primUpdates = new Dictionary>(); - - private delegate void PrimUpdatePerBucketSender(string bucketName, List primUpdates); - private Dictionary m_primUpdatesPerBucketSender = new Dictionary(); - - private delegate void PrimUpdatePerBucketReceiver(string bucketName, OSDMap data); - private Dictionary m_primUpdatesPerBucketReceiver = new Dictionary(); - - //The functions that encode properties in each bucket. For now, - //general bucket works on SOG, physics bucket works on SOP, so we define - //the arg to be of type Object to be general in the interface. - //TO DO: redesign the interface once the bucket encoders working on more - //consistent/specific arguments. - private delegate OSDMap UpdatePerBucketEncoder(string bucketName, Object arg); - private Dictionary m_updatePerBucketEncoder = new Dictionary(); - - //Decoders of properties in each bucket - private delegate void UpdatePerBucketDecoder(string bucketName, OSDMap data, out Object outData); - private Dictionary m_updatePerBucketDecoder = new Dictionary(); - - - private object m_updateScenePresenceLock = new object(); - private Dictionary m_presenceUpdates = new Dictionary(); - private int m_sendingUpdates = 0; - - private int m_maxNumOfPropertyBuckets; ///////////////////////////////////////////////////////////////////////////////////////// // Synchronization related functions, NOT exposed through IRegionSyncModule interface @@ -754,8 +728,21 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule foreach (SyncConnector connector in syncConnectors) { - lock (m_stats) m_statEventOut++; - connector.Send(rsm); + //special fix for demo, need better optimization later + if (rsm.Type == SymmetricSyncMessage.MsgType.PhysicsCollision && m_isSyncRelay) + { + //for persistence actor, only forward collision events to script engines + if (connector.OtherSideActorType == ScriptEngineSyncModule.ActorTypeString) + { + lock (m_stats) m_statEventOut++; + connector.Send(rsm); + } + } + else + { + lock (m_stats) m_statEventOut++; + connector.Send(rsm); + } } } @@ -868,6 +855,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //m_actorType = m_scene.ActorSyncModule.ActorType; } + //m_actorType = m_scene.ActorSyncModule.ActorType.ToString(); + //Start symmetric synchronization initialization automatically SyncStart(null); } @@ -1315,6 +1304,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.WarnFormat("Sending region name: \"{0}\"", m_scene.RegionInfo.RegionName); SendSyncMessage(SymmetricSyncMessage.MsgType.ActorID, m_actorID); + SendSyncMessage(SymmetricSyncMessage.MsgType.ActorType, m_scene.RegionSyncActorType); SendSyncMessage(SymmetricSyncMessage.MsgType.GetTerrain); SendSyncMessage(SymmetricSyncMessage.MsgType.GetObjects); @@ -2361,6 +2351,30 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private void OnLocalPhysicsCollision(UUID partUUID, OSDArray collisionUUIDs) { + //temp solution for reducing collision events for demo + switch (m_reportCollisions) + { + case "All": + break; + case "PrimToAvatarOnly": + SceneObjectPart part = m_scene.GetSceneObjectPart(partUUID); + if (part == null) return; + for (int i = 0; i < collisionUUIDs.Count; i++) + { + OSD arg = collisionUUIDs[i]; + UUID collidingUUID = arg.AsUUID(); + ScenePresence sp = m_scene.GetScenePresence(collidingUUID); + if (sp == null) + { + //not colliding with an avatar, don't propagate + return; + } + } + break; + default: + break; + } + OSDMap data = new OSDMap(); data["primUUID"] = OSD.FromUUID(partUUID); data["collisionUUIDs"] = collisionUUIDs; diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs index e4486f829e..b21c328adb 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/ScriptEngineSyncModule.cs @@ -150,6 +150,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule #region IDSGActorSyncModule members and functions + public static string ActorTypeString = DSGActorTypes.ScriptEngine.ToString(); + private DSGActorTypes m_actorType = DSGActorTypes.ScriptEngine; public DSGActorTypes ActorType { diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs index fa1c23602f..af7b0eb5c8 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs @@ -56,6 +56,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule RegionName, //RegionStatus, ActorID, + ActorType, //events NewScript, UpdateScript, diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs index e5c0586c26..ff89273b94 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SyncConnector.cs @@ -80,7 +80,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public string OtherSideActorID { get { return m_syncOtherSideActorID; } - set { m_syncOtherSideActorID = value; } + //set { m_syncOtherSideActorID = value; } } //The region name of the other side of the connection @@ -90,6 +90,13 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule get { return m_syncOtherSideRegionName; } } + private string m_syncOtherSideActorType; + public string OtherSideActorType + { + get { return m_syncOtherSideActorType; } + //set { m_syncOtherSideActorID = value; } + } + // Check if the client is connected public bool Connected { get { return (m_tcpConnection !=null && m_tcpConnection.Connected); } } @@ -322,6 +329,17 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.DebugFormat("Syncing to actor \"{0}\"", m_syncOtherSideActorID); return; } + case SymmetricSyncMessage.MsgType.ActorType: + { + m_syncOtherSideActorType = Encoding.ASCII.GetString(msg.Data, 0, msg.Length); + if (m_regionSyncModule.IsSyncRelay) + { + SymmetricSyncMessage outMsg = new SymmetricSyncMessage(SymmetricSyncMessage.MsgType.ActorType, m_regionSyncModule.LocalScene.RegionSyncActorType ); + Send(outMsg); + } + m_log.DebugFormat("Syncing to actor type \"{0}\"", m_syncOtherSideActorType); + return; + } default: break; } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index d0ff495340..38b996d75a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -483,6 +483,23 @@ namespace OpenSim.Region.Framework.Scenes set { m_regionSyncMode = value; } } + private string m_regionSyncActorType = String.Empty; + public string RegionSyncActorType + { + get + { + if (m_regionSyncActorType == String.Empty) + { + IDSGActorSyncModule DSGActorSyncModule = RequestModuleInterface(); + if (DSGActorSyncModule != null) + { + m_regionSyncActorType = DSGActorSyncModule.ActorType.ToString(); + } + } + return m_regionSyncActorType; + } + } + public bool ToScheduleFullUpdate() { //Only Scene (SyncServer) or Client Manager (SyncClient) will schedule update to send to its client. Script Engine will not (its update should be sent to Scene).