From e0d7bf4bc4a1e6a0afac8428124233bb39dab6d2 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 30 Jun 2017 10:33:35 +0100 Subject: [PATCH] [server] Rework line part reflections. --- Nibriboard/Client/LineIncubator.cs | 31 +------------------ .../Messages/LinePartReflectionMessage.cs | 31 +++++++++++++++++++ Nibriboard/Client/NibriClient.cs | 18 ++++------- Nibriboard/Nibriboard.csproj | 1 + 4 files changed, 39 insertions(+), 42 deletions(-) create mode 100644 Nibriboard/Client/Messages/LinePartReflectionMessage.cs diff --git a/Nibriboard/Client/LineIncubator.cs b/Nibriboard/Client/LineIncubator.cs index c79dfb4..6b7d4be 100644 --- a/Nibriboard/Client/LineIncubator.cs +++ b/Nibriboard/Client/LineIncubator.cs @@ -5,24 +5,6 @@ using SBRL.Utilities; namespace Nibriboard.Client { - public class LinePartEventArgs : EventArgs - { - /// - /// The client who drew the additional points. - /// - public NibriClient DrawingClient; - /// - /// The id of the line that justu had some points added to it. - /// - public string LineId; - /// - /// The new points that got added to the line. - /// - public List NewPoints; - } - - public delegate void OnLinePartAddition(object sender, LinePartEventArgs eventArgs); - /// /// Manages the construction of lines that the clients are drawing bit by bit. /// @@ -47,11 +29,6 @@ namespace Nibriboard.Client } } - /// - /// Fired when points get added to a line in this incubator. - /// - public event OnLinePartAddition OnLinePartAddition; - public LineIncubator() { } @@ -72,7 +49,7 @@ namespace Nibriboard.Client /// /// The line id to add the points to. /// The points to add to the lines. - public void AddBit(NibriClient drawingClient, string lineId, List points) + public void AddBit(string lineId, List points) { // Create a new line if one doesn't exist already if(!currentLines.ContainsKey(lineId)) @@ -80,12 +57,6 @@ namespace Nibriboard.Client // Add these points to the line currentLines[lineId].Points.AddRange(points); - - OnLinePartAddition(this, new LinePartEventArgs() { - DrawingClient = drawingClient, - LineId = lineId, - NewPoints = points - }); } /// diff --git a/Nibriboard/Client/Messages/LinePartReflectionMessage.cs b/Nibriboard/Client/Messages/LinePartReflectionMessage.cs new file mode 100644 index 0000000..a2f9e59 --- /dev/null +++ b/Nibriboard/Client/Messages/LinePartReflectionMessage.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +using SBRL.Utilities; + +namespace Nibriboard.Client.Messages +{ + /// + /// The reflection of a that's sent to everyone else on the same plane. + /// Contains a list of point the client has added to the line they're drawing. + /// + public class LinePartReflectionMessage : Message + { + /// + /// The id of the client drawing the line. + /// + public int OtherClientId; + /// + /// The id of the line to add the points to. + /// + public string LineId; + /// + /// The points to add to the line + /// + public List Points; + + public LinePartReflectionMessage() + { + } + } +} diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs index 0661d20..cf2b78c 100644 --- a/Nibriboard/Client/NibriClient.cs +++ b/Nibriboard/Client/NibriClient.cs @@ -122,8 +122,6 @@ namespace Nibriboard.Client manager = inManager; client = inClient; - manager.LineIncubator.OnLinePartAddition += handleLinePartAddition; - client.DataReceived += async (WebSocket clientSocket, string frame) => { try { @@ -401,6 +399,12 @@ namespace Nibriboard.Client manager.LineIncubator.AddBit(message.LineId, linePoints); + manager.BroadcastPlane(this, new LinePartReflectionMessage() { + OtherClientId = Id, + LineId = message.LineId, + Points = message.Points + }); + return Task.CompletedTask; } @@ -448,16 +452,6 @@ namespace Nibriboard.Client Send(clientNotification); } - protected void handleLinePartAddition(object sender, LinePartEventArgs eventArgs) - { - // Ignore line part additions for ourselves and for clienst who aren't on the same plane as us - if(eventArgs.DrawingClient.Id == Id || - eventArgs.DrawingClient.CurrentPlane != CurrentPlane) - return; - - - } - #endregion diff --git a/Nibriboard/Nibriboard.csproj b/Nibriboard/Nibriboard.csproj index 3e2b8c5..6542174 100644 --- a/Nibriboard/Nibriboard.csproj +++ b/Nibriboard/Nibriboard.csproj @@ -101,6 +101,7 @@ +