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
@@ -9,6 +9,8 @@ type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean }
|
||||
|
||||
export class SurfaceCompositor {
|
||||
private readonly surfaces = new Map<string, Surface>()
|
||||
private shellScene: Uint8Array | null = null
|
||||
setShellScene(bytes: Uint8Array): void { this.shellScene = new Uint8Array(bytes) }
|
||||
private dimBelow = 0
|
||||
private dimFactor = 1
|
||||
private blanked = false
|
||||
@@ -55,11 +57,11 @@ export class SurfaceCompositor {
|
||||
composite(): Uint8Array {
|
||||
const output = new Uint8Array(this.width * this.height)
|
||||
if (this.blanked) return output
|
||||
const surfaces = [...this.surfaces.values()].filter(s => s.visible).sort((a, b) => a.zOrder - b.zOrder)
|
||||
const surfaces = [...this.surfaces.values()].filter(s => s.visible && !(this.shellScene && s === this.surfaces.get('shell'))).sort((a, b) => a.zOrder - b.zOrder)
|
||||
for (const surface of surfaces) {
|
||||
const left = Math.max(0, surface.x), right = Math.min(this.width, surface.x + surface.width)
|
||||
const top = Math.max(0, surface.y), bottom = Math.min(this.height, surface.y + surface.height)
|
||||
const dim = surface.zOrder < this.dimBelow ? this.dimFactor : 1
|
||||
const dim = !this.shellScene && surface.zOrder < this.dimBelow ? this.dimFactor : 1
|
||||
for (let y = top; y < bottom; y++) {
|
||||
let source = (y - surface.y) * surface.width + left - surface.x
|
||||
let target = y * this.width + left
|
||||
@@ -72,6 +74,21 @@ export class SurfaceCompositor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.shellScene && !surfaces.some(s => s.zOrder > 1)) {
|
||||
const quantize = (v: number) => Math.min(15, (v + 8) >> 4)
|
||||
for (let i=0;i<output.length;i++) output[i]=quantize(output[i])*16
|
||||
const bytes=this.shellScene, view=new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
||||
let p=2
|
||||
for(let i=0;i<view.getUint16(0,true);i++) {
|
||||
const x=view.getInt16(p+2,true), y=view.getInt16(p+4,true), w=view.getUint16(p+6,true), h=view.getUint16(p+8,true), dim=view.getUint16(p+10,true)
|
||||
p+=14
|
||||
if(dim<256) for(let j=0;j<output.length;j++) output[j]=Math.floor((output[j]/16)*dim/256)*16
|
||||
for(let yy=0;yy<h;yy++) for(let xx=0;xx<w;xx++) {
|
||||
if(x+xx>=0 && y+yy>=0 && x+xx<this.width && y+yy<this.height) output[(y+yy)*this.width+x+xx]=quantize(bytes[p+yy*w+xx])*16
|
||||
}
|
||||
p+=w*h
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user