/** Stop counting, call this method right after you performed the task you want to keep track of. Call {@link #start()} again * when you perform more of that task. */ public void stop () { if (startTime > 0L) { current += (TimeUtils.nanoTime() - startTime) * nano2seconds; startTime = 0L; valid = true; } }
/** If true, sets the visual pressed time to now. If false, clears the visual pressed time. */ public void setVisualPressed (boolean visualPressed) { if (visualPressed) visualPressedTime = TimeUtils.millis() + (long)(visualPressedDuration * 1000); else visualPressedTime = 0; }
@Override public void create () { // test nanos -> millis -> nanos long now = TimeUtils.nanoTime(); long nowConvertToMillis = TimeUtils.nanosToMillis(now); long nowConvertBackToNanos = TimeUtils.millisToNanos(nowConvertToMillis); assertEpsilonEqual(now, nowConvertBackToNanos, "Nano -> Millis conversion"); // test millis -> nanos -> millis long millis = TimeUtils.millis(); long millisToNanos = TimeUtils.millisToNanos(millis); long nanosToMillis = TimeUtils.nanosToMillis(millisToNanos); assertAbsoluteEqual(millis, nanosToMillis, "Millis -> Nanos conversion"); // test comparison for 1 sec long oneSecondMillis = 1000; long oneSecondNanos = 1000000000; assertAbsoluteEqual(oneSecondMillis, TimeUtils.nanosToMillis(oneSecondNanos), "One Second Comparison, Nano -> Millis"); assertAbsoluteEqual(TimeUtils.millisToNanos(oneSecondMillis), oneSecondNanos, "One Second Comparison, Millis -> Nanos"); }
/** Start counting, call this method just before performing the task you want to keep track of. Call {@link #stop()} when done. */ public void start () { startTime = TimeUtils.nanoTime(); valid = false; }
/** Returns true if a touch is over the actor or within the tap square or has been very recently. This allows the UI to show a * press and release that was so fast it occurred within a single frame. */ public boolean isVisualPressed () { if (pressed) return true; if (visualPressedTime <= 0) return false; if (visualPressedTime > TimeUtils.millis()) return true; visualPressedTime = 0; return false; }
/** Stop counting, call this method right after you performed the task you want to keep track of. Call {@link #start()} again * when you perform more of that task. */ public void stop () { if (startTime > 0L) { current += (TimeUtils.nanoTime() - startTime) * nano2seconds; startTime = 0L; valid = true; } }
/** If true, sets the visual pressed time to now. If false, clears the visual pressed time. */ public void setVisualPressed (boolean visualPressed) { if (visualPressed) visualPressedTime = TimeUtils.millis() + (long)(visualPressedDuration * 1000); else visualPressedTime = 0; }
/** Get the time in nanos passed since a previous time * @param prevTime - must be nanoseconds * @return - time passed since prevTime in nanoseconds */ public static long timeSinceNanos (long prevTime) { return nanoTime() - prevTime; }
/** Get the time in millis passed since a previous time * @param prevTime - must be milliseconds * @return - time passed since prevTime in milliseconds */ public static long timeSinceMillis (long prevTime) { return millis() - prevTime; } }
/** Start counting, call this method just before performing the task you want to keep track of. Call {@link #stop()} when done. */ public void start () { startTime = TimeUtils.nanoTime(); valid = false; }
/** Function is called by BatchTiledMapRenderer render(), lastTiledMapRenderTime is used to keep all of the tiles in lock-step * animation and avoids having to call TimeUtils.millis() in getTextureRegion() */ public static void updateAnimationBaseTime () { lastTiledMapRenderTime = TimeUtils.millis() - initialTimeOffset; }
/** @param duration * @return whether the user touched the screen for as much or more than the given duration. */ public boolean isLongPressed (float duration) { if (gestureStartTime == 0) return false; return TimeUtils.nanoTime() - gestureStartTime > (long)(duration * 1000000000l); }
/** Function is called by BatchTiledMapRenderer render(), lastTiledMapRenderTime is used to keep all of the tiles in lock-step * animation and avoids having to call TimeUtils.millis() in getTextureRegion() */ public static void updateAnimationBaseTime () { lastTiledMapRenderTime = TimeUtils.millis() - initialTimeOffset; }
/** Get the time in nanos passed since a previous time * @param prevTime - must be nanoseconds * @return - time passed since prevTime in nanoseconds */ public static long timeSinceNanos (long prevTime) { return nanoTime() - prevTime; }
/** Get the time in millis passed since a previous time * @param prevTime - must be milliseconds * @return - time passed since prevTime in milliseconds */ public static long timeSinceMillis (long prevTime) { return millis() - prevTime; } }
/** @param duration * @return whether the user touched the screen for as much or more than the given duration. */ public boolean isLongPressed (float duration) { if (gestureStartTime == 0) return false; return TimeUtils.nanoTime() - gestureStartTime > (long)(duration * 1000000000l); }
/** Returns true if a touch is over the actor or within the tap square or has been very recently. This allows the UI to show a * press and release that was so fast it occurred within a single frame. */ public boolean isVisualPressed () { if (pressed) return true; if (visualPressedTime <= 0) return false; if (visualPressedTime > TimeUtils.millis()) return true; visualPressedTime = 0; return false; }
@Override public void create () { lastFrameTime = TimeUtils.nanoTime(); }
/** Updates the AssetManager continuously for the specified number of milliseconds, yielding the CPU to the loading thread * between updates. This may block for less time if all loading tasks are complete. This may block for more time if the portion * of a single task that happens in the GL thread takes a long time. * @return true if all loading is finished. */ public boolean update (int millis) { long endTime = TimeUtils.millis() + millis; while (true) { boolean done = update(); if (done || TimeUtils.millis() > endTime) return done; ThreadUtils.yield(); } }
public FPSLogger () { startTime = TimeUtils.nanoTime(); }