mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:10:46 +00:00
Fix UnitLayer perf counters in prod overlay
This commit is contained in:
@@ -485,11 +485,15 @@ export class GameRenderer {
|
||||
|
||||
const tickLayerDurations: Record<string, number> = {};
|
||||
const layerCounters: Record<string, Record<string, number>> = {};
|
||||
let unitLayerCounters: Record<string, number> | null = null;
|
||||
|
||||
for (const layer of this.layers) {
|
||||
if (!layer.tick) {
|
||||
const counters = layer.getPerfCounters?.();
|
||||
if (counters && Object.keys(counters).length > 0) {
|
||||
if (layer instanceof UnitLayer) {
|
||||
unitLayerCounters = counters;
|
||||
}
|
||||
const label = layer.constructor?.name ?? "UnknownLayer";
|
||||
layerCounters[label] = counters;
|
||||
}
|
||||
@@ -519,12 +523,16 @@ export class GameRenderer {
|
||||
|
||||
const counters = layer.getPerfCounters?.();
|
||||
if (counters && Object.keys(counters).length > 0) {
|
||||
if (layer instanceof UnitLayer) {
|
||||
unitLayerCounters = counters;
|
||||
}
|
||||
const label = layer.constructor?.name ?? "UnknownLayer";
|
||||
layerCounters[label] = counters;
|
||||
}
|
||||
}
|
||||
|
||||
this.performanceOverlay.updateLayerCounters(layerCounters);
|
||||
this.performanceOverlay.updateUnitLayerCounters(unitLayerCounters);
|
||||
|
||||
if (shouldProfileTick) {
|
||||
this.performanceOverlay.updateTickLayerMetrics(tickLayerDurations);
|
||||
|
||||
@@ -133,6 +133,9 @@ export class PerformanceOverlay extends LitElement implements Layer {
|
||||
@state()
|
||||
private layerCounters: Record<string, Record<string, number>> = {};
|
||||
|
||||
@state()
|
||||
private unitLayerCounters: Record<string, number> | null = null;
|
||||
|
||||
// Smoothed per-layer render-per-tick timings (EMA over recent ticks)
|
||||
private renderPerTickLayerStats: Map<
|
||||
string,
|
||||
@@ -734,6 +737,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
|
||||
this.renderLastTickLayerTotalMs = 0;
|
||||
this.renderLastTickLayerDurations = {};
|
||||
this.layerCounters = {};
|
||||
this.unitLayerCounters = null;
|
||||
this.renderPerTickLayerStats.clear();
|
||||
this.renderLayersExpanded = false;
|
||||
this.tickLayersExpanded = false;
|
||||
@@ -909,6 +913,11 @@ export class PerformanceOverlay extends LitElement implements Layer {
|
||||
this.layerCounters = counters;
|
||||
}
|
||||
|
||||
updateUnitLayerCounters(counters: Record<string, number> | null) {
|
||||
if (!this.isVisible) return;
|
||||
this.unitLayerCounters = counters;
|
||||
}
|
||||
|
||||
updateTickMetrics(tickExecutionDuration?: number, tickDelay?: number) {
|
||||
if (!this.isVisible) return;
|
||||
|
||||
@@ -1029,6 +1038,9 @@ export class PerformanceOverlay extends LitElement implements Layer {
|
||||
this.tickLayerStats,
|
||||
).map((layer) => ({ ...layer })),
|
||||
layerCounters: { ...this.layerCounters },
|
||||
unitLayerCounters: this.unitLayerCounters
|
||||
? { ...this.unitLayerCounters }
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1112,7 +1124,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
|
||||
|
||||
const renderLayersToShow = renderLayerBreakdown.slice(0, 10);
|
||||
const tickLayersToShow = tickLayerBreakdown.slice(0, 10);
|
||||
const unitLayerCounters = this.layerCounters.UnitLayer ?? null;
|
||||
const unitLayerCounters = this.unitLayerCounters;
|
||||
|
||||
const maxLayerAvg =
|
||||
renderLayersToShow.length > 0
|
||||
|
||||
Reference in New Issue
Block a user