Package com.jme3.app

Class LegacyApplication

java.lang.Object
com.jme3.app.LegacyApplication
All Implemented Interfaces:
Application, SystemListener
Direct Known Subclasses:
SimpleApplication

public class LegacyApplication extends Object implements Application, SystemListener
The LegacyApplication class represents an instance of a real-time 3D rendering jME application. An LegacyApplication provides all the tools that are commonly used in jME3 applications. jME3 applications *SHOULD NOT EXTEND* this class but extend SimpleApplication instead.
  • Field Details

  • Constructor Details

    • LegacyApplication

      public LegacyApplication()
      Create a new instance of LegacyApplication.
    • LegacyApplication

      public LegacyApplication(AppState... initialStates)
      Create a new instance of LegacyApplication, preinitialized with the specified set of app states.
      Parameters:
      initialStates - app states to pre-attach, or null for none
  • Method Details

    • getLostFocusBehavior

      public LostFocusBehavior getLostFocusBehavior()
      Determine the application's behavior when unfocused.
      Specified by:
      getLostFocusBehavior in interface Application
      Returns:
      The lost focus behavior of the application.
    • setLostFocusBehavior

      public void setLostFocusBehavior(LostFocusBehavior lostFocusBehavior)
      Changes the application's behavior when unfocused. By default, the application will throttle the update loop so as not to use 100% of the CPU when out of focus, e.g. alt-tabbed, minimized, or hidden by another window.
      Specified by:
      setLostFocusBehavior in interface Application
      Parameters:
      lostFocusBehavior - The new lost focus behavior to use.
      See Also:
    • isPauseOnLostFocus

      public boolean isPauseOnLostFocus()
      Returns true if pause on lost focus is enabled, false otherwise.
      Specified by:
      isPauseOnLostFocus in interface Application
      Returns:
      true if pause on lost focus is enabled
      See Also:
    • setPauseOnLostFocus

      public void setPauseOnLostFocus(boolean pauseOnLostFocus)
      Enable or disable pause on lost focus.

      By default, pause on lost focus is enabled. If enabled, the application will stop updating when it loses focus or becomes inactive (e.g. alt-tab). For online or real-time applications, this might be undesirable, so this feature should be disabled. For other applications, it is best to keep it enabled so the CPU is not used unnecessarily.

      Specified by:
      setPauseOnLostFocus in interface Application
      Parameters:
      pauseOnLostFocus - True to enable pause on lost focus, false otherwise.
      See Also:
    • setAssetManager

      @Deprecated public void setAssetManager(AssetManager assetManager)
      Deprecated.
    • setSettings

      public void setSettings(AppSettings settings)
      Set the display settings to define the display created.

      Examples of display parameters include display pixel width and height, color bit depth, z-buffer bits, anti-aliasing samples, and update frequency. If this method is called while the application is already running, then restart() must be called to apply the settings to the display.

      Specified by:
      setSettings in interface Application
      Parameters:
      settings - The settings to set.
    • setTimer

      public void setTimer(Timer timer)
      Sets the Timer implementation that will be used for calculating frame times. By default, Application will use the Timer as returned by the current JmeContext implementation.
      Specified by:
      setTimer in interface Application
      Parameters:
      timer - the desired timer (alias created)
    • getTimer

      public Timer getTimer()
      Specified by:
      getTimer in interface Application
    • getAssetManager

      public AssetManager getAssetManager()
      Specified by:
      getAssetManager in interface Application
      Returns:
      The asset manager for this application.
    • getInputManager

      public InputManager getInputManager()
      Specified by:
      getInputManager in interface Application
      Returns:
      the input manager.
    • getStateManager

      public AppStateManager getStateManager()
      Specified by:
      getStateManager in interface Application
      Returns:
      the app state manager
    • getRenderManager

      public RenderManager getRenderManager()
      Specified by:
      getRenderManager in interface Application
      Returns:
      the render manager
    • getRenderer

      public Renderer getRenderer()
      Specified by:
      getRenderer in interface Application
      Returns:
      The renderer for the application
    • getAudioRenderer

      public AudioRenderer getAudioRenderer()
      Specified by:
      getAudioRenderer in interface Application
      Returns:
      The audio renderer for the application
    • getListener

      public Listener getListener()
      Specified by:
      getListener in interface Application
      Returns:
      The listener object for audio
    • getContext

      public JmeContext getContext()
      Specified by:
      getContext in interface Application
      Returns:
      The display context for the application
    • getCamera

      public Camera getCamera()
      Specified by:
      getCamera in interface Application
      Returns:
      The camera for the application
    • start

      public void start()
      Starts the application in display mode.
      Specified by:
      start in interface Application
      See Also:
    • start

      public void start(boolean waitFor)
      Starts the application in display mode.
      Specified by:
      start in interface Application
      Parameters:
      waitFor - true→wait for the context to be initialized, false→don't wait
      See Also:
    • start

      public void start(JmeContext.Type contextType)
      Starts the application. Creating a rendering context and executing the main loop in a separate thread.
      Parameters:
      contextType - the type of context to create
    • start

      public void start(JmeContext.Type contextType, boolean waitFor)
      Starts the application. Creating a rendering context and executing the main loop in a separate thread.
      Parameters:
      contextType - the type of context to create
      waitFor - true→wait for the context to be initialized, false→don't wait
    • setAppProfiler

      public void setAppProfiler(AppProfiler prof)
      Sets an AppProfiler hook that will be called back for specific steps within a single update frame. Value defaults to null.
      Specified by:
      setAppProfiler in interface Application
      Parameters:
      prof - the profiler to use (alias created) or null for none
    • getAppProfiler

      public AppProfiler getAppProfiler()
      Returns the current AppProfiler hook, or null if none is set.
      Specified by:
      getAppProfiler in interface Application
      Returns:
      the pre-existing instance, or null if none
    • createCanvas

      public void createCanvas()
      Initializes the application's canvas for use.

      After calling this method, cast the getContext() context to JmeCanvasContext, then acquire the canvas with JmeCanvasContext.getCanvas() and attach it to an AWT/Swing Frame. The rendering thread will start when the canvas becomes visible on screen, however if you wish to start the context immediately you may call startCanvas() to force the rendering thread to start.

      See Also:
    • startCanvas

      public void startCanvas()
      Starts the rendering thread after createCanvas() has been called.

      Same as calling startCanvas(false)

      See Also:
    • startCanvas

      public void startCanvas(boolean waitFor)
      Starts the rendering thread after createCanvas() has been called.

      Calling this method is optional, the canvas will start automatically when it becomes visible.

      Parameters:
      waitFor - If true, the current thread will block until the rendering thread is running
    • reshape

      public void reshape(int w, int h)
      Internal use only.
      Specified by:
      reshape in interface SystemListener
      Parameters:
      w - the new width of the display (in pixels, ≥0)
      h - the new height of the display (in pixels, ≥0)
    • rescale

      public void rescale(float x, float y)
      Description copied from interface: SystemListener
      Called to notify the application that the scale has changed.
      Specified by:
      rescale in interface SystemListener
      Parameters:
      x - the new horizontal scale of the display
      y - the new vertical scale of the display
    • restart

      public void restart()
      Restarts the context, applying any changed settings.

      Changes to the AppSettings of this Application are not applied immediately; calling this method forces the context to restart, applying the new settings.

      Specified by:
      restart in interface Application
    • stop

      public void stop()
      Requests the context to close, shutting down the main loop and making necessary cleanup operations. Same as calling stop(false)
      Specified by:
      stop in interface Application
      See Also:
    • stop

      public void stop(boolean waitFor)
      Requests the context to close, shutting down the main loop and making necessary cleanup operations. After the application has stopped, it cannot be used anymore.
      Specified by:
      stop in interface Application
      Parameters:
      waitFor - true→wait for the context to be fully destroyed, true→don't wait
    • initialize

      public void initialize()
      Do not call manually. Callback from ContextListener.

      Initializes the Application, by creating a display and default camera. If display settings are not specified, a default 640x480 display is created. Default values are used for the camera; perspective projection with 45° field of view, with near and far values 1 and 1000 units respectively.

      Specified by:
      initialize in interface SystemListener
    • handleError

      public void handleError(String errMsg, Throwable t)
      Internal use only.
      Specified by:
      handleError in interface SystemListener
      Parameters:
      errMsg - The error message, if any, or null.
      t - Throwable object, or null.
    • gainFocus

      public void gainFocus()
      Internal use only.
      Specified by:
      gainFocus in interface SystemListener
    • loseFocus

      public void loseFocus()
      Internal use only.
      Specified by:
      loseFocus in interface SystemListener
    • requestClose

      public void requestClose(boolean esc)
      Internal use only.
      Specified by:
      requestClose in interface SystemListener
      Parameters:
      esc - If true, the user pressed ESC to close the application.
    • enqueue

      public <V> Future<V> enqueue(Callable<V> callable)
      Enqueues a task/callable object to execute in the jME3 rendering thread.

      Callables are executed right at the beginning of the main loop. They are executed even if the application is currently paused or out of focus.

      Specified by:
      enqueue in interface Application
      Type Parameters:
      V - type of result returned by the Callable
      Parameters:
      callable - The callable to run in the main jME3 thread
      Returns:
      a new instance
    • enqueue

      public void enqueue(Runnable runnable)
      Enqueues a runnable object to execute in the jME3 rendering thread.

      Runnables are executed right at the beginning of the main loop. They are executed even if the application is currently paused or out of focus.

      Specified by:
      enqueue in interface Application
      Parameters:
      runnable - The runnable to run in the main jME3 thread
    • runQueuedTasks

      protected void runQueuedTasks()
      Runs tasks enqueued via enqueue(Callable)
    • update

      public void update()
      Do not call manually. Callback from ContextListener.
      Specified by:
      update in interface SystemListener
    • destroyInput

      protected void destroyInput()
    • destroy

      public void destroy()
      Do not call manually. Callback from ContextListener.
      Specified by:
      destroy in interface SystemListener
    • getGuiViewPort

      public ViewPort getGuiViewPort()
      Specified by:
      getGuiViewPort in interface Application
      Returns:
      The GUI viewport. Which is used for the on screen statistics and FPS.
    • getViewPort

      public ViewPort getViewPort()
      Specified by:
      getViewPort in interface Application