Advertisement

[java] Tick Count in Java

Started by August 11, 2000 04:07 PM
3 comments, last by loserkid 24 years, 4 months ago
Does anyone know how to calculate the tick count in java? Thanks in advance. ============================= silly programmer vb is for kids.
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
Tick count? Do you mean fps? The way to get time is via:

static long java.lang.System.currentTimeMillis()
"We who cut mere stones must always be envisioning cathedrals"
Advertisement
Of course, that''s ugly. The granularity on the measurements that returns is about 50 or 60 ms, and the resolution is 10 ms. Although, come to think of it, if the granularity is that high, the greater precision doesn''t mean anything.

I wouldn''t trust that function to provide any better timing info than the nearest 1/10th of a second, which is far too large a chunk to be useful in most game programming.
Forgive me for being so vague in my original question, let me try to clarify it (I hope). At the Java One site they had a seminar on animations in Java and they mentioned how to get the tick count with the following code:

    millis  = System.currentTimeMillis();tickdPassed = (millis - lastMillis)*ticks_per_MS;currentTicks = lastTicks + ticksPassed;lastTicks = currentTicks;lastMillis = currentMillis;return (currentTicks - lastTicks);    


The code above is all well and good, but they didn''t seem to mention the value of the var ticks_per_MS, or how to get the value. So if you have any ideas it would be great.

Thanks.


=============================
silly programmer vb is for kids.
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
Anon, don''t know of any better ways of getting the time in Java, I agree, it is pretty pants though :-)

loserkid, from the code frag. it seems that ticks_per_MS is equal to the number of ticks each millisecond. What that frag. is doing, is returning the number of ticks which have passed since the function was last called.

ticks_per_MS is essentially the speed. For example if you wanted the rate to be 1 tick every 5 milliseconds, then it would be (1/5 * milliseconds_passed), or 0.2 * milliseconds_passed...
"We who cut mere stones must always be envisioning cathedrals"

This topic is closed to new replies.

Advertisement