#Bevy system indirection

10 messages · Page 1 of 1 (latest)

sinful cedar
#

Hello, I'm trying to design a crate for procedural story generation / complex quest system, which is mainly based on a hierarchical task network.

For my own use, I'd probably need hundreds of tasks, and I don't really fancy manually adding each and every one of those tasks' prerequisite update functions (or whatever else I end up doing) to the scheduler.
So I've been trying to find a way to have an indirection layer that would schedule all the needed systems for my tasks.

Is there any way to reference systems in Structs, or better yet, have a Trait's function to be used as a system? Or any other way to link a system to an asset?
A simple function can obviously be used as a system, but I'm more interested in a system that can use Query<> and Res<> for example (I couldn't find how to write a signature that would work).

If it's possible, I'm think of having a system update the internal state of the task, and each node in the task can read the internal state to see if this task has it's preconditions fulfilled. The user would make their own update system and internal state, and the crate would take care of scheduling the update system (through commands.add()), amongst other things.

Obviously, I'm out of my depth, so any advice is welcome.

wise tundra
sinful cedar
#

Thanks, having the SystemId would be a good way of linking the system to the asset, and having inputs and outputs would be amazing for some other part of the design, but there would still be the need to manually register the system. Otherwise, I could use the world.run_system_once(), but I still get stuck at trying to get the function signature to be generalised enough to be a true system, if that make sense. I'm also concerned about the lack of multithreading if I go that route.

timid badger
#

A trait can return a system if you call .into_system() on a function

#

So iirc it's:

trait MyTrait {
  fn get_system(&self) -> System;
}

impl MyTrait for MyStruct {
  fn get_system(&self) -> System {
    move |q: Query<&Transform>|{}.into_system()
  }
}
#

You might need to make it a boxed system, I'm fairly sure there's a way to do that though

#

According to the IntoSystemConfigs docs, it should be Box<dyn System<(), ()>>

magic siren
sinful cedar
#

Saying that it's based on a HTN might have been a bit of a simplification on my part, it similar to one at least. I'm trying to build something similar to what's described in this paper https://eis.ucsc.edu/papers/Mason_Lume.pdf

sinful cedar