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

[server] Add line incubator and start writing line part handler

This commit is contained in:
Starbeamrainbowlabs 2017-03-29 21:34:24 +01:00
parent a8c1b8e99c
commit 62857c1004
3 changed files with 75 additions and 1 deletions

View file

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using Nibriboard.RippleSpace;
using SBRL.Utilities;
namespace Nibriboard.Client
{
/// <summary>
/// Manages the construction of lines that the clients are drawing bit by bit.
/// </summary>
public class LineIncubator
{
/// <summary>
/// The current lines that haven't been completed yet.
/// </summary>
private Dictionary<Guid, DrawnLine> currentLines = new Dictionary<Guid, DrawnLine>();
/// <summary>
/// The number of lines that this line incubator has completed.
/// </summary>
public int LinesCompleted { get; private set; } = 0;
/// <summary>
/// The number of liens that are still incubating and haven't been completed yet.
/// </summary>
public int IncompletedLines {
get {
return currentLines.Count;
}
}
public LineIncubator()
{
}
public void AddBit(Guid lineId, List<LocationReference> points)
{
// Create a new line if one doesn't exist already
if(!currentLines.ContainsKey(lineId))
currentLines.Add(lineId, new DrawnLine());
// Add these points to the line
currentLines[lineId].Points.AddRange(points);
}
/// <summary>
/// Mark a line as complete and remove it from the incubator.
/// </summary>
/// <param name="lineId">The id of the line to complete.</param>
/// <returns>The completed line.</returns>
public DrawnLine CompleteLine(Guid lineId)
{
if(!currentLines.ContainsKey(lineId))
throw new KeyNotFoundException("Error: A line with that id wasn't found in this LineIncubator.");
DrawnLine completedLine = currentLines[lineId];
currentLines.Remove(lineId);
return completedLine;
}
}
}

View file

@ -54,7 +54,8 @@ namespace Nibriboard.Client
["HandshakeRequest"] = typeof(HandshakeRequestMessage),
["CursorPosition"] = typeof(CursorPositionMessage),
["PlaneChange"] = typeof(PlaneChangeMessage),
["ChunkUpdateRequest"] = typeof(ChunkUpdateRequestMessage)
["ChunkUpdateRequest"] = typeof(ChunkUpdateRequestMessage),
["LinePartMessage"] = typeof(LinePartMessage)
};
/// <summary>
@ -326,6 +327,16 @@ namespace Nibriboard.Client
return Task.CompletedTask;
}
protected Task handleLinePartMessage(LinePartMessage message)
{
// Forward the line part to everyone on this plane
manager.BroadcastPlane(this, message);
return Task.CompletedTask;
}
#endregion

View file

@ -96,6 +96,7 @@
<Compile Include="Client\Messages\ChunkUpdateRequestMessage.cs" />
<Compile Include="Client\ChunkCache.cs" />
<Compile Include="Client\Messages\LinePartMessage.cs" />
<Compile Include="Client\LineIncubator.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" />