Set fallback void color to black, pause high fps redraws if nothing changes to save GPU usage

This commit is contained in:
Lukas Rieger (Blue) 2023-11-18 14:20:45 +01:00
parent c69b31ce84
commit 6d3774f24e
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
3 changed files with 14 additions and 4 deletions

View File

@ -113,6 +113,9 @@ export class MapViewer {
this.markers = new MarkerSet("bm-root");
this.lastFrame = 0;
this.lastRedrawChange = 0;
events.addEventListener("bluemapCameraMoved", () => this.lastRedrawChange = Date.now())
events.addEventListener("bluemapTileLoaded", () => this.lastRedrawChange = Date.now())
// initialize
this.initializeRootElement();
@ -272,7 +275,6 @@ export class MapViewer {
// calculate delta time
if (this.lastFrame <= 0) this.lastFrame = now;
let delta = now - this.lastFrame;
this.lastFrame = now;
// update stats
this.stats.begin();
@ -283,7 +285,10 @@ export class MapViewer {
}
// render
this.render(delta);
if (delta >= 1000 || Date.now() - this.lastRedrawChange < 1000) {
this.lastFrame = now;
this.render(delta);
}
// update stats
this.stats.update();

View File

@ -63,7 +63,7 @@ export class Map {
name: id,
startPos: {x: 0, z: 0},
skyColor: new Color(),
voidColor: new Color(),
voidColor: new Color(0, 0, 0),
ambientLight: 0,
hires: {
tileSize: {x: 32, z: 32},

View File

@ -24,7 +24,7 @@
*/
import { Vector2, Scene, Group } from 'three';
import { Tile } from './Tile.js';
import {alert, hashTile} from '../util/Utils.js';
import {alert, dispatchEvent, hashTile} from '../util/Utils.js';
import {TileMap} from "./TileMap";
export class TileManager {
@ -194,6 +194,11 @@ export class TileManager {
this.tiles.set(tileHash, tile);
tile.load(this.tileLoader)
.then(() => {
dispatchEvent(this.events, "bluemapTileLoaded", {
tileManager: this,
tile: tile
});
if (this.loadTimeout) clearTimeout(this.loadTimeout);
this.loadTimeout = setTimeout(this.loadCloseTiles, 0);
})