/* * call-seq: * Clock.wait( time, nice=false ) -> Integer * * time:: The target wait time, in milliseconds. * (Non-negative Integer. Required.) * nice:: If true, try to let other ruby threads run during the delay. * (true or false. Optional.) * * Returns:: The actual wait time, in milliseconds. * * Pause the program for approximately +time+ milliseconds. Both this * function and Clock.delay can be used to slow down the framerate so * that the application doesn't use too much CPU time. See also * Clock#tick for a good and easy way to limit the framerate. * * The accuracy of this function depends on processor scheduling, * which varies with operating system and hardware. The actual delay * time may be up to 10ms longer than +time+. If you need more * accuracy use Clock.delay, which is more accurate but uses slightly * more CPU time. * * If +nice+ is true, this function will try to allow other ruby * threads to run during this function. Otherwise, other ruby threads * will probably also be paused. Setting +nice+ to true is only * useful if your application is multithreaded. It's safe (but * pointless) to use this feature for single threaded applications. * * The Rubygame timer system will be initialized when you call this * function, if it has not been already. See Clock.runtime. * */ VALUE rbgm_clock_wait(int argc, VALUE *argv, VALUE module) { rg_init_sdl_timer(); VALUE vtime, vnice; rb_scan_args(argc,argv,"11", &vtime, &vnice); int delay = NUM2INT(vtime); if( delay < 0 ) { delay = 0; } int nice = (vnice == Qtrue) ? 1 : 0; return UINT2NUM( rg_threaded_delay(delay, nice) ); }