From 74903876eb5a521fc2e8e0a056d3e1a5132a50cb Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 17 Mar 2011 10:29:03 -0700 Subject: [PATCH 1/2] Collision events generated by physics engine and processed by script engine. --- .../ClientStack/LindenUDP/LLUDPServer.cs | 2 + .../SymmetricSync/RegionSyncModule.cs | 44 +++++++++++++- .../SymmetricSync/SymmetricSyncMessage.cs | 1 + .../Region/Framework/Scenes/EventManager.cs | 2 +- .../Framework/Scenes/SceneObjectPart.cs | 57 ++++++++++++++++++- 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index db35a2ffc1..ce9a6667ef 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -245,10 +245,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP Watchdog.StartThread(IncomingPacketHandler, "Incoming Packets (" + m_scene.RegionInfo.RegionName + ")", ThreadPriority.Normal, false); Watchdog.StartThread(OutgoingPacketHandler, "Outgoing Packets (" + m_scene.RegionInfo.RegionName + ")", ThreadPriority.Normal, false); m_elapsedMSSinceLastStatReport = Environment.TickCount; + /* System.Timers.Timer packet_type_timer = new System.Timers.Timer(60000); packet_type_timer.Elapsed +=new System.Timers.ElapsedEventHandler(packet_type_timer_Elapsed); packet_type_timer.AutoReset = true; packet_type_timer.Start(); + */ } void packet_type_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs index 5ee27bff5f..062872422d 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/RegionSyncModule.cs @@ -13,6 +13,7 @@ using OpenSim.Region.CoreModules.Framework.InterfaceCommander; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; +using OpenSim.Region.Physics.Manager; using OpenSim.Services.Interfaces; using log4net; using System.Net; @@ -592,6 +593,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule case EventManager.EventNames.Attach: OnLocalAttach((uint)evArgs[0], (UUID)evArgs[1], (UUID)evArgs[2]); return; + case EventManager.EventNames.PhysicsCollision: + OnLocalPhysicsCollision((UUID)evArgs[0], (OSDArray)evArgs[1]); + return; default: return; } @@ -1607,6 +1611,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule case SymmetricSyncMessage.MsgType.ObjectGrabbing: case SymmetricSyncMessage.MsgType.ObjectDeGrab: case SymmetricSyncMessage.MsgType.Attach: + case SymmetricSyncMessage.MsgType.PhysicsCollision: { HandleRemoteEvent(msg, senderActorID); return; @@ -1992,6 +1997,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule case SymmetricSyncMessage.MsgType.Attach: HandleRemoteEvent_OnAttach(init_actorID, evSeqNum, data); break; + case SymmetricSyncMessage.MsgType.PhysicsCollision: + HandleRemoteEvent_PhysicsCollision(init_actorID, evSeqNum, data); + break; } //if this is a relay node, forwards the event @@ -2304,7 +2312,33 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule uint localID = part.LocalId; m_scene.EventManager.TriggerOnAttachLocally(localID, itemID, avatarID); - + } + + private void HandleRemoteEvent_PhysicsCollision(string actorID, ulong evSeqNum, OSDMap data) + { + UUID primUUID = data["primUUID"].AsUUID(); + OSDArray collisionLocalIDs = (OSDArray)data["collisionLocalIDs"]; + + SceneObjectPart part = m_scene.GetSceneObjectPart(primUUID); + if (part == null) + { + m_log.WarnFormat("{0}: HandleRemoteEvent_PhysicsCollision: no part with UUID {1} found", LogHeader, primUUID); + return; + } + if (collisionLocalIDs == null) + { + m_log.WarnFormat("{0}: HandleRemoteEvent_PhysicsCollision: no collisionLocalIDs", LogHeader); + return; + } + + // Build up the collision list. The contact point is ignored so we generate some default. + CollisionEventUpdate e = new CollisionEventUpdate(); + foreach (uint collisionID in collisionLocalIDs) + { + // e.addCollider(collisionID, new ContactPoint()); + e.addCollider(collisionID, new ContactPoint(Vector3.Zero, Vector3.UnitX, 0.03f)); + } + part.PhysicsCollisionLocally(e); } /// @@ -2463,6 +2497,14 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule SendSceneEvent(SymmetricSyncMessage.MsgType.Attach, data); } + private void OnLocalPhysicsCollision(UUID partUUID, OSDArray collisionLocalIDs) + { + OSDMap data = new OSDMap(); + data["primUUID"] = OSD.FromUUID(partUUID); + data["collisionLocalIDs"] = collisionLocalIDs; + SendSceneEvent(SymmetricSyncMessage.MsgType.PhysicsCollision, data); + } + private void OnLocalGrabObject(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) { /* diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs index 04e11751f3..d9b348aa85 100755 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SymmetricSync/SymmetricSyncMessage.cs @@ -47,6 +47,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule ObjectGrabbing, ObjectDeGrab, Attach, + PhysicsCollision, //contorl command SyncStateReport, } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 9d83bba6b3..ebd120208c 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -60,7 +60,7 @@ namespace OpenSim.Region.Framework.Scenes ObjectGrabbing, ObjectDeGrab, Attach, //attaching object to avatar - + PhysicsCollision, } public EventManager(Scene scene) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 6d618588ad..34af0bbe64 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2202,7 +2202,7 @@ namespace OpenSim.Region.Framework.Scenes { } - public void PhysicsCollision(EventArgs e) + public virtual void PhysicsCollision(EventArgs e) { // single threaded here if (e == null) @@ -5495,6 +5495,7 @@ namespace OpenSim.Region.Framework.Scenes //} localPart.AggregateScriptEvents = updatedPart.AggregateScriptEvents; + aggregateScriptEventSubscriptions(); m_bucketSyncInfoList[bucketName].LastUpdateTimeStamp = updatedPart.BucketSyncInfoList[bucketName].LastUpdateTimeStamp; m_bucketSyncInfoList[bucketName].LastUpdateActorID = updatedPart.BucketSyncInfoList[bucketName].LastUpdateActorID; @@ -5518,6 +5519,36 @@ namespace OpenSim.Region.Framework.Scenes m_bucketSyncInfoList[bucketName].TaintBucketBySync(); } + // Do any subscriptions based on the AggregateScriptEvents + protected void aggregateScriptEventSubscriptions() + { + if ( + ((AggregateScriptEvents & scriptEvents.collision) != 0) || + ((AggregateScriptEvents & scriptEvents.collision_end) != 0) || + ((AggregateScriptEvents & scriptEvents.collision_start) != 0) || + ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || + ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || + ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || + (CollisionSound != UUID.Zero) + ) + { + // subscribe to physics updates. + if (PhysActor != null) + { + PhysActor.OnCollisionUpdate += PhysicsCollision; + PhysActor.SubscribeEvents(1000); + + } + } + else + { + if (PhysActor != null) + { + PhysActor.UnSubscribeEvents(); + PhysActor.OnCollisionUpdate -= PhysicsCollision; + } + } + } //NOTE: only touch the properties and BucketSyncInfo that is related to the given bucketName. Other properties and //buckets may not be filled at all in "updatedPart". @@ -5944,6 +5975,30 @@ namespace OpenSim.Region.Framework.Scenes } return false; } + + public override void PhysicsCollision(EventArgs e) + { + if (m_parentGroup.Scene.RegionSyncModule != null) + { + CollisionEventUpdate a = (CollisionEventUpdate)e; + Dictionary collisionswith = a.m_objCollisionList; + OSDArray collisionLocalIDs = new OSDArray(); + foreach (uint collisionObject in collisionswith.Keys) + { + collisionLocalIDs.Add(collisionObject); + } + object[] eventArgs = new object[2]; + eventArgs[0] = this.UUID; + eventArgs[1] = collisionLocalIDs; + m_parentGroup.Scene.RegionSyncModule.PublishSceneEvent(EventManager.EventNames.PhysicsCollision, eventArgs); + } + PhysicsCollisionLocally(e); + } + + public void PhysicsCollisionLocally(EventArgs e) + { + base.PhysicsCollision(e); + } } //end of SYMMETRIC SYNC From ab6b9e58121f7c621c5ef77f656d1c60d4649e70 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Thu, 17 Mar 2011 14:10:01 -0700 Subject: [PATCH 2/2] Changed warning to debug message for outgoing packet queues --- OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index ce9a6667ef..998eec5ad9 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -258,7 +258,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP for (int i = 0; i < 9; ++i) { int val = Interlocked.Exchange(ref OutgoingPacket.CatCounts[i], 0); - m_log.WarnFormat("OutgoingPacket type {0} count = {1}", i, val); + m_log.DebugFormat("OutgoingPacket type {0} count = {1}", i, val); } }