|
@@ -57,7 +57,9 @@ class NodeBuilder {
|
|
|
this.varyings = [];
|
|
|
this.vars = { vertex: [], fragment: [], compute: [] };
|
|
|
this.flow = { code: '' };
|
|
|
- this.stack = [];
|
|
|
+ this.chaining = [];
|
|
|
+ this.stack = stack();
|
|
|
+ this.tab = '\t';
|
|
|
|
|
|
this.context = {
|
|
|
keywords: new NodeKeywords(),
|
|
@@ -75,59 +77,59 @@ class NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
- get node() {
|
|
|
+ setHashNode( node, hash ) {
|
|
|
|
|
|
- return this.stack[ this.stack.length - 1 ];
|
|
|
+ this.hashNodes[ hash ] = node;
|
|
|
|
|
|
}
|
|
|
|
|
|
- addStack( node ) {
|
|
|
-
|
|
|
- /*
|
|
|
- if ( this.stack.indexOf( node ) !== - 1 ) {
|
|
|
-
|
|
|
- console.warn( 'Recursive node: ', node );
|
|
|
+ addNode( node ) {
|
|
|
|
|
|
- }
|
|
|
- */
|
|
|
+ if ( this.nodes.indexOf( node ) === - 1 ) {
|
|
|
|
|
|
- this.stack.push( node );
|
|
|
+ const updateType = node.getUpdateType( this );
|
|
|
|
|
|
- }
|
|
|
+ if ( updateType !== NodeUpdateType.NONE ) {
|
|
|
|
|
|
- removeStack( node ) {
|
|
|
+ this.updateNodes.push( node );
|
|
|
|
|
|
- const lastStack = this.stack.pop();
|
|
|
+ }
|
|
|
|
|
|
- if ( lastStack !== node ) {
|
|
|
+ this.nodes.push( node );
|
|
|
|
|
|
- throw new Error( 'NodeBuilder: Invalid node stack!' );
|
|
|
+ this.setHashNode( node, node.getHash( this ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- setHashNode( node, hash ) {
|
|
|
+ get currentNode() {
|
|
|
|
|
|
- this.hashNodes[ hash ] = node;
|
|
|
+ return this.chaining[ this.chaining.length - 1 ];
|
|
|
|
|
|
}
|
|
|
|
|
|
- addNode( node ) {
|
|
|
+ addChain( node ) {
|
|
|
|
|
|
- if ( this.nodes.indexOf( node ) === - 1 ) {
|
|
|
+ /*
|
|
|
+ if ( this.chaining.indexOf( node ) !== - 1 ) {
|
|
|
|
|
|
- const updateType = node.getUpdateType( this );
|
|
|
+ console.warn( 'Recursive node: ', node );
|
|
|
|
|
|
- if ( updateType !== NodeUpdateType.NONE ) {
|
|
|
+ }
|
|
|
+ */
|
|
|
|
|
|
- this.updateNodes.push( node );
|
|
|
+ this.chaining.push( node );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- this.nodes.push( node );
|
|
|
+ removeChain( node ) {
|
|
|
|
|
|
- this.setHashNode( node, node.getHash( this ) );
|
|
|
+ const lastChain = this.chaining.pop();
|
|
|
+
|
|
|
+ if ( lastChain !== node ) {
|
|
|
+
|
|
|
+ throw new Error( 'NodeBuilder: Invalid node chaining!' );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -447,9 +449,21 @@ class NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
- createStack() {
|
|
|
+ addStack() {
|
|
|
+
|
|
|
+ this.stack = stack( this.stack );
|
|
|
+
|
|
|
+ return this.stack;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ removeStack() {
|
|
|
+
|
|
|
+ const currentStack = this.stack;
|
|
|
|
|
|
- return stack();
|
|
|
+ this.stack = currentStack.parent;
|
|
|
+
|
|
|
+ return currentStack;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -570,16 +584,46 @@ class NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
- addFlowCode( code, breakline = true ) {
|
|
|
+ addLineFlowCode( code ) {
|
|
|
+
|
|
|
+ if ( code === '' ) return this;
|
|
|
|
|
|
- if ( breakline && ! /;\s*$/.test( code ) ) {
|
|
|
+ code = this.tab + code;
|
|
|
|
|
|
- code += ';\n\t';
|
|
|
+ if ( ! /;\s*$/.test( code ) ) {
|
|
|
+
|
|
|
+ code = code + ';\n';
|
|
|
|
|
|
}
|
|
|
|
|
|
this.flow.code += code;
|
|
|
|
|
|
+ return this;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ addFlowCode( code ) {
|
|
|
+
|
|
|
+ this.flow.code += code;
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ addFlowTab() {
|
|
|
+
|
|
|
+ this.tab += '\t';
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ removeFlowTab() {
|
|
|
+
|
|
|
+ this.tab = this.tab.slice( 0, - 1 );
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
getFlowData( node/*, shaderStage*/ ) {
|
|
@@ -628,7 +672,7 @@ class NodeBuilder {
|
|
|
|
|
|
if ( propertyName !== null ) {
|
|
|
|
|
|
- flowData.code += `${propertyName} = ${flowData.result};\n\t`;
|
|
|
+ flowData.code += `${propertyName} = ${flowData.result};\n` + this.tab;
|
|
|
|
|
|
}
|
|
|
|