Package dev.prozilla.pine.core
Class Application
java.lang.Object
dev.prozilla.pine.core.Application
- All Implemented Interfaces:
Destructible,Initializable,InputHandler,Renderable,Updatable,ApplicationContext,StateProvider<Application,ApplicationState>
public class Application
extends Object
implements Initializable, InputHandler, Updatable, Renderable, Destructible, ApplicationContext, StateProvider<Application,ApplicationState>
2D application using the LWJGL library.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ApplicationManagerprotected final AudioDeviceprotected final Configprotected Scenestatic final ApplicationModestatic final intstatic final Stringstatic GLCapabilitiesThe capabilities of the OpenGL context, ornullif OpenGL has not been initialized yet.protected Inputprotected final LocalStorageprotected final AppLoggerprotected final ApplicationModeprotected final ModManagerprotected final LazyProperty<String> protected final Rendererprotected booleanprotected final StateMachine<Application, ApplicationState> protected final Timerprotected final Trackerprotected final Window -
Constructor Summary
ConstructorsConstructorDescriptionApplication(int width, int height) Creates an application titled "Untitled".Application(String title, int width, int height) Creates an application.Application(String title, int width, int height, Scene scene) Creates an application.Application(String title, int width, int height, Scene scene, int targetFps) Creates an application.Application(String title, int width, int height, Scene scene, int targetFps, ApplicationMode mode) Creates an application. -
Method Summary
Modifier and TypeMethodDescriptionvoidDefers calling a function until the next frame.voiddestroy()Stops the application and cleans up resources.intReturns an integer that is incremented whenever a scene is loaded/unloaded.getInput()getMode()getState()doublegetTime()Returns the current time if the application is still running, or the timestamp of the last frame.getTimer()voidinit()Initializes the application.voidinitPreview(Input input, int width, int height) voidinput(float deltaTime) Handles input for the application.booleanisAnyState(ApplicationState[] states) Checks whether this application is in any of the given states.static booleanChecks if the application is running in developer mode.booleanstatic booleanbooleanisPaused()booleanbooleanChecks whether this application hasn't been stopped yet.booleanbooleanisState(ApplicationState state) Checks whether this application is in a given state.voidLoads the window icons.voidloadScene(int index) voidvoidLoads the next scene.voidpause()Pauses the application.voidLoads the previous scene.voidPrints system information and library versions.static booleanChecks if the application is currently running in developer mode.voidReloads the current scene.voidremoveScene(Scene scene) voidRenders the application.voidstatic voidThrows an exception if OpenGL has not been initialized yet.voidresume()Resumes the application panel.voidrun()Initializes and starts the application and handles exceptions.voidsetApplicationManager(ApplicationManager applicationManager) voidsetDefaultFont(String fontPath) Sets the default font path for text elements.static voidsetDevMode(boolean enabled) voidSets the icons of the application's window.voidstart()Starts the application loop.voidstop()Tells the application to stop after the current frame.voidPauses or resumes the application panel based on the current state.voidUnloads the current scene.voidupdate(float deltaTime) Updates the application.voidupdatePreview(float deltaTime)
-
Field Details
-
glCapabilities
The capabilities of the OpenGL context, ornullif OpenGL has not been initialized yet. -
shouldStop
protected boolean shouldStop -
mode
-
persistentDataPathProperty
-
currentScene
-
config
-
logger
-
timer
-
renderer
-
audioDevice
-
window
-
input
-
tracker
-
modManager
-
stateMachine
-
localStorage
-
applicationManager
-
DEFAULT_TITLE
- See Also:
-
DEFAULT_TARGET_FPS
public static final int DEFAULT_TARGET_FPS- See Also:
-
DEFAULT_MODE
-
-
Constructor Details
-
Application
public Application(int width, int height) Creates an application titled "Untitled".- Parameters:
width- Width of the windowheight- height of the window
-
Application
Creates an application.- Parameters:
title- Title of the applicationwidth- Width of the windowheight- height of the window
-
Application
Creates an application.- Parameters:
title- Title of the applicationwidth- Width of the windowheight- height of the windowscene- Starting scene
-
Application
Creates an application.- Parameters:
title- Title of the applicationwidth- Width of the windowheight- height of the windowscene- Starting scenetargetFps- Amount of frames per second to target
-
Application
public Application(String title, int width, int height, Scene scene, int targetFps, ApplicationMode mode) Creates an application.- Parameters:
title- Title of the applicationwidth- Width of the windowheight- height of the windowscene- Starting scenetargetFps- Amount of frames per second to target
-
-
Method Details
-
run
public void run()Initializes and starts the application and handles exceptions. -
init
Initializes the application.- Specified by:
initin interfaceInitializable- Throws:
RuntimeException
-
initPreview
-
start
public void start()Starts the application loop. Destroys the application after the application loop has been stopped. -
input
public void input(float deltaTime) Handles input for the application.- Specified by:
inputin interfaceInputHandler- Parameters:
deltaTime- Delta time in seconds
-
update
public void update(float deltaTime) Updates the application. -
updatePreview
public void updatePreview(float deltaTime) -
render
Renders the application.- Specified by:
renderin interfaceRenderable
-
renderPreview
public void renderPreview() -
pause
public void pause()Pauses the application. -
resume
public void resume()Resumes the application panel. -
togglePause
public void togglePause()Pauses or resumes the application panel based on the current state. -
stop
public void stop()Tells the application to stop after the current frame. -
destroy
public void destroy()Stops the application and cleans up resources. This should not be called before the application loop ends.- Specified by:
destroyin interfaceDestructible
-
printInfo
public void printInfo()Prints system information and library versions. -
addScene
-
removeScene
-
reloadScene
public void reloadScene()Reloads the current scene. -
nextScene
public void nextScene()Loads the next scene. -
previousScene
public void previousScene()Loads the previous scene. -
loadScene
public void loadScene(int index) -
loadScene
-
unloadScene
public void unloadScene()Unloads the current scene. -
getCurrentScene
-
setApplicationManager
-
isRunning
public boolean isRunning()Checks whether this application hasn't been stopped yet. -
isLoading
public boolean isLoading() -
isPaused
public boolean isPaused() -
getState
- Specified by:
getStatein interfaceStateProvider<Application,ApplicationState> - Returns:
- The state of this application
-
isState
Checks whether this application is in a given state.- Specified by:
isStatein interfaceStateProvider<Application,ApplicationState>
-
isAnyState
Checks whether this application is in any of the given states.- Specified by:
isAnyStatein interfaceStateProvider<Application,ApplicationState>
-
setIcons
Sets the icons of the application's window.- Parameters:
icons- Paths of icons
-
loadIcons
public void loadIcons()Loads the window icons. -
setDefaultFont
Sets the default font path for text elements.- Parameters:
fontPath- Path to the font file
-
getDefaultFont
- Returns:
- The default font of this application.
-
getPersistentDataPath
-
isPreview
public boolean isPreview() -
isStandalone
public boolean isStandalone() -
getMode
-
getContextId
public int getContextId()Returns an integer that is incremented whenever a scene is loaded/unloaded.- Returns:
- The current context ID.
-
defer
Defers calling a function until the next frame.- Parameters:
callback- The function to call in the next frame
-
getInput
- Specified by:
getInputin interfaceApplicationContext
-
getWindow
- Specified by:
getWindowin interfaceApplicationContext
-
getRenderer
- Specified by:
getRendererin interfaceApplicationContext
-
getTimer
- Specified by:
getTimerin interfaceApplicationContext
-
getTracker
- Specified by:
getTrackerin interfaceApplicationContext
-
getConfig
- Specified by:
getConfigin interfaceApplicationContext
-
getModManager
- Specified by:
getModManagerin interfaceApplicationContext
-
getLogger
- Specified by:
getLoggerin interfaceApplicationContext
-
getAudioDevice
- Specified by:
getAudioDevicein interfaceApplicationContext
-
getLocalStorage
- Specified by:
getLocalStoragein interfaceApplicationContext
-
getTime
public double getTime()Returns the current time if the application is still running, or the timestamp of the last frame.This is the time elapsed since GLFW was initialized.
- Returns:
- The current time in seconds.
-
requireOpenGL
Throws an exception if OpenGL has not been initialized yet.- Throws:
IllegalStateException- If OpenGL has not been initialized yet.
-
isOpenGLInitialized
public static boolean isOpenGLInitialized() -
isDevMode
public static boolean isDevMode()Checks if the application is running in developer mode.This method is optimized and will only read the system property once.
- See Also:
-
readDevMode
public static boolean readDevMode()Checks if the application is currently running in developer mode.- Returns:
trueif system propertydev-modeis currently set totrue.
-
setDevMode
public static void setDevMode(boolean enabled)
-