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

[server] Fix line splitting logic.... except it broke again :-(

This commit is contained in:
Starbeamrainbowlabs 2017-04-28 22:25:55 +01:00
parent 4954d53523
commit b21608d261
3 changed files with 28 additions and 8 deletions

View file

@ -41,7 +41,7 @@ namespace Nibriboard.RippleSpace
ChunkReference containingChunk = Points[0].ContainingChunk; ChunkReference containingChunk = Points[0].ContainingChunk;
foreach(LocationReference point in Points) foreach(LocationReference point in Points)
{ {
if (point.ContainingChunk != containingChunk) if (!point.ContainingChunk.Equals(containingChunk))
return true; return true;
} }
return false; return false;
@ -67,7 +67,11 @@ namespace Nibriboard.RippleSpace
LineId = inLineId; LineId = inLineId;
} }
public List<DrawnLine> SplitOnChunks(int chunkSize) /// <summary>
/// Splits this line into a list of lines that don't cross chunk boundaries.
/// </summary>
/// <returns>A list of lines, that, when stitched together, will produce this line.</returns>
public List<DrawnLine> SplitOnChunks()
{ {
List<DrawnLine> results = new List<DrawnLine>(); List<DrawnLine> results = new List<DrawnLine>();
@ -82,7 +86,7 @@ namespace Nibriboard.RippleSpace
ChunkReference currentChunk = null; ChunkReference currentChunk = null;
foreach(LocationReference point in Points) foreach(LocationReference point in Points)
{ {
if(currentChunk != null && point.ContainingChunk != currentChunk) if(currentChunk != null && !point.ContainingChunk.Equals(currentChunk))
{ {
// We're heading into a new chunk! Split the line up here. // We're heading into a new chunk! Split the line up here.
// TODO: Add connecting lines to each DrawnLine instance to prevent gaps // TODO: Add connecting lines to each DrawnLine instance to prevent gaps
@ -91,8 +95,13 @@ namespace Nibriboard.RippleSpace
} }
nextLine.Points.Add(point); nextLine.Points.Add(point);
if(!point.ContainingChunk.Equals(currentChunk))
currentChunk = point.ContainingChunk;
} }
if(nextLine.Points.Count > 0)
results.Add(nextLine);
return results; return results;
} }
} }

View file

@ -119,7 +119,11 @@ namespace Nibriboard.RippleSpace
// Uh-oh! The chunk isn't loaded at moment. Load it quick & then // Uh-oh! The chunk isn't loaded at moment. Load it quick & then
// return it fast. // return it fast.
string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename()); string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename());
Chunk loadedChunk = await Chunk.FromFile(this, chunkFilePath); Chunk loadedChunk;
if(File.Exists(chunkFilePath)) // If the chunk exists on disk, load it
loadedChunk = await Chunk.FromFile(this, chunkFilePath);
else // Ooooh! It's a _new_, never-before-seen one! Create a brand new chunk :D
loadedChunk = new Chunk(this, ChunkSize, chunkLocation);
loadedChunk.OnChunkUpdate += handleChunkUpdate; loadedChunk.OnChunkUpdate += handleChunkUpdate;
loadedChunkspace.Add(chunkLocation, loadedChunk); loadedChunkspace.Add(chunkLocation, loadedChunk);
@ -128,15 +132,21 @@ namespace Nibriboard.RippleSpace
public async Task AddLine(DrawnLine newLine) public async Task AddLine(DrawnLine newLine)
{ {
List<DrawnLine> chunkedLine; List<DrawnLine> chunkedLineParts;
// Split the line up into chunked pieces if neccessary // Split the line up into chunked pieces if neccessary
if(newLine.SpansMultipleChunks) if(newLine.SpansMultipleChunks)
chunkedLine = newLine.SplitOnChunks(ChunkSize); chunkedLineParts = newLine.SplitOnChunks();
else else
chunkedLine = new List<DrawnLine>() { newLine }; chunkedLineParts = new List<DrawnLine>() { newLine };
foreach(DrawnLine linePart in chunkedLineParts)
{
if(linePart.Points.Count == 0)
Log.WriteLine("[Plane/{0}] Warning: A line part has no points in it O.o", Name);
}
// Add each segment to the appropriate chunk // Add each segment to the appropriate chunk
foreach(DrawnLine newLineSegment in chunkedLine) foreach(DrawnLine newLineSegment in chunkedLineParts)
{ {
Chunk containingChunk = await FetchChunk(newLineSegment.ContainingChunk); Chunk containingChunk = await FetchChunk(newLineSegment.ContainingChunk);
containingChunk.Add(newLineSegment); containingChunk.Add(newLineSegment);

View file

@ -15,6 +15,7 @@ namespace Nibriboard.RippleSpace
public Reference(Plane inPlane, int inX, int inY) public Reference(Plane inPlane, int inX, int inY)
{ {
Plane = inPlane; Plane = inPlane;
X = inX; Y = inY;
} }
public override string ToString() public override string ToString()