Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do i send std::list?  (Read 1759 times)

0 Members and 1 Guest are viewing this topic.

nonikel

  • Newbie
  • *
  • Posts: 13
    • View Profile
How do i send std::list?
« 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;

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How do i send std::list?
« Reply #1 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)  ;)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do i send std::list?
« Reply #2 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything