aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs
diff options
context:
space:
mode:
authordiva2009-02-18 01:49:18 +0000
committerdiva2009-02-18 01:49:18 +0000
commit3f25128e77af2a53e765436454b8fddeb8f88894 (patch)
tree461d17a9e357e262a08583789617749986978881 /OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs
parentMakes SP.CopyFrom a bit more robust with respect to sims in older versions wh... (diff)
downloadopensim-SC_OLD-3f25128e77af2a53e765436454b8fddeb8f88894.zip
opensim-SC_OLD-3f25128e77af2a53e765436454b8fddeb8f88894.tar.gz
opensim-SC_OLD-3f25128e77af2a53e765436454b8fddeb8f88894.tar.bz2
opensim-SC_OLD-3f25128e77af2a53e765436454b8fddeb8f88894.tar.xz
Adds support for preserving animations on region crossings and TPs.
Known issue: after TP, the self client doesn't see the animations going, but others can see them. So there's a bug there (TPs only, crossings seem to be all fine). Untested: did not test animation overriders; only tested playing animations from the viewer.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs506
1 files changed, 506 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs b/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs
new file mode 100644
index 0000000..e181b91
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs
@@ -0,0 +1,506 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenSim.Framework;
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34
35namespace OpenSim.Region.Framework.Scenes
36{
37 public interface IAgentData
38 {
39 UUID AgentID { get; set; }
40
41 OSDMap PackUpdateMessage();
42 void UnpackUpdateMessage(OSDMap map);
43 }
44
45 /// <summary>
46 /// Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.
47 /// </summary>
48 public class AgentPosition : IAgentData
49 {
50 private UUID m_id;
51 public UUID AgentID
52 {
53 get { return m_id; }
54 set { m_id = value; }
55 }
56
57 public ulong RegionHandle;
58 public uint CircuitCode;
59 public UUID SessionID;
60
61 public float Far;
62 public Vector3 Position;
63 public Vector3 Velocity;
64 public Vector3 Center;
65 public Vector3 Size;
66 public Vector3 AtAxis;
67 public Vector3 LeftAxis;
68 public Vector3 UpAxis;
69 public bool ChangedGrid;
70
71 // This probably shouldn't be here
72 public byte[] Throttles;
73
74
75 public OSDMap PackUpdateMessage()
76 {
77 OSDMap args = new OSDMap();
78 args["message_type"] = OSD.FromString("AgentPosition");
79
80 args["region_handle"] = OSD.FromString(RegionHandle.ToString());
81 args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
82 args["agent_uuid"] = OSD.FromUUID(AgentID);
83 args["session_uuid"] = OSD.FromUUID(SessionID);
84
85 args["position"] = OSD.FromString(Position.ToString());
86 args["velocity"] = OSD.FromString(Velocity.ToString());
87 args["center"] = OSD.FromString(Center.ToString());
88 args["size"] = OSD.FromString(Size.ToString());
89 args["at_axis"] = OSD.FromString(AtAxis.ToString());
90 args["left_axis"] = OSD.FromString(LeftAxis.ToString());
91 args["up_axis"] = OSD.FromString(UpAxis.ToString());
92
93 args["far"] = OSD.FromReal(Far);
94 args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
95
96 if ((Throttles != null) && (Throttles.Length > 0))
97 args["throttles"] = OSD.FromBinary(Throttles);
98
99 return args;
100 }
101
102 public void UnpackUpdateMessage(OSDMap args)
103 {
104 if (args.ContainsKey("region_handle"))
105 UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
106
107 if (args["circuit_code"] != null)
108 UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
109
110 if (args["agent_uuid"] != null)
111 AgentID = args["agent_uuid"].AsUUID();
112
113 if (args["session_uuid"] != null)
114 SessionID = args["session_uuid"].AsUUID();
115
116 if (args["position"] != null)
117 Vector3.TryParse(args["position"].AsString(), out Position);
118
119 if (args["velocity"] != null)
120 Vector3.TryParse(args["velocity"].AsString(), out Velocity);
121
122 if (args["center"] != null)
123 Vector3.TryParse(args["center"].AsString(), out Center);
124
125 if (args["size"] != null)
126 Vector3.TryParse(args["size"].AsString(), out Size);
127
128 if (args["at_axis"] != null)
129 Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
130
131 if (args["left_axis"] != null)
132 Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
133
134 if (args["up_axis"] != null)
135 Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
136
137 if (args["changed_grid"] != null)
138 ChangedGrid = args["changed_grid"].AsBoolean();
139
140 if (args["far"] != null)
141 Far = (float)(args["far"].AsReal());
142
143 if (args["throttles"] != null)
144 Throttles = args["throttles"].AsBinary();
145 }
146
147 /// <summary>
148 /// Soon to be decommissioned
149 /// </summary>
150 /// <param name="cAgent"></param>
151 public void CopyFrom(ChildAgentDataUpdate cAgent)
152 {
153 AgentID = new UUID(cAgent.AgentID);
154
155 // next: ???
156 Size = new Vector3();
157 Size.Z = cAgent.AVHeight;
158
159 Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z);
160 Far = cAgent.drawdistance;
161 Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z);
162 RegionHandle = cAgent.regionHandle;
163 Throttles = cAgent.throttles;
164 Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z);
165 }
166
167 }
168
169 public class AgentGroupData
170 {
171 public UUID GroupID;
172 public ulong GroupPowers;
173 public bool AcceptNotices;
174
175 public AgentGroupData(UUID id, ulong powers, bool notices)
176 {
177 GroupID = id;
178 GroupPowers = powers;
179 AcceptNotices = notices;
180 }
181
182 public AgentGroupData(OSDMap args)
183 {
184 UnpackUpdateMessage(args);
185 }
186
187 public OSDMap PackUpdateMessage()
188 {
189 OSDMap groupdata = new OSDMap();
190 groupdata["group_id"] = OSD.FromUUID(GroupID);
191 groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString());
192 groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices);
193
194 return groupdata;
195 }
196
197 public void UnpackUpdateMessage(OSDMap args)
198 {
199 if (args["group_id"] != null)
200 GroupID = args["group_id"].AsUUID();
201 if (args["group_powers"] != null)
202 UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers);
203 if (args["accept_notices"] != null)
204 AcceptNotices = args["accept_notices"].AsBoolean();
205 }
206 }
207
208 //public class AgentAnimationData
209 //{
210 // public UUID Animation;
211 // public UUID ObjectID;
212
213 // public AgentAnimationData(UUID anim, UUID obj)
214 // {
215 // Animation = anim;
216 // ObjectID = obj;
217 // }
218
219 // public AgentAnimationData(OSDMap args)
220 // {
221 // UnpackUpdateMessage(args);
222 // }
223
224 // public OSDMap PackUpdateMessage()
225 // {
226 // OSDMap anim = new OSDMap();
227 // anim["animation"] = OSD.FromUUID(Animation);
228 // anim["object_id"] = OSD.FromUUID(ObjectID);
229 // return anim;
230 // }
231
232 // public void UnpackUpdateMessage(OSDMap args)
233 // {
234 // if (args["animation"] != null)
235 // Animation = args["animation"].AsUUID();
236 // if (args["object_id"] != null)
237 // ObjectID = args["object_id"].AsUUID();
238 // }
239 //}
240
241 public class AgentData : IAgentData
242 {
243 private UUID m_id;
244 public UUID AgentID
245 {
246 get { return m_id; }
247 set { m_id = value; }
248 }
249 public ulong RegionHandle;
250 public uint CircuitCode;
251 public UUID SessionID;
252
253 public Vector3 Position;
254 public Vector3 Velocity;
255 public Vector3 Center;
256 public Vector3 Size;
257 public Vector3 AtAxis;
258 public Vector3 LeftAxis;
259 public Vector3 UpAxis;
260 public bool ChangedGrid;
261
262 public float Far;
263 public float Aspect;
264 //public int[] Throttles;
265 public byte[] Throttles;
266
267 public uint LocomotionState;
268 public Quaternion HeadRotation;
269 public Quaternion BodyRotation;
270 public uint ControlFlags;
271 public float EnergyLevel;
272 public Byte GodLevel;
273 public bool AlwaysRun;
274 public UUID PreyAgent;
275 public Byte AgentAccess;
276 public UUID[] AgentTextures;
277 public UUID ActiveGroupID;
278
279 public AgentGroupData[] Groups;
280 public Animation[] Anims;
281
282 public UUID GranterID;
283 public Dictionary<string, string> NVPairs;
284
285 public byte[] VisualParams;
286
287 public string CallbackURI;
288
289 public OSDMap PackUpdateMessage()
290 {
291 OSDMap args = new OSDMap();
292 args["message_type"] = OSD.FromString("AgentData");
293
294 args["region_handle"] = OSD.FromString(RegionHandle.ToString());
295 args["circuit_code"] = OSD.FromString(CircuitCode.ToString());
296 args["agent_uuid"] = OSD.FromUUID(AgentID);
297 args["session_uuid"] = OSD.FromUUID(SessionID);
298
299 args["position"] = OSD.FromString(Position.ToString());
300 args["velocity"] = OSD.FromString(Velocity.ToString());
301 args["center"] = OSD.FromString(Center.ToString());
302 args["size"] = OSD.FromString(Size.ToString());
303 args["at_axis"] = OSD.FromString(AtAxis.ToString());
304 args["left_axis"] = OSD.FromString(LeftAxis.ToString());
305 args["up_axis"] = OSD.FromString(UpAxis.ToString());
306
307 args["changed_grid"] = OSD.FromBoolean(ChangedGrid);
308 args["far"] = OSD.FromReal(Far);
309 args["aspect"] = OSD.FromReal(Aspect);
310
311 if ((Throttles != null) && (Throttles.Length > 0))
312 args["throttles"] = OSD.FromBinary(Throttles);
313
314 args["locomotion_state"] = OSD.FromString(LocomotionState.ToString());
315 args["head_rotation"] = OSD.FromString(HeadRotation.ToString());
316 args["body_rotation"] = OSD.FromString(BodyRotation.ToString());
317 args["control_flags"] = OSD.FromString(ControlFlags.ToString());
318
319 args["energy_level"] = OSD.FromReal(EnergyLevel);
320 args["god_level"] = OSD.FromString(GodLevel.ToString());
321 args["always_run"] = OSD.FromBoolean(AlwaysRun);
322 args["prey_agent"] = OSD.FromUUID(PreyAgent);
323 args["agent_access"] = OSD.FromString(AgentAccess.ToString());
324
325 if ((AgentTextures != null) && (AgentTextures.Length > 0))
326 {
327 OSDArray textures = new OSDArray(AgentTextures.Length);
328 foreach (UUID uuid in AgentTextures)
329 textures.Add(OSD.FromUUID(uuid));
330 args["agent_textures"] = textures;
331 }
332
333 args["active_group_id"] = OSD.FromUUID(ActiveGroupID);
334
335 if ((Groups != null) && (Groups.Length > 0))
336 {
337 OSDArray groups = new OSDArray(Groups.Length);
338 foreach (AgentGroupData agd in Groups)
339 groups.Add(agd.PackUpdateMessage());
340 args["groups"] = groups;
341 }
342
343 if ((Anims != null) && (Anims.Length > 0))
344 {
345 OSDArray anims = new OSDArray(Anims.Length);
346 foreach (Animation aanim in Anims)
347 anims.Add(aanim.PackUpdateMessage());
348 args["animations"] = anims;
349 }
350
351 if ((VisualParams != null) && (VisualParams.Length > 0))
352 args["visual_params"] = OSD.FromBinary(VisualParams);
353
354 // Last few fields are still missing: granter and NVPais
355
356 if ((CallbackURI != null) && (!CallbackURI.Equals("")))
357 args["callback_uri"] = OSD.FromString(CallbackURI);
358
359 return args;
360 }
361
362 /// <summary>
363 /// Deserialization of agent data.
364 /// Avoiding reflection makes it painful to write, but that's the price!
365 /// </summary>
366 /// <param name="hash"></param>
367 public void UnpackUpdateMessage(OSDMap args)
368 {
369 if (args.ContainsKey("region_handle"))
370 UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
371
372 if (args["circuit_code"] != null)
373 UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
374
375 if (args["agent_uuid"] != null)
376 AgentID = args["agent_uuid"].AsUUID();
377
378 if (args["session_uuid"] != null)
379 SessionID = args["session_uuid"].AsUUID();
380
381 if (args["position"] != null)
382 Vector3.TryParse(args["position"].AsString(), out Position);
383
384 if (args["velocity"] != null)
385 Vector3.TryParse(args["velocity"].AsString(), out Velocity);
386
387 if (args["center"] != null)
388 Vector3.TryParse(args["center"].AsString(), out Center);
389
390 if (args["size"] != null)
391 Vector3.TryParse(args["size"].AsString(), out Size);
392
393 if (args["at_axis"] != null)
394 Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
395
396 if (args["left_axis"] != null)
397 Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
398
399 if (args["up_axis"] != null)
400 Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
401
402 if (args["changed_grid"] != null)
403 ChangedGrid = args["changed_grid"].AsBoolean();
404
405 if (args["far"] != null)
406 Far = (float)(args["far"].AsReal());
407
408 if (args["aspect"] != null)
409 Aspect = (float)args["aspect"].AsReal();
410
411 if (args["throttles"] != null)
412 Throttles = args["throttles"].AsBinary();
413
414 if (args["locomotion_state"] != null)
415 UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
416
417 if (args["head_rotation"] != null)
418 Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
419
420 if (args["body_rotation"] != null)
421 Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
422
423 if (args["control_flags"] != null)
424 UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
425
426 if (args["energy_level"] != null)
427 EnergyLevel = (float)(args["energy_level"].AsReal());
428
429 if (args["god_level"] != null)
430 Byte.TryParse(args["god_level"].AsString(), out GodLevel);
431
432 if (args["always_run"] != null)
433 AlwaysRun = args["always_run"].AsBoolean();
434
435 if (args["prey_agent"] != null)
436 PreyAgent = args["prey_agent"].AsUUID();
437
438 if (args["agent_access"] != null)
439 Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
440
441 if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
442 {
443 OSDArray textures = (OSDArray)(args["agent_textures"]);
444 AgentTextures = new UUID[textures.Count];
445 int i = 0;
446 foreach (OSD o in textures)
447 AgentTextures[i++] = o.AsUUID();
448 }
449
450 if (args["active_group_id"] != null)
451 ActiveGroupID = args["active_group_id"].AsUUID();
452
453 if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
454 {
455 OSDArray groups = (OSDArray)(args["groups"]);
456 Groups = new AgentGroupData[groups.Count];
457 int i = 0;
458 foreach (OSD o in groups)
459 {
460 if (o.Type == OSDType.Map)
461 {
462 Groups[i++] = new AgentGroupData((OSDMap)o);
463 }
464 }
465 }
466
467 if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
468 {
469 OSDArray anims = (OSDArray)(args["animations"]);
470 Anims = new Animation[anims.Count];
471 int i = 0;
472 foreach (OSD o in anims)
473 {
474 if (o.Type == OSDType.Map)
475 {
476 Anims[i++] = new Animation((OSDMap)o);
477 }
478 }
479 }
480
481 if (args["visual_params"] != null)
482 VisualParams = args["visual_params"].AsBinary();
483
484 if (args["callback_uri"] != null)
485 CallbackURI = args["callback_uri"].AsString();
486 }
487
488 public AgentData()
489 {
490 }
491
492 public AgentData(Hashtable hash)
493 {
494 //UnpackUpdateMessage(hash);
495 }
496
497 public void Dump()
498 {
499 System.Console.WriteLine("------------ AgentData ------------");
500 System.Console.WriteLine("UUID: " + AgentID);
501 System.Console.WriteLine("Region: " + RegionHandle);
502 System.Console.WriteLine("Position: " + Position);
503 }
504 }
505
506}