So I am programming the multiplayer part of my RTS game with Enet. After I was able to send important data, I realized that my packets are taking forever to get from the client to the server… although they are running from localhost. I have not been able to find any information regarding a possible fix to this, so I will just go ahead and post any code more that might be needed to help me solve the problem.
So here is what I currently am sending:
struct PlayerStatePacket {
int posX[500];
int posY[500];
int posZ[500];
int teamNo[500];
};
This is the struct that is being sent with the packet. Each individual packet is intended to account for each and every unit that is on the game battlefield. I use this method because all of the units are in a vector, and it iterates through this vector when the rendering and unit selection is done… and now that list also includes the packets that are being sent. Moreover, the positions are set and sent like so:
clientInstance.playerStatePacketVariable.posX[i] = units[i].positions.x;
clientInstance.playerStatePacketVariable.posY[i] = units[i].positions.y;
clientInstance.playerStatePacketVariable.posZ[i] = units[i].positions.z;
And this is done for every frame.
I have done some testing, and I have found that sending the packet for every iteration in every frame slows the game down drastically, though I kind of saw that one coming…
But however, that leads me to believe that something is clogging up the information that is being sent over from the client to the server.
Either that or there is some stupid timer that I forgot to account for.
Anyone here have any ideas as to what I might be doing wrong?
Thank you!
-rydog