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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Pandaman407

Pages: [1]
1
Network / Question about Socket Selector and UDP sockets
« on: October 24, 2015, 02:43:33 am »
I've started diving into the magic world of networking in SFML. All is fine, I got a nice UDP server and client to run. However, I read on the sfml tutorials about the socket selector class, and I started to ask myself questions. Does my server, which is one UDP socket, have to store each client as a seperate socket, or would I store the IP addresses to know who is who?

Server code (receiving and sending. very simple atm)
while (running)
        {
                if (selector.wait())
                {
                        if (selector.isReady(socket))
                        {
                                sf::IpAddress rec;
                                unsigned short rPort;
                                sf::Packet packet;

                                socket.receive(packet, rec, rPort);

                                std::cout << "Recieved a packet from: " << rec.toString() << " " << rPort << std::endl;
                                std::string x;
                                packet >> x;
                                std::cout << "Packet:[ " << x << " ]" << std::endl;
                        }

                }
        }
as you can see, im using socket selector, but I'm thinking it's pointless.

2
General / Re: Help with camera movement from keyboard
« on: October 22, 2015, 11:27:56 pm »
Oh yeah, I didn't think about that. That would be the fastest and easiest way to solve my problem for now. Thanks

edit: new code: thought of  a way to do it without a 3rd condition

        int hor = 0;
        int ver = 0;

       
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        {
                ver = 1;
        }
         if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        {      
               
                ver--;
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        {
                hor = 1;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        {
                hor--;
        }

3
General / Help with camera movement from keyboard
« on: October 22, 2015, 11:13:03 pm »
My camera movment works, however, if I hold the the 'S' key (down) it will move the camera down as i want to, but then if I hold 'W' after holding 'S' it will always go up. I tried many ways to fix this, all were not working and just confusing. Can you guys help me improve this code?

        extern float deltaTime;

        int hor = 0;
        int ver = 0;

       
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        {
                ver = 1;
        }
         else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        {      
                ver = -1;
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        {
                hor = -1;
        }
         else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        {
                hor = 1;
        }
       


        if (hor != 0 || ver != 0)
                view.move(speed * hor * deltaTime, speed * -ver * deltaTime);
                //y value is inverted, camera works with +y being down and -y being up

hor is a number to store the direction in the horizontal axis.
ver is a number to store the direction in the vertical axis.

Pages: [1]