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

Pages: [1] 2
1
Network / Can someone help me with this simple client/server test?
« on: May 11, 2011, 02:26:25 am »
okay, this one might be a bit smaller and more simple. the problem is it only connects to one client instead of two. Can anyone help me figure out why?

Server:
Code: [Select]

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

void sendInfo(void *UserData)
{
    sf::IPAddress* ip = static_cast<sf::IPAddress*>(UserData);
    // Print something...
    while(true){
        // Create the UDP socket
        sf::SocketUDP Socket;

        // Create bytes to send
        char Buffer[] = "sending info.";

        // Send data to "192.168.0.2" on port 4567
        if (Socket.Send(Buffer, sizeof(Buffer), *ip, 4444) != sf::Socket::Done)
        {
            // Error...
        }
    }
}

void receiveInfo(void *userData)
{
    // Print something...
    while(true){
        // Create the UDP socket
        sf::SocketUDP Socket;

        // Bind it (listen) to the port 4567
        if (!Socket.Bind(4444))
        {
            // Error...
        }

        char Buffer[128];
        std::size_t Received;
        sf::IPAddress Sender;
        unsigned short Port;
        if (Socket.Receive(Buffer, sizeof(Buffer), Received, Sender, Port) != sf::Socket::Done)
        {
            // Error...
        }

        // Show the address / port of the sender
        std::cout << Buffer << std::endl;

        Socket.Close();

    }
}

int main()
{
    sf::IPAddress client[2];
    int connected = 0;
    while(connected < 2){
        // Create the UDP socket
        sf::SocketUDP Socket;

        // Bind it (listen) to the port 4567
        if (!Socket.Bind(4444))
        {
            // Error...
        }

        char Buffer[128];
        std::size_t Received;
        sf::IPAddress Sender;
        unsigned short Port;
        if (Socket.Receive(Buffer, sizeof(Buffer), Received, Sender, Port) != sf::Socket::Done)
        {
            // Error...
        }

        // Show the address / port of the sender
        client[connected] = Sender;

        Socket.Close();

        sf::Thread* send = new sf::Thread(&sendInfo, &client[connected]);
        sf::Thread* receive = new sf::Thread(&receiveInfo, &client[connected]);
        // Start it !
        send->Launch();
        receive->Launch();
        connected++;
    }

    while(true){

    }

    return EXIT_SUCCESS;
}



client:

Code: [Select]

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

void sendInfo(void *UserData)
{
    // Print something...
    while(true){
        // Create the UDP socket
        sf::SocketUDP Socket;

        // Create bytes to send
        char Buffer[] = "client sending info.";

        // Send data to "192.168.0.2" on port 4567
        if (Socket.Send(Buffer, sizeof(Buffer),  "127.0.0.1", 4444) != sf::Socket::Done)
        {
            // Error...
        }
    }
}

void receiveInfo(void *userData)
{
    // Print something...
    while(true){
        // Create the UDP socket
        sf::SocketUDP Socket;

        // Bind it (listen) to the port 4567
        if (!Socket.Bind(4444))
        {
            // Error...
        }

        char Buffer[128];
        std::size_t Received;
        sf::IPAddress Sender;
        unsigned short Port;
        if (Socket.Receive(Buffer, sizeof(Buffer), Received, Sender, Port) != sf::Socket::Done)
        {
            // Error...
        }

        // Show the address / port of the sender
        std::cout << Buffer << std::endl;

        Socket.Close();

    }
}

int main()
{
    // Create the UDP socket
    sf::SocketUDP Socket;

    // Create bytes to send
    char Buffer[] = "Client Joined.";

    // Send data to "192.168.0.2" on port 4567
    if (Socket.Send(Buffer, sizeof(Buffer), "127.0.0.1", 4444) != sf::Socket::Done)
    {
        // Error...
    }

    sf::Thread* send = new sf::Thread(&sendInfo);
    sf::Thread* receive = new sf::Thread(&receiveInfo);
    // Start it !
    send->Launch();
    receive->Launch();


    while(true){

    }

    return EXIT_SUCCESS;
}



2
Network / Can someone help me with this simple client/server test?
« on: May 10, 2011, 10:23:51 pm »
alright, I've been working on this for about 5 hours today alone, and I still can't get anything working. Can someone tell me what I'm doing wrong? I'm getting no output from the server at all, nor the client.

Client:
Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    // Create the main rendering window
    sf::IPAddress addy("76.121.76.188");


    sf::SocketUDP Socket;

    // Create bytes to send
    char Buffer[] = "Player joining.";

    // Send data to "192.168.0.2" on port 4444
    if (Socket.Send(Buffer, sizeof(Buffer), addy, 4444) != sf::Socket::Done)
    {
        cout << "Sending failed." << endl;
    }

    while (true)
    {
        // Process events
        if (addy.IsValid()){
            //recieve enemy posititon
            sf::SocketUDP receiverSocket;

            // Bind it (listen) to the port 4444
            if (!receiverSocket.Bind(4444))
            {
                cout << "binding failed" << endl;
            }

            //get data
            char buffer[128];
            std::size_t Received;
            sf::IPAddress Sender;
            unsigned short Port;

            if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
            {
                cout << "error receiveing packet" << endl;
            }

            else{
                cout<<buffer<<endl;
            }

            //send player position
            sf::SocketUDP Socket;
            ostringstream sin;
            sin << "Goodbye.";
            sin.str().c_str();

            // Send data to "192.168.0.2" on port 4444
            if (Socket.Send(sin.str().c_str(), sizeof(sin.str().c_str()), addy, 4444) != sf::Socket::Done)
            {
                cout << "Sending failed" << endl;
            }

        }
    }

    return EXIT_SUCCESS;
}


Server:
Code: [Select]

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

#include "player.h"
#include "playerthread.h"

using namespace std;

int main()
{
    bool done = false;
    int numConnected = 0;
    sf::IPAddress playerIP[2];
    Playerthread *pthread[2];
    // Start game loop
    while (!done)
{
        sf::SocketUDP receiverSocket;

        // Bind it (listen) to the port 4444
        if (!receiverSocket.Bind(4444))
        {
            cout << "binding failed" << endl;
        }

        //get data
        char buffer[128];
        std::size_t Received;
        sf::IPAddress Sender;
        unsigned short Port;

        if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
        {
            cout << "error receiveing packet" << endl;
        }

        else{
            playerIP[numConnected] = Sender;
            pthread[numConnected] = new Playerthread(playerIP[numConnected]);
            pthread[numConnected]->startThread();
            numConnected++;
        }

        // Show the address of the sender
        std::cout << Sender << std::endl;

        // Show the message
        std::cout << buffer << std::endl; // "Hi guys !"

        //close socket
        receiverSocket.Close();
    }

    return EXIT_SUCCESS;
}



Server Thread:
Code: [Select]

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

using namespace std;

class Playerthread : private sf::Thread{
public:
int get_RetLevel();

sf::IPAddress playerIP;

Playerthread(sf::IPAddress &nplayerIP){
        playerIP = nplayerIP;
}
void startThread(){
        Launch();
    }
private:
virtual void Run(){
while(true){
if (playerIP.IsValid()){
                    //send enemy position

                        sf::SocketUDP Socket;
                        ostringstream sin;

                        sin << "enemy local";
                        sin.str().c_str();

                        // Send data to "192.168.0.2" on port 4444
                        if (Socket.Send(sin.str().c_str(), sizeof(sin.str().c_str()), playerIP, 4444) != sf::Socket::Done)
                        {
                            cout << "Sending failed" << endl;
                        }
                    }

                    //recieve player posititon
                    sf::SocketUDP receiverSocket;

                    // Bind it (listen) to the port 4444
                    if (!receiverSocket.Bind(4444))
                    {
                        cout << "binding failed" << endl;
                    }

                    //get data
                    char buffer[128];
                    std::size_t Received;
                    sf::IPAddress Sender;
                    unsigned short Port;

                    if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
                    {
                        cout << "error receiveing packet" << endl;
                    }

                    else{
                        if(Sender.ToString().compare(playerIP.ToString())){
                            cout << "thread" << buffer << endl;
                        }
                    }

}
}
};


3
Network / Port problems
« on: May 10, 2011, 06:25:54 pm »
Yeah, my bad. I had ver 1.6 and reading the tutorial for 1.2 :\

4
Network / Port problems
« on: May 10, 2011, 12:15:29 pm »
I'm having the same problem. Why isn't this compiling?

Code: [Select]



#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
using namespace std;

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(640, 480, 32), "blah");
    sf::IPAddress addy("127.0.0.1");
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        if (addy.IsValid()){
            sf::SocketUDP Socket;

            // Create bytes to send
            char Buffer[] = "Hi guys !";

            // Send data to "192.168.0.2" on port 4444
            if (Socket.Send(Buffer, sizeof(Buffer), addy, 4444) != sf::Socket::Done)
            {
                cout << "sending failed";
            }

            //bind socket before recieveing data
            sf::SocketUDP socket2;

            // Bind it (listen) to the port 4444
            if (!socket2.Bind(4444))
            {
                cout << "binding failed";
            }

            //get data
            char buffer2[128];
            std::size_t Received;
            sf::IPAddress Sender;
            if (socket2.Receive(buffer2, sizeof(buffer2), Received, Sender) != sf::Socket::Done)
            {
                // Error...
            }

            // Show the address of the sender
            std::cout << Sender << std::endl;

            // Show the message
            std::cout << buffer2 << std::endl; // "Hi guys !"

            //close socket
            socket2.Close();

        }

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}



Errors:
Code: [Select]

/home/ubuntu/Desktop/projects/Metaship/main.cpp|51|error: no matching function for call to ‘sf::SocketUDP::Receive(char [128], unsigned int, size_t&, sf::IPAddress&)’|

5
General / load a array of sprites using 1 sf::Image?
« on: April 07, 2011, 11:42:01 am »
Oh, wow. I didn't know that! Thank you very much. you've helped me out a lot! ^_^

6
General / load a array of sprites using 1 sf::Image?
« on: April 07, 2011, 11:35:35 am »
But isn't the image data in the sf::Sprite object too?

7
General / load a array of sprites using 1 sf::Image?
« on: April 07, 2011, 11:20:39 am »
I want to load a array of sf::Sprites using only 1 sf::Image, and loading images to that image over and over. I don't want to create a array of images because I'm worried about ram usage. But I can't get anything to work. It aether loads every sprite as 1 image, or gives me a white box. How would I go about doing this?

edit: my code: http://pastebin.com/RW0ZeySP

8
General / Drawing tilemap is lowering my fps to a crawl
« on: April 03, 2011, 05:53:18 pm »
That worked! Thank you very much!!!!

9
General / Drawing tilemap is lowering my fps to a crawl
« on: April 03, 2011, 05:10:54 pm »
Quote from: "Elffus"
If tiles aren't being constantly changed wouldn't it be easier to store them in an sf::Image and only perform changes when necessary? Showing one big image is much faster than loads of smaller ones I believe.
How would I go about doing this?

10
General / Drawing tilemap is lowering my fps to a crawl
« on: April 03, 2011, 04:41:27 pm »
Okay, I'm trying to get my fps to 60, but right now it's at around 20. What can I do to this code to speed it up? Note: this is c++ using sfml.

Code: [Select]
       App.Clear();
        for(int x = 0; x < lv.width; x++){
            for(int y = 0; y < lv.height; y++){
 
                int tileXCoord = 0;
                int tileYCoord = 0;
                int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;
 
                if (lv.tile[x][y] != 0)
                {
                    tileXCoord = lv.tile[x][y] % tileSheetWidth;
                    tileYCoord = lv.tile[x][y] / tileSheetWidth;
                }
 
                tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
                tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
                App.Draw(tilemap);
            }
        }
 
        playerSprite.SetSubRect(sf::IntRect(player.width * player.frame, player.height * player.state,
                                       (player.width * player.frame) + player.width, (player.height * player.state) + player.height));
        playerSprite.SetPosition(player.x, player.y);
 
        App.Draw(playerSprite);
 
        if(player.walking){
            if(player.frameDelay >= 0)
                player.frameDelay--;
 
            if(player.frameDelay <= 0){
 
                player.frame++;
                player.frameDelay = 10;
 
                if(player.frame >= 4)
                    player.frame = 0;
            }
        }
 
 
        for(int x = 0; x < lv.width; x++){
            for(int y = 0; y < lv.height; y++){
 
                int tileXCoord = 0;
                int tileYCoord = 0;
                int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;
 
                if (lv.ftile[x][y] != 0)
                {
                    tileXCoord = lv.ftile[x][y] % tileSheetWidth;
                    tileYCoord = lv.ftile[x][y] / tileSheetWidth;
                }
 
                tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
                tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
                App.Draw(tilemap);
            }
        }
 
 
        App.Display();

11
Graphics / Grey box displaying around sprite's loaded image.
« on: April 01, 2011, 04:27:33 am »
Quote from: "netdragon"
I'm a teammate of the OP and have new information. I just found a solution of calling SetSmooth(false) but not sure why that prevented the artifact. It'd be great if we still had the option of smoothing. Any ideas?

Code: [Select]

void ViewBase::drawImage(sf::RenderWindow & target, const std::string & filename, const Point & origin)
{
    sf::Image sfi;
    sfi.SetSmooth(false);
    sf::Sprite sprite;
    if (!sfi.LoadFromFile(filename))
    {
        Log::debug("Failed to load file");
        return;
    }
    sprite.SetImage(sfi);
    sprite.SetPosition(origin.x,origin.y);
    target.Draw(sprite);
}


The image in question (as on disk, without the artifact created when displayed in SFML):
This helped me. Thank you. :)

12
General / How to test if the Joystick POV is at angle 90?
« on: March 31, 2011, 09:03:14 am »
Code: [Select]

if((Event.Type == sf::Event::JoyMoved) && (Event.JoyMove.Axis == sf::Joy::AxisPOV) && (Event.JoyMove.Position >= 80 && Event.JoyMove.Position <= 100)){
                Sound.Play();
                cout << Event.JoyMove.Position <<endl;
            }


Still not working. tried on 2 controllers.

13
General / How to test if the Joystick POV is at angle 90?
« on: March 31, 2011, 05:34:19 am »
How would I do that?
I tried

Code: [Select]

if((Event.Type == sf::Event::JoyMoved) && (Event.JoyMove.Axis == 0) && (Event.JoyMove.Position == 90))


But that didn't work.

14
General / Problem making SFML Window (And any other SFML)
« on: October 09, 2010, 09:27:46 pm »
Quote from: "Laurent"
Quote
I can make the System just fine, and I see lib/mingw/libsfml-system-d.a and the .dll with it

It's impossible, the output filename is libsfml2-system-d.a.
Yup, on checking this you're right, but I do have libsfml2-system-d.a  in that path. and the .dll version and not libsfml-system-d (I have sfml2-system-d, not sfml-system-d).

15
General / Problem making SFML Window (And any other SFML)
« on: October 09, 2010, 02:02:48 am »
Okay, so when I open the workspace in sfml2/build/codeblocks I can make the System just fine, and I see lib/mingw/libsfml-system-d.a and the .dll with it, but when I  double  click on the Window project in the workspace I get this error:

Code: [Select]
Linking dynamic library: ..\..\lib\mingw\sfml2-window-d.dll
mingw32-g++.exe: ..\..\lib\mingw\libsfml2-system-d.a: No such file or directory


Anyone know why? It's right where it should be, so I don't know why I get this error.

Pages: [1] 2