| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.ECS7.InternalComponents; |
| | 4 | | using DCL.ECSRuntime; |
| | 5 | |
|
| | 6 | | public class InternalECSComponents : IDisposable, IInternalECSComponents |
| | 7 | | { |
| 63 | 8 | | internal readonly IList<InternalComponentWriteData> scheduledWrite = new List<InternalComponentWriteData>(50); |
| | 9 | |
|
| 1 | 10 | | public IInternalECSComponent<InternalTexturizable> texturizableComponent { get; } |
| 1 | 11 | | public IInternalECSComponent<InternalMaterial> materialComponent { get; } |
| 1 | 12 | | public IInternalECSComponent<InternalColliders> onPointerColliderComponent { get; } |
| 0 | 13 | | public IInternalECSComponent<InternalColliders> physicColliderComponent { get; } |
| 2 | 14 | | public IInternalECSComponent<InternalInputEventResults> inputEventResultsComponent { get; } |
| 1 | 15 | | public IInternalECSComponent<InternalRenderers> renderersComponent { get; } |
| 1 | 16 | | public IInternalECSComponent<InternalVisibility> visibilityComponent { get; } |
| 43 | 17 | | public IInternalECSComponent<InternalUiContainer> uiContainerComponent { get; } |
| | 18 | |
|
| 63 | 19 | | public InternalECSComponents(ECSComponentsManager componentsManager, ECSComponentsFactory componentsFactory) |
| | 20 | | { |
| 63 | 21 | | texturizableComponent = new InternalECSComponent<InternalTexturizable>( |
| | 22 | | InternalECSComponentsId.TEXTURIZABLE, |
| | 23 | | componentsManager, |
| | 24 | | componentsFactory, |
| 13 | 25 | | () => new RemoveOnConditionHandler<InternalTexturizable>( |
| 33 | 26 | | () => texturizableComponent, model => model.renderers.Count == 0), |
| | 27 | | scheduledWrite); |
| | 28 | |
|
| 63 | 29 | | materialComponent = new InternalECSComponent<InternalMaterial>( |
| | 30 | | InternalECSComponentsId.MATERIAL, |
| | 31 | | componentsManager, |
| | 32 | | componentsFactory, |
| | 33 | | null, |
| | 34 | | scheduledWrite); |
| | 35 | |
|
| 63 | 36 | | onPointerColliderComponent = new InternalECSComponent<InternalColliders>( |
| | 37 | | InternalECSComponentsId.COLLIDER_POINTER, |
| | 38 | | componentsManager, |
| | 39 | | componentsFactory, |
| 47 | 40 | | () => new RemoveOnConditionHandler<InternalColliders>( |
| 109 | 41 | | () => onPointerColliderComponent, model => model.colliders.Count == 0), |
| | 42 | | scheduledWrite); |
| | 43 | |
|
| 63 | 44 | | physicColliderComponent = new InternalECSComponent<InternalColliders>( |
| | 45 | | InternalECSComponentsId.COLLIDER_PHYSICAL, |
| | 46 | | componentsManager, |
| | 47 | | componentsFactory, |
| 22 | 48 | | () => new RemoveOnConditionHandler<InternalColliders>( |
| 44 | 49 | | () => physicColliderComponent, model => model.colliders.Count == 0), |
| | 50 | | scheduledWrite); |
| | 51 | |
|
| 63 | 52 | | renderersComponent = new InternalECSComponent<InternalRenderers>( |
| | 53 | | InternalECSComponentsId.RENDERERS, |
| | 54 | | componentsManager, |
| | 55 | | componentsFactory, |
| 22 | 56 | | () => new RemoveOnConditionHandler<InternalRenderers>( |
| 74 | 57 | | () => renderersComponent, model => model.renderers.Count == 0), |
| | 58 | | scheduledWrite); |
| | 59 | |
|
| 63 | 60 | | visibilityComponent = new InternalECSComponent<InternalVisibility>( |
| | 61 | | InternalECSComponentsId.VISIBILITY, |
| | 62 | | componentsManager, |
| | 63 | | componentsFactory, |
| | 64 | | null, |
| | 65 | | scheduledWrite); |
| | 66 | |
|
| 63 | 67 | | inputEventResultsComponent = new InternalECSComponent<InternalInputEventResults>( |
| | 68 | | InternalECSComponentsId.INPUT_EVENTS_RESULT, |
| | 69 | | componentsManager, |
| | 70 | | componentsFactory, |
| | 71 | | null, |
| | 72 | | scheduledWrite); |
| | 73 | |
|
| 63 | 74 | | uiContainerComponent = new InternalECSComponent<InternalUiContainer>( |
| | 75 | | InternalECSComponentsId.UI_CONTAINER, |
| | 76 | | componentsManager, |
| | 77 | | componentsFactory, |
| 32 | 78 | | () => new UiContainerHandler(() => uiContainerComponent), |
| | 79 | | scheduledWrite); |
| 63 | 80 | | } |
| | 81 | |
|
| | 82 | | public void Dispose() |
| | 83 | | { |
| 1 | 84 | | scheduledWrite.Clear(); |
| | 85 | |
|
| 1 | 86 | | texturizableComponent.Dispose(); |
| 1 | 87 | | materialComponent.Dispose(); |
| 1 | 88 | | onPointerColliderComponent.Dispose(); |
| 1 | 89 | | physicColliderComponent.Dispose(); |
| 1 | 90 | | renderersComponent.Dispose(); |
| 1 | 91 | | inputEventResultsComponent.Dispose(); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | public void WriteSystemUpdate() |
| | 95 | | { |
| 114 | 96 | | for (int i = 0; i < scheduledWrite.Count; i++) |
| | 97 | | { |
| 40 | 98 | | var writeData = scheduledWrite[i]; |
| 40 | 99 | | if (writeData.scene?.crdtExecutor == null) |
| | 100 | | continue; |
| | 101 | |
|
| 40 | 102 | | InternalComponent data = writeData.data; |
| 40 | 103 | | if (data != null) |
| | 104 | | { |
| 38 | 105 | | data._dirty = false; |
| 38 | 106 | | } |
| | 107 | | else |
| | 108 | | { |
| 2 | 109 | | writeData.scene.crdtExecutor.ExecuteWithoutStoringState(writeData.entityId, writeData.componentId, null) |
| | 110 | | } |
| | 111 | | } |
| 17 | 112 | | scheduledWrite.Clear(); |
| 17 | 113 | | } |
| | 114 | | } |