Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions com.dotsui.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

**This file contains changelog for all DotsUI packages**

## [0.5.0] 2019-12-15

### Added

* Toggle control


### Changes

* Refactored input system (significant performance improvement)
* Implemented dedicated parent system. It works with the same components, but write group prevents some Unity.Transforms systems from querying entities with RectTransfrom. This way we can remove some unnecessary components (like LocalToWorld and LocalToParent) and see a great performance boost.


## [0.4.0] 2019-09-11

### Added
Expand Down
64 changes: 16 additions & 48 deletions com.dotsui.core/DotsUI.Controls/ButtonSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DotsUI.Core;
using System.Diagnostics;
using DotsUI.Core;
using DotsUI.Core.Utils;
using DotsUI.Input;
using Unity.Entities;
Expand All @@ -9,72 +10,39 @@
namespace DotsUI.Controls
{
[UpdateInGroup(typeof(InputSystemGroup))]
[UpdateAfter(typeof(ControlsInputSystem))]
[UpdateAfter(typeof(ControlsInputSystemGroup))]
public class ButtonSystem : JobComponentSystem
{
private EntityQuery m_EventGroup;
private InputHandleBarrier m_Barrier;

private PointerEventQuery m_PointerQuery;

protected override void OnCreate()
{
m_Barrier = World.GetOrCreateSystem<InputHandleBarrier>();
m_EventGroup = GetEntityQuery(new EntityQueryDesc()
{
All = new[]
{
ComponentType.ReadWrite<PointerInputBuffer>(),
ComponentType.ReadWrite<PointerEvent>()
}
});
GetEntityQuery(ComponentType.ReadOnly<Button>());
m_PointerQuery = PointerEventQuery.Create<Button>(EntityManager);
}

protected override void OnDestroy()
{
}
[BurstCompile]
private struct ProcessClicks : IJobChunk
{
[ReadOnly] public ArchetypeChunkComponentType<PointerEvent> EventType;
[ReadOnly] public ArchetypeChunkBufferType<PointerInputBuffer> BufferType;

[WriteOnly] public AddFlagComponentCommandBuffer.ParallelWriter ClickedButtons;
[ReadOnly] public ComponentDataFromEntity<Button> ButtonTargetType;
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var reader = m_PointerQuery.CreatePointerEventReader(Allocator.TempJob);

public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
for (int i = 0; i < reader.EntityCount; i++)
{
var eventArray = chunk.GetNativeArray(EventType);
var bufferAccessor = chunk.GetBufferAccessor(BufferType);
for (int i = 0; i < chunk.Count; i++)
foreach (var ev in reader.GetEventsForTargetEntity(reader[i]))
{
if (ButtonTargetType.Exists(eventArray[i].Target))
{
var buff = bufferAccessor[i];
for (int j = 0; j < buff.Length; j++)
{
if (buff[j].EventType == PointerEventType.Click)
{
ClickedButtons.TryAdd(eventArray[i].Target);
}
}
}

if (ev.EventType == PointerEventType.Click)
EntityManager.AddComponent<ButtonClickedEvent>(reader[i]);
}
}
}

protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var commandBuff = m_Barrier.CreateAddFlagComponentCommandBuffer<ButtonClickedEvent>();
ProcessClicks clicksJob = new ProcessClicks
{
BufferType = GetArchetypeChunkBufferType<PointerInputBuffer>(),
EventType = GetArchetypeChunkComponentType<PointerEvent>(),
ButtonTargetType = GetComponentDataFromEntity<Button>(),
ClickedButtons = commandBuff.AsParallelWriter()
};
inputDeps = clicksJob.Schedule(m_EventGroup, inputDeps);
m_Barrier.AddJobHandleForProducer(inputDeps);
inputDeps = reader.Dispose(inputDeps);
return inputDeps;
}
}
}
}
3 changes: 3 additions & 0 deletions com.dotsui.core/DotsUI.Controls/ControlsCleanupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class ControlsCleanupSystem : ComponentSystem
private EntityQuery m_InputFieldEndEditQuery;
private EntityQuery m_InputFieldReturnQuery;
private EntityQuery m_SliderValueChangedQuery;
private EntityQuery m_ToggleValueChangedQuery;

protected override void OnCreate()
{
m_ButtonClickedQuery = GetEntityQuery(typeof(ButtonClickedEvent));
m_SliderValueChangedQuery = GetEntityQuery(typeof(SliderValueChangedEvent));
m_InputFieldEndEditQuery = GetEntityQuery(typeof(InputFieldEndEditEvent));
m_InputFieldReturnQuery = GetEntityQuery(typeof(InputFieldReturnEvent));
m_ToggleValueChangedQuery = GetEntityQuery(typeof(ToggleValueChangedEvent));
}

protected override void OnUpdate()
Expand All @@ -25,6 +27,7 @@ protected override void OnUpdate()
EntityManager.RemoveComponent(m_SliderValueChangedQuery, typeof(SliderValueChangedEvent));
EntityManager.RemoveComponent(m_InputFieldEndEditQuery, typeof(InputFieldEndEditEvent));
EntityManager.RemoveComponent(m_InputFieldReturnQuery, typeof(InputFieldReturnEvent));
EntityManager.RemoveComponent(m_ToggleValueChangedQuery, typeof(ToggleValueChangedEvent));
}
}
}
16 changes: 8 additions & 8 deletions com.dotsui.core/DotsUI.Controls/InputCaretSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected override void OnCreate()
All = new ComponentType[]
{
ComponentType.ReadOnly<InputFieldCaret>(),
ComponentType.ReadWrite<ControlVertexData>(),
ComponentType.ReadWrite<ControlVertexIndex>(),
ComponentType.ReadWrite<ElementVertexData>(),
ComponentType.ReadWrite<ElementVertexIndex>(),
}
});
}
Expand All @@ -45,8 +45,8 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)
var inputField = EntityManager.GetComponentData<InputField>(inputFieldEntity);
var caretState = EntityManager.GetComponentData<InputFieldCaretState>(inputFieldEntity);

var controlVertexData = EntityManager.GetBuffer<ControlVertexData>(entity);
var controlVertexIndex = EntityManager.GetBuffer<ControlVertexIndex>(entity);
var controlVertexData = EntityManager.GetBuffer<ElementVertexData>(entity);
var controlVertexIndex = EntityManager.GetBuffer<ElementVertexIndex>(entity);

var rect = TextUtils.GetCaretRect(inputField.Target, EntityManager, caretState.CaretPosition);

Expand All @@ -56,28 +56,28 @@ protected override JobHandle OnUpdate(JobHandle inputDeps)
? new float4(0.0f, 0.0f, 0.0f, 1.0f)
: new float4(0.0f, 0.0f, 0.0f, 0.0f);

controlVertexData.Add(new ControlVertexData()
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Min, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ControlVertexData()
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Max.x, rect.Min.y, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ControlVertexData()
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Position = new float3(rect.Max.x, rect.Max.y, 0.0f),
TexCoord0 = new float2(0.0f)
});
controlVertexData.Add(new ControlVertexData()
controlVertexData.Add(new ElementVertexData()
{
Color = color,
Normal = new float3(0.0f, 0.0f, -1.0f),
Expand Down
Loading