How to implement a more complex Command processing scheme #7363
-
Hello, I am using Bevy to experiment with data driven architectures for embedded development. Embedded systems typically implement increasingly more complex routine, periodic processing, for which Bevy system/query/scheduler design seems... simply ideal. But such systems are also expected to react to numerous inbound commands, each associated with arbitrarily complex logics. Commands must be processed in the ordered they were received and can arbitrarily mutate the application state. Bevy's Command concept seems to fit this usecase well. In traditional SW, significant boilerplate code is required to connect an inbound Command type to the desired trigerred behavior. It seems Bevy does not provide mechanisms as powerful as the system/query mechanism there. If I have understood the documentation correctly, I can register a system with the World and the list of Commands as parameters. I can then implement something similar to the system/query mechanisms by looking at the relevant Bevy source code. I also found this blog post with very helpful explanations. As a first step, my goal would be to allow registration of command handlers based on the Command type. Is my approach sane? Since I am new to the ECS approach, I fear I am missing something important. Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
It sounds like you're likely to want to use If you instead need something significantly more powerful / flexible, you're likely interested in one-shot systems: see #2192 for discussions and links to draft implementations. |
Beta Was this translation helpful? Give feedback.
-
Hello again, Following up on your really helpful comments and links, I have studied #7999 in more details and come up with a new design. I want to execute a small (<20) sequence of arbitrary commands each cycle, depending on the network messages received each cycle:
Given those requirements, my use case seemed to map naturally to Bevy's commands. But, ergonomics are clearly in favor of systems: extensive user system registration API, type-safe system dependency injection... Since the release of Bevy ECS schedule v3, one of the key differences commands and exclusive systems (w.r.t. to my use case at least) is now captured in the much improved Schedule abstractions. Maybe one should bridge the developer experience gap between Commands and Systems by extending the Schedule APIs instead ? For example, I can implement my command execution scheme using an exclusive system which would dynamically construct a schedule and then run it. A specific resource can provide the mapping between network messages and target system-like commands. My main concern is I read building schedules dynamically might be expensive. It is true I do not need a full DAG-based parallel execution for this use case. Maybe I can customize a schedule just for this? What do you think? |
Beta Was this translation helpful? Give feedback.
It sounds like you're likely to want to use
Events
here. These are lightweight, processed in order, dispatched across systems and strongly typed.If you instead need something significantly more powerful / flexible, you're likely interested in one-shot systems: see #2192 for discussions and links to draft implementations.