Refactor GUI rendering and align RTA axis
This commit is contained in:
+11
-17
@@ -1,5 +1,6 @@
|
||||
// core/registry.js — Lazy Loader + Safe Runner für Meter
|
||||
// Lädt Meter-Module on-demand (oder via registerMeter) und kapselt Fehler.
|
||||
import { createCanvasSurface } from './canvas_surface.js';
|
||||
|
||||
const cache = {
|
||||
meters: new Map(), // id -> module
|
||||
@@ -7,26 +8,12 @@ const cache = {
|
||||
|
||||
const meterRenderCache = new Map(); // key -> surface
|
||||
const METER_CACHE_MARGIN = 32;
|
||||
const METER_RENDER_CACHE_LIMIT = 48;
|
||||
let activeFrameStamp = 0;
|
||||
|
||||
const CAN_USE_OFFSCREEN = typeof OffscreenCanvas === 'function';
|
||||
|
||||
function createCacheSurface(width, height) {
|
||||
const w = Math.max(1, Math.ceil(width));
|
||||
const h = Math.max(1, Math.ceil(height));
|
||||
if (CAN_USE_OFFSCREEN) {
|
||||
const canvas = new OffscreenCanvas(w, h);
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) return { canvas, ctx, width: w, height: h, stamp: -1 };
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) return { canvas, ctx, width: w, height: h, stamp: -1 };
|
||||
}
|
||||
return null;
|
||||
const surface = createCanvasSurface(width, height);
|
||||
return surface ? { ...surface, stamp: -1 } : null;
|
||||
}
|
||||
|
||||
function cacheKeyForMeter(id, rect) {
|
||||
@@ -40,10 +27,17 @@ function cacheKeyForMeter(id, rect) {
|
||||
function ensureCacheSurface(id, rect) {
|
||||
const key = cacheKeyForMeter(id, rect);
|
||||
let surface = meterRenderCache.get(key);
|
||||
if (surface) {
|
||||
meterRenderCache.delete(key);
|
||||
meterRenderCache.set(key, surface);
|
||||
}
|
||||
if (!surface) {
|
||||
surface = createCacheSurface(rect.w + METER_CACHE_MARGIN * 2, rect.h + METER_CACHE_MARGIN * 2);
|
||||
if (!surface) return null;
|
||||
meterRenderCache.set(key, surface);
|
||||
while (meterRenderCache.size > METER_RENDER_CACHE_LIMIT) {
|
||||
meterRenderCache.delete(meterRenderCache.keys().next().value);
|
||||
}
|
||||
}
|
||||
if (!surface.canvas || !surface.ctx) return null;
|
||||
const w = Math.max(1, Math.ceil(rect.w + METER_CACHE_MARGIN * 2));
|
||||
|
||||
Reference in New Issue
Block a user