- fixed reading compressed content
- added tests for compressed content reading
This commit is contained in:
parent
85f23ea06d
commit
d2943674f6
@ -105,6 +105,15 @@ namespace ANX.Framework.TestCenter.ContentPipeline.Helper
|
|||||||
false, contentRootDirectory, referenceLocationPath);
|
false, contentRootDirectory, referenceLocationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WriteAsset(Stream output, object value, bool compress)
|
||||||
|
{
|
||||||
|
WriteAsset(output,
|
||||||
|
value,
|
||||||
|
Microsoft.Xna.Framework.Content.Pipeline.TargetPlatform.Windows,
|
||||||
|
Microsoft.Xna.Framework.Graphics.GraphicsProfile.HiDef,
|
||||||
|
compress, contentRootDirectory, referenceLocationPath);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddTypeWriter(ContentTypeWriter writer)
|
public void AddTypeWriter(ContentTypeWriter writer)
|
||||||
{
|
{
|
||||||
MethodInfo addTypeWriter = GetPrivateMethod("AddTypeWriter");
|
MethodInfo addTypeWriter = GetPrivateMethod("AddTypeWriter");
|
||||||
|
@ -74,17 +74,45 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestCompiler()
|
public void TestCompileWithoutCompression()
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
Compiler.WriteAsset(stream,
|
Compiler.WriteAsset(stream, ANX.Framework.Color.CornflowerBlue);
|
||||||
ANX.Framework.Color.CornflowerBlue);
|
|
||||||
|
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
Assert.AreEqual(stream.ReadByte(), 'X');
|
byte[] buffer = new byte[6];
|
||||||
Assert.AreEqual(stream.ReadByte(), 'N');
|
stream.Read(buffer, 0, 6);
|
||||||
Assert.AreEqual(stream.ReadByte(), 'B');
|
|
||||||
|
Assert.AreEqual(buffer[0], 'X');
|
||||||
|
Assert.AreEqual(buffer[1], 'N');
|
||||||
|
Assert.AreEqual(buffer[2], 'B');
|
||||||
|
Assert.AreEqual(buffer[3], 'w');
|
||||||
|
|
||||||
|
bool compressed = (buffer[5] >> 4) > 0;
|
||||||
|
Assert.AreEqual(compressed, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCompileWithCompression()
|
||||||
|
{
|
||||||
|
using (var stream = new MemoryStream())
|
||||||
|
{
|
||||||
|
//System.Diagnostics.Debugger.Launch();
|
||||||
|
Compiler.WriteAsset(stream, ANX.Framework.Color.CornflowerBlue, true);
|
||||||
|
|
||||||
|
stream.Position = 0;
|
||||||
|
byte[] buffer = new byte[6];
|
||||||
|
stream.Read(buffer, 0, 6);
|
||||||
|
|
||||||
|
Assert.AreEqual(buffer[0], 'X');
|
||||||
|
Assert.AreEqual(buffer[1], 'N');
|
||||||
|
Assert.AreEqual(buffer[2], 'B');
|
||||||
|
Assert.AreEqual(buffer[3], 'w');
|
||||||
|
|
||||||
|
bool compressed = (buffer[5] >> 4) > 0;
|
||||||
|
Assert.AreEqual(compressed, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +122,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Assert.Fail("not implemented");
|
Assert.Fail("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestBoundingBoxSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestBoundingBoxSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -110,7 +139,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Max = new AnxFrame.Vector3(4, 5, 6)
|
Max = new AnxFrame.Vector3(4, 5, 6)
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingBox>(null, stream, "Box");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingBox>(null, stream, "Box");
|
||||||
|
|
||||||
@ -118,8 +147,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestBoundingFrustumSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestBoundingFrustumSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -167,7 +197,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
M44 = 44,
|
M44 = 44,
|
||||||
});
|
});
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingFrustum>(null, stream, "Frustum");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingFrustum>(null, stream, "Frustum");
|
||||||
|
|
||||||
@ -175,8 +205,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestBoundingSphereSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestBoundingSphereSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -191,7 +222,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Radius = 4
|
Radius = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingSphere>(null, stream, "Sphere");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.BoundingSphere>(null, stream, "Sphere");
|
||||||
|
|
||||||
@ -199,13 +230,14 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestColorSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestColorSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using(var stream = new MemoryStream())
|
using(var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
var input = Microsoft.Xna.Framework.Color.CornflowerBlue;
|
var input = Microsoft.Xna.Framework.Color.CornflowerBlue;
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
|
|
||||||
//System.Diagnostics.Debugger.Launch();
|
//System.Diagnostics.Debugger.Launch();
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
@ -219,8 +251,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestMatrixSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestMatrixSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -269,7 +302,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
M44 = 44,
|
M44 = 44,
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Matrix>(null, stream, "Matrix");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Matrix>(null, stream, "Matrix");
|
||||||
|
|
||||||
@ -277,8 +310,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestPlaneSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestPlaneSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -293,7 +327,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
D = 4
|
D = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Plane>(null, stream, "Plane");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Plane>(null, stream, "Plane");
|
||||||
|
|
||||||
@ -301,8 +335,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestPointSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestPointSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -317,7 +352,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Y = 2
|
Y = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Point>(null, stream, "Point");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Point>(null, stream, "Point");
|
||||||
|
|
||||||
@ -325,8 +360,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestQuaternionSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestQuaternionSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -345,7 +381,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
W = 4
|
W = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Quaternion>(null, stream, "Quaternion");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Quaternion>(null, stream, "Quaternion");
|
||||||
|
|
||||||
@ -353,8 +389,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestRaySerialization()
|
[TestCase(true)]
|
||||||
|
public void TestRaySerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -369,7 +406,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Direction = new AnxFrame.Vector3(4, 5, 6),
|
Direction = new AnxFrame.Vector3(4, 5, 6),
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Ray>(null, stream, "Ray");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Ray>(null, stream, "Ray");
|
||||||
|
|
||||||
@ -377,8 +414,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestRectangleSerialization()
|
[TestCase(true)]
|
||||||
|
public void TestRectangleSerialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -397,7 +435,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Height = 4
|
Height = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Rectangle>(null, stream, "Rectangle");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Rectangle>(null, stream, "Rectangle");
|
||||||
|
|
||||||
@ -405,8 +443,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestVector2Serialization()
|
[TestCase(true)]
|
||||||
|
public void TestVector2Serialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -421,7 +460,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Y = 2
|
Y = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector2>(null, stream, "Vector2");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector2>(null, stream, "Vector2");
|
||||||
|
|
||||||
@ -429,8 +468,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestVector3Serialization()
|
[TestCase(true)]
|
||||||
|
public void TestVector3Serialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -447,7 +487,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
Z = 3
|
Z = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector3>(null, stream, "Vector3");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector3>(null, stream, "Vector3");
|
||||||
|
|
||||||
@ -455,8 +495,9 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[TestCase(false)]
|
||||||
public void TestVector4Serialization()
|
[TestCase(true)]
|
||||||
|
public void TestVector4Serialization(bool compress)
|
||||||
{
|
{
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -475,7 +516,7 @@ namespace ANX.Framework.TestCenter.ContentPipeline
|
|||||||
W = 4
|
W = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.WriteAsset(stream, input);
|
Compiler.WriteAsset(stream, input, compress);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector4>(null, stream, "Vector4");
|
var actual = AnxFrame.Content.ContentReader.ReadAsset<AnxFrame.Vector4>(null, stream, "Vector4");
|
||||||
|
|
||||||
|
@ -174,13 +174,12 @@ namespace ANX.Framework.Content
|
|||||||
|
|
||||||
bool isCompressed = (flags & 0x80) != 0;
|
bool isCompressed = (flags & 0x80) != 0;
|
||||||
|
|
||||||
uint sizeOnDisk = reader.ReadUInt32();
|
int sizeOnDisk = reader.ReadInt32();
|
||||||
// TODO: check stream length
|
// TODO: check stream length
|
||||||
|
|
||||||
if (isCompressed)
|
if (isCompressed)
|
||||||
{
|
{
|
||||||
int decompressedSize = reader.ReadInt32();
|
return Decompressor.DecompressStream(reader, input, sizeOnDisk);
|
||||||
return Decompressor.DecompressStream(reader, input, decompressedSize);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<NoStdLib>true</NoStdLib>
|
<NoStdLib>true</NoStdLib>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<XnaCompressContent>false</XnaCompressContent>
|
<XnaCompressContent>False</XnaCompressContent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user