Class SceneContext
- All Implemented Interfaces:
Updatable
SceneContext
to the currently active scene during each
frame update, which allows the scene to perform frame update logic. The
renderer then renders the frame based on the current contents of the stage.
The SceneContext
also allows sub-scenes to be attached to
the current scene. These sub-scenes can contain their own logic, but cannot
outlive their parent scene. When the active scene is changed, both the scene
itself and its sub-scenes will be terminated and the stage will be cleared
in preparation for the next scene.
-
Constructor Summary
ConstructorDescriptionSceneContext
(Renderer renderer, MediaLoader media, InputDevice input, Network network) Creates a newSceneContext
from the specified renderer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Wraps aRunnable
so that is acts as a sub-scene for the currently active scene.void
Attaches a sub-scene to the currently active scene.void
Attaches anUpdatable
to act as a sub-scene for the currently active scene.void
attachGlobal
(Scene globalSubScene) Attaches a scene that is *not* tied to the currently active scene, and will remain active for the rest of the application.void
changeScene
(Scene requestedScene) Requests to change the active scene after the current frame update has been completed.Returns debug and support information that can be displayed when running a MultimediaLib application in debug mode.getInput()
Returns the display name for the underlying renderer.getStage()
protected void
replaceTimer
(nl.colorize.util.Stopwatch timer) Replaces theStopwatch
that is used as a timer for the animation loop and frame updates.int
Synchronizes between "native" frames and application frame updates.void
Terminates the application.void
update
(float deltaTime) Performs an application frame update.
-
Constructor Details
-
SceneContext
Creates a newSceneContext
from the specified renderer. This constructor should not be called from application code. The renderer will create theSceneContext
from the animation loop thread.
-
-
Method Details
-
replaceTimer
protected void replaceTimer(nl.colorize.util.Stopwatch timer) Replaces theStopwatch
that is used as a timer for the animation loop and frame updates. -
syncFrame
public int syncFrame()Synchronizes between "native" frames and application frame updates. Should be called by the renderer during every "native" frame. Depending on the elapsed time and target framerate, this method will then manage application frame updates by callingupdate(float)
accordingly.Although this class provides the renderer with the delta time since the last frame update, this may not always reflect the actual elapsed time. it is not realistic to expect applications to be able to function correctly for every possible
deltaTime
value, so this method will attempt to produce frame updates that try to find a balance between the targeted framerate and the actual elapsed time.Note that rendering the frame is not managed by this method. The renderer should make sure that every "native" frame is rendered, even if that frame did not lead to an application frame update.
Calling this method will also register the corresponding performance statistics with the
FrameStats
instance provided in the constructor.- Returns:
- The number of application frame updates that were performed during the frame synchronization process. A value of zero indicates no frame updates were performed, meaning that it is not necessary for the renderer to render the frame.
-
update
public void update(float deltaTime) Performs an application frame update. The renderer should not call this method. Instead, it should callsyncFrame()
, which will decouple "native" frame updates in the renderer from application frame updates. Attempting to render the application at the renderer's native refresh rate can introduce slowdown if application and/or graphics complexity makes it impossible to actually achieve the native framerate. -
changeScene
Requests to change the active scene after the current frame update has been completed. If another scene had already been requested, calling this method again will overrule that request. -
attach
Attaches a sub-scene to the currently active scene. The sub-scene will remain active until it is detached or the parent scene ends. -
attach
Attaches anUpdatable
to act as a sub-scene for the currently active scene. The sub-scene will remain active until it is detached or the parent scene ends. -
attach
Wraps aRunnable
so that is acts as a sub-scene for the currently active scene. The sub-scene will remain active until it is detached or the parent scene ends. -
attachGlobal
Attaches a scene that is *not* tied to the currently active scene, and will remain active for the rest of the application. Multiple global scenes can be attached. -
getRendererName
Returns the display name for the underlying renderer. The display name will not include the word "renderer". -
getDebugInformation
Returns debug and support information that can be displayed when running a MultimediaLib application in debug mode. The returned list is intended to be displayed in aText
, which can be styled to match the application appearance. -
terminate
public void terminate()Terminates the application. This method will forward to the underlyingRenderer.terminate()
. It is exposed by this class to allow it to be used during frame updates. -
getGraphicsMode
-
getDisplayMode
-
getCanvas
-
getStage
-
getMediaLoader
-
getInput
-
getNetwork
-
getFrameStats
-