#Best practices on exposing Bevy data to the outside world?

1 messages · Page 1 of 1 (latest)

barren yacht
#

I am trying to expose data from my Bevy app to non-Bevy callers within the same address space without going through disk I/O.

The general idea is to use Bevy as the backend to run a simulation and periodically query it to extract state. Kinda similar to what the Render World is doing, but at random rather than each frame, and probably via a DLL.

The data will be Plain Old Stack Data owned by the receiver, i.e. we don't need to worry about lifetimes or anything; I'm pretty flexible on the structure(s). It doesn't need to be generic, the number of types exposed will be finite.

So far I've gotten comms going the other way by creating a static ⁨AtomicBool⁩ that the DLL user can toggle, so that seems like one option - but I was wondering if anyone might have a neater pattern around this?

ionic elbow
drowsy whale
#

another option is for the DLL to provide a callback, and then having a bevy system call that callback with the data. the advantage would be no need to use a channel, the disadvantage would be the external code can't ask for updates, but has to wait for the next callback

barren yacht
# drowsy whale another option is for the DLL to provide a callback, and then having a bevy syst...

That could actually be pretty nice in some ways, a push model rather than a pull model.

I'd need to dig up some examples of calling a function pointer via the FFI from Rust though, since I have no idea what that looks like rn.

I'm concerned it might be a bad deal in this case - I don't really need the flexibility of a callback here and might be more brittle - but I think it's worth keeping in my back pocket for the future

drowsy whale
#

hell, if your data is really cheap and access infrequent you could just use Bevy Remote Protocol and not need linking at all

barren yacht
#

I've seen BRP and entirely forgot it can do these kinds of things

#

🤦‍♂️

drowsy whale
#

hey if that works for your usecase that's really cool

barren yacht
#

requires a SerDe into JSON, which is a bit painful

drowsy whale
#

thats why i said infrequent access, but its not actually that slow

#

fast enough for an entity inspector

barren yacht
#

Probably too slow for my purposes, it's AI code

#

I guess if you only used it for the coarse stuff and batch it, might be fine