From 552fd4c0e7310a8ca9e8a5f525f60e7c257c4658 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 26 Dec 2017 12:14:48 +0000 Subject: [PATCH] [client] Fix depth-sorting issue with lines passing through multiple chunks. Fixes #2. --- Nibriboard/ClientFiles/Chunk.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Nibriboard/ClientFiles/Chunk.js b/Nibriboard/ClientFiles/Chunk.js index a38c195..7d187e1 100644 --- a/Nibriboard/ClientFiles/Chunk.js +++ b/Nibriboard/ClientFiles/Chunk.js @@ -121,7 +121,7 @@ class Chunk * @param {ChunkCache} chunkCache The chunk cache to use to fetch data from surrounding chunks. * @param {Rectangle} chunkArea The area in which chunks are being rendered. */ - render(canvas, context, chunkCache, chunkArea) + render(canvas, context, chunkCache, chunkArea, mode) { var planeSpaceRef = this.chunkRef.inPlaneSpace(this.size); @@ -131,20 +131,41 @@ class Chunk for(let line of this.lines) { // Don't draw lines that are walked by other chunks - if(line.ContinuesFrom != null && + /**if(line.ContinuesFrom != null && !(chunkCache.fetchChunk(line.ContinuesFrom) instanceof Chunk)) - continue; + continue;*/ let linePoints = line.Points; + // If this line continues from a previous chunk, fetch the last + // point of that line to stitch it up properly + if(line.ContinuesFrom != null && + chunkCache.fetchChunk(line.ContinuesFrom) instanceof Chunk) { + let prevChunk = chunkCache.fetchChunk(line.ContinuesFrom); + let prevLine = prevChunk.getLineByUniqueId(line.ContinuesFromId); + linePoints.unshift(prevLine.Points[prevLine.Points.length - 1]); + } + + // If this line continues into another chunk, fetch the first point + // of that line to stitch it up properly + if(line.ContinuesIn != null && + chunkCache.fetchChunk(line.ContinuesIn) instanceof Chunk) { + let nextChunk = chunkCache.fetchChunk(line.ContinuesIn); + let nextLine = nextChunk.getLineByUniqueId(line.ContinuesWithId); + if(nextLine != null) + linePoints.push(nextLine.Points[0]); + else + console.warn("Next line was null when we tried to fetch the first point of the following line!"); + } + // Fetch all the points on fragments of this line forwards from here - if(line.ContinuesIn != null) { + /*if(line.ContinuesIn != null) { let nextLines = chunkCache.fetchLineFragments(line.ContainingChunk, line.UniqueId); linePoints = []; for (let nextLine of nextLines) { linePoints = linePoints.concat(nextLine.Points); } - } + }*/ context.beginPath(); context.moveTo(