This commit is contained in:
CortexCore
2023-07-17 10:23:47 +08:00
parent 3a61f6677b
commit 936a94c84b
17 changed files with 161 additions and 47 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
namespace BITKit
{
public interface IDoubleBuffer<T>
{
T Current { get; }
void Release(T newValue);
event Action<T> OnRelease;
bool TryGetRelease(out T result);
}
public class DoubleBuffer<T> : IDoubleBuffer<T>
{
public T Current
{
get;
// ReSharper disable once MemberCanBePrivate.Global
protected set;
}
public void Release(T newValue)
{
Current = newValue;
OnRelease?.Invoke(newValue);
}
public event Action<T> OnRelease;
private readonly Queue<T> _releases = new();
public bool TryGetRelease(out T result)
{
return _releases.TryDequeue(out result);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa92f9c5ddad64741a2a86086b4fc977
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: