Class GLFWContext.MainLoop

java.lang.Object
com.blackrook.gloop.glfw.GLFWContext.MainLoop
All Implemented Interfaces:
Runnable
Enclosing class:
GLFWContext

public static class GLFWContext.MainLoop extends Object implements Runnable
Main GLFW looper. This class serves as a means to create a simple event listener loop where the user can add hooks that need to run on the main thread before or after event processing.
Author:
Matthew Tropiano
  • Method Details

    • addRunnableAlways

      public void addRunnableAlways(Runnable runnable)
      Adds a Runnable that is invoked at the beginning of the loop such that they execute on the main thread.

      Runnables are executed in the order that they are added this way.

      Parameters:
      runnable - the runnable to add.
    • removeRunnableAlways

      public void removeRunnableAlways(Runnable runnable)
      Removes a Runnable that was added by addRunnableAlways(Runnable).
      Parameters:
      runnable - the runnable to remove.
    • addRunnableAlwaysAfterPoll

      public void addRunnableAlwaysAfterPoll(Runnable runnable)
      Adds a Runnable that is invoked at the end of the loop after events are polled such that they execute on the main thread, after event/input polling.

      Runnables are executed in the order that they are added this way, after event/input polling.

      Parameters:
      runnable - the runnable to add.
    • removeRunnableAlwaysAfterPoll

      public void removeRunnableAlwaysAfterPoll(Runnable runnable)
      Removes a Runnable that was added by addRunnableAlwaysAfterPoll(Runnable).
      Parameters:
      runnable - the runnable to remove.
    • addRunnableOnce

      public void addRunnableOnce(Runnable runnable)
      Adds a Runnable that is invoked only once at the beginning of the loop such that it executes on the main thread, but before the "always runnables" are invoked.

      Runnables are executed in the order that they are added this way.

      NOTE: You can invoke most things that require being on the "main thread" using this, provided that the loop is active!

      Parameters:
      runnable - the runnable to add.
    • addRunnableOnLoopExit

      public void addRunnableOnLoopExit(Runnable runnable)
      Adds a Runnable that is invoked only once at the end of the loop such that it executes on the main thread, but only once the loop is escaped due to a closing window.

      Runnables are executed in the order that they are added this way.

      Parameters:
      runnable - the runnable to add.
    • setEventWait

      public void setEventWait(long eventWaitMillis)
      Sets the amount of time in milliseconds to wait for new events in the loop. By the time this wait occurs, joystick events will have been polled. Default is 1 millisecond.
      Parameters:
      eventWaitMillis - the time to wait in milliseconds, or 0 or less for no wait.
    • setLoopWaitMillis

      public void setLoopWaitMillis(long loopWaitMillis)
      Sets the amount of time in milliseconds to wait at the end of the loop after all hooks run and all events are polled. Default is 0 milliseconds (no wait).
      Parameters:
      loopWaitMillis - the time to wait in milliseconds, or 0 or less for no wait.
    • setShutDownOnExit

      public void setShutDownOnExit(boolean shutDownOnExit)
      Sets if GLFW shuts down on exit. If enabled, once the loop exits, the window is destroyed, input callbacks are freed, and GLFWContext.terminate() is called. Disabled by default.
      Parameters:
      shutDownOnExit - true to enable, false to disable.
    • run

      public void run()
      Enters a loop that sets the window and input system, and polls for events and input until the window is closed. When the window closes, the loop exits.

      It is strongly advised that you use this method for starting the main event loop.

      This must only be called from the main thread to ensure that everything works properly!

      Specified by:
      run in interface Runnable
      See Also: