aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-10-17 23:54:05 +0100
committerJustin Clark-Casey (justincc)2012-10-17 23:54:05 +0100
commit3ec2923022dbc3e0b5411b17c6495dab6d641f0b (patch)
tree0aca3759da3f2ee6ec7b12f7d24a65238df9f09b /OpenSim/Region/ClientStack/Linden/UDP
parentExplicitly return only the incoming AgentUpdate packet as this is the only on... (diff)
downloadopensim-SC_OLD-3ec2923022dbc3e0b5411b17c6495dab6d641f0b.zip
opensim-SC_OLD-3ec2923022dbc3e0b5411b17c6495dab6d641f0b.tar.gz
opensim-SC_OLD-3ec2923022dbc3e0b5411b17c6495dab6d641f0b.tar.bz2
opensim-SC_OLD-3ec2923022dbc3e0b5411b17c6495dab6d641f0b.tar.xz
Reuse the same AgentUpdateArgs object for each AgentUpdate UDP packet (of which there are 10 a second) rather than constructing a new one every time.
We can do this because AgentUpdate packets are handled synchronously.
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs109
1 files changed, 68 insertions, 41 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 1e93b84..65daca0 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -92,8 +92,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
92 public event ObjectDeselect OnObjectDetach; 92 public event ObjectDeselect OnObjectDetach;
93 public event ObjectDrop OnObjectDrop; 93 public event ObjectDrop OnObjectDrop;
94 public event Action<IClientAPI, bool> OnCompleteMovementToRegion; 94 public event Action<IClientAPI, bool> OnCompleteMovementToRegion;
95
96 /// <summary>
97 /// Called when an AgentUpdate message is received and before OnAgentUpdate.
98 /// </summary>
99 /// <remarks>
100 /// Listeners must not retain a reference to AgentUpdateArgs since this object is reused for subsequent AgentUpdates.
101 /// </remarks>
95 public event UpdateAgent OnPreAgentUpdate; 102 public event UpdateAgent OnPreAgentUpdate;
103
104 /// <summary>
105 /// Called when an AgentUpdate message is received and after OnPreAgentUpdate.
106 /// </summary>
107 /// <remarks>
108 /// Listeners must not retain a reference to AgentUpdateArgs since this object is reused for subsequent AgentUpdates.
109 /// </remarks>
96 public event UpdateAgent OnAgentUpdate; 110 public event UpdateAgent OnAgentUpdate;
111
97 public event AgentRequestSit OnAgentRequestSit; 112 public event AgentRequestSit OnAgentRequestSit;
98 public event AgentSit OnAgentSit; 113 public event AgentSit OnAgentSit;
99 public event AvatarPickerRequest OnAvatarPickerRequest; 114 public event AvatarPickerRequest OnAvatarPickerRequest;
@@ -347,7 +362,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
347 private int m_moneyBalance; 362 private int m_moneyBalance;
348 private int m_animationSequenceNumber = 1; 363 private int m_animationSequenceNumber = 1;
349 private bool m_SendLogoutPacketWhenClosing = true; 364 private bool m_SendLogoutPacketWhenClosing = true;
350 private AgentUpdateArgs lastarg; 365
366 /// <summary>
367 /// We retain a single AgentUpdateArgs so that we can constantly reuse it rather than construct a new one for
368 /// every single incoming AgentUpdate. Every client sends 10 AgentUpdate UDP messages per second, even if it
369 /// is doing absolutely nothing.
370 /// </summary>
371 /// <remarks>
372 /// This does mean that agent updates must be processed synchronously, at least for each client, and called methods
373 /// cannot retain a reference to it outside of that method.
374 /// </remarks>
375 private AgentUpdateArgs m_lastAgentUpdateArgs;
351 376
352 protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>(); 377 protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>();
353 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers 378 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
@@ -5198,7 +5223,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5198 protected virtual void RegisterLocalPacketHandlers() 5223 protected virtual void RegisterLocalPacketHandlers()
5199 { 5224 {
5200 AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout); 5225 AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
5226
5227 // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
5228 // for each AgentUpdate packet.
5201 AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false); 5229 AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
5230
5202 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false); 5231 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
5203 AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false); 5232 AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
5204 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false); 5233 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
@@ -5429,73 +5458,71 @@ namespace OpenSim.Region.ClientStack.LindenUDP
5429 { 5458 {
5430 if (OnAgentUpdate != null) 5459 if (OnAgentUpdate != null)
5431 { 5460 {
5432 bool update = false; 5461 AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
5433 AgentUpdatePacket agenUpdate = (AgentUpdatePacket)packet;
5434 5462
5435 #region Packet Session and User Check 5463 #region Packet Session and User Check
5436 if (agenUpdate.AgentData.SessionID != SessionId || agenUpdate.AgentData.AgentID != AgentId) 5464 if (agentUpdate.AgentData.SessionID != SessionId || agentUpdate.AgentData.AgentID != AgentId)
5437 { 5465 {
5438 PacketPool.Instance.ReturnPacket(packet); 5466 PacketPool.Instance.ReturnPacket(packet);
5439 return false; 5467 return false;
5440 } 5468 }
5441 #endregion 5469 #endregion
5442 5470
5443 AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData; 5471 bool update = false;
5444 5472 AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
5445 // We can only check when we have something to check
5446 // against.
5447 5473
5448 if (lastarg != null) 5474 if (m_lastAgentUpdateArgs != null)
5449 { 5475 {
5476 // These should be ordered from most-likely to
5477 // least likely to change. I've made an initial
5478 // guess at that.
5450 update = 5479 update =
5451 ( 5480 (
5452 (x.BodyRotation != lastarg.BodyRotation) || 5481 (x.BodyRotation != m_lastAgentUpdateArgs.BodyRotation) ||
5453 (x.CameraAtAxis != lastarg.CameraAtAxis) || 5482 (x.CameraAtAxis != m_lastAgentUpdateArgs.CameraAtAxis) ||
5454 (x.CameraCenter != lastarg.CameraCenter) || 5483 (x.CameraCenter != m_lastAgentUpdateArgs.CameraCenter) ||
5455 (x.CameraLeftAxis != lastarg.CameraLeftAxis) || 5484 (x.CameraLeftAxis != m_lastAgentUpdateArgs.CameraLeftAxis) ||
5456 (x.CameraUpAxis != lastarg.CameraUpAxis) || 5485 (x.CameraUpAxis != m_lastAgentUpdateArgs.CameraUpAxis) ||
5457 (x.ControlFlags != lastarg.ControlFlags) || 5486 (x.ControlFlags != m_lastAgentUpdateArgs.ControlFlags) ||
5458 (x.Far != lastarg.Far) || 5487 (x.Far != m_lastAgentUpdateArgs.Far) ||
5459 (x.Flags != lastarg.Flags) || 5488 (x.Flags != m_lastAgentUpdateArgs.Flags) ||
5460 (x.State != lastarg.State) || 5489 (x.State != m_lastAgentUpdateArgs.State) ||
5461 (x.HeadRotation != lastarg.HeadRotation) || 5490 (x.HeadRotation != m_lastAgentUpdateArgs.HeadRotation) ||
5462 (x.SessionID != lastarg.SessionID) || 5491 (x.SessionID != m_lastAgentUpdateArgs.SessionID) ||
5463 (x.AgentID != lastarg.AgentID) 5492 (x.AgentID != m_lastAgentUpdateArgs.AgentID)
5464 ); 5493 );
5465 } 5494 }
5466 else 5495 else
5467 { 5496 {
5497 m_lastAgentUpdateArgs = new AgentUpdateArgs();
5468 update = true; 5498 update = true;
5469 } 5499 }
5470 5500
5471 // These should be ordered from most-likely to
5472 // least likely to change. I've made an initial
5473 // guess at that.
5474
5475 if (update) 5501 if (update)
5476 { 5502 {
5477// m_log.DebugFormat("[LLCLIENTVIEW]: Triggered AgentUpdate for {0}", sener.Name); 5503// m_log.DebugFormat("[LLCLIENTVIEW]: Triggered AgentUpdate for {0}", sener.Name);
5478 5504
5479 AgentUpdateArgs arg = new AgentUpdateArgs(); 5505 m_lastAgentUpdateArgs.AgentID = x.AgentID;
5480 arg.AgentID = x.AgentID; 5506 m_lastAgentUpdateArgs.BodyRotation = x.BodyRotation;
5481 arg.BodyRotation = x.BodyRotation; 5507 m_lastAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
5482 arg.CameraAtAxis = x.CameraAtAxis; 5508 m_lastAgentUpdateArgs.CameraCenter = x.CameraCenter;
5483 arg.CameraCenter = x.CameraCenter; 5509 m_lastAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
5484 arg.CameraLeftAxis = x.CameraLeftAxis; 5510 m_lastAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
5485 arg.CameraUpAxis = x.CameraUpAxis; 5511 m_lastAgentUpdateArgs.ControlFlags = x.ControlFlags;
5486 arg.ControlFlags = x.ControlFlags; 5512 m_lastAgentUpdateArgs.Far = x.Far;
5487 arg.Far = x.Far; 5513 m_lastAgentUpdateArgs.Flags = x.Flags;
5488 arg.Flags = x.Flags; 5514 m_lastAgentUpdateArgs.HeadRotation = x.HeadRotation;
5489 arg.HeadRotation = x.HeadRotation; 5515 m_lastAgentUpdateArgs.SessionID = x.SessionID;
5490 arg.SessionID = x.SessionID; 5516 m_lastAgentUpdateArgs.State = x.State;
5491 arg.State = x.State; 5517
5492 UpdateAgent handlerAgentUpdate = OnAgentUpdate; 5518 UpdateAgent handlerAgentUpdate = OnAgentUpdate;
5493 UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate; 5519 UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate;
5494 lastarg = arg; // save this set of arguments for nexttime 5520
5495 if (handlerPreAgentUpdate != null) 5521 if (handlerPreAgentUpdate != null)
5496 OnPreAgentUpdate(this, arg); 5522 OnPreAgentUpdate(this, m_lastAgentUpdateArgs);
5523
5497 if (handlerAgentUpdate != null) 5524 if (handlerAgentUpdate != null)
5498 OnAgentUpdate(this, arg); 5525 OnAgentUpdate(this, m_lastAgentUpdateArgs);
5499 5526
5500 handlerAgentUpdate = null; 5527 handlerAgentUpdate = null;
5501 handlerPreAgentUpdate = null; 5528 handlerPreAgentUpdate = null;