blocking function for timing purposes
Some code I am dealing with has a function from the classic mac OS (toolbox I think?), that pauses for a short time..
so things like this are done:
instead of somthing like being in a main loop and updating when a specific time goes past, there too much use of tick's and tick events for me to recode it all in a game loop, so I need to find some replacement.
I want a function that I can call that will block for a set amount of time (actually until a specific date/time) but will not affect background events or cause things to slow down or any problems like that.. would usleep cause problems or be suitable?
Using Cocoa Obj-C, and C together.
Thanks in advance..
Code:
WaitTick(); /* Wait for a system tick to go by */so things like this are done:
Code:
BlastScreen();
StartSong(SongListPtr[0]); /* Play the song */
FadeTo(rMacPlayPal); /* Fade in the picture */
WaitTicksEvent(240); /* Wait for event */
FadeTo(rIdLogoPal);instead of somthing like being in a main loop and updating when a specific time goes past, there too much use of tick's and tick events for me to recode it all in a game loop, so I need to find some replacement.
I want a function that I can call that will block for a set amount of time (actually until a specific date/time) but will not affect background events or cause things to slow down or any problems like that.. would usleep cause problems or be suitable?
Using Cocoa Obj-C, and C together.
Thanks in advance..
Sir, e^iπ + 1 = 0, hence God exists; reply!
I think runUntilDate might be what you want.
This will process events and timers and return once the date you specified has passed. usleep will not process events. If you use timers at some point and mix it with the code above, you'll probably get into trouble, though, and event handling routines can and will be called while the calling function blocks at the line above.
Code:
[[NSRunLoop currentRunLoop] runUntilDate:<some date>];This will process events and timers and return once the date you specified has passed. usleep will not process events. If you use timers at some point and mix it with the code above, you'll probably get into trouble, though, and event handling routines can and will be called while the calling function blocks at the line above.
Would nanosleep() fit your bill? You have to calculate the delay, but it would do what you want.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
nanosleep() or sleep() is what I would use myself.
ok Im sure nanosleep is what I require, thanks guys.
I figure I'll have to make a c function in my NSOpenGLView subclass that will call [[self openGLContext] flushBuffer], so that my other code © can call it, or is there a better way?
also would it be best to call the sleep function with the same argument every time (the one meaning 1/60th of a sec), or should I be sleeping for a variable amount depending on how long it is until the next tick would end.. counting from the start of the game?
I figure I'll have to make a c function in my NSOpenGLView subclass that will call [[self openGLContext] flushBuffer], so that my other code © can call it, or is there a better way?
also would it be best to call the sleep function with the same argument every time (the one meaning 1/60th of a sec), or should I be sleeping for a variable amount depending on how long it is until the next tick would end.. counting from the start of the game?
Sir, e^iπ + 1 = 0, hence God exists; reply!
Sleeping for a variable amount of time should be more accurate to get the time you want.
Yeah, sleep for the remaining time. Otherwise the speed won't be uniform.
Also, on OSX I don't think you can sleep for less than 10ms or so, and make sure you don't sleep until everything in that tick is done. If you have VBL sync on and try to sleep before swapping buffers, the frame rate get stuttery as the two wait times fight.
Also, on OSX I don't think you can sleep for less than 10ms or so, and make sure you don't sleep until everything in that tick is done. If you have VBL sync on and try to sleep before swapping buffers, the frame rate get stuttery as the two wait times fight.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Key blocking | Miglu | 40 | 13,799 |
Sep 13, 2010 12:39 PM Last Post: sealfin |
|
| Non-blocking VBL sync? | TomorrowPlusX | 4 | 3,648 |
Feb 28, 2005 02:06 PM Last Post: arekkusu |
|
| Drawing fps/Event timing using Carbon | Nickolei | 11 | 5,699 |
Jul 8, 2002 01:02 AM Last Post: Jens |
|
| Game Timing (Cocoa) | Fletch | 7 | 3,961 |
Jun 26, 2002 08:44 AM Last Post: Fletch |
|

