Hey Matt,
it's always nice to look under the hood of other people's projects and see some of the same ideas that you've had.
I just had a look at the time.java file and saw
Code:previousTime = currentTime;
currentTime = System.currentTimeMillis();
// remember kids: time is counted as a long with 1000 to a second (millisecond)
// hense the 0.001f to get the float value of deltaTime.
deltaTime = (currentTime - previousTime) * 0.001d * timeScale;
countTime += deltaTime;
..then went to look inside something I made in January,
Esfera mod by spxl 6, and see almost exactly the same process:
Code:// Timing calculations
clockPrevMillis = clockMillis;
clockMillis = millis();
int millisSinceLastFrame = clockMillis - clockPrevMillis;
// frameMillis and runMillis are affected by the timeWarp...
int frameMillis = int(millisSinceLastFrame * timeWarp);
runMillis += frameMillis;
About the only difference is that I've kept the times in milliseconds, and my code appears in the main draw() function of my sketch.
Also, I hadn't gone on to timer events or anything like that, but did create an Oscillator class with it's own kind of automation - though you have to call the tick() method each frame.
Hmm... Looking some more at your code - I don't entirely follow what is going on in TimerEvent... I'm supposing it calls a method called "timerEvent" in the main sketch every targetTime seconds (of elapsed Time.deltaTime), but I'm not familiar with things like "parent.getClass().getMethod("timerEvent", new Class[] { TimerEvent.class });"
I see that the StopWatch uses system time, not the Time time. I have some questions about it:
In getResultMillis() and getResultSeconds(), if "run" is 1 (started) then you return t2... which will be zero if you've only started the stopwatch once. Do you think using System.currentTimeMillis() - t1 would make more sense?
Every time you start(), t1 is set based on the current system clock (so it is essentially a reset). How about being able to use start() and stop() multiple times to get a cumulative count, with a separate reset() method?
From what I remember years ago having stopwatches on watches (I don't use a watch anymore - time from my phone), there are two buttons: start/stop and split/reset. Start/stop controls the flow of time - like a play/pause button on a CD player. Split allows you to pause the display for reading) whilst the clock keeps ticking in the background - we don't need that in code, since the return value from the getResult methods is "instantaneous" and can be stored in a variable by the caller. A reset() method could be useful though, and work both running and stopped ("run" values 1 and 2).
-spxl