|
|
|
|
|
by efnx
289 days ago
|
|
> but that, in turn, means that you have to lock that RwLock every frame, also not great. Unless that RwLock is in contention to get acquired every frame I doubt it will add anything significant to the frame time. Worrying about things like this without profiling can cause a lot of unnecessary complexity when planning abstractions in Rust. Furthermore- UI updates are usually all run from the same single thread, so it’s unlikely the other widgets could even contend for that lock! You might be able to get away with the lock approach and you may even be able to use Rc<RefCell<_>>, which would get a little speed up. |
|
:+1: - it was mostly about "damn, it _feels_ like there should be a better way".
> You might be able to get away with the lock approach and you may even be able to use Rc<RefCell<_>>, which would get a little speed up.
In this particular case that'd be a bit more awkward, because in the actual game the UI is driven by async fn (the rendering itself is sync, of course, but waiting for input is async, and both happen as a part of the same function).
`spawn_local()` could be a good enough solution for that, though.