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

Pages: [1] 2 3 ... 5
1
General / ReĀ : Can't get SFML set up in qt creator
« on: October 25, 2016, 06:13:38 pm »
Hello, how should we get this to work with SFML 2.4 now? The "libs" directory no longer exists, it has been replaced by "extlibs" with different subdirectories; files like sfml-window.lib are nowhere to be found.

Thank you.

2
Network / Re: TCP Connection
« on: September 23, 2016, 10:27:29 am »
Okay, the fact that nobody seemed to find anything wrong in my code made me think it was completely operational, so I started to focus on other things... and it turned out the problem had nothing to do with the network framework. I do apologize so terribly...

If you're interested in the reason things were failing miserably, here's why. I have an enum.

enum Message : quint8   {
                                // ...
                                Join                                    = 15,
                                // ...
                                };

and the first packet that is to be sent in my project is a packet with Enum::Message::Join inside. So here's what I did:

NS::SendingPacket.clear();
NS::SendingPacket << Enum::Message::Join << // other stuff

But when unpacking, I was always reading 0 (instead of 15)... The following code fixed everything:

NS::SendingPacket.clear();
NS::SendingPacket << static_cast<quint8>(Enum::Message::Join) << // other stuff

So there you have it. I'm surprised I had to cast it, but as long as my code works I suppose it doesn't matter. Thank you again, all of you :)

3
Network / Re: TCP Connection
« on: September 22, 2016, 01:48:14 pm »
This is a Qt project, but since I like how user-friendly the SFML/Network library looks like, I'm using it.

So this is the slot called when the user (server) clicks the "Host" push button. As you can see, it's part of a class named ConnectionInterface, which basically derives from QMainWindow:

void ConnectionInterface::handleHosting(bool checked) const
{
        if (checked) // When you click it or when HostButton->setChecked(true) is called
        {
                if (NS::GameListener.listen(38956) != sf::Socket::Done)
                {
                        QMessageBox::critical(MainWidget, "Err", "Could not listen to port.");
                        HostButton->setChecked(false);
                }
                else
                {
                        NS::GameListener.setBlocking(false);
                        NS::GameListener.accept(NS::GamingSocket);
                        HostButton->setText("Hosting...");
               
                        QObject::connect(&GS::RoutineNetworkingTimer, SIGNAL(timeout(void)), const_cast<ConnectionInterface*>(this), SLOT(hostingRoutineFunction(void)));
                        GS::RoutineNetworkingTimer.start(GS::MinimalNetworkingPeriod);
                }
        }
        else // When you unclick it or when HostButton->setChecked(false) is called, but that never happens
        {
                NS::GameListener.close();
                NS::GamingSocket.disconnect();
                HostButton->setText("Host");
                NS::GameListener.setBlocking(true);

                GS::RoutineNetworkingTimer.stop();
                QObject::disconnect(&GS::RoutineNetworkingTimer, SIGNAL(timeout(void)), const_cast<ConnectionInterface*>(this), SLOT(hostingRoutineFunction(void)));
        }
}

Then ConnectionInterface::hostingRoutineFunction is called every 10 ms, until the sf::TcpSocket is accepted by the sf::TcpListener.

void ConnectionInterface::hostingRoutineFunction(void) const
{
        if (NS::GameListener.accept(NS::GamingSocket) != sf::Socket::Done)
                return;
       
        GS::RoutineNetworkingTimer.stop();
        QObject::disconnect(&GS::RoutineNetworkingTimer, SIGNAL(timeout(void)), const_cast<ConnectionInterface*>(this), SLOT(hostingRoutineFunction(void)));
       
        QObject::connect(&GS::RoutineNetworkingTimer, SIGNAL(timeout(void)), const_cast<ConnectionInterface*>(this), SLOT(gameRoutineFunction(void)));
        GS::RoutineNetworkingTimer.start(GS::MinimalNetworkingPeriod);

        // Do game-related, network-unrelated stuff
}

Then that function doesn't need to be called anymore, and we can move onto the function that is receiving packets over and over until the connection is closed / until the game is over. And this is what that function (ConnectionInterface::gameRoutineFunction) looks like:

void ConnectionInterface::gameRoutineFunction(void) const
{
        if ((NS::LastReceivingStatus == sf::Socket::Status::Partial && GS::PendingPacket) || not GS::PendingPacket)
        {
                NS::LastReceivingStatus = NS::GamingSocket.receive(NS::ReceivingPacket);
                GS::PendingPacket = (NS::ReceivingPacket.getDataSize() > 0);
        }
       
        if (GS::PendingPacket && NS::LastReceivingStatus == sf::Socket::Status::Done)
        {
                // and we never get there, for GS::PendingPacket is always false...
                // (while NS::LastReceivingStatus is always equal to sf::Socket::Status::NotReady)
        }
}

I'm glad you didn't ask me to see what the other side looks like ^^

4
Network / Re: TCP Connection
« on: September 22, 2016, 01:01:47 pm »
Well unless you have a better idea, my project is a card game, and I intend the player to be able to interact with the game scene at all times ^^ (The player interacts only with the other player, there's no other people involved.) I didn't know there was a FAQ, so I read it and it made me install Wireshark. I could check that a frame (or whatever it's called) was indeed sent from the client to the server, and inside that frame was what I had written. (I wrote an std::string in that packet, and I could find and read it on Wireshark.) Wireshark spotted and listed that frame both from the client's computer, and from the server's.

Unfortunately, my socket keeps returning NotReady on the server's end. I must be missing something, since as I said the connection was successfully established, and the packet was successfully sent and received, if not by the sf::TcpSocket, at least by the server's computer.

:S

5
Network / Re: TCP Connection
« on: September 22, 2016, 10:52:31 am »
Thanks for replying eXpl0it3r! Really! I think I got the gist of it now.

What are the most common mistakes that newbies make with sf::TcpSockets though? I'm currently having a problem with my sf::TcpSockets. Once the connection is established (and it always is, I have no problem on that score), an sf::Packet of 418 data bytes is sent from the client's side in one piece (although the socket itself is non-blocking) and the result status is sf::Socket::Status::Done. On the server's side, sf::TcpSocket::receive(sf::Packet&) always returns sf::TcpSocket::NotReady no matter what. The problem remains exactly the same if I try to send something from the server, and try to receive that thing on the client's side.

I repeated this experiment over and over and nothing has ever changed. I always send the sf::Packet successfully, but the other side never even sees it. My sf::TcpSocket is non-blocking and sf::TcpSocket::receive(sf::Packet&) is called by a QTimer every 10 ms.

Do I need to show some code, or could you share some common mistakes that I might have made first?

6
Network / Re: TCP Connection
« on: September 18, 2016, 04:44:47 pm »
I'm sorry to bump this but I realize there's yet another basic thing I'm not sure I understood. If the socket the sender uses to send data has Status::Done, does this mean that the sender is sure that the recipient has got the message?

Conversely, if the socket the recipient uses to receive data has Status::Done, does this mean that the recipient is sure that the sender is sure that his message went through?

Additional comment:
I apologize if I'm being annoying, but I don't seem to be getting many replies. Is there anything wrong with my messages? Does anyone in the SFML coding team know how their Network library work at all? I'm sorry if I'm asking questions, but I'm lacking basic information. As a newbie I thought it'd be smart to get here and ask. I would also be interested to know how to make an sf::TcpSocket back on track if it has an sf::Status of Error or Disconnected, since I failed to find any relevant information in the tutorial about that :S

Thanks!

7
Network / Re: TCP Connection
« on: August 02, 2016, 10:16:41 pm »
Using a third-party server is definitely an option. But I would like people to be able to play on their own as well.

Timestamps aren't an option because it's impossible to make both players' clocks start at the same time.

The only solution that I could think of so far is: whenever a player gets a message, they immediately send a reply saying ok. And whenever a player sends a message, they wait for the ok reply before starting their own QPropertyAnimation. If the next message they get isn't ok, the QPropertyAnimation is aborted and nothing happens.

In the situation where two players send a message at the same time, the next message they get isn't ok, but the other player's message. So each player forfeits their QPropertyAnimation and they have to send a message again. It's highly unlikely that they'll manage to send a message at the same time twice in a row.

Thoughts?

8
Network / Re: TCP Connection
« on: August 02, 2016, 06:26:41 pm »
I forgot to add that once a message went through, the exact same QPropertyAnimation is supposed to occur on the sender's end. So if Player 1 sends the message "Move Card_42 from pile A to pile B" and Player 2 sends the message "Move Card_42 from pile A to pile C" at the same time, one of the two players will have to forfeit their own message and follow the other one. The other message has to be discarded otherwise it would cause a segmentation fault  after the first message has been completely carried out. (Since Card_42 is no longer in pile A for neither player.)

So I need a way for players to know if their message has been acknowledged before or after they acknowledged their opponent's  message. If Player 1's message was acknowledged by Player 2 before Player 2 acknowledged Player 1's,  then it's obvious to both players that Player 1's message should be carried out, while Player 2's should be for ever disregarded.

Is this feasible with the SFML? If not, how would you solve this issue?

9
Network / Re: TCP Connection
« on: August 01, 2016, 06:15:48 pm »
Here's my predicament.

Two players are connected to each other. They send messages to each other. A message starts a QPropertyAnimation that lasts 250 ms, and for various reasons it is important that only one QPropertyAnimation is processed at a time. While a QPropertyAnimation is being processed, a player isn't able to send other messages, and should he receive one, it would be ignored anyway.

Let's go straight to the unlucky/problematic scenario. Due to misfortune or due to an Internet lag, while no QPropertyAnimation is being processed, both users send a message at the same time. How can I make sure that each player processes the same message and discards the other message? (For various reasons, the other message has to be discarded instead of simply delayed.)

How should I implement that? For now, I plan to give each user one sf::TcpSocket for sending, and one sf::TcpSocket (+ one sf::TcpListener) for receiving. Is this smart, or should I use only one sf::TcpSocket for both sending and receiving?

Thank you in advance for enlightening me.

10
Network / TCP Connection
« on: August 01, 2016, 01:15:57 pm »
Hi,

Let's assume that two users are connected through a TCP connection, with TCP sockets. During a very short amount of time (like 500 ms), the Internet connection between these two users is cut, for whatever reason. Unfortunately, during that short period of time, each user sent a (different) message to the other, using the TCP connection (sockets) that they set up earlier. When the Internet connection is up again, how will these two messages be handled ? Which one will be processed first, causing one user to get confirmation that their message went through first, before receiving the other user's message ?

Not sure if I'm clear enough, but thanks in advance for your input.

11
Network / Re: Compiling code doesn't compile anymore due to g++ update
« on: November 15, 2015, 07:56:20 pm »
Sounds like you're not linking against sfml-system or not in the right order.
Precisely! Thank you.

12
Network / Re: Compiling code doesn't compile anymore due to g++ update
« on: November 15, 2015, 02:19:45 pm »
I used the same SFML directory I first used when I installed it with github, and some things were removed, but now I get that:

/usr/local/lib/libsfgui.so: undefined reference to `sf::String::String(std::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> > const&)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::String(std::string const&, std::locale const&)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::Shader::loadFromMemory(std::string const&, std::string const&)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::toAnsiString(std::locale const&) const'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::end()'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::begin() const'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::end() const'
/usr/local/lib/libsfgui.so: undefined reference to `sf::Font::loadFromFile(std::string const&)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::Shader::setParameter(std::string const&, sf::Texture const&)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::String::begin()'
/usr/local/lib/libsfgui.so: undefined reference to `sf::Shader::setParameter(std::string const&, float, float)'
/usr/local/lib/libsfgui.so: undefined reference to `sf::Image::loadFromFile(std::string const&)'
collect2: error: ld returned 1 exit status
Makefile:211: recipe for target 'Menu' failed
make: *** [Menu] Error 1

Do you think I should re-download the whole directory from github?

13
Network / [Solved] Compiling code doesn't compile anymore due to g++ update
« on: November 15, 2015, 12:01:14 pm »
Hello,

I'm using Ubuntu 15.04 and was compiling my project fine until today. Yesterday I agreed to run the occasional Ubuntu update and today I rebooted my computer. G++ got updated to 5.1.1 and my code suddenly encounters the following linking problems:

ConnectionInterface.o: In function `ConnectionInterface::ConnectionInterface()':
/home/lol/Documents/Coding/Union/ConnectionInterface.cpp:64: undefined reference to `sf::IpAddress::toString[abi:cxx11]() const'
/home/lol/Documents/Coding/Union/ConnectionInterface.cpp:74: undefined reference to `sf::IpAddress::toString[abi:cxx11]() const'
ConnectionInterface.o: In function `ConnectionInterface::EstablishConnection()':
/home/lol/Documents/Coding/Union/ConnectionInterface.cpp:159: undefined reference to `sf::IpAddress::IpAddress(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Makefile:211: recipe for target 'Menu' failed
make: *** [Menu] Error 1

Usually when I get this issue, I just delete all .o files and start over, or check that I didn't forget any flag, but this time the problem persists. Any advice? Thanks.

14
Graphics / Re: Qt & SFML
« on: October 05, 2015, 01:10:08 pm »
What do you mean? I'm basically launching this function:

void Handler(int sig)
{
        std::cout << "Aborting..." << std::endl;
        void *array[10];
        size_t size;
        // get void*'s for all entries on the stack
        size = backtrace(array, 10);
        // print out all the frames to stderr
        fprintf(stderr, "Error: signal %d:\n", sig);
        backtrace_symbols_fd(array, size, STDERR_FILENO);
        exit(1);
}

15
Graphics / Re: Qt & SFML
« on: October 04, 2015, 08:23:08 pm »
Well I've tested my program on Ubuntu 15.04 and I have different problems. I -think- that the above problems are solved, but I can't be sure because I have another issue to take care of before I can finally see for myself.

It seems that sf::Texts cause problems when I try to sf::RenderWindow::draw them. Some traces:

./Menu(_Z7Handleri+0x56)[0x54916c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10d10)[0x7fe704668d10]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0xa4d2a)[0x7fe70437ad2a]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNSt8_Rb_treeIjSt4pairIKjN2sf4Font4PageEESt10_Select1stIS5_ESt4lessIjESaIS5_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS5_ERS1_+0x41)[0x7fe7064caea1]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Font8getGlyphEjjb+0x2b5)[0x7fe7064ca0b5]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Text20ensureGeometryUpdateEv+0x171)[0x7fe7064f4ca1]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Text4drawERNS_12RenderTargetENS_12RenderStatesE+0x1b)[0x7fe7064f5c5b]
/usr/local/lib/libsfml-graphics.so.2.3(_ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE+0x39)[0x7fe7064ea8e9]

Even if I comment some segfaulting lines, sf::Text::getLocalBounds also seems to be a problem sometimes:

./Menu(_Z7Handleri+0x56)[0x54a3a0]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10d10)[0x7fa60931fd10]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Font14setCurrentSizeEj+0x13)[0x7fa60b17e383]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Font20getUnderlinePositionEj+0x16)[0x7fa60b17e656]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Text20ensureGeometryUpdateEv+0x134)[0x7fa60b1abc64]
/usr/local/lib/libsfml-graphics.so.2.3(_ZNK2sf4Text14getLocalBoundsEv+0xd)[0x7fa60b1acbad]

Again, this is some code that works perfectly on its own, if it is completely separated from Qt. I checked that separately on Ubuntu 15.04 too. Any ideas? :)

Thank you for your help so far!

Pages: [1] 2 3 ... 5
anything