Further performance improvements
This commit is contained in:
parent
b2880700e8
commit
b7efda9bf6
|
@ -13,7 +13,7 @@ import { round1Digit } from "./utils";
|
||||||
|
|
||||||
const logger = createLogger("buffers");
|
const logger = createLogger("buffers");
|
||||||
|
|
||||||
const bufferGcDurationSeconds = 10;
|
const bufferGcDurationSeconds = 5;
|
||||||
|
|
||||||
export class BufferMaintainer {
|
export class BufferMaintainer {
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,29 @@ export class BufferMaintainer {
|
||||||
this.root.signals.gameFrameStarted.add(this.update, this);
|
this.root.signals.gameFrameStarted.add(this.update, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the buffer stats
|
||||||
|
*/
|
||||||
|
getStats() {
|
||||||
|
let stats = {
|
||||||
|
rootKeys: 0,
|
||||||
|
subKeys: 0,
|
||||||
|
vramBytes: 0,
|
||||||
|
};
|
||||||
|
this.cache.forEach((subCache, key) => {
|
||||||
|
++stats.rootKeys;
|
||||||
|
|
||||||
|
subCache.forEach((cacheEntry, subKey) => {
|
||||||
|
++stats.subKeys;
|
||||||
|
|
||||||
|
const canvas = cacheEntry.canvas;
|
||||||
|
stats.vramBytes += canvas.width * canvas.height * 4;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Goes to the next buffer iteration, clearing all buffers which were not used
|
* Goes to the next buffer iteration, clearing all buffers which were not used
|
||||||
* for a few iterations
|
* for a few iterations
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { gMetaBuildingRegistry } from "../core/global_registries";
|
import { gMetaBuildingRegistry } from "../core/global_registries";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { Rectangle } from "../core/rectangle";
|
import { Rectangle } from "../core/rectangle";
|
||||||
import { randomInt, round2Digits } from "../core/utils";
|
import { randomInt, round2Digits, round3Digits } from "../core/utils";
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { Savegame } from "../savegame/savegame";
|
import { Savegame } from "../savegame/savegame";
|
||||||
import { SavegameSerializer } from "../savegame/savegame_serializer";
|
import { SavegameSerializer } from "../savegame/savegame_serializer";
|
||||||
|
@ -454,7 +454,7 @@ export class GameCore {
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.showAtlasInfo) {
|
if (G_IS_DEV && globalConfig.debug.showAtlasInfo) {
|
||||||
context.font = "13px GameFont";
|
context.font = "13px GameFont";
|
||||||
context.fillStyle = "yellow";
|
context.fillStyle = "blue";
|
||||||
context.fillText(
|
context.fillText(
|
||||||
"Atlas: " +
|
"Atlas: " +
|
||||||
desiredAtlasScale +
|
desiredAtlasScale +
|
||||||
|
@ -462,8 +462,22 @@ export class GameCore {
|
||||||
round2Digits(zoomLevel) +
|
round2Digits(zoomLevel) +
|
||||||
" / Effective Zoom: " +
|
" / Effective Zoom: " +
|
||||||
round2Digits(effectiveZoomLevel),
|
round2Digits(effectiveZoomLevel),
|
||||||
200,
|
20,
|
||||||
20
|
600
|
||||||
|
);
|
||||||
|
|
||||||
|
const stats = this.root.buffers.getStats();
|
||||||
|
context.fillText(
|
||||||
|
"Buffers: " +
|
||||||
|
stats.rootKeys +
|
||||||
|
" root keys, " +
|
||||||
|
stats.subKeys +
|
||||||
|
" sub keys / buffers / VRAM: " +
|
||||||
|
round2Digits(stats.vramBytes / (1024 * 1024)) +
|
||||||
|
" MB",
|
||||||
|
|
||||||
|
20,
|
||||||
|
620
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,10 @@ export class ColorItem extends BaseItem {
|
||||||
|
|
||||||
const realDiameter = diameter * 0.6;
|
const realDiameter = diameter * 0.6;
|
||||||
const dpi = smoothenDpi(globalConfig.shapesSharpness * parameters.zoomLevel);
|
const dpi = smoothenDpi(globalConfig.shapesSharpness * parameters.zoomLevel);
|
||||||
const key = realDiameter + "/" + dpi;
|
const key = realDiameter + "/" + dpi + "/" + this.color;
|
||||||
const canvas = parameters.root.buffers.getForKey({
|
const canvas = parameters.root.buffers.getForKey({
|
||||||
key,
|
key: "coloritem",
|
||||||
subKey: this.color,
|
subKey: key,
|
||||||
w: realDiameter,
|
w: realDiameter,
|
||||||
h: realDiameter,
|
h: realDiameter,
|
||||||
dpi,
|
dpi,
|
||||||
|
|
|
@ -284,10 +284,10 @@ export class ShapeDefinition extends BasicSerializableObject {
|
||||||
this.bufferGenerator = this.internalGenerateShapeBuffer.bind(this);
|
this.bufferGenerator = this.internalGenerateShapeBuffer.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = diameter + "/" + dpi;
|
const key = diameter + "/" + dpi + "/" + this.cachedHash;
|
||||||
const canvas = parameters.root.buffers.getForKey({
|
const canvas = parameters.root.buffers.getForKey({
|
||||||
key,
|
key: "shapedef",
|
||||||
subKey: this.cachedHash,
|
subKey: key,
|
||||||
w: diameter,
|
w: diameter,
|
||||||
h: diameter,
|
h: diameter,
|
||||||
dpi,
|
dpi,
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class MapResourcesSystem extends GameSystem {
|
||||||
*/
|
*/
|
||||||
drawChunk(parameters, chunk) {
|
drawChunk(parameters, chunk) {
|
||||||
const basicChunkBackground = this.root.buffers.getForKey({
|
const basicChunkBackground = this.root.buffers.getForKey({
|
||||||
key: "chunkres",
|
key: "mapresourcebg",
|
||||||
subKey: chunk.renderKey,
|
subKey: chunk.renderKey,
|
||||||
w: globalConfig.mapChunkSize,
|
w: globalConfig.mapChunkSize,
|
||||||
h: globalConfig.mapChunkSize,
|
h: globalConfig.mapChunkSize,
|
||||||
|
|
Loading…
Reference in New Issue