Skip to content

Commit

Permalink
- Imported PluginSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Kintaro committed Mar 17, 2010
1 parent da897ce commit 9b819e0
Show file tree
Hide file tree
Showing 18 changed files with 806 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Hyperion.Core/Hyperion.Core.csproj
Expand Up @@ -135,6 +135,22 @@
<Compile Include="Parallel\ITask.cs" />
<Compile Include="Parallel\ConditionVariable.cs" />
<Compile Include="Parallel\ParallelUtility.cs" />
<Compile Include="PluginSystem\AcceleratorPlugin.cs" />
<Compile Include="PluginSystem\AreaLightPlugin.cs" />
<Compile Include="PluginSystem\CameraPlugin.cs" />
<Compile Include="PluginSystem\FilmPlugin.cs" />
<Compile Include="PluginSystem\FilterPlugin.cs" />
<Compile Include="PluginSystem\LightPlugin.cs" />
<Compile Include="PluginSystem\MaterialPlugin.cs" />
<Compile Include="PluginSystem\Plugin.cs" />
<Compile Include="PluginSystem\PluginManager.cs" />
<Compile Include="PluginSystem\SamplerPlugin.cs" />
<Compile Include="PluginSystem\ShapePlugin.cs" />
<Compile Include="PluginSystem\SurfaceIntegratorPlugin.cs" />
<Compile Include="PluginSystem\TexturePlugin.cs" />
<Compile Include="PluginSystem\VolumeIntegratorPlugin.cs" />
<Compile Include="Tools\TextureParameterSet.cs" />
<Compile Include="PluginSystem\RendererPlugin.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Geometry\" />
Expand All @@ -144,6 +160,7 @@
<Folder Include="Parser\" />
<Folder Include="Parser\Nodes\" />
<Folder Include="Parallel\" />
<Folder Include="PluginSystem\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
38 changes: 38 additions & 0 deletions Hyperion.Core/PluginSystem/AcceleratorPlugin.cs
@@ -0,0 +1,38 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of cameras.
/// </summary>
public class AcceleratorPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate IPrimitive CreateAcceleratorDelegate (List<IPrimitive> primitives, ParameterSet paramSet);

/// <summary>
///
/// </summary>
public CreateAcceleratorDelegate CreateAccelerator;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public AcceleratorPlugin (string name) : base("Accelerators", name)
{
MethodInfo methodInfo = GetMethod ("CreateAccelerator");
CreateAccelerator = Delegate.CreateDelegate (typeof(CreateAcceleratorDelegate), methodInfo) as CreateAcceleratorDelegate;
}
}
}
38 changes: 38 additions & 0 deletions Hyperion.Core/PluginSystem/AreaLightPlugin.cs
@@ -0,0 +1,38 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of cameras.
/// </summary>
public class AreaLightPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate ILight CreateAreaLightDelegate (Transform objectToWorld, ParameterSet parameters, IShape shape);

/// <summary>
///
/// </summary>
public CreateAreaLightDelegate CreateAreaLight;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public AreaLightPlugin (string name) : base("Lights", name)
{
MethodInfo methodInfo = GetMethod ("CreateAreaLight");
CreateAreaLight = Delegate.CreateDelegate (typeof(CreateAreaLightDelegate), methodInfo) as CreateAreaLightDelegate;
}
}
}
37 changes: 37 additions & 0 deletions Hyperion.Core/PluginSystem/CameraPlugin.cs
@@ -0,0 +1,37 @@

using System;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of cameras.
/// </summary>
public class CameraPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate ICamera CreateCameraDelegate (ParameterSet paramSet, Transform worldToCamera, IFilm film);

/// <summary>
///
/// </summary>
public CreateCameraDelegate CreateCamera;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public CameraPlugin (string name) : base("Cameras", name)
{
MethodInfo methodInfo = GetMethod ("CreateCamera");
CreateCamera = Delegate.CreateDelegate (typeof(CreateCameraDelegate), methodInfo) as CreateCameraDelegate;
}
}
}
37 changes: 37 additions & 0 deletions Hyperion.Core/PluginSystem/FilmPlugin.cs
@@ -0,0 +1,37 @@

using System;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of films.
/// </summary>
public class FilmPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate IFilm CreateFilmDelegate (ParameterSet paramSet, IFilter filter);

/// <summary>
///
/// </summary>
public CreateFilmDelegate CreateFilm;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public FilmPlugin (string name) : base("Films", name)
{
MethodInfo methodInfo = GetMethod ("CreateFilm");
CreateFilm = Delegate.CreateDelegate (typeof(CreateFilmDelegate), methodInfo) as CreateFilmDelegate;
}
}
}
37 changes: 37 additions & 0 deletions Hyperion.Core/PluginSystem/FilterPlugin.cs
@@ -0,0 +1,37 @@

using System;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of films.
/// </summary>
public class FilterPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate IFilter CreateFilterDelegate (ParameterSet paramSet);

/// <summary>
///
/// </summary>
public CreateFilterDelegate CreateFilter;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public FilterPlugin (string name) : base("Filters", name)
{
MethodInfo methodInfo = GetMethod ("CreateFilter");
CreateFilter = Delegate.CreateDelegate (typeof(CreateFilterDelegate), methodInfo) as CreateFilterDelegate;
}
}
}
37 changes: 37 additions & 0 deletions Hyperion.Core/PluginSystem/LightPlugin.cs
@@ -0,0 +1,37 @@

using System;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of cameras.
/// </summary>
public class LightPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate ILight CreateLightDelegate (Transform lightToWorld, ParameterSet paramSet);

/// <summary>
///
/// </summary>
public CreateLightDelegate CreateLight;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public LightPlugin (string name) : base("Lights", name)
{
MethodInfo methodInfo = GetMethod ("CreateLight");
CreateLight = Delegate.CreateDelegate (typeof(CreateLightDelegate), methodInfo) as CreateLightDelegate;
}
}
}
37 changes: 37 additions & 0 deletions Hyperion.Core/PluginSystem/MaterialPlugin.cs
@@ -0,0 +1,37 @@

using System;
using System.Reflection;
using Hyperion.Core.Interfaces;
using Hyperion.Core.Tools;
using Hyperion.Core.Geometry;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// Plugin for all kinds of cameras.
/// </summary>
public class MaterialPlugin : Plugin
{
/// <summary>
///
/// </summary>
public delegate IMaterial CreateMaterialDelegate (Transform objectToWorld, TextureParameterSet parameters);

/// <summary>
///
/// </summary>
public CreateMaterialDelegate CreateMaterial;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public MaterialPlugin (string name) : base("Materials", name)
{
MethodInfo methodInfo = GetMethod ("CreateMaterial");
CreateMaterial = Delegate.CreateDelegate (typeof(CreateMaterialDelegate), methodInfo) as CreateMaterialDelegate;
}
}
}
96 changes: 96 additions & 0 deletions Hyperion.Core/PluginSystem/Plugin.cs
@@ -0,0 +1,96 @@

using System;
using System.IO;
using System.Reflection;

namespace Hyperion.Core.PluginSystem
{
/// <summary>
/// This is the basic Plugin class. So far, a plugin holds track
/// of it's name and a library handle. To use a plugin, the pluginclass
/// has to inherit from Plugin and provide a Creation Method. Afterwards it
/// can be used like this:
///
/// <code>
/// ICamera cam = PluginManager.CreateCamera ("PerspectiveCamera");
/// </code>
///
/// Therefore your class must contain this (again, the camera as an example):
///
/// <code>
/// public class CameraPlugin : Plugin
/// {
/// delegate ICamera CreateCameraDelegate ();
/// public CreateCameraDelegate CreateCamera;
/// }
/// </code>
/// </summary>
public class Plugin
{
/// <summary>
/// The plugin's name
/// </summary>
private string _name;

/// <summary>
/// The plugin's assembly
/// </summary>
private Assembly _assembly;

/// <summary>
/// Initialize the plugin and it's name
/// </summary>
/// <param name="name">
/// The plugin's name
/// </param>
public Plugin (string category, string name)
{
_name = name;

string currentDirectory = Directory.GetCurrentDirectory ();
string[] files = Directory.GetFiles (currentDirectory);
string assemblyPath = string.Empty;

foreach (string file in files)
{
if (file.Contains (category + "." + name + ".dll"))
{
assemblyPath = file;
break;
}
}

_assembly = Assembly.LoadFile (assemblyPath);
}

/// <summary>
/// Retrieves a pointer to a method in the plugin's assembly
/// </summary>
/// <param name="methodName">
/// The method's name
/// </param>
/// <returns>
/// The method info
/// </returns>
public MethodInfo GetMethod (string methodName)
{
Type[] types = null;
try
{
types = _assembly.GetTypes ();
}
catch (ReflectionTypeLoadException e)
{
types = e.Types;
}

foreach (Type type in types)
{
if (type.Name == _name)
return type.GetMethod (methodName);
}

return null;
}
}
}

0 comments on commit 9b819e0

Please sign in to comment.