lwjgl getTime and it's delta issue

I’ve been following a youtube tutorial(The Coding Universe) for LWJGL and everything’s been working fine up until the section on timers.

I copied it directly as he was saying but when i did System.out.println(getDelta());

it’s returning not only extremly large numbers there are also negatives!

[quote]-46529436
-1408005007
1916619492
946277273
-219630599
-1189971696
2134655081
968748809
-1590588
-971929407
-2137834079
1186795520
216458401
-949444671
-1919780668
1404851209
238949737
-731384560
-1701718279
1427349145
457016548
[/quote]


   private long getTime() {
		//returns time in milliseconds
		return (Sys.getTime()* 1000) / (Sys.getTimerResolution());
	}
	
	private int getDelta() {
		long currentTime = getTime();
		int delta = (int)(currentTime * lastFrame);
		lastFrame = getTime();
		return delta;
	}

i get similar results with System.currentTimeMillis() and System.nanoTime()

[quote=currentTimeMillis()]1389113138376
1389113138393
1389113138409
1389113138426
1389113138443
1389113138459
1389113138476
[/quote]

[quote=nanoTime()]98300200493549
98300217430225
98300234429621
98300250546376
98300267714546
98300284704819
98300300789074
[/quote]
i wanted to see if it would affect the rest of the code, so i kept going (supposed to use the delta to move a box off the screen) but where you should see the box move off, it doesnt even show up. (or does and gets flung off the screen faster than i can see it?!)

and removing or keeping Display.sync(60); in the code doesnt change anything.

the code he linked in the comments for the example isnt quite the same either (same code pieces but main loop and opengl initialization is placed in the main instead of creating a method and starting it in the main.

working in eclipse on windows 8 pro if that makes any difference… :frowning:

Just look at his code in the repo then. If he pushed it to his repo, I imagine it works, so why not start there?

honestly i thought about it but:

  1. i’d really like to know why it’s behaving the way it is and
  2. his link in the video’s comments shows the code also as completed (for the whole video)

i’d like to be able to work through the video as a whole to get a better understanding on how this part works.

another option would be to try coding the example again >.<


int delta = (int)(currentTime * lastFrame);

Here is your problem. The delta should be the difference between the times, not the product. In mathematics, the Greek letter delta is often used for differences because, well, it’s like a D for difference :wink:

And the negatives are probably because (long * long) cast to int will often overflow.

I figured it was something like that. To OP, hope this solved your issue.