bladecoder / blade-ink-rs

Inkle Ink runtime implementation in Rust
Apache License 2.0
32 stars 6 forks source link

`Story` thread-safe behind feature flag #2

Open IFcoltransG opened 1 year ago

IFcoltransG commented 1 year ago

There's some work going on to use Blade Ink in a Bevy game engine plugin for Ink, but Bevy strongly prefers Send types so it can parallelise. It would be valuable if Story were Send.

For example, there could be a crate feature flag that replaces a type Ref<T> = Rc<T> with type Ref<T> = Arc<T> and similar for Mutex instead of RefCell. That way users who only need single-threaded can avoid the slight overhead of Arc over Rc.

LeCalicot commented 1 year ago

@bladecoder would you need some help to work on that feature? On our side, we are blocked for the bevy integration by this issue, so we may as well help if we can :)

bladecoder commented 1 year ago

@IFcoltransG I like the way you propose to support threadsafe through a feature. I started to implement it in this branch and I realized it is not as easy as it seems.

I used RwLock as substitute of RefCell but the methods are different, so we will need to implement these methods and use them in all the code. I have implemented the brcell_borrow method in the threadsafe.rs file as a proof of concept and it works (see use in native_function_call.rs).

@LeCalicot Help is always welcome ! I let you complete this feature if you want. Just create a PR when you are finish and I will review it before merging.

Thanks

LeCalicot commented 1 year ago

To be honest, it might take me a long time, I'm that good with rust yet.

jaminhaber commented 11 months ago

You can use bladeink in a bevy game as a NonSend resource and emit events whenever something changes in the story

IFcoltransG commented 11 months ago

@jaminhaber That's what I'm doing for a current project, but lack of Send does prevent making a story into a component.