We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › timer() usage
Page Index Toggle Pages: 1
timer() usage (Read 929 times)
timer() usage
Sep 17th, 2005, 5:39pm
 
I've come across a number of programs that use what I take to be a Processing timer construct, usually initialized like

timer myTimer = new timer(millis());

and then called to output the time between frames in the draw() method.

float dt = myTimer.M_getDelta(millis())/1000;

I can't find any documentation of this function in the processing reference, or the dev javadoc; it doesn't seem to match with java.util.timer, which has no input for millis() and when I search the sun dev site I can't find reference to M_getDelta anywhere..

I'd like to use this method of determining the elapsed time since the last frame in a simple physics library I'm writing for my own use (so, called from within a .java file) .. what do I need to import to do so? processing.core.* doesn't cut it, apparantly.
Re: timer() usage
Reply #1 - Sep 17th, 2005, 7:53pm
 
it's not part of the processing api, i think most are either java.util.Timer (whose api i think has changed.. it may have been originally part of swing and then maybe made its way into java.util?) or self-created timer classes of the same name.
Re: timer() usage
Reply #2 - Sep 30th, 2005, 2:27am
 
I was doing some physics simulation work recently and found that having an accurate elapsed time mechanism for the simulation was useful. I did this by making a small class that i would then initialize with the simulation initialization which then kept track of the main object timing.

What Alterscape is talking about looks to me like an object that is doing the same thing. The java.util.Timer is a utility for scheduling thread processes and has a different initialization and methods attached to it (at least in 1.5).

My guess is that the class is just a simple variable that takes the initialization argument and stores it. Then when called it is passed the current time and returns the difference. by dividing by 1000 this gives the seconds elapsed.

my code is:

public class Time implements Cloneable{

private long t;

 public Time(){
  this.t=System.currentTimeMillis();
 }

 public int millis(){
  return (int)(System.currentTimeMillis() - this.t);
 }

 public void resetTime(){
  this.t=System.currentTimeMillis();
 }

 public Object clone(){
    try
       {
       return super.clone();
       }
    catch ( CloneNotSupportedException e )
       {
       return null;
       }
     }
}
Page Index Toggle Pages: 1