where goes my accuracy?

hello, since i read in the other thread that System.currentMillis is better than nanoTime i tried to change my Timing class.

in order to get the time that has passed since the last frame in my gameloop, i use this code.

[


lastTime = curTime;
curTime = System.currentTimeMillis();
	
frameTime = (curTime-lastTime)  /   1000.0; 
		
System.out.println(frameTime);


(all variables are doubles, not longs)

unfortunately this seems to be very inaccurate. the results are like this.

0.0
0.0
0.0
0.0
0.0
0.015
0.0
0.0
0.0
0.016

where exactly is my problem? thanks!

currentTimeMillis() isn’t better then nanoTime(). It’s more robust, but it’s resolution is a lot lower.

See this thread for details:
http://www.java-gaming.org/forums/index.php?topic=16481.0

See also:
http://www.java-gaming.org/forums/index.php?topic=11640.30

you don’t understand the code

frame time should calculate how much ms has passed executing some block of code, simplified:


startTime = curretTimeMillies();
//... some code
endTime = currentTimeMillies();
frameTime = endTime - startTime;

if this was a in a loop then you could do “startTime = endTime;” instead, like in your code, because time that has passed for calculating frameTime is extreamly small compared to code you are measuring. But if you do this then you need to carefully initialize variables before entering the loop since it won’t be good when calculating for first time.

ok thanks.
i switched back to nanoTime()…