clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 OpenSimulator 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.Reflection; |
||
31 | |||
32 | using log4net; |
||
33 | using Nini.Config; |
||
34 | |||
35 | using OpenSim.Framework; |
||
36 | using OpenMetaverse; |
||
37 | |||
38 | namespace OpenSim.Region.Physics.Manager |
||
39 | { |
||
40 | public delegate void physicsCrash(); |
||
41 | |||
42 | public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal); |
||
43 | public delegate void RayCallback(List<ContactResult> list); |
||
44 | |||
45 | public delegate void JointMoved(PhysicsJoint joint); |
||
46 | public delegate void JointDeactivated(PhysicsJoint joint); |
||
47 | public delegate void JointErrorMessage(PhysicsJoint joint, string message); // this refers to an "error message due to a problem", not "amount of joint constraint violation" |
||
48 | |||
49 | public enum RayFilterFlags : ushort |
||
50 | { |
||
51 | // the flags |
||
52 | water = 0x01, |
||
53 | land = 0x02, |
||
54 | agent = 0x04, |
||
55 | nonphysical = 0x08, |
||
56 | physical = 0x10, |
||
57 | phantom = 0x20, |
||
58 | volumedtc = 0x40, |
||
59 | |||
60 | // ray cast colision control (may only work for meshs) |
||
61 | ContactsUnImportant = 0x2000, |
||
62 | BackFaceCull = 0x4000, |
||
63 | ClosestHit = 0x8000, |
||
64 | |||
65 | // some combinations |
||
66 | LSLPhantom = phantom | volumedtc, |
||
67 | PrimsNonPhantom = nonphysical | physical, |
||
68 | PrimsNonPhantomAgents = nonphysical | physical | agent, |
||
69 | |||
70 | AllPrims = nonphysical | phantom | volumedtc | physical, |
||
71 | AllButLand = agent | nonphysical | physical | phantom | volumedtc, |
||
72 | |||
73 | ClosestAndBackCull = ClosestHit | BackFaceCull, |
||
74 | |||
75 | All = 0x3f |
||
76 | } |
||
77 | |||
78 | public delegate void RequestAssetDelegate(UUID assetID, AssetReceivedDelegate callback); |
||
79 | public delegate void AssetReceivedDelegate(AssetBase asset); |
||
80 | |||
81 | /// <summary> |
||
82 | /// Contact result from a raycast. |
||
83 | /// </summary> |
||
84 | public struct ContactResult |
||
85 | { |
||
86 | public Vector3 Pos; |
||
87 | public float Depth; |
||
88 | public uint ConsumerID; |
||
89 | public Vector3 Normal; |
||
90 | } |
||
91 | |||
92 | public abstract class PhysicsScene |
||
93 | { |
||
94 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
95 | |||
96 | /// <summary> |
||
97 | /// A unique identifying string for this instance of the physics engine. |
||
98 | /// Useful in debug messages to distinguish one OdeScene instance from another. |
||
99 | /// Usually set to include the region name that the physics engine is acting for. |
||
100 | /// </summary> |
||
101 | public string Name { get; protected set; } |
||
102 | |||
103 | /// <summary> |
||
104 | /// A string identifying the family of this physics engine. Most common values returned |
||
105 | /// are "OpenDynamicsEngine" and "BulletSim" but others are possible. |
||
106 | /// </summary> |
||
107 | public string EngineType { get; protected set; } |
||
108 | |||
109 | // The only thing that should register for this event is the SceneGraph |
||
110 | // Anything else could cause problems. |
||
111 | public event physicsCrash OnPhysicsCrash; |
||
112 | |||
113 | public static PhysicsScene Null |
||
114 | { |
||
115 | get { return new NullPhysicsScene(); } |
||
116 | } |
||
117 | |||
118 | public RequestAssetDelegate RequestAssetMethod { get; set; } |
||
119 | |||
120 | public virtual void TriggerPhysicsBasedRestart() |
||
121 | { |
||
122 | physicsCrash handler = OnPhysicsCrash; |
||
123 | if (handler != null) |
||
124 | { |
||
125 | OnPhysicsCrash(); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public abstract void Initialise(IMesher meshmerizer, IConfigSource config); |
||
130 | |||
131 | /// <summary> |
||
132 | /// Add an avatar |
||
133 | /// </summary> |
||
134 | /// <param name="avName"></param> |
||
135 | /// <param name="position"></param> |
||
136 | /// <param name="size"></param> |
||
137 | /// <param name="isFlying"></param> |
||
138 | /// <returns></returns> |
||
139 | public abstract PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying); |
||
140 | |||
141 | /// <summary> |
||
142 | /// Add an avatar |
||
143 | /// </summary> |
||
144 | /// <param name="localID"></param> |
||
145 | /// <param name="avName"></param> |
||
146 | /// <param name="position"></param> |
||
147 | /// <param name="size"></param> |
||
148 | /// <param name="isFlying"></param> |
||
149 | /// <returns></returns> |
||
150 | public virtual PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying) |
||
151 | { |
||
152 | PhysicsActor ret = AddAvatar(avName, position, size, isFlying); |
||
153 | if (ret != null) ret.LocalID = localID; |
||
154 | return ret; |
||
155 | } |
||
156 | |||
157 | /// <summary> |
||
158 | /// Remove an avatar. |
||
159 | /// </summary> |
||
160 | /// <param name="actor"></param> |
||
161 | public abstract void RemoveAvatar(PhysicsActor actor); |
||
162 | |||
163 | /// <summary> |
||
164 | /// Remove a prim. |
||
165 | /// </summary> |
||
166 | /// <param name="prim"></param> |
||
167 | public abstract void RemovePrim(PhysicsActor prim); |
||
168 | |||
169 | public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, |
||
170 | Vector3 size, Quaternion rotation, bool isPhysical, uint localid); |
||
171 | |||
172 | public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, |
||
173 | Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid) |
||
174 | { |
||
175 | return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid); |
||
176 | } |
||
177 | |||
178 | public virtual float TimeDilation |
||
179 | { |
||
180 | get { return 1.0f; } |
||
181 | } |
||
182 | |||
183 | public virtual bool SupportsNINJAJoints |
||
184 | { |
||
185 | get { return false; } |
||
186 | } |
||
187 | |||
188 | public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position, |
||
189 | Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation) |
||
190 | { return null; } |
||
191 | |||
192 | public virtual void RequestJointDeletion(string objectNameInScene) |
||
193 | { return; } |
||
194 | |||
195 | public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor) |
||
196 | { return; } |
||
197 | |||
198 | public virtual void DumpJointInfo() |
||
199 | { return; } |
||
200 | |||
201 | public event JointMoved OnJointMoved; |
||
202 | |||
203 | protected virtual void DoJointMoved(PhysicsJoint joint) |
||
204 | { |
||
205 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does |
||
206 | // not allow subclasses to invoke the parent class event. |
||
207 | if (OnJointMoved != null) |
||
208 | { |
||
209 | OnJointMoved(joint); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | public event JointDeactivated OnJointDeactivated; |
||
214 | |||
215 | protected virtual void DoJointDeactivated(PhysicsJoint joint) |
||
216 | { |
||
217 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does |
||
218 | // not allow subclasses to invoke the parent class event. |
||
219 | if (OnJointDeactivated != null) |
||
220 | { |
||
221 | OnJointDeactivated(joint); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | public event JointErrorMessage OnJointErrorMessage; |
||
226 | |||
227 | protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message) |
||
228 | { |
||
229 | // We need this to allow subclasses (but not other classes) to invoke the event; C# does |
||
230 | // not allow subclasses to invoke the parent class event. |
||
231 | if (OnJointErrorMessage != null) |
||
232 | { |
||
233 | OnJointErrorMessage(joint, message); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | public virtual Vector3 GetJointAnchor(PhysicsJoint joint) |
||
238 | { return Vector3.Zero; } |
||
239 | |||
240 | public virtual Vector3 GetJointAxis(PhysicsJoint joint) |
||
241 | { return Vector3.Zero; } |
||
242 | |||
243 | public abstract void AddPhysicsActorTaint(PhysicsActor prim); |
||
244 | |||
245 | /// <summary> |
||
246 | /// Perform a simulation of the current physics scene over the given timestep. |
||
247 | /// </summary> |
||
248 | /// <param name="timeStep"></param> |
||
249 | /// <returns>The number of frames simulated over that period.</returns> |
||
250 | public abstract float Simulate(float timeStep); |
||
251 | |||
252 | /// <summary> |
||
253 | /// Get statistics about this scene. |
||
254 | /// </summary> |
||
255 | /// <remarks>This facility is currently experimental and subject to change.</remarks> |
||
256 | /// <returns> |
||
257 | /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null. |
||
258 | /// </returns> |
||
259 | public virtual Dictionary<string, float> GetStats() { return null; } |
||
260 | |||
261 | public abstract void GetResults(); |
||
262 | |||
263 | public abstract void SetTerrain(float[] heightMap); |
||
264 | |||
265 | public abstract void SetWaterLevel(float baseheight); |
||
266 | |||
267 | public abstract void DeleteTerrain(); |
||
268 | |||
269 | public abstract void Dispose(); |
||
270 | |||
271 | public abstract Dictionary<uint, float> GetTopColliders(); |
||
272 | |||
273 | public abstract bool IsThreaded { get; } |
||
274 | |||
275 | /// <summary> |
||
276 | /// True if the physics plugin supports raycasting against the physics scene |
||
277 | /// </summary> |
||
278 | public virtual bool SupportsRayCast() |
||
279 | { |
||
280 | return false; |
||
281 | } |
||
282 | |||
283 | public virtual bool SupportsCombining() |
||
284 | { |
||
285 | return false; |
||
286 | } |
||
287 | |||
288 | public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {} |
||
289 | |||
290 | public virtual void UnCombine(PhysicsScene pScene) {} |
||
291 | |||
292 | /// <summary> |
||
293 | /// Queue a raycast against the physics scene. |
||
294 | /// The provided callback method will be called when the raycast is complete |
||
295 | /// |
||
296 | /// Many physics engines don't support collision testing at the same time as |
||
297 | /// manipulating the physics scene, so we queue the request up and callback |
||
298 | /// a custom method when the raycast is complete. |
||
299 | /// This allows physics engines that give an immediate result to callback immediately |
||
300 | /// and ones that don't, to callback when it gets a result back. |
||
301 | /// |
||
302 | /// ODE for example will not allow you to change the scene while collision testing or |
||
303 | /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene. |
||
304 | /// |
||
305 | /// This is named RayCastWorld to not conflict with modrex's Raycast method. |
||
306 | /// </summary> |
||
307 | /// <param name="position">Origin of the ray</param> |
||
308 | /// <param name="direction">Direction of the ray</param> |
||
309 | /// <param name="length">Length of ray in meters</param> |
||
310 | /// <param name="retMethod">Method to call when the raycast is complete</param> |
||
311 | public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod) |
||
312 | { |
||
313 | if (retMethod != null) |
||
314 | retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero); |
||
315 | } |
||
316 | |||
317 | public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod) |
||
318 | { |
||
319 | if (retMethod != null) |
||
320 | retMethod(new List<ContactResult>()); |
||
321 | } |
||
322 | |||
323 | public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count) |
||
324 | { |
||
325 | return new List<ContactResult>(); |
||
326 | } |
||
327 | |||
328 | public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter) |
||
329 | { |
||
330 | return null; |
||
331 | } |
||
332 | |||
333 | public virtual bool SupportsRaycastWorldFiltered() |
||
334 | { |
||
335 | return false; |
||
336 | } |
||
337 | |||
338 | // Extendable interface for new, physics engine specific operations |
||
339 | public virtual object Extension(string pFunct, params object[] pParams) |
||
340 | { |
||
341 | // A NOP if the extension thing is not implemented by the physics engine |
||
342 | return null; |
||
343 | } |
||
344 | } |
||
345 | } |