Full code cleanup

This commit is contained in:
Pieter Vander Vennet 2021-11-07 16:34:51 +01:00
parent 8e6ee8c87f
commit bd21212eba
246 changed files with 19418 additions and 11729 deletions

View file

@ -13,35 +13,35 @@ export default class TileFreshnessCalculator {
* @param tileId
* @param freshness
*/
public addTileLoad(tileId: number, freshness: Date){
public addTileLoad(tileId: number, freshness: Date) {
const existingFreshness = this.freshnessFor(...Tiles.tile_from_index(tileId))
if(existingFreshness >= freshness){
if (existingFreshness >= freshness) {
return;
}
this.freshnesses.set(tileId, freshness)
// Do we have freshness for the neighbouring tiles? If so, we can mark the tile above as loaded too!
let [z, x, y] = Tiles.tile_from_index(tileId)
if(z === 0){
if (z === 0) {
return;
}
x = x - (x % 2) // Make the tiles always even
y = y - (y % 2)
const ul = this.freshnessFor(z, x, y)?.getTime()
if(ul === undefined){
if (ul === undefined) {
return
}
const ur = this.freshnessFor(z, x + 1, y)?.getTime()
if(ur === undefined){
if (ur === undefined) {
return
}
const ll = this.freshnessFor(z, x, y + 1)?.getTime()
if(ll === undefined){
if (ll === undefined) {
return
}
const lr = this.freshnessFor(z, x + 1, y + 1)?.getTime()
if(lr === undefined){
if (lr === undefined) {
return
}
@ -50,22 +50,22 @@ export default class TileFreshnessCalculator {
date.setTime(leastFresh)
this.addTileLoad(
Tiles.tile_index(z - 1, Math.floor(x / 2), Math.floor(y / 2)),
date
date
)
}
public freshnessFor(z: number, x: number, y:number): Date {
if(z < 0){
public freshnessFor(z: number, x: number, y: number): Date {
if (z < 0) {
return undefined
}
const tileId = Tiles.tile_index(z, x, y)
if(this.freshnesses.has(tileId)) {
if (this.freshnesses.has(tileId)) {
return this.freshnesses.get(tileId)
}
// recurse up
return this.freshnessFor(z - 1, Math.floor(x /2), Math.floor(y / 2))
return this.freshnessFor(z - 1, Math.floor(x / 2), Math.floor(y / 2))
}
}