SoftwareGuy / Ignorance

Ignorance utilizes the power of ENet to provide a reliable UDP networking transport for Mirror Networking.
Other
248 stars 31 forks source link

Make an ISegmentTransport interface #25

Closed MichalPetryka closed 5 years ago

MichalPetryka commented 5 years ago

I've made an interface that can be copied to other transports, will make integrating other transport easiers @martindevans @SoftwareGuy

martindevans commented 5 years ago

If you're going to go this path I would suggest renaming it to something more generic like ISegmentTransport. Of course it's only useful to implement this if you can persuade other transport authors to implement this. It also only solves half of the problem (receiving packets also allocates per packet).

High level applications using Mirror can do a runtime test to start using this automatically:

if (NetworkManager.instance.transport is ISegmentTransport) {
    // Use segment transport methods for zero alloc sending
} else {
    // Use usual transport methods by creating a new `byte[]` for each message
}

Of course this is really a workaround for the correct way to do it, which is to get it merged into Mirror. I proposed this in this PR) but it was rejected. If you're really concerned about allocations with Mirror I would suggest getting behind that PR and maybe picking up where I left off - they wanted a tonne of benchmarks to demonstrate the benefit.

MichalPetryka commented 5 years ago

Make those Benchmarks?

SoftwareGuy commented 5 years ago

Looks good. This will probably break when master eventually migrates away from ENET but for now I'll accept it.