|
|
| yield_timeslice(), rest(), Sleep() - what to use? |
|
Daniel Schlyder
Member #257
April 2000
|
For some reason I can't get this through to the Allegro mailing list, so I'm posting it here... I'm reading these mails about yield_timeslice() and my head is spinning... Could somebody please explain what I can/should put in the else {} below (if anything?). (It's a loop for a crude menu in a windowed game.) I guess what I have been using doesn't make sense? Thanks in advance.
|
|
Goodbytes
Member #448
June 2000
|
If you want your loop to respond quickly to input, then definitely don't use rest() - those types of delays have a resolution of about 55 milliseconds, so even if you think you're only pausing for one millisecond, you're actually doing it for about one 18th of a second. Also, the delay might cause a buildup in the key buffer. yield_timeslice() is a better choice if you want to play nice with the OS, but I don't think it's necessary - you won't be using a lot of CPU time anyway. At least, I don't think so. I'm not 100% sure on what I said about yield_timeslice(). Hope this helps a bit. |
|
Blade Nick
Member #1,597
October 2001
|
First off ain't Sleep fir qbasic and why on earth do you wan't to try to slow down the game when pressing a key as this would make an upeven speed truought asdfkj asd F)ÿÄ3§Ä 62 87&%&^$$ fd87 UI87....... Heh something happend anyhough this would give and uneven speed which would be anoying to people unless your idea is to use this stange abomination to somehow takeover the world then go for it but otherwize you are just going so kill ureselfe or someon else wiht a starnge code.. 123468 4518+bAAJ1#ç54354
Bad Website Of Mine |
|
Daniel Schlyder
Member #257
April 2000
|
I didn't know rest() took that long, but it does seem to respond quickly enough for my needs. As I said, this is not for in-game input, but for a crude menu that goes something like F1... play, F2.. configure, ESC.. exit. I put in the rest() cause when running the game in Windows XP the System Task Manager claims my program/process uses 100% CPU time when using yield_timeslice() or nothing. I guess it's this 100% value that confuses me. I can play mp3s in the background without problems, so it can't really be 100%. Blade Nick: Sleep() is part of win32 API. yield_timeslice() == Sleep(0) in Windows. |
|
gnolam
Member #2,030
March 2002
|
Ok, let me get this straight: yield_timeslice() == Sleep(0) So what the hell does it do then? Resting 0 ms doesn't make any sense to me (and I don't understand what the docs say about it either - all it says is that it "gives up the rest of the current scheduler timeslice"). Anyone care to enlighten me? -- |
|
Daniel Schlyder
Member #257
April 2000
|
Hehe, I see I'm not the only one who's a bit confused. Goodbytes: I re-read your post. I don't fully get timeslices and processes CPU usage, but I think calling yield_timeslice() on all platforms is probably what I should do in my game's menu. Thanks for your help! |
|
|