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 - P@u1

Pages: 1 2 3 [4] 5 6
46
Network / No endianess problems for double/float?
« on: June 12, 2011, 07:39:36 pm »
Thx for your help!
I will definitely give SFML 2.0 a try!

The only thing which does not really convince me so far is the support for asynchronous io.
The biggest problem is that I can't poll if the socket is busy without actually trying to send or receive.
Maybe i will use an additional thread which does synchronous I/O to emulate async I/O.

Edit:
For the additional thread I would need something like a wait condition I think...
Edit2:
I now tried sfml 2.0 and it doesen't help.
Maybe its up to my usage, but I don't know what I'm doing wrong...

47
Network / No endianess problems for double/float?
« on: June 12, 2011, 06:17:38 pm »
I was hoping for an platform independant header :-)

Do I have these functions automaticully when including SFML/Network.hpp?

Maybe you wonder, why I'm asking all this.
The non-blocking mode of sf::SocketUDP with sf::Packet seems not to work very good for me.
After receiving a packet over udp with return value sf::Socket::DONE the packet is not valid after reading out the same amount of values I put in on the server side.
Maybe it's just wrong usage by me...

I thought about giving boost::asio a try, but afaik it's lacking features for binary data, so I think about try to roll my own on top of boost::asio.

48
Network / No endianess problems for double/float?
« on: June 12, 2011, 05:56:27 pm »
Hi,

I recognized, that in SFML 1.6 the sf::packet code for float and double don't do anything about endianess.

Is there no endianess problem for float/double?

I used google and found some articles about how to convert endianess of float/double, so it seems if these datatypes also have endianess, but I'm not sure...

Another question:
With which header do you get access to functions like htonl?

49
Network / Need help with simple UDP game
« on: June 09, 2011, 11:24:24 pm »
Hi,

I'm trying to build a very simple game with UDP just for testing.
Unfortunately at the moment it works worse than it used to work with TCP...
I'm not exactly sure, what the problem is, I thought that you maybe can help me.

Here is the full code:
http://pastebin.com/2ERzSk1n
or
http://codepad.org/qsznZjow

And here are the two most important passages:

Code: [Select]

void Game::sendGameState()
{
sf::Packet toSend;
toSend << myServerPlayer.xPos << myServerPlayer.yPos << myServerPlayer.input
<< myClientPlayer.xPos << myClientPlayer.yPos;
sf::Socket::Status status = mySocket.Send(toSend, myIPAddress, PORT);
switch(status)
{
case sf::Socket::Disconnected:
cout << "Disconnected" << endl;
myIsConnected = false;
break;
case sf::Socket::Error:
cout << "Error sending" << endl;
break;
case sf::Socket::Done:
break;
case sf::Socket::NotReady:
//try again next time;
break;
}
}

void Game::receiveAndSyncGameState()
{
sf::Packet toReceive;
unsigned short port = PORT;
sf::Socket::Status status = mySocket.Receive(toReceive, myIPAddress, port);
switch(status)
{
case sf::Socket::Disconnected:
cout << "Disconnected" << endl;
myIsConnected = false;
break;
case sf::Socket::Error:
cout << "Error receiving game state" << endl;
break;
case sf::Socket::Done:
toReceive >> myServerPlayer.xPos >> myServerPlayer.yPos >> myServerPlayer.input
>> myClientPlayer.xPos >> myClientPlayer.yPos;
//no interpolation yet
break;
case sf::Socket::NotReady:
//try again next time;
break;
}
}


I'm sending gamestate data periodically from the server to the client and the client sends input data periodically to the server.
In the current code it is sent 100 times per second, which is quite huge, but I tried it with 20/s and it didn't work very well too.
At client side the rectangle controlled by the server is always "jumping" between two positions which aren't close to each other.
And after some time there also is quite big delay and some socket errors occur.
I'm not sure if the "jumping" is caused by UDP specific problems, maybe it is caused by lack of mechanism which ensure that data arrives correctly and in the right order?
Or it is just some silly bug i build into my code? :D

But there is also the delay... sending 20 times per second ~10bytes with UDP over LAN should be no problem, should it?

And I'm also not sure, if I'm using the asnyc sockets in the right way...

I can upload the .exe file if you want/need it.

It would be very nice, if you can help me :-)

50
Network / How to use non-blocking TCP?
« on: May 30, 2011, 06:59:01 pm »
Ok, thank you for your help, I will do some experiments now.

But it would be much nicer to be able to poll the status like
Code: [Select]

if(socket.GetStatus() == Socket::Done)
{
   //put in new date
}


The problem is that with you approach I always have to prepare a new packet without knowing if I will be able to sent it.

And does NotReady in this case mean that it will be sent later, or that it wont be sent at all?

And how does non-blocking io work for receiving?
I would try it like this:
Code: [Select]

sf::Packet toReceive;
socket >> receive;
if(!toReceive)
{
    //packet invalid, try again later...
}

Does it work like this?

51
Network / How to use non-blocking TCP?
« on: May 30, 2011, 06:06:18 pm »
how can it be that they are always ready to send and they are still not blocking?

I think I can put in data much faster than it can be sent, so it would be nice to have a way to find out how fast data must be put in so that the sending process still catches up...
Otherwise I will have lots of data and it will be sent with a big delay and some queue (maybe deep in the operating system) will fill up more and more.

Any suggestions?

52
Network / How to use non-blocking TCP?
« on: May 30, 2011, 03:35:13 pm »
Hi,

I'm trying to use an sf::SocketTCP in non-blocking mode.
I want to use it like this:
Code: [Select]

if(/*socket is ready*/)
{
   socket.Send(...);
}
//if not ready continue the next main loop and send the date next time if the socket has become ready


How can I do this?
I need a method like
socket.IsReady(), but there is none.
Send() returns a status, but I want to check the status without actually sending anything.

Please help :-)

53
Graphics / sf::Shape.SetPosition not properly working?
« on: May 24, 2011, 11:12:35 pm »
thx for your fast response.
I fixed it now.

But could you please explain to me, why you did it like this?
Is this also true for sfml 2.0?

Imo this behaviour is quite counter-intuitive and its not mentioned in the docs of SetPosition, maybe you should add a little note for other people :-)

And one more question:
Does sf::Shape::Rectangle internally work by storing all points of the Rectangle?
I got this idea when I read the documentation of sf::Shape, as there are some point-modifying methods.

54
Graphics / sf::Shape.SetPosition not properly working?
« on: May 24, 2011, 10:58:03 pm »
Hallo everyone,

I'm doing the following:
Code: [Select]
while(app.IsOpened)
{
  //event proccessing omitted

  app.Clear();
  sf::Shape shape(sf::Shape::Rectangle(100,100, 150, 150, sf::Color::Green));
  //shape.SetPosition(0,0);
  app.Draw(shape);
  app.Display();
}


When I comment out the SetPosition line it is just a rectangle with coords 100,100,150,150.
But when I uncomment it i expect it to move to
0,0,50,50
But it just doesent move...
Why is that and what do I have to do to set the position to absolute coords?

55
Graphics / How to move a line smoothly?
« on: May 19, 2011, 04:47:46 pm »
Hello everyone,

I want to move a line from left to right and it must look like a smooth movement.
Unfortuantely I didnt get this working so far, the movement seems not to be smooth, especially, when I maximize the screen.
I looks like sometimes the line jumps a bit and sometimes it seems to flicker and so, it just doesen't look good.

Here is the code which I used:
Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   //both with and without verticalsync it doesent look good.
App.UseVerticalSync(true);
sf::Shape line(sf::Shape::Line(0,0,200,200,2,sf::Color::Green));
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();

line.Move(App.GetFrameTime() * 50, 0);
if(line.GetPosition().x > App.GetWidth())
{
line.SetPosition(0, line.GetPosition().y);
}

App.Draw(line);
App.Display();
}

return EXIT_SUCCESS;
}


Would be nice if you have any suggestions to improve this.

Edit: I Just tested it on other pcs and there it just runs fine, so its probably a problem with the graphics driver or my hardware is too old (which I dont think).
I'm using a GForce 6200 Graphics card at this pc, which is indeed not very new, but I think it should be good enough to display some lines :-)

56
Graphics / Need to get pointers to OpenGL functions manually?
« on: May 10, 2011, 07:11:04 pm »
Hi,

I just tried to do some openGL with SFML and recognized some commands and keywords from openGL are not available:

Code: [Select]

glGenBuffers
GL_ARRAY_BUFFER


I am very new to OpenGL and just wanted to try some things from an tutorial. Somewhere else I read that for for openGL functions you somehow have to get pointers to these functions manually.
Is it true that SFML doesen't to that?
I this is true, how can I get acess to these functions?
Or do I maybe just need to add an include to get things working?

Thanks for your help in advance!

57
Graphics / Somtimes Black Line appears when drawing a sprite
« on: May 09, 2011, 07:06:39 pm »
It usually happens when moving but in my game (which is more than the source code i posted here) i also managed to stop moving in the right moment, so that the black line stays visible.
I just tried limiting the framerate, unfortunately it does not help.
Thanks for the suggeston anyway.

If some1 tries out my code with the picture, please make sure to run the program for atleast 30 seconds. Usually the effect appears much earlier, but it is not happening regularly so you might miss it if you dont test long enough.

Edit: I just recognized that the same or atleast a similar issue is mentioned here: http://www.sfml-dev.org/forum/viewtopic.php?t=4744

58
Graphics / Somtimes Black Line appears when drawing a sprite
« on: May 09, 2011, 06:05:42 pm »
Hi everyone,

I have a problem with drawing a simple sprite from an image.
Sometimes a black line at the right end of the image appears (its not regularly).
I created a minimal example to show this.
(I hope that you will see the same effect, a friend of mine already confirmed, that he has the same effects).
I uploaded the image I used here:
http://www.megaupload.com/?d=GPPOH5RP

Here is the source code:

Code: [Select]

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

int main()
{
sf::Image img;
img.LoadFromFile("marioandluigi.png");
img.SetSmooth(false);
sf::Sprite mario(img);
int x = 0;
mario.SetSubRect(sf::IntRect(1+17*x, 232, 1+17*x+16, 232+32));
mario.SetScale(5,5);
int xDir = 1;

sf::RenderWindow app(sf::VideoMode(800, 600, 32), "SFML Window");
while(app.IsOpened())
{
sf::Event event;
while (app.GetEvent(event))
{
if(event.Type == sf::Event::Closed)
{
app.Close();
}
}

app.Clear(sf::Color::Green);
app.Draw(mario);
if(mario.GetPosition().x > app.GetWidth() - mario.GetSize().x)
{
xDir = -1;
}
if(mario.GetPosition().x < 0)
{
xDir = 1;
}
mario.Move(app.GetFrameTime() * 100 * xDir, 0);
app.Display();
}
return 0;
}


Please tell me if you have any clue, why this line appears.

59
Graphics / Problems with Get and Set Position after setting Center
« on: May 03, 2011, 08:13:13 pm »
Quote from: "Nexus"
I don't really see the problem... Just define your own global function instead of using sf::Sprite::GetPosition(). This is not a workaround, this is the usual way to implement advanced functionality on top of an existing class with a basic, given interface.


That's what I did, but it can still easily happen that i accidentily use the normal methods.

60
Graphics / Problems with Get and Set Position after setting Center
« on: May 02, 2011, 10:13:49 pm »
no problem, sfml is very nice anyway :-)
I found an more or less acceptable workaround now.

Pages: 1 2 3 [4] 5 6