Alcaros / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

Reverse the order in which channel.SendQueuedMessages is called #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently:
  1. Messages are queued in their respective channels
  2. The NetConnection.m_sendChannels array is iterated through, calling SendQueuedMessages to actually send the messages

My suggestion is to reverse the order that m_sendChannels is iterated through, 
so the end result is that ReliableOrdered messages are sent *before* Unreliable 
messages.

Reasoning:
  Imagine creating a networked game. Objects need to be created and destroyed, and fields need to be updated. Object creation and destruction is generally important to gameplay so must be sent with ReliableOrdered. Fields may change often and so Unreliable can be used to reduce overhead.

  On a host during a tick:
    1. Recieved messages are processed
    2. Object creation/destruction messages are queued using the ReliableOrdered channel
    3. Object field update messages are queued using the Unreliable channel

  However, when all channels have their messages actually sent, the unreliable messages get sent first. This means that the client will recieve the field update messages for an object which hasn't been created yet and will have to ignore them. It will have to wait for the client to get onto the next tick.

  Now by design, the order in which messages are sent should *not* matter between channels. Just because I send a ReliableOrdered message before an Unreliable one shouldn't mean that they are sent in that order. However, reversing the order in which channels are *flushed* would make the above case much more efficient - usually, all the field updates would come in straight after the creation message.

Changes required:
  The channels are flushed on line 209 of NetConnection.cs (as of rev 150). Reversing the order is trivial and shouldn't break anything. I have included a patch below.

Original issue reported on code.google.com by truthisfanatic@gmail.com on 10 Nov 2010 at 9:41

Attachments:

GoogleCodeExporter commented 9 years ago
Good idea. Even better would be to send them in the order they were queued, to 
give the user full control... that would however require a larger refactoring - 
this will do fine for now. Added in rev 151 - thanks!

Original comment by lidg...@gmail.com on 10 Nov 2010 at 10:51

GoogleCodeExporter commented 9 years ago
Awesome - thanks for the quick response :D

Original comment by truthisfanatic@gmail.com on 10 Nov 2010 at 10:59