1
0
Fork 0

[client] Fix chunk update piping & display logic

This commit is contained in:
Starbeamrainbowlabs 2017-06-11 21:39:33 +01:00
parent 6ca05e8d44
commit 6a0d3180a7
4 changed files with 37 additions and 13 deletions

View File

@ -8,7 +8,6 @@
"Utilities/*.js"
],
"dontLoad": [
"node_module/**",
"NibriClient.js"
],
"plugins": {
@ -27,4 +26,4 @@
},
"commonjs": {}
}
}
}

View File

@ -9,7 +9,8 @@ class Chunk
{
/**
* Creates a new chunk.
* @param {ChunkReference} inChunkRef The location of the new chunk.
* @param {ChunkReference} inChunkRef The location of the new chunk.
* @param {number} inSize The size of this chunk.
*/
constructor(inChunkRef, inSize)
{
@ -45,14 +46,14 @@ class Chunk
{
context.beginPath();
context.moveTo(
line.Points[0].x - this.chunkRef.x,
line.Points[0].y - this.chunkRef.y
line.Points[0].x - this.chunkRef.inPlaneSpace(this.size).x,
line.Points[0].y - this.chunkRef.inPlaneSpace(this.size).y
);
for(let i = 1; i < line.Points.length; i++)
{
context.lineTo(
line.Points[i].x - this.chunkRef.x,
line.Points[i].y - this.chunkRef.y
line.Points[i].x - this.chunkRef.inPlaneSpace(this.size).x,
line.Points[i].y - this.chunkRef.inPlaneSpace(this.size).y
);
}

View File

@ -3,6 +3,7 @@
import ChunkReference from './ChunkReference';
import Chunk from './Chunk';
import Rectangle from './Utilities/Rectangle';
import Vector from './Utilities/Vector';
class ChunkCache
{
@ -16,14 +17,19 @@ class ChunkCache
/**
* Adds the given chunk to the chunk cache.
* @param {Chunk} chunkData The chunk to add to the cache.
* @param {Chunk} chunkData The chunk to add to the cache.
* @returns {bool} Whether we actually updated an existing chunk in the
* cache instead of adding a new one.
*/
add(chunkData, override = false)
{
if(!override && this.cache.contains(chunkData.chunkRef.toString()))
var hasChunk = this.cache.has(chunkData.chunkRef.toString());
if(!override && hasChunk)
throw new Error("Error: We already have a chunk at that location stored.");
this.cache.set(chunkData.chunkRef.toString(), chunkData);
return !hasChunk;
}
/**
@ -56,7 +62,9 @@ class ChunkCache
{
let cChunk = new ChunkReference(
this.boardWindow.currentPlaneName,
cx, cy
// Translate from plane space to chunk space when creating
// a _chunk_ reference
cx / chunkSize, cy / chunkSize
);
let chunk = this.cache.get(cChunk.toString());
if(typeof chunk != "undefined")
@ -76,10 +84,16 @@ class ChunkCache
chunkData.Location.Y
);
let newChunk = new Chunk(newChunkRef, chunkData.Size);
newChunk.lines = newChunk.lines.concat(chunkData.lines);
console.info(`Chunk Update @ ${newChunkRef}`)
this.add(newChunk);
let newChunk = new Chunk(newChunkRef, chunkData.Size);
let newLines = chunkData.lines.map((line) => {
line.Points = line.Points.map((raw) => new Vector(raw.X, raw.Y));
return line;
});
newChunk.lines = newChunk.lines.concat(newLines);
this.add(newChunk, true);
}
}
}

View File

@ -10,6 +10,16 @@ class ChunkReference extends Vector
this.planeName = inPlaneName;
}
/**
* Returns a plain Vector of this chunk reference in plane space.
* @param {number} chunkSize The size of the chunk this ChunkReference refers to.
* @return {Vector} This ChunkReference in plane space.
*/
inPlaneSpace(chunkSize)
{
return this.clone().multiply(chunkSize);
}
toString()
{
return `ChunkReference: (${this.x}, ${this.y}, ${this.planeName})`;