aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs237
1 files changed, 103 insertions, 134 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 00a1487..5b86735 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -840,6 +840,9 @@ namespace OpenSim.Region.Framework.Scenes
840 840
841 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 841 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
842 842
843 bool wasChild = m_isChildAgent;
844 m_isChildAgent = false;
845
843 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 846 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
844 if (gm != null) 847 if (gm != null)
845 m_grouptitle = gm.GetGroupTitle(m_uuid); 848 m_grouptitle = gm.GetGroupTitle(m_uuid);
@@ -929,14 +932,21 @@ namespace OpenSim.Region.Framework.Scenes
929 // Animator.SendAnimPack(); 932 // Animator.SendAnimPack();
930 933
931 m_scene.SwapRootAgentCount(false); 934 m_scene.SwapRootAgentCount(false);
932 935
933 //CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); 936 // The initial login scene presence is already root when it gets here
934 //if (userInfo != null) 937 // and it has already rezzed the attachments and started their scripts.
935 // userInfo.FetchInventory(); 938 // We do the following only for non-login agents, because their scripts
936 //else 939 // haven't started yet.
937 // m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid); 940 if (wasChild && Attachments != null && Attachments.Count > 0)
938 941 {
939 m_isChildAgent = false; 942 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments...");
943 // Resume scripts
944 Attachments.ForEach(delegate(SceneObjectGroup sog)
945 {
946 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
947 sog.ResumeScripts();
948 });
949 }
940 950
941 // send the animations of the other presences to me 951 // send the animations of the other presences to me
942 m_scene.ForEachScenePresence(delegate(ScenePresence presence) 952 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
@@ -948,6 +958,20 @@ namespace OpenSim.Region.Framework.Scenes
948 m_scene.EventManager.TriggerOnMakeRootAgent(this); 958 m_scene.EventManager.TriggerOnMakeRootAgent(this);
949 } 959 }
950 960
961 public int GetStateSource()
962 {
963 AgentCircuitData aCircuit = m_scene.AuthenticateHandler.GetAgentCircuitData(UUID);
964
965 if (aCircuit != null && (aCircuit.teleportFlags != (uint)TeleportFlags.Default))
966 {
967 // This will get your attention
968 //m_log.Error("[XXX] Triggering CHANGED_TELEPORT");
969
970 return 5; // StateSource.Teleporting
971 }
972 return 2; // StateSource.PrimCrossing
973 }
974
951 /// <summary> 975 /// <summary>
952 /// This turns a root agent into a child agent 976 /// This turns a root agent into a child agent
953 /// when an agent departs this region for a neighbor, this gets called. 977 /// when an agent departs this region for a neighbor, this gets called.
@@ -1139,7 +1163,6 @@ namespace OpenSim.Region.Framework.Scenes
1139 AbsolutePosition = pos; 1163 AbsolutePosition = pos;
1140 } 1164 }
1141 1165
1142 m_isChildAgent = false;
1143 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1166 bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1144 MakeRootAgent(AbsolutePosition, m_flying); 1167 MakeRootAgent(AbsolutePosition, m_flying);
1145 1168
@@ -2340,12 +2363,14 @@ namespace OpenSim.Region.Framework.Scenes
2340 2363
2341 #region Update Client(s) 2364 #region Update Client(s)
2342 2365
2366
2343 /// <summary> 2367 /// <summary>
2344 /// Sends a location update to the client connected to this scenePresence 2368 /// Sends a location update to the client connected to this scenePresence
2345 /// </summary> 2369 /// </summary>
2346 /// <param name="remoteClient"></param> 2370 /// <param name="remoteClient"></param>
2347 public void SendTerseUpdateToClient(IClientAPI remoteClient) 2371 public void SendTerseUpdateToClient(IClientAPI remoteClient)
2348 { 2372 {
2373
2349 // If the client is inactive, it's getting its updates from another 2374 // If the client is inactive, it's getting its updates from another
2350 // server. 2375 // server.
2351 if (remoteClient.IsActive) 2376 if (remoteClient.IsActive)
@@ -2358,8 +2383,8 @@ namespace OpenSim.Region.Framework.Scenes
2358 //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); 2383 //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity);
2359 2384
2360 remoteClient.SendPrimUpdate( 2385 remoteClient.SendPrimUpdate(
2361 this, 2386 this,
2362 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity 2387 PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity
2363 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity); 2388 | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity);
2364 2389
2365 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2390 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
@@ -2367,16 +2392,31 @@ namespace OpenSim.Region.Framework.Scenes
2367 } 2392 }
2368 } 2393 }
2369 2394
2395
2396 // vars to support reduced update frequency when velocity is unchanged
2397 private Vector3 lastVelocitySentToAllClients = Vector3.Zero;
2398 private int lastTerseUpdateToAllClientsTick = Util.EnvironmentTickCount();
2399
2370 /// <summary> 2400 /// <summary>
2371 /// Send a location/velocity/accelleration update to all agents in scene 2401 /// Send a location/velocity/accelleration update to all agents in scene
2372 /// </summary> 2402 /// </summary>
2373 public void SendTerseUpdateToAllClients() 2403 public void SendTerseUpdateToAllClients()
2374 { 2404 {
2375 m_perfMonMS = Util.EnvironmentTickCount(); 2405 int currentTick = Util.EnvironmentTickCount();
2376
2377 m_scene.ForEachClient(SendTerseUpdateToClient);
2378 2406
2379 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); 2407 // decrease update frequency when avatar is moving but velocity is not changing
2408 if (m_velocity.Length() < 0.01f
2409 || Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f
2410 || currentTick - lastTerseUpdateToAllClientsTick > 1500)
2411 {
2412 m_perfMonMS = currentTick;
2413 lastVelocitySentToAllClients = m_velocity;
2414 lastTerseUpdateToAllClientsTick = currentTick;
2415
2416 m_scene.ForEachClient(SendTerseUpdateToClient);
2417
2418 m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
2419 }
2380 } 2420 }
2381 2421
2382 public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs) 2422 public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
@@ -2632,18 +2672,17 @@ namespace OpenSim.Region.Framework.Scenes
2632 cadu.GroupAccess = 0; 2672 cadu.GroupAccess = 0;
2633 cadu.Position = AbsolutePosition; 2673 cadu.Position = AbsolutePosition;
2634 cadu.regionHandle = m_rootRegionHandle; 2674 cadu.regionHandle = m_rootRegionHandle;
2675
2676 // Throttles
2635 float multiplier = 1; 2677 float multiplier = 1;
2636 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); 2678 int childRegions = m_knownChildRegions.Count;
2637 if (innacurateNeighbors != 0) 2679 if (childRegions != 0)
2638 { 2680 multiplier = 1f / childRegions;
2639 multiplier = 1f / (float)innacurateNeighbors; 2681
2640 } 2682 // Minimum throttle for a child region is 1/4 of the root region throttle
2641 if (multiplier <= 0f) 2683 if (multiplier <= 0.25f)
2642 {
2643 multiplier = 0.25f; 2684 multiplier = 0.25f;
2644 }
2645 2685
2646 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString());
2647 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); 2686 cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier);
2648 cadu.Velocity = Velocity; 2687 cadu.Velocity = Velocity;
2649 2688
@@ -3039,16 +3078,14 @@ namespace OpenSim.Region.Framework.Scenes
3039 3078
3040 // Throttles 3079 // Throttles
3041 float multiplier = 1; 3080 float multiplier = 1;
3042 int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); 3081 int childRegions = m_knownChildRegions.Count;
3043 if (innacurateNeighbors != 0) 3082 if (childRegions != 0)
3044 { 3083 multiplier = 1f / childRegions;
3045 multiplier = 1f / innacurateNeighbors; 3084
3046 } 3085 // Minimum throttle for a child region is 1/4 of the root region throttle
3047 if (multiplier <= 0f) 3086 if (multiplier <= 0.25f)
3048 {
3049 multiplier = 0.25f; 3087 multiplier = 0.25f;
3050 } 3088
3051 //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString());
3052 cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); 3089 cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier);
3053 3090
3054 cAgent.HeadRotation = m_headrotation; 3091 cAgent.HeadRotation = m_headrotation;
@@ -3064,54 +3101,6 @@ namespace OpenSim.Region.Framework.Scenes
3064 3101
3065 cAgent.Appearance = new AvatarAppearance(m_appearance); 3102 cAgent.Appearance = new AvatarAppearance(m_appearance);
3066 3103
3067/*
3068 try
3069 {
3070 // We might not pass the Wearables in all cases...
3071 // They're only needed so that persistent changes to the appearance
3072 // are preserved in the new region where the user is moving to.
3073 // But in Hypergrid we might not let this happen.
3074 int i = 0;
3075 UUID[] wears = new UUID[m_appearance.Wearables.Length * 2];
3076 foreach (AvatarWearable aw in m_appearance.Wearables)
3077 {
3078 if (aw != null)
3079 {
3080 wears[i++] = aw.ItemID;
3081 wears[i++] = aw.AssetID;
3082 }
3083 else
3084 {
3085 wears[i++] = UUID.Zero;
3086 wears[i++] = UUID.Zero;
3087 }
3088 }
3089 cAgent.Wearables = wears;
3090
3091 cAgent.VisualParams = m_appearance.VisualParams;
3092
3093 if (m_appearance.Texture != null)
3094 cAgent.AgentTextures = m_appearance.Texture.GetBytes();
3095 }
3096 catch (Exception e)
3097 {
3098 m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message);
3099 }
3100
3101 //Attachments
3102 List<int> attPoints = m_appearance.GetAttachedPoints();
3103 if (attPoints != null)
3104 {
3105 //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count);
3106 int i = 0;
3107 AvatarAttachment[] attachs = new AvatarAttachment[attPoints.Count];
3108 foreach (int point in attPoints)
3109 {
3110 attachs[i++] = new AvatarAttachment(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point));
3111 }
3112 cAgent.Attachments = attachs;
3113 }
3114*/
3115 lock (scriptedcontrols) 3104 lock (scriptedcontrols)
3116 { 3105 {
3117 ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; 3106 ControllerData[] controls = new ControllerData[scriptedcontrols.Count];
@@ -3131,9 +3120,26 @@ namespace OpenSim.Region.Framework.Scenes
3131 } 3120 }
3132 catch { } 3121 catch { }
3133 3122
3134 // cAgent.GroupID = ?? 3123 // Attachment objects
3135 // Groups??? 3124 if (m_attachments != null && m_attachments.Count > 0)
3136 3125 {
3126 cAgent.AttachmentObjects = new List<ISceneObject>();
3127 cAgent.AttachmentObjectStates = new List<string>();
3128 IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
3129 foreach (SceneObjectGroup sog in m_attachments)
3130 {
3131 // We need to make a copy and pass that copy
3132 // because of transfers withn the same sim
3133 ISceneObject clone = sog.CloneForNewScene();
3134 // Attachment module assumes that GroupPosition holds the offsets...!
3135 ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
3136 ((SceneObjectGroup)clone).RootPart.IsAttachment = false;
3137 cAgent.AttachmentObjects.Add(clone);
3138 cAgent.AttachmentObjectStates.Add(sog.GetStateSnapshot());
3139 // Let's remove the scripts of the original object here
3140 sog.RemoveScriptInstances(true);
3141 }
3142 }
3137 } 3143 }
3138 3144
3139 public void CopyFrom(AgentData cAgent) 3145 public void CopyFrom(AgentData cAgent)
@@ -3174,50 +3180,6 @@ namespace OpenSim.Region.Framework.Scenes
3174 AddToPhysicalScene(isFlying); 3180 AddToPhysicalScene(isFlying);
3175 } 3181 }
3176 3182
3177/*
3178 uint i = 0;
3179 try
3180 {
3181 if (cAgent.Wearables == null)
3182 cAgent.Wearables = new UUID[0];
3183 AvatarWearable[] wears = new AvatarWearable[cAgent.Wearables.Length / 2];
3184 for (uint n = 0; n < cAgent.Wearables.Length; n += 2)
3185 {
3186 UUID itemId = cAgent.Wearables[n];
3187 UUID assetId = cAgent.Wearables[n + 1];
3188 wears[i++] = new AvatarWearable(itemId, assetId);
3189 }
3190 // m_appearance.Wearables = wears;
3191 Primitive.TextureEntry textures = null;
3192 if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1)
3193 textures = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length);
3194
3195 byte[] visuals = null;
3196
3197 if ((cAgent.VisualParams != null) && (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT))
3198 visuals = (byte[])cAgent.VisualParams.Clone();
3199
3200 m_appearance = new AvatarAppearance(cAgent.AgentID,wears,textures,visuals);
3201 }
3202 catch (Exception e)
3203 {
3204 m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message);
3205 }
3206
3207 // Attachments
3208 try
3209 {
3210 if (cAgent.Attachments != null)
3211 {
3212 m_appearance.ClearAttachments();
3213 foreach (AvatarAttachment att in cAgent.Attachments)
3214 {
3215 m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID);
3216 }
3217 }
3218 }
3219 catch { }
3220*/
3221 try 3183 try
3222 { 3184 {
3223 lock (scriptedcontrols) 3185 lock (scriptedcontrols)
@@ -3247,8 +3209,18 @@ namespace OpenSim.Region.Framework.Scenes
3247 } 3209 }
3248 catch { } 3210 catch { }
3249 3211
3250 //cAgent.GroupID = ?? 3212 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0)
3251 //Groups??? 3213 {
3214 m_attachments = new List<SceneObjectGroup>();
3215 int i = 0;
3216 foreach (ISceneObject so in cAgent.AttachmentObjects)
3217 {
3218 ((SceneObjectGroup)so).LocalId = 0;
3219 ((SceneObjectGroup)so).RootPart.UpdateFlag = 0;
3220 so.SetState(cAgent.AttachmentObjectStates[i++], m_scene);
3221 m_scene.IncomingCreateObject(so);
3222 }
3223 }
3252 } 3224 }
3253 3225
3254 public bool CopyAgent(out IAgentData agent) 3226 public bool CopyAgent(out IAgentData agent)
@@ -3271,10 +3243,7 @@ namespace OpenSim.Region.Framework.Scenes
3271 3243
3272 m_updateflag = true; 3244 m_updateflag = true;
3273 3245
3274 // The magic constant 0.95f seems to make walking feel less jerky, 3246 Velocity = force;
3275 // probably because it hackishly accounts for the overall latency of
3276 // these Velocity updates -- Diva
3277 Velocity = force * .95F;
3278 3247
3279 m_forceToApply = null; 3248 m_forceToApply = null;
3280 } 3249 }