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.cs250
1 files changed, 0 insertions, 250 deletions
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
deleted file mode 100644
index ddbe80b..0000000
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ /dev/null
@@ -1,250 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenMetaverse;
36
37namespace OpenSim.Region.Physics.Manager
38{
39 /// <summary>
40 /// Description of MyClass.
41 /// </summary>
42 public class PhysicsPluginManager
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 private Dictionary<string, IPhysicsPlugin> _PhysPlugins = new Dictionary<string, IPhysicsPlugin>();
47 private Dictionary<string, IMeshingPlugin> _MeshPlugins = new Dictionary<string, IMeshingPlugin>();
48
49 /// <summary>
50 /// Constructor.
51 /// </summary>
52 public PhysicsPluginManager()
53 {
54 // Load "plugins", that are hard coded and not existing in form of an external lib, and hence always
55 // available
56 IMeshingPlugin plugHard;
57 plugHard = new ZeroMesherPlugin();
58 _MeshPlugins.Add(plugHard.GetName(), plugHard);
59
60 m_log.Info("[PHYSICS]: Added meshing engine: " + plugHard.GetName());
61 }
62
63 // Legacy method for simulators before extent was passed
64 public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName,
65 IConfigSource config, string regionName)
66 {
67 Vector3 extent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
68 return GetPhysicsScene(physEngineName, meshEngineName, config, regionName, extent);
69 }
70
71 /// <summary>
72 /// Get a physics scene for the given physics engine and mesher.
73 /// </summary>
74 /// <param name="physEngineName"></param>
75 /// <param name="meshEngineName"></param>
76 /// <param name="config"></param>
77 /// <returns></returns>
78 public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName,
79 IConfigSource config, string regionName, Vector3 regionExtent)
80 {
81 if (String.IsNullOrEmpty(physEngineName))
82 {
83 return PhysicsScene.Null;
84 }
85
86 if (String.IsNullOrEmpty(meshEngineName))
87 {
88 return PhysicsScene.Null;
89 }
90
91 IMesher meshEngine = null;
92 if (_MeshPlugins.ContainsKey(meshEngineName))
93 {
94 m_log.Info("[PHYSICS]: creating meshing engine " + meshEngineName);
95 meshEngine = _MeshPlugins[meshEngineName].GetMesher(config);
96 }
97 else
98 {
99 m_log.WarnFormat("[PHYSICS]: couldn't find meshingEngine: {0}", meshEngineName);
100 throw new ArgumentException(String.Format("couldn't find meshingEngine: {0}", meshEngineName));
101 }
102
103 if (_PhysPlugins.ContainsKey(physEngineName))
104 {
105 m_log.Info("[PHYSICS]: creating " + physEngineName);
106 PhysicsScene result = _PhysPlugins[physEngineName].GetScene(regionName);
107 result.Initialise(meshEngine, config, regionExtent);
108 return result;
109 }
110 else
111 {
112 m_log.WarnFormat("[PHYSICS]: couldn't find physicsEngine: {0}", physEngineName);
113 throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}", physEngineName));
114 }
115 }
116
117 /// <summary>
118 /// Load all plugins in assemblies at the given path
119 /// </summary>
120 /// <param name="pluginsPath"></param>
121 public void LoadPluginsFromAssemblies(string assembliesPath)
122 {
123 // Walk all assemblies (DLLs effectively) and see if they are home
124 // of a plugin that is of interest for us
125 string[] pluginFiles = Directory.GetFiles(assembliesPath, "*.dll");
126
127 for (int i = 0; i < pluginFiles.Length; i++)
128 {
129 LoadPluginsFromAssembly(pluginFiles[i]);
130 }
131 }
132
133 /// <summary>
134 /// Load plugins from an assembly at the given path
135 /// </summary>
136 /// <param name="assemblyPath"></param>
137 public void LoadPluginsFromAssembly(string assemblyPath)
138 {
139 // TODO / NOTE
140 // The assembly named 'OpenSim.Region.Physics.BasicPhysicsPlugin' was loaded from
141 // 'file:///C:/OpenSim/trunk2/bin/Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll'
142 // using the LoadFrom context. The use of this context can result in unexpected behavior
143 // for serialization, casting and dependency resolution. In almost all cases, it is recommended
144 // that the LoadFrom context be avoided. This can be done by installing assemblies in the
145 // Global Assembly Cache or in the ApplicationBase directory and using Assembly.
146 // Load when explicitly loading assemblies.
147 Assembly pluginAssembly = null;
148 Type[] types = null;
149
150 try
151 {
152 pluginAssembly = Assembly.LoadFrom(assemblyPath);
153 }
154 catch (Exception ex)
155 {
156 m_log.Error("[PHYSICS]: Failed to load plugin from " + assemblyPath, ex);
157 }
158
159 if (pluginAssembly != null)
160 {
161 try
162 {
163 types = pluginAssembly.GetTypes();
164 }
165 catch (ReflectionTypeLoadException ex)
166 {
167 m_log.Error("[PHYSICS]: Failed to enumerate types in plugin from " + assemblyPath + ": " +
168 ex.LoaderExceptions[0].Message, ex);
169 }
170 catch (Exception ex)
171 {
172 m_log.Error("[PHYSICS]: Failed to enumerate types in plugin from " + assemblyPath, ex);
173 }
174
175 if (types != null)
176 {
177 foreach (Type pluginType in types)
178 {
179 if (pluginType.IsPublic)
180 {
181 if (!pluginType.IsAbstract)
182 {
183 Type physTypeInterface = pluginType.GetInterface("IPhysicsPlugin");
184
185 if (physTypeInterface != null)
186 {
187 IPhysicsPlugin plug =
188 (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
189 plug.Init();
190 if (!_PhysPlugins.ContainsKey(plug.GetName()))
191 {
192 _PhysPlugins.Add(plug.GetName(), plug);
193 m_log.Info("[PHYSICS]: Added physics engine: " + plug.GetName());
194 }
195 }
196
197 Type meshTypeInterface = pluginType.GetInterface("IMeshingPlugin");
198
199 if (meshTypeInterface != null)
200 {
201 IMeshingPlugin plug =
202 (IMeshingPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
203 if (!_MeshPlugins.ContainsKey(plug.GetName()))
204 {
205 _MeshPlugins.Add(plug.GetName(), plug);
206 m_log.Info("[PHYSICS]: Added meshing engine: " + plug.GetName());
207 }
208 }
209
210 physTypeInterface = null;
211 meshTypeInterface = null;
212 }
213 }
214 }
215 }
216 }
217
218 pluginAssembly = null;
219 }
220
221 //---
222 public static void PhysicsPluginMessage(string message, bool isWarning)
223 {
224 if (isWarning)
225 {
226 m_log.Warn("[PHYSICS]: " + message);
227 }
228 else
229 {
230 m_log.Info("[PHYSICS]: " + message);
231 }
232 }
233
234 //---
235 }
236
237 public interface IPhysicsPlugin
238 {
239 bool Init();
240 PhysicsScene GetScene(String sceneIdentifier);
241 string GetName();
242 void Dispose();
243 }
244
245 public interface IMeshingPlugin
246 {
247 string GetName();
248 IMesher GetMesher(IConfigSource config);
249 }
250}