Class LegacyApplication
- All Implemented Interfaces:
Application
,SystemListener
- Direct Known Subclasses:
SimpleApplication
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 Summary
Modifier and TypeFieldDescriptionprotected AssetManager
protected AudioRenderer
protected Camera
protected JmeContext
protected ViewPort
protected boolean
protected InputManager
protected JoyInput
protected KeyInput
protected Listener
protected LostFocusBehavior
protected MouseInput
protected boolean
protected AppProfiler
protected Renderer
protected RenderManager
protected AppSettings
protected float
protected AppStateManager
protected Timer
protected TouchInput
protected ViewPort
-
Constructor Summary
ConstructorDescriptionCreate a new instance ofLegacyApplication
.LegacyApplication
(AppState... initialStates) Create a new instance ofLegacyApplication
, preinitialized with the specified set of app states. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initializes the application's canvas for use.void
destroy()
Do not call manually.protected void
void
Enqueues a runnable object to execute in the jME3 rendering thread.<V> Future<V>
Enqueues a task/callable object to execute in the jME3 rendering thread.void
Internal use only.Returns the current AppProfiler hook, or null if none is set.Determine the application's behavior when unfocused.getTimer()
void
handleError
(String errMsg, Throwable t) Internal use only.void
Do not call manually.boolean
Returns true if pause on lost focus is enabled, false otherwise.void
Internal use only.void
requestClose
(boolean esc) Internal use only.void
rescale
(float x, float y) Called to notify the application that the scale has changed.void
reshape
(int w, int h) Internal use only.void
restart()
Restarts the context, applying any changed settings.protected void
Runs tasks enqueued viaenqueue(Callable)
void
setAppProfiler
(AppProfiler prof) Sets an AppProfiler hook that will be called back for specific steps within a single update frame.void
setAssetManager
(AssetManager assetManager) Deprecated.void
setLostFocusBehavior
(LostFocusBehavior lostFocusBehavior) Changes the application's behavior when unfocused.void
setPauseOnLostFocus
(boolean pauseOnLostFocus) Enable or disable pause on lost focus.void
setSettings
(AppSettings settings) Set the display settings to define the display created.void
Sets the Timer implementation that will be used for calculating frame times.void
start()
Starts the application indisplay
mode.void
start
(boolean waitFor) Starts the application indisplay
mode.void
start
(JmeContext.Type contextType) Starts the application.void
start
(JmeContext.Type contextType, boolean waitFor) Starts the application.void
Starts the rendering thread after createCanvas() has been called.void
startCanvas
(boolean waitFor) Starts the rendering thread after createCanvas() has been called.void
stop()
Requests the context to close, shutting down the main loop and making necessary cleanup operations.void
stop
(boolean waitFor) Requests the context to close, shutting down the main loop and making necessary cleanup operations.void
update()
Do not call manually.
-
Field Details
-
assetManager
-
audioRenderer
-
renderer
-
renderManager
-
viewPort
-
guiViewPort
-
context
-
settings
-
timer
-
cam
-
listener
-
inputEnabled
protected boolean inputEnabled -
lostFocusBehavior
-
speed
protected float speed -
paused
protected boolean paused -
mouseInput
-
keyInput
-
joyInput
-
touchInput
-
inputManager
-
stateManager
-
prof
-
-
Constructor Details
-
LegacyApplication
public LegacyApplication()Create a new instance ofLegacyApplication
. -
LegacyApplication
Create a new instance ofLegacyApplication
, preinitialized with the specified set of app states.- Parameters:
initialStates
- app states to pre-attach, or null for none
-
-
Method Details
-
getLostFocusBehavior
Determine the application's behavior when unfocused.- Specified by:
getLostFocusBehavior
in interfaceApplication
- Returns:
- The lost focus behavior of the application.
-
setLostFocusBehavior
Changes the application's behavior when unfocused. By default, the application willthrottle 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 interfaceApplication
- 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 interfaceApplication
- 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 interfaceApplication
- Parameters:
pauseOnLostFocus
- True to enable pause on lost focus, false otherwise.- See Also:
-
setAssetManager
Deprecated. -
setSettings
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 interfaceApplication
- Parameters:
settings
- The settings to set.
-
setTimer
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 interfaceApplication
- Parameters:
timer
- the desired timer (alias created)
-
getTimer
- Specified by:
getTimer
in interfaceApplication
-
getAssetManager
- Specified by:
getAssetManager
in interfaceApplication
- Returns:
- The
asset manager
for this application.
-
getInputManager
- Specified by:
getInputManager
in interfaceApplication
- Returns:
- the
input manager
.
-
getStateManager
- Specified by:
getStateManager
in interfaceApplication
- Returns:
- the
app state manager
-
getRenderManager
- Specified by:
getRenderManager
in interfaceApplication
- Returns:
- the
render manager
-
getRenderer
- Specified by:
getRenderer
in interfaceApplication
- Returns:
- The
renderer
for the application
-
getAudioRenderer
- Specified by:
getAudioRenderer
in interfaceApplication
- Returns:
- The
audio renderer
for the application
-
getListener
- Specified by:
getListener
in interfaceApplication
- Returns:
- The
listener
object for audio
-
getContext
- Specified by:
getContext
in interfaceApplication
- Returns:
- The
display context
for the application
-
getCamera
- Specified by:
getCamera
in interfaceApplication
- Returns:
- The
camera
for the application
-
start
public void start()Starts the application indisplay
mode.- Specified by:
start
in interfaceApplication
- See Also:
-
start
public void start(boolean waitFor) Starts the application indisplay
mode.- Specified by:
start
in interfaceApplication
- Parameters:
waitFor
- true→wait for the context to be initialized, false→don't wait- See Also:
-
start
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
Starts the application. Creating a rendering context and executing the main loop in a separate thread.- Parameters:
contextType
- the type of context to createwaitFor
- true→wait for the context to be initialized, false→don't wait
-
setAppProfiler
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 interfaceApplication
- Parameters:
prof
- the profiler to use (alias created) or null for none
-
getAppProfiler
Returns the current AppProfiler hook, or null if none is set.- Specified by:
getAppProfiler
in interfaceApplication
- 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 callstartCanvas()
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 interfaceSystemListener
- 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 interfaceSystemListener
- Parameters:
x
- the new horizontal scale of the displayy
- 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 interfaceApplication
-
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 interfaceApplication
- 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 interfaceApplication
- Parameters:
waitFor
- true→wait for the context to be fully destroyed, false→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 interfaceSystemListener
-
handleError
Internal use only.- Specified by:
handleError
in interfaceSystemListener
- 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 interfaceSystemListener
-
loseFocus
public void loseFocus()Internal use only.- Specified by:
loseFocus
in interfaceSystemListener
-
requestClose
public void requestClose(boolean esc) Internal use only.- Specified by:
requestClose
in interfaceSystemListener
- Parameters:
esc
- If true, the user pressed ESC to close the application.
-
enqueue
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 interfaceApplication
- 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
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 interfaceApplication
- Parameters:
runnable
- The runnable to run in the main jME3 thread
-
runQueuedTasks
protected void runQueuedTasks()Runs tasks enqueued viaenqueue(Callable)
-
update
public void update()Do not call manually. Callback from ContextListener.- Specified by:
update
in interfaceSystemListener
-
destroyInput
protected void destroyInput() -
destroy
public void destroy()Do not call manually. Callback from ContextListener.- Specified by:
destroy
in interfaceSystemListener
-
getGuiViewPort
- Specified by:
getGuiViewPort
in interfaceApplication
- Returns:
- The GUI viewport. Which is used for the on screen statistics and FPS.
-
getViewPort
- Specified by:
getViewPort
in interfaceApplication
-