LWJGL
May 23, 2012, 03:34:00 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Yet another Display.sync question  (Read 681 times)
sufimaster
Newbie
*
Posts: 7


« on: January 04, 2012, 20:51:35 »

Hi,

My game loop occasionally has problems.  I have a first person camera and generally speaking I get smooth movement.  But for some reason once in a while for days my forward/strafe movement becomes choppy.  I investigated a little, and what was going on is that the time delta between loops was coming out as 0 and would only be a larger amount every 6 or 7 loop cycles.  Here is the gist of my loop:

Code:

        lastTime = getTime();
        fpsTime = getTime();

        while (!Display.isCloseRequested() &&
                !Keyboard.isKeyDown(Keyboard.KEY_Q))
        {
        framesPassed++;
       
        time = getTime();
        //System.out.println("Current time: " + time + ", lastTime: " + lastTime);

            dt = time - lastTime;
            lastTime = time;

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glMatrixMode(GL_MODELVIEW);
    GLUtil.logError(-10, 0);

            glLoadIdentity();                       
            updateScene(dt);           
            renderScene(dt);
            updateFPS(dt);
                       
            Display.update();
            Display.sync(60);
        }
        return true;

This seemed like a fairly simple game loop to me. I looked through some of the threads in this forum and there was some fairly complicated stuff going on.  However, then I thought, for some reason, my  mouse look is not choppy at all, even when the movement is choppy.  Surely this must mean there is some other problem?  Anyone have an idea about what might be going on?
Logged
Fool Running
Nerdus Imperius
*****
Posts: 648


« Reply #1 on: January 05, 2012, 06:01:56 »

What is the getTime() method using to get the time?
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
sufimaster
Newbie
*
Posts: 7


« Reply #2 on: January 05, 2012, 07:25:07 »

I've experimented.  Initially I was using Sys.getTime() *1000 / Sys.getTimerResolution().

I thought that was the problem, so I switched so System.nanoTime() which didn't fix anything. Same with System.currentTimeinMillis.

I enabled VSync thinking that would do it - but still no.  Which gets me back to the mouselook question. If my timing was screwed up, wouldn't mouselook also move in a jerky manner? It moves very smoothly.
Logged
sufimaster
Newbie
*
Posts: 7


« Reply #3 on: January 05, 2012, 18:51:34 »

This was a very stupid programming error on my part. I was using floats for my time storing variables. I don't even know why or how it ever worked appropriately. Now it works fine that I changed them to long. DISREGARD STUPIDITY, PROGRAM GAME.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!