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