diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa0ae6..41fd551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ # Changelog +## [1.0.15] - 2023-07-27 + +### Changed + +* Updated com.unity.entities dependency to 1.0.14 +* Use of non required TempJob allocation and use Allocator.Temp instead. + +### Fixed + +* Runtime EntityQuery leaks and reduce runtime memory pressure due to continuously allocating queries without disposing. +* Reduced memory usage in Editor tests, by avoiding allocating queries continuously in hot paths. + + ## [1.0.12] - 2023-06-19 ### Changed @@ -37,6 +50,8 @@ * exceptions when NetworkRequestListen and/or. NetworkRequestConnect are handled and proper handling of multiple (erroneous) requests presents. * A problem with InterpolatedTick, going back and not recovering correctly in presence of large application, either the server or the client, stalls (i.e after loading). +* `MultiplayerPlayModeWindow > Dump Packet Logs` now works more reliably, now works with NUnit tests, and dump files are named with more context. +* Fixed bug in `GhostSendSystem` that caused it to not replicate ghosts when enabling packet dumps. `GhostValuesAreSerialized_WithPacketDumpsEnabled` test added. ## [1.0.8] - 2023-04-17 diff --git a/Editor/MultiplayerPlayModeWindow.cs b/Editor/MultiplayerPlayModeWindow.cs index 52ec8ea..3a9b150 100644 --- a/Editor/MultiplayerPlayModeWindow.cs +++ b/Editor/MultiplayerPlayModeWindow.cs @@ -973,9 +973,8 @@ static void DisconnectSpecificClient(EntityManager entityManager, NetworkId netw { entityManager.CompleteAllTrackedJobs(); using var activeConnectionsQuery = entityManager.CreateEntityQuery(ComponentType.ReadOnly(), ComponentType.Exclude()); - - using var entities = activeConnectionsQuery.ToEntityArray(Allocator.Temp); - using var networkIds = activeConnectionsQuery.ToComponentDataArray(Allocator.Temp); + var entities = activeConnectionsQuery.ToEntityArray(Allocator.Temp); + var networkIds = activeConnectionsQuery.ToComponentDataArray(Allocator.Temp); for (var i = 0; i < entities.Length; i++) { if (networkIds[i].Value == networkId.Value) @@ -990,8 +989,7 @@ static void DisconnectAllClients(EntityManager entityManager, NetworkStreamDisco { entityManager.CompleteAllTrackedJobs(); using var activeConnectionsQuery = entityManager.CreateEntityQuery(ComponentType.ReadOnly(), ComponentType.Exclude()); - - using var entities = activeConnectionsQuery.ToEntityArray(Allocator.Temp); + var entities = activeConnectionsQuery.ToEntityArray(Allocator.Temp); for (var i = 0; i < entities.Length; i++) { // TODO - Convert to batch when API supports 1 NetworkStreamRequestDisconnect for n entities. diff --git a/Runtime/Analytics/NetCodeAnalyticsState.cs b/Runtime/Analytics/NetCodeAnalyticsState.cs index 60ff86b..11d8a17 100644 --- a/Runtime/Analytics/NetCodeAnalyticsState.cs +++ b/Runtime/Analytics/NetCodeAnalyticsState.cs @@ -21,7 +21,7 @@ public static int GetPlayerCount() public static uint GetUpdateLength(World world) { - var query = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); if (query.CalculateEntityCount() != 1) { return 0; diff --git a/Runtime/Authoring/Hybrid/GhostAuthoringComponentBaker.cs b/Runtime/Authoring/Hybrid/GhostAuthoringComponentBaker.cs index 50f55dc..b6823b9 100644 --- a/Runtime/Authoring/Hybrid/GhostAuthoringComponentBaker.cs +++ b/Runtime/Authoring/Hybrid/GhostAuthoringComponentBaker.cs @@ -199,10 +199,8 @@ partial class GhostAuthoringBakingSystem : SystemBase protected override void OnCreate() { - base.OnCreate(); - // Query to get all the root entities baked before - m_NoLongerBakedRootEntities = EntityManager.CreateEntityQuery(new EntityQueryDesc + m_NoLongerBakedRootEntities = GetEntityQuery(new EntityQueryDesc { None = new [] { @@ -218,7 +216,7 @@ protected override void OnCreate() m_NoLongerBakedRootEntitiesMask = m_NoLongerBakedRootEntities.GetEntityQueryMask(); // Query to get all the root entities baked before - m_GhostEntities = EntityManager.CreateEntityQuery(new EntityQueryDesc + m_GhostEntities = GetEntityQuery(new EntityQueryDesc { All = new [] { diff --git a/Runtime/ClientServerWorld/ClientServerBootstrap.cs b/Runtime/ClientServerWorld/ClientServerBootstrap.cs index 5e141cc..a75cd05 100644 --- a/Runtime/ClientServerWorld/ClientServerBootstrap.cs +++ b/Runtime/ClientServerWorld/ClientServerBootstrap.cs @@ -560,7 +560,7 @@ public void OnCreate(ref SystemState state) var world = World.All[i]; if (world.IsClient()) { - var driver = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var driver = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); UnityEngine.Assertions.Assert.IsFalse(driver.IsEmpty); var driverData = driver.ToComponentDataArray(Allocator.Temp); UnityEngine.Assertions.Assert.IsTrue(driverData.Length == 1); diff --git a/Runtime/Connection/DriverMigrationSystem.cs b/Runtime/Connection/DriverMigrationSystem.cs index a53f109..469e83e 100644 --- a/Runtime/Connection/DriverMigrationSystem.cs +++ b/Runtime/Connection/DriverMigrationSystem.cs @@ -102,13 +102,12 @@ public int StoreWorld(World sourceWorld) driverMap.Add(ticket, default); - var driverSingletonQuery = sourceWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); + using var driverSingletonQuery = sourceWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); ref var driverSingleton = ref driverSingletonQuery.GetSingletonRW().ValueRW; driverSingletonQuery.CompleteDependency(); - driverSingletonQuery.Dispose(); Store(driverSingleton.StoreMigrationState(), ticket); - var filter = sourceWorld.EntityManager.CreateEntityQuery(typeof(NetworkStreamConnection)); + using var filter = sourceWorld.EntityManager.CreateEntityQuery(typeof(NetworkStreamConnection)); var backupWorld = new World(sourceWorld.Name, sourceWorld.Flags); backupWorld.EntityManager.MoveEntitiesFrom(sourceWorld.EntityManager, filter); diff --git a/Runtime/Connection/NetworkStreamDriver.cs b/Runtime/Connection/NetworkStreamDriver.cs index 5bddea3..2d9c34f 100644 --- a/Runtime/Connection/NetworkStreamDriver.cs +++ b/Runtime/Connection/NetworkStreamDriver.cs @@ -166,7 +166,8 @@ public Entity Connect(EntityManager entityManager, NetworkEndpoint endpoint, Ent if (DriverStore.DriversCount != 1) throw new InvalidOperationException("Too many NetworkDriver created for the client. Only one NetworkDriver instance should exist"); var builder = new EntityQueryBuilder(Allocator.Temp).WithAll(); - if (!entityManager.CreateEntityQuery(builder).IsEmpty) + using var query = entityManager.CreateEntityQuery(builder); + if (!query.IsEmpty) throw new InvalidOperationException("Connection to server already initiated, only one connection allowed at a time."); #endif #if UNITY_EDITOR || !UNITY_CLIENT diff --git a/Runtime/Debug/NetCodeDebugConfig.cs b/Runtime/Debug/NetCodeDebugConfig.cs index c2d3454..fab6869 100644 --- a/Runtime/Debug/NetCodeDebugConfig.cs +++ b/Runtime/Debug/NetCodeDebugConfig.cs @@ -42,8 +42,8 @@ internal partial struct DebugConnections : ISystem [BurstCompile] public void OnCreate(ref SystemState state) { - m_ConnectionsQueryWithout = state.EntityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll().WithNone()); - m_ConnectionsQueryWith = state.EntityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll().WithAll()); + m_ConnectionsQueryWithout = state.GetEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll().WithNone()); + m_ConnectionsQueryWith = state.GetEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll().WithAll()); } public void OnUpdate(ref SystemState state) @@ -78,13 +78,6 @@ public void OnUpdate(ref SystemState state) state.EntityManager.RemoveComponent(m_ConnectionsQueryWith); } } - - [BurstCompile] - public void OnDestroy(ref SystemState state) - { - m_ConnectionsQueryWithout.Dispose(); - m_ConnectionsQueryWith.Dispose(); - } } #endif } diff --git a/Runtime/Rpc/RpcCommandRequest.cs b/Runtime/Rpc/RpcCommandRequest.cs index bf3351a..e17d1f5 100644 --- a/Runtime/Rpc/RpcCommandRequest.cs +++ b/Runtime/Rpc/RpcCommandRequest.cs @@ -89,7 +89,7 @@ public partial class RpcCommandRequestSystemGroup : ComponentSystemGroup protected override void OnCreate() { base.OnCreate(); - m_Query = EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + m_Query = GetEntityQuery(ComponentType.ReadOnly()); } protected override void OnUpdate() { diff --git a/Runtime/Snapshot/GhostCollectionSystem.cs b/Runtime/Snapshot/GhostCollectionSystem.cs index c3f7dcf..126ccf7 100644 --- a/Runtime/Snapshot/GhostCollectionSystem.cs +++ b/Runtime/Snapshot/GhostCollectionSystem.cs @@ -182,13 +182,13 @@ public void OnCreate(ref SystemState state) entityQueryBuilder.Reset(); entityQueryBuilder.WithAll(); - m_InGameQuery = state.EntityManager.CreateEntityQuery(entityQueryBuilder); + m_InGameQuery = state.GetEntityQuery(entityQueryBuilder); entityQueryBuilder.Reset(); entityQueryBuilder.WithAll(); - m_AllConnectionsQuery = state.EntityManager.CreateEntityQuery(entityQueryBuilder); + m_AllConnectionsQuery = state.GetEntityQuery(entityQueryBuilder); entityQueryBuilder.Reset(); entityQueryBuilder.WithAll().WithNone(); - m_RegisterGhostTypesQuery = state.EntityManager.CreateEntityQuery(entityQueryBuilder); + m_RegisterGhostTypesQuery = state.GetEntityQuery(entityQueryBuilder); if (!SystemAPI.TryGetSingletonEntity(out m_CodePrefabSingleton)) m_CodePrefabSingleton = state.EntityManager.CreateSingletonBuffer(); @@ -207,8 +207,6 @@ public void OnDestroy(ref SystemState state) m_AllComponentTypes.Dispose(); if (m_StableHashToComponentTypeIndex.IsCreated) m_StableHashToComponentTypeIndex.Dispose(); - m_InGameQuery.Dispose(); - m_AllConnectionsQuery.Dispose(); state.EntityManager.DestroyEntity(m_CollectionSingleton); #if UNITY_EDITOR || NETCODE_DEBUG m_PredictionErrorNames.Dispose(); diff --git a/Runtime/Snapshot/GhostDistancePartitioningSystem.cs b/Runtime/Snapshot/GhostDistancePartitioningSystem.cs index cd71fcb..ed8ef68 100644 --- a/Runtime/Snapshot/GhostDistancePartitioningSystem.cs +++ b/Runtime/Snapshot/GhostDistancePartitioningSystem.cs @@ -140,7 +140,7 @@ public void OnCreate(ref SystemState state) state.RequireForUpdate(); var builder = new EntityQueryBuilder(Allocator.Temp) .WithAll(); - m_DistancePartitionedEntitiesQuery = state.WorldUnmanaged.EntityManager.CreateEntityQuery(builder); + m_DistancePartitionedEntitiesQuery = state.GetEntityQuery(builder); } [BurstCompile] diff --git a/Runtime/Snapshot/GhostPrefabCreation.cs b/Runtime/Snapshot/GhostPrefabCreation.cs index 5b1834f..27349a1 100644 --- a/Runtime/Snapshot/GhostPrefabCreation.cs +++ b/Runtime/Snapshot/GhostPrefabCreation.cs @@ -816,9 +816,8 @@ public static void CollectAllComponents(EntityManager entityManager, NativeArray var variants = new NativeArray(allComponents.Length, Allocator.Temp); // TODO - Consider changing the API to pass this as an arg. - var collectionDataQuery = entityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll()); + using var collectionDataQuery = entityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll()); var collectionData = collectionDataQuery.GetSingleton(); - collectionDataQuery.Dispose(); #if ENABLE_UNITY_COLLECTIONS_CHECKS { @@ -869,13 +868,12 @@ public static void CollectAllComponents(EntityManager entityManager, NativeArray FinalizePrefabComponents(config, entityManager, prefab, ghostType, linkedEntitiesArray, allComponents, componentCounts, target, prefabTypes); - var codePrefabQuery = entityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll()); + using var codePrefabQuery = entityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll()); if (!codePrefabQuery.TryGetSingletonEntity(out var codePrefabSingleton)) codePrefabSingleton = entityManager.CreateSingletonBuffer(); var codePrefabs = entityManager.GetBuffer(codePrefabSingleton); - codePrefabQuery.Dispose(); - #if NETCODE_DEBUG +#if NETCODE_DEBUG for (int i = 0; i < codePrefabs.Length; ++i) { if (entityManager.GetComponentData(codePrefabs[i].entity) == ghostType) diff --git a/Runtime/Snapshot/GhostReceiveSystem.cs b/Runtime/Snapshot/GhostReceiveSystem.cs index 9d589fd..9e50607 100644 --- a/Runtime/Snapshot/GhostReceiveSystem.cs +++ b/Runtime/Snapshot/GhostReceiveSystem.cs @@ -204,7 +204,7 @@ public void OnCreate(ref SystemState state) builder.Reset(); builder.WithAll(); - m_SubSceneQuery = state.EntityManager.CreateEntityQuery(builder); + m_SubSceneQuery = state.GetEntityQuery(builder); m_CompressionModel = StreamCompressionModel.Default; diff --git a/Runtime/Snapshot/GhostSendSystem.cs b/Runtime/Snapshot/GhostSendSystem.cs index ed17ab3..d4d2958 100644 --- a/Runtime/Snapshot/GhostSendSystem.cs +++ b/Runtime/Snapshot/GhostSendSystem.cs @@ -359,7 +359,7 @@ public void OnCreate(ref SystemState state) }; ghostSpawnQuery = state.GetEntityQuery(filterSpawn); ghostDespawnQuery = state.GetEntityQuery(filterDespawn); - prespawnSharedComponents = state.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + prespawnSharedComponents = state.GetEntityQuery(ComponentType.ReadOnly()); m_FreeGhostIds = new NativeQueue(Allocator.Persistent); m_AllocatedGhostIds = new NativeArray(2, Allocator.Persistent); diff --git a/Runtime/Stats/GhostStatsSystem.cs b/Runtime/Stats/GhostStatsSystem.cs index b9846c7..82b7eee 100644 --- a/Runtime/Stats/GhostStatsSystem.cs +++ b/Runtime/Stats/GhostStatsSystem.cs @@ -27,7 +27,7 @@ public static void OpenDebugger() } #endif - struct GhostStatsToSend : IDisposable + struct GhostStatsToSend { readonly public World managedWorld; public EntityQuery singletonQuery; @@ -37,10 +37,6 @@ public GhostStatsToSend(World world, EntityQuery query) managedWorld = world; singletonQuery = query; } - public void Dispose() - { - singletonQuery.Dispose(); - } } private DebugWebSocket m_Socket; private List m_StatsCollections; @@ -82,7 +78,6 @@ public void Update() if (!collectionDataQry.HasSingleton()) { - collectionDataQry.Dispose(); continue; } SetStatIndex(collectionDataQry, m_StatsCollections.Count); diff --git a/Tests/Editor/CommandBufferSerialization.cs b/Tests/Editor/CommandBufferSerialization.cs index 4569785..f87a0ac 100644 --- a/Tests/Editor/CommandBufferSerialization.cs +++ b/Tests/Editor/CommandBufferSerialization.cs @@ -277,11 +277,10 @@ public void CommandDataBuffer_OwnerPredicted_InterpolatedClientes_ShouldNotRecei //Assign the owner on the respective clients. Client3 is passive (no entity) for(int i=0;i<2;++i) { - var query = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(typeof(GhostOwner)); + using var query = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(typeof(GhostOwner)); var entities = query.ToEntityArray(Allocator.Temp); var owners = query.ToComponentDataArray(Allocator.Temp); - var connQuery = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery( - typeof(NetworkId)); + using var connQuery = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(typeof(NetworkId)); var conn = connQuery.GetSingletonEntity(); var networkId = connQuery.GetSingleton(); for(int e=0;e(testWorld.ClientWorlds[clientOwner]); var netId1 = testWorld.ClientWorlds[clientOwner].EntityManager.GetComponentData(net1); - var entities = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()) - .ToEntityArray(Allocator.Temp); + //TODO: dispose this + using var entitiesQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + var entities = entitiesQuery.ToEntityArray(Allocator.Temp); testWorld.ServerWorld.EntityManager.SetComponentData(serverEnt, new GhostOwner {NetworkId = netId1.Value}); testWorld.ServerWorld.EntityManager.SetComponentData(serverEnt, new GhostGen_IntStruct {IntValue = 1000}); for (int i = 0; i < entities.Length; ++i) diff --git a/Tests/Editor/CommandDataTests.cs b/Tests/Editor/CommandDataTests.cs index d963686..158bc14 100644 --- a/Tests/Editor/CommandDataTests.cs +++ b/Tests/Editor/CommandDataTests.cs @@ -350,7 +350,7 @@ public void MultipleAutoCommandTargetSendsData() for (int i = 0; i < 16; ++i) testWorld.Tick(deltaTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostOwner)); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostOwner)); var clientEnts = query.ToEntityArray(Allocator.Temp); Assert.AreEqual(2, clientEnts.Length); Assert.AreNotEqual(Entity.Null, clientEnts[0]); @@ -358,9 +358,7 @@ public void MultipleAutoCommandTargetSendsData() if (testWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEnts[0]).ghostId != testWorld.ServerWorld.EntityManager.GetComponentData(serverEnt).ghostId) { // swap 0 and 1 - var temp = clientEnts[0]; - clientEnts[0] = clientEnts[1]; - clientEnts[1] = temp; + (clientEnts[0], clientEnts[1]) = (clientEnts[1], clientEnts[0]); } testWorld.ServerWorld.EntityManager.AddComponent(serverEnt); diff --git a/Tests/Editor/ConnectionTests.cs b/Tests/Editor/ConnectionTests.cs index f5ca38d..76953c9 100644 --- a/Tests/Editor/ConnectionTests.cs +++ b/Tests/Editor/ConnectionTests.cs @@ -98,7 +98,7 @@ public void SameVersion_ConnectSuccessfully() for (int i = 0; i < 16; ++i) testWorld.Tick(16f/1000f); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.AreEqual(1, query.CalculateEntityCount()); } } @@ -126,7 +126,7 @@ public void DifferentVersions_AreDisconnnected() //Different NetCodeVersion var clientVersion = testWorld.ClientWorlds[0].EntityManager.CreateEntity(typeof(NetworkProtocolVersion)); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); testWorld.ClientWorlds[0].EntityManager.SetComponentData(clientVersion, new NetworkProtocolVersion { NetCodeVersion = 2, @@ -233,7 +233,7 @@ public void ProtocolVersionDebugInfoAppearsOnMismatch(bool debugServer) testWorld.Tick(16f/1000f); // Verify client connection is disconnected - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.AreEqual(0, query.CalculateEntityCount()); } } @@ -268,7 +268,7 @@ public void DisconnectEventAndRPCVersionErrorProcessedInSameFrame(bool checkServ testWorld.Tick(dt); // Verify client connection is disconnected - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.AreEqual(0, query.CalculateEntityCount()); } } @@ -282,7 +282,7 @@ void LogExpectProtocolError(NetCodeTestWorld testWorld, World world, bool checkS LogAssert.Expect(LogType.Error, "RPC List (for above 'bad protocol version' error): " + rpcs.Length); for (int i = 0; i < rpcs.Length; ++i) LogAssert.Expect(LogType.Error, new Regex("Unity.NetCode")); - var collection = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var collection = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var serializers = world.EntityManager.GetBuffer(collection.ToEntityArray(Allocator.Temp)[0]); LogAssert.Expect(LogType.Error, "Component serializer data (for above 'bad protocol version' error): " + serializers.Length); for (int i = 0; i < serializers.Length; ++i) diff --git a/Tests/Editor/GameObjectConversionTest.cs b/Tests/Editor/GameObjectConversionTest.cs index ea78476..fc31966 100644 --- a/Tests/Editor/GameObjectConversionTest.cs +++ b/Tests/Editor/GameObjectConversionTest.cs @@ -155,8 +155,8 @@ public class GameObjectConversionTest { void CheckComponent(World w, ComponentType testType, int expectedCount) { - var query = w.EntityManager.CreateEntityQuery(testType); - using (var ghosts = query.ToEntityArray(Allocator.TempJob)) + using var query = w.EntityManager.CreateEntityQuery(testType); + using (var ghosts = query.ToEntityArray(Allocator.Temp)) { var compCount = ghosts.Length; Assert.AreEqual(expectedCount, compCount); diff --git a/Tests/Editor/GhostSerializationTestsForEnableableBits.cs b/Tests/Editor/GhostSerializationTestsForEnableableBits.cs index 42c2eaa..c3be3e7 100644 --- a/Tests/Editor/GhostSerializationTestsForEnableableBits.cs +++ b/Tests/Editor/GhostSerializationTestsForEnableableBits.cs @@ -240,11 +240,10 @@ private void VerifyGhostGroupValues(bool expectValueReplicated, bool expectEn var rootType = ComponentType.ReadOnly(); var childType = ComponentType.ReadOnly(); - var rootQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(rootType); - var childQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(childType); - - using (var clientRootEntities = rootQuery.ToEntityArray(Allocator.TempJob)) - using (var clientChildEntities = childQuery.ToEntityArray(Allocator.TempJob)) + using var rootQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(rootType); + using var childQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(childType); + using (var clientRootEntities = rootQuery.ToEntityArray(Allocator.Temp)) + using (var clientChildEntities = childQuery.ToEntityArray(Allocator.Temp)) { for (int i = 0; i < clientRootEntities.Length; i++) { @@ -276,136 +275,131 @@ private void VerifyGhostGroupEnabledBits(bool expectValueReplicated, bool exp var rootType = ComponentType.ReadOnly(); var childType = ComponentType.ReadOnly(); - var rootQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(rootType); - var childQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(childType); + using var rootQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(rootType); + using var childQuery = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(childType); + using var clientRootEntities = rootQuery.ToEntityArray(Allocator.Temp); + using var clientChildEntities = childQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(clientRootEntities.Length, clientChildEntities.Length); + Assert.AreEqual(m_ServerEntities.Length, clientChildEntities.Length + clientRootEntities.Length, $"[{typeof(T)}] Expect client group has entities!"); - using (var clientRootEntities = rootQuery.ToEntityArray(Allocator.TempJob)) - using (var clientChildEntities = childQuery.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientRootEntities.Length; i++) { - Assert.AreEqual(clientRootEntities.Length, clientChildEntities.Length); - Assert.AreEqual(m_ServerEntities.Length, clientChildEntities.Length + clientRootEntities.Length, $"[{typeof(T)}] Expect client group has entities!"); + var clientGroupRootEntity = clientRootEntities[i]; + var clientGroupMemberEntity = clientChildEntities[i]; - for (int i = 0; i < clientRootEntities.Length; i++) + var rootEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientGroupRootEntity); + var memberEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientGroupMemberEntity); + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) // Ghost groups are root entities, by definition. { - var clientGroupRootEntity = clientRootEntities[i]; - var clientGroupMemberEntity = clientChildEntities[i]; - - var rootEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientGroupRootEntity); - var memberEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientGroupMemberEntity); - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) // Ghost groups are root entities, by definition. - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, rootEnabled, $"[{typeof(T)}] Expect \"group root\" entity enabled IS replicated when `{m_SendForChildrenTestCase}`!"); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, memberEnabled, $"[{typeof(T)}] Expect \"group member\" entity enabled IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, rootEnabled, $"[{typeof(T)}] Expect \"group root\" entity enabled NOT replicated when `{m_SendForChildrenTestCase}`!"); - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, memberEnabled, $"[{typeof(T)}] Expect \"group member\" entity enabled NOT replicated when `{m_SendForChildrenTestCase}`!"); - } + Assert.AreEqual(m_ExpectedEnabledIfReplicated, rootEnabled, $"[{typeof(T)}] Expect \"group root\" entity enabled IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, memberEnabled, $"[{typeof(T)}] Expect \"group member\" entity enabled IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, rootEnabled, $"[{typeof(T)}] Expect \"group root\" entity enabled NOT replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, memberEnabled, $"[{typeof(T)}] Expect \"group member\" entity enabled NOT replicated when `{m_SendForChildrenTestCase}`!"); } - - ValidateChangeMaskForComponent(expectEnabledReplicated | expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true), true); } + + ValidateChangeMaskForComponent(expectEnabledReplicated | expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true), true); } private void VerifyLinkedBufferValues(bool expectValuesReplicated, bool expectEnabledReplicated) where T : unmanaged, IBufferElementData, IEnableableComponent, IComponentValue { var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + + using var clientEntities = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); + var serverEntity = m_ServerEntities[i]; + var clientEntity = clientEntities[i]; - for (int i = 0; i < clientEntities.Length; i++) - { - var serverEntity = m_ServerEntities[i]; - var clientEntity = clientEntities[i]; + Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), "Has client linked group!"); - Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), "Has client linked group!"); + var serverEntityGroup = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntity, true); + var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + Assert.AreEqual(2, clientEntityGroup.Length, "client linked group, expecting parent + child"); - var serverEntityGroup = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntity, true); - var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); - Assert.AreEqual(2, clientEntityGroup.Length, "client linked group, expecting parent + child"); + var clientParentEntityComponentEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[0].Value); + var clientChildEntityComponentEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); - var clientParentEntityComponentEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[0].Value); - var clientChildEntityComponentEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent entity component enabled bit IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent entity component enabled bit NOT replicated when `{m_SendForChildrenTestCase}`!"); + } - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent entity component enabled bit IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent entity component enabled bit NOT replicated when `{m_SendForChildrenTestCase}`!"); - } + var serverParentBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntityGroup[0].Value, true); + var serverChildBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntityGroup[1].Value, true); + var clientParentBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntityGroup[0].Value, true); + var clientChildBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntityGroup[1].Value, true); - var serverParentBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntityGroup[0].Value, true); - var serverChildBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntityGroup[1].Value, true); - var clientParentBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntityGroup[0].Value, true); - var clientChildBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntityGroup[1].Value, true); + Assert.AreEqual(m_ExpectedServerBufferSize, serverParentBuffer.Length, $"[{typeof(T)}] Expect server parent buffer length!"); + Assert.AreEqual(m_ExpectedServerBufferSize, serverChildBuffer.Length, $"[{typeof(T)}] Expect server child buffer length!"); - Assert.AreEqual(m_ExpectedServerBufferSize, serverParentBuffer.Length, $"[{typeof(T)}] Expect server parent buffer length!"); - Assert.AreEqual(m_ExpectedServerBufferSize, serverChildBuffer.Length, $"[{typeof(T)}] Expect server child buffer length!"); + // Root: + if (expectValuesReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedServerBufferSize, clientParentBuffer.Length, $"[{typeof(T)}] Expect client parent buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent buffer enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kBakedBufferSize, clientParentBuffer.Length, $"[{typeof(T)}] Expect client parent buffer length NOT replicated when `{m_SendForChildrenTestCase}`, so expect it will use default client buffer length!"); + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent buffer enable bit NOT replicated when `{m_SendForChildrenTestCase}`!"); + } - // Root: + for (int j = 0; j < serverParentBuffer.Length; ++j) + { + var serverValue = serverParentBuffer[j]; + var clientValue = clientParentBuffer[j]; + + var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); + Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect server parent value is written [{i}]"); if (expectValuesReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) { - Assert.AreEqual(m_ExpectedServerBufferSize, clientParentBuffer.Length, $"[{typeof(T)}] Expect client parent buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent buffer enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client parent value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); } else { - Assert.AreEqual(kBakedBufferSize, clientParentBuffer.Length, $"[{typeof(T)}] Expect client parent buffer length NOT replicated when `{m_SendForChildrenTestCase}`, so expect it will use default client buffer length!"); - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientParentEntityComponentEnabled, $"[{typeof(T)}] Expect client parent buffer enable bit NOT replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] Expect client parent value [{i}] NOT replicated when `{m_SendForChildrenTestCase}`!"); } + } - for (int j = 0; j < serverParentBuffer.Length; ++j) - { - var serverValue = serverParentBuffer[j]; - var clientValue = clientParentBuffer[j]; - - var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); - Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect server parent value is written [{i}]"); - if (expectValuesReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client parent value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] Expect client parent value [{i}] NOT replicated when `{m_SendForChildrenTestCase}`!"); - } - } + // Children: + if (IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) + { + Assert.AreEqual(m_ExpectedServerBufferSize, clientChildBuffer.Length, $"[{typeof(T)}] Expect client child buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientChildEntityComponentEnabled, $"[{typeof(T)}] Expect client child buffer enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kBakedBufferSize, clientChildBuffer.Length, $"[{typeof(T)}] Expect client child buffer length NOT replicated when `{m_SendForChildrenTestCase}`, so expect it will use the default client buffer length!"); + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientChildEntityComponentEnabled, $"[{typeof(T)}] Expect client child buffer enable bit NOT replicated when `{m_SendForChildrenTestCase}`!"); + } + for (int j = 0; j < serverChildBuffer.Length; ++j) + { + var serverValue = serverChildBuffer[j]; + var clientValue = clientChildBuffer[j]; + + var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); + Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect client child value is written [{i}]!"); - // Children: if (IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) { - Assert.AreEqual(m_ExpectedServerBufferSize, clientChildBuffer.Length, $"[{typeof(T)}] Expect client child buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, clientChildEntityComponentEnabled, $"[{typeof(T)}] Expect client child buffer enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client child entity buffer value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); } else { - Assert.AreEqual(kBakedBufferSize, clientChildBuffer.Length, $"[{typeof(T)}] Expect client child buffer length NOT replicated when `{m_SendForChildrenTestCase}`, so expect it will use the default client buffer length!"); - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, clientChildEntityComponentEnabled, $"[{typeof(T)}] Expect client child buffer enable bit NOT replicated when `{m_SendForChildrenTestCase}`!"); - } - for (int j = 0; j < serverChildBuffer.Length; ++j) - { - var serverValue = serverChildBuffer[j]; - var clientValue = clientChildBuffer[j]; - - var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); - Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect client child value is written [{i}]!"); - - if (IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) - { - Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client child entity buffer value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] client parent value [{i}] NOT replicated when `{m_SendForChildrenTestCase}`!"); - } + Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] client parent value [{i}] NOT replicated when `{m_SendForChildrenTestCase}`!"); } } } @@ -417,44 +411,41 @@ private void VerifyLinkedComponentValues(bool expectValueReplicated, bool exp VerifyLinkedComponentEnabled(expectValueReplicated, expectEnabledReplicated, forceChildReplication); var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); - - for (int i = 0; i < clientEntities.Length; i++) - { - var clientEntity = clientEntities[i]; + var clientEntity = clientEntities[i]; - Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity)); + Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity)); - var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); - Assert.AreEqual(2, clientEntityGroup.Length, "Client entity count should always be correct."); + var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + Assert.AreEqual(2, clientEntityGroup.Length, "Client entity count should always be correct."); - var clientRootValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[0].Value).GetValue(); - var clientChildValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[1].Value).GetValue(); - if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedValueIfReplicated, clientRootValue, $"[{typeof(T)}] Expected that value on component on root entity [{i}] IS replicated correctly when using this `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientRootValue, $"[{typeof(T)}] Expected that value on component on root entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); - } - - if (forceChildReplication ?? expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) - { - Assert.AreEqual(m_ExpectedValueIfReplicated, clientChildValue, $"[{typeof(T)}] Expected that value on component on child entity [{i}] IS replicated when using this `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientChildValue, $"[{typeof(T)}] Expected that value on component on child entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); - } + var clientRootValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[0].Value).GetValue(); + var clientChildValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[1].Value).GetValue(); + if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedValueIfReplicated, clientRootValue, $"[{typeof(T)}] Expected that value on component on root entity [{i}] IS replicated correctly when using this `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kDefaultValueIfNotReplicated, clientRootValue, $"[{typeof(T)}] Expected that value on component on root entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); } - ValidateChangeMaskForComponent(forceChildReplication ?? expectValueReplicated | expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false), false); + if (forceChildReplication ?? expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) + { + Assert.AreEqual(m_ExpectedValueIfReplicated, clientChildValue, $"[{typeof(T)}] Expected that value on component on child entity [{i}] IS replicated when using this `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kDefaultValueIfNotReplicated, clientChildValue, $"[{typeof(T)}] Expected that value on component on child entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); + } } + + ValidateChangeMaskForComponent(forceChildReplication ?? expectValueReplicated | expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false), false); } void VerifyLinkedComponentValueOnChild(bool expectValueReplicated, bool expectEnabledReplicated) @@ -463,31 +454,29 @@ void VerifyLinkedComponentValueOnChild(bool expectValueReplicated, bool expec VerifyLinkedComponentEnabledOnChild(expectValueReplicated, expectEnabledReplicated); var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) - { - Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Expect client has entities!"); - for (int i = 0; i < clientEntities.Length; i++) - { - var clientEntity = clientEntities[i]; + for (int i = 0; i < clientEntities.Length; i++) + { + var clientEntity = clientEntities[i]; - Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity)); + Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity)); - var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); - Assert.AreEqual(2, clientEntityGroup.Length, "Client entity count should always be correct."); + var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + Assert.AreEqual(2, clientEntityGroup.Length, "Client entity count should always be correct."); - // This method is exclusively to test behaviour of children. + // This method is exclusively to test behaviour of children. - var value = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[1].Value).GetValue(); - if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) - { - Assert.AreEqual(m_ExpectedValueIfReplicated, value, $"[{typeof(T)}] Expected that value on component on child entity [{i}] IS replicated when using this `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, value, $"[{typeof(T)}] Expected that value on component on child entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); - } + var value = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntityGroup[1].Value).GetValue(); + if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) + { + Assert.AreEqual(m_ExpectedValueIfReplicated, value, $"[{typeof(T)}] Expected that value on component on child entity [{i}] IS replicated when using this `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kDefaultValueIfNotReplicated, value, $"[{typeof(T)}] Expected that value on component on child entity [{i}] is NOT replicated by default (via this `{m_SendForChildrenTestCase}`)!"); } } } @@ -496,76 +485,70 @@ private void VerifyLinkedComponentEnabled(bool expectValueReplicated, bool ex where T : unmanaged, IComponentData, IEnableableComponent { var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Client has entity with TopLevelGhostEntity."); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Client has entity with TopLevelGhostEntity."); - - for (int i = 0; i < clientEntities.Length; i++) - { - var clientEntity = clientEntities[i]; + var clientEntity = clientEntities[i]; - Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), $"[{typeof(T)}] Client has entities with the LinkedEntityGroup."); + Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), $"[{typeof(T)}] Client has entities with the LinkedEntityGroup."); - var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); - Assert.AreEqual(2, clientEntityGroup.Length, $"[{typeof(T)}] Entities in the LinkedEntityGroup!"); + var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + Assert.AreEqual(2, clientEntityGroup.Length, $"[{typeof(T)}] Entities in the LinkedEntityGroup!"); - var rootEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[0].Value); - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, rootEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on root entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, rootEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on root entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); - } - - var childEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); - if (forceChildReplication ?? expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on child entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on child entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); - } + var rootEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[0].Value); + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, rootEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on root entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, rootEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on root entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); } - ValidateChangeMaskForComponent(forceChildReplication ?? expectValueReplicated|expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false), false); + var childEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); + if (forceChildReplication ?? expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on child entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component on child entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); + } } + + ValidateChangeMaskForComponent(forceChildReplication ?? expectValueReplicated|expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false), false); } private void VerifyLinkedComponentEnabledOnChild(bool expectValueReplicated, bool expectEnabledReplicated) where T : unmanaged, IComponentData, IEnableableComponent { var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Client has entity with TopLevelGhostEntity."); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - Assert.AreEqual(m_ServerEntities.Length, clientEntities.Length, $"[{typeof(T)}] Client has entity with TopLevelGhostEntity."); + var clientEntity = clientEntities[i]; - for (int i = 0; i < clientEntities.Length; i++) - { - var clientEntity = clientEntities[i]; + Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), $"[{typeof(T)}] Client has entities with the LinkedEntityGroup."); - Assert.IsTrue(m_TestWorld.ClientWorlds[0].EntityManager.HasComponent(clientEntity), $"[{typeof(T)}] Client has entities with the LinkedEntityGroup."); + var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + Assert.AreEqual(2, clientEntityGroup.Length, $"[{typeof(T)}] Entities in the LinkedEntityGroup!"); - var clientEntityGroup = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); - Assert.AreEqual(2, clientEntityGroup.Length, $"[{typeof(T)}] Entities in the LinkedEntityGroup!"); + // This method is exclusively to test behaviour of children. - // This method is exclusively to test behaviour of children. - - var childEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component ONLY on child entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component ONLY on child entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); - } + var childEntityEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntityGroup[1].Value); + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, false)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component ONLY on child entity [{i}] is replicated when using `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, childEntityEnabled, $"[{typeof(T)}] Expected that the enable-bit on component ONLY on child entity [{i}] is NOT replicated by default when using `{m_SendForChildrenTestCase}`!"); } } @@ -578,41 +561,38 @@ private void VerifyLinkedComponentEnabledOnChild(bool expectValueReplicated, var builder = new EntityQueryBuilder(Allocator.Temp) .WithAll().WithOptions(EntityQueryOptions.IgnoreComponentEnabledState); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(builder); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(builder); + using var clientEntitiesWithoutFiltering = query.ToEntityArray(Allocator.Temp); + Assert.AreEqual(m_ServerEntities.Length, clientEntitiesWithoutFiltering.Length, $"[{typeof(T)}] Expect client has entities!"); - using (var clientEntitiesWithoutFiltering = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntitiesWithoutFiltering.Length; i++) { - Assert.AreEqual(m_ServerEntities.Length, clientEntitiesWithoutFiltering.Length, $"[{typeof(T)}] Expect client has entities!"); + var serverEntity = m_ServerEntities[i]; + var clientEntity = clientEntitiesWithoutFiltering[i]; - for (int i = 0; i < clientEntitiesWithoutFiltering.Length; i++) - { - var serverEntity = m_ServerEntities[i]; - var clientEntity = clientEntitiesWithoutFiltering[i]; + var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); + var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); + var serverValue = m_TestWorld.ServerWorld.EntityManager.GetComponentData(serverEntity).GetValue(); + var clientValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntity).GetValue(); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] Test expects server enable bit [{i}] to still be same!"); + Assert.AreEqual(m_ExpectedValueIfReplicated, serverValue, $"[{typeof(T)}] Test expects server value [{i}] to still be same!"); - var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); - var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); - var serverValue = m_TestWorld.ServerWorld.EntityManager.GetComponentData(serverEntity).GetValue(); - var clientValue = m_TestWorld.ClientWorlds[0].EntityManager.GetComponentData(clientEntity).GetValue(); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] Test expects server enable bit [{i}] to still be same!"); - Assert.AreEqual(m_ExpectedValueIfReplicated, serverValue, $"[{typeof(T)}] Test expects server value [{i}] to still be same!"); - - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"[{typeof(T)}] Test expects client enable bit [{i}] IS replicated when using `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"[{typeof(T)}] Test expects client enable bit [{i}] NOT replicated when using `{m_SendForChildrenTestCase}`!"); - } - if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - // Note that values are replicated even if the component is disabled! - Assert.AreEqual(m_ExpectedValueIfReplicated, clientValue, $"[{typeof(T)}] Test expects client value [{i}] IS replicated when using `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue, $"[{typeof(T)}] Test expects client value [{i}] NOT replicated when using `{m_SendForChildrenTestCase}`!"); - } + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"[{typeof(T)}] Test expects client enable bit [{i}] IS replicated when using `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"[{typeof(T)}] Test expects client enable bit [{i}] NOT replicated when using `{m_SendForChildrenTestCase}`!"); + } + if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + // Note that values are replicated even if the component is disabled! + Assert.AreEqual(m_ExpectedValueIfReplicated, clientValue, $"[{typeof(T)}] Test expects client value [{i}] IS replicated when using `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue, $"[{typeof(T)}] Test expects client value [{i}] NOT replicated when using `{m_SendForChildrenTestCase}`!"); } } } @@ -640,7 +620,7 @@ private void ValidateChangeMask(bool isExpectedToBeReplicated, ComponentType com componentTypeSet.Add(componentType); var builder = new EntityQueryBuilder(Allocator.Temp).WithAll(ref componentTypeSet).WithOptions(EntityQueryOptions.IgnoreComponentEnabledState); var clientEm = m_TestWorld.ClientWorlds[0].EntityManager; - var query = clientEm.CreateEntityQuery(builder); + using var query = clientEm.CreateEntityQuery(builder); var chunks = query.ToArchetypeChunkArray(Allocator.Temp); for (var chunkIdx = 0; chunkIdx < chunks.Length; chunkIdx++) { @@ -659,36 +639,32 @@ private void ValidateChangeMask(bool isExpectedToBeReplicated, ComponentType com else Assert.IsFalse(didChangeSinceLastVerifyCall, $"[{componentType}] [Chunk:{chunkIdx}] We did not modify this component (nor it's enabled flag), so it SHOULDN'T be changed! {componentChangeVersionInChunk} vs {m_LastGlobalSystemVersion}. Implies a bug in GhostUpdateSystem Change Filtering."); } - query.Dispose(); } private void VerifyFlagComponentEnabledBit(bool expectValueReplicated, bool expectEnabledReplicated) where T : unmanaged, IComponentData, IEnableableComponent { var type = ComponentType.ReadOnly(); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(type); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + var clientEntitiesWithoutFilteringLength = query.CalculateEntityCountWithoutFiltering(); + Assert.AreEqual(m_ServerEntities.Length, clientEntitiesWithoutFilteringLength, $"[{typeof(T)}] Expect client has entities!"); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - var clientEntitiesWithoutFilteringLength = query.CalculateEntityCountWithoutFiltering(); - Assert.AreEqual(m_ServerEntities.Length, clientEntitiesWithoutFilteringLength, $"[{typeof(T)}] Expect client has entities!"); + var serverEntity = m_ServerEntities[i]; + var clientEntity = clientEntities[i]; - for (int i = 0; i < clientEntities.Length; i++) - { - var serverEntity = m_ServerEntities[i]; - var clientEntity = clientEntities[i]; - - var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); - var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] Expect flag component server enabled bit is correct."); + var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); + var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] Expect flag component server enabled bit is correct."); - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"{typeof(T)} Expected client enabled bit IS replicated."); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"{typeof(T)} Expected client enabled bit is NOT replicated."); - } + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"{typeof(T)} Expected client enabled bit IS replicated."); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"{typeof(T)} Expected client enabled bit is NOT replicated."); } } @@ -700,59 +676,56 @@ private void ValidateChangeMask(bool isExpectedToBeReplicated, ComponentType com private void VerifyBufferValues(bool expectValueReplicated, bool expectEnabledReplicated) where T: unmanaged, IBufferElementData, IEnableableComponent, IComponentValue { var builder = new EntityQueryBuilder(Allocator.Temp).WithAll().WithOptions(EntityQueryOptions.IgnoreComponentEnabledState); - var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(builder); + using var query = m_TestWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(builder); + using var clientEntities = query.ToEntityArray(Allocator.Temp); + var totalEntities = query.CalculateEntityCountWithoutFiltering(); + Assert.AreEqual(totalEntities, clientEntities.Length, $"[{typeof(T)}] Client entity count should ALWAYS be correct, regardless of setting: `{m_SendForChildrenTestCase}`!"); - using (var clientEntities = query.ToEntityArray(Allocator.TempJob)) + for (int i = 0; i < clientEntities.Length; i++) { - var totalEntities = query.CalculateEntityCountWithoutFiltering(); - Assert.AreEqual(totalEntities, clientEntities.Length, $"[{typeof(T)}] Client entity count should ALWAYS be correct, regardless of setting: `{m_SendForChildrenTestCase}`!"); + var serverEntity = m_ServerEntities[i]; + var clientEntity = clientEntities[i]; + + var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); + var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); + var serverBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntity, true); + var clientBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + + Assert.AreEqual(m_ExpectedServerBufferSize, serverBuffer.Length, $"[{typeof(T)}] server buffer length"); + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] server enable bit"); - for (int i = 0; i < clientEntities.Length; i++) + if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"[{typeof(T)}] Client enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else + { + Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"[{typeof(T)}] Client enable bit is NOT replicated when `{m_SendForChildrenTestCase}`!"); + } + if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) + { + Assert.AreEqual(m_ExpectedServerBufferSize, clientBuffer.Length, $"[{typeof(T)}] Expect client buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); + } + else { - var serverEntity = m_ServerEntities[i]; - var clientEntity = clientEntities[i]; + Assert.AreEqual(kBakedBufferSize, clientBuffer.Length, $"[{typeof(T)}] Expect client buffer length should NOT be replicated when `{m_SendForChildrenTestCase}`, thus should be the default CLIENT value"); + } - var isServerEnabled = m_TestWorld.ServerWorld.EntityManager.IsComponentEnabled(serverEntity); - var isClientEnabled = m_TestWorld.ClientWorlds[0].EntityManager.IsComponentEnabled(clientEntity); - var serverBuffer = m_TestWorld.ServerWorld.EntityManager.GetBuffer(serverEntity, true); - var clientBuffer = m_TestWorld.ClientWorlds[0].EntityManager.GetBuffer(clientEntity, true); + for (int j = 0; j < serverBuffer.Length; ++j) + { + var serverValue = serverBuffer[j]; + var clientValue = clientBuffer[j]; - Assert.AreEqual(m_ExpectedServerBufferSize, serverBuffer.Length, $"[{typeof(T)}] server buffer length"); - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isServerEnabled, $"[{typeof(T)}] server enable bit"); + var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); + Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect server buffer value [{i}]"); - if (expectEnabledReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(m_ExpectedEnabledIfReplicated, isClientEnabled, $"[{typeof(T)}] Client enable bit IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(m_ExpectedEnabledIfNotReplicated, isClientEnabled, $"[{typeof(T)}] Client enable bit is NOT replicated when `{m_SendForChildrenTestCase}`!"); - } if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) { - Assert.AreEqual(m_ExpectedServerBufferSize, clientBuffer.Length, $"[{typeof(T)}] Expect client buffer length IS replicated when `{m_SendForChildrenTestCase}`!"); + Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client buffer value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); } else { - Assert.AreEqual(kBakedBufferSize, clientBuffer.Length, $"[{typeof(T)}] Expect client buffer length should NOT be replicated when `{m_SendForChildrenTestCase}`, thus should be the default CLIENT value"); - } - - for (int j = 0; j < serverBuffer.Length; ++j) - { - var serverValue = serverBuffer[j]; - var clientValue = clientBuffer[j]; - - var expectedBufferValue = m_IsValidatingBakedValues ? kDefaultValueIfNotReplicated : ((j + 1) * 1000 + m_ExpectedValueIfReplicated); - Assert.AreEqual(expectedBufferValue, serverValue.GetValue(), $"[{typeof(T)}] Expect server buffer value [{i}]"); - - if (expectValueReplicated && IsExpectedToBeReplicated(m_SendForChildrenTestCase, true)) - { - Assert.AreEqual(expectedBufferValue, clientValue.GetValue(), $"[{typeof(T)}] Expect client buffer value [{i}] IS replicated when `{m_SendForChildrenTestCase}`!"); - } - else - { - Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] Expect client buffer value [{i}] is NOT replicated when `{m_SendForChildrenTestCase}`!"); - } + Assert.AreEqual(kDefaultValueIfNotReplicated, clientValue.GetValue(), $"[{typeof(T)}] Expect client buffer value [{i}] is NOT replicated when `{m_SendForChildrenTestCase}`!"); } } } diff --git a/Tests/Editor/GhostTypeTests.cs b/Tests/Editor/GhostTypeTests.cs index f0b92a1..d614c50 100644 --- a/Tests/Editor/GhostTypeTests.cs +++ b/Tests/Editor/GhostTypeTests.cs @@ -30,18 +30,16 @@ public class GhostTypeTests void VerifyGhostTypes(World w) { var type = ComponentType.ReadOnly(); - var query = w.EntityManager.CreateEntityQuery(type); + using var query = w.EntityManager.CreateEntityQuery(type); var count = new NativeArray(2, Allocator.Temp); - using (var ghosts = query.ToEntityArray(Allocator.TempJob)) + var ghosts = query.ToEntityArray(Allocator.Temp); + for (int i = 0; i < ghosts.Length; ++i) { - for (int i = 0; i < ghosts.Length; ++i) - { - var typeIndex = w.EntityManager.GetComponentData(ghosts[i]); - count[typeIndex.Value] = count[typeIndex.Value] + 1; - } - Assert.AreEqual(2, count[0]); - Assert.AreEqual(2, count[1]); + var typeIndex = w.EntityManager.GetComponentData(ghosts[i]); + count[typeIndex.Value] = count[typeIndex.Value] + 1; } + Assert.AreEqual(2, count[0]); + Assert.AreEqual(2, count[1]); } [Test] public void GhostsWithSameArchetypeAreDifferent() diff --git a/Tests/Editor/InputComponentDataTest.cs b/Tests/Editor/InputComponentDataTest.cs index a7d4df8..ae0ed81 100644 --- a/Tests/Editor/InputComponentDataTest.cs +++ b/Tests/Editor/InputComponentDataTest.cs @@ -298,8 +298,7 @@ public void InputComponentData_InputBufferIsRemotePredictedWhenAppropriate() Assert.IsTrue(testWorld.Connect(m_DeltaTime, 64)); testWorld.GoInGame(); - using var serverConnectionQuery = - testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var serverConnectionQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var serverConnectionEntities = serverConnectionQuery.ToEntityArray(Allocator.Temp); Assert.AreEqual(2, serverConnectionEntities.Length); var serverConnectionEntToClient1 = serverConnectionEntities[0]; @@ -315,8 +314,8 @@ public void InputComponentData_InputBufferIsRemotePredictedWhenAppropriate() testWorld.ServerWorld.EntityManager.SetComponentData(serverEntPlayer2, new GhostOwner {NetworkId = netId2}); // Wait for client spawn - EntityQuery clientQuery1 = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - EntityQuery clientQuery2 = testWorld.ClientWorlds[1].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using EntityQuery clientQuery1 = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using EntityQuery clientQuery2 = testWorld.ClientWorlds[1].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); for (int i = 0; i < 16; ++i) { if (clientQuery1.CalculateEntityCount() == 2 && clientQuery2.CalculateEntityCount() == 2) break; @@ -602,8 +601,8 @@ public void InputComponentData_BufferCopiesGhostComponentConfigFromInputComponen void CheckComponent(World w, ComponentType testType, int expectedCount) { - var query = w.EntityManager.CreateEntityQuery(testType); - using (var ghosts = query.ToEntityArray(Allocator.TempJob)) + using var query = w.EntityManager.CreateEntityQuery(testType); + using (var ghosts = query.ToEntityArray(Allocator.Temp)) { var compCount = ghosts.Length; Assert.AreEqual(expectedCount, compCount); diff --git a/Tests/Editor/LateJoinCompletionTests.cs b/Tests/Editor/LateJoinCompletionTests.cs index d66038f..b7d92be 100644 --- a/Tests/Editor/LateJoinCompletionTests.cs +++ b/Tests/Editor/LateJoinCompletionTests.cs @@ -88,7 +88,7 @@ public void ServerGhostCountOnlyIncludesRelevantSet() ghostRelevancy.GhostRelevancyMode = GhostRelevancyMode.SetIsRelevant; var serverConnectionEnt = testWorld.TryGetSingletonEntity(testWorld.ServerWorld); var serverConnectionId = testWorld.ServerWorld.EntityManager.GetComponentData(serverConnectionEnt).Value; - var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); + using var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); var ghosts = query.ToComponentDataArray(Allocator.Temp); Assert.AreEqual(ghosts.Length, 8); for (int i = 0; i < 6; ++i) @@ -143,7 +143,7 @@ public void ServerGhostCountDoesNotIncludeIrrelevantSet() ghostRelevancy.GhostRelevancyMode = GhostRelevancyMode.SetIsIrrelevant; var serverConnectionEnt = testWorld.TryGetSingletonEntity(testWorld.ServerWorld); var serverConnectionId = testWorld.ServerWorld.EntityManager.GetComponentData(serverConnectionEnt).Value; - var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); + using var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadWrite()); var ghosts = query.ToComponentDataArray(Allocator.Temp); Assert.AreEqual(ghosts.Length, 8); for (int i = 0; i < 6; ++i) diff --git a/Tests/Editor/PerPrefabOverridesTests.cs b/Tests/Editor/PerPrefabOverridesTests.cs index 5d61ec4..b3c2f55 100644 --- a/Tests/Editor/PerPrefabOverridesTests.cs +++ b/Tests/Editor/PerPrefabOverridesTests.cs @@ -57,7 +57,8 @@ GameObject[] CreatePrefabs(string[] names) //Check that the component prefab serializer and indexes are initialized as expected void CheckCollection(World world, int serializerIndex, int entityIndex) { - var collection = world.EntityManager.CreateEntityQuery(typeof(GhostCollection)).GetSingletonEntity(); + using var collectionQuery = world.EntityManager.CreateEntityQuery(typeof(GhostCollection)); + var collection = collectionQuery.GetSingletonEntity(); var ghostSerializerCollection = world.EntityManager.GetBuffer(collection); var ghostComponentIndex = world.EntityManager.GetBuffer(collection); Assert.AreEqual(4, ghostSerializerCollection.Length); diff --git a/Tests/Editor/Prespawn/LateJoinOptTests.cs b/Tests/Editor/Prespawn/LateJoinOptTests.cs index 506d457..29aba6b 100644 --- a/Tests/Editor/Prespawn/LateJoinOptTests.cs +++ b/Tests/Editor/Prespawn/LateJoinOptTests.cs @@ -22,7 +22,7 @@ public class LateJoinOptTests : TestWithSceneAsset private static void CheckPrespawnArePresent(int numObjects, NetCodeTestWorld testWorld) { //Before going in game there should N prespawned objects - var serverGhosts = testWorld.ServerWorld.EntityManager.CreateEntityQuery(new EntityQueryDesc + using var serverGhosts = testWorld.ServerWorld.EntityManager.CreateEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly(typeof(PreSpawnedGhostIndex))}, Options = EntityQueryOptions.IncludeDisabledEntities @@ -30,7 +30,7 @@ private static void CheckPrespawnArePresent(int numObjects, NetCodeTestWorld tes Assert.AreEqual(numObjects, serverGhosts.CalculateEntityCount()); for (int i = 0; i < testWorld.ClientWorlds.Length; ++i) { - var clientGhosts = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(new EntityQueryDesc + using var clientGhosts = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(new EntityQueryDesc { All = new [] { ComponentType.ReadOnly(typeof(PreSpawnedGhostIndex))}, Options = EntityQueryOptions.IncludeDisabledEntities @@ -120,9 +120,10 @@ private void CheckBaselineAreCreated(World world) void ValidateReceivedSnapshotData(World clientWorld) { - var query = clientWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly()); + using var query = clientWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly()); + using var collectionQuery = clientWorld.EntityManager.CreateEntityQuery(typeof(GhostCollection)); var entities = query.ToEntityArray(Allocator.Temp); - var ghostCollectionEntity = clientWorld.EntityManager.CreateEntityQuery(typeof(GhostCollection)).GetSingletonEntity(); + var ghostCollectionEntity = collectionQuery.GetSingletonEntity(); var ghostCollection = clientWorld.EntityManager.GetBuffer(ghostCollectionEntity); var ghostComponentIndex = clientWorld.EntityManager.GetBuffer(ghostCollectionEntity); var ghostSerializers = clientWorld.EntityManager.GetBuffer(ghostCollectionEntity); @@ -197,12 +198,12 @@ void ValidateReceivedSnapshotData(World clientWorld) //To Disable the prespawn optimization, just remove the baselines if (!enableFallbackBaseline) { - var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(PrespawnGhostBaseline)); + using var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(PrespawnGhostBaseline)); testWorld.ServerWorld.EntityManager.RemoveComponent(query); for (int i = 0; i < testWorld.ClientWorlds.Length; ++i) { - query = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(typeof(PrespawnGhostBaseline)); - testWorld.ClientWorlds[i].EntityManager.RemoveComponent(query); + using var clientQuery = testWorld.ClientWorlds[i].EntityManager.CreateEntityQuery(typeof(PrespawnGhostBaseline)); + testWorld.ClientWorlds[i].EntityManager.RemoveComponent(clientQuery); } } diff --git a/Tests/Editor/Prespawn/PreSpawnTests.cs b/Tests/Editor/Prespawn/PreSpawnTests.cs index eb659f7..f817e80 100644 --- a/Tests/Editor/Prespawn/PreSpawnTests.cs +++ b/Tests/Editor/Prespawn/PreSpawnTests.cs @@ -37,10 +37,8 @@ protected override void OnCreate() protected override void OnUpdate() { - var ghostComponents = _ghostComponentQuery.ToComponentDataArray(Allocator.TempJob); - var preSpawnedGhostIds = _preSpawnedGhostIdsQuery.ToComponentDataArray(Allocator.TempJob); - using (ghostComponents) - using (preSpawnedGhostIds) + var ghostComponents = _ghostComponentQuery.ToComponentDataArray(Allocator.Temp); + var preSpawnedGhostIds = _preSpawnedGhostIdsQuery.ToComponentDataArray(Allocator.Temp); { Matches = 0; var idList = new List(); @@ -81,6 +79,7 @@ void CheckAllPrefabsInWorlds(NetCodeTestWorld testWorld) void CheckAllPrefabsInWorld(World world) { + //TODO: dispose these Assert.IsFalse(world.EntityManager.CreateEntityQuery(new EntityQueryDesc { All = new [] {ComponentType.ReadOnly()}, @@ -228,18 +227,21 @@ public void DestroyedPreSpawnedObjectsCleanup() testWorld.SetInGame(0); // Delete one prespawned entity on the server var deletedId = 0; + var q = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance), ComponentType.ReadOnly()); + var prespawnedQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance), ComponentType.ReadOnly()); for (int i = 0; i < 16; ++i) { testWorld.Tick(1.0f/60.0f); - var prespawnedGhost = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance), ComponentType.ReadOnly()).ToComponentDataArray(Allocator.TempJob); + var prespawnedGhost = q.ToComponentDataArray(Allocator.Temp); // Filter for GhostComoponent and grab it after prespawn processing is done (ghost id valid) if (prespawnedGhost.Length == 0 || (prespawnedGhost.Length > 0 && prespawnedGhost[0].ghostId == 0)) { prespawnedGhost.Dispose(); continue; } - var prespawned = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance), ComponentType.ReadOnly()).ToEntityArray(Allocator.TempJob); + deletedId = prespawnedGhost[0].ghostId; + var prespawned = prespawnedQuery.ToEntityArray(Allocator.Temp); testWorld.ServerWorld.EntityManager.DestroyEntity(prespawned[0]); prespawned.Dispose(); prespawnedGhost.Dispose(); @@ -306,12 +308,12 @@ public void GhostCleanup() testWorld.GoInGame(); // If servers spawns something before connection is in game it will be registered as a prespawned entity // Wait until prespawned ghosts have been initialized + var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(PreSpawnedGhostIndex), + typeof(GhostInstance)); for (int i = 0; i < 16; ++i) { testWorld.Tick(1.0f/60f); - var prespawns = testWorld.ServerWorld.EntityManager - .CreateEntityQuery(typeof(PreSpawnedGhostIndex), typeof(GhostInstance)) - .CalculateEntityCount(); + var prespawns = query.CalculateEntityCount(); if (prespawns > 0) break; } @@ -321,10 +323,11 @@ public void GhostCleanup() var ghostCount = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance), typeof(PreSpawnedGhostIndex)).CalculateEntityCount(); // Wait until it's spawned on client int currentCount = 0; + var clientQuery = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostInstance), typeof(PreSpawnedGhostIndex)); for (int i = 0; i < 64 && currentCount != ghostCount; ++i) { testWorld.Tick(1.0f/60f); - currentCount = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostInstance), typeof(PreSpawnedGhostIndex)).CalculateEntityCount(); + currentCount = clientQuery.CalculateEntityCount(); } Assert.That(ghostCount == currentCount, "Client did not spawn runtime entity (clientCount=" + currentCount + " serverCount=" + ghostCount + ")"); @@ -344,14 +347,14 @@ public void GhostCleanup() int clientGhostCount = 0; int expectedServerGhostCount = VerifyGhostIds.GhostsPerScene + 2; //Also the ghost list int expectedClientGhostCount = VerifyGhostIds.GhostsPerScene; //only the prespawn should remain + var serverGhosts = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance)); + var clientGhosts = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostInstance)); for (int i = 0; i < 16; ++i) { testWorld.Tick(1.0f/60f); // clientGhostCount will be 6 for a bit as it creates an initial archetype ghost and later a delayed one when on the right tick - serverGhostCount = testWorld.ServerWorld.EntityManager.CreateEntityQuery(typeof(GhostInstance)) - .CalculateEntityCount(); - clientGhostCount = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(typeof(GhostInstance)) - .CalculateEntityCount(); + serverGhostCount = serverGhosts.CalculateEntityCount(); + clientGhostCount = clientGhosts.CalculateEntityCount(); //Debug.Log("serverCount=" + serverGhostCount + " clientCount=" + clientGhostCount); //DumpGhosts(serverWorld, clientWorld); if (serverGhostCount == expectedServerGhostCount && clientGhostCount == 0) diff --git a/Tests/Editor/RelevancyTests.cs b/Tests/Editor/RelevancyTests.cs index 2c23d4c..0d68a4c 100644 --- a/Tests/Editor/RelevancyTests.cs +++ b/Tests/Editor/RelevancyTests.cs @@ -274,7 +274,7 @@ public void MarkedIrrelevantAtSpawnIsNeverSeen() var serverEnt = spawnAndSetId(testWorld, ghostGameObject, 1); testWorld.ServerWorld.GetExistingSystemManaged().IrrelevantGhosts.Add(1); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); for (int i = 0; i < 16; ++i) { var clientValues = query.ToComponentDataArray(Allocator.Temp); @@ -309,7 +309,7 @@ public void MarkedIrrelevantIsDespawned() for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var clientValues = query.ToComponentDataArray(Allocator.Temp); Assert.AreEqual(129, clientValues.Length); bool foundOne = false; @@ -368,7 +368,7 @@ public void MarkIrrelevantAtRuntimeReachTheClient(int ghostsPerFrame) for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var checkHashSet = new HashSet(); var clientValues = query.ToComponentDataArray(Allocator.Temp); @@ -414,7 +414,7 @@ public void MarkRelevantAtRuntimeReachTheClient(int ghostsPerFrame) for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var checkHashSet = new HashSet(); var clientValues = query.ToComponentDataArray(Allocator.Temp); @@ -463,7 +463,7 @@ public void ChangeRelevantSetAtRuntimeReachTheClient(int ghostsPerFrame) for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var checkHashSet = new HashSet(); var clientValues = query.ToComponentDataArray(Allocator.Temp); @@ -511,7 +511,7 @@ public void ToggleEveryFrameDoesNotRepetedlySpawn() for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var clientValues = query.ToComponentDataArray(Allocator.Temp); // Check that the ghost does not exist Assert.AreEqual(128, clientValues.Length); diff --git a/Tests/Editor/RpcTestSystems.cs b/Tests/Editor/RpcTestSystems.cs index 6468841..d32c38b 100644 --- a/Tests/Editor/RpcTestSystems.cs +++ b/Tests/Editor/RpcTestSystems.cs @@ -276,9 +276,7 @@ protected override void OnCreate() //Even if we would tag the connection synchronously (in the middle of the frame) //if the client system is schedule to execute AFTER the RpcCommandRequestSystem (or the RpcSystem) or the system that //change the connection state, clients can still queue commands even though the connection will be closed. - var query = EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - RequireForUpdate(query); - + RequireForUpdate(); worldId = NetCodeTestWorld.CalculateWorldId(World); } diff --git a/Tests/Editor/RpcTests.cs b/Tests/Editor/RpcTests.cs index 8f275ff..51c65ed 100644 --- a/Tests/Editor/RpcTests.cs +++ b/Tests/Editor/RpcTests.cs @@ -273,7 +273,7 @@ void SendRpc(World world, Entity entity) RpcWithEntity RecvRpc(World world) { - var query = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var query = world.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.AreEqual(1, query.CalculateEntityCount()); var rpcReceived = query.GetSingleton(); world.EntityManager.DestroyEntity(query); diff --git a/Tests/Editor/SendToOwnerTests.cs b/Tests/Editor/SendToOwnerTests.cs index 53aba23..d11fe78 100644 --- a/Tests/Editor/SendToOwnerTests.cs +++ b/Tests/Editor/SendToOwnerTests.cs @@ -24,7 +24,8 @@ public void Bake(GameObject gameObject, IBaker baker) void ChangeSendToOwnerOption(World world) { - var entity = world.EntityManager.CreateEntityQuery(typeof(GhostCollection)).GetSingletonEntity(); + using var query = world.EntityManager.CreateEntityQuery(typeof(GhostCollection)); + var entity = query.GetSingletonEntity(); var collection = world.EntityManager.GetBuffer(entity); for (int i = 0; i < collection.Length; ++i) { @@ -85,9 +86,9 @@ public void SendToOwner_Clients_ReceiveTheCorrectData(GhostModeMask modeMask, Gh //Here I do a trick: I will wait until the CollectionSystem is run and the component collection built. //Then I will change the serializer flags a little to make them behave the way I want. //This is a temporary hack, can be remove whe override per prefab will be available. - var queryServer = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - var queryClient0 = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - var queryClient1 = testWorld.ClientWorlds[1].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var queryServer = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var queryClient0 = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var queryClient1 = testWorld.ClientWorlds[1].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); while (true) { testWorld.Tick(1.0f/60f); diff --git a/Tests/Editor/StaticOptimizationTests.cs b/Tests/Editor/StaticOptimizationTests.cs index 476e8a4..1725ce5 100644 --- a/Tests/Editor/StaticOptimizationTests.cs +++ b/Tests/Editor/StaticOptimizationTests.cs @@ -78,33 +78,31 @@ public void StaticGhostsAreNotSent() SetupBasicTest(testWorld, 16); var clientEntityManager = testWorld.ClientWorlds[0].EntityManager; - var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - using (var clientEntities = clientQuery.ToEntityArray(Allocator.TempJob)) - { - Assert.AreEqual(16, clientEntities.Length); + using var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + var clientEntities = clientQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(16, clientEntities.Length); - var lastSnapshot = new NativeArray(clientEntities.Length, Allocator.Temp); - for (int i = 0; i < clientEntities.Length; ++i) - { - var clientEnt = clientEntities[i]; - // Store the last tick we got for this - var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); - var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); - lastSnapshot[i] = clientSnapshot.GetLatestTick(clientSnapshotBuffer); - } + var lastSnapshot = new NativeArray(clientEntities.Length, Allocator.Temp); + for (int i = 0; i < clientEntities.Length; ++i) + { + var clientEnt = clientEntities[i]; + // Store the last tick we got for this + var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); + var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); + lastSnapshot[i] = clientSnapshot.GetLatestTick(clientSnapshotBuffer); + } - // Run a bit longer - for (int i = 0; i < 16; ++i) - testWorld.Tick(frameTime); - // Verify that we did not get any new snapshot - for (int i = 0; i < clientEntities.Length; ++i) - { - var clientEnt = clientEntities[i]; - // Store the last tick we got for this - var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); - var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); - Assert.AreEqual(lastSnapshot[i], clientSnapshot.GetLatestTick(clientSnapshotBuffer)); - } + // Run a bit longer + for (int i = 0; i < 16; ++i) + testWorld.Tick(frameTime); + // Verify that we did not get any new snapshot + for (int i = 0; i < clientEntities.Length; ++i) + { + var clientEnt = clientEntities[i]; + // Store the last tick we got for this + var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); + var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); + Assert.AreEqual(lastSnapshot[i], clientSnapshot.GetLatestTick(clientSnapshotBuffer)); } } } @@ -120,33 +118,31 @@ public void GhostsCanBeStaticWhenChunksAreDirty() SetupBasicTest(testWorld, 16); var clientEntityManager = testWorld.ClientWorlds[0].EntityManager; - var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - using (var clientEntities = clientQuery.ToEntityArray(Allocator.TempJob)) - { - Assert.AreEqual(16, clientEntities.Length); + using var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + var clientEntities = clientQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(16, clientEntities.Length); - var lastSnapshot = new NativeArray(clientEntities.Length, Allocator.Temp); - for (int i = 0; i < clientEntities.Length; ++i) - { - var clientEnt = clientEntities[i]; - // Store the last tick we got for this - var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); - var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); - lastSnapshot[i] = clientSnapshot.GetLatestTick(clientSnapshotBuffer); - } + var lastSnapshot = new NativeArray(clientEntities.Length, Allocator.Temp); + for (int i = 0; i < clientEntities.Length; ++i) + { + var clientEnt = clientEntities[i]; + // Store the last tick we got for this + var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); + var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); + lastSnapshot[i] = clientSnapshot.GetLatestTick(clientSnapshotBuffer); + } - // Run a bit longer - for (int i = 0; i < 16; ++i) - testWorld.Tick(frameTime); - // Verify that we did not get any new snapshot - for (int i = 0; i < clientEntities.Length; ++i) - { - var clientEnt = clientEntities[i]; - // Store the last tick we got for this - var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); - var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); - Assert.AreEqual(lastSnapshot[i], clientSnapshot.GetLatestTick(clientSnapshotBuffer)); - } + // Run a bit longer + for (int i = 0; i < 16; ++i) + testWorld.Tick(frameTime); + // Verify that we did not get any new snapshot + for (int i = 0; i < clientEntities.Length; ++i) + { + var clientEnt = clientEntities[i]; + // Store the last tick we got for this + var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); + var clientSnapshot = clientEntityManager.GetComponentData(clientEnt); + Assert.AreEqual(lastSnapshot[i], clientSnapshot.GetLatestTick(clientSnapshotBuffer)); } } } @@ -236,33 +232,29 @@ public void DynamicGhostsInSameChunkAsStaticAreSent() // Spawn 16 ghosts SetupBasicTest(testWorld, 16); // Set the ghost id for one of them to 1 so it is modified - var serverQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); - using (var serverEntities = serverQuery.ToEntityArray(Allocator.TempJob)) - { - Assert.AreEqual(16, serverEntities.Length); - testWorld.ServerWorld.EntityManager.SetComponentData(serverEntities[0], new GhostOwner{NetworkId = 1}); - } + using var serverQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + var serverEntities = serverQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(16, serverEntities.Length); + testWorld.ServerWorld.EntityManager.SetComponentData(serverEntities[0], new GhostOwner{NetworkId = 1}); // Get the changes across to the client for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); var clientEntityManager = testWorld.ClientWorlds[0].EntityManager; - var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Entity clientEnt = Entity.Null; - using (var clientEntities = clientQuery.ToEntityArray(Allocator.TempJob)) + var clientEntities = clientQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(16, clientEntities.Length); + for (int i = 0; i < clientEntities.Length; ++i) { - Assert.AreEqual(16, clientEntities.Length); - for (int i = 0; i < clientEntities.Length; ++i) + if (clientEntityManager.GetComponentData(clientEntities[i] ).NetworkId == 1) { - if (clientEntityManager.GetComponentData(clientEntities[i] ).NetworkId == 1) - { - Assert.AreEqual(Entity.Null, clientEnt); - clientEnt = clientEntities[i]; - } + Assert.AreEqual(Entity.Null, clientEnt); + clientEnt = clientEntities[i]; } - Assert.AreNotEqual(Entity.Null, clientEnt); } + Assert.AreNotEqual(Entity.Null, clientEnt); // Store the last tick we got for this var clientSnapshotBuffer = clientEntityManager.GetBuffer(clientEnt); @@ -288,13 +280,11 @@ public void RelevancyChangesSendsStaticGhosts() // Spawn 16 ghosts SetupBasicTest(testWorld, 16); // Set the ghost id for one of them to 1 so it is modified - var serverQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var serverQuery = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); int ghostId; - using (var serverEntities = serverQuery.ToEntityArray(Allocator.TempJob)) - { - Assert.AreEqual(16, serverEntities.Length); - ghostId = testWorld.ServerWorld.EntityManager.GetComponentData(serverEntities[0]).ghostId; - } + var serverEntities = serverQuery.ToEntityArray(Allocator.Temp); + Assert.AreEqual(16, serverEntities.Length); + ghostId = testWorld.ServerWorld.EntityManager.GetComponentData(serverEntities[0]).ghostId; var con = testWorld.TryGetSingletonEntity(testWorld.ServerWorld); Assert.AreNotEqual(Entity.Null, con); var connectionId = testWorld.ServerWorld.EntityManager.GetComponentData(con).Value; @@ -304,7 +294,7 @@ public void RelevancyChangesSendsStaticGhosts() testWorld.Tick(frameTime); var clientEntityManager = testWorld.ClientWorlds[0].EntityManager; - var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + using var clientQuery = clientEntityManager.CreateEntityQuery(ComponentType.ReadOnly()); var clientEntities = clientQuery.ToComponentDataArray(Allocator.Temp); Assert.AreEqual(16, clientEntities.Length); diff --git a/Tests/Editor/SubSceneLoadingTests.cs b/Tests/Editor/SubSceneLoadingTests.cs index c319b12..4365d42 100644 --- a/Tests/Editor/SubSceneLoadingTests.cs +++ b/Tests/Editor/SubSceneLoadingTests.cs @@ -50,7 +50,7 @@ public partial class UpdatePrespawnGhostTransform : SystemBase { protected override void OnCreate() { - RequireForUpdate(EntityManager.CreateEntityQuery(ComponentType.ReadOnly())); + RequireForUpdate(); } protected override void OnUpdate() @@ -102,8 +102,7 @@ public void SubSceneListIsSentToClient() float frameTime = 1.0f / 60.0f; Assert.IsTrue(testWorld.Connect(frameTime, 4)); testWorld.GoInGame(); - var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType - .ReadOnly()); + var query = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.IsTrue(query.IsEmptyIgnoreFilter); //First tick // - the Populate prespawn should run and add the ghosts to the mapping on the server. @@ -144,7 +143,6 @@ public void SubSceneListIsSentToClient() //Check that they are identically mapped. foreach (var kv in sendGhostMap.Value) { - var ghost = kv.Key; if (PrespawnHelper.IsRuntimeSpawnedGhost(ghost.ghostId)) continue; @@ -215,20 +213,18 @@ public void ClientLoadSceneWhileInGame() testWorld.Tick(frameTime); } - var q = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery( - ComponentType.ReadOnly()); - Assert.IsFalse(q.IsEmptyIgnoreFilter); - Assert.AreEqual(5, q.CalculateEntityCount()); + var someDataQuery = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); + Assert.IsFalse(someDataQuery.IsEmptyIgnoreFilter); + Assert.AreEqual(5, someDataQuery.CalculateEntityCount()); //Modify some data on the server - q = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType - .ReadOnly()); - var subsceneList = q.ToComponentDataArray(Allocator.Temp); + var subsceneList = testWorld.ServerWorld.EntityManager.CreateEntityQuery(ComponentType.ReadOnly()) + .ToComponentDataArray(Allocator.Temp); + var q = testWorld.ServerWorld.EntityManager.CreateEntityQuery( + ComponentType.ReadOnly(), + ComponentType.ReadWrite(), ComponentType.ReadOnly()); for (int i = 0; i < subsceneList.Length; ++i) { - q = testWorld.ServerWorld.EntityManager.CreateEntityQuery( - ComponentType.ReadOnly(), - ComponentType.ReadWrite(), ComponentType.ReadOnly()); q.SetSharedComponentFilter(new SubSceneGhostComponentHash { Value = subsceneList[i].SubSceneHash @@ -248,16 +244,15 @@ public void ClientLoadSceneWhileInGame() testWorld.Tick(frameTime); } - q = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery( - ComponentType.ReadOnly()); + q = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery(ComponentType.ReadOnly()); Assert.AreEqual(10, q.CalculateEntityCount()); //Check everything is in sync + q = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery( + ComponentType.ReadOnly(), + ComponentType.ReadWrite(), ComponentType.ReadOnly()); for (int i = 0; i < subsceneList.Length; ++i) { - q = testWorld.ClientWorlds[0].EntityManager.CreateEntityQuery( - ComponentType.ReadOnly(), - ComponentType.ReadWrite(), ComponentType.ReadOnly()); q.SetSharedComponentFilter(new SubSceneGhostComponentHash { Value = subsceneList[i].SubSceneHash @@ -268,7 +263,6 @@ public void ClientLoadSceneWhileInGame() { Assert.AreEqual(100 + 100 * i + d, data[d].Value); } - data.Dispose(); } } @@ -337,11 +331,11 @@ public void ServerAndClientsLoadSceneInGame() for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - + //Check everything is in sync { - //Check everything is in sync var q = testWorld.ServerWorld.EntityManager.CreateEntityQuery( - ComponentType.ReadOnly(), ComponentType.ReadWrite()); + ComponentType.ReadOnly(), + ComponentType.ReadWrite()); var data = q.ToComponentDataArray(Allocator.Temp); for (int i = 0; i < numObjects; ++i) { @@ -360,11 +354,11 @@ public void ServerInitiatedSceneUnload() //Get all the ids and collect the ranges from the ghost components. They are going to be used later //for checking ids re-use var ranges = new Dictionary(); + using var q = world.EntityManager.CreateEntityQuery( + ComponentType.ReadOnly(), + ComponentType.ReadOnly()); for (int i = 0; i < subSceneList.Length; ++i) { - var q = world.EntityManager.CreateEntityQuery( - ComponentType.ReadOnly(), - ComponentType.ReadOnly()); q.SetSharedComponentFilter(new SubSceneGhostComponentHash { Value = subSceneList[i].SubSceneHash @@ -512,7 +506,7 @@ public void ClientLoadUnloadScene() for (int i = 0; i < 16; ++i) testWorld.Tick(frameTime); - using var translations = query.ToComponentDataArray(Allocator.TempJob); + var translations = query.ToComponentDataArray(Allocator.Temp); for (int i = 0; i < translations.Length; ++i) Assert.AreNotEqual(0.0f, translations[i]); diff --git a/Tests/Editor/TestEnterExitGame.cs b/Tests/Editor/TestEnterExitGame.cs index 7f8deef..d34dcb8 100644 --- a/Tests/Editor/TestEnterExitGame.cs +++ b/Tests/Editor/TestEnterExitGame.cs @@ -15,7 +15,7 @@ public class TestEnterExitGame : TestWithSceneAsset { private void UnloadSubScene(World world) { - var subScene = Object.FindObjectOfType(); + var subScene = Object.FindFirstObjectByType(); SceneSystem.UnloadScene(world.Unmanaged, subScene.SceneGUID, SceneSystem.UnloadParameters.DestroyMetaEntities); } diff --git a/Tests/Utils/NetCodeScenarioUtils.cs b/Tests/Utils/NetCodeScenarioUtils.cs index 3e9a28b..5165bbb 100644 --- a/Tests/Utils/NetCodeScenarioUtils.cs +++ b/Tests/Utils/NetCodeScenarioUtils.cs @@ -82,8 +82,7 @@ public static void ExecuteScenario(ScenarioDesc scenario, ScenarioParams paramet // instantiate var type = ComponentType.ReadOnly(); - var query = scenarioWorld.ServerWorld.EntityManager.CreateEntityQuery(type); - var connections = query.ToEntityArray(Allocator.TempJob); + var connections = scenarioWorld.ServerWorld.EntityManager.CreateEntityQuery(type).ToEntityArray(Allocator.Temp); Assert.IsTrue(connections.Length == parameters.NumClients); Assert.IsTrue(scenario.GhostPrefabs.Length == parameters.SpawnCount.Length); @@ -128,9 +127,9 @@ public static void ExecuteScenario(ScenarioDesc scenario, ScenarioParams paramet for (int i = 0; i < scenario.GhostComponentForVerification?.Length; i++) { - var q = scenarioWorld.ServerWorld.EntityManager.CreateEntityQuery( + using var query = scenarioWorld.ServerWorld.EntityManager.CreateEntityQuery( scenario.GhostComponentForVerification[i]); - Assert.IsTrue(parameters.SpawnCount[i] == q.CalculateEntityCount()); + Assert.IsTrue(parameters.SpawnCount[i] == query.CalculateEntityCount()); } } } diff --git a/Tests/Utils/NetCodeTestWorld.cs b/Tests/Utils/NetCodeTestWorld.cs index 9c81026..2afb56e 100644 --- a/Tests/Utils/NetCodeTestWorld.cs +++ b/Tests/Utils/NetCodeTestWorld.cs @@ -627,10 +627,13 @@ public void GoInGame(World w = null) } var type = ComponentType.ReadOnly(); - var query = w.EntityManager.CreateEntityQuery(type); - var connections = query.ToEntityArray(Allocator.TempJob); - for (int i = 0; i < connections.Length; ++i) - w.EntityManager.AddComponentData(connections[i], new NetworkStreamInGame()); + using var query = w.EntityManager.CreateEntityQuery(type); + var connections = query.ToEntityArray(Allocator.Temp); + foreach (var connection in connections) + { + w.EntityManager.AddComponentData(connection, new NetworkStreamInGame()); + } + connections.Dispose(); } @@ -639,7 +642,7 @@ public void ExitFromGame() void RemoveTag(World world) { var type = ComponentType.ReadOnly(); - var query = world.EntityManager.CreateEntityQuery(type); + using var query = world.EntityManager.CreateEntityQuery(type); var connections = query.ToEntityArray(Allocator.Temp); for (int i = 0; i < connections.Length; ++i) { @@ -659,13 +662,13 @@ void RemoveTag(World world) public void SetInGame(int client) { var type = ComponentType.ReadOnly(); - var clientQuery = ClientWorlds[client].EntityManager.CreateEntityQuery(type); + using var clientQuery = ClientWorlds[client].EntityManager.CreateEntityQuery(type); var clientEntity = clientQuery.ToEntityArray(Allocator.Temp); ClientWorlds[client].EntityManager.AddComponent(clientEntity[0]); var clientNetId = ClientWorlds[client].EntityManager.GetComponentData(clientEntity[0]); clientEntity.Dispose(); - var query = ServerWorld.EntityManager.CreateEntityQuery(type); + using var query = ServerWorld.EntityManager.CreateEntityQuery(type); var connections = query.ToEntityArray(Allocator.Temp); for (int i = 0; i < connections.Length; ++i) { @@ -683,13 +686,13 @@ public void SetInGame(int client) public void RemoveFromGame(int client) { var type = ComponentType.ReadOnly(); - var clientQuery = ClientWorlds[client].EntityManager.CreateEntityQuery(type); + using var clientQuery = ClientWorlds[client].EntityManager.CreateEntityQuery(type); var clientEntity = clientQuery.ToEntityArray(Allocator.Temp); ClientWorlds[client].EntityManager.RemoveComponent(clientEntity[0]); var clientNetId = ClientWorlds[client].EntityManager.GetComponentData(clientEntity[0]); clientEntity.Dispose(); - var query = ServerWorld.EntityManager.CreateEntityQuery(type); + using var query = ServerWorld.EntityManager.CreateEntityQuery(type); var connections = query.ToEntityArray(Allocator.Temp); for (int i = 0; i < connections.Length; ++i) { @@ -707,44 +710,36 @@ public void RemoveFromGame(int client) public Entity TryGetSingletonEntity(World w) { var type = ComponentType.ReadOnly(); - using (var query = w.EntityManager.CreateEntityQuery(type)) - { - int entCount = query.CalculateEntityCount(); + using var query = w.EntityManager.CreateEntityQuery(type); + int entCount = query.CalculateEntityCount(); #if UNITY_EDITOR - if (entCount >= 2) - Debug.LogError("Trying to get singleton, but there are multiple matching entities"); + if (entCount >= 2) + Debug.LogError("Trying to get singleton, but there are multiple matching entities"); #endif - if (entCount != 1) - return Entity.Null; - return query.GetSingletonEntity(); - } + if (entCount != 1) + return Entity.Null; + return query.GetSingletonEntity(); } public T GetSingleton(World w) where T : unmanaged, IComponentData { var type = ComponentType.ReadOnly(); - using (var query = w.EntityManager.CreateEntityQuery(type)) - { - return query.GetSingleton(); - } + using var query = w.EntityManager.CreateEntityQuery(type); + return query.GetSingleton(); } public RefRW GetSingletonRW(World w) where T : unmanaged, IComponentData { var type = ComponentType.ReadWrite(); - using (var query = w.EntityManager.CreateEntityQuery(type)) - { - return query.GetSingletonRW(); - } + using var query = w.EntityManager.CreateEntityQuery(type); + return query.GetSingletonRW(); } public DynamicBuffer GetSingletonBuffer(World w) where T : unmanaged, IBufferElementData { var type = ComponentType.ReadOnly(); - using (var query = w.EntityManager.CreateEntityQuery(type)) - { - return query.GetSingletonBuffer(); - } + using var query = w.EntityManager.CreateEntityQuery(type); + return query.GetSingletonBuffer(); } #if UNITY_EDITOR @@ -798,16 +793,15 @@ private Entity BakeGameObject(GameObject go, World world, BlobAssetStore blobAss // Copy all the tracked/baked entities. That TransformAuthoring is present on all entities added by the baker for the // converted gameobject. It is sufficient condition to copy all the additional entities as well. - var builder = new EntityQueryBuilder(Allocator.Temp) - .WithAll(); + var builder = new EntityQueryBuilder(Allocator.Temp).WithAll(); using var bakedEntities = intermediateWorld.EntityManager.CreateEntityQuery(builder); world.EntityManager.MoveEntitiesFrom(intermediateWorld.EntityManager, bakedEntities); // Search for the entity in the final world by comparing the EntityGuid from entity in the intermediate world using var query = world.EntityManager.CreateEntityQuery(typeof(EntityGuid), typeof(Prefab)); - using var entityArray = query.ToEntityArray(Allocator.TempJob); - using var entityGUIDs = query.ToComponentDataArray(Allocator.TempJob); + var entityArray = query.ToEntityArray(Allocator.Temp); + var entityGUIDs = query.ToComponentDataArray(Allocator.Temp); for (int index = 0; index < entityGUIDs.Length; ++index) { if (entityGUIDs[index] == intermediateEntityGuid) diff --git a/Tests/Utils/SubSceneHelper.cs b/Tests/Utils/SubSceneHelper.cs index 9ac9556..666d0a4 100644 --- a/Tests/Utils/SubSceneHelper.cs +++ b/Tests/Utils/SubSceneHelper.cs @@ -183,7 +183,7 @@ static public GameObject CreatePrefab(string path, GameObject go) static public void LoadSubScene(World world, params SubScene[] subScenes) { if(subScenes.Length == 0) - subScenes = Object.FindObjectsOfType(); + subScenes = Object.FindObjectsByType(FindObjectsSortMode.None); var sceneEntities = new Entity[subScenes.Length]; for(int i=0;i Dump Packet Logs` now works more reliably, now works with NUnit tests, and dump files are named with more context.\n* Fixed bug in `GhostSendSystem` that caused it to not replicate ghosts when enabling packet dumps. `GhostValuesAreSerialized_WithPacketDumpsEnabled` test added." + "changelog": "### Changed\n\n* Updated com.unity.entities dependency to 1.0.14\n* Use of non required TempJob allocation and use Allocator.Temp instead.\n\n### Fixed\n\n* Runtime EntityQuery leaks and reduce runtime memory pressure due to continuously allocating queries without disposing.\n* Reduced memory usage in Editor tests, by avoiding allocating queries continuously in hot paths." }, "upmCi": { - "footprint": "cf5420ec6d17a2c7db7e73d934d24e9997619cc9" + "footprint": "e6289d65df199ced74648f8de51830472111eac8" }, "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/index.html", "repository": { "url": "https://github.cds.internal.unity3d.com/unity/dots.git", "type": "git", - "revision": "81c21934f16a49fc5f826187f07aaea4728d63c3" + "revision": "13433ff314ae6503bb855899b83d26a063650441" } }