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

Pages: [1] 2 3 4
1
SFML projects / Re: SFNUL
« on: February 24, 2014, 03:36:45 am »
Hey Binary,

I remember you mentioning this library a while back to me in pm. I'm still lurking around here, just low on time :(.  Wanted to pop in and just say congrats and thanks for releasing this! 

I'm sure it is quality and I look forward to using it when I have the time to get into game coding again :)


2
Network / Re: UDP simple functions
« on: August 17, 2013, 06:59:14 am »
Doesn't SocketServerTest.setBlocking(0); set you in non-blocking mode meaning your receive function always returns immediately?

3
General discussions / Re: SFML Game Development -- A book on SFML
« on: July 01, 2013, 09:23:14 am »
Was very happy to see this mentioned on the main SFML page -- went ahead and bought it; looks like exactly what I'm looking for.

Very excited to read, and congratulations on the release!


[EDIT] Reading the PDF (which is great Packt included with my hard copy book... head start! :D)... so far... fantastic!  Work tomorrow (I guess today already since I am now in the AM's :P) is going to come to a crawl because I will be so eager to continue reading this =]].

4
SFML projects / Re: Simple Paint Program Example
« on: May 20, 2013, 05:02:45 am »
please put code=cpp tags around your source ;], thanks for the share

5
Haven't compiled or tried it yet/know if this is a valid idea, but have you tried sticking the line

sf::TcpListener    listener;
 

inside your while(1) loop?

6
SFML website / Re: Post content deleted before submission, logged off
« on: April 11, 2013, 06:33:49 am »
For long posts I suggest getting in the habit of writing in notepad or something first.  Very frustrating when it happens XD

7
Network / Re: What do I need to send?
« on: March 13, 2013, 01:37:11 am »
Just click modify on the original post and change the subject line ;]

8
General / Re: Declaring a global RenderWindow
« on: March 12, 2013, 03:29:56 am »
I probably gave a little bit of a bad example, but to explain:

I had a face object that I defined that draw function.  That draws other objects that I have that also have that draw function defined.  So in main I can just do a draw of my face object. 

(I'll post some more when I get back home)


the following is all heavy pseudo code

so in main:
renderwindow window

gameLoop()
{
   pool events

   do stuff
   
   window.clear()
   window.draw( ObjectA )
   window.display()
}
 

objecta.hpp
class
{
  public:
       ...
  private:
          //we use this so we can have a nice draw(object) format
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
        ....
        ObjectB anotherThing;
};
 


objecta.cpp
void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw( anotherThing );
}
 

objectb.cpp
  another draw function defined
 


You can peek at what I did w/ http://en.sfml-dev.org/forums/index.php?topic=10363.0

9
General / Re: Declaring a global RenderWindow
« on: March 12, 2013, 02:17:44 am »
I recall reading this post:

http://en.sfml-dev.org/forums/index.php?topic=10855.msg74954#msg74954


Although I did a quick test and it does compile/run (though I think I misread the post now that I look back at it ;]):

#include <SFML/Graphics.hpp>

sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Playground");

int main( int argc, char* argv[])
{
    sf::RectangleShape rectangle;
    rectangle.setSize(sf::Vector2f(100, 50));
    rectangle.setOutlineColor(sf::Color::Red);
    rectangle.setOutlineThickness(5);
    rectangle.setPosition(10, 20);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {

                window.close();
            }
        }
        window.draw( rectangle );
        window.display();
        window.clear();
    }
   return 0;
}
 


But why exactly would you need it global?   If you have your main game loop drawing and updating states, it should be limited to that scope?

Any object can define its own draw function

    private:
        //we use this so we can have a nice draw(object) format
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
 

void Face::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    target.draw( *m_LeftEye );
    target.draw( *m_RightEye );
    target.draw( *m_Mouth );
    target.draw( *m_Nose );
}
 


That way in main you can just do a window.draw(face)

10
Network / Re: [Updated] Movement Lag on Client
« on: March 10, 2013, 10:00:01 am »
So I've cleaned up the code a touch...


I'm sending a packet with x y coord that will be used as a move offset every 1/3 of a second. 

I've identified that the movement was choppy in my previous post's code on the client end because the move distance offset is larger than compared to the server between window draws. 

The more packets I send per second, the smoother movement is on the client end because the movement offset between draws are smaller -- but this is not a solution... we want to keep @ about 30 packets a second.

I've added interpolation, and this has seemed to help the smoothness a lot -- although you can still notice the client side is slightly sluggish and very very slightly jumpy.  Still trying to figure out how to fix this.

One thing I am really confused about is this:


The black line is the server box movement.  At snap two, we send to the client pos x, pos y (grey line)... because the client doesn't know about the move left and move right of the server he will just go straight down with his interpolation...  If the server sends more data, then our packet size gets bigger and I'm guessing that's bad?  I think I could always send more data and not render it... just use it for any extra calculations and render based on how I am doing it now (the green line)



Current Result
http://www.youtube.com/watch?v=8IaDKJr2fJA


Some Articles I read for reference:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking  <-- very good article
http://en.wikipedia.org/wiki/Client-side_prediction
http://www.mindcontrol.org/~hplus/epic/
http://www.racer.nl/tech/multiplayer.html

I've also attached the below code incase you want to grab it and don't want to copy paste
updated tcp_issue.hpp
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <cmath>


const float MOVE_SPEED = 70;
const int PORT = 7777;

sf::TcpSocket socket;
sf::Mutex globalMutex;
sf::Packet serverPacket;


bool quit = false;

std::string v_command = "";

float v_offset_x = 0;
float v_offset_y = 0;


void serverListener();
void serverSend();
void clientListener();



void issueServer( std::string mode, std::string method )
{
    std::cout << "Incoming mode: " << mode << std::endl;
    std::cout << "Incoming method: " << method << std::endl;


    sf::Thread serverListenerThread(&serverListener);
    sf::Thread clientListenerThread(&clientListener);



    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Playground");
    window.setFramerateLimit(60);

    sf::Clock Clock;
    sf::Clock PacketClock;
    int packet_counter = 0;

    sf::Time time;

    sf::RectangleShape rectangle;
    rectangle.setSize(sf::Vector2f(100, 50));
    rectangle.setOutlineColor(sf::Color::Red);
    rectangle.setOutlineThickness(5);
    rectangle.setPosition(10, 20);


    int left_over_x = 0;
    int left_over_y = 0;
    float offset_x = 0;
    float offset_y = 0;
    std::string command = "";

    if( mode.compare("server") == 0 )
        serverListenerThread.launch();
    else
    {
        socket.connect("127.0.0.1",7777);
        clientListenerThread.launch();
    }


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                quit = true;

                if( mode.compare("server") == 0 )
                    serverListenerThread.terminate();
                else
                    clientListenerThread.terminate();

                window.close();
            }
        }
        if( mode.compare("server") == 0 )
        {
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                rectangle.move(-1*MOVE_SPEED*time.asSeconds(),0);

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                rectangle.move(0,1*MOVE_SPEED*time.asSeconds());

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                rectangle.move(1*MOVE_SPEED*time.asSeconds(),0);

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                rectangle.move(0,-1*MOVE_SPEED*time.asSeconds());

        }
        else //client mode
        {
            if( v_command.compare("move") == 0 )
            {
                globalMutex.lock();
                command = v_command;

                offset_x = v_offset_x - rectangle.getPosition().x;
                offset_y = v_offset_y - rectangle.getPosition().y;

                v_command = "";
                v_offset_x = 0;
                v_offset_y = 0;
                globalMutex.unlock();

                left_over_x = offset_x;
                left_over_y = offset_y;

            } //end of if v_command is "move"

            float move_offset = MOVE_SPEED*time.asSeconds();
            //interpolation
            if( left_over_x != 0 )
            {
                if( left_over_x < 0 )
                {
                    if( (left_over_x + move_offset) < 0 )
                    {
                        rectangle.move(-1*move_offset,0);
                        left_over_x += move_offset;
                    }
                    else
                    {
                        rectangle.move(left_over_x,0);
                        left_over_x = 0;
                    }
                }
                else if( left_over_x > 0 )
                {
                    if( (left_over_x - move_offset) > 0 )
                    {
                        rectangle.move(move_offset,0);
                        left_over_x -= move_offset;
                    }
                    else
                    {
                        rectangle.move(left_over_x,0);
                        left_over_x = 0;
                    }
                }
            }
            if( left_over_y != 0 )
            {
                if( left_over_y < 0 )
                {
                    if( (left_over_y + move_offset) < 0 )
                    {
                        rectangle.move(0,-1*move_offset);
                        left_over_y += move_offset;
                    }
                    else
                    {
                        rectangle.move(0,left_over_y);
                        left_over_y = 0;
                    }
                }
                else if( left_over_y > 0 )
                {
                    if( (left_over_y - move_offset) > 0 )
                    {
                        rectangle.move(0,move_offset);
                        left_over_y -= move_offset;
                    }
                    else
                    {
                        rectangle.move(0,left_over_y);
                        left_over_y = 0;
                    }
                }
            }
            //end of interpolation

            window.draw( rectangle );
            window.display();
            window.clear();

        } //end of client mode if


        if( mode.compare("server") == 0 )
        {
            window.draw( rectangle );
            window.display();
            window.clear();

            if( PacketClock.getElapsedTime().asSeconds() >= 1 )
            {
                packet_counter = 0;
                PacketClock.restart();
            }
            else if( (PacketClock.getElapsedTime().asMilliseconds()/23) > packet_counter )
            {
                serverPacket << "move" << rectangle.getPosition().x << rectangle.getPosition().y;
                serverSend();
                packet_counter++;
            }
        }

        time = Clock.restart();
    }
}

void serverListener()
{
    std::cout << "Listening for clients." << std::endl;
    sf::TcpListener listener;
    listener.listen(PORT);
    listener.accept(socket);
    std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
}

void clientListener()
{
    std::string command;
    float offset_x;
    float offset_y;

    while( !quit )
    {
        socket.receive(serverPacket);

        while( !serverPacket.endOfPacket() )
        {
            globalMutex.lock();
            serverPacket >> command >> offset_x >> offset_y;
            v_command = command;
            v_offset_x = offset_x;
            v_offset_y = offset_y;
            globalMutex.unlock();
        }

        serverPacket.clear();
    }
}


void serverSend()
{
    if( serverPacket.getDataSize() > 0 )
    {
        globalMutex.lock();
        socket.send(serverPacket);
        serverPacket.clear();
        globalMutex.unlock();
    }
}
 

[attachment deleted by admin]

11
Network / Re: Movement Lag on Client
« on: March 09, 2013, 11:04:02 am »
(Updated code 3/10/2013)

Well, I think I am getting a lot closer!

http://www.youtube.com/watch?v=wdMOjeutUZI&hd=1



Updated code is below.  Video is more choppy then when running and I am not screen recording... but I am getting very close to what I want to achieve.

I think client end is choppy because it is making bigger moves then server... maybe I have to break this down somehow for a smoother move?

Am I taking the correct approach now?  Thanks (=.. I think after some more work I'll finally get this how I want.


Here is the updated code
main.cpp
#include "tcp_issue.hpp"


int main( int argc, char* argv[])
{

    if( argc > 2 )
    {
        //tcp/udp issue
        issueServer( argv[1], argv[2] ); //[server,client] [tcp,udp]
    }


    return EXIT_SUCCESS;
}
 

tcp_issue.hpp
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <queue>
#include <cmath>


const float MOVE_SPEED = 70;
const int PORT = 7777;

sf::TcpSocket socket;
sf::Mutex globalMutex;
sf::Packet serverPacket;


bool quit = false;
std::string sendString = "";

std::string v_command;
float v_offset_x = 0;
float v_offset_y = 0;


void serverListener();
void serverSend();
void clientListener();



void issueServer( std::string mode, std::string method )
{
    std::cout << "Incoming mode: " << mode << std::endl;
    std::cout << "Incoming method: " << method << std::endl;


    sf::Thread serverListenerThread(&serverListener);
    sf::Thread clientListenerThread(&clientListener);



    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Playground");
    window.setFramerateLimit(60);

    sf::Clock Clock;
    sf::Clock PacketClock;
    int packet_counter = 0;

    sf::Time time;

    sf::RectangleShape rectangle;
    rectangle.setSize(sf::Vector2f(100, 50));
    rectangle.setOutlineColor(sf::Color::Red);
    rectangle.setOutlineThickness(5);
    rectangle.setPosition(10, 20);



    if( mode.compare("server") == 0 )
        serverListenerThread.launch();
    else
    {
        socket.connect("127.0.0.1",7777);
        clientListenerThread.launch();
    }


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                quit = true;

                if( mode.compare("server") == 0 )
                    serverListenerThread.terminate();
                else
                    clientListenerThread.terminate();

                window.close();
            }
        }
        if( mode.compare("server") == 0 )
        {
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                rectangle.move(-1*MOVE_SPEED*time.asSeconds(),0);

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                rectangle.move(0,1*MOVE_SPEED*time.asSeconds());

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                rectangle.move(1*MOVE_SPEED*time.asSeconds(),0);

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                rectangle.move(0,-1*MOVE_SPEED*time.asSeconds());

        }
        else //client mode
        {
            float offset_x = 0;
            float offset_y = 0;
            std::string command = "";


            if( v_command.compare("move") == 0 )
            {
                sf::Clock test_clock;
                sf::Time test_time;
                globalMutex.lock();
                command = v_command;
                offset_x = v_offset_x - rectangle.getPosition().x;
                offset_y = v_offset_y - rectangle.getPosition().y;
                v_command = "";
                v_offset_x = 0;
                v_offset_y = 0;
                globalMutex.unlock();

                rectangle.move(offset_x,offset_y);
            }

            window.draw( rectangle );
            window.display();
            window.clear();

        }


        if( mode.compare("server") == 0 )
        {
            window.draw( rectangle );
            window.display();
            window.clear();

            if( PacketClock.getElapsedTime().asSeconds() >= 1 )
            {
                packet_counter = 0;
                PacketClock.restart();
            }
            else if( (PacketClock.getElapsedTime().asMilliseconds()/30) > packet_counter )
            {
                globalMutex.lock();
                serverPacket << "move" << rectangle.getPosition().x << rectangle.getPosition().y;
                globalMutex.unlock();

                serverSend();
                packet_counter++;
            }
        }

        time = Clock.restart();
    }
}

void serverListener()
{
    std::cout << "Listening for clients." << std::endl;
    sf::TcpListener listener;
    listener.listen(PORT);
    listener.accept(socket);
    std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
}

void clientListener()
{
    std::string command;
    float offset_x;
    float offset_y;

    while( !quit )
    {
        socket.receive(serverPacket);

        while( !serverPacket.endOfPacket() )
        {
            globalMutex.lock();
            serverPacket >> command >> offset_x >> offset_y;
            v_command = command;
            v_offset_x = offset_x;
            v_offset_y = offset_y;
            globalMutex.unlock();
        }

        serverPacket.clear();
    }
}


void serverSend()
{
    if( serverPacket.getDataSize() > 0 )
    {
        globalMutex.lock();
        socket.send(serverPacket);
        serverPacket.clear();
        globalMutex.unlock();
    }
}
 

12
SFML projects / Re: Space Invaders
« on: March 09, 2013, 08:19:26 am »
Kool.   Good work :)


Some suggestions.


1) Pause button
2) Visual feedback when you get hit
3) 
http://www.youtube.com/watch?v=437Ld_rKM2s 
go to out about 1.22 seconds  ; I think on your game you need to decrease the enemy line length each time the farthest enemy is eliminated.  They should move all the way to the right of the screen (if this makes sense)

4)  I'm not sure if this is how the game is intented, but it seems to me the enemies move reallly... really fast after a little while.  Did you limit fps/take into consideration different computer speeds?



Maybe include an attachment of the source code so people can peek at it :)

13
Network / Re: What do I need to send?
« on: March 09, 2013, 02:37:33 am »
I was actually having the same problem:

http://en.sfml-dev.org/forums/index.php?topic=10803.0

What I was recommended was to limit packets sent (30 packets per second) and to actually send offsets of position instead of just move down.

Laurent said that on my end it was not really network lag as the movements being performed were the same, but actually the way I handled what was being sent.  I'll be working on incorporating his suggestions/fixing it over the weekend and when I get it resolved I will definitely be posting my code.

It will be helpful if you provide a little more information btw -- what exactly do you mean by lag?  Lag as in the paddles are not synching up on each end or the actual program runs slow etc.

Hopefully you'll get a better answer then above, as I'm completely new with networking O: ), but hopefully some of it helps. 



14
SFML projects / Re: Kroniax - A game of skill
« on: March 08, 2013, 02:43:25 am »
[Unlocked]
1860


I just beat the tutorial and exited, reloaded, and the progress is saved. 

I think my progress didn't save because I had a crash when exiting (clicked the x button... not sure on the details anymore) -- so this is explainable then. 

Maybe update your progress file after every level?

15
SFML projects / Re: Kroniax - A game of skill
« on: March 07, 2013, 07:50:15 am »
Mm I don't think impossible :).  I took a peek at the rest of the level 5 and it looks doable with just the right movements.   Definitely too hard for a level five, but a great challenge and I want to beat it at its current settings ;].

Did version .3 save your progress, because I don't think mine ended up saved -- or is this for a future release.

Thanks,
and again good work :)


Pages: [1] 2 3 4
anything