| | 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 | | { |
| 50 | 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; } |
| | 17 | |
|
| 50 | 18 | | public InternalECSComponents(ECSComponentsManager componentsManager, ECSComponentsFactory componentsFactory) |
| | 19 | | { |
| 50 | 20 | | texturizableComponent = new InternalECSComponent<InternalTexturizable>( |
| | 21 | | InternalECSComponentsId.TEXTURIZABLE, |
| | 22 | | componentsManager, |
| | 23 | | componentsFactory, |
| 13 | 24 | | () => new RemoveOnConditionHandler<InternalTexturizable>( |
| 33 | 25 | | () => texturizableComponent, model => model.renderers.Count == 0), |
| | 26 | | scheduledWrite); |
| | 27 | |
|
| 50 | 28 | | materialComponent = new InternalECSComponent<InternalMaterial>( |
| | 29 | | InternalECSComponentsId.MATERIAL, |
| | 30 | | componentsManager, |
| | 31 | | componentsFactory, |
| | 32 | | null, |
| | 33 | | scheduledWrite); |
| | 34 | |
|
| 50 | 35 | | onPointerColliderComponent = new InternalECSComponent<InternalColliders>( |
| | 36 | | InternalECSComponentsId.COLLIDER_POINTER, |
| | 37 | | componentsManager, |
| | 38 | | componentsFactory, |
| 47 | 39 | | () => new RemoveOnConditionHandler<InternalColliders>( |
| 109 | 40 | | () => onPointerColliderComponent, model => model.colliders.Count == 0), |
| | 41 | | scheduledWrite); |
| | 42 | |
|
| 50 | 43 | | physicColliderComponent = new InternalECSComponent<InternalColliders>( |
| | 44 | | InternalECSComponentsId.COLLIDER_PHYSICAL, |
| | 45 | | componentsManager, |
| | 46 | | componentsFactory, |
| 22 | 47 | | () => new RemoveOnConditionHandler<InternalColliders>( |
| 44 | 48 | | () => physicColliderComponent, model => model.colliders.Count == 0), |
| | 49 | | scheduledWrite); |
| | 50 | |
|
| 50 | 51 | | renderersComponent = new InternalECSComponent<InternalRenderers>( |
| | 52 | | InternalECSComponentsId.RENDERERS, |
| | 53 | | componentsManager, |
| | 54 | | componentsFactory, |
| 22 | 55 | | () => new RemoveOnConditionHandler<InternalRenderers>( |
| 74 | 56 | | () => renderersComponent, model => model.renderers.Count == 0), |
| | 57 | | scheduledWrite); |
| | 58 | |
|
| 50 | 59 | | visibilityComponent = new InternalECSComponent<InternalVisibility>( |
| | 60 | | InternalECSComponentsId.VISIBILITY, |
| | 61 | | componentsManager, |
| | 62 | | componentsFactory, |
| | 63 | | null, |
| | 64 | | scheduledWrite); |
| | 65 | |
|
| 50 | 66 | | inputEventResultsComponent = new InternalECSComponent<InternalInputEventResults>( |
| | 67 | | InternalECSComponentsId.INPUT_EVENTS_RESULT, |
| | 68 | | componentsManager, |
| | 69 | | componentsFactory, |
| | 70 | | null, |
| | 71 | | scheduledWrite); |
| 50 | 72 | | } |
| | 73 | |
|
| | 74 | | public void Dispose() |
| | 75 | | { |
| 1 | 76 | | scheduledWrite.Clear(); |
| | 77 | |
|
| 1 | 78 | | texturizableComponent.Dispose(); |
| 1 | 79 | | materialComponent.Dispose(); |
| 1 | 80 | | onPointerColliderComponent.Dispose(); |
| 1 | 81 | | physicColliderComponent.Dispose(); |
| 1 | 82 | | renderersComponent.Dispose(); |
| 1 | 83 | | inputEventResultsComponent.Dispose(); |
| 1 | 84 | | } |
| | 85 | |
|
| | 86 | | public void WriteSystemUpdate() |
| | 87 | | { |
| 114 | 88 | | for (int i = 0; i < scheduledWrite.Count; i++) |
| | 89 | | { |
| 40 | 90 | | var writeData = scheduledWrite[i]; |
| 40 | 91 | | if (writeData.scene == null) |
| | 92 | | continue; |
| | 93 | |
|
| 40 | 94 | | InternalComponent data = writeData.data; |
| 40 | 95 | | if (data != null) |
| | 96 | | { |
| 38 | 97 | | data._dirty = false; |
| 38 | 98 | | } |
| | 99 | | else |
| | 100 | | { |
| 2 | 101 | | writeData.scene.crdtExecutor.ExecuteWithoutStoringState(writeData.entityId, writeData.componentId, null) |
| | 102 | | } |
| | 103 | | } |
| 17 | 104 | | scheduledWrite.Clear(); |
| 17 | 105 | | } |
| | 106 | | } |