Class Application

java.lang.Object
dev.prozilla.pine.core.Application
All Implemented Interfaces:
Destructible, Initializable, InputHandler, Renderable, Updatable, ApplicationContext, StateProvider<Application,ApplicationState>

2D application using the LWJGL library.
  • Field Details

  • Constructor Details

    • Application

      public Application(int width, int height)
      Creates an application titled "Untitled".
      Parameters:
      width - Width of the window
      height - height of the window
    • Application

      public Application(String title, int width, int height)
      Creates an application.
      Parameters:
      title - Title of the application
      width - Width of the window
      height - height of the window
    • Application

      public Application(String title, int width, int height, Scene scene)
      Creates an application.
      Parameters:
      title - Title of the application
      width - Width of the window
      height - height of the window
      scene - Starting scene
    • Application

      public Application(String title, int width, int height, Scene scene, int targetFps)
      Creates an application.
      Parameters:
      title - Title of the application
      width - Width of the window
      height - height of the window
      scene - Starting scene
      targetFps - 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 application
      width - Width of the window
      height - height of the window
      scene - Starting scene
      targetFps - Amount of frames per second to target
  • Method Details

    • run

      public void run()
      Initializes and starts the application and handles exceptions.
    • init

      public void init() throws RuntimeException
      Initializes the application.
      Specified by:
      init in interface Initializable
      Throws:
      RuntimeException
    • initPreview

      public void initPreview(Input input, int width, int height)
    • 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:
      input in interface InputHandler
      Parameters:
      deltaTime - Delta time in seconds
    • update

      public void update(float deltaTime)
      Updates the application.
      Specified by:
      update in interface Updatable
      Parameters:
      deltaTime - Delta time in seconds
    • updatePreview

      public void updatePreview(float deltaTime)
    • render

      public void render(Renderer renderer)
      Renders the application.
      Specified by:
      render in interface Renderable
    • 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:
      destroy in interface Destructible
    • printInfo

      public void printInfo()
      Prints system information and library versions.
    • addScene

      public void addScene(Scene scene)
    • removeScene

      public void removeScene(Scene scene)
    • 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

      public void loadScene(Scene scene)
    • unloadScene

      public void unloadScene()
      Unloads the current scene.
    • getCurrentScene

      public Scene getCurrentScene()
    • setApplicationManager

      public void setApplicationManager(ApplicationManager applicationManager)
    • isRunning

      public boolean isRunning()
      Checks whether this application hasn't been stopped yet.
    • isLoading

      public boolean isLoading()
    • isPaused

      public boolean isPaused()
    • getState

      public ApplicationState getState()
      Specified by:
      getState in interface StateProvider<Application,ApplicationState>
      Returns:
      The state of this application
    • isState

      public boolean isState(ApplicationState state)
      Checks whether this application is in a given state.
      Specified by:
      isState in interface StateProvider<Application,ApplicationState>
    • isAnyState

      public boolean isAnyState(ApplicationState[] states)
      Checks whether this application is in any of the given states.
      Specified by:
      isAnyState in interface StateProvider<Application,ApplicationState>
    • setIcons

      public void setIcons(String... icons)
      Sets the icons of the application's window.
      Parameters:
      icons - Paths of icons
    • loadIcons

      public void loadIcons()
      Loads the window icons.
    • setDefaultFont

      public void setDefaultFont(String fontPath)
      Sets the default font path for text elements.
      Parameters:
      fontPath - Path to the font file
    • getDefaultFont

      public Font getDefaultFont()
      Returns:
      The default font of this application.
    • getPersistentDataPath

      public String getPersistentDataPath()
    • isPreview

      public boolean isPreview()
    • isStandalone

      public boolean isStandalone()
    • getMode

      public ApplicationMode getMode()
    • getContextId

      public int getContextId()
      Returns an integer that is incremented whenever a scene is loaded/unloaded.
      Returns:
      The current context ID.
    • defer

      public Timer.Timeout defer(Callback callback)
      Defers calling a function until the next frame.
      Parameters:
      callback - The function to call in the next frame
    • getInput

      public Input getInput()
      Specified by:
      getInput in interface ApplicationContext
    • getWindow

      public Window getWindow()
      Specified by:
      getWindow in interface ApplicationContext
    • getRenderer

      public Renderer getRenderer()
      Specified by:
      getRenderer in interface ApplicationContext
    • getTimer

      public Timer getTimer()
      Specified by:
      getTimer in interface ApplicationContext
    • getTracker

      public Tracker getTracker()
      Specified by:
      getTracker in interface ApplicationContext
    • getConfig

      public Config getConfig()
      Specified by:
      getConfig in interface ApplicationContext
    • getModManager

      public ModManager getModManager()
      Specified by:
      getModManager in interface ApplicationContext
    • getLogger

      public Logger getLogger()
      Specified by:
      getLogger in interface ApplicationContext
    • getAudioDevice

      public AudioDevice getAudioDevice()
      Specified by:
      getAudioDevice in interface ApplicationContext
    • getLocalStorage

      public LocalStorage getLocalStorage()
      Specified by:
      getLocalStorage in interface ApplicationContext
    • 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

      public static void requireOpenGL() throws IllegalStateException
      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:
      true if system property dev-mode is currently set to true.
    • setDevMode

      public static void setDevMode(boolean enabled)