|
| 1 | +using Improbable.Gdk.Core; |
| 2 | +using Improbable.Gdk.Test; |
| 3 | +using Improbable.Gdk.TestUtils; |
| 4 | +using Improbable.Worker.CInterop; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace Improbable.Gdk.EditmodeTests |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class Test : MockBase |
| 11 | + { |
| 12 | + private const long EntityId = 1; |
| 13 | + |
| 14 | + [Test] |
| 15 | + public void Authority_changes_are_kept_in_order_and_applied_in_order() |
| 16 | + { |
| 17 | + World |
| 18 | + .Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) |
| 19 | + .Step(world => |
| 20 | + { |
| 21 | + world.Connection.ChangeAuthority(EntityId, 54, Authority.Authoritative); |
| 22 | + world.Connection.ChangeAuthority(EntityId, 54, Authority.NotAuthoritative); |
| 23 | + }) |
| 24 | + .Step(world => |
| 25 | + { |
| 26 | + var authChanges = world |
| 27 | + .GetSystem<ComponentUpdateSystem>() |
| 28 | + .GetAuthorityChangesReceived(new EntityId(EntityId), 54); |
| 29 | + |
| 30 | + Assert.AreEqual(2, authChanges.Count); |
| 31 | + Assert.AreEqual(Authority.Authoritative, authChanges[0].Authority); |
| 32 | + Assert.AreEqual(Authority.NotAuthoritative, authChanges[1].Authority); |
| 33 | + |
| 34 | + var ecsEntity = world.GetSystem<WorkerSystem>().GetEntity(new EntityId(EntityId)); |
| 35 | + |
| 36 | + Assert.IsFalse(world.Worker.World.EntityManager.HasComponent<Position.HasAuthority>(ecsEntity)); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + [Test] |
| 41 | + public void Component_updates_are_kept_in_order() |
| 42 | + { |
| 43 | + World |
| 44 | + .Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) |
| 45 | + .Step(world => |
| 46 | + { |
| 47 | + world.Connection.UpdateComponent(EntityId, 54, new Position.Update |
| 48 | + { |
| 49 | + Coords = new Coordinates(1, 0, 0) |
| 50 | + }); |
| 51 | + world.Connection.UpdateComponent(EntityId, 54, new Position.Update |
| 52 | + { |
| 53 | + Coords = new Coordinates(-1, 0, 0) |
| 54 | + }); |
| 55 | + }) |
| 56 | + .Step(world => |
| 57 | + { |
| 58 | + var componentUpdates = world |
| 59 | + .GetSystem<ComponentUpdateSystem>() |
| 60 | + .GetComponentUpdatesReceived<Position.Update>(); |
| 61 | + |
| 62 | + Assert.AreEqual(2, componentUpdates.Count); |
| 63 | + Assert.AreEqual(1, componentUpdates[0].Update.Coords.Value.X); |
| 64 | + Assert.AreEqual(-1, componentUpdates[1].Update.Coords.Value.X); |
| 65 | + |
| 66 | + var ecsEntity = world.GetSystem<WorkerSystem>().GetEntity(new EntityId(EntityId)); |
| 67 | + |
| 68 | + Assert.AreEqual(-1, world.Worker.World.EntityManager.GetComponentData<Position.Component>(ecsEntity).Coords.X); |
| 69 | + }); |
| 70 | + } |
| 71 | + |
| 72 | + private static EntityTemplate GetTemplate() |
| 73 | + { |
| 74 | + var template = new EntityTemplate(); |
| 75 | + template.AddComponent(new Position.Snapshot()); |
| 76 | + return template; |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments