-
Notifications
You must be signed in to change notification settings - Fork 37
Maybe improve design of application by using sync primitives #56
Comments
If we really want to allow full access to everything from multiple threads, we can just use I don't think anything needs to be mutated by multiple threads, so an Giving an |
I agree.
Whether or not we need an
I agree, I also planned on doing exactly that.
To what? I'm not sure I understand what you are suggesting. #58 is also about updating the view. The world can potentially mutated at multiple spots in our program. One important example is the player's interaction with the world. Currently, when a click event is forwarded to the player via the
I don't like (1.) because it again mixes different concerns and grows function signatures. I don't like (2.) because this makes our code more complex than it needs to be and everyone thinks Rust is annoying 😛 So again, I think that we should pass at least some inner-mutability-containers around to avoid those problems. |
Well, we wouldn't need a queue of click events, just a bool flag (or a few) |
This was tackled in #71. While we might want to improve the design in the future, I'll close this issue for now. |
I'm a bit unhappy with the current structure: we pass an immutable reference of one module (not Rust module) to all other modules that need to use it. For example, the current main loop looks like:
We pass the world and the camera to the renderer, as well as all event receivers to the event manager. The renderer needs a whole lot more things in the future, like the weather system and the sky system; so we can expect the function signature of
render()
to increase in argument count. The event manager would also be nicer with methods likeadd_handler()
.The problem here is that we, of course, can't pass immutable references (or in the case of the event manager: mutable ones) around while still mutating the object on our own. A possible solution would be to use an
RwLock
(taking into account that we will have threads in the future).But the question is: what is more rusty, more efficient and the better design? The current design works and the borrow checker doesn't complain. The
RwLock
design also adds some complexity and introduces some overhead for locking. Maybe it's not that bad to have terrible long argument lists. I'm really not sure about this (?). Maybe at the very least we should wrap theWorld
into anRwLock
and give it to everyone?I'm curious what you think, especially @jonas-schievink ...
The text was updated successfully, but these errors were encountered: