Insprill / dv-multiplayer

A Derail Valley mod adding multiplayer to the game.
Apache License 2.0
33 stars 16 forks source link

Use an attribute system for subscribing to packets #1

Closed Insprill closed 1 year ago

Insprill commented 1 year ago

Instead of manually listing out the NetPacketProcessor#SubscribeReusable call for each packet, we should have an attribute that can be added to a method, and then it will get registered automatically.

The NetworkManager can have a static initializer that will search all methods for the attribute. When a method is found, its parameters will be checked. The first parameter will be for the packet, and the second, if present, will be for the user data (Usually a NetPeer). With this system, adding a new packet listener is as simple as creating the method with the packet as a parameter and adding the attribute.

Insprill commented 1 year ago

After investigating this, it isn't worth the development time. Perhaps in the future, we'll have a better system for handling packet sending and receiving overall, but for now, the current system will do.