- extended TargetPlatform enumeration for all supported platforms
- extended ContentWriter - extended XNB Inspector to show new TargetPlatforms
This commit is contained in:
parent
9f61e9ae70
commit
93a848e883
@ -71,10 +71,9 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
{
|
{
|
||||||
compressContent = this.ShouldCompressContent(targetPlatform, value);
|
compressContent = this.ShouldCompressContent(targetPlatform, value);
|
||||||
}
|
}
|
||||||
using (ContentWriter contentWriter = new ContentWriter(this, output, targetPlatform, targetProfile, compressContent, rootDirectory, referenceRelocationPath))
|
using (ContentWriter contentWriter = new ContentWriter(this, output, compressContent, rootDirectory, referenceRelocationPath) { TargetPlatform = targetPlatform, TargetProfile = targetProfile })
|
||||||
{
|
{
|
||||||
contentWriter.WriteObject<object>(value);
|
contentWriter.WriteObject<object>(value);
|
||||||
contentWriter.FlushOutput();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
{
|
{
|
||||||
private bool canDeserializeIntoExistingObject;
|
private bool canDeserializeIntoExistingObject;
|
||||||
private Type targetType;
|
private Type targetType;
|
||||||
|
internal readonly bool TargetIsValueType;
|
||||||
|
|
||||||
protected ContentTypeWriter(Type targetType)
|
protected ContentTypeWriter(Type targetType)
|
||||||
{
|
{
|
||||||
@ -140,7 +141,7 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,33 +16,35 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
{
|
{
|
||||||
public sealed class ContentWriter : BinaryWriter
|
public sealed class ContentWriter : BinaryWriter
|
||||||
{
|
{
|
||||||
private TargetPlatform targetPlatform;
|
#region Private Members
|
||||||
private GraphicsProfile targetProfile;
|
|
||||||
private ContentCompiler compiler;
|
private ContentCompiler compiler;
|
||||||
private MemoryStream headerData;
|
|
||||||
private MemoryStream contentData;
|
|
||||||
private Stream finalOutput;
|
|
||||||
private Boolean compressContent;
|
private Boolean compressContent;
|
||||||
private string rootDirectory;
|
private string rootDirectory;
|
||||||
private string referenceRelocationPath;
|
private string referenceRelocationPath;
|
||||||
|
private Dictionary<Type, int> typeTable = new Dictionary<Type, int>();
|
||||||
|
private List<ContentTypeWriter> typeWriters = new List<ContentTypeWriter>();
|
||||||
|
|
||||||
|
private Stream outputStream;
|
||||||
|
private MemoryStream header = new MemoryStream();
|
||||||
|
private MemoryStream content = new MemoryStream();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
const byte xnbFormatVersion = (byte)5;
|
const byte xnbFormatVersion = (byte)5;
|
||||||
char[] xnbMagicWord = new char[] { 'X', 'N', 'B' };
|
char[] xnbMagicWord = new char[] { 'X', 'N', 'B' };
|
||||||
|
|
||||||
internal ContentWriter(ContentCompiler compiler, Stream output, TargetPlatform targetPlatform, GraphicsProfile targetProfile, bool compressContent, string rootDirectory, string referenceRelocationPath)
|
internal ContentWriter(ContentCompiler compiler, Stream output, bool compressContent, string rootDirectory, string referenceRelocationPath)
|
||||||
{
|
{
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
this.targetPlatform = targetPlatform;
|
|
||||||
this.targetProfile = targetProfile;
|
|
||||||
this.compressContent = compressContent;
|
this.compressContent = compressContent;
|
||||||
this.rootDirectory = rootDirectory;
|
this.rootDirectory = rootDirectory;
|
||||||
this.referenceRelocationPath = referenceRelocationPath;
|
this.referenceRelocationPath = referenceRelocationPath;
|
||||||
this.finalOutput = output;
|
|
||||||
this.headerData = new MemoryStream();
|
this.outputStream = output;
|
||||||
this.contentData = new MemoryStream();
|
this.OutStream = content;
|
||||||
this.OutStream = this.contentData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Write value types
|
||||||
public void Write(Color value)
|
public void Write(Color value)
|
||||||
{
|
{
|
||||||
base.Write(value.PackedValue);
|
base.Write(value.PackedValue);
|
||||||
@ -97,9 +99,17 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
base.Write(value.W);
|
base.Write(value.W);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void WriteExternalReference<T>(ExternalReference<T> reference)
|
public void WriteExternalReference<T>(ExternalReference<T> reference)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (reference == null || String.IsNullOrEmpty(reference.Filename))
|
||||||
|
{
|
||||||
|
Write(String.Empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Write(Path.GetFileNameWithoutExtension(reference.Filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteObject<T>(T value)
|
public void WriteObject<T>(T value)
|
||||||
@ -110,19 +120,107 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentTypeWriter typeWriter = this.compiler.GetTypeWriter(value.GetType());
|
int typeIndex;
|
||||||
|
ContentTypeWriter typeWriter = this.GetTypeWriter(value.GetType(), out typeIndex);
|
||||||
|
base.Write7BitEncodedInt(typeIndex + 1);
|
||||||
|
|
||||||
base.Write7BitEncodedInt(1);
|
//TODO: test for recursive cyclic calls
|
||||||
//if (this.recurseDetector.ContainsKey(value))
|
|
||||||
//{
|
|
||||||
// throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.FoundCyclicReference, new object[]
|
|
||||||
// {
|
|
||||||
// value
|
|
||||||
// }));
|
|
||||||
//}
|
|
||||||
//this.recurseDetector.Add(value, true);
|
|
||||||
this.InvokeWriter<T>(value, typeWriter);
|
this.InvokeWriter<T>(value, typeWriter);
|
||||||
//this.recurseDetector.Remove(value);
|
}
|
||||||
|
|
||||||
|
public void WriteObject<T>(T value, ContentTypeWriter typeWriter)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
base.Write7BitEncodedInt(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeWriter.TargetIsValueType)
|
||||||
|
{
|
||||||
|
this.InvokeWriter<T>(value, typeWriter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.WriteObject<T>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteRawObject<T>(T value)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
int typeIndex;
|
||||||
|
ContentTypeWriter typeWriter = this.GetTypeWriter(typeof(T), out typeIndex);
|
||||||
|
this.InvokeWriter<T>(value, typeWriter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteRawObject<T>(T value, ContentTypeWriter typeWriter)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("value");
|
||||||
|
}
|
||||||
|
if (typeWriter == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("typeWriter");
|
||||||
|
}
|
||||||
|
this.InvokeWriter<T>(value, typeWriter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteSharedResource<T>(T value)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TargetPlatform TargetPlatform
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraphicsProfile TargetProfile
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
WriteData();
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteData()
|
||||||
|
{
|
||||||
|
OutStream = header;
|
||||||
|
Write7BitEncodedInt(this.typeWriters.Count);
|
||||||
|
foreach (ContentTypeWriter current in this.typeWriters)
|
||||||
|
{
|
||||||
|
Write(current.GetRuntimeReader(TargetPlatform));
|
||||||
|
Write(current.TypeVersion);
|
||||||
|
}
|
||||||
|
Write7BitEncodedInt((int)0); // number of shared resources
|
||||||
|
//TODO: write shared resources
|
||||||
|
|
||||||
|
|
||||||
|
OutStream = outputStream;
|
||||||
|
|
||||||
|
Write(xnbMagicWord); // magic bytes for file recognition - 03 bytes
|
||||||
|
Write((byte)TargetPlatform); // target platform of content file - 01 byte
|
||||||
|
Write((byte)xnbFormatVersion); // version of this file - 01 byte
|
||||||
|
Write((byte)(TargetProfile == GraphicsProfile.HiDef ? 0x01 : 0x00)); // flags - 01 byte
|
||||||
|
Write((int)header.Length + (int)content.Length + 10); // size of file - 04 byte
|
||||||
|
if (compressContent)
|
||||||
|
{
|
||||||
|
//TODO: write compressed size
|
||||||
|
}
|
||||||
|
|
||||||
|
OutStream.Write(header.GetBuffer(), 0, (int)header.Length);
|
||||||
|
OutStream.Write(content.GetBuffer(), 0, (int)content.Length); //TODO: write compressed stream if compressedContent is true
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InvokeWriter<T>(T value, ContentTypeWriter writer)
|
private void InvokeWriter<T>(T value, ContentTypeWriter writer)
|
||||||
@ -136,94 +234,30 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
writer.Write(this, value);
|
writer.Write(this, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteObject<T>(T value, ContentTypeWriter typeWriter)
|
private ContentTypeWriter GetTypeWriter(Type type, out int typeIndex)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (this.typeTable.TryGetValue(type, out typeIndex))
|
||||||
}
|
{
|
||||||
|
return this.typeWriters[typeIndex];
|
||||||
|
}
|
||||||
|
|
||||||
public void WriteRawObject<T>(T value)
|
IEnumerable<Type> enumerable = null;
|
||||||
{
|
ContentTypeWriter typeWriter = this.compiler.GetTypeWriter(type); //TODO:, out enumerable);
|
||||||
throw new NotImplementedException();
|
typeIndex = this.typeWriters.Count;
|
||||||
}
|
this.typeWriters.Add(typeWriter);
|
||||||
|
this.typeTable.Add(type, typeIndex);
|
||||||
|
|
||||||
public void WriteRawObject<T>(T value, ContentTypeWriter typeWriter)
|
//TODO: what is this for?
|
||||||
{
|
//foreach (Type current in enumerable)
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteSharedResource<T>(T value)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void FlushOutput()
|
|
||||||
{
|
|
||||||
//TODO: implement
|
|
||||||
|
|
||||||
//this.WriteSharedResources();
|
|
||||||
this.WriteHeader();
|
|
||||||
this.WriteFinalOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteHeader()
|
|
||||||
{
|
|
||||||
this.OutStream = this.headerData;
|
|
||||||
//TODO: implement
|
|
||||||
//base.Write7BitEncodedInt(this.typeWriters.Count);
|
|
||||||
//foreach (ContentTypeWriter current in this.typeWriters)
|
|
||||||
//{
|
//{
|
||||||
// this.Write(current.GetRuntimeReader(this.targetPlatform));
|
// if (!(current == typeof(object)))
|
||||||
// this.Write(current.TypeVersion);
|
// {
|
||||||
|
// int num;
|
||||||
|
// this.GetTypeWriter(current, out num);
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
//base.Write7BitEncodedInt(this.sharedResourceNames.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteFinalOutput()
|
return typeWriter;
|
||||||
{
|
|
||||||
this.OutStream = this.finalOutput;
|
|
||||||
this.Write(xnbMagicWord);
|
|
||||||
this.Write((byte)this.targetPlatform);
|
|
||||||
if (this.compressContent)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
//this.WriteCompressedOutput();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.WriteUncompressedOutput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteUncompressedOutput()
|
|
||||||
{
|
|
||||||
this.Write(xnbFormatVersion); // Version
|
|
||||||
|
|
||||||
byte flags = 0;
|
|
||||||
if (TargetProfile == GraphicsProfile.HiDef)
|
|
||||||
{
|
|
||||||
flags |= 0x01;
|
|
||||||
}
|
|
||||||
this.Write(flags);
|
|
||||||
|
|
||||||
this.Write(10 + this.headerData.Length + this.contentData.Length);
|
|
||||||
this.OutStream.Write(this.headerData.GetBuffer(), 0, (int)this.headerData.Length);
|
|
||||||
this.OutStream.Write(this.contentData.GetBuffer(), 0, (int)this.contentData.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetPlatform TargetPlatform
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return targetPlatform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GraphicsProfile TargetProfile
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return targetProfile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,28 +19,16 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
|
|
||||||
protected internal override void Write(ContentWriter output, object value)
|
protected internal override void Write(ContentWriter output, object value)
|
||||||
{
|
{
|
||||||
this.Write(output, ContentTypeWriter<T>.CastType(value));
|
if (value is T)
|
||||||
|
{
|
||||||
|
this.Write(output, (T)value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new FormatException("The type of the value-object does not match the generic T-parameter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal abstract void Write(ContentWriter output, T value);
|
protected internal abstract void Write(ContentWriter output, T value);
|
||||||
|
|
||||||
private static T CastType(object value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("value");
|
|
||||||
}
|
|
||||||
if (!(value is T))
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debugger.Break();
|
|
||||||
//throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.WrongArgumentType, new object[]
|
|
||||||
//{
|
|
||||||
// typeof(T),
|
|
||||||
// value.GetType()
|
|
||||||
//}));
|
|
||||||
}
|
|
||||||
return (T)((object)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,11 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
|||||||
|
|
||||||
protected internal override void Write(ContentWriter output, CompiledEffectContent value)
|
protected internal override void Write(ContentWriter output, CompiledEffectContent value)
|
||||||
{
|
{
|
||||||
//TODO: implement
|
if (output.TargetPlatform != TargetPlatform.Windows)
|
||||||
//if (output.TargetPlatform == TargetPlatform.WindowsPhone)
|
{
|
||||||
//{
|
throw new InvalidOperationException("currently only HLSL windows effects are supported by EffectWriter");
|
||||||
// throw new InvalidContentException(Resources.MobileNoEffects);
|
}
|
||||||
//}
|
|
||||||
byte[] effectCode = value.GetEffectCode();
|
byte[] effectCode = value.GetEffectCode();
|
||||||
output.Write(effectCode.Length);
|
output.Write(effectCode.Length);
|
||||||
output.Write(effectCode);
|
output.Write(effectCode);
|
||||||
|
@ -11,8 +11,17 @@ namespace ANX.Framework.Content.Pipeline
|
|||||||
{
|
{
|
||||||
public enum TargetPlatform : byte
|
public enum TargetPlatform : byte
|
||||||
{
|
{
|
||||||
Windows = (byte)119,
|
Windows = (byte)'w',
|
||||||
WindowsPhone = (byte)109,
|
WindowsPhone = (byte)'m',
|
||||||
XBox360 = (byte)120,
|
XBox360 = (byte)'x',
|
||||||
|
|
||||||
|
// ANX-Extensions
|
||||||
|
Android = (byte)'a',
|
||||||
|
IOS = (byte)'i',
|
||||||
|
Linux = (byte)'l',
|
||||||
|
MacOs = (byte)'o',
|
||||||
|
PsVita = (byte)'p',
|
||||||
|
WindowsMetro = (byte)'8',
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,13 @@ namespace ANX.Tools.XNBInspector
|
|||||||
// w = Microsoft Windows
|
// w = Microsoft Windows
|
||||||
// m = Windows Phone 7
|
// m = Windows Phone 7
|
||||||
// x = Xbox 360
|
// x = Xbox 360
|
||||||
|
// ANX-EXTENSIONS:
|
||||||
|
// a = Android
|
||||||
|
// i = iOS
|
||||||
|
// l = Linux
|
||||||
|
// o = MacOs
|
||||||
|
// p = PS Vita / Mobile
|
||||||
|
// 8 = Windows 8 Metro
|
||||||
result.Append(Severity.None, "Target platform : ");
|
result.Append(Severity.None, "Target platform : ");
|
||||||
switch ((char)targetPlattform)
|
switch ((char)targetPlattform)
|
||||||
{
|
{
|
||||||
@ -90,8 +97,26 @@ namespace ANX.Tools.XNBInspector
|
|||||||
case 'x':
|
case 'x':
|
||||||
result.AppendFormat(Severity.Success, "{0}[x] (Xbox 360)", targetPlattform);
|
result.AppendFormat(Severity.Success, "{0}[x] (Xbox 360)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
|
case 'a':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[a] (Android) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[i] (iOS) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[l] (Linux) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[o] (MacOS) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[p] (PS Vita / mobile) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
result.AppendFormat(Severity.Success, "{0}[8] (Windows 8 metro) | ANX extension", targetPlattform);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
result.AppendFormat(Severity.Error, "{0} (Unknown or non XNA platform)", targetPlattform);
|
result.AppendFormat(Severity.Error, "{0} (Unknown or non XNA/ANX platform)", targetPlattform);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.3.0.0")]
|
[assembly: AssemblyVersion("0.3.1.0")]
|
||||||
[assembly: AssemblyFileVersion("0.3.0.0")]
|
[assembly: AssemblyFileVersion("0.3.1.0")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user