aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ConvertToPlugins/src/physics/PhysicsManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ConvertToPlugins/src/physics/PhysicsManager.cs167
-rw-r--r--ConvertToPlugins/src/physics/PhysicsManager.csproj41
2 files changed, 208 insertions, 0 deletions
diff --git a/ConvertToPlugins/src/physics/PhysicsManager.cs b/ConvertToPlugins/src/physics/PhysicsManager.cs
new file mode 100644
index 0000000..0986501
--- /dev/null
+++ b/ConvertToPlugins/src/physics/PhysicsManager.cs
@@ -0,0 +1,167 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27using System;
28using System.Collections.Generic;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32
33namespace PhysicsSystem
34{
35 /// <summary>
36 /// Description of MyClass.
37 /// </summary>
38 public class PhysicsManager
39 {
40 private Dictionary<string, IPhysicsPlugin> _plugins=new Dictionary<string, IPhysicsPlugin>();
41
42 public PhysicsManager()
43 {
44
45 }
46
47 public PhysicsScene GetPhysicsScene(string engineName)
48 {
49 if(_plugins.ContainsKey(engineName))
50 {
51 ServerConsole.MainConsole.Instance.WriteLine("creating "+engineName);
52 return _plugins[engineName].GetScene();
53 }
54 else
55 {
56 ServerConsole.MainConsole.Instance.WriteLine("couldn't find physicsEngine: "+ engineName);
57 return null;
58 }
59 }
60
61 public void LoadPlugins()
62 {
63 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory ,"Physics");
64 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
65
66
67 for(int i= 0; i<pluginFiles.Length; i++)
68 {
69 this.AddPlugin(pluginFiles[i]);
70 }
71 }
72
73 private void AddPlugin(string FileName)
74 {
75 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
76
77 foreach (Type pluginType in pluginAssembly.GetTypes())
78 {
79 if (pluginType.IsPublic)
80 {
81 if (!pluginType.IsAbstract)
82 {
83 Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true);
84
85 if (typeInterface != null)
86 {
87 IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
88 plug.Init();
89 this._plugins.Add(plug.GetName(),plug);
90
91 }
92
93 typeInterface = null;
94 }
95 }
96 }
97
98 pluginAssembly = null;
99 }
100 }
101 public interface IPhysicsPlugin
102 {
103 bool Init();
104 PhysicsScene GetScene();
105 string GetName();
106 void Dispose();
107 }
108
109 public abstract class PhysicsScene
110 {
111 public abstract PhysicsActor AddAvatar(PhysicsVector position);
112
113 public abstract void Simulate(float timeStep);
114
115 public abstract void GetResults();
116
117 public abstract void SetTerrain(float[] heightMap);
118
119 public abstract bool IsThreaded
120 {
121 get;
122 }
123 }
124
125 public abstract class PhysicsActor
126 {
127 public abstract PhysicsVector Position
128 {
129 get;
130 set;
131 }
132
133 public abstract PhysicsVector Velocity
134 {
135 get;
136 set;
137 }
138
139 public abstract PhysicsVector Acceleration
140 {
141 get;
142 }
143
144 public abstract void AddForce(PhysicsVector force);
145
146 public abstract void SetMomentum(PhysicsVector momentum);
147 }
148
149 public class PhysicsVector
150 {
151 public float X;
152 public float Y;
153 public float Z;
154
155 public PhysicsVector()
156 {
157
158 }
159
160 public PhysicsVector(float x, float y, float z)
161 {
162 X = x;
163 Y = y;
164 Z = z;
165 }
166 }
167}
diff --git a/ConvertToPlugins/src/physics/PhysicsManager.csproj b/ConvertToPlugins/src/physics/PhysicsManager.csproj
new file mode 100644
index 0000000..dc705e2
--- /dev/null
+++ b/ConvertToPlugins/src/physics/PhysicsManager.csproj
@@ -0,0 +1,41 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <OutputType>Library</OutputType>
4 <RootNamespace>PhysicsManager</RootNamespace>
5 <AssemblyName>PhysicsManager</AssemblyName>
6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8 <ProjectGuid>{3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}</ProjectGuid>
9 </PropertyGroup>
10 <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
11 <OutputPath>bin\Debug\</OutputPath>
12 <Optimize>False</Optimize>
13 <DefineConstants>DEBUG;TRACE</DefineConstants>
14 <DebugSymbols>True</DebugSymbols>
15 <DebugType>Full</DebugType>
16 <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
17 </PropertyGroup>
18 <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
19 <OutputPath>bin\Release\</OutputPath>
20 <Optimize>True</Optimize>
21 <DefineConstants>TRACE</DefineConstants>
22 <DebugSymbols>False</DebugSymbols>
23 <DebugType>None</DebugType>
24 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
25 </PropertyGroup>
26 <ItemGroup>
27 <Reference Include="System" />
28 <Reference Include="System.Xml" />
29 </ItemGroup>
30 <ItemGroup>
31 <Compile Include="PhysicsManager.cs" />
32 <Compile Include="AssemblyInfo.cs" />
33 </ItemGroup>
34 <ItemGroup>
35 <ProjectReference Include="..\ServerConsole\ServerConsole\ServerConsole.csproj">
36 <Project>{C9A6026D-8E0C-4FE4-8691-FB2A566AA245}</Project>
37 <Name>ServerConsole</Name>
38 </ProjectReference>
39 </ItemGroup>
40 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
41</Project> \ No newline at end of file