SFML community forums

Help => Network => Topic started by: nonikel on April 19, 2014, 03:57:44 pm

Title: How do i send std::list?
Post by: nonikel on April 19, 2014, 03:57:44 pm
Hello everyone,

im trying to pack a std::list into a packet. I´ve read the tutorial on extending packets to handle user types. But i have my problems to get it to work with std::list. The list contains bullets which are a struct with four float variables. I hope somebody can help me with this.  :)
struct BulletInfo
        {
                float PosX;
                float PosY;
                float SpeedX;
                float SpeedY;
        };

        //List
        std::list<BulletInfo>BulletList;
Title: Re: How do i send std::list?
Post by: Jesper Juhl on April 19, 2014, 04:05:13 pm
"How do I send std::list"

One element at a time (possibly preceded by an element count)  ;)
Title: Re: How do i send std::list?
Post by: Nexus on April 19, 2014, 04:06:17 pm
Provide your overloads of operator<< and operator>> for the BulletInfo type, by serializing each member.

To prepare a packet for transmission, you iterate through the list and serialize every element. To extract data from a packet after receiving, you add new elements to the list until there is no more data in the packet.