This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using ShrinkEventBus;
|
||||
using Unity.Collections;
|
||||
|
||||
namespace ShrinkEventBus.Entities
|
||||
{
|
||||
/// <summary>Burst-safe producer queue; playback enters the regular Bus instance.</summary>
|
||||
public sealed class ShrinkEcsEventQueue<TEvent> : IDisposable where TEvent : unmanaged, IShrinkEvent
|
||||
{
|
||||
private NativeQueue<TEvent> _queue;
|
||||
|
||||
public ShrinkEcsEventQueue(Allocator allocator = Allocator.Persistent)
|
||||
{
|
||||
_queue = new NativeQueue<TEvent>(allocator);
|
||||
Writer = new ShrinkEcsEventWriter<TEvent>(_queue.AsParallelWriter());
|
||||
}
|
||||
|
||||
public ShrinkEcsEventWriter<TEvent> Writer { get; }
|
||||
|
||||
public int Playback(IShrinkEventBus bus)
|
||||
{
|
||||
if (bus == null)
|
||||
throw new ArgumentNullException(nameof(bus));
|
||||
var count = 0;
|
||||
while (_queue.TryDequeue(out var eventData))
|
||||
{
|
||||
bus.Post(in eventData);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_queue.IsCreated)
|
||||
_queue.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct ShrinkEcsEventWriter<TEvent> where TEvent : unmanaged, IShrinkEvent
|
||||
{
|
||||
private readonly NativeQueue<TEvent>.ParallelWriter _writer;
|
||||
|
||||
internal ShrinkEcsEventWriter(NativeQueue<TEvent>.ParallelWriter writer)
|
||||
{
|
||||
_writer = writer;
|
||||
}
|
||||
|
||||
public void Post(in TEvent eventData) => _writer.Enqueue(eventData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05a2db7ffefb4841bdcd63d8fd3ac6fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "ShrinkEventBus.Entities.Runtime",
|
||||
"rootNamespace": "ShrinkEventBus.Entities",
|
||||
"references": [
|
||||
"ShrinkEventBus.Runtime",
|
||||
"Unity.Collections",
|
||||
"Unity.Entities"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"autoReferenced": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e31f017584a4a04992bb6fa7538cb2f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user