diff options
author | MW | 2007-05-16 12:44:58 +0000 |
---|---|---|
committer | MW | 2007-05-16 12:44:58 +0000 |
commit | 3d93d390485075345442b9b5ea35eed88a9cab49 (patch) | |
tree | a51cdb72cd310ae3f579650886836ddc0211d986 /OpenSim.RegionServer/world/Avatar.Update.cs | |
parent | made QueItem a nested class in SimClient. (diff) | |
download | opensim-SC_OLD-3d93d390485075345442b9b5ea35eed88a9cab49.zip opensim-SC_OLD-3d93d390485075345442b9b5ea35eed88a9cab49.tar.gz opensim-SC_OLD-3d93d390485075345442b9b5ea35eed88a9cab49.tar.bz2 opensim-SC_OLD-3d93d390485075345442b9b5ea35eed88a9cab49.tar.xz |
started to refactor startup code and to move udp server code out to its own class (currently not being used though) so that a single instance can handle multiple regions (each will need to be listening on a separate udp port)
Diffstat (limited to 'OpenSim.RegionServer/world/Avatar.Update.cs')
-rw-r--r-- | OpenSim.RegionServer/world/Avatar.Update.cs | 331 |
1 files changed, 331 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/Avatar.Update.cs b/OpenSim.RegionServer/world/Avatar.Update.cs new file mode 100644 index 0000000..ba2965d --- /dev/null +++ b/OpenSim.RegionServer/world/Avatar.Update.cs | |||
@@ -0,0 +1,331 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | using libsecondlife.Packets; | ||
6 | |||
7 | namespace 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 | foreach (SimClient client in m_clientThreads.Values) | ||
32 | { | ||
33 | client.OutPacket(terse); | ||
34 | } | ||
35 | |||
36 | updateflag = false; | ||
37 | //this._updateCount = 0; | ||
38 | } | ||
39 | else | ||
40 | { | ||
41 | |||
42 | if ((pos2 != this.positionLastFrame) || (this.movementflag == 16)) | ||
43 | { | ||
44 | _updateCount++; | ||
45 | if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0)) | ||
46 | { | ||
47 | //It has been a while since last update was sent so lets send one. | ||
48 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); | ||
49 | ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); | ||
50 | terse.RegionData.RegionHandle = m_regionHandle; // FIXME | ||
51 | terse.RegionData.TimeDilation = 64096; | ||
52 | terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
53 | terse.ObjectData[0] = terseBlock; | ||
54 | foreach (SimClient client in m_clientThreads.Values) | ||
55 | { | ||
56 | client.OutPacket(terse); | ||
57 | } | ||
58 | _updateCount = 0; | ||
59 | } | ||
60 | |||
61 | if (this.movementflag == 16) | ||
62 | { | ||
63 | movementflag = 0; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | } | ||
68 | this.positionLastFrame = pos2; | ||
69 | |||
70 | if (!this.ControllingClient.m_sandboxMode) | ||
71 | { | ||
72 | if (pos2.X < 0) | ||
73 | { | ||
74 | ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); | ||
75 | } | ||
76 | |||
77 | if (pos2.Y < 0) | ||
78 | { | ||
79 | ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); | ||
80 | } | ||
81 | |||
82 | if (pos2.X > 255) | ||
83 | { | ||
84 | ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); | ||
85 | } | ||
86 | |||
87 | if (pos2.Y > 255) | ||
88 | { | ||
89 | ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | public ObjectUpdatePacket CreateUpdatePacket() | ||
96 | { | ||
97 | System.Text.Encoding _enc = System.Text.Encoding.ASCII; | ||
98 | //send a objectupdate packet with information about the clients avatar | ||
99 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
100 | objupdate.RegionData.RegionHandle = m_regionHandle; | ||
101 | objupdate.RegionData.TimeDilation = 64096; | ||
102 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
103 | |||
104 | objupdate.ObjectData[0] = AvatarTemplate; | ||
105 | //give this avatar object a local id and assign the user a name | ||
106 | objupdate.ObjectData[0].ID = this.localid; | ||
107 | objupdate.ObjectData[0].FullID = ControllingClient.AgentID; | ||
108 | objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); | ||
109 | |||
110 | libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z); | ||
111 | |||
112 | byte[] pb = pos2.GetBytes(); | ||
113 | |||
114 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); | ||
115 | return objupdate; | ||
116 | } | ||
117 | |||
118 | public void SendInitialPosition() | ||
119 | { | ||
120 | System.Text.Encoding _enc = System.Text.Encoding.ASCII; | ||
121 | //send a objectupdate packet with information about the clients avatar | ||
122 | |||
123 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
124 | objupdate.RegionData.RegionHandle = m_regionHandle; | ||
125 | objupdate.RegionData.TimeDilation = 64096; | ||
126 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
127 | objupdate.ObjectData[0] = AvatarTemplate; | ||
128 | //give this avatar object a local id and assign the user a name | ||
129 | |||
130 | objupdate.ObjectData[0].ID = this.localid; | ||
131 | this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID; | ||
132 | objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); | ||
133 | libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z); | ||
134 | byte[] pb = pos2.GetBytes(); | ||
135 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); | ||
136 | m_world._localNumber++; | ||
137 | foreach (SimClient client in m_clientThreads.Values) | ||
138 | { | ||
139 | client.OutPacket(objupdate); | ||
140 | if (client.AgentID != ControllingClient.AgentID) | ||
141 | { | ||
142 | //the below line is already in Simclient.cs at line number 245 , directly below the call to this method | ||
143 | //if there is a problem/bug with that , then lets fix it there rather than duplicating it here | ||
144 | //client.ClientAvatar.SendAppearanceToOtherAgent(this.ControllingClient); | ||
145 | |||
146 | SendAppearanceToOtherAgent(client); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | public void SendInitialAppearance() | ||
152 | { | ||
153 | AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); | ||
154 | aw.AgentData.AgentID = this.ControllingClient.AgentID; | ||
155 | aw.AgentData.SerialNum = 0; | ||
156 | aw.AgentData.SessionID = ControllingClient.SessionID; | ||
157 | |||
158 | aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; | ||
159 | AgentWearablesUpdatePacket.WearableDataBlock awb; | ||
160 | for (int i = 0; i < 13; i++) | ||
161 | { | ||
162 | awb = new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
163 | awb.WearableType = (byte)i; | ||
164 | awb.AssetID = this.Wearables[i].AssetID; | ||
165 | awb.ItemID = this.Wearables[i].ItemID; | ||
166 | aw.WearableData[i] = awb; | ||
167 | } | ||
168 | |||
169 | ControllingClient.OutPacket(aw); | ||
170 | } | ||
171 | |||
172 | public void SendAppearanceToOtherAgent(SimClient userInfo) | ||
173 | { | ||
174 | AvatarAppearancePacket avp = new AvatarAppearancePacket(); | ||
175 | avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218]; | ||
176 | avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes(); | ||
177 | |||
178 | //a wearable update packets should only be sent about the viewers/agents own avatar not for other avatars | ||
179 | //but it seems that the following code only created the packets and never actually sent them anyway | ||
180 | /*AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); | ||
181 | aw.AgentData.AgentID = this.ControllingClient.AgentID; | ||
182 | aw.AgentData.SessionID = userInfo.SessionID; | ||
183 | aw.AgentData.SerialNum = 0; //removed the use of a random number as a random number could be less than the last number, should have a counter variable for this | ||
184 | |||
185 | aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; | ||
186 | AgentWearablesUpdatePacket.WearableDataBlock awb; | ||
187 | for (int i = 0; i < 13; i++) | ||
188 | { | ||
189 | awb = new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
190 | awb.WearableType = (byte)i; | ||
191 | awb.AssetID = this.Wearables[i].AssetID; | ||
192 | awb.ItemID = this.Wearables[i].ItemID; | ||
193 | aw.WearableData[i] = awb; | ||
194 | }*/ | ||
195 | |||
196 | AvatarAppearancePacket.VisualParamBlock avblock = null; | ||
197 | for (int i = 0; i < 218; i++) | ||
198 | { | ||
199 | avblock = new AvatarAppearancePacket.VisualParamBlock(); | ||
200 | avblock.ParamValue = visualParams[i]; | ||
201 | avp.VisualParam[i] = avblock; | ||
202 | } | ||
203 | |||
204 | avp.Sender.IsTrial = false; | ||
205 | avp.Sender.ID = ControllingClient.AgentID; | ||
206 | userInfo.OutPacket(avp); | ||
207 | } | ||
208 | |||
209 | public void SetAppearance(AgentSetAppearancePacket appear) | ||
210 | { | ||
211 | LLObject.TextureEntry tex = new LLObject.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); | ||
212 | this.avatarAppearanceTexture = tex; | ||
213 | for (int i = 0; i < appear.VisualParam.Length; i++) | ||
214 | { | ||
215 | this.visualParams[i] = appear.VisualParam[i].ParamValue; | ||
216 | } | ||
217 | foreach (SimClient client in m_clientThreads.Values) | ||
218 | { | ||
219 | if (client.AgentID != ControllingClient.AgentID) | ||
220 | { | ||
221 | SendAppearanceToOtherAgent(client); | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | |||
226 | public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() | ||
227 | { | ||
228 | byte[] bytes = new byte[60]; | ||
229 | int i = 0; | ||
230 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
231 | |||
232 | dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; | ||
233 | libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0); | ||
234 | lock (m_world.LockPhysicsEngine) | ||
235 | { | ||
236 | pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); | ||
237 | } | ||
238 | |||
239 | uint ID = this.localid; | ||
240 | |||
241 | bytes[i++] = (byte)(ID % 256); | ||
242 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
243 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
244 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
245 | bytes[i++] = 0; | ||
246 | bytes[i++] = 1; | ||
247 | i += 14; | ||
248 | bytes[i++] = 128; | ||
249 | bytes[i++] = 63; | ||
250 | |||
251 | byte[] pb = pos2.GetBytes(); | ||
252 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
253 | i += 12; | ||
254 | ushort InternVelocityX; | ||
255 | ushort InternVelocityY; | ||
256 | ushort InternVelocityZ; | ||
257 | Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0); | ||
258 | lock (m_world.LockPhysicsEngine) | ||
259 | { | ||
260 | internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z); | ||
261 | } | ||
262 | internDirec = internDirec / 128.0f; | ||
263 | internDirec.x += 1; | ||
264 | internDirec.y += 1; | ||
265 | internDirec.z += 1; | ||
266 | |||
267 | InternVelocityX = (ushort)(32768 * internDirec.x); | ||
268 | InternVelocityY = (ushort)(32768 * internDirec.y); | ||
269 | InternVelocityZ = (ushort)(32768 * internDirec.z); | ||
270 | |||
271 | ushort ac = 32767; | ||
272 | bytes[i++] = (byte)(InternVelocityX % 256); | ||
273 | bytes[i++] = (byte)((InternVelocityX >> 8) % 256); | ||
274 | bytes[i++] = (byte)(InternVelocityY % 256); | ||
275 | bytes[i++] = (byte)((InternVelocityY >> 8) % 256); | ||
276 | bytes[i++] = (byte)(InternVelocityZ % 256); | ||
277 | bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); | ||
278 | |||
279 | //accel | ||
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 | bytes[i++] = (byte)(ac % 256); | ||
285 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
286 | |||
287 | //rot | ||
288 | bytes[i++] = (byte)(ac % 256); | ||
289 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
290 | bytes[i++] = (byte)(ac % 256); | ||
291 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
292 | bytes[i++] = (byte)(ac % 256); | ||
293 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
294 | bytes[i++] = (byte)(ac % 256); | ||
295 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
296 | |||
297 | //rotation vel | ||
298 | bytes[i++] = (byte)(ac % 256); | ||
299 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
300 | bytes[i++] = (byte)(ac % 256); | ||
301 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
302 | bytes[i++] = (byte)(ac % 256); | ||
303 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
304 | |||
305 | dat.Data = bytes; | ||
306 | return (dat); | ||
307 | } | ||
308 | |||
309 | // Sends animation update | ||
310 | public void SendAnimPack() | ||
311 | { | ||
312 | AvatarAnimationPacket ani = new AvatarAnimationPacket(); | ||
313 | ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1]; | ||
314 | ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock(); | ||
315 | ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID; | ||
316 | ani.Sender = new AvatarAnimationPacket.SenderBlock(); | ||
317 | ani.Sender.ID = ControllingClient.AgentID; | ||
318 | ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1]; | ||
319 | ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock(); | ||
320 | ani.AnimationList[0].AnimID = this.current_anim; | ||
321 | ani.AnimationList[0].AnimSequenceID = this.anim_seq; | ||
322 | |||
323 | //ControllingClient.OutPacket(ani); | ||
324 | foreach (SimClient client in m_clientThreads.Values) | ||
325 | { | ||
326 | client.OutPacket(ani); | ||
327 | } | ||
328 | } | ||
329 | |||
330 | } | ||
331 | } | ||