forked from Blendman974/faceclaw
Display lists
This commit is contained in:
1 parent
a7af84e231
commit
4320021222
44 files changed
+823
-284
No files matched your search
+16
-4
@@ -80,6 +80,7 @@ export interface LayerContext {
|
||||
}
|
||||
|
||||
export interface Layer {
|
||||
paintParts?(): Plane[];
|
||||
readonly paintOverBase?: boolean;
|
||||
/**
|
||||
* Dim everything painted beneath this layer: a 0..1 brightness factor
|
||||
@@ -116,6 +117,12 @@ export interface Layer {
|
||||
|
||||
export class LayerStack {
|
||||
private readonly layers: Layer[];
|
||||
private static nextShellKey = 3;
|
||||
static allocateShellKey(): number {
|
||||
if (this.nextShellKey > 65535) this.nextShellKey = 3;
|
||||
return this.nextShellKey++;
|
||||
}
|
||||
private readonly shellKeys = new WeakMap<Layer, number>();
|
||||
private readonly ctx: LayerContext;
|
||||
private baseWidth: number;
|
||||
private baseHeight: number;
|
||||
@@ -225,6 +232,8 @@ export class LayerStack {
|
||||
* A stack whose base is transparent over something else (the shell chrome
|
||||
* over the window surfaces) forwards this to what lies beneath.
|
||||
*/
|
||||
paintUndimmed(): Plane[] { return this.paintLayer(this.layers.length - 1, 1, true); }
|
||||
|
||||
baseDim(): number | false {
|
||||
return this.lastBaseDim;
|
||||
}
|
||||
@@ -259,8 +268,11 @@ export class LayerStack {
|
||||
|
||||
|
||||
/** Paint layer `index`; `dimSoFar` is the factor the layers above apply to it. */
|
||||
private paintLayer(index: number, dimSoFar: number): Plane[] {
|
||||
private paintLayer(index: number, dimSoFar: number, raw = false): Plane[] {
|
||||
const layer = this.layers[index]!;
|
||||
if (raw && index === 0 && layer.paintParts) return layer.paintParts();
|
||||
let key = this.shellKeys.get(layer);
|
||||
if (key === undefined) { key = LayerStack.allocateShellKey(); this.shellKeys.set(layer, key); }
|
||||
let canvas: GrayImage | null = null;
|
||||
let belowRequested = false;
|
||||
const image = spanCurrent(`paint[${index}]:${layer.constructor.name}`, () =>
|
||||
@@ -272,7 +284,7 @@ export class LayerStack {
|
||||
return canvas;
|
||||
}),
|
||||
);
|
||||
const ownPlane: Plane = { image, x: 0, y: 0 };
|
||||
const ownPlane: Plane = { image, x: 0, y: 0, shellKey: key, dimUnderneath: layer.dimUnderneath === false ? 1 : layer.dimUnderneath };
|
||||
if (index <= 0) {
|
||||
this.lastBaseDim = dimSoFar;
|
||||
return [ownPlane];
|
||||
@@ -281,7 +293,7 @@ export class LayerStack {
|
||||
return [ownPlane];
|
||||
}
|
||||
const dim = layer.dimUnderneath || 1;
|
||||
const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim);
|
||||
return [...(dim < 1 ? dimPlanes(below, dim) : below), ownPlane];
|
||||
const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim, raw);
|
||||
return [...(!raw && dim < 1 ? dimPlanes(below, dim) : below), ownPlane];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user