diff --git a/build/litegraph.core.js b/build/litegraph.core.js index bc137a94f..d8bbe6b84 100644 --- a/build/litegraph.core.js +++ b/build/litegraph.core.js @@ -1059,6 +1059,10 @@ var start = LiteGraph.getTime(); this.globaltime = 0.001 * (start - this.starttime); + //not optimal: executes possible pending actions in node, problem is it is not optimized + //it is done here as if it was done in the later loop it wont be called in the node missed the onExecute + + //from now on it will iterate only on executable nodes which is faster var nodes = this._nodes_executable ? this._nodes_executable : this._nodes; @@ -1073,7 +1077,8 @@ for (var i = 0; i < num; i++) { for (var j = 0; j < limit; ++j) { var node = nodes[j]; - node.executePendingActions(); + if(LiteGraph.use_deferred_actions && node._waiting_actions && node._waiting_actions.length) + node.executePendingActions(); if (node.mode == LiteGraph.ALWAYS && node.onExecute) { //wrap node.onExecute(); node.doExecute(); @@ -1089,13 +1094,14 @@ if (this.onAfterExecute) { this.onAfterExecute(); } - } else { + } else { //catch errors try { //iterations for (var i = 0; i < num; i++) { for (var j = 0; j < limit; ++j) { var node = nodes[j]; - node.executePendingActions(); + if(LiteGraph.use_deferred_actions && node._waiting_actions && node._waiting_actions.length) + node.executePendingActions(); if (node.mode == LiteGraph.ALWAYS && node.onExecute) { node.onExecute(); } @@ -3366,7 +3372,7 @@ var target_connection = node.inputs[link_info.target_slot]; //instead of executing them now, it will be executed in the next graph loop, to ensure data flow - if(LiteGraph.use_deferred_actions) + if(LiteGraph.use_deferred_actions && node.onExecute) { if(!node._waiting_actions) node._waiting_actions = []; diff --git a/build/litegraph.core.min.js b/build/litegraph.core.min.js index d0ffcf087..2c3db303f 100644 --- a/build/litegraph.core.min.js +++ b/build/litegraph.core.min.js @@ -32,25 +32,25 @@ w.supported_types};w.STATUS_STOPPED=1;w.STATUS_RUNNING=2;w.prototype.clear=funct 0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};w.prototype.attachCanvas=function(a){if(a.constructor!=q)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)}; w.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};w.prototype.start=function(a){if(this.status!=w.STATUS_RUNNING){this.status=w.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=h.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){function c(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c); if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}}this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};w.prototype.stop=function(){if(this.status!=w.STATUS_STOPPED){this.status=w.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id), -this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};w.prototype.runStep=function(a,b,c){a=a||1;var d=h.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var f=0;fg&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes=function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order: -this._nodes;if(d)for(var e=0,f=d.length;e=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_idg&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes= +function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1== +a.id?a.id=++this.last_node_id:this.last_node_id