Warning, /firebird/packages/firebird-ng/display/src/lib/services/render-loop.ts is written in an unsupported language. File is not indexed.
0001 /**
0002 * Render-loop decisions, kept free of renderer state so specs can pin them.
0003 * ThreeService.renderLoop calls these once per animation frame.
0004 */
0005
0006 /** The per-view state the frame decision reads. */
0007 export interface DirtyFlag {
0008 dirty: boolean;
0009 }
0010
0011 /**
0012 * Whether this animation frame renders. Continuous mode renders every
0013 * frame; on-demand mode renders only when something set a dirty flag since
0014 * the last rendered frame: `invalidate()` (all views), controls 'change',
0015 * or a per-view knob. One dirty view renders a frame that repaints ALL
0016 * views (see ThreeService.renderLoop for why).
0017 */
0018 export function shouldRenderFrame(continuous: boolean, renderRequested: boolean, views: readonly DirtyFlag[]): boolean {
0019 return continuous || renderRequested || views.some(view => view.dirty);
0020 }
0021
0022 /**
0023 * Calls `invoke` for each target and isolates failures: a target that
0024 * throws is reported through `onError` and does not stop the remaining
0025 * targets. Returns the targets that threw, so the caller can disable them
0026 * (a hook that throws once usually throws on every frame).
0027 */
0028 export function runIsolated<T>(
0029 targets: readonly T[],
0030 invoke: (target: T) => void,
0031 onError: (target: T, error: unknown) => void,
0032 ): T[] {
0033 const failed: T[] = [];
0034 for (const target of targets) {
0035 try {
0036 invoke(target);
0037 } catch (error) {
0038 failed.push(target);
0039 onError(target, error);
0040 }
0041 }
0042 return failed;
0043 }