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

Pages: [1]
1
Network / Non-blocking SocketUDP behavior?
« on: November 24, 2014, 02:11:46 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]

Quote
// 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?

2
Network / alternative to whatismyip.org
« on: November 24, 2014, 02:07:09 pm »
Hi,

to retrieve the public ip address, the website www.whatismyip.org is queried. Unfortunately, sometimes (seldomly, but it happens) this site is down, so it may be useful to check another site, too?
There is http://checkip.dyndns.org which sends back a strings like
Code:

Quote
<html><head><title>Current IP Check</title></head><body>Current IP Address: 84.58.110.116</body></html>

which is a little more work to parse than the other one but I think it's worth.

3
Audio / probem in load sounds
« on: November 24, 2014, 01:59:07 pm »

i am thinking that my game have a problem with the sounds, if a run the game at first time it run ok, but when i close and run again when the game load the sounds it crash, the computer not only the game but for play the game again i need to restart the computer

*it have a lot of sounds buffer

edit:

i discovered that the problem is in the musics, i have one to the menu and another to the game, but in computers with low hardware this system crash

4
Graphics / SFML 2.0 - Repeated Animations
« on: November 24, 2014, 01:53:48 pm »
Hi. I am trying to do a laser fire animation as seen in the space invaders game. I have some ideas but I really have no idea how to implement them. The idea I think I have is to have the visibility is the sprite set to off, or have it behind the tank so it looks like it isn't there, then for the sprite to follow the tank around (Left and Right). Once the space button is fired the visibility of the laser is shown, and then it shoots up towards the top of the screen. This is my second day for SFML and the only way I have tried to do the laser shoot is to use the .move but this isn't working as it only moves once and not continuously.  This is what I have at the moment:

int spriteWalkSpeed = 10;
int DownspriteWalkSpeed = 5;
int up=-spriteWalkSpeed, down=DownspriteWalkSpeed, left=-spriteWalkSpeed, right=spriteWalkSpeed;

        tankSprite.setPosition(400,550);
        laserSprite.setPosition(400,550);

while (App.isOpen())
        {
                // Process events
                sf::Event Event;
                while (App.pollEvent(Event))
                {
                        if (Event.type == sf::Event::KeyPressed)
                        {
                                if (Event.key.code == sf::Keyboard::Left)
                                {
                                        tankSprite.move(left,0);
                                }
                                if (Event.key.code == sf::Keyboard::Right)
                                {
                                        tankSprite.move(right,0);
                                }
                                if (Event.key.code == sf::Keyboard::Space)
                                {
                                        laserSprite.move(up, up);
                                        laser.play();
                                }

                        }
           }

5
Graphics / PushGLstates not working correctly
« on: November 24, 2014, 01:45:41 pm »
void Engine::run()
{
    while (App.isOpen())
    {
        while (c_FPSClock.getElapsedTime().asSeconds() < 1.f/60)
        {
        }


       

        // Set the active window before using OpenGL commands
        // It's useless here because active window is always the same,
        // but don't forget it if you use multiple windows or controls
        App.setActive();
       
       

        App.pushGLStates();
        App.draw(text);
        App.popGLStates();

        // Clear color and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

       

        getInput();
        update();
        render();

        App.display();
    }
}

But this is making my game mess up pretty bad:

    The input isn't working like before at all
    The player is rendering below the map


all i want to do is draw some text to display health and a rectangle at the bottom of the screen! haha.

I am also getting these errors in the console

Quote
Quote
An internal OpenGL call failed in RenderTarget.cpp <255> : GL_INVALID_OPPERATION,the specified opertaion is not allowed in the current state.

The game is built with C++ OpenGL and SFML to render the window and gui

Any help will be appreciated thanks

6
Window / Is this related to the ATI Bug? Crash on exit for Intel
« on: November 23, 2014, 12:11:01 pm »
I have a tester that has an odd problem that sounds quite reminiscent of the ATI bug. None of these bugs will happen to literally anyone else. This is on SFML 2.0. It is statically linked, and the problems do not show up on ATI cards, but it still sounds like the same thing.

This tester is using an Intel 4-series integrated GPU.
- Upon leaving the main, the program will crash. Same error as the ATI bug's.
- Going into fullscreen will also crash.

- The problem might be compounded by the fact that he's using a dual monitor setup on an old GPU/driver
- There are misc rendering issues on one of his screens, (I have a certain sf::Text object that will be rendered only on every other frame for example. This bug does not exist for anyone else)
- If he has the game on the other screen, it will render properly, but display at half the FPS. Turning off VSync will not fix this, either.
- The above 3 might be unavoidable, since I know that SFML does not support multiple screens.

These types of problems seem difficult to work with since it's only one person with a very specific setup that's getting them. I thought I might as well ask anyways.

7
Window / Breaking vertical sync
« on: November 23, 2014, 12:05:20 pm »
I just noticed that when using Windows 7 basic theme and running a Fullscreen window, alt-tabbing turns off vsync.

Thought I'd drop it in here in case it turns out to be bug for the tracker.

8
General / odd error when compiling sfml
« on: November 23, 2014, 12:01:49 pm »
history:
It was not 3 hours ago i was going through a tutorial on sfml and compiling it fine, then got an error saying directory was not there. Throughout the process, i had trouble with g++, so i purged g++ from my ubuntu and reinstalled.

I also reinstalled some pre-reqs, but i still get the same error:


Quote
sudo apt-get install libpthread-stubs0-dev libgl1-mesa-dev  libx11-dev libxrandr-dev libfreetype6-dev libglew1.5-dev libjpeg8-dev libsndfile1-dev libopenal-dev cmake


after reinstalling i now get this error:

Quote
libGL error: failed to load driver: swrast
libGL error: Try again with LIBGL_DEBUG=verbose for more details.

after putting in that argument i get this error:

Quote
g++: error: LIBGL_DEBUG=verbose: No such file or directory

I am not really sure where to go after this. I have spent the better part of tonight messing with the error i had with g++, and now that i have that working well, i seem to be stuck yet again at sfml. I am not really sure what intially sparked the problem in the first place as i was just compiling sfml between tutorials at the time, not installing, not hcanging config files, or not updating or anything. So its odd that it just seemed to happen out of thin air.


g++  -std=c++11  -Wall -o "%e" "%f" -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system &&"./%e"
sfml 2.1 on ubuntu 13.04
gcc version 4.7.3

9
General / SFML Game Book (github code) Run-time error & LNK2019 error.
« on: November 23, 2014, 11:53:29 am »
So I got the github code from Laurent, ran it through CMake for VS12 and everything seems to have worked out, I went to chapter 2 (where I'm at on the book right now) and fitted in the additional SFML compiler includes and linker libraries + resources.

Now I had to place the debug dlls here:



And running the thing in release slapped me in the face with a ton of LNK2019 errors which I'm not even gonna bother with right this moment.

In debug, the execution dies out right were the breakpoint is set:



I'm assuming this is a directory issue, however I have no clue where I should be putting the stuff.  I used CMake to generate everything in the same folder (source and target are the same) but it clearly didn't pick them up...

Any clue about this, and whether or not the CMake caused an error or if this is something normal that should be taken care of prior to compilation?

Cheers

10
General / Large Procedurally Generated Tile Map From Chunks
« on: November 23, 2014, 11:47:52 am »
I'm building a 2D open-world survival game, and I want to setup a rather large procedurally generated tile map. I've already got a single Chunk setup using the official tutorial about creating your own entities with VertexArrays. I'm looking for some general advice on how to expand this into a large map where individual tiles can be updated and changed so the player can build structures on the map. When I tried to push the size of a chunk much past 32x32 with 32-pixel-wide tiles I was getting a segmentation fault.

Pages: [1]