1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

[server] Rework line part reflections.

This commit is contained in:
Starbeamrainbowlabs 2017-06-30 10:33:35 +01:00
parent 551ceeb17e
commit e0d7bf4bc4
4 changed files with 39 additions and 42 deletions

View file

@ -5,24 +5,6 @@ using SBRL.Utilities;
namespace Nibriboard.Client namespace Nibriboard.Client
{ {
public class LinePartEventArgs : EventArgs
{
/// <summary>
/// The client who drew the additional points.
/// </summary>
public NibriClient DrawingClient;
/// <summary>
/// The id of the line that justu had some points added to it.
/// </summary>
public string LineId;
/// <summary>
/// The new points that got added to the line.
/// </summary>
public List<LocationReference> NewPoints;
}
public delegate void OnLinePartAddition(object sender, LinePartEventArgs eventArgs);
/// <summary> /// <summary>
/// Manages the construction of lines that the clients are drawing bit by bit. /// Manages the construction of lines that the clients are drawing bit by bit.
/// </summary> /// </summary>
@ -47,11 +29,6 @@ namespace Nibriboard.Client
} }
} }
/// <summary>
/// Fired when points get added to a line in this incubator.
/// </summary>
public event OnLinePartAddition OnLinePartAddition;
public LineIncubator() public LineIncubator()
{ {
} }
@ -72,7 +49,7 @@ namespace Nibriboard.Client
/// </summary> /// </summary>
/// <param name="lineId">The line id to add the points to.</param> /// <param name="lineId">The line id to add the points to.</param>
/// <param name="points">The points to add to the lines.</param> /// <param name="points">The points to add to the lines.</param>
public void AddBit(NibriClient drawingClient, string lineId, List<LocationReference> points) public void AddBit(string lineId, List<LocationReference> points)
{ {
// Create a new line if one doesn't exist already // Create a new line if one doesn't exist already
if(!currentLines.ContainsKey(lineId)) if(!currentLines.ContainsKey(lineId))
@ -80,12 +57,6 @@ namespace Nibriboard.Client
// Add these points to the line // Add these points to the line
currentLines[lineId].Points.AddRange(points); currentLines[lineId].Points.AddRange(points);
OnLinePartAddition(this, new LinePartEventArgs() {
DrawingClient = drawingClient,
LineId = lineId,
NewPoints = points
});
} }
/// <summary> /// <summary>

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using SBRL.Utilities;
namespace Nibriboard.Client.Messages
{
/// <summary>
/// The reflection of a <see cref="LinePartMessage" /> 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.
/// </summary>
public class LinePartReflectionMessage : Message
{
/// <summary>
/// The id of the client drawing the line.
/// </summary>
public int OtherClientId;
/// <summary>
/// The id of the line to add the points to.
/// </summary>
public string LineId;
/// <summary>
/// The points to add to the line
/// </summary>
public List<Vector2> Points;
public LinePartReflectionMessage()
{
}
}
}

View file

@ -122,8 +122,6 @@ namespace Nibriboard.Client
manager = inManager; manager = inManager;
client = inClient; client = inClient;
manager.LineIncubator.OnLinePartAddition += handleLinePartAddition;
client.DataReceived += async (WebSocket clientSocket, string frame) => { client.DataReceived += async (WebSocket clientSocket, string frame) => {
try try
{ {
@ -401,6 +399,12 @@ namespace Nibriboard.Client
manager.LineIncubator.AddBit(message.LineId, linePoints); manager.LineIncubator.AddBit(message.LineId, linePoints);
manager.BroadcastPlane(this, new LinePartReflectionMessage() {
OtherClientId = Id,
LineId = message.LineId,
Points = message.Points
});
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -448,16 +452,6 @@ namespace Nibriboard.Client
Send(clientNotification); 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 #endregion

View file

@ -101,6 +101,7 @@
<Compile Include="Client\Messages\ErrorMessage.cs" /> <Compile Include="Client\Messages\ErrorMessage.cs" />
<Compile Include="Client\Messages\PlaneChangeOkMessage.cs" /> <Compile Include="Client\Messages\PlaneChangeOkMessage.cs" />
<Compile Include="Client\RawChunkReference.cs" /> <Compile Include="Client\RawChunkReference.cs" />
<Compile Include="Client\Messages\LinePartReflectionMessage.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" /> <EmbeddedResource Include="ClientFiles\index.html" />