Jump to content

  • Log In with Google      Sign In   
  • Create Account


Packet combining


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Telanor   Members   -  Reputation: 1311

Like
0Likes
Like

Posted 23 May 2014 - 09:05 PM

How do games usually handle having a bunch of different packets to send out in a single tick?

Suppose you have:
- 5 entities that have moved
- 3 entities that have started playing a new animation
- 6 new particle systems created (or rather 6 events that will create particle systems and sounds, etc)
- 2 new effects (as in the poison, heal, etc) applied to an entity (which is more than just a particle system, its also an icon to display on the UI)

Would any of those packets be combined into one to reduce overhead? If so, how? Do you combine all of the same type? Combine everything? Combine as many as you can until a certain size limit? What would the size limit be?

Suppose only some of those packets need to be sent to player A and some to player B (with some being sent to both). How does that affect the combining?

By the way, I'm using the lidgren networking library, in case that's important.

Sponsor:

#2 radioteeth   Prime Members   -  Reputation: 1003

Like
0Likes
Like

Posted 24 May 2014 - 02:07 AM

They would most certainly be combined into a single update packet. The way you do that is by putting all the entities, and their properties, in a list inside the packet. This includes any other properties an entity may need to convey an update about. You would have a byte telling the recipient how many entities are listed, and at the beginning of each entity have a byte that describes what entity properties are described. Then you can easily sift through each incoming packet to pull out the data that needs to be applied to entities locally.



#3 Telanor   Members   -  Reputation: 1311

Like
0Likes
Like

Posted 24 May 2014 - 10:46 AM

Well that's exactly what I'm doing currently, but only that. I'd like to know if there's more I should be doing. The entity packets are combined, but the event packets and effect packets aren't. I also haven't dealt with the "some packets to player A, some to player B" thing yet. So I'd like to know how to deal with those two things.

#4 radioteeth   Prime Members   -  Reputation: 1003

Like
1Likes
Like

Posted 24 May 2014 - 11:46 AM

You would include other things just the same way, so the first part of your packet is something like (for example) 3 bytes, one byte for how many entities are in the packet, one for how many events are in the packet, and one for effects.

 

Then the first byte of each entity (after an entity ID) is which properties of that entity follow.

 

After all the entities, and their info are in the packet, you move on to listing the events, then effects and their properties.



#5 Angus Hollands   Members   -  Reputation: 713

Like
1Likes
Like

Posted 24 May 2014 - 01:08 PM

There are many different ways of handling your packets. I tend to define a header as the size of the packet contents, then its protocol. That is it. This helps avoid errors within a single packet from causing off-by-n errors elsewhere. So an entity update packet might involve sending the number of repeated entities, then packing their data, and appending the header to that packet. 


Edited by Angus Hollands, 24 May 2014 - 01:08 PM.


#6 Telanor   Members   -  Reputation: 1311

Like
0Likes
Like

Posted 24 May 2014 - 04:55 PM

So I should combine them all together then? How about the "some packets to player A, some to player B" issue? How is that dealt with?

#7 hplus0603   Moderators   -  Reputation: 5165

Like
1Likes
Like

Posted 24 May 2014 - 05:35 PM

How about the "some packets to player A, some to player B" issue? How is that dealt with?


1. Set a network tick rate, such as 10 Hz or 20 Hz or 60 Hz
2. Each time a network tick comes up, iterate over all connected players
3. For each connected player, glom together all the updates that that particular player needs to see, and send as one packet to that player
enum Bool { True, False, FileNotFound };

#8 Telanor   Members   -  Reputation: 1311

Like
0Likes
Like

Posted 25 May 2014 - 12:26 PM

So I have to go through the whole process again for each player? Guess I'll have to rework things a little bit then. Thanks for the help guys




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS