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

Pages: 1 2 [3]
31
Network / sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« on: April 14, 2010, 07:01:50 pm »
I just tried updating to 1.6, but it didn't work too well. :P

It still goes up, and when I try to run the executable without going through Code::Blocks (like double clicking the EXE) it says it can't find libgcc_s_dw2-1.dll (like last time I tried to upgrade) (although this time I did try to upgrade the compiler). :roll:

I'm not sure if this helps, but the socket isn't valid before using SetBlocking and afterwards it is.

Quote from: "Laurent"
Quote
Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! Laughing When I add it in, it works just the same.

Yep, the linker seems to care only about variables, not functions. If you use the graphics module you'll get some errors.


I've never done it when using graphics either...

I'll just keep testing different things.

EDIT: It goes up at a much slower rate (around 100) when I use Listen first:

Code: [Select]

#include <SFML/Network.hpp>
#include <iostream>

using namespace std;
using namespace sf;

int main()
{
    bool isTesting = true;
    bool triedOnce = false;
    while ( isTesting )
    {
        sf::SocketTCP *testSocket = new sf::SocketTCP;
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 1: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 1: Socket isn't valid." << std::endl;
            }
        }
        testSocket->Listen( 23132 );
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 2: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 2: Socket isn't valid." << std::endl;
            }
        }
        testSocket->SetBlocking( true );
        if ( !triedOnce )
        {
            if ( testSocket->IsValid() )
            {
                cout << "Test 3: Socket is valid." << std::endl;
            }
            else
            {
                cout << "Test 3: Socket isn't valid." << std::endl;
            }
        }
        delete testSocket;
        triedOnce = true;
    }
    return 0;
}


It's not valid on test 1 but afterwards it is.

EDIT 2: Changing the order of SetBlocking and Listen doesn't do anything, but if I comment out Listen it goes up fast again.

EDIT 3: SocketUDP does the same thing, except the socket is valid from the start.

32
Network / sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« on: April 14, 2010, 05:34:47 pm »
I'm finally trying the networking package again, but I'm having another problem, which is probably another silly mistake. :(

I'm using SFML 1.5 (dynamically linked) (going to upgrade soon) on Windows XP with Code::Blocks.

When I open task manager and go under processes, the far right column is Mem Usage, and processes usually have something like 4,484 K. This number goes up by around 10,000 (for the application I'm trying to make) every half-a-second-ish. I've been playing around with commenting stuff, and I found the problem (I think).

I make a pointer to a socket, and it points to one made with new. At first I thought it happened because I didn't delete it, but when all I had was new and delete, it worked fine.

Earlier, it was only going up when I used SetBlocking to false, but now it does it if I use SetBlocking at all...

Don't bother asking for a minimal example, I already made one! :D

Code: [Select]

#include <SFML/Network.hpp>

using namespace sf;

int main()
{
    bool isTesting = true;
    while ( isTesting )
    {
        sf::SocketTCP *testSocket = new sf::SocketTCP;
        testSocket->SetBlocking( true );
        delete testSocket;
    }
    return 0;
}


For once, I would be happy if it was a silly mistake. :P



Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! :lol: When I add it in, it works just the same.

33
Graphics / 3d character
« on: March 29, 2010, 11:20:31 pm »
The full SDK has an OpenGL sample which draws a rotating 3D cube. You could probably borrow code from that, and load the 3D model (I don't know how) and make/find a function to draw it (the uses SFML).

As for animating, I don't know. :P You might try storing the current animation to show (and current "frame"), and then adding a few if statements to check what animation/stage your on. I'm not sure if this works the same in 3D though, so you might want to look on Google (and/or wait for more replies) on how to do that.

34
System / Problems with a Class Inheriting from sf::Thread
« on: March 29, 2010, 09:19:36 pm »
I never knew that. I guess you (or me, in this case.) learn something new every day. :)

I wish the problems I asked about weren't silly mistakes. Next time, I'll ask somewhere else (if it's something like that) so that you can help people who's problem has to do with SFML and not C++ in general. :)

Thanks! But now that it works, there's apparently a problem with a font a chose (judging by the error). That belongs in the Graphics section though, so I'll post that in there, instead (if I can't find anything in search).

35
System / Problems with a Class Inheriting from sf::Thread
« on: March 29, 2010, 03:50:24 am »
I'm using SFML 1.5 linked dynamically, on Microsoft Windows XP Professional (Version 2002, Service Pack 3).

Compiler Errors:
Quote
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\main.cpp|24|error: no matching function for call to `LoadingThread::LoadingThread()'|
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\Thread_Class.h|10|note: candidates are: LoadingThread::LoadingThread(const LoadingThread&)|


I have a pretty good feeling that I'm not supposed to define anything of my own that's public (when inheriting public sf::Thread), because commenting that out makes it compile fine (except for the 'LoadingThread has no member X ' errors).

Relevant Part of main.cpp
Code: [Select]
   LoadingThread loading;
    loading.images = gameImages;
    loading.images = gameFonts;
    loading.Launch();



Thread_Class.h:
Code: [Select]
#ifndef THREAD_CLASS_H
#define THREAD_CLASS_H

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include <map>

class LoadingThread : public sf::Thread
{
    private:
        int loadedSoFar;
        virtual void Run();

    public:
        int GetLoadedSoFar();
        std::map<std::string, sf::Image>& images;
        std::map<std::string, sf::Font>& fonts;
};

#endif

36
Network / Send() goes to... which executable?
« on: January 04, 2010, 07:24:44 pm »
I don't think so, considering I had no idea there was one.... :X

Sorry for bothering you.

37
Network / Send() goes to... which executable?
« on: January 04, 2010, 03:29:33 am »
I am getting thoroughly confused. I am trying to make a (semi-simple) chat program, but it seems random which application it chooses to send it to (when multiple are open) (usually the second one opened, sometimes the first). It also doesn't necessarily send it to one in server mode, even when I changed the 'to server' and 'to client' ports! I have been (mostly) trying this on one computer. When I opened the server on one computer and a client on another, I sent a message and it gave me the error message (on the server). Now when I open another on the server computer and send something, it sends it to itself, A LOT. It doesn't give me the error, either. Can someone point out where in my code I am going wrong?

(By the way, I already know what happens when a message is sent while you are typing, I plan on moving to a normal window later.)

Code: [Select]

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

//Namespaces
using namespace std;
using namespace sf;

//Constants
const int CONNECT = 1;
const int HOST = 2;
const int UNKNOWN = 3;    //This part will be implemented later.

//Classes
class client_receive : public sf::Thread
{
    public:
        bool receiving;
        sf::Packet packet;
        sf::IPAddress sender;
        sf::SocketUDP socket;
        string buffer;
        unsigned short port;

    private:

        virtual void Run()
        {
            while (receiving == true)
            {
                if (socket.Receive(packet,sender,port) != sf::Socket::Done)
                {
                    cout << "Odd... It seems there was an error receiving the message.\n";
                }
                string buffer;
                packet >> buffer;
                cout << buffer << "\n";
                packet.Clear();
            }
        }
};

int main()
{
    cout << "Welcome to the SGM Chat! Please wait for the program to load...\n";
    cout << "CAUTION: Program uses UDP, so some messages may not be received.\n\n";
    sf::SocketUDP socket;
    if (!socket.Bind(54358))
    {
        cout << "ERROR BINDING SOCKET\n";
    }
    sf::IPAddress ip = sf::IPAddress::GetLocalAddress();
    bool answ_ques = false;
    string answ_to;
    int answ_res;
    while (answ_ques == false)
    {
        cout << "Would you like to:\n";
        cout << "\tA. Connect to a Server\n";
        cout << "\tB. Host a Server\n";
        getline(cin,answ_to);
        if (answ_to == "A" or answ_to == "a")
        {
            cout << "\nWell goody! Please enter the IP address.\n";
            answ_res = CONNECT;
            answ_ques = true;
        }
        else if (answ_to == "B" or answ_to == "b")
        {
            cout << "\nTell people on your network to connect to " << ip << ", if they are in your network. You can go to whatismyip.org to get your external IP address, but using that you will probably need to port forward.\n\n";
            answ_res = HOST;
            answ_ques = true;

        }
        else
        {
            cout << "\nUh, you need to pick one of the two choices. Try READING them this time.\n\n";
            answ_res = UNKNOWN;
        }
    }
    if (answ_res == HOST)
    //Host will be separated later.
    {
        cout << "Open another window if you want to talk, depending on how busy your server is you might not get to read much.\n\n";
        //sf::SelectorUDP selector;
        std::vector<sf::IPAddress> clients;
        bool not_canc = true;
        sf::IPAddress sender;
        unsigned short port;
        bool client_found = false;
        while (not_canc == true)
        {
            sf::Packet packet;
            if (socket.Receive(packet,sender,port) != sf::Socket::Done)
            {
                cout << "Odd... It seems there was an error receiving the message.\n";
            }
            string buffer;
            packet >> buffer;
            cout << buffer << "\n";
            packet.Clear();
            packet << buffer;

            for (unsigned int i = 0; i < clients.size(); i++)
            {
                if (clients[i] == sender)
                {
                    client_found = true;
                }
                else
                {
                    socket.Send(packet, clients[i], 54359);
                }
            }
            if (client_found == false)
            {
                clients.push_back(sender);
            }
            packet.Clear();
            client_found = false;
        }
    }
    else if (answ_res == CONNECT)
    {
        string str_tocon;
        bool inc_ip = true;
        while (inc_ip == true)
        {
            getline(cin,str_tocon);
            sf::IPAddress ip_tocon(str_tocon);
            if (ip_tocon./*sf::IPAddress::*/IsValid() and str_tocon != "" and str_tocon != " ")
            {
                cout << "\nYay! The IP is valid!\n";
                inc_ip = false;
            }
            else
            {
                cout << "\nYou are very naughty. That IP is NOT valid. Please try again.\n";
                inc_ip = true;
            }
        }
        string str_tosen;
        cout <<"Now, what is your name?\n";
        string user;
        getline(cin,user);
        bool sen_msg = true;
        sf::Packet packet;
        cout << "\n";
        sf::IPAddress sender;
        client_receive thread;
        thread.receiving = true;
        thread.port = 54359;
        thread.socket = socket;
        thread.Launch();
        while (sen_msg == true)
        {
            getline(cin,str_tosen);
            std::stringstream stri_stre;
            stri_stre << user << ": " << str_tosen;
            packet << stri_stre.str();
            sf::IPAddress ip_tocon(str_tocon);
            /*if (*/socket.Send(packet, ip_tocon, 54358)/* != )
            {
                cout << "Error sending message.";
            }*/;
            packet.Clear();
        }
    }
    socket.Close();
    return 0;
}


(I am using SFML 1.5)

38
System / Is there anything wrong with a WHILE statement in a thread?
« on: January 04, 2010, 02:42:20 am »
Good, thanks. :)

39
System / Is there anything wrong with a WHILE statement in a thread?
« on: January 04, 2010, 02:05:38 am »
Also, would it be bad to put a blocking function (i.e Receive() in sf::Socket) in that while loop?

Pages: 1 2 [3]
anything