From 2fe5bf351cc3bfba7722004936a0542427fafd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=8B=D1=82=D0=BA=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD?= Date: Sat, 20 Sep 2025 00:22:07 +0300 Subject: [PATCH] =?UTF-8?q?FrameAssembler=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D1=81=D0=BE=D0=B1?= =?UTF-8?q?=D0=B8=D1=80=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BA=D0=B0=D0=B4=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=BE=D0=B4=D0=BD=D0=BE=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/FrameAssembler.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Client/FrameAssembler.cs b/Client/FrameAssembler.cs index 5618de6..5d4186e 100644 --- a/Client/FrameAssembler.cs +++ b/Client/FrameAssembler.cs @@ -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> _frameCallback; - private readonly List _buffer = new List(); + private readonly Dictionary> _frames = new(); private const int FrameSize = 9; public FrameAssembler(Action> 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(_buffer)); - _buffer.Clear(); + _frames[frameIndex] = new Dictionary(); + } + + _frames[frameIndex][overlayPoint] = data; // Overwrite if duplicate + + if (_frames[frameIndex].Count == FrameSize) + { + List frameData = _frames[frameIndex].Values + .OrderBy(d => d.OverlayPoint) + .ToList(); + _frameCallback(frameData); + _frames.Remove(frameIndex); } } } \ No newline at end of file