Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-env node */
module.exports = {
root: true,
env: {
es2022: true
},
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended'
Expand Down
26 changes: 14 additions & 12 deletions common/webapp/src/js/BlueMapApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import "./BlueMap";
import {MapViewer} from "./MapViewer";
import {MapControls} from "./controls/map/MapControls";
import {FreeFlightControls} from "./controls/freeflight/FreeFlightControls";
import {FileLoader, MathUtils, Vector3} from "three";
import {MathUtils, Vector3} from "three";
import {Map as BlueMapMap} from "./map/Map";
import {alert, animate, EasingFunctions, generateCacheHash} from "./util/Utils";
import {alert, animate, EasingFunctions} from "./util/Utils";
import {MainMenu} from "./MainMenu";
import {PopupMarker} from "./PopupMarker";
import {MarkerSet} from "./markers/MarkerSet";
import {getLocalStorage, round, setLocalStorage} from "./Utils";
import {RevalidatingFileLoader} from "./util/RevalidatingFileLoader";
import {i18n, setLanguage} from "../i18n";
import {PlayerMarkerManager} from "./markers/PlayerMarkerManager";
import {NormalMarkerManager} from "./markers/NormalMarkerManager";
Expand Down Expand Up @@ -310,7 +311,7 @@ export class BlueMapApp {
let map = new BlueMapMap(mapId, settings.mapDataRoot + "/" + mapId, settings.liveDataRoot + "/" + mapId, this.loadBlocker, this.mapViewer.events);
maps.push(map);

return map.loadSettings(this.mapViewer.tileCacheHash)
return map.loadSettings(this.mapViewer.revalidatedUrls)
.catch(error => {
alert(this.events, `Failed to load settings for map '${map.data.id}':` + error, "warning");
});
Expand Down Expand Up @@ -366,9 +367,10 @@ export class BlueMapApp {
*/
loadSettings() {
return new Promise((resolve, reject) => {
let loader = new FileLoader();
let loader = new RevalidatingFileLoader();
loader.setRevalidatedUrls(new Set()); // force no-cache requests
loader.setResponseType("json");
loader.load("settings.json?" + generateCacheHash(),
loader.load("settings.json",
resolve,
() => {},
() => reject("Failed to load the settings.json!")
Expand All @@ -382,9 +384,10 @@ export class BlueMapApp {
*/
loadPlayerData(map) {
return new Promise((resolve, reject) => {
let loader = new FileLoader();
let loader = new RevalidatingFileLoader();
loader.setRevalidatedUrls(new Set()); // force no-cache requests
loader.setResponseType("json");
loader.load(map.data.liveDataRoot + "/live/players.json?" + generateCacheHash(),
loader.load(map.data.liveDataRoot + "/live/players.json",
fileData => {
if (!fileData) reject(`Failed to parse '${this.fileUrl}'!`);
else resolve(fileData);
Expand Down Expand Up @@ -636,11 +639,11 @@ export class BlueMapApp {
return;
}

// Only reuse the user's tile cash hash if the current browser navigation event is not a reload.
// If it's a reload, we assume the user is troubleshooting and actually wants to refresh the map.
// If it's a reload, we assume the user is troubleshooting and actually
// wants to fully refresh the map.
const [entry] = performance.getEntriesByType("navigation");
if (entry.type != "reload") {
this.mapViewer.clearTileCache(this.loadUserSetting("tileCacheHash", this.mapViewer.tileCacheHash));
if (entry.type === "reload") {
this.mapViewer.clearTileCache();
}

this.mapViewer.superSampling = this.loadUserSetting("superSampling", this.mapViewer.data.superSampling);
Expand All @@ -665,7 +668,6 @@ export class BlueMapApp {
if (!this.settings.useCookies) return;

this.saveUserSetting("resetSettings", false);
this.saveUserSetting("tileCacheHash", this.mapViewer.tileCacheHash);

this.saveUserSetting("superSampling", this.mapViewer.data.superSampling);
this.saveUserSetting("hiresViewDistance", this.mapViewer.data.loadedHiresViewDistance);
Expand Down
21 changes: 12 additions & 9 deletions common/webapp/src/js/MapViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {Map} from "./map/Map";
import {SkyboxScene} from "./skybox/SkyboxScene";
import {ControlsManager} from "./controls/ControlsManager";
import Stats from "./util/Stats";
import {alert, dispatchEvent, elementOffset, generateCacheHash, htmlToElement, softClamp} from "./util/Utils";
import {alert, dispatchEvent, elementOffset, htmlToElement, softClamp} from "./util/Utils";
import {TileManager} from "./map/TileManager";
import {HIRES_VERTEX_SHADER} from "./map/hires/HiresVertexShader";
import {HIRES_FRAGMENT_SHADER} from "./map/hires/HiresFragmentShader";
Expand Down Expand Up @@ -79,7 +79,12 @@ export class MapViewer {
loadedLowresViewDistance: 2000,
});

this.tileCacheHash = generateCacheHash();
/** @import { RevalidatingFileLoader } from "./util/RevalidatingFileLoader" */
/**
* Used by {@link RevalidatingFileLoader}.
* @type {Set<string> | undefined}
*/
this.revalidatedUrls = undefined;

this.stats = new Stats();
this.stats.hide();
Expand Down Expand Up @@ -405,7 +410,7 @@ export class MapViewer {
this.map = map;

if (this.map && this.map.isMap) {
return map.load(HIRES_VERTEX_SHADER, HIRES_FRAGMENT_SHADER, LOWRES_VERTEX_SHADER, LOWRES_FRAGMENT_SHADER, this.data.uniforms, this.tileCacheHash)
return map.load(HIRES_VERTEX_SHADER, HIRES_FRAGMENT_SHADER, LOWRES_VERTEX_SHADER, LOWRES_FRAGMENT_SHADER, this.data.uniforms, this.revalidatedUrls)
.then(() => {
for (let texture of this.map.loadedTextures){
this.renderer.initTexture(texture);
Expand Down Expand Up @@ -462,15 +467,13 @@ export class MapViewer {
}
}

clearTileCache(newTileCacheHash) {
if (!newTileCacheHash) newTileCacheHash = generateCacheHash();

this.tileCacheHash = newTileCacheHash;
clearTileCache() {
this.revalidatedUrls = new Set();
if (this.map) {
for (let i = 0; i < this.map.lowresTileManager.length; i++) {
this.map.lowresTileManager[i].tileLoader.tileCacheHash = this.tileCacheHash;
this.map.lowresTileManager[i].tileLoader.revalidatedUrls = this.revalidatedUrls;
}
this.map.hiresTileManager.tileLoader.tileCacheHash = this.tileCacheHash;
this.map.hiresTileManager.tileLoader.revalidatedUrls = this.revalidatedUrls;
}
}

Expand Down
12 changes: 7 additions & 5 deletions common/webapp/src/js/map/LowresTileLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
import {pathFromCoords} from "../util/Utils";
import {
TextureLoader,
Mesh,
PlaneGeometry,
FrontSide,
Expand All @@ -34,23 +33,25 @@ import {
NearestMipMapLinearFilter,
Vector2
} from "three";
import {RevalidatingTextureLoader} from "../util/RevalidatingTextureLoader";

export class LowresTileLoader {

constructor(tilePath, tileSettings, lod, vertexShader, fragmentShader, uniforms, loadBlocker = () => Promise.resolve(), tileCacheHash = 0) {
constructor(tilePath, tileSettings, lod, vertexShader, fragmentShader, uniforms, loadBlocker = () => Promise.resolve(), revalidatedUrls) {
Object.defineProperty( this, 'isLowresTileLoader', { value: true } );

this.tilePath = tilePath;
this.tileSettings = tileSettings;
this.lod = lod;
this.loadBlocker = loadBlocker;
this.tileCacheHash = tileCacheHash;
this.revalidatedUrls = revalidatedUrls;

this.vertexShader = vertexShader;
this.fragmentShader = fragmentShader;
this.uniforms = uniforms;

this.textureLoader = new TextureLoader();
this.textureLoader = new RevalidatingTextureLoader();
this.textureLoader.setRevalidatedUrls(this.revalidatedUrls);
this.geometry = new PlaneGeometry(
tileSettings.tileSize.x + 1, tileSettings.tileSize.z + 1,
Math.ceil(100 / (lod * 2)), Math.ceil(100 / (lod * 2))
Expand All @@ -66,7 +67,8 @@ export class LowresTileLoader {

//await this.loadBlocker();
return new Promise((resolve, reject) => {
this.textureLoader.load(tileUrl + '?' + this.tileCacheHash,
this.textureLoader.setRevalidatedUrls(this.revalidatedUrls);
this.textureLoader.load(tileUrl,
async texture => {
texture.anisotropy = 1;
texture.generateMipmaps = false;
Expand Down
32 changes: 17 additions & 15 deletions common/webapp/src/js/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import {
ClampToEdgeWrapping,
Color,
FileLoader,
FrontSide,
NearestFilter,
NearestMipMapLinearFilter,
Expand All @@ -34,6 +33,7 @@ import {
Texture,
Vector3
} from "three";
import {RevalidatingFileLoader} from "../util/RevalidatingFileLoader";
import {alert, dispatchEvent, getPixel, hashTile, stringToImage, vecArrToObj} from "../util/Utils";
import {TileManager} from "./TileManager";
import {TileLoader} from "./TileLoader";
Expand Down Expand Up @@ -110,14 +110,14 @@ export class Map {
* @param lowresVertexShader {string}
* @param lowresFragmentShader {string}
* @param uniforms {object}
* @param tileCacheHash {number}
* @param revalidatedUrls {Set<string> | undefined}
* @returns {Promise<void>}
*/
load(hiresVertexShader, hiresFragmentShader, lowresVertexShader, lowresFragmentShader, uniforms, tileCacheHash = 0) {
load(hiresVertexShader, hiresFragmentShader, lowresVertexShader, lowresFragmentShader, uniforms, revalidatedUrls) {
this.unload()

let settingsPromise = this.loadSettings(tileCacheHash);
let textureFilePromise = this.loadTexturesFile(tileCacheHash);
let settingsPromise = this.loadSettings(revalidatedUrls);
let textureFilePromise = this.loadTexturesFile(revalidatedUrls);

this.lowresMaterial = this.createLowresMaterial(lowresVertexShader, lowresFragmentShader, uniforms);

Expand All @@ -133,7 +133,7 @@ export class Map {
this.hiresMaterial,
this.data.hires,
this.loadBlocker,
tileCacheHash
revalidatedUrls
), this.onTileLoad("hires"), this.onTileUnload("hires"), this.events);
this.hiresTileManager.scene.matrixWorldAutoUpdate = false;

Expand All @@ -147,7 +147,7 @@ export class Map {
lowresFragmentShader,
uniforms,
async () => {},
tileCacheHash
revalidatedUrls
), this.onTileLoad("lowres"), this.onTileUnload("lowres"), this.events);
this.lowresTileManager[i].scene.matrixWorldAutoUpdate = false;
}
Expand All @@ -160,8 +160,8 @@ export class Map {
* Loads the settings of this map
* @returns {Promise<void>}
*/
loadSettings(tileCacheHash) {
return this.loadSettingsFile(tileCacheHash)
loadSettings(revalidatedUrls) {
return this.loadSettingsFile(revalidatedUrls)
.then(worldSettings => {
this.data.name = worldSettings.name ? worldSettings.name : this.data.name;

Expand Down Expand Up @@ -259,13 +259,14 @@ export class Map {
* Loads the settings.json file for this map
* @returns {Promise<Object>}
*/
loadSettingsFile(tileCacheHash) {
loadSettingsFile(revalidatedUrls) {
return new Promise((resolve, reject) => {
alert(this.events, `Loading settings for map '${this.data.id}'...`, "fine");

let loader = new FileLoader();
let loader = new RevalidatingFileLoader();
loader.setRevalidatedUrls(revalidatedUrls);
loader.setResponseType("json");
loader.load(this.data.settingsUrl + "?" + tileCacheHash,
loader.load(this.data.settingsUrl,
resolve,
() => {},
() => reject(`Failed to load the settings.json for map: ${this.data.id}`)
Expand All @@ -277,13 +278,14 @@ export class Map {
* Loads the textures.json file for this map
* @returns {Promise<Object>}
*/
loadTexturesFile(tileCacheHash) {
loadTexturesFile(revalidatedUrls) {
return new Promise((resolve, reject) => {
alert(this.events, `Loading textures for map '${this.data.id}'...`, "fine");

let loader = new FileLoader();
let loader = new RevalidatingFileLoader();
loader.setRevalidatedUrls(revalidatedUrls);
loader.setResponseType("json");
loader.load(this.data.texturesUrl + "?" + tileCacheHash,
loader.load(this.data.texturesUrl,
resolve,
() => {},
() => reject(`Failed to load the textures.json for map: ${this.data.id}`)
Expand Down
15 changes: 9 additions & 6 deletions common/webapp/src/js/map/TileLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
* THE SOFTWARE.
*/
import {pathFromCoords} from "../util/Utils";
import {BufferGeometryLoader, FileLoader, Mesh, Material} from "three";
import {BufferGeometryLoader, Mesh, Material} from "three";
import {PRBMLoader} from "./hires/PRBMLoader";
import {RevalidatingFileLoader} from "../util/RevalidatingFileLoader";

export class TileLoader {

Expand All @@ -37,21 +38,22 @@ export class TileLoader {
* translate: {x: number, z: number}
* }}
* @param loadBlocker {function: Promise}
* @param tileCacheHash {number}
* @param revalidatedUrls {Set<string> | undefined}
*/
constructor(tilePath, material, tileSettings, loadBlocker = () => Promise.resolve(), tileCacheHash = 0) {
constructor(tilePath, material, tileSettings, loadBlocker = () => Promise.resolve(), revalidatedUrls) {
Object.defineProperty( this, 'isTileLoader', { value: true } );

this.tilePath = tilePath;
this.material = material;
this.tileSettings = tileSettings;

this.tileCacheHash = tileCacheHash;
this.revalidatedUrls = revalidatedUrls;

this.loadBlocker = loadBlocker;

this.fileLoader = new FileLoader();
this.fileLoader = new RevalidatingFileLoader();
this.fileLoader.setResponseType('arraybuffer');
this.fileLoader.setRevalidatedUrls(this.revalidatedUrls);

this.bufferGeometryLoader = new PRBMLoader();
}
Expand All @@ -60,7 +62,8 @@ export class TileLoader {
let tileUrl = this.tilePath + pathFromCoords(tileX, tileZ) + '.prbm';

return new Promise((resolve, reject) => {
this.fileLoader.load(tileUrl + '?' + this.tileCacheHash,
this.fileLoader.setRevalidatedUrls(this.revalidatedUrls);
this.fileLoader.load(tileUrl,
async data => {

await this.loadBlocker();
Expand Down
11 changes: 6 additions & 5 deletions common/webapp/src/js/markers/MarkerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import {FileLoader} from "three";
import {MarkerSet} from "./MarkerSet";
import {alert, generateCacheHash} from "../util/Utils";
import {alert} from "../util/Utils";
import {RevalidatingFileLoader} from "../util/RevalidatingFileLoader";

/**
* A manager for loading and updating markers from a file
Expand Down Expand Up @@ -116,9 +116,10 @@ export class MarkerManager {
*/
loadMarkerFile() {
return new Promise((resolve, reject) => {
let loader = new FileLoader();
let loader = new RevalidatingFileLoader();
loader.setRevalidatedUrls(new Set()); // force no-cache requests
loader.setResponseType("json");
loader.load(this.fileUrl + "?" + generateCacheHash(),
loader.load(this.fileUrl,
markerFileData => {
if (!markerFileData) reject(`Failed to parse '${this.fileUrl}'!`);
else resolve(markerFileData);
Expand All @@ -129,4 +130,4 @@ export class MarkerManager {
});
}

}
}
Loading
Loading