aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorCharles Krinke2008-11-27 05:16:47 +0000
committerCharles Krinke2008-11-27 05:16:47 +0000
commit921692a15f7b793da55cd4ddc4d85eae4393964e (patch)
treeebe7565de552bedbd856cd6615bd8107363eea79
parentUnconditionally set the slam bit oon all object to agent inventory transfers. (diff)
downloadopensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.zip
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.gz
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.bz2
opensim-SC-921692a15f7b793da55cd4ddc4d85eae4393964e.tar.xz
Thank you kindly, Nlin for a patch that:
Adds a new method to IClientAPI to allow adding message handlers for GenericMessages (of which "autopilot" is one). Part 2 adds a specific autopilot handler in ScenePresence.cs. 2) Removing unused variables and functions. 3) Simplifying the navigation logic in ScenePresence.cs. The original patch was somewhat complex because it included orientation logic for a future enhancement of orienting the avatar to point towards the direction being walked. Currently this isn't working, though, so I removed the orientation code, which leaves just the smaller and hopefully simpler-to-understand movement code.
-rw-r--r--OpenSim/Framework/IClientAPI.cs2
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs54
-rw-r--r--OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.cs132
-rw-r--r--OpenSim/Region/Environment/Scenes/Tests/TestClient.cs6
-rw-r--r--OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs10
6 files changed, 199 insertions, 15 deletions
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index 8d9cdaa..88cb49e 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -1045,5 +1045,7 @@ namespace OpenSim.Framework
1045 void SendTerminateFriend(UUID exFriendID); 1045 void SendTerminateFriend(UUID exFriendID);
1046 1046
1047 void KillEndDone(); 1047 void KillEndDone();
1048
1049 bool AddGenericPacketHandler(string MethodName, GenericMessage handler);
1048 } 1050 }
1049} 1051}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index 7c66599..e3b91a5 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -93,6 +93,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
93 new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients 93 new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
94 94
95 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>(); 95 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>();
96 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
96 97
97 protected IScene m_scene; 98 protected IScene m_scene;
98 99
@@ -608,6 +609,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
608 return result; 609 return result;
609 } 610 }
610 611
612 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
613 {
614 bool result = false;
615 lock (m_genericPacketHandlers)
616 {
617 if (!m_genericPacketHandlers.ContainsKey(MethodName))
618 {
619 m_genericPacketHandlers.Add(MethodName, handler);
620 result = true;
621 }
622 }
623 return result;
624 }
625
611 /// <summary> 626 /// <summary>
612 /// Try to process a packet using registered packet handlers 627 /// Try to process a packet using registered packet handlers
613 /// </summary> 628 /// </summary>
@@ -3457,21 +3472,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3457 public bool HandleGenericMessage(IClientAPI sender, Packet pack) 3472 public bool HandleGenericMessage(IClientAPI sender, Packet pack)
3458 { 3473 {
3459 GenericMessagePacket gmpack = (GenericMessagePacket) pack; 3474 GenericMessagePacket gmpack = (GenericMessagePacket) pack;
3460 handlerGenericMessage = OnGenericMessage; 3475 if (m_genericPacketHandlers.Count == 0) return false;
3461 3476 handlerGenericMessage = null;
3462 List<string> msg = new List<string>(); 3477 string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
3463 3478 if(m_genericPacketHandlers.TryGetValue(method, out handlerGenericMessage))
3464 if (handlerGenericMessage != null)
3465 { 3479 {
3466 string method = Util.FieldToString(gmpack.MethodData.Method); 3480 List<string> msg = new List<string>();
3467 foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList) 3481
3482 if (handlerGenericMessage != null)
3468 { 3483 {
3469 msg.Add(Util.FieldToString(block.Parameter)); 3484 foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
3485 {
3486 msg.Add(Util.FieldToString(block.Parameter));
3487 }
3488 try
3489 {
3490 handlerGenericMessage(sender, method, msg);
3491 return true;
3492 }
3493 catch (Exception ex)
3494 {
3495 }
3470 } 3496 }
3471
3472 handlerGenericMessage(this, method, msg);
3473 } 3497 }
3474 return true; 3498 return false;
3475 } 3499 }
3476 3500
3477 public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack) 3501 public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack)
@@ -3965,12 +3989,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3965 { 3989 {
3966 #region Scene/Avatar 3990 #region Scene/Avatar
3967 3991
3968 case PacketType.GenericMessage: 3992 // case PacketType.GenericMessage:
3969 GenericMessagePacket gmpack = (GenericMessagePacket)Pack; 3993 // GenericMessagePacket gmpack = (GenericMessagePacket)Pack;
3970 3994
3971 DecipherGenericMessage(Utils.BytesToString(gmpack.MethodData.Method), gmpack.MethodData.Invoice, gmpack.ParamList); 3995 // DecipherGenericMessage(Utils.BytesToString(gmpack.MethodData.Method), gmpack.MethodData.Invoice, gmpack.ParamList);
3972 3996
3973 break; 3997 // break;
3974 case PacketType.AvatarPropertiesRequest: 3998 case PacketType.AvatarPropertiesRequest:
3975 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; 3999 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
3976 4000
diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
index 0a27086..b5a5123 100644
--- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs
@@ -991,5 +991,15 @@ namespace OpenSim.Region.Environment.Modules.World.NPC
991 public void SendTerminateFriend(UUID exFriendID) 991 public void SendTerminateFriend(UUID exFriendID)
992 { 992 {
993 } 993 }
994
995 #region IClientAPI Members
996
997
998 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
999 {
1000 throw new NotImplementedException();
1001 }
1002
1003 #endregion
994 } 1004 }
995} 1005}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index 29c7c3e..998140f 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -175,6 +175,12 @@ namespace OpenSim.Region.Environment.Scenes
175 175
176 private string m_nextSitAnimation = String.Empty; 176 private string m_nextSitAnimation = String.Empty;
177 177
178 //PauPaw:Proper PID Controler for autopilot************
179 private bool m_moveToPositionInProgress = false;
180 private Vector3 m_moveToPositionTarget = Vector3.Zero;
181 private int m_moveToPositionStateStatus = 0;
182 //*****************************************************
183
178 // Agent's Draw distance. 184 // Agent's Draw distance.
179 protected float m_DrawDistance = 0f; 185 protected float m_DrawDistance = 0f;
180 186
@@ -550,6 +556,7 @@ namespace OpenSim.Region.Environment.Scenes
550 m_controllingClient.OnStopAnim += HandleStopAnim; 556 m_controllingClient.OnStopAnim += HandleStopAnim;
551 m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; 557 m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls;
552 m_controllingClient.OnAutoPilotGo += DoAutoPilot; 558 m_controllingClient.OnAutoPilotGo += DoAutoPilot;
559 m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition);
553 560
554 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 561 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
555 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 562 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -1063,10 +1070,13 @@ namespace OpenSim.Region.Environment.Scenes
1063 1070
1064 if (m_parentID == 0) 1071 if (m_parentID == 0)
1065 { 1072 {
1073 bool bAllowUpdateMoveToPosition = false;
1074 bool bResetMoveToPosition = false;
1066 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags))) 1075 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags)))
1067 { 1076 {
1068 if ((flags & (uint) DCF) != 0) 1077 if ((flags & (uint) DCF) != 0)
1069 { 1078 {
1079 bResetMoveToPosition = true;
1070 DCFlagKeyPressed = true; 1080 DCFlagKeyPressed = true;
1071 try 1081 try
1072 { 1082 {
@@ -1090,9 +1100,100 @@ namespace OpenSim.Region.Environment.Scenes
1090 m_movementflag -= (byte) (uint) DCF; 1100 m_movementflag -= (byte) (uint) DCF;
1091 update_movementflag = true; 1101 update_movementflag = true;
1092 } 1102 }
1103 else
1104 {
1105 bAllowUpdateMoveToPosition = true;
1106 }
1093 } 1107 }
1094 i++; 1108 i++;
1095 } 1109 }
1110
1111 //Paupaw:Do Proper PID for Autopilot here
1112 if (bResetMoveToPosition)
1113 {
1114 m_moveToPositionTarget = Vector3.Zero;
1115 m_moveToPositionInProgress = false;
1116 update_movementflag = true;
1117 bAllowUpdateMoveToPosition = false;
1118 }
1119
1120 if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving))
1121 {
1122 //Check the error term of the current position in relation to the target position
1123 if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 1.5)
1124 {
1125 // we are close enough to the target
1126 m_moveToPositionTarget = Vector3.Zero;
1127 m_moveToPositionInProgress = false;
1128 update_movementflag = true;
1129 }
1130 else
1131 {
1132 try
1133 {
1134 // move avatar in 2D at one meter/second towards target, in avatar coordinate frame.
1135 // This movement vector gets added to the velocity through AddNewMovement().
1136 // Theoretically we might need a more complex PID approach here if other
1137 // unknown forces are acting on the avatar and we need to adaptively respond
1138 // to such forces, but the following simple approach seems to works fine.
1139 Vector3 LocalVectorToTarget3D =
1140 (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
1141 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords
1142 // Ignore z component of vector
1143 Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1144 LocalVectorToTarget2D.Normalize();
1145 agent_control_v3 += LocalVectorToTarget2D;
1146
1147 // update avatar movement flags. the avatar coordinate system is as follows:
1148 //
1149 // +X (forward)
1150 //
1151 // ^
1152 // |
1153 // |
1154 // |
1155 // |
1156 // (left) +Y <--------o--------> -Y
1157 // avatar
1158 // |
1159 // |
1160 // |
1161 // |
1162 // v
1163 // -X
1164 //
1165
1166 // based on the above avatar coordinate system, classify the movement into
1167 // one of left/right/back/forward.
1168 if (LocalVectorToTarget2D.Y > 0)//MoveLeft
1169 {
1170 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
1171 update_movementflag = true;
1172 }
1173 else if (LocalVectorToTarget2D.Y < 0) //MoveRight
1174 {
1175 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
1176 update_movementflag = true;
1177 }
1178 if (LocalVectorToTarget2D.X < 0) //MoveBack
1179 {
1180 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
1181 update_movementflag = true;
1182 }
1183 else if (LocalVectorToTarget2D.X > 0) //Move Forward
1184 {
1185 m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
1186 update_movementflag = true;
1187 }
1188 }
1189 catch (Exception)
1190 {
1191
1192 //Avoid system crash, can be slower but...
1193 }
1194
1195 }
1196 }
1096 } 1197 }
1097 1198
1098 // Cause the avatar to stop flying if it's colliding 1199 // Cause the avatar to stop flying if it's colliding
@@ -1158,6 +1259,37 @@ namespace OpenSim.Region.Environment.Scenes
1158// } 1259// }
1159 } 1260 }
1160 1261
1262 public void DoMoveToPosition(Object sender, string method, List<String> args)
1263 {
1264 try
1265 {
1266 float locx = 0f;
1267 float locy = 0f;
1268 float locz = 0f;
1269 uint regionX = 0;
1270 uint regionY = 0;
1271 try
1272 {
1273 Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY);
1274 locx = Convert.ToSingle(args[0]) - (float)regionX;
1275 locy = Convert.ToSingle(args[1]) - (float)regionY;
1276 locz = Convert.ToSingle(args[2]);
1277 }
1278 catch (InvalidCastException)
1279 {
1280 m_log.Error("[CLIENT]: Invalid autopilot request");
1281 return;
1282 }
1283 m_moveToPositionInProgress = true;
1284 m_moveToPositionTarget = new Vector3(locx, locy, locz);
1285 }
1286 catch (Exception ex)
1287 {
1288 //Why did I get this error?
1289 System.Diagnostics.Debug.WriteLine(ex.ToString());
1290 }
1291 }
1292
1161 private void CheckAtSitTarget() 1293 private void CheckAtSitTarget()
1162 { 1294 {
1163 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); 1295 //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString());
diff --git a/OpenSim/Region/Environment/Scenes/Tests/TestClient.cs b/OpenSim/Region/Environment/Scenes/Tests/TestClient.cs
index 392a53b..606b1fb 100644
--- a/OpenSim/Region/Environment/Scenes/Tests/TestClient.cs
+++ b/OpenSim/Region/Environment/Scenes/Tests/TestClient.cs
@@ -939,5 +939,11 @@ namespace OpenSim.Region.Environment.Scenes.Tests
939 public void SendTerminateFriend(UUID exFriendID) 939 public void SendTerminateFriend(UUID exFriendID)
940 { 940 {
941 } 941 }
942
943 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
944 {
945 throw new NotImplementedException();
946 }
947
942 } 948 }
943} 949}
diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs
index b5ab1ac..89b3bf6 100644
--- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs
+++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs
@@ -991,5 +991,15 @@ namespace OpenSim.Region.Examples.SimpleModule
991 public void SendTerminateFriend(UUID exFriendID) 991 public void SendTerminateFriend(UUID exFriendID)
992 { 992 {
993 } 993 }
994
995 #region IClientAPI Members
996
997
998 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
999 {
1000 throw new NotImplementedException();
1001 }
1002
1003 #endregion
994 } 1004 }
995} 1005}