clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
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 // Deprecated. Do not use this for new physics engines.
130 public abstract void Initialise(IMesher meshmerizer, IConfigSource config);
131  
132 // For older physics engines that do not implement non-legacy region sizes.
133 // If the physics engine handles the region extent feature, it overrides this function.
134 public virtual void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
135 {
136 // If not overridden, call the old initialization entry.
137 Initialise(meshmerizer, config);
138 }
139  
140 /// <summary>
141 /// Add an avatar
142 /// </summary>
143 /// <param name="avName"></param>
144 /// <param name="position"></param>
145 /// <param name="size"></param>
146 /// <param name="isFlying"></param>
147 /// <returns></returns>
148 public abstract PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying);
149  
150 /// <summary>
151 /// Add an avatar
152 /// </summary>
153 /// <param name="localID"></param>
154 /// <param name="avName"></param>
155 /// <param name="position"></param>
156 /// <param name="size"></param>
157 /// <param name="isFlying"></param>
158 /// <returns></returns>
159 public virtual PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying)
160 {
161 PhysicsActor ret = AddAvatar(avName, position, size, isFlying);
162 if (ret != null) ret.LocalID = localID;
163 return ret;
164 }
165  
166 /// <summary>
167 /// Remove an avatar.
168 /// </summary>
169 /// <param name="actor"></param>
170 public abstract void RemoveAvatar(PhysicsActor actor);
171  
172 /// <summary>
173 /// Remove a prim.
174 /// </summary>
175 /// <param name="prim"></param>
176 public abstract void RemovePrim(PhysicsActor prim);
177  
178 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
179 Vector3 size, Quaternion rotation, bool isPhysical, uint localid);
180  
181 public virtual PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
182 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapetype, uint localid)
183 {
184 return AddPrimShape(primName, pbs, position, size, rotation, isPhysical, localid);
185 }
186  
187 public virtual float TimeDilation
188 {
189 get { return 1.0f; }
190 }
191  
192 public virtual bool SupportsNINJAJoints
193 {
194 get { return false; }
195 }
196  
197 public virtual PhysicsJoint RequestJointCreation(string objectNameInScene, PhysicsJointType jointType, Vector3 position,
198 Quaternion rotation, string parms, List<string> bodyNames, string trackedBodyName, Quaternion localRotation)
199 { return null; }
200  
201 public virtual void RequestJointDeletion(string objectNameInScene)
202 { return; }
203  
204 public virtual void RemoveAllJointsConnectedToActorThreadLocked(PhysicsActor actor)
205 { return; }
206  
207 public virtual void DumpJointInfo()
208 { return; }
209  
210 public event JointMoved OnJointMoved;
211  
212 protected virtual void DoJointMoved(PhysicsJoint joint)
213 {
214 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
215 // not allow subclasses to invoke the parent class event.
216 if (OnJointMoved != null)
217 {
218 OnJointMoved(joint);
219 }
220 }
221  
222 public event JointDeactivated OnJointDeactivated;
223  
224 protected virtual void DoJointDeactivated(PhysicsJoint joint)
225 {
226 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
227 // not allow subclasses to invoke the parent class event.
228 if (OnJointDeactivated != null)
229 {
230 OnJointDeactivated(joint);
231 }
232 }
233  
234 public event JointErrorMessage OnJointErrorMessage;
235  
236 protected virtual void DoJointErrorMessage(PhysicsJoint joint, string message)
237 {
238 // We need this to allow subclasses (but not other classes) to invoke the event; C# does
239 // not allow subclasses to invoke the parent class event.
240 if (OnJointErrorMessage != null)
241 {
242 OnJointErrorMessage(joint, message);
243 }
244 }
245  
246 public virtual Vector3 GetJointAnchor(PhysicsJoint joint)
247 { return Vector3.Zero; }
248  
249 public virtual Vector3 GetJointAxis(PhysicsJoint joint)
250 { return Vector3.Zero; }
251  
252 public abstract void AddPhysicsActorTaint(PhysicsActor prim);
253  
254 /// <summary>
255 /// Perform a simulation of the current physics scene over the given timestep.
256 /// </summary>
257 /// <param name="timeStep"></param>
258 /// <returns>The number of frames simulated over that period.</returns>
259 public abstract float Simulate(float timeStep);
260  
261 /// <summary>
262 /// Get statistics about this scene.
263 /// </summary>
264 /// <remarks>This facility is currently experimental and subject to change.</remarks>
265 /// <returns>
266 /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null.
267 /// </returns>
268 public virtual Dictionary<string, float> GetStats() { return null; }
269  
270 public abstract void GetResults();
271  
272 public abstract void SetTerrain(float[] heightMap);
273  
274 public abstract void SetWaterLevel(float baseheight);
275  
276 public abstract void DeleteTerrain();
277  
278 public abstract void Dispose();
279  
280 public abstract Dictionary<uint, float> GetTopColliders();
281  
282 public abstract bool IsThreaded { get; }
283  
284 /// <summary>
285 /// True if the physics plugin supports raycasting against the physics scene
286 /// </summary>
287 public virtual bool SupportsRayCast()
288 {
289 return false;
290 }
291  
292 public virtual bool SupportsCombining()
293 {
294 return false;
295 }
296  
297 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
298  
299 public virtual void UnCombine(PhysicsScene pScene) {}
300  
301 /// <summary>
302 /// Queue a raycast against the physics scene.
303 /// The provided callback method will be called when the raycast is complete
304 ///
305 /// Many physics engines don't support collision testing at the same time as
306 /// manipulating the physics scene, so we queue the request up and callback
307 /// a custom method when the raycast is complete.
308 /// This allows physics engines that give an immediate result to callback immediately
309 /// and ones that don't, to callback when it gets a result back.
310 ///
311 /// ODE for example will not allow you to change the scene while collision testing or
312 /// it asserts, 'opteration not valid for locked space'. This includes adding a ray to the scene.
313 ///
314 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
315 /// </summary>
316 /// <param name="position">Origin of the ray</param>
317 /// <param name="direction">Direction of the ray</param>
318 /// <param name="length">Length of ray in meters</param>
319 /// <param name="retMethod">Method to call when the raycast is complete</param>
320 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
321 {
322 if (retMethod != null)
323 retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
324 }
325  
326 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
327 {
328 if (retMethod != null)
329 retMethod(new List<ContactResult>());
330 }
331  
332 public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
333 {
334 return new List<ContactResult>();
335 }
336  
337 public virtual object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
338 {
339 return null;
340 }
341  
342 public virtual bool SupportsRaycastWorldFiltered()
343 {
344 return false;
345 }
346  
347 // Extendable interface for new, physics engine specific operations
348 public virtual object Extension(string pFunct, params object[] pParams)
349 {
350 // A NOP if the extension thing is not implemented by the physics engine
351 return null;
352 }
353 }
354 }