Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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 🦀

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