aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs286
1 files changed, 12 insertions, 274 deletions
diff --git a/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs b/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
index 67eab24..33132cf 100644
--- a/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
+++ b/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
@@ -11,327 +11,65 @@ namespace OpenSim.world
11 { 11 {
12 public override void update() 12 public override void update()
13 { 13 {
14 if (!this.childAvatar) 14
15 {
16 if (this._physActor == null)
17 {
18 //HACKHACK: Note to work out why this entity does not have a physics actor
19 // and prehaps create one.
20 return;
21 }
22 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
23 if (this.updateflag)
24 {
25 //need to send movement info
26 //so create the improvedterseobjectupdate packet
27 //use CreateTerseBlock()
28 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
29 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
30 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
31 terse.RegionData.TimeDilation = 64096;
32 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
33 terse.ObjectData[0] = terseBlock;
34 List<Avatar> avList = this.m_world.RequestAvatarList();
35 foreach (Avatar client in avList)
36 {
37 client.SendPacketToViewer(terse);
38 }
39
40 updateflag = false;
41 //this._updateCount = 0;
42 }
43 else
44 {
45
46 if ((pos2 != this.positionLastFrame) || (this.movementflag == 16))
47 {
48 _updateCount++;
49 if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0))
50 {
51 //It has been a while since last update was sent so lets send one.
52 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
53 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
54 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
55 terse.RegionData.TimeDilation = 64096;
56 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
57 terse.ObjectData[0] = terseBlock;
58 List<Avatar> avList = this.m_world.RequestAvatarList();
59 foreach (Avatar client in avList)
60 {
61 client.SendPacketToViewer(terse);
62 }
63 _updateCount = 0;
64 }
65
66 if (this.movementflag == 16)
67 {
68 movementflag = 0;
69 }
70 }
71
72 }
73 this.positionLastFrame = pos2;
74
75 if (!this.ControllingClient.m_sandboxMode)
76 {
77 if (pos2.X < 0)
78 {
79 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
80 }
81
82 if (pos2.Y < 0)
83 {
84 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
85 }
86
87 if (pos2.X > 255)
88 {
89 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
90 }
91
92 if (pos2.Y > 255)
93 {
94 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
95 }
96 }
97 }
98 15
99 } 16 }
100 17
101 public void SendUpdateToOtherClient(Avatar remoteAvatar) 18 public void SendUpdateToOtherClient(Avatar remoteAvatar)
102 { 19 {
103 ObjectUpdatePacket objupdate = CreateUpdatePacket(); 20
104 remoteAvatar.SendPacketToViewer(objupdate);
105 } 21 }
106 22
107 public ObjectUpdatePacket CreateUpdatePacket() 23 public ObjectUpdatePacket CreateUpdatePacket()
108 { 24 {
109 System.Text.Encoding _enc = System.Text.Encoding.ASCII; 25
110 //send a objectupdate packet with information about the clients avatar
111 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
112 objupdate.RegionData.RegionHandle = m_regionHandle;
113 objupdate.RegionData.TimeDilation = 64096;
114 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
115
116 objupdate.ObjectData[0] = AvatarTemplate;
117 //give this avatar object a local id and assign the user a name
118 objupdate.ObjectData[0].ID = this.localid;
119 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
120 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
121
122 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
123
124 byte[] pb = pos2.GetBytes();
125
126 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
127 return objupdate;
128 } 26 }
129 27
130 public void SendInitialPosition() 28 public void SendInitialPosition()
131 { 29 {
132 System.Text.Encoding _enc = System.Text.Encoding.ASCII; 30
133 //send a objectupdate packet with information about the clients avatar
134
135 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
136 objupdate.RegionData.RegionHandle = m_regionHandle;
137 objupdate.RegionData.TimeDilation = 64096;
138 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
139 objupdate.ObjectData[0] = AvatarTemplate;
140 //give this avatar object a local id and assign the user a name
141
142 objupdate.ObjectData[0].ID = this.localid;
143 this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
144 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
145 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z);
146 byte[] pb = pos2.GetBytes();
147 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
148 m_world._localNumber++;
149
150 List<Avatar> avList = this.m_world.RequestAvatarList();
151 foreach (Avatar client in avList)
152 {
153 client.SendPacketToViewer(objupdate);
154 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
155 {
156 SendAppearanceToOtherAgent(client);
157 }
158 }
159 } 31 }
160 32
161 public void SendOurAppearance() 33 public void SendOurAppearance()
162 { 34 {
163 ControllingClient.SendAppearance(this.Wearables); 35
164 } 36 }
165 37
166 public void SendOurAppearance(ClientView OurClient) 38 public void SendOurAppearance(ClientView OurClient)
167 { 39 {
168 //event handler for wearables request 40
169 this.SendOurAppearance();
170 } 41 }
171 42
172 public void SendAppearanceToOtherAgent(Avatar avatarInfo) 43 public void SendAppearanceToOtherAgent(Avatar avatarInfo)
173 { 44 {
174 AvatarAppearancePacket avp = new AvatarAppearancePacket(); 45
175 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
176 avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes();
177
178 AvatarAppearancePacket.VisualParamBlock avblock = null;
179 for (int i = 0; i < 218; i++)
180 {
181 avblock = new AvatarAppearancePacket.VisualParamBlock();
182 avblock.ParamValue = visualParams[i];
183 avp.VisualParam[i] = avblock;
184 }
185
186 avp.Sender.IsTrial = false;
187 avp.Sender.ID = ControllingClient.AgentID;
188 avatarInfo.SendPacketToViewer(avp);
189 } 46 }
190 47
191 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam) 48 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
192 { 49 {
193 LLObject.TextureEntry tex = new LLObject.TextureEntry(texture, 0, texture.Length); 50
194 this.avatarAppearanceTexture = tex;
195
196 for (int i = 0; i < visualParam.Length; i++)
197 {
198 this.visualParams[i] = visualParam[i].ParamValue;
199 }
200
201 List<Avatar> avList = this.m_world.RequestAvatarList();
202 foreach (Avatar client in avList)
203 {
204 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
205 {
206 SendAppearanceToOtherAgent(client);
207 }
208 }
209 } 51 }
210 52
211 public void StopMovement() 53 public void StopMovement()
212 { 54 {
213 this._physActor.Velocity = new PhysicsVector(0, 0, 0); 55
214 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
215 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
216 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
217 terse.RegionData.TimeDilation = 64096;
218 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
219 terse.ObjectData[0] = terseBlock;
220 List<Avatar> avList = this.m_world.RequestAvatarList();
221 foreach (Avatar client in avList)
222 {
223 client.SendPacketToViewer(terse);
224 }
225 } 56 }
226 57
227 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() 58 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
228 { 59 {
229 byte[] bytes = new byte[60]; 60
230 int i = 0;
231 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
232
233 dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry;
234 libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0);
235 lock (m_world.LockPhysicsEngine)
236 {
237 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
238 }
239
240 uint ID = this.localid;
241
242 bytes[i++] = (byte)(ID % 256);
243 bytes[i++] = (byte)((ID >> 8) % 256);
244 bytes[i++] = (byte)((ID >> 16) % 256);
245 bytes[i++] = (byte)((ID >> 24) % 256);
246 bytes[i++] = 0;
247 bytes[i++] = 1;
248 i += 14;
249 bytes[i++] = 128;
250 bytes[i++] = 63;
251
252 byte[] pb = pos2.GetBytes();
253 Array.Copy(pb, 0, bytes, i, pb.Length);
254 i += 12;
255 ushort InternVelocityX;
256 ushort InternVelocityY;
257 ushort InternVelocityZ;
258 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0);
259 lock (m_world.LockPhysicsEngine)
260 {
261 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
262 }
263 internDirec = internDirec / 128.0f;
264 internDirec.x += 1;
265 internDirec.y += 1;
266 internDirec.z += 1;
267
268 InternVelocityX = (ushort)(32768 * internDirec.x);
269 InternVelocityY = (ushort)(32768 * internDirec.y);
270 InternVelocityZ = (ushort)(32768 * internDirec.z);
271
272 ushort ac = 32767;
273 bytes[i++] = (byte)(InternVelocityX % 256);
274 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
275 bytes[i++] = (byte)(InternVelocityY % 256);
276 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
277 bytes[i++] = (byte)(InternVelocityZ % 256);
278 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
279
280 //accel
281 bytes[i++] = (byte)(ac % 256);
282 bytes[i++] = (byte)((ac >> 8) % 256);
283 bytes[i++] = (byte)(ac % 256);
284 bytes[i++] = (byte)((ac >> 8) % 256);
285 bytes[i++] = (byte)(ac % 256);
286 bytes[i++] = (byte)((ac >> 8) % 256);
287
288 //rot
289 bytes[i++] = (byte)(ac % 256);
290 bytes[i++] = (byte)((ac >> 8) % 256);
291 bytes[i++] = (byte)(ac % 256);
292 bytes[i++] = (byte)((ac >> 8) % 256);
293 bytes[i++] = (byte)(ac % 256);
294 bytes[i++] = (byte)((ac >> 8) % 256);
295 bytes[i++] = (byte)(ac % 256);
296 bytes[i++] = (byte)((ac >> 8) % 256);
297
298 //rotation vel
299 bytes[i++] = (byte)(ac % 256);
300 bytes[i++] = (byte)((ac >> 8) % 256);
301 bytes[i++] = (byte)(ac % 256);
302 bytes[i++] = (byte)((ac >> 8) % 256);
303 bytes[i++] = (byte)(ac % 256);
304 bytes[i++] = (byte)((ac >> 8) % 256);
305
306 dat.Data = bytes;
307 return (dat);
308 } 61 }
309 62
310 // Sends animation update 63 // Sends animation update
311 public void SendAnimPack(LLUUID animID, int seq) 64 public void SendAnimPack(LLUUID animID, int seq)
312 { 65 {
313 AvatarAnimationPacket ani = new AvatarAnimationPacket(); 66
314 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
315 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
316 ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID;
317 ani.Sender = new AvatarAnimationPacket.SenderBlock();
318 ani.Sender.ID = ControllingClient.AgentID;
319 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1];
320 ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock();
321 ani.AnimationList[0].AnimID = this.current_anim = animID;
322 ani.AnimationList[0].AnimSequenceID = this.anim_seq = seq;
323
324 List<Avatar> avList = this.m_world.RequestAvatarList();
325 foreach (Avatar client in avList)
326 {
327 client.SendPacketToViewer(ani);
328 }
329 67
330 } 68 }
331 69
332 public void SendAnimPack() 70 public void SendAnimPack()
333 { 71 {
334 this.SendAnimPack(this.current_anim, this.anim_seq); 72
335 } 73 }
336 74
337 } 75 }