gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Wait or Sleep?

#5855 - theSparko - Sat May 10, 2003 9:44 pm

Hey,

This should be a pretty easy question to answer, but I didn't see anything else about this on the forum. How do I make my game sleep for say, 500ms? I'd like to just write a sleep function that takes an int and sleeps for that many miliseconds.

Thanks,
theSparko

#5856 - tepples - Sat May 10, 2003 11:21 pm

theSparko wrote:
How do I make my game sleep for say, 500ms? I'd like to just write a sleep function that takes an int and sleeps for that many miliseconds.

In general, what I'd do to wait for 500ms is wait for 30 vblanks.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#5858 - sgeos - Sat May 10, 2003 11:27 pm

tepples wrote:
In general, what I'd do to wait for 500ms is wait for 30 vblanks.


So far I've assumed that 60 vblanks is about a second. Is this correct?

-Brendan

#5860 - tepples - Sun May 11, 2003 12:56 am

sgeos wrote:
So far I've assumed that 60 vblanks is about a second. Is this correct?

That's close enough for government work. 16777216 cycles in a second, 280896 cycles between vblanks. Thus, 59.7275 frames per second. The difference (under 0.3 fps) becomes significant mostly in sound coding and multiplayer coding. Each machine in a multiplayer setup will have a slightly different clock rate, but each machine will probably run within +/- 1 fps of each other.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#5863 - sgeos - Sun May 11, 2003 3:14 am

tepples wrote:

Each machine in a multiplayer setup will have a slightly different clock rate, but each machine will probably run within +/- 1 fps of each other.


Is this ever a problem? Is there a way to re-synchronize them?

-Brendan

#5867 - tepples - Sun May 11, 2003 7:58 am

sgeos wrote:
tepples wrote:
Each machine in a multiplayer setup will have a slightly different clock rate

Is this ever a problem?

It makes multiplayer code more difficult to write, but it can always be worked around.

Quote:
Is there a way to re-synchronize them?

Use the same synchronization techniques that any other networked game uses.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#5884 - Krakken - Mon May 12, 2003 9:12 am

You could use this:
http://www.sapian.co.uk/files/GBATimers.doc

:)

#5891 - ampz - Mon May 12, 2003 12:14 pm

tepples wrote:
The difference (under 0.3 fps) becomes significant mostly in sound coding and multiplayer coding.


No, the fact that the frame rate is not exactly 60.00fps does not matter at all in multiplayer coding.
The fact the the crystals run at slightly different frequencies might matter, but that's a totally different thing.