Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While nodes with iteration & UserFromUserRef #32

Merged
merged 8 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ProjectObsidian/ProtoFlux/Flow/AsyncWhileWithIteration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using ProtoFlux.Core;
using System.Threading.Tasks;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Flow
{
[NodeCategory("Obsidian/Flow")]
[NodeName("AsyncWhile With I", false)]
public class AsyncWhileWithIteration : AsyncActionNode<ExecutionContext>
{
public ValueInput<bool> Condition;
public AsyncCall LoopStart;
public AsyncCall LoopIteration;
public Continuation LoopEnd;
public readonly ValueOutput<int> i;
private int iter;

protected override async Task<IOperation> RunAsync(ExecutionContext context)
{
iter = 0;
await LoopStart.ExecuteAsync(context);
while (Condition.Evaluate(context, defaultValue: false))
{
i.Write(iter, context);
if (context.AbortExecution)
{
throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, LoopIteration.Target, isAsync: true);
}
await LoopIteration.ExecuteAsync(context);
iter++;
}
return LoopEnd.Target;
}

public AsyncWhileWithIteration()
{
i = new ValueOutput<int>(this);
}
}
}
39 changes: 39 additions & 0 deletions ProjectObsidian/ProtoFlux/Flow/WhileWithIteration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Flow
{
[NodeCategory("Obsidian/Flow")]
[NodeName("While With I", false)]
public class WhileWithIteration : ActionNode<ExecutionContext>
{
public ValueInput<bool> Condition;
public Call LoopStart;
public Call LoopIteration;
public Call LoopEnd;
public readonly ValueOutput<int> i;
private int iter;

protected override IOperation Run(ExecutionContext context)
{
iter = 0;
LoopStart.Execute(context);
while (Condition.Evaluate(context, defaultValue: false))
{
i.Write(iter, context);
if (context.AbortExecution)
{
throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, LoopIteration.Target, isAsync: false);
}
LoopIteration.Execute(context);
iter++;
}
return LoopEnd.Target;
}

public WhileWithIteration()
{
i = new ValueOutput<int>(this);
}
}
}
21 changes: 21 additions & 0 deletions ProjectObsidian/ProtoFlux/Users/UserFromUserRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FrooxEngine.ProtoFlux;
using ProtoFlux.Core;
using FrooxEngine;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Users
{
[ContinuouslyChanging]
[NodeCategory("Obsidian/Users")]
[NodeName("User From UserRef")]
public class UserFromUserRef : ObjectFunctionNode<FrooxEngineContext, User>
{
public readonly ObjectInput<UserRef> UserRef;

protected override User Compute(FrooxEngineContext context)
{
UserRef userRef = UserRef.Evaluate(context);
return userRef.Target;
}
}
}