aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs')
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs143
1 files changed, 72 insertions, 71 deletions
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index 81bc938..09ebf29 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -33,77 +33,77 @@ using OpenSim.Framework.Console;
33 33
34namespace OpenSim.Region.Physics.Manager 34namespace OpenSim.Region.Physics.Manager
35{ 35{
36 /// <summary> 36 /// <summary>
37 /// Description of MyClass. 37 /// Description of MyClass.
38 /// </summary> 38 /// </summary>
39 public class PhysicsPluginManager 39 public class PhysicsPluginManager
40 { 40 {
41 private Dictionary<string, IPhysicsPlugin> _plugins=new Dictionary<string, IPhysicsPlugin>(); 41 private Dictionary<string, IPhysicsPlugin> _plugins = new Dictionary<string, IPhysicsPlugin>();
42 42
43 public PhysicsPluginManager() 43 public PhysicsPluginManager()
44 { 44 {
45 45 }
46 } 46
47 47 public PhysicsScene GetPhysicsScene(string engineName)
48 public PhysicsScene GetPhysicsScene(string engineName) 48 {
49 {
50 if (String.IsNullOrEmpty(engineName)) 49 if (String.IsNullOrEmpty(engineName))
51 { 50 {
52 return PhysicsScene.Null; 51 return PhysicsScene.Null;
53 } 52 }
54 53
55 if(_plugins.ContainsKey(engineName)) 54 if (_plugins.ContainsKey(engineName))
56 { 55 {
57 MainLog.Instance.Verbose("PHYSICS","creating "+engineName); 56 MainLog.Instance.Verbose("PHYSICS", "creating " + engineName);
58 return _plugins[engineName].GetScene(); 57 return _plugins[engineName].GetScene();
59 } 58 }
60 else 59 else
61 { 60 {
62 MainLog.Instance.Warn("PHYSICS", "couldn't find physicsEngine: {0}", engineName); 61 MainLog.Instance.Warn("PHYSICS", "couldn't find physicsEngine: {0}", engineName);
63 throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}",engineName)); 62 throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}", engineName));
64 } 63 }
65 } 64 }
66 65
67 public void LoadPlugins() 66 public void LoadPlugins()
68 { 67 {
69 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory ,"Physics"); 68 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Physics");
70 string[] pluginFiles = Directory.GetFiles(path, "*.dll"); 69 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
71 70
72 71
73 for(int i= 0; i<pluginFiles.Length; i++) 72 for (int i = 0; i < pluginFiles.Length; i++)
74 { 73 {
75 this.AddPlugin(pluginFiles[i]); 74 AddPlugin(pluginFiles[i]);
76 } 75 }
77 } 76 }
78 77
79 private void AddPlugin(string FileName) 78 private void AddPlugin(string FileName)
80 { 79 {
81 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 80 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
82 81
83 foreach (Type pluginType in pluginAssembly.GetTypes()) 82 foreach (Type pluginType in pluginAssembly.GetTypes())
84 { 83 {
85 if (pluginType.IsPublic) 84 if (pluginType.IsPublic)
86 { 85 {
87 if (!pluginType.IsAbstract) 86 if (!pluginType.IsAbstract)
88 { 87 {
89 Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true); 88 Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true);
90 89
91 if (typeInterface != null) 90 if (typeInterface != null)
92 { 91 {
93 IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 92 IPhysicsPlugin plug =
94 plug.Init(); 93 (IPhysicsPlugin) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
95 this._plugins.Add(plug.GetName(),plug); 94 plug.Init();
96 OpenSim.Framework.Console.MainLog.Instance.Verbose("PHYSICS","Added physics engine: " + plug.GetName()); 95 _plugins.Add(plug.GetName(), plug);
97 96 MainLog.Instance.Verbose("PHYSICS", "Added physics engine: " + plug.GetName());
98 } 97 }
99 98
100 typeInterface = null; 99 typeInterface = null;
101 } 100 }
102 } 101 }
103 } 102 }
104 103
105 pluginAssembly = null; 104 pluginAssembly = null;
106 } 105 }
106
107 //--- 107 //---
108 public static void PhysicsPluginMessage(string message, bool isWarning) 108 public static void PhysicsPluginMessage(string message, bool isWarning)
109 { 109 {
@@ -116,14 +116,15 @@ namespace OpenSim.Region.Physics.Manager
116 MainLog.Instance.Verbose("PHYSICS", message); 116 MainLog.Instance.Verbose("PHYSICS", message);
117 } 117 }
118 } 118 }
119
119 //--- 120 //---
120 } 121 }
121 122
122 public interface IPhysicsPlugin 123 public interface IPhysicsPlugin
123 { 124 {
124 bool Init(); 125 bool Init();
125 PhysicsScene GetScene(); 126 PhysicsScene GetScene();
126 string GetName(); 127 string GetName();
127 void Dispose(); 128 void Dispose();
128 } 129 }
129} 130} \ No newline at end of file