Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  lwjgl getTime and it's delta issue  (Read 324 times)
0 Members and 1 Guest are viewing this topic.
Offline ryuzoku

Junior Newbie





« Posted 2014-01-07 17:09:43 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   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 from: currentTimeMillis()
1389113138376
1389113138393
1389113138409
1389113138426
1389113138443
1389113138459
1389113138476

Quote from: nanoTime()
98300200493549
98300217430225
98300234429621
98300250546376
98300267714546
98300284704819
98300300789074

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...  Sad
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-01-07 17:18:56 »

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?

Offline ryuzoku

Junior Newbie





« Reply #2 - Posted 2014-01-07 17:29:23 »

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 >.<
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DavidW

Junior Member


Medals: 3
Exp: 7 years



« Reply #3 - Posted 2014-01-07 17:42:14 »

1  
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

Hello!
Offline Sickan

Senior Member


Medals: 9



« Reply #4 - Posted 2014-01-08 13:56:51 »

1  
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.
Offline DavidW

Junior Member


Medals: 3
Exp: 7 years



« Reply #5 - Posted 2014-01-09 18:06:28 »

1  
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.

Hello!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!