@ Override public void run ( long timeToRun ) { // Increment the frame number frame ++ ; // Clear the list of tasks to run runList . size = 0 ; // Go through each task for ( int i = 0 ; i < schedulableRecords . size ; i ++ ) { SchedulableRecord record = schedulableRecords . get ( i ) ; // If it is due, schedule it if ( ( frame + record . phase ) % record . frequency == 0 ) runList . add ( record ) ; } // Keep track of the current time long lastTime = TimeUtils . nanoTime ( ) ; // Find the number of tasks we need to run int numToRun = runList . size ; // Go through the tasks to run for ( int i = 0 ; i < numToRun ; i ++ ) { // Find the available time long currentTime = TimeUtils . nanoTime ( ) ; timeToRun -= currentTime - lastTime ; long availableTime = timeToRun / ( numToRun - i ) ; // Run the schedulable object runList . get ( i ) . schedulable . run ( availableTime ) ; // Store the current time lastTime = currentTime ; } }
Executes scheduled tasks based on their frequency and phase . This method must be called once per frame .