OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
BSActors.cs
Go to the documentation of this file.
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  */
27 using System;
28 using System.Collections.Generic;
29 using System.Text;
30 
31 namespace OpenSim.Region.PhysicsModule.BulletS
32 {
33 public class BSActorCollection
34 {
35  private Dictionary<string, BSActor> m_actors;
36 
38  {
39  m_actors = new Dictionary<string, BSActor>();
40  }
41  public void Add(string name, BSActor actor)
42  {
43  lock (m_actors)
44  {
45  if (!m_actors.ContainsKey(name))
46  {
47  m_actors[name] = actor;
48  }
49  }
50  }
51  public bool RemoveAndRelease(string name)
52  {
53  bool ret = false;
54  lock (m_actors)
55  {
56  if (m_actors.ContainsKey(name))
57  {
58  BSActor beingRemoved = m_actors[name];
59  m_actors.Remove(name);
60  beingRemoved.Dispose();
61  ret = true;
62  }
63  }
64  return ret;
65  }
66  public void Clear()
67  {
68  lock (m_actors)
69  {
70  ForEachActor(a => a.Dispose());
71  m_actors.Clear();
72  }
73  }
74  public void Dispose()
75  {
76  Clear();
77  }
78  public bool HasActor(string name)
79  {
80  return m_actors.ContainsKey(name);
81  }
82  public bool TryGetActor(string actorName, out BSActor theActor)
83  {
84  return m_actors.TryGetValue(actorName, out theActor);
85  }
86  public void ForEachActor(Action<BSActor> act)
87  {
88  lock (m_actors)
89  {
90  foreach (KeyValuePair<string, BSActor> kvp in m_actors)
91  act(kvp.Value);
92  }
93  }
94 
95  public void Enable(bool enabl)
96  {
97  ForEachActor(a => a.SetEnabled(enabl));
98  }
99  public void Refresh()
100  {
101  ForEachActor(a => a.Refresh());
102  }
103  public void RemoveDependencies()
104  {
105  ForEachActor(a => a.RemoveDependencies());
106  }
107 }
108 
109 // =============================================================================
118 public abstract class BSActor
119 {
120  protected BSScene m_physicsScene { get; private set; }
121  protected BSPhysObject m_controllingPrim { get; private set; }
122  public virtual bool Enabled { get; set; }
123  public string ActorName { get; private set; }
124 
125  public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName)
126  {
127  m_physicsScene = physicsScene;
128  m_controllingPrim = pObj;
129  ActorName = actorName;
130  Enabled = true;
131  }
132 
133  // Return 'true' if activily updating the prim
134  public virtual bool isActive
135  {
136  get { return Enabled; }
137  }
138 
139  // Turn the actor on an off. Only used by ActorCollection to set all enabled/disabled.
140  // Anyone else should assign true/false to 'Enabled'.
141  public void SetEnabled(bool setEnabled)
142  {
143  Enabled = setEnabled;
144  }
145  // Release any connections and resources used by the actor.
146  public abstract void Dispose();
147  // Called when physical parameters (properties set in Bullet) need to be re-applied.
148  public abstract void Refresh();
149  // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
150  // Register a prestep action to restore physical requirements before the next simulation step.
151  public abstract void RemoveDependencies();
152 
153 }
154 }
Each physical object can have 'actors' who are pushing the object around. This can be used for hover...
Definition: BSActors.cs:118
BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName)
Definition: BSActors.cs:125
bool TryGetActor(string actorName, out BSActor theActor)
Definition: BSActors.cs:82
void Add(string name, BSActor actor)
Definition: BSActors.cs:41