mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[client] Fix chunk update piping & display logic
This commit is contained in:
parent
6ca05e8d44
commit
6a0d3180a7
4 changed files with 37 additions and 13 deletions
|
@ -8,7 +8,6 @@
|
||||||
"Utilities/*.js"
|
"Utilities/*.js"
|
||||||
],
|
],
|
||||||
"dontLoad": [
|
"dontLoad": [
|
||||||
"node_module/**",
|
|
||||||
"NibriClient.js"
|
"NibriClient.js"
|
||||||
],
|
],
|
||||||
"plugins": {
|
"plugins": {
|
||||||
|
|
|
@ -9,7 +9,8 @@ class Chunk
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a new 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)
|
constructor(inChunkRef, inSize)
|
||||||
{
|
{
|
||||||
|
@ -45,14 +46,14 @@ class Chunk
|
||||||
{
|
{
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(
|
context.moveTo(
|
||||||
line.Points[0].x - this.chunkRef.x,
|
line.Points[0].x - this.chunkRef.inPlaneSpace(this.size).x,
|
||||||
line.Points[0].y - this.chunkRef.y
|
line.Points[0].y - this.chunkRef.inPlaneSpace(this.size).y
|
||||||
);
|
);
|
||||||
for(let i = 1; i < line.Points.length; i++)
|
for(let i = 1; i < line.Points.length; i++)
|
||||||
{
|
{
|
||||||
context.lineTo(
|
context.lineTo(
|
||||||
line.Points[i].x - this.chunkRef.x,
|
line.Points[i].x - this.chunkRef.inPlaneSpace(this.size).x,
|
||||||
line.Points[i].y - this.chunkRef.y
|
line.Points[i].y - this.chunkRef.inPlaneSpace(this.size).y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import ChunkReference from './ChunkReference';
|
import ChunkReference from './ChunkReference';
|
||||||
import Chunk from './Chunk';
|
import Chunk from './Chunk';
|
||||||
import Rectangle from './Utilities/Rectangle';
|
import Rectangle from './Utilities/Rectangle';
|
||||||
|
import Vector from './Utilities/Vector';
|
||||||
|
|
||||||
class ChunkCache
|
class ChunkCache
|
||||||
{
|
{
|
||||||
|
@ -16,14 +17,19 @@ class ChunkCache
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given chunk to the chunk cache.
|
* 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)
|
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.");
|
throw new Error("Error: We already have a chunk at that location stored.");
|
||||||
|
|
||||||
this.cache.set(chunkData.chunkRef.toString(), chunkData);
|
this.cache.set(chunkData.chunkRef.toString(), chunkData);
|
||||||
|
|
||||||
|
return !hasChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +62,9 @@ class ChunkCache
|
||||||
{
|
{
|
||||||
let cChunk = new ChunkReference(
|
let cChunk = new ChunkReference(
|
||||||
this.boardWindow.currentPlaneName,
|
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());
|
let chunk = this.cache.get(cChunk.toString());
|
||||||
if(typeof chunk != "undefined")
|
if(typeof chunk != "undefined")
|
||||||
|
@ -76,10 +84,16 @@ class ChunkCache
|
||||||
chunkData.Location.Y
|
chunkData.Location.Y
|
||||||
);
|
);
|
||||||
|
|
||||||
let newChunk = new Chunk(newChunkRef, chunkData.Size);
|
console.info(`Chunk Update @ ${newChunkRef}`)
|
||||||
newChunk.lines = newChunk.lines.concat(chunkData.lines);
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,16 @@ class ChunkReference extends Vector
|
||||||
this.planeName = inPlaneName;
|
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()
|
toString()
|
||||||
{
|
{
|
||||||
return `ChunkReference: (${this.x}, ${this.y}, ${this.planeName})`;
|
return `ChunkReference: (${this.x}, ${this.y}, ${this.planeName})`;
|
||||||
|
|
Loading…
Reference in a new issue