Skip to content

Commit

Permalink
fix: outdated colliders cache on gltf reconfiguration (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorux0 authored Aug 30, 2024
1 parent 11ea5b0 commit 69b402f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder,
ReportGltfErrorsSystem.InjectToWorld(ref builder, globalDeps.ReportsHandlingSettings);

// GLTF Container
LoadGltfContainerSystem.InjectToWorld(ref builder, buffer, sharedDependencies.SceneData);
LoadGltfContainerSystem.InjectToWorld(ref builder, buffer, sharedDependencies.SceneData, sharedDependencies.EntityCollidersSceneCache);
FinalizeGltfContainerLoadingSystem.InjectToWorld(ref builder, persistentEntities.SceneRoot, globalDeps.FrameTimeBudget,
sharedDependencies.EntityCollidersSceneCache, sharedDependencies.SceneData, buffer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Arch.System;
using Arch.SystemGroups;
using Arch.SystemGroups.Throttling;
using CRDT;
using DCL.ECSComponents;
using ECS.Abstract;
using ECS.Prioritization.Components;
Expand All @@ -12,6 +13,7 @@
using ECS.Unity.GLTFContainer.Components.Defaults;
using System.Threading;
using DCL.Diagnostics;
using DCL.Interaction.Utility;
using SceneRunner.Scene;
using UnityEngine.Assertions;
using Promise = ECS.StreamableLoading.Common.AssetPromise<ECS.Unity.GLTFContainer.Asset.Components.GltfContainerAsset, ECS.Unity.GLTFContainer.Asset.Components.GetGltfContainerAssetIntention>;
Expand All @@ -27,11 +29,14 @@ public partial class LoadGltfContainerSystem : BaseUnityLoopSystem
{
private readonly EntityEventBuffer<GltfContainerComponent> eventsBuffer;
private readonly ISceneData sceneData;
private readonly IEntityCollidersSceneCache entityCollidersSceneCache;

internal LoadGltfContainerSystem(World world, EntityEventBuffer<GltfContainerComponent> eventsBuffer, ISceneData sceneData) : base(world)
internal LoadGltfContainerSystem(World world, EntityEventBuffer<GltfContainerComponent> eventsBuffer, ISceneData sceneData,
IEntityCollidersSceneCache entityCollidersSceneCache) : base(world)
{
this.eventsBuffer = eventsBuffer;
this.sceneData = sceneData;
this.entityCollidersSceneCache = entityCollidersSceneCache;
}

protected override void Update(float t)
Expand Down Expand Up @@ -66,7 +71,8 @@ private void StartLoading(in Entity entity, ref PBGltfContainer sdkComponent, re

// SDK Component was changed
[Query]
private void ReconfigureGltfContainer(Entity entity, ref GltfContainerComponent component, ref PBGltfContainer sdkComponent, ref PartitionComponent partitionComponent)
private void ReconfigureGltfContainer(Entity entity, ref GltfContainerComponent component, ref PBGltfContainer sdkComponent, ref PartitionComponent partitionComponent,
ref CRDTEntity sdkEntity)
{
if (!sdkComponent.IsDirty) return;

Expand Down Expand Up @@ -116,9 +122,11 @@ private void ReconfigureGltfContainer(Entity entity, ref GltfContainerComponent
ConfigureGltfContainerColliders.SetupInvisibleColliders(ref component, result.Asset);
}

entityCollidersSceneCache.Associate(in component, World.Reference(entity), sdkEntity);

return;
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using Arch.Core;
using Arch.Core;
using CRDT;
using DCL.ECSComponents;
using DCL.Interaction.Utility;
using DCL.Optimization.PerformanceBudgeting;
using ECS.Abstract;
using ECS.Prioritization.Components;
using ECS.StreamableLoading.AssetBundles;
using ECS.StreamableLoading.Common;
using ECS.StreamableLoading.Common.Components;
using ECS.TestSuite;
using ECS.Unity.GLTFContainer.Asset.Components;
using ECS.Unity.GLTFContainer.Asset.Systems;
using ECS.Unity.GLTFContainer.Asset.Tests;
using ECS.Unity.GLTFContainer.Components;
using ECS.Unity.GLTFContainer.Systems;
using ECS.Unity.SceneBoundsChecker;
using ECS.Unity.Transforms.Components;
using NSubstitute;
using NUnit.Framework;
using SceneRunner.Scene;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SceneRunner.Scene;
using UnityEngine.TestTools;
using Utility;

Expand Down Expand Up @@ -50,7 +47,7 @@ public void SetUp()
x[1] = "";
return false;
});
system = new LoadGltfContainerSystem(world, eventBuffer = new EntityEventBuffer<GltfContainerComponent>(1), sceneData);
system = new LoadGltfContainerSystem(world, eventBuffer = new EntityEventBuffer<GltfContainerComponent>(1), sceneData, Substitute.For<IEntityCollidersSceneCache>());
var budget = Substitute.For<IReleasablePerformanceBudget>();
budget.TrySpendBudget().Returns(true);
createGltfAssetFromAssetBundleSystem = new CreateGltfAssetFromAssetBundleSystem(world, budget, budget);
Expand Down Expand Up @@ -110,7 +107,7 @@ public async Task ReconfigureInvisibleColliders(bool from, bool to)
var e = world.Create(component, new PBGltfContainer
{
Src = GltfContainerTestResources.SCENE_WITH_COLLIDER_HASH
}, PartitionComponent.TOP_PRIORITY);
}, PartitionComponent.TOP_PRIORITY, new CRDTEntity());
var transformComponent = AddTransformToEntity(e);

ConfigureGltfContainerColliders.SetupColliders(ref component, result.Asset);
Expand Down Expand Up @@ -152,7 +149,7 @@ public void ReconfigureSource()
var e = world.Create(component, new PBGltfContainer
{
Src = GltfContainerTestResources.RENDERER_WITH_LEGACY_ANIM_NAME, IsDirty = true
}, PartitionComponent.TOP_PRIORITY);
}, PartitionComponent.TOP_PRIORITY, new CRDTEntity());
AddTransformToEntity(e);

system.Update(0);
Expand Down Expand Up @@ -185,4 +182,4 @@ public void FailIfSceneHashIsNotAvailable()
Assert.That(component.Promise.Result!.Value.Succeeded, Is.EqualTo(false));
}
}
}
}

0 comments on commit 69b402f

Please sign in to comment.