UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

119 lines (99 loc) 2.19 kB
import { assert } from "../../../../core/assert.js"; import { FrameGraphNode } from "./FrameGraphNode.js"; /** * @template T */ export class FramePassNode extends FrameGraphNode { /** * * @param {T} data * @param {FramePassResources} resources * @param {IFrameGraphContext} context */ execute(data, resources, context) { // override } /** * * @type {boolean} */ has_side_effects = false; /** * * @type {Object} */ data = {}; /** * IDs of created resources * @type {number[]} */ resource_creates = []; /** * IDs of read resources * @type {number[]} */ resource_reads = []; /** * IDs of written resources * @type {number[]} */ resource_writes = []; /** * * @param {number} id * @return {boolean} */ creates(id) { assert.isNonNegativeInteger(id, 'id'); return this.resource_creates.includes(id); } /** * * @param {number} id * @return {boolean} */ reads(id) { assert.isNonNegativeInteger(id, 'id'); return this.resource_reads.includes(id); } /** * * @param {number} id * @return {boolean} */ writes(id) { assert.isNonNegativeInteger(id, 'id'); return this.resource_writes.includes(id); } /** * * @param {number} resource * @returns {number} */ write(resource) { if (this.writes(resource)) { return resource; } this.resource_writes.push(resource); return resource; } /** * * @param {number} resource * @returns {number} same as the input */ read(resource) { if (this.reads(resource)) { return resource; } this.resource_reads.push(resource); return resource; } /** * * @return {boolean} */ can_execute() { return this.ref_count > 0 || this.has_side_effects; } }