I have a server and a client for my OpenGL game, and I want to be able to get a packet containing floats from the server for my gluLookAt function on the client side.
The problem is, after sending and receiving around 10 valid packets with correct information (the amount varies), the client will freeze. The function to retrieve the information from the server is run every frame - BUT, it doesn't matter how many frames per second the program gets.
I'm working with UDP, by the way.
The information retrieving function on the client:
void updateCamera() {
sendToServer(sf::Uint16(4));
sf::Packet output = getServerResponse();
sf::Uint16 camtype;
output >> camtype;
float camx;
float camupangle;
float camz;
float camlx;
float camheight;
float camlz;
output >> camx >> camupangle >> camz
>> camlx >> camheight >> camlz;
if (camtype != 4) {
return;
}
gluLookAt( camx, camupangle, camz,
camx+camlx, camheight, camz+camlz,
0.0f, 1.0f, 0.0f);
std::cout<<"Set position\n";
}
On the server to send it to the client:
else if (type == 4) {
getPlayer(sender.toString()).init();
sf::Packet tosend;
sf::Uint16 newtype = 4;
tosend << newtype;
float camx = getPlayer(sender.toString()).x;
float camupangle = getPlayer(sender.toString()).upAngle;
float camz = getPlayer(sender.toString()).z;
float camlx = getPlayer(sender.toString()).lx;
float camheight = getPlayer(sender.toString()).height;
float camlz = getPlayer(sender.toString()).lz;
tosend << camx << camupangle <<
camz << camlx << camheight <<
camlz;
serverSocket.send(tosend,sender,senderPort);
std::cout<<"Got camera request.\n";
}
Remember, this is valid code and I WILL get around 10 CORRECT packets.
Thanks!

New Topic/Question
Reply



MultiQuote






|