Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Worker Inspector window & Entity List #1375

Merged
merged 7 commits into from
May 29, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion workers/unity/Packages/io.improbable.gdk.core/EntityId.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ namespace Improbable.Gdk.Core
/// Instances of this type should be treated as transient identifiers that will not be
/// consistent between different runs of the same simulation.
/// </remarks>
public readonly struct EntityId : IEquatable<EntityId>
public readonly struct EntityId : IEquatable<EntityId>, IComparable<EntityId>, IComparable
{
/// <summary>
/// The value of the EntityId.
@@ -82,5 +82,42 @@ public override string ToString()
{
return Id.ToString();
}

public int CompareTo(EntityId other)
{
return Id.CompareTo(other.Id);
}

public int CompareTo(object obj)
{
if (ReferenceEquals(null, obj))
{
return 1;
}

return obj is EntityId other
? CompareTo(other)
: throw new ArgumentException($"Object must be of type {nameof(EntityId)}");
}

public static bool operator <(EntityId left, EntityId right)
{
return left.CompareTo(right) < 0;
}

public static bool operator >(EntityId left, EntityId right)
{
return left.CompareTo(right) > 0;
}

public static bool operator <=(EntityId left, EntityId right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >=(EntityId left, EntityId right)
{
return left.CompareTo(right) >= 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ namespace Improbable.Gdk.Core
[UpdateBefore(typeof(SpatialOSReceiveSystem))]
public class EntitySystem : ComponentSystem
{
public int ViewVersion { get; private set; }

private readonly List<EntityId> entitiesAdded = new List<EntityId>();
private readonly List<EntityId> entitiesRemoved = new List<EntityId>();

@@ -49,6 +51,11 @@ internal void ApplyDiff(ViewDiff diff)
{
entitiesRemoved.Add(entityId);
}

if (entitiesAdded.Count != 0 || entitiesRemoved.Count != 0)
jamiebrynes7 marked this conversation as resolved.
Show resolved Hide resolved
{
ViewVersion += 1;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Improbable.Gdk.Debug.EditmodeTests")]

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

Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
"Improbable.Gdk.Core",
"Unity.Entities",
"Sirenix.OdinInspector.Editor",
"Improbable.Gdk.Core.Editor"
"Improbable.Gdk.Core.Editor",
"Improbable.Gdk.Generated"
jamiebrynes7 marked this conversation as resolved.
Show resolved Hide resolved
],
"includePlatforms": [
"Editor"
@@ -15,5 +16,6 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}
8 changes: 8 additions & 0 deletions workers/unity/Packages/io.improbable.gdk.debug/Tests.meta

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Improbable.Gdk.Debug.EditmodeTests",
"references": [
"GUID:40425aeb5a2b3f74797745fff21bc766",
"GUID:c5f2ea2f695256346af9ccd76c6f055d",
"GUID:edb3612c44ad0d24988d387581fd5fbe",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:734d92eba21c94caba915361bd5ac177",
"GUID:bd66e1825421d9041a8f2c4fa9ca562a"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll",
"Improbable.Worker.CInterop.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Improbable.Gdk.Core;
using Improbable.Gdk.Debug.WorkerInspector;
using Improbable.Gdk.TestUtils;
using NUnit.Framework;

namespace Improbable.Gdk.Debug.EditmodeTests.WorkerInspector
{
[TestFixture]
public class EntityListDataTests : MockBase
{
[TestCase]
public void Data_is_empty_intially()
{
var data = new EntityListData();
Assert.IsEmpty(data.Data);
}

[TestCase]
public void SetNewWorld_should_not_throw()
{
var data = new EntityListData();
Assert.DoesNotThrow(() => data.SetNewWorld(null));
}

[TestCase]
public void RefreshData_does_not_throw_if_no_world()
{
var data = new EntityListData();
Assert.DoesNotThrow(() => data.RefreshData());
}

[TestCase]
public void ApplySearch_does_not_throw_if_no_world()
{
var data = new EntityListData();
Assert.DoesNotThrow(() => data.ApplySearch(EntitySearchParameters.FromSearchString("")));
}

[TestCase]
public void RefreshData_finds_entities_after_setting_world()
{
World
.Step(world =>
{
world.Connection.CreateEntity(1, GetTemplate("some-entity"));
})
.Step(world =>
{
var data = new EntityListData();
data.SetNewWorld(world.Worker.World); // Yikes
return data;
})
.Step((world, data) =>
{
data.RefreshData();
Assert.AreEqual(1, data.Data.Count);

var entityData = data.Data[0];
Assert.AreEqual(1, entityData.EntityId.Id);
Assert.AreEqual("some-entity", entityData.Metadata);
});
}

[TestCase]
public void ApplySearchFilter_immediately_filters_data()
{
World
.Step(world =>
{
world.Connection.CreateEntity(1, GetTemplate("some-entity"));
})
.Step(world =>
{
var data = new EntityListData();
data.SetNewWorld(world.Worker.World); // Yikes
return data;
})
.Step((world, data) =>
{
data.RefreshData();
Assert.AreEqual(1, data.Data.Count);
})
.Step((world, data) =>
{
data.ApplySearch(EntitySearchParameters.FromSearchString("2")); // Entity ID = 2
Assert.IsEmpty(data.Data);
});
}

[TestCase]
public void SetNewWorld_resets_data()
{
World
.Step(world =>
{
world.Connection.CreateEntity(1, GetTemplate("some-entity"));
})
.Step(world =>
{
var data = new EntityListData();
data.SetNewWorld(world.Worker.World); // Yikes
return data;
})
.Step((world, data) =>
{
data.RefreshData();
Assert.AreEqual(1, data.Data.Count);
})
.Step((world, data) =>
{
data.SetNewWorld(null);
Assert.IsEmpty(data.Data);
});
}

[TestCase]
public void SearchFilter_persists_through_RefreshData()
{
World
.Step(world =>
{
world.Connection.CreateEntity(1, GetTemplate("some-entity"));
})
.Step(world =>
{
var data = new EntityListData();
data.ApplySearch(EntitySearchParameters.FromSearchString("2")); // Entity ID = 2
data.SetNewWorld(world.Worker.World); // Yikes
return data;
})
.Step((world, data) =>
{
data.RefreshData();
Assert.IsEmpty(data.Data);
});
}

private EntityTemplate GetTemplate(string metadata)
{
var template = new EntityTemplate();
template.AddComponent(new Position.Snapshot());
template.AddComponent(new Metadata.Snapshot(metadata));
return template;
}
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Improbable.Gdk.Debug.WorkerInspector;
using NUnit.Framework;

namespace Improbable.Gdk.Debug.EditmodeTests.WorkerInspector
{
[TestFixture]
public class EntitySearchParametersTests
{
[TestCase("1", 1)]
[TestCase(" 1 ", 1)]
[TestCase("1 ", 1)]
public void FromSearchString_parses_out_numbers(string searchString, long resultingId)
{
var searchParams = EntitySearchParameters.FromSearchString(searchString);
Assert.IsTrue(searchParams.EntityId.HasValue);
Assert.AreEqual(resultingId, searchParams.EntityId.Value.Id);
}

[TestCase("0")]
[TestCase("-1")]
[TestCase("300 spartans")]
[TestCase("9223372036854775808")] // Max long + 1
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
public void FromSearchString_rejects_non_entity_id_values(string searchString)
{
var searchParams = EntitySearchParameters.FromSearchString(searchString);
Assert.IsFalse(searchParams.EntityId.HasValue);
}

[TestCase("some value", "some value")]
[TestCase(" with leading space", "with leading space")]
[TestCase("with trailing space ", "with trailing space")]
[TestCase(" with both! ", "with both!")]
public void FromSearchString_ignores_leading_and_trailing_whitespace(string searchString, string expectedFragment)
{
var searchParams = EntitySearchParameters.FromSearchString(searchString);
Assert.IsNotNull(searchParams.SearchFragment);
Assert.AreEqual(expectedFragment, searchParams.SearchFragment);
}

[TestCase]
public void FromSearchString_converts_all_to_lower()
{
var searchParams = EntitySearchParameters.FromSearchString("CAPS");
Assert.IsNotNull(searchParams.SearchFragment);
Assert.AreEqual("caps", searchParams.SearchFragment);
}
}
}

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

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

Loading