You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/2024/11-15-bevy-channel-trigger/index.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
+++
2
-
title = "Extending Bevy with C: Communicating via FFI"
3
-
date = 2024-11-14
2
+
title = "Sending Events to Bevy from anywhere"
3
+
date = 2024-11-15
4
4
[extra]
5
5
tags=["rust","bevy","gamedev"]
6
6
hidden = true
7
-
custom_summary = "We released the bevy_channel_trigger crate to simplify communication between Bevy and foreign libraries or languages."
7
+
custom_summary = "We released the bevy_channel_trigger crate to simplify communication from foreign libraries or languages to Bevy."
8
8
+++
9
9
10
10
In this short post we introduce the recently released [bevy_channel_trigger](https://crates.io/crates/bevy_channel_trigger) crate, why we need it to talk to foreign code and what it sets it apart from alternatives. If you just want to start using it, find it on [GitHub](https://github.com/rustunit/bevy_channel_trigger).
@@ -23,10 +23,14 @@ You can just call foreign functions of course right from your Bevy Systems but t
23
23
24
24
This is where channels like [crossbeam](https://github.com/crossbeam-rs/crossbeam), [async-channel](https://docs.rs/async-channel/latest/async_channel/) or [flume](https://github.com/zesterer/flume) come in handy to communicate back into our Bevy game logic.
25
25
26
-
Lets look at an example.
26
+
Lets look at a very simple example.
27
27
28
28
# Show me an example
29
29
30
+
The this example we show how to define an Event type `MyEvent` (line **2**)
31
+
that we want to send as a reaction to a foreign function calling us
32
+
(via callbacks or whatever the mechanism).
33
+
30
34
```rust,linenos
31
35
#[derive(Event)]
32
36
struct MyEvent(i32);
@@ -58,10 +62,6 @@ fn main() {
58
62
}
59
63
```
60
64
61
-
The above example shows how we define an Event type `MyEvent` (line **2**)
62
-
that we want to send as a reaction to a foreign function calling us
63
-
(via callbacks or whatever the mechanism).
64
-
65
65
For the purposes of this example we simulate this by spinning off a
66
66
separate thread (line **14**) and passing `sender` into it. Since this is
67
67
a multiple-producers-single-consumer channel we can clone the sender
Copy file name to clipboardExpand all lines: docs/blog/2024/11-15-bevy-channel-trigger/index.html
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,12 @@
23
23
</header>
24
24
25
25
<divid="blogpage">
26
-
<divclass="date">2024-11-14</div>
26
+
<divclass="date">2024-11-15</div>
27
27
28
28
<divclass="hidden">hidden</div>
29
29
30
30
<h1class="title">
31
-
Extending Bevy with C: Communicating via FFI
31
+
Sending Events to Bevy from anywhere
32
32
</h1>
33
33
<divclass="content">
34
34
<p>In this short post we introduce the recently released <ahref="https://crates.io/crates/bevy_channel_trigger">bevy_channel_trigger</a> crate, why we need it to talk to foreign code and what it sets it apart from alternatives. If you just want to start using it, find it on <ahref="https://github.com/rustunit/bevy_channel_trigger">GitHub</a>.</p>
@@ -42,8 +42,11 @@ <h1 id="why">Why?</h1>
42
42
</ul>
43
43
<p>You can just call foreign functions of course right from your Bevy Systems but that is often not a good idea as we don't want to block our game logic. Often these APIs are async as well which means they will produce a result sometime later that we then want to receive back in our Bevy Systems. The schema on the right visualizes this.</p>
44
44
<p>This is where channels like <ahref="https://github.com/crossbeam-rs/crossbeam">crossbeam</a>, <ahref="https://docs.rs/async-channel/latest/async_channel/">async-channel</a> or <ahref="https://github.com/zesterer/flume">flume</a> come in handy to communicate back into our Bevy game logic.</p>
45
-
<p>Lets look at an example.</p>
45
+
<p>Lets look at a very simple example.</p>
46
46
<h1id="show-me-an-example">Show me an example</h1>
47
+
<p>The this example we show how to define an Event type <code>MyEvent</code> (line <strong>2</strong>)
48
+
that we want to send as a reaction to a foreign function calling us
0 commit comments