- extended ContentPipeline ProcessorManager with method to select a default processor for a importer or imported type

- extended ContentImporter to provide OutputType of imported content
- provided a list of available ContentProcessors in current context

PlatformSystems are no longer AddIns. This doesn't mean, that you can't load them dynamically. The handling is just different. There's only a single PlatformSystem available for each platform ANX runs on. This one is auto loaded. If it doesn't exist the game doesn't run. The reason for this is, that we will move the AddIn system from ANX.Framework to the specialized PlatformSystem. This is necessary because we want ANX.Framework to become platform independent. The AddIn system is different for some platforms (Android, iOS, Windows 8 Metro) and needs to be specialized. On the other hand we are able to simplify the AddIn system when moving it to the PlatformSystem because we don't need a big AddIn system supporting all platforms with much conditional compiling.

THIS COMMIT DOES BREAK SOME FUNCTIONALITY. METRO DOESN'T WORK ANYMORE, AS IT IS NOT TESTED. DON'T USE THIS COMMIT IF YOU ARE NO ANX.FRAMEWORK DEVELOPER. We will catch up soon with a tested and working version.
This commit is contained in:
Glatzemann 2012-09-18 05:53:08 +00:00 committed by Konstantin Koch
parent e51a8943aa
commit 933ef7cae6
28 changed files with 290 additions and 127 deletions

View File

@ -1,4 +1,9 @@
// This file is part of the ANX.Framework created by the
#region Using Statements
using System;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
@ -13,6 +18,14 @@ namespace ANX.Framework.Content.Pipeline
public abstract T Import(string filename, ContentImporterContext context);
public Type OutputType
{
get
{
return typeof(T);
}
}
object IContentImporter.Import(string filename, ContentImporterContext context)
{
return this.Import(filename, context);

View File

@ -12,5 +12,7 @@ namespace ANX.Framework.Content.Pipeline
public interface IContentImporter
{
Object Import(string filename, ContentImporterContext context);
Type OutputType { get; }
}
}

View File

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using ANX.Framework.Content.Pipeline.Audio;
using WaveUtils;
@ -24,5 +25,6 @@ namespace ANX.Framework.Content.Pipeline.Importer
FileType = AudioFileType.Wav,
};
}
}
}

View File

@ -15,7 +15,7 @@ namespace ANX.Framework.Content.Pipeline.Tasks
{
public class ProcessorManager
{
private Dictionary<String, IContentProcessor> processors = new Dictionary<string,IContentProcessor>();
private Dictionary<string, IContentProcessor> processors = new Dictionary<string, IContentProcessor>();
public ProcessorManager()
{
@ -45,7 +45,7 @@ namespace ANX.Framework.Content.Pipeline.Tasks
public String GetProcessorForType(Type type)
{
foreach (KeyValuePair<String, IContentProcessor> processorDescription in processors)
foreach (KeyValuePair<string, IContentProcessor> processorDescription in processors)
{
if (Type.Equals(processorDescription.Value.InputType, type))
{
@ -53,7 +53,23 @@ namespace ANX.Framework.Content.Pipeline.Tasks
}
}
return String.Empty;
return string.Empty;
}
public string GetProcessorForImporter(IContentImporter contentImporter)
{
return GetProcessorForType(contentImporter.OutputType);
}
public IEnumerable<KeyValuePair<string, IContentProcessor>> AvailableProcessors
{
get
{
foreach (KeyValuePair<string, IContentProcessor> kvp in processors)
{
yield return kvp;
}
}
}
}
}

View File

@ -439,6 +439,8 @@
<Compile Include="NonXNA\PlatformSystem\INativeGameTimer.cs" />
<Compile Include="NonXNA\PlatformSystem\INativeContentManager.cs" />
<Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" />
<Compile Include="NonXNA\PlatformSystem\PlatformSystem.cs" />
<Compile Include="NonXNA\PlatformSystem\PlatformSystemInstanceException.cs" />
<Compile Include="NonXNA\Reflection\AssemblyLoader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" />
<Compile Include="NonXNA\RenderSystem\IOcclusionQuery.cs" />
@ -449,7 +451,7 @@
<Compile Include="NonXNA\Windows8\IServiceProvider.cs" />
<Compile Include="NonXNA\NoInputDeviceException.cs" />
<Compile Include="NonXNA\OSInformation.cs" />
<Compile Include="NonXNA\PlatformSystem\IPlatformSystemCreator.cs" />
<Compile Include="NonXNA\PlatformSystem\IPlatformSystem.cs" />
<Compile Include="NonXNA\RenderSystem\EffectProcessorOutputFormat.cs" />
<Compile Include="NonXNA\ICreator.cs" />
<Compile Include="NonXNA\InputSystem\IGamePad.cs" />

View File

@ -5,6 +5,7 @@ using System.IO;
using ANX.Framework.Audio.XactParser;
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA.PlatformSystem;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -47,7 +48,7 @@ namespace ANX.Framework.Audio
// TODO: get renderer details
RendererDetails = new ReadOnlyCollection<RendererDetail>(new List<RendererDetail>());
Stream loadingStream = AddInSystemFactory.DefaultPlatformCreator.OpenReadFilestream(settingsFile);
Stream loadingStream = PlatformSystem.Instance.OpenReadFilestream(settingsFile);
generalSettings = new XactGeneralSettings(loadingStream);
loadingStream.Dispose();
}
@ -59,7 +60,7 @@ namespace ANX.Framework.Audio
// TODO: lookAheadTime and rendererId
Stream loadingStream = AddInSystemFactory.DefaultPlatformCreator.OpenReadFilestream(settingsFile);
Stream loadingStream = PlatformSystem.Instance.OpenReadFilestream(settingsFile);
generalSettings = new XactGeneralSettings(loadingStream);
loadingStream.Dispose();
}

View File

@ -66,8 +66,7 @@ namespace ANX.Framework.Content
#region Constructor
private ContentManager()
{
nativeImplementation =
AddInSystemFactory.DefaultPlatformCreator.CreateContentManager();
nativeImplementation = PlatformSystem.Instance.CreateContentManager();
loadedAssets =
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

View File

@ -76,7 +76,6 @@ namespace ANX.Framework
AddSystemCreator<IInputSystemCreator>();
AddSystemCreator<ISoundSystemCreator>();
AddSystemCreator<IPlatformSystemCreator>();
AddSystemCreator<IRenderSystemCreator>();
CreateGameHost();
@ -114,11 +113,7 @@ namespace ANX.Framework
private void CreateGameHost()
{
Logger.Info("creating GameHost");
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IPlatformSystemCreator>();
if (creator == null)
Logger.ErrorAndThrow<NullReferenceException>("Could not fetch PlatformSystem creator to create a game host.");
host = creator.CreateGameHost(this);
host = PlatformSystem.Instance.CreateGameHost(this);
host.Activated += HostActivated;
host.Deactivated += HostDeactivated;

View File

@ -20,7 +20,7 @@ namespace ANX.Framework
public GameTimer()
{
nativeImplementation = AddInSystemFactory.DefaultPlatformCreator.CreateGameTimer();
nativeImplementation = PlatformSystem.Instance.CreateGameTimer();
nativeImplementation.Reset();
lastUpdate = nativeImplementation.ElapsedTime;

View File

@ -94,13 +94,13 @@ namespace ANX.Framework.Media
#region Constructor
public MediaLibrary()
{
nativeLibrary = AddInSystemFactory.DefaultPlatformCreator.CreateMediaPlayer();
nativeLibrary = PlatformSystem.Instance.CreateMediaPlayer();
MediaSource = MediaSource.GetAvailableMediaSources()[0];
}
public MediaLibrary(MediaSource setSource)
{
nativeLibrary = AddInSystemFactory.DefaultPlatformCreator.CreateMediaPlayer();
nativeLibrary = PlatformSystem.Instance.CreateMediaPlayer();
MediaSource = setSource;
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.PlatformSystem;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -35,7 +36,7 @@ namespace ANX.Framework.Media
#region Constructor
public static IList<MediaSource> GetAvailableMediaSources()
{
return AddInSystemFactory.DefaultPlatformCreator.GetAvailableMediaSources();
return PlatformSystem.Instance.GetAvailableMediaSources();
}
#endregion

View File

@ -18,7 +18,6 @@ namespace ANX.Framework.NonXNA
typeof(IInputSystemCreator),
typeof(IRenderSystemCreator),
typeof(ISoundSystemCreator),
typeof(IPlatformSystemCreator),
};
#endregion
@ -44,13 +43,6 @@ namespace ANX.Framework.NonXNA
}
}
internal static IPlatformSystemCreator DefaultPlatformCreator
{
get
{
return Instance.GetDefaultCreator<IPlatformSystemCreator>();
}
}
#endregion
#region Constructor

View File

@ -10,6 +10,5 @@ namespace ANX.Framework.NonXNA
RenderSystem,
InputSystem,
SoundSystem,
PlatformSystem,
}
}

View File

@ -6,6 +6,7 @@ using System;
namespace ANX.Framework.NonXNA
{
//TODO: remove conditional compilation
public static class OSInformation
{
#region IsWindows

View File

@ -9,7 +9,7 @@ using ANX.Framework.Storage;
namespace ANX.Framework.NonXNA.PlatformSystem
{
public interface IPlatformSystemCreator : ICreator
public interface IPlatformSystem
{
GameHost CreateGameHost(Game game);
INativeStorageDevice CreateStorageDevice(StorageDevice device, PlayerIndex player, int sizeInBytes, int directoryCount);

View File

@ -0,0 +1,181 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Media;
using System.IO;
using ANX.Framework.Storage;
using System.Reflection;
using ANX.Framework.NonXNA.Reflection;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.NonXNA.PlatformSystem
{
internal class PlatformSystem : IPlatformSystem
{
private static PlatformSystem singletonInstance;
private static IPlatformSystem runtimeInstance;
private const string prefix = "ANX.PlatformSystem.";
private const string suffix = ".dll";
private PlatformSystem()
{
runtimeInstance = CreateRuntimeInstance(OSInformation.GetName());
}
private IPlatformSystem CreateRuntimeInstance(PlatformName platform)
{
string platformAssemblyName = string.Empty;
try
{
platformAssemblyName = GetPlatformAssemblyName(platform);
}
catch (PlatformSystemInstanceException ex)
{
Logger.Error(ex.Message);
return null;
}
Assembly assembly = Assembly.LoadFrom(platformAssemblyName);
foreach (Type type in assembly.GetExportedTypes())
{
if (TypeHelper.IsTypeAssignableFrom(typeof(IPlatformSystem), type))
{
return TypeHelper.Create<IPlatformSystem>(type);
}
}
return null;
}
private string GetPlatformAssemblyName(PlatformName platform)
{
switch (platform)
{
case PlatformName.Windows7:
case PlatformName.WindowsVista:
case PlatformName.WindowsXP:
return prefix + "Windows" + suffix;
case PlatformName.Linux:
case PlatformName.PSVita:
return prefix + platform.ToString() + suffix;
case PlatformName.Windows8:
return prefix + "Metro" + suffix;
default:
throw new PlatformSystemInstanceException("couldn't solve assembly name for platform '" + platform.ToString() + "'");
}
}
public static PlatformSystem Instance
{
get
{
if (singletonInstance == null)
{
singletonInstance = new PlatformSystem();
}
return singletonInstance;
}
}
public GameHost CreateGameHost(Game game)
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateGameHost(game);
}
public INativeStorageDevice CreateStorageDevice(StorageDevice device, PlayerIndex player, int sizeInBytes, int directoryCount)
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateStorageDevice(device, player, sizeInBytes, directoryCount);
}
public INativeStorageContainer CreateStorageContainer(StorageContainer container)
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateStorageContainer(container);
}
public INativeTitleContainer CreateTitleContainer()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateTitleContainer();
}
public INativeGameTimer CreateGameTimer()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateGameTimer();
}
public INativeContentManager CreateContentManager()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateContentManager();
}
public Stream OpenReadFilestream(string filepath)
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.OpenReadFilestream(filepath);
}
public INativeMediaLibrary CreateMediaPlayer()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateMediaPlayer();
}
public IList<MediaSource> GetAvailableMediaSources()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.GetAvailableMediaSources();
}
}
}

View File

@ -0,0 +1,24 @@
#region Using Statements
using System;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.NonXNA.PlatformSystem
{
public class PlatformSystemInstanceException : Exception
{
public PlatformSystemInstanceException()
: base()
{
}
public PlatformSystemInstanceException(string message)
: base(message)
{
}
}
}

View File

@ -41,8 +41,7 @@ namespace ANX.Framework.Storage
StorageDevice = device;
DisplayName = displayName;
nativeImplementation =
AddInSystemFactory.DefaultPlatformCreator.CreateStorageContainer(this);
nativeImplementation = PlatformSystem.Instance.CreateStorageContainer(this);
}
~StorageContainer()

View File

@ -63,9 +63,7 @@ namespace ANX.Framework.Storage
#region Constructor
internal StorageDevice(PlayerIndex player, int sizeInBytes, int directoryCount)
{
nativeImplementation =
AddInSystemFactory.DefaultPlatformCreator.CreateStorageDevice(
this, player, sizeInBytes, directoryCount);
nativeImplementation = PlatformSystem.Instance.CreateStorageDevice(this, player, sizeInBytes, directoryCount);
}
#endregion

View File

@ -18,16 +18,35 @@ namespace ANX.Framework
static TitleContainer()
{
nativeImplementation = AddInSystemFactory.DefaultPlatformCreator.CreateTitleContainer();
try
{
nativeImplementation = PlatformSystem.Instance.CreateTitleContainer();
}
catch (PlatformSystemInstanceException ex)
{
//TODO: error handling
}
}
public static Stream OpenStream(string name)
{
if (nativeImplementation == null)
{
//TODO: error handling
return null;
}
return nativeImplementation.OpenStream(name);
}
internal static string GetCleanPath(string path)
{
if (nativeImplementation == null)
{
//TODO: error handling
return null;
}
return nativeImplementation.GetCleanPath(path);
}
}

View File

@ -41,7 +41,7 @@
<Compile Include="LinuxGameHost.cs" />
<Compile Include="LinuxGameTimer.cs" />
<Compile Include="LinuxGameWindow.cs" />
<Compile Include="LinuxPlatformCreator.cs" />
<Compile Include="LinuxPlatformSystem.cs" />
<Compile Include="LinuxStorageContainer.cs" />
<Compile Include="LinuxStorageDevice.cs" />
<Compile Include="LinuxTitleContainer.cs" />

View File

@ -13,35 +13,9 @@ using ANX.Framework.Storage;
namespace ANX.PlatformSystem.Linux
{
public class LinuxPlatformCreator : IPlatformSystemCreator
public class LinuxPlatformSystem : IPlatformSystem
{
#region Public
public string Name
{
get
{
return "Linux";
}
}
public int Priority
{
get
{
return 100;
}
}
public bool IsSupported
{
get
{
return OSInformation.GetName() == PlatformName.Linux;
}
}
#endregion
public LinuxPlatformCreator()
public LinuxPlatformSystem()
{
}
@ -49,7 +23,6 @@ namespace ANX.PlatformSystem.Linux
public GameHost CreateGameHost(Game game)
{
Logger.Info("creating Linux GameHost");
AddInSystemFactory.Instance.PreventSystemChange(AddInType.PlatformSystem);
return new LinuxGameHost(game);
}
#endregion

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.60.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.50.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -14,34 +14,8 @@ using ANX.Framework.Storage;
namespace ANX.PlatformSystem.PsVita
{
public class PsVitaPlatformCreator : IPlatformSystemCreator
public class PsVitaPlatformCreator : IPlatformSystem
{
#region Public
public string Name
{
get
{
return "Platform.PsVita";
}
}
public int Priority
{
get
{
return 100;
}
}
public bool IsSupported
{
get
{
return OSInformation.GetName() == PlatformName.PSVita;
}
}
#endregion
#region Constructor
public PsVitaPlatformCreator()
{
@ -52,7 +26,6 @@ namespace ANX.PlatformSystem.PsVita
public GameHost CreateGameHost(Game game)
{
Logger.Info("creating PsVita GameHost");
AddInSystemFactory.Instance.PreventSystemChange(AddInType.PlatformSystem);
return new PsVitaGameHost(game);
}
#endregion

View File

@ -45,7 +45,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsGameHost.cs" />
<Compile Include="WindowsGameWindow.cs" />
<Compile Include="WindowsPlatformCreator.cs" />
<Compile Include="WindowsPlatformSystem.cs" />
<Compile Include="WindowsStorageDevice.cs" />
<Compile Include="WindowsTitleContainer.cs" />
</ItemGroup>

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.75.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -13,35 +13,9 @@ using ANX.Framework.Storage;
namespace ANX.PlatformSystem.Windows
{
public class WindowsPlatformCreator : IPlatformSystemCreator
public class WindowsPlatformSystem : IPlatformSystem
{
#region Public
public string Name
{
get
{
return "Windows";
}
}
public int Priority
{
get
{
return 100;
}
}
public bool IsSupported
{
get
{
return OSInformation.IsWindows;
}
}
#endregion
public WindowsPlatformCreator()
public WindowsPlatformSystem()
{
}
@ -49,7 +23,6 @@ namespace ANX.PlatformSystem.Windows
public GameHost CreateGameHost(Game game)
{
Logger.Info("creating Windows GameHost");
AddInSystemFactory.Instance.PreventSystemChange(AddInType.PlatformSystem);
return new WindowsGameHost(game);
}
#endregion