blade-ink-rs icon indicating copy to clipboard operation
blade-ink-rs copied to clipboard

`Story` thread-safe behind feature flag

Open IFcoltransG opened this issue 2 years ago • 5 comments

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.

IFcoltransG avatar Oct 21 '23 22:10 IFcoltransG

@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 :)

LeCalicot avatar Oct 22 '23 21:10 LeCalicot

@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

bladecoder avatar Oct 23 '23 16:10 bladecoder

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

LeCalicot avatar Oct 23 '23 21:10 LeCalicot

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

jaminhaber avatar Dec 09 '23 19:12 jaminhaber

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

IFcoltransG avatar Dec 10 '23 08:12 IFcoltransG