aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActors.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSActors.cs131
1 files changed, 131 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
new file mode 100755
index 0000000..5a19ba4
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs
@@ -0,0 +1,131 @@
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 copyrightD
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.Region.Physics.BulletSPlugin
32{
33public class BSActorCollection
34{
35 private BSScene PhysicsScene { get; set; }
36 private Dictionary<string, BSActor> m_actors;
37
38 public BSActorCollection(BSScene physicsScene)
39 {
40 PhysicsScene = physicsScene;
41 m_actors = new Dictionary<string, BSActor>();
42 }
43 public void Add(string name, BSActor actor)
44 {
45 m_actors[name] = actor;
46 }
47 public bool RemoveAndRelease(string name)
48 {
49 bool ret = false;
50 if (m_actors.ContainsKey(name))
51 {
52 BSActor beingRemoved = m_actors[name];
53 beingRemoved.Dispose();
54 m_actors.Remove(name);
55 ret = true;
56 }
57 return ret;
58 }
59 public void Clear()
60 {
61 Release();
62 m_actors.Clear();
63 }
64 public bool HasActor(string name)
65 {
66 return m_actors.ContainsKey(name);
67 }
68 public void ForEachActor(Action<BSActor> act)
69 {
70 foreach (KeyValuePair<string, BSActor> kvp in m_actors)
71 act(kvp.Value);
72 }
73
74 public void Release()
75 {
76 ForEachActor(a => a.Dispose());
77 }
78 public void Refresh()
79 {
80 ForEachActor(a => a.Refresh());
81 }
82 public void RemoveBodyDependencies()
83 {
84 ForEachActor(a => a.RemoveBodyDependencies());
85 }
86}
87
88// =============================================================================
89/// <summary>
90/// Each physical object can have 'actors' who are pushing the object around.
91/// This can be used for hover, locking axis, making vehicles, etc.
92/// Each physical object can have multiple actors acting on it.
93///
94/// An actor usually registers itself with physics scene events (pre-step action)
95/// and modifies the parameters on the host physical object.
96/// </summary>
97public abstract class BSActor
98{
99 protected BSScene m_physicsScene { get; private set; }
100 protected BSPhysObject m_controllingPrim { get; private set; }
101 protected bool Enabled { get; set; }
102 public string ActorName { get; private set; }
103
104 public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName)
105 {
106 m_physicsScene = physicsScene;
107 m_controllingPrim = pObj;
108 ActorName = actorName;
109 Enabled = true;
110 }
111
112 // Return 'true' if activily updating the prim
113 public virtual bool isActive
114 {
115 get { return Enabled; }
116 }
117 // Turn the actor on an off.
118 public virtual void Enable(bool setEnabled)
119 {
120 Enabled = setEnabled;
121 }
122 // Release any connections and resources used by the actor.
123 public abstract void Dispose();
124 // Called when physical parameters (properties set in Bullet) need to be re-applied.
125 public abstract void Refresh();
126 // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
127 // Register a prestep action to restore physical requirements before the next simulation step.
128 public abstract void RemoveBodyDependencies();
129
130}
131}