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 - Mr. Moon

Pages: [1]
1
Network / What causes an sf::Socket::Error?
« on: October 20, 2010, 08:39:25 am »
Quote from: "Mindiell"
and be carfeul not to send too much packets too ;)


I haven't done any network programming for a game before; how do I know if I'm sending out too many packets?  If I'm sending out small packets constantly at 30 FPS, is that too much?  60 FPS?

And Laurent, I appreciate the concern.  If the problem persists I'll try to write a minimal example that reproduces the problem.

2
Network / What causes an sf::Socket::Error?
« on: October 18, 2010, 09:30:07 am »
Quote from: "Laurent"
In your code, it's not the status which is an error, it's "inPacket >> x >> y" that fails. So what's true? Your code or your explanation? ;)

UDP is not a reliable protocol: sometimes, data may arrive corrupted. This might explain that you sometimes get an error.


 The "if (!(inPacket >> x >> y))" code doesn't actually do any error handling; the code just ignores the bad packet.  The errors I'm referring to are because rcvStatus is sometimes set to sf::Socket::Error after I call Receive().  I know this because I'm printing rcvStatus as an sf::String later in my code.  So what I'm wondering is, what does it mean if Receive() returns with an error?  Does that just mean the packet was corrupt?  And why is my performance getting worse the longer I test my game at high framerates?

3
Network / What causes an sf::Socket::Error?
« on: October 18, 2010, 06:15:41 am »
So I have some code for a 2-player game that looks like this for both the host and client player, using a non-blocking SocketUDP:

Code: [Select]

sf::Socket::Status sendStatus;
sf::Socket::Status rcvStatus;
if (socket.IsValid())
{
        // SEND position data to the other player

        sf::Packet outPacket;
        outPacket << myPlayer.getX() << myPlayer.getY();
        sf::IPAddress tip = theirIP;
        sendStatus = socket.Send(outPacket, tip, PORT);

        // RECEIVE position data from the other player

        float x = theirPlayer.getX();
        float y = theirPlayer.getY();
        sf::Packet inPacket;
        unsigned short port = PORT;
        tip = theirIP;
        rcvStatus = socket.Receive(inPacket, tip, port);

        if (rcvStatus == sf::Socket::Done)
        {
                if (!(inPacket >> x >> y))
                {
                        // Error...
                }
                else
                {
                        theirPlayer.SetPosition(x, y);
                }
        }
}
else
{
        // Error.  Quit game.
}


Both players are just sending their positions to one another.

Initially I had the framerate capped at 120 FPS, and this code ran every game loop (inefficient, I know).  It would work fine for awhile, but rcvStatus would occasionally be sf::Socket::Error rather than sf::Socket::Done, which is what it usually sits at.  The problem seemed to get worse the longer the session was.  The problem persisted at 60 FPS.

At a forced limit of 10 FPS I didn't notice any of these errors.

So my hypothesis is that I was just sending out too many packets.  Could that cause an sf::Socket::Error condition?  Is there any way to find out what triggered an sf::Socket::Error?

I'm using SFML 1.6 and Visual Studio 2010 if that matters.

4
Network / P2P game with VOIP/Teamspeak?
« on: October 18, 2010, 01:41:49 am »
Okay, thanks for the words of wisdom, fellas!  Unfortunately I'm too behind schedule to include the voice chat in this version of my game, but I will definitely take that into account :) .

5
Network / P2P game with VOIP/Teamspeak?
« on: October 15, 2010, 01:44:55 am »
Quote from: "Laurent"
Quote
I've heard that a separate TCP connection will interfere with the UDP one

What do you mean? Separate connections are... separate ;)


I'm going off this article:

Quote
The problem is that since TCP and UDP are both built on top of IP, the underlying packets sent by each protocol will affect each other. Exactly how they affect each other is quite complicated and relates to how TCP performs reliability and flow control, but fundamentally you should remember that TCP tends to induce packet loss in UDP packets. ...Don’t mix TCP and UDP, instead learn how to implement the specific pieces of TCP that you wish to use inside your own custom UDP based protocol.

(http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/)

Assuming he means separate UDP/TCP connections (is there any other option?), I wasn't aware of such a thing.  I just didn't want to rush in and make that kind of mistake.

6
Network / P2P game with VOIP/Teamspeak?
« on: October 14, 2010, 05:03:14 am »
I'm currently working on a 2-player peer-to-peer action game where one player is designated as the host and the other as the client player.  I'm using UDP to transmit the client's movement data to the server player.

I'd like to have some form of built-in voice communication in the game.  Do I need to set up a separate connection to send the audio streams, or should I use the same one that's used for sending movement data?  I've heard that a separate TCP connection will interfere with the UDP one; is this true for separate UDP connections as well?

7
Network / Non-blocking SocketUDP behavior?
« on: September 13, 2010, 10:25:34 pm »
I'm currently making a P2P two-person co-op game.  This is my first experience with network programming.

I started with a simple example where two remote clients each move a square around onscreen, and are updated on the other's movements.

My question pertains to this code in my game loop:

Code: [Select]
       
// GAME LOOP
{
...
        // Has the player moved?
        bool moved = false;

        // Handle controls

        // Time since last frame
        float deltaTime = window.GetFrameTime();

        if (window.GetInput().IsKeyDown(sf::Key::Left))
        {
                mySquare.Move(-MOVE_SPEED * deltaTime, 0.f);
                moved = true;
        }
        else if (window.GetInput().IsKeyDown(sf::Key::Right))
        {
                mySquare.Move(MOVE_SPEED * deltaTime, 0.f);
                moved = true;
        }
        if (window.GetInput().IsKeyDown(sf::Key::Up))
        {
                mySquare.Move(0.f, -MOVE_SPEED * deltaTime);
                moved = true;
        }
        else if (window.GetInput().IsKeyDown(sf::Key::Down))
        {
                mySquare.Move(0.f, MOVE_SPEED * deltaTime);
                moved = true;
        }

        // SEND INFORMATION

        sf::Packet outPacket;

        outPacket << mySquare.GetPosition().x << mySquare.GetPosition().y;

        // Only send packets to the other player if I've updated my square's position.
        // NOTE: if I set this to "if (true)", the program works fine.
        if (moved)
        {
                std::stringstream ss;
                ss << "Moved";
                writeError(ss);

                if (socket.Send(outPacket, theirIP, port) != sf::Socket::Done)
                {
                        std::stringstream ss;
                        ss << "Couldn't send packet";
                        writeError(ss);
                }
        }

        // GET INFORMATION

        sf::Packet inPacket;

        if (socket.Receive(inPacket, theirIP, port) != sf::Socket::Done)
        {
                std::stringstream ss;
                ss << "Couldn't send packet";
                writeError(ss);
        }
        else
        {
                // Received a packet
                std::stringstream ss;
                ss << "Received a packet";
                writeError(ss);
        }

        float theirX = theirSquare.GetPosition().x;
        float theirY = theirSquare.GetPosition().y;

        if (!(inPacket >> theirX >> theirY))
        {
                std::stringstream ss;
                ss << "Invalid packet read";
                writeError(ss);
        }
        else
        {
                // Update the remote player's position
                theirSquare.SetPosition(theirX, theirY);
        }
...
}


If I set moved to always be "true" (i.e., I'm sending a packet at each iteration of the game loop regardless of whether or not there's a need to) the program works fine.  Otherwise, the other player's square never moves at all.  I know I'm sending packets, but it's as if the other client is never receiving them.

The single UDP socket I'm using is non-blocking.  My thought is the problem is caused because I'm calling Receive() more often than Send().  How does Receive() behave in this scenario?  And if I do have to match each Receive() call to a Send() call, how can I determine how often the other client is calling Send()?  Would it be better to use a blocking socket in a separate thread instead?

8
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 16, 2010, 12:18:32 am »
Fixed!

The problem turned out to be my Windows display drivers.  Once I updated those, performance skyrocketed again.

I profiled the program with Very Sleepy again and the wglChoosePixelFormat routine didn't even show up.

Thanks for the help everyone.

9
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 15, 2010, 01:39:39 am »
Quote from: "Svenstaro"
I'm almost certain that the problem is related to your crappy Intel graphics drivers for Windows. This is why I made you test it on Linux.


So you think it's the Windows-specific drivers and not the card itself?

In that case I may just have to go back to SDL.  I'd rather foresake hardware acceleration for a game that I don't have to worry about these kinds of issues with.  I guess I just didn't realize what I was in for.

10
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 15, 2010, 12:20:54 am »
Okay, my performance is back to normal again on my 32-bit Ubuntu partition.  Frame rates in excess of 500 fps.  I couldn't use the version of SFML from the site (bad archive?), so I used the version in the repos, which seems to be 1.5.

My game is intended for Windows users as well, though, so I still need to figure out what's going wrong there.  Should I try an earlier version of SFML, perhaps?

11
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 14, 2010, 11:16:51 pm »
Admittedly my graphics card isn't great, but I can still run some decent-looking 3D games.  I can't imagine displaying a single 800x600 texture would be the sole cause of such a huge performance hit.

Quote from: "Laurent"
Do you make your performances tests in release mode (not debug)?


Usually debug mode, but I'm now in release and getting the same results.

Quote from: "Spodi"
I have very little OpenGL experience, but looking at where it is called in SFML's code (latest version of 2.0), I don't think wglchoosepixelformat should be getting called that often. Then again, that is assuming I am reading this Very Sleepy output correctly.


I should mention I'm using SFML 1.6.  Maybe this has to do with the fact that I'm using a 64-bit OS?  Someone mentioned similar problems here http://www.qtcentre.org/threads/24192-OpenGL-frame-rate and concluded that it had something to do with incorrect OGL DLLs.

12
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 14, 2010, 05:17:58 am »
Quote from: "Svenstaro"
I mean run your system profiler or debugger or whatever you use with to record which system call takes how much % of your total runtime. On Linux you'd use sysprof or gprof. This way we can check which part actually makes it slow.


That doesn't seem to be a feature in MSVC++ Express (which I'm not very experienced with, so perhaps I'm wrong?), so I used Very Sleepy (http://www.codersnotes.com/sleepy/sleepy). My application was taking up about 50% of my CPU cycles, and wglChoosePixelFormat was taking up almost 100% of the calls, so I analyzed that.  This http://i.imgur.com/ombmg.png was my output.

So...it seems like that OpenGL function could be the culprit?

13
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 14, 2010, 02:34:02 am »
Quote from: "Svenstaro"
What's your hardware? Can you give us a profile of 10 seconds of runtime?

Also try to limit FPS to 60 in any case and report results.


Dell Studio 17
CPU: Pentium Dual-Core 2.10 GHz
RAM: 2 GB
Video card: Intel Graphics Media Accelerator 4500MHD

I'm compiling with the static libraries in MSVC++ 2010 on Windows 7.

I'm not sure what you mean by profile, but in any case here's the framerate output in that time:

Code: [Select]

2.43682
5.99203
7.39104
8.39077
8.39245
8.41012
8.29009
8.20897
8.37966
8.34473
8.43425
8.31317
7.90502
8.23046
8.3182
8.40324
8.37757
8.34313
8.36165
8.36281
8.27326
8.28989
8.20495
8.37726
8.37037
8.40134
8.19397
8.30234
8.26932
8.31256
8.37822
8.39721
8.42528
8.40183
8.37096
8.23911
8.3507
8.38214
8.38018
8.35356
8.26955
8.36261
8.34848
8.21543
8.27591
8.24792
8.2015
8.25531
8.41257
8.3787
8.44075
8.40638
8.40963
8.05344
8.2814
8.28694
8.32992
8.39738
8.38547
8.40438
8.41915
8.37455
8.37936
8.22401
8.33583
8.43664
8.33304
8.13746
8.41839
8.35455
8.33725
8.29766
8.32928
8.40221
8.41683
8.43313
8.39369
8.33382
8.3833
8.39149
2.41406

14
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 14, 2010, 01:16:26 am »
Good idea.  Here's a minimal example:

Code: [Select]

#include "game.h"

#include <fstream>
#include <sstream>

int main()
{  
        std::ofstream fpsLog("fps.txt");

        if (fpsLog.fail())
        {
                return EXIT_FAILURE;
        }

        sf::RenderWindow window(sf::VideoMode(800, 600, 32), "test", sf::Style::Fullscreen);

        sf::Image bgIm;
        bgIm.LoadFromFile("background1test.png");

        sf::Sprite bg;
        bg.SetImage(bgIm);

        while (window.IsOpened())
        {
                // Process events
                sf::Event windowEvent;
                while (window.GetEvent(windowEvent))
                {
                        // Close window : exit
                        if (windowEvent.Type == sf::Event::Closed)
                        {
                                window.Close();
                        }

                        // A key has been pressed
                        if (windowEvent.Type == sf::Event::KeyPressed)
                        {
                                // Escape key : exit
                                if (windowEvent.Key.Code == sf::Key::Escape)
                                {
                                        window.Close();
                                }
                        }
                }

                window.Draw(bg);

                window.Display();

                // Record FPS
                std::stringstream ss;
                ss << 1.f / window.GetFrameTime() << std::endl;
                fpsLog << ss.str();
        }

        return EXIT_SUCCESS;
}


Still having the same problem.  I can't get more than 10 FPS.

File type seems to be a non-issue.  I tried saving my background as PNG, TGA, JPG, and BMP, and nothing seemed to change.

The smaller I make the background file, the higher my framerate gets.  It's as if SFML just doesn't like how big the texture is.

Any ideas...?  I would really hate to go back to SDL at this point :[ .

15
Graphics / [SOLVED] Huge performance hit when I draw a big background.
« on: August 13, 2010, 01:09:36 am »
Hi everyone!  I'm very new to SFML, pardon if I'm making a glaring error here...

Normally my game runs at about 150 fps, but as soon as I load an 800x600 PNG background, assign it to a background Sprite, and Draw() it in my game loop, the game plummets to <10 fps.

My code looks something like this:

Code: [Select]
void Game::gameMain()
{
        // Game loop
        while (!quitLevel && window.IsOpened())
        {
                // Process events
                // ...event handling...

                // This changes depending on what the current level is.  Right now it's set to level1().
                (this->*updateAndDisplay)();

                window.Display();
        }
}

void Game::level1()
{      
        // SPRITES

        static sf::Image background1Im;

        // Sprite is a derived class of sf::Sprite with a few wrapper functions included.
        static Sprite background1;

        // INITIALIZED WORLD

        if (!initializedLevel)
        {
                // Load images

                background1Im.LoadFromFile("background1.png");

                background1.SetImage(background1Im);
               
                // ...

                initializedLevel = true;
        }

       // ...

       // DRAW WORLD

//        fillScreen(50, 50, 50);
        window.Draw(background1);
}


I'm compiling in Visual Studio Express 2010 with the static libraries.  I'm running it on a pretty low-performance laptop, but I can still play 3D games, so I can't imagine that's the cause of the performance hit.

What I'm actually trying to do is cut up a 8000x600 background into 800x600 pieces (the game is a sidescroller) since SFML doesn't seem to be able to load textures that large.

Pages: [1]
anything