FrameAssembler теперь может собирать несколько кадров одновременно
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Domain;
|
using Domain;
|
||||||
|
|
||||||
namespace Client;
|
namespace Client;
|
||||||
@@ -7,7 +8,7 @@ namespace Client;
|
|||||||
public class FrameAssembler
|
public class FrameAssembler
|
||||||
{
|
{
|
||||||
private readonly Action<List<Data>> _frameCallback;
|
private readonly Action<List<Data>> _frameCallback;
|
||||||
private readonly List<Data> _buffer = new List<Data>();
|
private readonly Dictionary<long, Dictionary<string, Data>> _frames = new();
|
||||||
private const int FrameSize = 9;
|
private const int FrameSize = 9;
|
||||||
|
|
||||||
public FrameAssembler(Action<List<Data>> frameCallback)
|
public FrameAssembler(Action<List<Data>> frameCallback)
|
||||||
@@ -17,11 +18,23 @@ public class FrameAssembler
|
|||||||
|
|
||||||
public void AddData(Data data)
|
public void AddData(Data data)
|
||||||
{
|
{
|
||||||
_buffer.Add(data);
|
long frameIndex = data.FrameIndex;
|
||||||
if (_buffer.Count >= FrameSize)
|
string overlayPoint = data.OverlayPoint;
|
||||||
|
|
||||||
|
if (!_frames.ContainsKey(frameIndex))
|
||||||
{
|
{
|
||||||
_frameCallback(new List<Data>(_buffer));
|
_frames[frameIndex] = new Dictionary<string, Data>();
|
||||||
_buffer.Clear();
|
}
|
||||||
|
|
||||||
|
_frames[frameIndex][overlayPoint] = data; // Overwrite if duplicate
|
||||||
|
|
||||||
|
if (_frames[frameIndex].Count == FrameSize)
|
||||||
|
{
|
||||||
|
List<Data> frameData = _frames[frameIndex].Values
|
||||||
|
.OrderBy(d => d.OverlayPoint)
|
||||||
|
.ToList();
|
||||||
|
_frameCallback(frameData);
|
||||||
|
_frames.Remove(frameIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user