Open LeQuackers opened 2 months ago
I have no idea what you're trying to do here
I'm trying to get a given Task
to be scheduled during a particular Stage
(in my case just before the physics step).
The fiddle proof of concept shows a working example of how to "step" through a Task
, i.e. you could use it in a GameObjectSystem.Listen
callback and force some group of Tasks
to be scheduled during whatever Stage
you need.
Being able to "step" through Tasks
using the fiddle proof of concept is a nice because you would have fine control of when Tasks
are scheduled without needing to modify each Task's
code.
The GameTask.RunDuringStage
method was an alternative idea if the fiddle proof of concept wasn't allowed for whatever reason.
using System;
using System.Threading.Tasks;
public sealed class ExampleComponent : Component
{
protected override void OnAwake()
{
_ = SomeExampleTaskAsync();
}
private async ValueTask SomeExampleTaskAsync()
{
while ( true )
{
await GameTask.DelayRealtime( 100 );
Log.Info( $"This task is running during the {StageListener.CurrentStage} stage." );
}
}
}
public class StageListener : GameObjectSystem
{
public static Stage CurrentStage { get; private set; }
public StageListener( Scene scene ) : base( scene )
{
foreach ( var stage in Enum.GetValues<Stage>() )
{
Listen( stage, -1, () => CurrentStage = stage, Enum.GetName( stage ) );
}
}
}
Currently ExampleComponent.SomeExampleTaskAsync
is always running (being scheduled) after Stage.FinishUpdate
, which is at the very end. I want force it to run (be scheduled) during a particular Stage
(in my case just before the physics step).
Something like
await GameTask.WaitForStage(GameObjectSystem.Stages stage, int order, CancellationToken token = default);
would probably also work.
So you just want to be able to put async functions in listen?
So you just want to be able to put async functions in listen?
I want to make arbitrary Tasks
be ran/scheduled during a particular Stage
.
The fiddle example was an example of how to get that working. Because the TaskWalker
class allowed you to manually "step" through a task, you could literally force a given Task
or group of Tasks
to run using TaskWalker.DoStep
.
I mentioned GameObjectSystem.Listen
because the listener callback will run during whatever Stage
you specify, so if I call TaskWalker.DoStep
in the listener callback, then every Task
queued in that TaskWalker
will be literally forced to run during that Stage
.
I want the ExampleComponent.SomeExampleTaskAsync
method from the example code a few comments above to run just before the physics step.
For?
S&Box
What can't you do?
I'm unable to configure a given
Task
to run during a particularStage
or be ran manually in a particularGameObjectSystem
, which isn't ideal forTasks
that need to run during certain times.How would you like it to work?
GameTask.RunDuringStage(Func<Task>, GameObjectSystem.Stage, CancellationToken)
static method, which forcesTasks
to be ran/scheduled during a particularStage
:// Lerp the given GameObject's color after fixed update is finished with a random delay between them: GameTask.RunDuringStage(() => LerpColorAsync(gameObject, Color.Blue, delay: new RangedFloat(0.25f, 2.0f)), Stage.FinishFixedUpdate, token);
What have you tried?
Using my fiddle proof of concept in S&Box, but almost none of it is whitelisted:
Additional context
No response