Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Apr 3, 2019
1 parent 59d30fd commit ac4f67e
Show file tree
Hide file tree
Showing 33 changed files with 2,369 additions and 888 deletions.
18 changes: 9 additions & 9 deletions Unity.Entities.Editor/EntityDebugger/EntityIMGUIVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,25 @@ void ICustomVisit<float4>.CustomVisit(float4 f)
void ICustomVisit<float2x2>.CustomVisit(float2x2 f)
{
GUILayout.Label(Property.Name);
EditorGUILayout.Vector2Field("", (Vector2)f.m0);
EditorGUILayout.Vector2Field("", (Vector2)f.m1);
EditorGUILayout.Vector2Field("", (Vector2)f.c0);
EditorGUILayout.Vector2Field("", (Vector2)f.c1);
}

void ICustomVisit<float3x3>.CustomVisit(float3x3 f)
{
GUILayout.Label(Property.Name);
EditorGUILayout.Vector3Field("", (Vector3)f.m0);
EditorGUILayout.Vector3Field("", (Vector3)f.m1);
EditorGUILayout.Vector3Field("", (Vector3)f.m2);
EditorGUILayout.Vector3Field("", (Vector3)f.c0);
EditorGUILayout.Vector3Field("", (Vector3)f.c1);
EditorGUILayout.Vector3Field("", (Vector3)f.c2);
}

void ICustomVisit<float4x4>.CustomVisit(float4x4 f)
{
GUILayout.Label(Property.Name);
EditorGUILayout.Vector4Field("", (Vector4)f.m0);
EditorGUILayout.Vector4Field("", (Vector4)f.m1);
EditorGUILayout.Vector4Field("", (Vector4)f.m2);
EditorGUILayout.Vector4Field("", (Vector4)f.m3);
EditorGUILayout.Vector4Field("", (Vector4)f.c0);
EditorGUILayout.Vector4Field("", (Vector4)f.c1);
EditorGUILayout.Vector4Field("", (Vector4)f.c2);
EditorGUILayout.Vector4Field("", (Vector4)f.c3);
}

#region ICustomVisitPrimitives
Expand Down
13 changes: 11 additions & 2 deletions Unity.Entities.Hybrid/HybridSerializeUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ public static void Serialize(EntityManager manager, BinaryWriter writer, out Gam
public static void Deserialize(EntityManager manager, BinaryReader reader, GameObject sharedData)
{
int sharedComponentCount = Deserialize(manager, sharedData);
SerializeUtility.DeserializeWorld(manager, reader);
var transaction = manager.BeginExclusiveEntityTransaction();
SerializeUtility.DeserializeWorld(transaction, reader);
ReleaseSharedComponents(transaction, sharedComponentCount);
manager.EndExclusiveEntityTransaction();
}

public static void ReleaseSharedComponents(ExclusiveEntityTransaction transaction, int sharedComponentCount)
{
// Chunks have now taken over ownership of the shared components (reference counts have been added)
// so remove the ref that was added on deserialization
for (int i = 0; i < sharedComponentCount; ++i)
{
manager.m_SharedComponentManager.RemoveReference(i+1);
transaction.SharedComponentDataManager.RemoveReference(i+1);
}
}

Expand Down Expand Up @@ -52,6 +59,8 @@ public static unsafe int Deserialize(EntityManager manager, GameObject gameobjec
if (gameobject == null)
return 0;

manager.m_SharedComponentManager.PrepareForDeserialize();

var sharedData = gameobject.GetComponents<ComponentDataWrapperBase>();
for (int i = 0; i != sharedData.Length; i++)
{
Expand Down
8 changes: 5 additions & 3 deletions Unity.Entities.Hybrid/PlayerLoopManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public static void RegisterDomainUnload(CallbackFunction callback, int ordering
{
if (k_DomainUnloadMethods == null)
{
k_DomainUnloadMethods = new List<UnloadMethod>();
var go = new GameObject();
go.AddComponent<PlayerLoopDisableManager>().IsActive = true;
go.hideFlags = HideFlags.HideInHierarchy;
if (Application.isPlaying)
UnityEngine.Object.DontDestroyOnLoad(go);
else
go.hideFlags = HideFlags.HideAndDontSave;

go.AddComponent<PlayerLoopDisableManager>().IsActive = true;

k_DomainUnloadMethods = new List<UnloadMethod>();
}

k_DomainUnloadMethods.Add(new UnloadMethod { Function = callback, Ordering = ordering });
}

Expand Down
18 changes: 9 additions & 9 deletions Unity.Entities.Properties/JsonVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ void ICustomVisit<float2x2>.CustomVisit(float2x2 value)
StringBuffer.Append(' ', Style.Space * Indent);
StringBuffer.AppendPropertyName(Property.Name);
StringBuffer.Append('[');
StringBuffer.AppendFloat2(value.m0);
StringBuffer.AppendFloat2(value.c0);
StringBuffer.Append(',');
StringBuffer.AppendFloat2(value.m1);
StringBuffer.AppendFloat2(value.c1);
StringBuffer.Append(']');
StringBuffer.Append(",\n");
}
Expand Down Expand Up @@ -197,11 +197,11 @@ void ICustomVisit<float3x3>.CustomVisit(float3x3 value)
StringBuffer.Append(' ', Style.Space * Indent);
StringBuffer.AppendPropertyName(Property.Name);
StringBuffer.Append('[');
StringBuffer.AppendFloat3(value.m0);
StringBuffer.AppendFloat3(value.c0);
StringBuffer.Append(',');
StringBuffer.AppendFloat3(value.m1);
StringBuffer.AppendFloat3(value.c1);
StringBuffer.Append(',');
StringBuffer.AppendFloat3(value.m2);
StringBuffer.AppendFloat3(value.c2);
StringBuffer.Append(']');
StringBuffer.Append(",\n");
}
Expand All @@ -211,13 +211,13 @@ void ICustomVisit<float4x4>.CustomVisit(float4x4 value)
StringBuffer.Append(' ', Style.Space * Indent);
StringBuffer.AppendPropertyName(Property.Name);
StringBuffer.Append('[');
StringBuffer.AppendFloat4(value.m0);
StringBuffer.AppendFloat4(value.c0);
StringBuffer.Append(',');
StringBuffer.AppendFloat4(value.m1);
StringBuffer.AppendFloat4(value.c1);
StringBuffer.Append(',');
StringBuffer.AppendFloat4(value.m2);
StringBuffer.AppendFloat4(value.c2);
StringBuffer.Append(',');
StringBuffer.AppendFloat4(value.m3);
StringBuffer.AppendFloat4(value.c3);
StringBuffer.Append(']');
StringBuffer.Append(",\n");
}
Expand Down
2 changes: 1 addition & 1 deletion Unity.Entities.Tests/ComponentGroupDelta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void IterateStress()

list.Dispose();
}

[Test]
[Ignore("Needs to be implemented")]
public void IndexListSafety()
Expand Down
75 changes: 73 additions & 2 deletions Unity.Entities.Tests/EntityCommandBufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Burst;
using System.Collections.Generic;

namespace Unity.Entities.Tests
Expand Down Expand Up @@ -367,7 +368,7 @@ public void JobWithSharedComponentData()
}

// TODO: Burst breaks this test.
//[ComputeJobOptimization(CompileSynchronously = true)]
//[BurstCompile(CompileSynchronously = true)]
public struct TestBurstCommandBufferJob : IJob
{
public Entity e0;
Expand Down Expand Up @@ -468,7 +469,7 @@ public void TestCommandBufferDeleteRemoveSystemState()
var cmds = new EntityCommandBuffer(Allocator.TempJob);
for (var i = 0; i < entities.Length; i++)
{
cmds.RemoveSystemStateComponent<EcsState1>(entities[i]);
cmds.RemoveComponent<EcsState1>(entities[i]);
}

cmds.Playback(m_Manager);
Expand All @@ -481,5 +482,75 @@ public void TestCommandBufferDeleteRemoveSystemState()

Assert.AreEqual(0, count);
}

[Test]
public void TestShouldPlaybackFalse()
{
var cmds = new EntityCommandBuffer(Allocator.TempJob);
cmds.CreateEntity();
cmds.ShouldPlayback = false;
cmds.Playback(m_Manager);
cmds.Dispose();

var allEntities = m_Manager.GetAllEntities();
int count = allEntities.Length;
allEntities.Dispose();

Assert.AreEqual(0, count);
}

struct TestConcurrentJob : IJob
{
public EntityCommandBuffer.Concurrent Buffer;

public void Execute()
{
Buffer.CreateEntity();
Buffer.AddComponent(new EcsTestData { value = 1 });
}
}

[Test]
public void ConcurrentRecord()
{
var cmds = new EntityCommandBuffer(Allocator.TempJob);
cmds.CreateEntity();
new TestConcurrentJob { Buffer = cmds }.Schedule().Complete();
cmds.Playback(m_Manager);
cmds.Dispose();

var allEntities = m_Manager.GetAllEntities();
int count = allEntities.Length;
allEntities.Dispose();

Assert.AreEqual(2, count);
}

struct TestConcurrentParallelForJob : IJobParallelFor
{
public EntityCommandBuffer.Concurrent Buffer;

public void Execute(int index)
{
Buffer.CreateEntity();
Buffer.AddComponent(new EcsTestData { value = index });
}
}

[Test]
public void ConcurrentRecordParallelFor()
{
var cmds = new EntityCommandBuffer(Allocator.TempJob);
cmds.CreateEntity();
new TestConcurrentParallelForJob { Buffer = cmds }.Schedule(10000, 64).Complete();
cmds.Playback(m_Manager);
cmds.Dispose();

var allEntities = m_Manager.GetAllEntities();
int count = allEntities.Length;
allEntities.Dispose();

Assert.AreEqual(10001, count);
}
}
}
126 changes: 126 additions & 0 deletions Unity.Entities.Tests/EntityManagerBugTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.IO;
using System.Text;
using Unity.Collections;
using NUnit.Framework;
using Unity.Entities;
using UnityEngine;

namespace Unity.Entities.Tests
{
public struct Issue149Data : IComponentData
{
public int a;
public int b;
}

public class BatchDestroyTests : ECSTestsFixture
{
private EntityArchetype m_Archetype;

private const int kBatchCount = 512;

private class EntityBag
{
public NativeArray<Entity> Entities;
public int ValidVersion;
}

private EntityBag[] Bags = new EntityBag[3];

[Test]
public void TestIssue149()
{
m_Archetype = m_Manager.CreateArchetype(typeof(Issue149Data));

for (int i = 0; i < Bags.Length; ++i)
{
Bags[i] = new EntityBag();
}

var a = Bags[0];
var b = Bags[1];
var c = Bags[2];

try
{
RecycleEntities(a);
RecycleEntities(b);
RecycleEntities(c);
RecycleEntities(a);
RecycleEntities(b);
RecycleEntities(a);
RecycleEntities(c);
RecycleEntities(a);
RecycleEntities(a);
RecycleEntities(b);
RecycleEntities(a);
RecycleEntities(c);
RecycleEntities(a);
}
finally
{
// To get rid of leak errors in the log when the test fails.
a.Entities.Dispose();
b.Entities.Dispose();
c.Entities.Dispose();
}
}

private void RecycleEntities(EntityBag bag)
{
if (bag.Entities.Length > 0)
{
m_Manager.DestroyEntity(bag.Entities);
bag.Entities.Dispose();
}

bag.ValidVersion++;

// Sanity check all arrays.
SanityCheckVersions();

bag.Entities = new NativeArray<Entity>(kBatchCount, Allocator.Persistent);

for (int i = 0; i < bag.Entities.Length; ++i)
{
bag.Entities[i] = m_Manager.CreateEntity(m_Archetype);
}
}

private static readonly ComponentType[] s_OurTypes = new ComponentType[] {
typeof(Issue149Data)
};

// Walk all accessible entity data and check that the versions match what we
// believe the generation numbers should be.
private void SanityCheckVersions()
{
ArchetypeChunkArray chunks = m_Manager.CreateArchetypeChunkArray(
Array.Empty<ComponentType>(), // none
Array.Empty<ComponentType>(), // none
s_OurTypes, // all
Allocator.Temp);

ArchetypeChunkEntityType entityType = m_Manager.GetArchetypeChunkEntityType(false);

for (int i = 0; i < chunks.Length; ++i)
{
ArchetypeChunk chunk = chunks[i];
var entitiesInChunk = chunk.GetNativeArray(entityType);

for (int k = 0; k < chunk.Count; ++k)
{
Entity e = entitiesInChunk[k];
int index = e.Index;
int version = e.Version;

int ourArray = index / kBatchCount;
int ourVersion = Bags[ourArray].ValidVersion;

Assert.IsTrue(ourVersion == version);
}
}
}
}
}
11 changes: 11 additions & 0 deletions Unity.Entities.Tests/EntityManagerBugTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Unity.Entities.Tests/SerializeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public void SerializeEntities()
var reader = new TestBinaryReader(writer);

var deserializedWorld = new World("SerializeEntities Test World 3");
var entityManager = deserializedWorld.GetOrCreateManager<EntityManager>();

SerializeUtility.DeserializeWorld(deserializedWorld.GetOrCreateManager<EntityManager>(), reader);
SerializeUtility.DeserializeWorld(entityManager.BeginExclusiveEntityTransaction(), reader);
entityManager.EndExclusiveEntityTransaction();

try
{
var entityManager = deserializedWorld.GetExistingManager<EntityManager>();

var allEntities = entityManager.GetAllEntities(Allocator.Temp);
var count = allEntities.Length;
allEntities.Dispose();
Expand Down
Loading

0 comments on commit ac4f67e

Please sign in to comment.