-
Notifications
You must be signed in to change notification settings - Fork 66
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
Topics #65
base: main
Are you sure you want to change the base?
Topics #65
Conversation
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
Haven't had the time to fully read through the RFC, but a quick skim through raises the following questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding James's comments. Seems interesting, but definitely feels like something that can and should be explored extensively in a 3rd party crate.
Thanks for the incredibly quick feedback!
Totally agree that this can/should be an ecosystem crate. I opened the PR here to seek inputs from anyone else who may be interested in this idea and to avoid duplicating effort in case someone else is already working on this concept. If that's an inappropriate use of RFCs then feel free to close this PR and I'll seek out a new home for the document. All the same applies to #66 .
I think there are several key benefits, although the value of these benefits is situational, so I expect topics to complement Events and not replace them:
Very much acknowledged at the top of Implementation Strategy 😅
Acknowledged in the parallel publishing section.
Acknowledged in the Callback driven and Callback timing sections.
Truthfully I'm interested in using bevy in robotics, simulation, and IoT contexts rather than for conventional video game development, so I won't have a good answer for this since I'm not familiar with how client-server communication is done for conventional video games. But for the context that I'm coming from, distributed pub-sub architecture is a must-have, so making that accessible in bevy would open bevy up to whole new industries outside of video game development. Rising tide lifts all boats and whatnot. But really, why not Events??As I think more about it, I wonder if it would be possible to piggyback directly on the existing Events implementation to make scoped pub-sub work. That may also help to solve the concurrency concerns. Maybe instead of pub struct Message<T> {
for_topic: Topic,
data: T,
} Then each time you use Each message type Does that seem like a more feasible approach? Scheduling callbacks still presents some challenges, especially since this feature would need to support stageless systems and I'm not familiar with those yet. I'll need to get up to speed on stageless before I can reason about that. |
Unsure if this will be easier than making it a custom
Scheduling callbacks should be pretty straightforward post-Stageless: they'd just be emitted as commands, which can be evaluated whenever the user inserts a system that processes them ( a "command flush point"). You may end up wanting some performance improvements here; commands could be faster and the callbacks will be evaluated completely sequentially, but eh, for tiny callbacks that may actually be faster. |
That's what I was thinking! 😁 Something like: #[derive(SystemParam)]
pub struct Publisher<'w, 's, T> {
writer: EventWriter<'w, 's, Message<T>>,
}
impl<'w, 's, T> Publisher<'w, 's, T> {
pub fn publish(&mut self, to_topic: Topic, msg: T) {
self.writer.send(Message::new(to_topic, msg));
}
} Then there'd be a #[derive(SystemParam)]
pub struct Subscriber<'w, 's> {
commands: Commands<'w, 's>,
}
impl<'w, 's> Subscriber<'w, 's> {
pub fn subscribe<T, F>(&mut self, to_topic: Topic, callback: F) -> Result<Entity> {
// TODO: Do something to make sure that T is registered as a message type
// and return Err if it is not.
Ok(self.commands.spawn().insert(Subscription::new(to_topic, callback)).id())
}
} Then there'd be a system inserted for each I'm still hand waiving a lot when it comes to callback scheduling, but I think the approach to connecting publishers and subscriptions is feeling a lot more concrete. It seems like the |
|
RENDERED
This RFC propose a reactive pub-sub framework for Bevy, organized by topics.
I anticipate this RFC will need a considerable amount of feedback and iteration. I'm opening this to help facilitate technical discussion and not to declare that I have a firm solution for this feature.
If this concept is of significant interest, should we go ahead and reserve the
bevy_topics
crate?