Skip to content

Commit

Permalink
fix in deferred events system
Browse files Browse the repository at this point in the history
  • Loading branch information
tamat committed Jan 8, 2024
1 parent 1f3b786 commit 7d214c6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 98 deletions.
33 changes: 19 additions & 14 deletions build/litegraph.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@
for (var i = 0; i < num; i++) {
for (var j = 0; j < limit; ++j) {
var node = nodes[j];
node.executePendingActions();
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
//wrap node.onExecute();
node.doExecute();
Expand All @@ -1094,6 +1095,7 @@
for (var i = 0; i < num; i++) {
for (var j = 0; j < limit; ++j) {
var node = nodes[j];
node.executePendingActions();
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
node.onExecute();
}
Expand Down Expand Up @@ -3190,10 +3192,26 @@
this.mode = modeTo;
return true;
};

/**
* Triggers the execution of actions that were deferred when the action was triggered
* @method executePendingActions
*/
LGraphNode.prototype.executePendingActions = function() {
if(!this._waiting_actions || !this._waiting_actions.length)
return;
for(var i = 0; i < this._waiting_actions.length;++i)
{
var p = this._waiting_actions[i];
this.onAction(p[0],p[1],p[2],p[3],p[4]);
}
this._waiting_actions.length = 0;
}


/**
* Triggers the node code execution, place a boolean/counter to mark the node as being executed
* @method execute
* @method doExecute
* @param {*} param
* @param {*} options
*/
Expand All @@ -3204,13 +3222,6 @@
// enable this to give the event an ID
if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999);

if(this._waiting_actions && this._waiting_actions.length)
for(var i = 0; i < this._waiting_actions.length;++i)
{
var p = this._waiting_actions[i];
this.onAction(p[0],p[1],p[2],p[3],p[4]);
}

this.graph.nodes_executing[this.id] = true; //.push(this.id);

this.onExecute(param, options);
Expand All @@ -3225,12 +3236,6 @@
}
}
else {
if(this._waiting_actions && this._waiting_actions.length)
for(var i = 0; i < this._waiting_actions.length;++i)
{
var p = this._waiting_actions[i];
this.onAction(p[0],p[1],p[2],p[3],p[4]);
}
}
this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event
if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback
Expand Down
Loading

0 comments on commit 7d214c6

Please sign in to comment.