Java Code Examples for org.lwjgl.Sys#getTime()

The following examples show how to use org.lwjgl.Sys#getTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LwjglSmoothingTimer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void reset() {
    lastFrameDiff = 0;
    lastFPS = 0;
    lastTPF = 0;

    // init to -1 to indicate this is a new timer.
    oldTime = -1;
    //reset time
    startTime = Sys.getTime();

    tpf = new long[TIMER_SMOOTHNESS];
    smoothIndex = TIMER_SMOOTHNESS - 1;
    invTimerRezSmooth = ( 1f / (LWJGL_TIMER_RES * TIMER_SMOOTHNESS));

    // set tpf... -1 values will not be used for calculating the average in update()
    for ( int i = tpf.length; --i >= 0; ) {
        tpf[i] = -1;
    }
}
 
Example 2
Source File: LwjglSmoothingTimer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void reset() {
    lastFrameDiff = 0;
    lastFPS = 0;
    lastTPF = 0;

    // init to -1 to indicate this is a new timer.
    oldTime = -1;
    //reset time
    startTime = Sys.getTime();

    tpf = new long[TIMER_SMOOTHNESS];
    smoothIndex = TIMER_SMOOTHNESS - 1;
    invTimerRezSmooth = ( 1f / (LWJGL_TIMER_RES * TIMER_SMOOTHNESS));

    // set tpf... -1 values will not be used for calculating the average in update()
    for ( int i = tpf.length; --i >= 0; ) {
        tpf[i] = -1;
    }
}
 
Example 3
Source File: LwjglTimer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void reset() {
    startTime = Sys.getTime();
    oldTime = getTime();
}
 
Example 4
Source File: LwjglSmoothingTimer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @see com.jme.util.Timer#getTime()
 */
public long getTime() {
    return Sys.getTime() - startTime;
}
 
Example 5
Source File: LwjglMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public long getInputTimeNanos() {
    return Sys.getTime() * LwjglTimer.LWJGL_TIME_TO_NANOS;
}
 
Example 6
Source File: LwjglKeyInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public long getInputTimeNanos() {
    return Sys.getTime() * LwjglTimer.LWJGL_TIME_TO_NANOS;
}
 
Example 7
Source File: LwjglTimer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see Timer#getTime() 
 */
@Override
public long getTime() {
    return Sys.getTime() - startTime;
}
 
Example 8
Source File: MixinMinecraft.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
public long getTime() {
    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
 
Example 9
Source File: LwjglSmoothingTimer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * <code>update</code> recalulates the frame rate based on the previous
 * call to update. It is assumed that update is called each frame.
 */
@Override
public void update() {
    long newTime = Sys.getTime();
    long oldTime = this.oldTime;
    this.oldTime = newTime;
    if ( oldTime == -1 ) {
        // For the first frame use 60 fps. This value will not be counted in further averages.
        // This is done so initialization code between creating the timer and the first
        // frame is not counted as a single frame on its own.
        lastTPF = 1 / 60f;
        lastFPS = 1f / lastTPF;
        return;
    }

    long frameDiff = newTime - oldTime;
    long lastFrameDiff = this.lastFrameDiff;
    if ( lastFrameDiff > 0 && frameDiff > lastFrameDiff *100 ) {
        frameDiff = lastFrameDiff *100;
    }
    this.lastFrameDiff = frameDiff;
    tpf[smoothIndex] = frameDiff;
    smoothIndex--;
    if ( smoothIndex < 0 ) {
        smoothIndex = tpf.length - 1;
    }

    lastTPF = 0.0f;
    if (!allSmooth) {
        int smoothCount = 0;
        for ( int i = tpf.length; --i >= 0; ) {
            if ( tpf[i] != -1 ) {
                lastTPF += tpf[i];
                smoothCount++;
            }
        }
        if (smoothCount == tpf.length)
            allSmooth  = true;
        lastTPF *= ( INV_LWJGL_TIMER_RES / smoothCount );
    } else {
        for ( int i = tpf.length; --i >= 0; ) {
            if ( tpf[i] != -1 ) {
                lastTPF += tpf[i];
            }
        }
        lastTPF *= invTimerRezSmooth;
    }
    if ( lastTPF < FastMath.FLT_EPSILON ) {
        lastTPF = FastMath.FLT_EPSILON;
    }

    lastFPS = 1f / lastTPF;
}
 
Example 10
Source File: LwjglSmoothingTimer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * <code>update</code> recalulates the frame rate based on the previous
 * call to update. It is assumed that update is called each frame.
 */
public void update() {
    long newTime = Sys.getTime();
    long oldTime = this.oldTime;
    this.oldTime = newTime;
    if ( oldTime == -1 ) {
        // For the first frame use 60 fps. This value will not be counted in further averages.
        // This is done so initialization code between creating the timer and the first
        // frame is not counted as a single frame on it's own.
        lastTPF = 1 / 60f;
        lastFPS = 1f / lastTPF;
        return;
    }

    long frameDiff = newTime - oldTime;
    long lastFrameDiff = this.lastFrameDiff;
    if ( lastFrameDiff > 0 && frameDiff > lastFrameDiff *100 ) {
        frameDiff = lastFrameDiff *100;
    }
    this.lastFrameDiff = frameDiff;
    tpf[smoothIndex] = frameDiff;
    smoothIndex--;
    if ( smoothIndex < 0 ) {
        smoothIndex = tpf.length - 1;
    }

    lastTPF = 0.0f;
    if (!allSmooth) {
        int smoothCount = 0;
        for ( int i = tpf.length; --i >= 0; ) {
            if ( tpf[i] != -1 ) {
                lastTPF += tpf[i];
                smoothCount++;
            }
        }
        if (smoothCount == tpf.length)
            allSmooth  = true;
        lastTPF *= ( INV_LWJGL_TIMER_RES / smoothCount );
    } else {
        for ( int i = tpf.length; --i >= 0; ) {
            if ( tpf[i] != -1 ) {
                lastTPF += tpf[i];
            }
        }
        lastTPF *= invTimerRezSmooth;
    }
    if ( lastTPF < FastMath.FLT_EPSILON ) {
        lastTPF = FastMath.FLT_EPSILON;
    }

    lastFPS = 1f / lastTPF;
}
 
Example 11
Source File: LwjglMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public long getInputTimeNanos() {
    return Sys.getTime() * LwjglTimer.LWJGL_TIME_TO_NANOS;
}
 
Example 12
Source File: LwjglKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public long getInputTimeNanos() {
    return Sys.getTime() * LwjglTimer.LWJGL_TIME_TO_NANOS;
}
 
Example 13
Source File: LwjglTimer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void reset() {
    startTime = Sys.getTime();
    oldTime = getTime();
}
 
Example 14
Source File: DisplayManager.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
private static long getCurrentTime() {
	return Sys.getTime() * 1000 / Sys.getTimerResolution();
}
 
Example 15
Source File: LwjglTimer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @see com.jme.util.Timer#getTime()
 */
public long getTime() {
    return Sys.getTime() - startTime;
}
 
Example 16
Source File: GameContainer.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the accurate system time
 * 
 * @return The system time in milliseconds
 */
@Override
public long getTime() {
	return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
 
Example 17
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * http://wiki.lwjgl.org/index.php?title=LWJGL_Basics_4_%28Timing%29
 * Get the time in milliseconds
 *
 * @return The system time in milliseconds
 */
public long getTime() {
    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
 
Example 18
Source File: Animation.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the accurate system time
 * 
 * @return The system time in milliseconds
 */
private long getTime() {
	return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
 
Example 19
Source File: GameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the accurate system time
 * 
 * @return The system time in milliseconds
 */
public long getTime() {
	return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
 
Example 20
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 2 votes vote down vote up
/**
 * http://wiki.lwjgl.org/index.php?title=LWJGL_Basics_4_%28Timing%29
 * Get the time in milliseconds
 *
 * @return The system time in milliseconds
 */
public long getTime() {
    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}