mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[client] Refactor ChunkCache a bit to start adding chunk loading logic
This commit is contained in:
parent
5e59d7098a
commit
1935f6350e
1 changed files with 31 additions and 7 deletions
|
@ -35,6 +35,20 @@ class ChunkCache
|
||||||
return !hasChunk;
|
return !hasChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(dt, visibleArea)
|
||||||
|
{
|
||||||
|
let chunkSize = this.boardWindow.gridSize;
|
||||||
|
let chunkArea = this.CalculateChunkArea(visibleArea, chunkSize);
|
||||||
|
|
||||||
|
for(let cx = chunkArea.x; cx <= chunkArea.x + chunkArea.width; cx += chunkSize)
|
||||||
|
{
|
||||||
|
for(let cy = chunkArea.y; cy <= chunkArea.y + chunkArea.height; cy += chunkSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the specified area to the given canvas with the given context.
|
* Renders the specified area to the given canvas with the given context.
|
||||||
* @param {Rectangle} visibleArea The area to render.
|
* @param {Rectangle} visibleArea The area to render.
|
||||||
|
@ -47,13 +61,7 @@ class ChunkCache
|
||||||
{
|
{
|
||||||
context.save();
|
context.save();
|
||||||
let chunkSize = this.boardWindow.gridSize;
|
let chunkSize = this.boardWindow.gridSize;
|
||||||
let chunkArea = new Rectangle(
|
let chunkArea = this.CalculateChunkArea(visibleArea, chunkSize);
|
||||||
Math.floor(visibleArea.x / chunkSize) * chunkSize,
|
|
||||||
Math.floor(visibleArea.y / chunkSize) * chunkSize,
|
|
||||||
(Math.ceil((Math.abs(visibleArea.x) + (visibleArea.width)) / chunkSize) * chunkSize),
|
|
||||||
(Math.ceil((Math.abs(visibleArea.y) + (visibleArea.height)) / chunkSize) * chunkSize)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
for(let cx = chunkArea.x; cx <= chunkArea.x + chunkArea.width; cx += chunkSize)
|
for(let cx = chunkArea.x; cx <= chunkArea.x + chunkArea.width; cx += chunkSize)
|
||||||
{
|
{
|
||||||
|
@ -104,4 +112,20 @@ class ChunkCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the area of the chunks that cover a specified box.
|
||||||
|
* @param {Rectangle} visibleArea The box to calculate the covering chunks for.
|
||||||
|
* @param {number} chunkSize The size of the chunks that cover the box.
|
||||||
|
* @return {Rectangle} The area of the chunks that cover the box.
|
||||||
|
*/
|
||||||
|
ChunkCache.CalculateChunkArea = function(visibleArea, chunkSize) {
|
||||||
|
return new Rectangle(
|
||||||
|
Math.floor(visibleArea.x / chunkSize) * chunkSize,
|
||||||
|
Math.floor(visibleArea.y / chunkSize) * chunkSize,
|
||||||
|
(Math.ceil((Math.abs(visibleArea.x) + (visibleArea.width)) / chunkSize) * chunkSize),
|
||||||
|
(Math.ceil((Math.abs(visibleArea.y) + (visibleArea.height)) / chunkSize) * chunkSize)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export default ChunkCache;
|
export default ChunkCache;
|
||||||
|
|
Loading…
Reference in a new issue