diff options
Diffstat (limited to 'OpenSim/OpenSim.Region/Scenes/ScenePresence.cs')
-rw-r--r-- | OpenSim/OpenSim.Region/Scenes/ScenePresence.cs | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/Scenes/ScenePresence.cs b/OpenSim/OpenSim.Region/Scenes/ScenePresence.cs new file mode 100644 index 0000000..3fbda39 --- /dev/null +++ b/OpenSim/OpenSim.Region/Scenes/ScenePresence.cs | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Text; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using OpenSim.Physics.Manager; | ||
35 | using OpenSim.Framework.Inventory; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | using Axiom.MathLib; | ||
39 | |||
40 | namespace OpenSim.Region.Scenes | ||
41 | { | ||
42 | public partial class ScenePresence : Entity | ||
43 | { | ||
44 | public static bool PhysicsEngineFlying = false; | ||
45 | public static AvatarAnimations Animations; | ||
46 | public string firstname; | ||
47 | public string lastname; | ||
48 | public IClientAPI ControllingClient; | ||
49 | public LLUUID current_anim; | ||
50 | public int anim_seq; | ||
51 | private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate; | ||
52 | private bool updateflag = false; | ||
53 | private byte movementflag = 0; | ||
54 | private List<NewForce> forcesList = new List<NewForce>(); | ||
55 | private short _updateCount = 0; | ||
56 | private Axiom.MathLib.Quaternion bodyRot; | ||
57 | private LLObject.TextureEntry avatarAppearanceTexture = null; | ||
58 | private byte[] visualParams; | ||
59 | private AvatarWearable[] Wearables; | ||
60 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
61 | private ulong m_regionHandle; | ||
62 | private bool childAvatar = false; | ||
63 | private bool newForce = false; | ||
64 | |||
65 | protected RegionInfo m_regionInfo; | ||
66 | /// <summary> | ||
67 | /// | ||
68 | /// </summary> | ||
69 | /// <param name="theClient"></param> | ||
70 | /// <param name="world"></param> | ||
71 | /// <param name="clientThreads"></param> | ||
72 | /// <param name="regionDat"></param> | ||
73 | public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo) | ||
74 | { | ||
75 | |||
76 | m_world = world; | ||
77 | this.uuid = theClient.AgentId; | ||
78 | |||
79 | m_regionInfo = reginfo; | ||
80 | m_regionHandle = reginfo.RegionHandle; | ||
81 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Avatar.cs - Loading details from grid (DUMMY)"); | ||
82 | ControllingClient = theClient; | ||
83 | this.firstname = ControllingClient.FirstName; | ||
84 | this.lastname = ControllingClient.LastName; | ||
85 | m_localId = m_world.NextLocalId; | ||
86 | Pos = ControllingClient.StartPos; | ||
87 | visualParams = new byte[218]; | ||
88 | for (int i = 0; i < 218; i++) | ||
89 | { | ||
90 | visualParams[i] = 100; | ||
91 | } | ||
92 | |||
93 | Wearables = AvatarWearable.DefaultWearables; | ||
94 | |||
95 | this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
96 | |||
97 | //register for events | ||
98 | ControllingClient.OnRequestWearables += this.SendOurAppearance; | ||
99 | //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance); | ||
100 | ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement; | ||
101 | ControllingClient.OnCompleteMovementToRegion += this.SendInitialPosition; | ||
102 | ControllingClient.OnAgentUpdate += this.HandleAgentUpdate; | ||
103 | // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); | ||
104 | // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); | ||
105 | //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); | ||
106 | |||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// | ||
111 | /// </summary> | ||
112 | public PhysicsActor PhysActor | ||
113 | { | ||
114 | set | ||
115 | { | ||
116 | this._physActor = value; | ||
117 | } | ||
118 | get | ||
119 | { | ||
120 | return _physActor; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// | ||
126 | /// </summary> | ||
127 | /// <param name="status"></param> | ||
128 | public void ChildStatusChange(bool status) | ||
129 | { | ||
130 | this.childAvatar = status; | ||
131 | |||
132 | if (this.childAvatar == true) | ||
133 | { | ||
134 | this.Velocity = new LLVector3(0, 0, 0); | ||
135 | this.Pos = new LLVector3(128, 128, 70); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | |||
140 | /// <summary> | ||
141 | /// | ||
142 | /// </summary> | ||
143 | /// <param name="pos"></param> | ||
144 | public void UpGradeAvatar(LLVector3 pos) | ||
145 | { | ||
146 | //this.childAvatar = false; | ||
147 | this.Pos = pos; | ||
148 | } | ||
149 | |||
150 | protected void DownGradeAvatar() | ||
151 | { | ||
152 | this.Velocity = new LLVector3(0, 0, 0); | ||
153 | this.Pos = new LLVector3(128, 128, 70); | ||
154 | this.childAvatar = true; | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// | ||
159 | /// </summary> | ||
160 | /// <param name="pos"></param> | ||
161 | public void Teleport(LLVector3 pos) | ||
162 | { | ||
163 | this.Pos = pos; | ||
164 | this.SendTerseUpdateToALLClients(); | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// | ||
169 | /// </summary> | ||
170 | public override void addForces() | ||
171 | { | ||
172 | newForce = false; | ||
173 | lock (this.forcesList) | ||
174 | { | ||
175 | if (this.forcesList.Count > 0) | ||
176 | { | ||
177 | for (int i = 0; i < this.forcesList.Count; i++) | ||
178 | { | ||
179 | NewForce force = this.forcesList[i]; | ||
180 | |||
181 | this.updateflag = true; | ||
182 | this.Velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this | ||
183 | this.newForce = true; | ||
184 | } | ||
185 | for (int i = 0; i < this.forcesList.Count; i++) | ||
186 | { | ||
187 | this.forcesList.RemoveAt(0); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | |||
193 | public void SendTerseUpdateToClient(IClientAPI RemoteClient) | ||
194 | { | ||
195 | LLVector3 pos = this.Pos; | ||
196 | LLVector3 vel = this.Velocity; | ||
197 | RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z)); | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// | ||
202 | /// </summary> | ||
203 | public void SendTerseUpdateToALLClients() | ||
204 | { | ||
205 | List<ScenePresence> avatars = this.m_world.RequestAvatarList(); | ||
206 | for (int i = 0; i < avatars.Count; i++) | ||
207 | { | ||
208 | this.SendTerseUpdateToClient(avatars[i].ControllingClient); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | /// <summary> | ||
213 | /// Complete Avatar's movement into the region | ||
214 | /// </summary> | ||
215 | public void CompleteMovement() | ||
216 | { | ||
217 | LLVector3 look = this.Velocity; | ||
218 | if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) | ||
219 | { | ||
220 | look = new LLVector3(0.99f, 0.042f, 0); | ||
221 | } | ||
222 | this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look); | ||
223 | if (this.childAvatar) | ||
224 | { | ||
225 | this.childAvatar = false; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | /// <summary> | ||
230 | /// | ||
231 | /// </summary> | ||
232 | /// <param name="pack"></param> | ||
233 | public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) | ||
234 | { | ||
235 | |||
236 | if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0) | ||
237 | { | ||
238 | Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z); | ||
239 | if (((movementflag & 1) == 0) || (q != this.bodyRot)) | ||
240 | { | ||
241 | //we should add a new force to the list | ||
242 | // but for now we will deal with velocities | ||
243 | NewForce newVelocity = new NewForce(); | ||
244 | Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); | ||
245 | Axiom.MathLib.Vector3 direc = q * v3; | ||
246 | direc.Normalize(); | ||
247 | |||
248 | //work out velocity for sim physics system | ||
249 | direc = direc * ((0.03f) * 128f); | ||
250 | if (this._physActor.Flying) | ||
251 | direc *= 4; | ||
252 | |||
253 | newVelocity.X = direc.x; | ||
254 | newVelocity.Y = direc.y; | ||
255 | newVelocity.Z = direc.z; | ||
256 | this.forcesList.Add(newVelocity); | ||
257 | movementflag = 1; | ||
258 | this.bodyRot = q; | ||
259 | } | ||
260 | } | ||
261 | else | ||
262 | { | ||
263 | if ((movementflag) != 0) | ||
264 | { | ||
265 | NewForce newVelocity = new NewForce(); | ||
266 | newVelocity.X = 0; | ||
267 | newVelocity.Y = 0; | ||
268 | newVelocity.Z = 0; | ||
269 | this.forcesList.Add(newVelocity); | ||
270 | movementflag = 0; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | } | ||
275 | |||
276 | /// <summary> | ||
277 | /// | ||
278 | /// </summary> | ||
279 | public static void LoadAnims() | ||
280 | { | ||
281 | |||
282 | } | ||
283 | |||
284 | /// <summary> | ||
285 | /// | ||
286 | /// </summary> | ||
287 | public override void LandRenegerated() | ||
288 | { | ||
289 | |||
290 | } | ||
291 | |||
292 | |||
293 | public class NewForce | ||
294 | { | ||
295 | public float X; | ||
296 | public float Y; | ||
297 | public float Z; | ||
298 | |||
299 | public NewForce() | ||
300 | { | ||
301 | |||
302 | } | ||
303 | } | ||
304 | } | ||
305 | |||
306 | } | ||