naia-lib / naia

a cross-platform (including Wasm!) networking library built in Rust. Intended to make multiplayer game development dead-simple & lightning-fast
Apache License 2.0
857 stars 61 forks source link

Migrate back to a single enum for Naia events #179

Closed connorcarpenter closed 5 months ago

connorcarpenter commented 1 year ago

There are now (or will be, with the next release) 17 different types of events that the Client can emit.. Initially I really enjoyed the simplicity of being able to have a separate system for each type of Event, but I think there may be benefits to just having a single system handle all Client/Server events via a large enum .. It would reduce a lot of code and make things more maintainable going forward, as well as enforce a specific ordering between event types.

Interested if anyone has thoughts on this. Are the current event handling ergonomics worth it?

Veritius commented 1 year ago

I personally prefer discrete systems for code cleanliness and packing things into modules. Separate systems also helps with parallelism.

One example is if my auth system is especially complex, with a lot of system parameters, I may opt to move it to a module. If it all had to be one system, it's not ideal to have processed the auth events, but then those params are never released to be used by other systems, because the mutable references are still held even when not being used.