1
0
Fork 0

[client] Update chunk cache

This commit is contained in:
Starbeamrainbowlabs 2017-05-29 21:59:15 +01:00
parent a7132d344d
commit 6ca05e8d44
2 changed files with 14 additions and 6 deletions

View File

@ -11,9 +11,10 @@ class Chunk
* Creates a new chunk.
* @param {ChunkReference} inChunkRef The location of the new chunk.
*/
constructor(inChunkRef)
constructor(inChunkRef, inSize)
{
this.chunkRef = inChunkRef;
this.size = inSize;
this.lines = [];
}

View File

@ -18,9 +18,9 @@ class ChunkCache
* Adds the given chunk to the chunk cache.
* @param {Chunk} chunkData The chunk to add to the cache.
*/
add(chunkData)
add(chunkData, override = false)
{
if(this.cache.contains(chunkData.chunkRef.toString()))
if(!override && this.cache.contains(chunkData.chunkRef.toString()))
throw new Error("Error: We already have a chunk at that location stored.");
this.cache.set(chunkData.chunkRef.toString(), chunkData);
@ -69,10 +69,17 @@ class ChunkCache
handleChunkUpdate(message)
{
for (let chunk of message.Chunks) {
//let newChunkRef = new ChunkReference();
let newChunk = new Chunk(chunk.Location);
for (let chunkData of message.Chunks) {
let newChunkRef = new ChunkReference(
chunkData.Location.PlaneName,
chunkData.Location.X,
chunkData.Location.Y
);
let newChunk = new Chunk(newChunkRef, chunkData.Size);
newChunk.lines = newChunk.lines.concat(chunkData.lines);
this.add(newChunk);
}
}
}