SFML community forums

Help => Network => Topic started by: DarkNemesis on August 13, 2013, 09:39:50 pm

Title: Packets and Arrays
Post by: DarkNemesis on August 13, 2013, 09:39:50 pm
I know this question have been asked and answered several times, but since I wasn't satisfied with those, I decided to make a new thread. I have a 2D map array, which I want my server to send to the client. So other than arranging the packet manually like this
{
DataPacket << data[0] << data[1] << data[2]....
}
is there a better and quicker way to store the complete 2D array into the packet and send it to the client?
Title: Re: Packets and Arrays
Post by: Ivan on August 13, 2013, 09:56:35 pm
You can use a For loop to fill the packet or just overload the operators >> and << as its explained in the tutorials Extending Packets (http://www.sfml-dev.org/tutorials/2.1/network-packet.php)
Title: Re: Packets and Arrays
Post by: Nexus on August 13, 2013, 09:56:46 pm
A loop? ???
Title: Re: Packets and Arrays
Post by: Ivan on August 13, 2013, 10:07:22 pm
A loop? ???

I mean:

sf::Packet DataPacket;
for (int i = 0; i < sizeData; i++)
{
      DataPacket << data[i];
}
 

 ::)
Title: Re: Packets and Arrays
Post by: Nexus on August 13, 2013, 10:08:15 pm
Was directed to DarkNemesis, you and I meant the same :D
Title: Re: Packets and Arrays
Post by: Ivan on August 13, 2013, 10:10:53 pm
Ouuch, sorry  ;D