some code cleanup and implemented a dummy ReflectiveWriter for the compilation step
This commit is contained in:
parent
32b43c2a82
commit
23029218b1
@ -12,6 +12,8 @@ using System.Text;
|
||||
|
||||
namespace ANX.Framework.Content.Pipeline
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
[Serializable]
|
||||
public class ContentProcessorAttribute : Attribute
|
||||
{
|
||||
public ContentProcessorAttribute()
|
||||
|
@ -1,4 +1,5 @@
|
||||
#region Using Statements
|
||||
using ANX.Framework.Graphics.PackedVector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,12 +18,6 @@ namespace ANX.Framework.Content.Pipeline.Graphics
|
||||
private int _blockSize;
|
||||
private byte[] _pixelData;
|
||||
|
||||
protected DxtBitmapContent(int blockSize)
|
||||
{
|
||||
//TODO: set _pixelData
|
||||
_blockSize = blockSize;
|
||||
}
|
||||
|
||||
protected DxtBitmapContent(int blockSize, int width, int height)
|
||||
: base(width, height)
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
|
||||
dependencies = new List<Type>();
|
||||
|
||||
ContentTypeWriter contentTypeWriter;
|
||||
ContentTypeWriter contentTypeWriter = null;
|
||||
if (!this.writerInstances.TryGetValue(type, out contentTypeWriter))
|
||||
{
|
||||
if (type.IsGenericType)
|
||||
@ -69,10 +69,6 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
contentTypeWriter = default(ContentTypeWriter);
|
||||
}
|
||||
|
||||
if (contentTypeWriter == null)
|
||||
{
|
||||
@ -85,13 +81,14 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
|
||||
contentTypeWriter = Activator.CreateInstance(typeof(ArrayWriter<>).MakeGenericType(new Type[] { type.GetElementType() })) as ContentTypeWriter;
|
||||
}
|
||||
|
||||
if (type.IsEnum)
|
||||
else if (type.IsEnum)
|
||||
{
|
||||
contentTypeWriter = Activator.CreateInstance(typeof(EnumWriter<>).MakeGenericType(new Type[] { type.GetElementType() })) as ContentTypeWriter;
|
||||
}
|
||||
|
||||
//TODO: return new ReflectiveWriter(type);
|
||||
else
|
||||
{
|
||||
contentTypeWriter = new ReflectiveWriter(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (contentTypeWriter != null)
|
||||
|
@ -23,6 +23,7 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
private string referenceRelocationPath;
|
||||
private Dictionary<Type, int> typeTable = new Dictionary<Type, int>();
|
||||
private List<ContentTypeWriter> typeWriters = new List<ContentTypeWriter>();
|
||||
private List<object> sharedResources = new List<object>();
|
||||
|
||||
private Stream outputStream;
|
||||
private MemoryStream header = new MemoryStream();
|
||||
@ -122,6 +123,9 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
|
||||
int typeIndex;
|
||||
ContentTypeWriter typeWriter = this.GetTypeWriter(value.GetType(), out typeIndex);
|
||||
if (typeWriter == null)
|
||||
throw new InvalidOperationException(string.Format("Can't find a type writer for {0}.", value.GetType()));
|
||||
|
||||
base.Write7BitEncodedInt(typeIndex + 1);
|
||||
|
||||
//TODO: test for recursive cyclic calls
|
||||
@ -172,7 +176,21 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
|
||||
public void WriteSharedResource<T>(T value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (value == null)
|
||||
{
|
||||
//Index 0 is reserved for null
|
||||
Write7BitEncodedInt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int sharedResourceIndex = sharedResources.IndexOf(value);
|
||||
if (sharedResourceIndex == -1)
|
||||
{
|
||||
sharedResourceIndex = sharedResources.Count;
|
||||
sharedResources.Add(value);
|
||||
}
|
||||
base.Write7BitEncodedInt(sharedResourceIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public TargetPlatform TargetPlatform
|
||||
@ -196,16 +214,27 @@ namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
|
||||
private void WriteData()
|
||||
{
|
||||
OutStream = content;
|
||||
|
||||
//We wrote the main object previously in the content stream.
|
||||
//We also have to execute the shared resources writer before we write the typeWriters list,
|
||||
//because we may add additional type writers here.
|
||||
foreach (var resource in sharedResources)
|
||||
{
|
||||
this.WriteObject(resource);
|
||||
}
|
||||
|
||||
OutStream = header;
|
||||
|
||||
//Write type writers
|
||||
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
|
||||
|
||||
Write7BitEncodedInt(sharedResources.Count);
|
||||
|
||||
OutStream = outputStream;
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ANX.Framework.Content.Pipeline.Serialization.Compiler
|
||||
{
|
||||
class ReflectiveWriter : ContentTypeWriter
|
||||
{
|
||||
public ReflectiveWriter(Type targetType) : base(targetType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string GetRuntimeReader(TargetPlatform targetPlatform)
|
||||
{
|
||||
return" ANX.Framework.Content.ReflectiveReader";
|
||||
}
|
||||
|
||||
protected internal override void Write(ContentWriter output, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user