Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/extrawurst/bevy_extern_events
Bevy plugin for generic external events forwarded to Bevy EventReaders 🦀
https://github.com/extrawurst/bevy_extern_events
bevy extern-libraries
Last synced: about 2 months ago
JSON representation
Bevy plugin for generic external events forwarded to Bevy EventReaders 🦀
- Host: GitHub
- URL: https://github.com/extrawurst/bevy_extern_events
- Owner: extrawurst
- Created: 2023-11-24T09:03:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-27T13:38:44.000Z (about 1 year ago)
- Last Synced: 2024-05-01T19:46:26.585Z (8 months ago)
- Topics: bevy, extern-libraries
- Language: Rust
- Homepage: https://crates.io/crates/bevy_extern_events
- Size: 69.3 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# bevy_extern_events
[![crates.io](https://img.shields.io/crates/v/bevy_extern_events.svg)](https://crates.io/crates/bevy_extern_events)
[![docs](https://docs.rs/bevy_extern_events/badge.svg)](https://docs.rs/bevy_extern_events)## Why?
Because at some point you might want to interact with code outside of Bevy (External SDKs, Native Platform Code, non-Bevy crates). With the help of this crate you can queue events from anywhere and they will be available via the typical `EventReader` mechanism inside your Bevy Systems.
**Note** that this comes at the cost of us having a global static `RwLock`-based Queue that we poll every frame (`PreUpdate`) to forward into an `EventWriter`. Events are `Box`ed because I found no other way of having a global static generic Datatype without using `Any`.
Therefore I suggest using this for non-every-frame interaction and rolling a custom solution otherwise.
## Example:
```rust
#[derive(Default)]
pub struct MyEvent;#[derive(Resource, Reflect, Default)]
pub struct MyEventResource(i32);pub fn event_system(
mut res: ResMut,
mut native_events: EventReader>,
) {
for _e in native_events.read() {
res.0 += 1;
}
}fn test() {
let mut app = App::new();
app.init_resource::()
.add_plugins(ExternEventsPlugin::::default())
.add_systems(Update, event_system);queue_event(MyEvent::default());
app.update();
assert_eq!(app.world.resource::().0, 1);
}
```## TODO
- [ ] CI
- [ ] clippy