Winsock FPS Problem
Hi , Im making a simple game with network, my program is sending 4 variables at the moment , by putting them into the const chars
char xbuffer [5]; // buffer for x of man
char ybuffer [5]; // buffer for y of man
char facing [5]; // buffer for direction of facing
char rotation[5]; // rotation of man
then sending them to the other person using send(). and ofcourse the other person receiving them using recv , then reconverting them to the right variables etcetc.
,
My problem is when my client connects, my computers fps for the game drops to as low as the other computers fps running my clients (which has alot less powerful graphics card) .
emmm how do I stop this from happening ,
Thank you in advance,
Mark
> My problem is when my client connects, my computers fps for the
> game drops to as low as the other computers fps running my clients
> (which has alot less powerful graphics card).
Use a fixed interval for the updates, like 10 or 30 times per second.
This way the updates will have a fixed framerate, and the rendering
framerate will be independent from the simulation framerate. If a
computer is faster then it will have a higher rendering framerate.
If slower, it will drop frames and render less frames, but supply
the simulation data with the fixed rate.
Viktor
> game drops to as low as the other computers fps running my clients
> (which has alot less powerful graphics card).
Use a fixed interval for the updates, like 10 or 30 times per second.
This way the updates will have a fixed framerate, and the rendering
framerate will be independent from the simulation framerate. If a
computer is faster then it will have a higher rendering framerate.
If slower, it will drop frames and render less frames, but supply
the simulation data with the fixed rate.
Viktor
ahh but it seems my recv function waits until it gets a value , before anything happens : / , I think
Quote:Original post by Paladin2005
ahh but it seems my recv function waits until it gets a value , before anything happens : / , I think
put recv in a separate thread.
Do NOT start using threads unless you know you can synchronise the data, or at the least are familiar with how they work.
I would advise the use of a nonblocking socket, and only recv if the socket has pending data - use select() to find this out.
You don't really need to use the windows specific asynchronous sockets (in fact your code will be more portable if you don't) as these generate windows messages on pending data, and effectively wrap select() functionality.
I would advise the use of a nonblocking socket, and only recv if the socket has pending data - use select() to find this out.
You don't really need to use the windows specific asynchronous sockets (in fact your code will be more portable if you don't) as these generate windows messages on pending data, and effectively wrap select() functionality.
Quote:
Do NOT start using threads unless you know you can synchronise the data, or at the least are familiar with how they work.
I would advise the use of a nonblocking socket, and only recv if the socket has pending data - use select() to find this out.
You don't really need to use the windows specific asynchronous sockets (in fact your code will be more portable if you don't) as these generate windows messages on pending data, and effectively wrap select() functionality.
im having a similar problem where my recv() waits
how exactly do i use the select function to check if my socket has data
Using select with UDP (complete (simple) send/receive echo server example)
Using select with TCP
Two methods:
1. Leave the socket set to blocking. Use select() then read the socket when data is available.
2. Set the sock to non-blocking at startup. Read the socket and call WSAGetLastError() and check for (WSA)EWOULDBLOCK (no data is available).
For UDP sockets, I benchmarked using (1) against (2) and found the (2) was faster (though either method is fine for a game application: the difference in overhead for both methods is minimal WRT total game overhead).
Using select with TCP
Two methods:
1. Leave the socket set to blocking. Use select() then read the socket when data is available.
2. Set the sock to non-blocking at startup. Read the socket and call WSAGetLastError() and check for (WSA)EWOULDBLOCK (no data is available).
For UDP sockets, I benchmarked using (1) against (2) and found the (2) was faster (though either method is fine for a game application: the difference in overhead for both methods is minimal WRT total game overhead).
use select(...){recv(...);}
its the simple way of doing it and wont take too much changing to your code
really just put if select block around your recvs
so if there is nothing recieved you wont block trying to recieve something that hasnt arrived yet
btw, multithreading may sound scarry, but for the most parts i have no problems with multithreading, but you wont gain any advantage by using it unless your running on a multi cpu or core pc
your fps would still be the same almost
its the simple way of doing it and wont take too much changing to your code
really just put if select block around your recvs
so if there is nothing recieved you wont block trying to recieve something that hasnt arrived yet
btw, multithreading may sound scarry, but for the most parts i have no problems with multithreading, but you wont gain any advantage by using it unless your running on a multi cpu or core pc
your fps would still be the same almost
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement