Skip to content

Commit

Permalink
Enabled NCrunch for Myre.Testing and Added a tes project to Myre.Testing
Browse files Browse the repository at this point in the history
Added depth sorting for model instances and render batches

Signed-off-by: Martin Evans <martindevans@gmail.com>
  • Loading branch information
martindevans committed Dec 28, 2012
1 parent ad25fc8 commit 2bb47f0
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 5 deletions.
20 changes: 20 additions & 0 deletions Myre/Myre.Debugging.UI/(360) Myre.Debugging.UI.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
20 changes: 20 additions & 0 deletions Myre/Myre.Debugging/(360) Myre.Debugging.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
20 changes: 20 additions & 0 deletions Myre/Myre.Entities/(360) Myre.Entities.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
55 changes: 53 additions & 2 deletions Myre/Myre.Graphics/Geometry/ModelInstance.cs
Expand Up @@ -66,6 +66,8 @@ class MeshInstance

public BoundingSphere Bounds { get; private set; }

public Matrix WorldView;

public void UpdateBounds()
{
Bounds = Mesh.BoundingSphere.Transform(Instance.Transform);
Expand Down Expand Up @@ -165,6 +167,11 @@ public void Draw(string phase, BoxedValueStore<string> metadata)
foreach (var item in buffer)
item.IsVisible = true & !item.Instance.IsInvisible;

var view = metadata.Get<Matrix>("view");
CalculateWorldViews(meshes, ref view.Value); //Calculate WorldView for all mesh instances

DepthSortMeshes(meshes); //Sort batches by first item in batch

foreach (var mesh in meshes)
{
foreach (var instance in mesh.Instances)
Expand All @@ -185,6 +192,32 @@ public void Draw(string phase, BoxedValueStore<string> metadata)
buffer.Clear();
}

private void DepthSortMeshes(List<MeshRenderData> meshes)
{
meshes.Sort(RenderDataComparator);
}

private int RenderDataComparator(MeshRenderData a, MeshRenderData b)
{
if (a.Instances.Count > 0 && b.Instances.Count > 0)
return CompareWorldViews(ref a.Instances[0].WorldView, ref b.Instances[0].WorldView);
return a.Instances.Count.CompareTo(b.Instances.Count);
}

private void CalculateWorldViews(List<MeshRenderData> batches, ref Matrix view)
{
for (int b = 0; b < batches.Count; b++)
{
var instances = batches[b].Instances;
for (int i = 0; i < instances.Count; i++)
{
var instance = instances[i];
Matrix world = instance.Instance.Transform;
Matrix.Multiply(ref world, ref view, out instance.WorldView);
}
}
}

private void QueryVisible(BoundingVolume volume, List<MeshInstance> instances)
{
cullableBuffer.Clear();
Expand Down Expand Up @@ -212,19 +245,20 @@ private void DrawMesh(MeshRenderData data, BoxedValueStore<string> metadata)
device.Indices = mesh.IndexBuffer;

var world = metadata.Get<Matrix>("world");
var view = metadata.Get<Matrix>("view");
var projection = metadata.Get<Matrix>("projection");
var worldView = metadata.Get<Matrix>("worldview");
var worldViewProjection = metadata.Get<Matrix>("worldviewprojection");

DepthSortInstances(visibleInstances);

int maxPrimitives = device.GraphicsProfile == GraphicsProfile.HiDef ? 1048575 : 65535;

for (int i = 0; i < visibleInstances.Count; i++)
{
var instance = visibleInstances[i];

world.Value = instance.Instance.Transform;
Matrix.Multiply(ref world.Value, ref view.Value, out worldView.Value);
worldView.Value = instance.WorldView;
Matrix.Multiply(ref worldView.Value, ref projection.Value, out worldViewProjection.Value);

foreach (var pass in data.Material.Begin(metadata))
Expand Down Expand Up @@ -255,6 +289,23 @@ private void DrawMesh(MeshRenderData data, BoxedValueStore<string> metadata)
}
}

private void DepthSortInstances(List<MeshInstance> instances)
{
if (instances.Count > 1)
instances.Sort(InstanceComparator);
}

private int InstanceComparator(MeshInstance a, MeshInstance b)
{
return CompareWorldViews(ref a.WorldView, ref b.WorldView);
}

public static int CompareWorldViews(ref Matrix worldViewA, ref Matrix worldViewB)
{
//Negated, because XNA uses a negative Z space
return -worldViewA.Translation.Z.CompareTo(worldViewB.Translation.Z);
}

private List<MeshInstance> GetInstanceList(Mesh mesh)
{
List<MeshInstance> value;
Expand Down
19 changes: 19 additions & 0 deletions Myre/Myre.Physics2D/(x86) Myre.Physics2D.ncrunchproject
@@ -0,0 +1,19 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
20 changes: 20 additions & 0 deletions Myre/Myre.Serialisation/(x86) Myre.Serialisation.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
20 changes: 20 additions & 0 deletions Myre/Myre.UI/(360) Myre.UI.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
20 changes: 20 additions & 0 deletions Myre/Myre/(360) Myre.ncrunchproject
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
@@ -0,0 +1,20 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>
7 changes: 4 additions & 3 deletions Testing/Myre.Testing.ncrunchsolution
@@ -1,7 +1,8 @@
<SolutionConfiguration>
<FileVersion>0</FileVersion>
<AutoEnableOnStartup>Default</AutoEnableOnStartup>
<AllowParallelTestExecution>false</AllowParallelTestExecution>
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>True</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>UseStaticAnalysis</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>UseStaticAnalysis</FrameworkUtilisationTypeForMSpec>
Expand Down
20 changes: 20 additions & 0 deletions Testing/Myre.Testing.sln
Expand Up @@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Myre.Serialisation.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "(x86) Myre.Serialisation", "..\Myre\Myre.Serialisation\(x86) Myre.Serialisation.csproj", "{73911D37-4250-40BD-8F15-20824D586319}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Myre.Tests", "Myre.Tests\Myre.Tests.csproj", "{523C09C2-B475-4CCC-9CCE-C19B54E4C829}"
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Myre.Testing.vsmdi
Expand Down Expand Up @@ -450,6 +452,24 @@ Global
{73911D37-4250-40BD-8F15-20824D586319}.Release|x86.ActiveCfg = Release|x86
{73911D37-4250-40BD-8F15-20824D586319}.Release|x86.Build.0 = Release|x86
{73911D37-4250-40BD-8F15-20824D586319}.Release|Xbox 360.ActiveCfg = Release|x86
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Any CPU.Build.0 = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|x86.ActiveCfg = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Debug|Xbox 360.ActiveCfg = Debug|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Any CPU.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Any CPU.Build.0 = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Mixed Platforms.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Mixed Platforms.Build.0 = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|x86.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Profile|Xbox 360.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Any CPU.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Any CPU.Build.0 = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|x86.ActiveCfg = Release|Any CPU
{523C09C2-B475-4CCC-9CCE-C19B54E4C829}.Release|Xbox 360.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 2bb47f0

Please sign in to comment.