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 - FleshyOverlord

Pages: [1] 2
1
Network / Blocking and locking the UDP receive function
« on: January 28, 2020, 12:00:40 am »
Background: My program has two threads, the UDP receive function and the main game logic thread.

Is it safe to set a UDP socket to blocking and not lock the UDP receive thread when the socket.receive()function is called? I am worried that if I call a socket.send(packet, ip, port)function when the UDP socket is receiving it will interfere with socket. I was worried this is what might have been causing my program to lock up.

2
System / Re: Non-Locked threads and Locked Threads
« on: January 26, 2020, 03:21:45 pm »
Thank you for the help!

3
System / Non-Locked threads and Locked Threads
« on: January 26, 2020, 04:22:36 am »
If a non-locked thread tries to access data inside of a locked thread, will it be blocked from doing so?

4
Network / Should you use one UDP Socket for sending and receiving?
« on: January 17, 2020, 04:52:56 am »
Hello, I have a general question pertaining to SFML's networking. I read in one post that one UDP socket should not be used for both sending and receiving (I might have interpreted this incorrectly: https://en.sfml-dev.org/forums/index.php?topic=22917.0 4th post by Laurent). Is this true, or is it a good idea to stick to using one UDP socket for sending and receiving in SFML's architecture?

5
Network / Re: Using sf::Lock on UDP sockets
« on: January 16, 2020, 02:29:01 pm »
Thank you Laurent!

6
Network / Using sf::Lock on UDP sockets
« on: January 16, 2020, 04:50:01 am »
Hello, I am working on a tank game and am trying to use both TCP and UDP. So far the TCP is working however I am having difficulties getting UDP to work do to some confusion about mutex. Is it safe to use sf::Lock before calling receive on a blocking UDP socket, or will this stall the program?

                sf::Packet* uPack = new sf::Packet();
                sf::IpAddress rcvAddr;
                short unsigned int rcvPort;
                PacketCont* packCont = new PacketCont();
                sf::Lock lock(sManager->mutex);//this is the line I am worried about
                sf::Socket::Status status = m_UDPSocket.receive(*uPack, rcvAddr, rcvPort);
 
Note: I need the mutex since I am using multiple threads which access the UDP socket class.

7
Network / Re: Selector.wait() not calling after client disconnect
« on: May 29, 2019, 01:00:09 am »
Thank you for your help eXpl0it3r! I found that in a different file I was deleting the socket before I called
selector.remove(socket)
which is what caused the errors.

8
Network / Re: Selector.wait() not calling after client disconnect
« on: May 28, 2019, 06:36:47 pm »
I found the root of the problem is that the
selector.wait(sf::seconds(3)
is returning false without waiting 3 seconds after a client disconnects. What does the returning false mean?

9
Network / Re: Selector.wait() not calling after client disconnect
« on: May 27, 2019, 11:27:42 pm »
This code does work however I am still getting errors on my side but I think I found the root of the problem. Thank you for the quick responses!

10
Network / Re: Selector.wait() not calling after client disconnect
« on: May 27, 2019, 07:23:32 am »
I believe the problem is in my code. I was able to create a quick client connection test that worked perfectly even when clients disconnected. To test it, you should only need this file.

#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <vector>
#include <iostream>
#include <sstream>

int main(){
bool isClient;
std::cout << "Client?" << std::endl;
std::string answer;
std::cin >> answer;
if(answer == "yes"){
    isClient = true;
}
else{
    isClient = false;
}
// Create a socket to listen to new connections
sf::TcpListener listener;
if(!isClient){
listener.listen(55001);
std::cout << "setup server" << std::endl;
}
bool running = true;
//socket used by client
sf::TcpSocket mSocket;
// Create a list to store the future clients
std::list<sf::TcpSocket*> clients;
// Create a selector
sf::SocketSelector selector;
// Add the listener to the selector
selector.add(listener);
// Endless loop that waits for new connections
if(isClient){
    if(mSocket.connect(sf::IpAddress("127.0.0.1"), 55001) == sf::Socket::Status::Done){
    std::cout << "connected" << std::endl;
    }
}

while (running)
{
    // Make the selector wait for data on any socket
    if (selector.wait())
    {
        std::cout << "receiving data" << std::endl;
       if(!isClient){
        // Test the listener
        if (selector.isReady(listener))
        {
            std::cout << "added client" << std::endl;
            // The listener is ready: there is a pending connection
            sf::TcpSocket* client = new sf::TcpSocket;
            if (listener.accept(*client) == sf::Socket::Done)
            {
                // Add the new client to the clients list
                clients.push_back(client);
                // Add the new client to the selector so that we will
                // be notified when he sends something
                selector.add(*client);
            }
            else
            {
                // Error, we won't get a new connection, delete the socket
                delete client;
            }
        }
        else
        {
            // The listener socket is not ready, test all other sockets (the clients)
            for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
            {
                sf::TcpSocket& client = **it;
                if (selector.isReady(client))
                {
                    // The client has sent some data, we can receive it
                    sf::Packet packet;
                    sf::Socket::Status stat = client.receive(packet);
                    if (stat == sf::Socket::Done)
                    {
                    }
                    else if (stat == sf::Socket::Status::Disconnected){
                        std::cout << "disconnected" << std::endl;
                        selector.remove(**it);
                        it = clients.erase(it);
                    }
                }
            }
        }
    }
    else{

    }
    }
}
return 0;
}

 

11
Network / Re: Selector.wait() not calling after client disconnect
« on: May 26, 2019, 04:04:58 pm »
I just checked the version I was using and found it was SFML 2.5.1

12
Network / Selector.wait() not calling after client disconnect
« on: May 26, 2019, 01:46:25 am »
I have been working on a TCP networking game recently and have been having problems with the
 sf::SocketSelector::wait()
function. Whenever a client disconnects the selector basically stops functioning, it will not receive any packets or even trigger after a new client tries to connect. Is this intentional as a part of the SFML engine, or is this most likely a programming error on my part?

13
Graphics / Re: Creating simple 3D objects SFML
« on: April 23, 2019, 12:55:35 am »
I am just spitting ideas out now but to rotate objects along their pitch axis you could stretch all the quads that make up each vertex array and change the order of rendering for each layer when you exceed 180 degrees.

14
Graphics / Re: Creating simple 3D objects SFML
« on: April 21, 2019, 05:29:29 pm »
Thank you so much for the in-depth response fallahn! I found all I needed to do was apply the sf::Transform to each point of the quad using sf::Transform::transformPoint which I was unsure of how to use until now. To draw 100 of the models only requires about 30% of my GPU (GTX1060 on a lenovo laptop) and requires minimal CPU usage(10% max) on a core i7(laptop);


sf::Transform transform;
sf::Vector2f center = sf::Vector2f((tileWH / (2.0f)) + left, (tileWH / (2.0f)) + top);

transform.scale(sf::Vector2f(5.0f, 5.0f), center);
transform.rotate(angle, center);

quad[0].position = transform.transformPoint(sf::Vector2f(left, top + tileWH));
quad[1].position = transform.transformPoint(sf::Vector2f(left, top));
quad[2].position = transform.transformPoint(sf::Vector2f(left + tileWH, top));
quad[3].position = transform.transformPoint(sf::Vector2f(left + tileWH, top + tileWH));
                       
 

A working image of the code.

15
Graphics / Re: Creating simple 3D objects SFML
« on: April 21, 2019, 03:13:41 am »
Is it possible to have multiple sf::Transforms  (rotations and scales) for one renderstate? Each transform would have to correspond with one quad in a vertex array and each vertex quad would have a unique center point based on its texture. I am asking this because I need to rotate, scale, (and possibly translate though that is not as important) each vertex quad in a VertexArray around its own center point instead of around one center point.


In the code below I was able to resize my robot (the red figure in the image below) but not rotate the 22 layers that make up the robot around their own center point. Instead, they were rotated around the head of the robot as you can see below.
        sf::Texture* tex = new sf::Texture;
        tex->loadFromFile("spritesheet.png");
        sf::RenderStates rendState;

//tile Width and Height
//all the tiles are the same size
        float tileWH = tex->getSize().y;
        rendState.texture = tex;
                for (int j = 0; j < 22; j++) {
                        int i = (22 - j);
                        float yVal = (350.0f + (i*0.8f));
                        float left = xVal;
                        float top = yVal;

                        sf::Vertex * quad = &verticies[j * 4];

                        quad[0].position = sf::Vector2f(left, top + tileWH);
                        quad[1].position = sf::Vector2f(left, top);
                        quad[2].position = sf::Vector2f(left + tileWH, top);
                        quad[3].position = sf::Vector2f(left + tileWH, top + tileWH);
                       
                        quad[0].texCoords = sf::Vector2f(tileWH*i, tileWH);
                        quad[1].texCoords = sf::Vector2f(tileWH*i, 0.0f);
                        quad[2].texCoords = sf::Vector2f(tileWH*i + tileWH, 0.0f);
                        quad[3].texCoords = sf::Vector2f(tileWH*i + tileWH, tileWH);
                        sf::Transform transform;
                        sf::Transform secondTransfrom;
                        sf::Vector2f center = sf::Vector2f((tileWH / (2.0f)) + left, (tileWH / (2.0f)) + top);
                       
//rotation is only around the head of the robot instead of each image layer
                        secondTransfrom.rotate(angle, center);
//scaling is working
                        transform.scale(sf::Vector2f(5.0f, 5.0f), center);
                        rendState.transform *= secondTransfrom;
                        rendState.transform *= transform;
                        */

                }
                window->draw(verticies, rendState);

 
:

Pages: [1] 2