blade-ink-rs
blade-ink-rs copied to clipboard
`Story` thread-safe behind feature flag
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.
@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 :)
@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
To be honest, it might take me a long time, I'm that good with rust yet.
You can use bladeink in a bevy game as a NonSend resource and emit events whenever something changes in the story
@jaminhaber That's what I'm doing for a current project, but lack of Send does prevent making a story into a component.