added rudimentary ContentProcessor support to ContentBuilder tool
This commit is contained in:
parent
4234155c8c
commit
d64036a520
@ -35,6 +35,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AnxContentImporterContext.cs" />
|
||||
<Compile Include="AnxContentProcessorContext.cs" />
|
||||
<Compile Include="Audio\AudioContent.cs" />
|
||||
<Compile Include="Audio\AudioFileType.cs" />
|
||||
<Compile Include="Audio\AudioFormat.cs" />
|
||||
@ -170,6 +171,7 @@
|
||||
<Compile Include="Tasks\BuildItem.cs" />
|
||||
<Compile Include="Tasks\BuildRequest.cs" />
|
||||
<Compile Include="Tasks\ImporterManager.cs" />
|
||||
<Compile Include="Tasks\ProcessorManager.cs" />
|
||||
<Compile Include="VideoContent.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
116
ANX.Framework.Content.Pipeline/AnxContentProcessorContext.cs
Normal file
116
ANX.Framework.Content.Pipeline/AnxContentProcessorContext.cs
Normal file
@ -0,0 +1,116 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ANX.Framework.Graphics;
|
||||
|
||||
#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.Content.Pipeline
|
||||
{
|
||||
public class AnxContentProcessorContext : ContentProcessorContext
|
||||
{
|
||||
private string buildConfiguration;
|
||||
private string intermediateDirectory;
|
||||
private ContentBuildLogger contentBuildLogger;
|
||||
private string outputDirectory;
|
||||
private string outputFilename;
|
||||
private OpaqueDataDictionary parameters;
|
||||
private TargetPlatform targetPlatform;
|
||||
private GraphicsProfile targetProfile;
|
||||
|
||||
public override string BuildConfiguration
|
||||
{
|
||||
get
|
||||
{
|
||||
return buildConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
public override string IntermediateDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return intermediateDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
public override ContentBuildLogger Logger
|
||||
{
|
||||
get
|
||||
{
|
||||
return contentBuildLogger;
|
||||
}
|
||||
}
|
||||
|
||||
public override string OutputDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
public override string OutputFilename
|
||||
{
|
||||
get
|
||||
{
|
||||
return outputFilename;
|
||||
}
|
||||
}
|
||||
|
||||
public override OpaqueDataDictionary Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
public override TargetPlatform TargetPlatform
|
||||
{
|
||||
get
|
||||
{
|
||||
return targetPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
public override GraphicsProfile TargetProfile
|
||||
{
|
||||
get
|
||||
{
|
||||
return targetProfile;
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddDependency(string filename)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void AddOutputFile(string filename)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override TOutput BuildAndLoadAsset<TInput, TOutput>(ExternalReference<TInput> sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ExternalReference<TOutput> BuildAsset<TInput, TOutput>(ExternalReference<TInput> sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName, string assetName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override TOutput Convert<TInput, TOutput>(TInput input, string processorName, OpaqueDataDictionary processorParameters)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ namespace ANX.Framework.Content.Pipeline
|
||||
public OpaqueDataDictionary OpaqueData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,26 +14,27 @@ namespace ANX.Framework.Content.Pipeline
|
||||
{
|
||||
public abstract class ContentProcessor<TInput, TOutput> : IContentProcessor
|
||||
{
|
||||
protected ContentProcessor()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract TOutput Process(TInput input, ContentProcessorContext context);
|
||||
|
||||
Type IContentProcessor.InputType
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
get
|
||||
{
|
||||
return typeof(TInput);
|
||||
}
|
||||
}
|
||||
|
||||
Type IContentProcessor.OutputType
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
get
|
||||
{
|
||||
return typeof(TOutput);
|
||||
}
|
||||
}
|
||||
|
||||
object IContentProcessor.Process(object input, ContentProcessorContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Process((TInput)input, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ namespace ANX.Framework.Content.Pipeline
|
||||
{
|
||||
public ContentProcessorContext()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public abstract string BuildConfiguration { get; }
|
||||
|
@ -30,7 +30,14 @@ namespace ANX.Framework.Content.Pipeline.Processors
|
||||
|
||||
public override CompiledEffectContent Process(EffectContent input, ContentProcessorContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
byte[] effectCompiledCode = new byte[1]; //TODO: compile effect!!!
|
||||
|
||||
return new CompiledEffectContent(effectCompiledCode)
|
||||
{
|
||||
Identity = input.Identity,
|
||||
Name = input.Name,
|
||||
OpaqueData = input.OpaqueData
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace ANX.Framework.Content.Pipeline.Tasks
|
||||
public class BuildContent
|
||||
{
|
||||
private ImporterManager importerManager;
|
||||
private ProcessorManager processorManager;
|
||||
|
||||
public ImporterManager ImporterManager
|
||||
{
|
||||
@ -24,15 +25,36 @@ namespace ANX.Framework.Content.Pipeline.Tasks
|
||||
{
|
||||
this.importerManager = new ImporterManager();
|
||||
}
|
||||
|
||||
return this.importerManager;
|
||||
}
|
||||
}
|
||||
|
||||
public ProcessorManager ProcessorManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.processorManager == null)
|
||||
{
|
||||
this.processorManager = new ProcessorManager();
|
||||
}
|
||||
|
||||
return this.processorManager;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(IEnumerable<BuildItem> itemsToBuild)
|
||||
{
|
||||
foreach (BuildItem buildItem in itemsToBuild)
|
||||
{
|
||||
var importedObject = ImportAsset(buildItem);
|
||||
|
||||
if (String.IsNullOrEmpty(buildItem.BuildRequest.ProcessorName))
|
||||
{
|
||||
buildItem.BuildRequest.ProcessorName = ProcessorManager.GetProcessorForType(importedObject.GetType());
|
||||
}
|
||||
|
||||
var buildedItem = Process(buildItem, importedObject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,5 +69,19 @@ namespace ANX.Framework.Content.Pipeline.Tasks
|
||||
//});
|
||||
return instance.Import(item.BuildRequest.SourceFilename, context);
|
||||
}
|
||||
|
||||
private object Process(BuildItem item, object importedObject)
|
||||
{
|
||||
if (String.IsNullOrEmpty(item.BuildRequest.ProcessorName) == false)
|
||||
{
|
||||
IContentProcessor instance = this.ProcessorManager.GetInstance(item.BuildRequest.ProcessorName);
|
||||
ContentProcessorContext context = new AnxContentProcessorContext();
|
||||
return instance.Process(importedObject, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
return importedObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
59
ANX.Framework.Content.Pipeline/Tasks/ProcessorManager.cs
Normal file
59
ANX.Framework.Content.Pipeline/Tasks/ProcessorManager.cs
Normal file
@ -0,0 +1,59 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.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.Content.Pipeline.Tasks
|
||||
{
|
||||
public class ProcessorManager
|
||||
{
|
||||
private Dictionary<String, IContentProcessor> processors = new Dictionary<string,IContentProcessor>();
|
||||
|
||||
public ProcessorManager()
|
||||
{
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
ContentProcessorAttribute[] value = (ContentProcessorAttribute[]) type.GetCustomAttributes(typeof(ContentProcessorAttribute), true);
|
||||
if (value.Length > 0 && !processors.ContainsKey(type.Name))
|
||||
{
|
||||
processors[type.Name] = (IContentProcessor)Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IContentProcessor GetInstance(string processorName)
|
||||
{
|
||||
IContentProcessor processor;
|
||||
if (!this.processors.TryGetValue(processorName, out processor))
|
||||
{
|
||||
throw new Exception(String.Format("can't find processor {0}", processorName));
|
||||
}
|
||||
|
||||
return processor;
|
||||
}
|
||||
|
||||
public String GetProcessorForType(Type type)
|
||||
{
|
||||
foreach (KeyValuePair<String, IContentProcessor> processorDescription in processors)
|
||||
{
|
||||
if (Type.Equals(processorDescription.Value.InputType, type))
|
||||
{
|
||||
return processorDescription.Key;
|
||||
}
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ namespace ContentBuilder
|
||||
BuildItem buildItem = new BuildItem();
|
||||
buildItem.BuildRequest = new BuildRequest();
|
||||
buildItem.BuildRequest.ImporterName = ImporterManager.GuessImporterByFileExtension(arg);
|
||||
//TODO: set configured processor name
|
||||
buildItem.BuildRequest.SourceFilename = arg;
|
||||
buildItem.BuildRequest.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user