diff options
author | Diva Canto | 2015-08-31 16:23:43 -0700 |
---|---|---|
committer | Diva Canto | 2015-08-31 16:23:43 -0700 |
commit | 9435405ca1c173963dd6e97116a27b798a211801 (patch) | |
tree | e48898721c32cc0ff43e17a4ba660b8bcb55534d /OpenSim/Region/PhysicsModules/SharedBase | |
parent | Physics refactoring: all unit tests pass. (diff) | |
download | opensim-SC-9435405ca1c173963dd6e97116a27b798a211801.zip opensim-SC-9435405ca1c173963dd6e97116a27b798a211801.tar.gz opensim-SC-9435405ca1c173963dd6e97116a27b798a211801.tar.bz2 opensim-SC-9435405ca1c173963dd6e97116a27b798a211801.tar.xz |
Deleted physics plugin classes.
More unit tests fixed.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/SharedBase')
-rw-r--r-- | OpenSim/Region/PhysicsModules/SharedBase/PhysicsPluginManager.cs | 235 |
1 files changed, 0 insertions, 235 deletions
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsPluginManager.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsPluginManager.cs deleted file mode 100644 index 487582c..0000000 --- a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsPluginManager.cs +++ /dev/null | |||
@@ -1,235 +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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using log4net; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Region.PhysicsModules.SharedBase | ||
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 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// Get a physics scene for the given physics engine and mesher. | ||
58 | /// </summary> | ||
59 | /// <param name="physEngineName"></param> | ||
60 | /// <param name="meshEngineName"></param> | ||
61 | /// <param name="config"></param> | ||
62 | /// <returns></returns> | ||
63 | public PhysicsScene GetPhysicsScene(string physEngineName, string meshEngineName, | ||
64 | IConfigSource config, string regionName, Vector3 regionExtent) | ||
65 | { | ||
66 | if (String.IsNullOrEmpty(physEngineName)) | ||
67 | { | ||
68 | return PhysicsScene.Null; | ||
69 | } | ||
70 | |||
71 | if (String.IsNullOrEmpty(meshEngineName)) | ||
72 | { | ||
73 | return PhysicsScene.Null; | ||
74 | } | ||
75 | |||
76 | IMesher meshEngine = null; | ||
77 | if (_MeshPlugins.ContainsKey(meshEngineName)) | ||
78 | { | ||
79 | m_log.Info("[PHYSICS]: creating meshing engine " + meshEngineName); | ||
80 | meshEngine = _MeshPlugins[meshEngineName].GetMesher(config); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | m_log.WarnFormat("[PHYSICS]: couldn't find meshingEngine: {0}", meshEngineName); | ||
85 | throw new ArgumentException(String.Format("couldn't find meshingEngine: {0}", meshEngineName)); | ||
86 | } | ||
87 | |||
88 | if (_PhysPlugins.ContainsKey(physEngineName)) | ||
89 | { | ||
90 | m_log.Info("[PHYSICS]: creating " + physEngineName); | ||
91 | PhysicsScene result = _PhysPlugins[physEngineName].GetScene(regionName); | ||
92 | //result.Initialise(meshEngine, config, regionExtent); | ||
93 | return result; | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | m_log.WarnFormat("[PHYSICS]: couldn't find physicsEngine: {0}", physEngineName); | ||
98 | throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}", physEngineName)); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | /// <summary> | ||
103 | /// Load all plugins in assemblies at the given path | ||
104 | /// </summary> | ||
105 | /// <param name="pluginsPath"></param> | ||
106 | public void LoadPluginsFromAssemblies(string assembliesPath) | ||
107 | { | ||
108 | // Walk all assemblies (DLLs effectively) and see if they are home | ||
109 | // of a plugin that is of interest for us | ||
110 | string[] pluginFiles = Directory.GetFiles(assembliesPath, "*.dll"); | ||
111 | |||
112 | for (int i = 0; i < pluginFiles.Length; i++) | ||
113 | { | ||
114 | LoadPluginsFromAssembly(pluginFiles[i]); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// Load plugins from an assembly at the given path | ||
120 | /// </summary> | ||
121 | /// <param name="assemblyPath"></param> | ||
122 | public void LoadPluginsFromAssembly(string assemblyPath) | ||
123 | { | ||
124 | // TODO / NOTE | ||
125 | // The assembly named 'OpenSim.Region.PhysicsModule.BasicPhysics' was loaded from | ||
126 | // 'file:///C:/OpenSim/trunk2/bin/Physics/OpenSim.Region.PhysicsModule.BasicPhysics.dll' | ||
127 | // using the LoadFrom context. The use of this context can result in unexpected behavior | ||
128 | // for serialization, casting and dependency resolution. In almost all cases, it is recommended | ||
129 | // that the LoadFrom context be avoided. This can be done by installing assemblies in the | ||
130 | // Global Assembly Cache or in the ApplicationBase directory and using Assembly. | ||
131 | // Load when explicitly loading assemblies. | ||
132 | Assembly pluginAssembly = null; | ||
133 | Type[] types = null; | ||
134 | |||
135 | try | ||
136 | { | ||
137 | pluginAssembly = Assembly.LoadFrom(assemblyPath); | ||
138 | } | ||
139 | catch (Exception ex) | ||
140 | { | ||
141 | m_log.Error("[PHYSICS]: Failed to load plugin from " + assemblyPath, ex); | ||
142 | } | ||
143 | |||
144 | if (pluginAssembly != null) | ||
145 | { | ||
146 | try | ||
147 | { | ||
148 | types = pluginAssembly.GetTypes(); | ||
149 | } | ||
150 | catch (ReflectionTypeLoadException ex) | ||
151 | { | ||
152 | m_log.Error("[PHYSICS]: Failed to enumerate types in plugin from " + assemblyPath + ": " + | ||
153 | ex.LoaderExceptions[0].Message, ex); | ||
154 | } | ||
155 | catch (Exception ex) | ||
156 | { | ||
157 | m_log.Error("[PHYSICS]: Failed to enumerate types in plugin from " + assemblyPath, ex); | ||
158 | } | ||
159 | |||
160 | if (types != null) | ||
161 | { | ||
162 | foreach (Type pluginType in types) | ||
163 | { | ||
164 | if (pluginType.IsPublic) | ||
165 | { | ||
166 | if (!pluginType.IsAbstract) | ||
167 | { | ||
168 | Type physTypeInterface = pluginType.GetInterface("IPhysicsPlugin"); | ||
169 | |||
170 | if (physTypeInterface != null) | ||
171 | { | ||
172 | IPhysicsPlugin plug = | ||
173 | (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
174 | plug.Init(); | ||
175 | if (!_PhysPlugins.ContainsKey(plug.GetName())) | ||
176 | { | ||
177 | _PhysPlugins.Add(plug.GetName(), plug); | ||
178 | m_log.Info("[PHYSICS]: Added physics engine: " + plug.GetName()); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | Type meshTypeInterface = pluginType.GetInterface("IMeshingPlugin"); | ||
183 | |||
184 | if (meshTypeInterface != null) | ||
185 | { | ||
186 | IMeshingPlugin plug = | ||
187 | (IMeshingPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
188 | if (!_MeshPlugins.ContainsKey(plug.GetName())) | ||
189 | { | ||
190 | _MeshPlugins.Add(plug.GetName(), plug); | ||
191 | m_log.Info("[PHYSICS]: Added meshing engine: " + plug.GetName()); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | physTypeInterface = null; | ||
196 | meshTypeInterface = null; | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | pluginAssembly = null; | ||
204 | } | ||
205 | |||
206 | //--- | ||
207 | public static void PhysicsPluginMessage(string message, bool isWarning) | ||
208 | { | ||
209 | if (isWarning) | ||
210 | { | ||
211 | m_log.Warn("[PHYSICS]: " + message); | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | m_log.Info("[PHYSICS]: " + message); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | //--- | ||
220 | } | ||
221 | |||
222 | public interface IPhysicsPlugin | ||
223 | { | ||
224 | bool Init(); | ||
225 | PhysicsScene GetScene(String sceneIdentifier); | ||
226 | string GetName(); | ||
227 | void Dispose(); | ||
228 | } | ||
229 | |||
230 | public interface IMeshingPlugin | ||
231 | { | ||
232 | string GetName(); | ||
233 | IMesher GetMesher(IConfigSource config); | ||
234 | } | ||
235 | } | ||