mirror of
https://github.com/BlueMap-Minecraft/BlueMapWeb.git
synced 2025-02-17 18:31:21 +01:00
Switch using Map for a map instead of an Object
This commit is contained in:
parent
d2daa47fab
commit
92dd2136a3
@ -293,10 +293,10 @@ export class Map {
|
||||
this.raycaster.layers.enableAll();
|
||||
|
||||
let hiresTileHash = hashTile(Math.floor((x - this.hires.translate.x) / this.hires.tileSize.x), Math.floor((z - this.hires.translate.z) / this.hires.tileSize.z));
|
||||
let tile = this.hiresTileManager.tiles[hiresTileHash];
|
||||
let tile = this.hiresTileManager.tiles.get(hiresTileHash);
|
||||
if (!tile || !tile.model) {
|
||||
let lowresTileHash = hashTile(Math.floor((x - this.lowres.translate.x) / this.lowres.tileSize.x), Math.floor((z - this.lowres.translate.z) / this.lowres.tileSize.z));
|
||||
tile = this.lowresTileManager.tiles[lowresTileHash];
|
||||
tile = this.lowresTileManager.tiles.get(lowresTileHash);
|
||||
}
|
||||
|
||||
if (!tile || !tile.model){
|
||||
|
@ -51,7 +51,7 @@ export class TileManager {
|
||||
this.loadTimeout = null;
|
||||
|
||||
//map of loaded tiles
|
||||
this.tiles = {};
|
||||
this.tiles = new Map();
|
||||
|
||||
// a canvas that keeps track of the loaded tiles, used for shaders
|
||||
this.tileMap = new TileMap(TileManager.tileMapSize, TileManager.tileMapSize);
|
||||
@ -70,15 +70,11 @@ export class TileManager {
|
||||
this.removeFarTiles();
|
||||
|
||||
this.tileMap.setAll(TileMap.EMPTY);
|
||||
let keys = Object.keys(this.tiles);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!this.tiles.hasOwnProperty(keys[i])) continue;
|
||||
|
||||
let tile = this.tiles[keys[i]];
|
||||
this.tiles.forEach(tile => {
|
||||
if (!tile.loading) {
|
||||
this.tileMap.setTile(tile.x - this.centerTile.x + TileManager.tileMapHalfSize, tile.z - this.centerTile.y + TileManager.tileMapHalfSize, TileMap.LOADED);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.loadCloseTiles();
|
||||
@ -90,11 +86,7 @@ export class TileManager {
|
||||
}
|
||||
|
||||
removeFarTiles() {
|
||||
let keys = Object.keys(this.tiles);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!this.tiles.hasOwnProperty(keys[i])) continue;
|
||||
|
||||
let tile = this.tiles[keys[i]];
|
||||
this.tiles.forEach((tile, hash, map) => {
|
||||
if (
|
||||
tile.x + this.viewDistanceX < this.centerTile.x ||
|
||||
tile.x - this.viewDistanceX > this.centerTile.x ||
|
||||
@ -102,22 +94,18 @@ export class TileManager {
|
||||
tile.z - this.viewDistanceZ > this.centerTile.y
|
||||
) {
|
||||
tile.unload();
|
||||
delete this.tiles[keys[i]];
|
||||
map.delete(hash);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
removeAllTiles() {
|
||||
this.tileMap.setAll(TileMap.EMPTY);
|
||||
|
||||
let keys = Object.keys(this.tiles);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!this.tiles.hasOwnProperty(keys[i])) continue;
|
||||
|
||||
let tile = this.tiles[keys[i]];
|
||||
this.tiles.forEach(tile => {
|
||||
tile.unload();
|
||||
delete this.tiles[keys[i]];
|
||||
}
|
||||
});
|
||||
this.tiles.clear();
|
||||
}
|
||||
|
||||
loadCloseTiles = () => {
|
||||
@ -166,13 +154,13 @@ export class TileManager {
|
||||
|
||||
let tileHash = hashTile(x, z);
|
||||
|
||||
let tile = this.tiles[tileHash];
|
||||
let tile = this.tiles.get(tileHash);
|
||||
if (tile !== undefined) return false;
|
||||
|
||||
this.currentlyLoading++;
|
||||
|
||||
tile = new Tile(x, z, this.handleLoadedTile, this.handleUnloadedTile);
|
||||
this.tiles[tileHash] = tile;
|
||||
this.tiles.set(tileHash, tile);
|
||||
tile.load(this.tileLoader)
|
||||
.then(() => {
|
||||
this.tileMap.setTile(tile.x - this.centerTile.x + TileManager.tileMapHalfSize, tile.z - this.centerTile.y + TileManager.tileMapHalfSize, TileMap.LOADED);
|
||||
|
Loading…
Reference in New Issue
Block a user