123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace OpenSim.Region.Physics.BulletSPlugin
- {
- public class BSActorCollection
- {
- private BSScene m_physicsScene { get; set; }
- private Dictionary<string, BSActor> m_actors;
- public BSActorCollection(BSScene physicsScene)
- {
- m_physicsScene = physicsScene;
- m_actors = new Dictionary<string, BSActor>();
- }
- public void Add(string name, BSActor actor)
- {
- lock (m_actors)
- {
- if (!m_actors.ContainsKey(name))
- {
- m_actors[name] = actor;
- }
- }
- }
- public bool RemoveAndRelease(string name)
- {
- bool ret = false;
- lock (m_actors)
- {
- if (m_actors.ContainsKey(name))
- {
- BSActor beingRemoved = m_actors[name];
- m_actors.Remove(name);
- beingRemoved.Dispose();
- ret = true;
- }
- }
- return ret;
- }
- public void Clear()
- {
- lock (m_actors)
- {
- ForEachActor(a => a.Dispose());
- m_actors.Clear();
- }
- }
- public void Dispose()
- {
- Clear();
- }
- public bool HasActor(string name)
- {
- return m_actors.ContainsKey(name);
- }
- public bool TryGetActor(string actorName, out BSActor theActor)
- {
- return m_actors.TryGetValue(actorName, out theActor);
- }
- public void ForEachActor(Action<BSActor> act)
- {
- lock (m_actors)
- {
- foreach (KeyValuePair<string, BSActor> kvp in m_actors)
- act(kvp.Value);
- }
- }
- public void Enable(bool enabl)
- {
- ForEachActor(a => a.SetEnabled(enabl));
- }
- public void Refresh()
- {
- ForEachActor(a => a.Refresh());
- }
- public void RemoveDependencies()
- {
- ForEachActor(a => a.RemoveDependencies());
- }
- }
- public abstract class BSActor
- {
- protected BSScene m_physicsScene { get; private set; }
- protected BSPhysObject m_controllingPrim { get; private set; }
- public virtual bool Enabled { get; set; }
- public string ActorName { get; private set; }
- public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName)
- {
- m_physicsScene = physicsScene;
- m_controllingPrim = pObj;
- ActorName = actorName;
- Enabled = true;
- }
-
- public virtual bool isActive
- {
- get { return Enabled; }
- }
-
-
- public void SetEnabled(bool setEnabled)
- {
- Enabled = setEnabled;
- }
-
- public abstract void Dispose();
-
- public abstract void Refresh();
-
-
- public abstract void RemoveDependencies();
- }
- }
|