FrameAssembler теперь может собирать несколько кадров одновременно
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Domain;
|
||||
|
||||
namespace Client;
|
||||
@@ -7,7 +8,7 @@ namespace Client;
|
||||
public class FrameAssembler
|
||||
{
|
||||
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;
|
||||
|
||||
public FrameAssembler(Action<List<Data>> frameCallback)
|
||||
@@ -17,11 +18,23 @@ public class FrameAssembler
|
||||
|
||||
public void AddData(Data data)
|
||||
{
|
||||
_buffer.Add(data);
|
||||
if (_buffer.Count >= FrameSize)
|
||||
long frameIndex = data.FrameIndex;
|
||||
string overlayPoint = data.OverlayPoint;
|
||||
|
||||
if (!_frames.ContainsKey(frameIndex))
|
||||
{
|
||||
_frameCallback(new List<Data>(_buffer));
|
||||
_buffer.Clear();
|
||||
_frames[frameIndex] = new Dictionary<string, Data>();
|
||||
}
|
||||
|
||||
_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