Sub-frame timing?
Hi, all. I''m trying to write a music-based game, and as such, timing needs to be pretty accurate. Ideally, I want to call a function every 100ms, but I don''t want to be late or early about it (this may or may not end up driving the sound engine). Right now, I''ve got the windows message loop, GL loop, and timer loop running as 3 separate threads, and the GL loop and timer loop are constantly fighting over the CPU, so that''s bad. If I replace the busy-waiting in my timer loop with Sleep() statements, the thread always ends up sleeping a little too long (and if I shorten it, it''s back to busy-waiting), so that''s bad.
1)What''s the best way to get this to work? or...
2)Since I can throw a lot of the logic into the GL loop and into the input event handlers, my only real *need* for this is sound. Is there a better way?
Thanks,
Devin
November 21, 2002 09:28 AM
i''ve tried both waitforsingleobject and sleep, and funnily enough, i found sleep to be the more accurate, at least in my case.
what''s your target platform? have you looked at waitable timers? they''re NT/2K/XP only but pretty accurate.
also, are you adverse to using direct music? there are beat notifications that can be used with it driving the music. DX8.1 sample DMBoids uses it to sync the boids movements to the music.
what''s your target platform? have you looked at waitable timers? they''re NT/2K/XP only but pretty accurate.
also, are you adverse to using direct music? there are beat notifications that can be used with it driving the music. DX8.1 sample DMBoids uses it to sync the boids movements to the music.
Well, I was originally looking at something that might be portable, but I''m probably going to use BASS for music, so Win32 . It has beat notification as well, so I''ll look into that.
Is there a way to make another thread sleep (without having to intersperse it with if(toldtosleep)Sleep() statements, or the like)?
Is there a way to make another thread sleep (without having to intersperse it with if(toldtosleep)Sleep() statements, or the like)?
November 22, 2002 04:20 AM
to make one thread sleep from within another, use SuspendThread or some sort of blocking mechanism like a critical section or a mutex.
to make the thread sleep within itself use Sleep, WaitForSingleObject/Ex, WaitForMultipleObjects, or a waitable timer (NT/2K/XP only). there''s also SignalObjectAndWait for NT-based systems. i''ve never tried that one.
to make the thread sleep within itself use Sleep, WaitForSingleObject/Ex, WaitForMultipleObjects, or a waitable timer (NT/2K/XP only). there''s also SignalObjectAndWait for NT-based systems. i''ve never tried that one.
yeah, what i didn''t want to do was use some synchronous blocking method like mutexes, so SuspendThread sounds perfect. (this way, when/if beat information needs to get processed, I can get it done w/o having to fight with the graphics engine, which can wait a few milliseconds.) thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement