Class Application

java.lang.Object
dev.prozilla.pine.core.Application
All Implemented Interfaces:
Lifecycle, ApplicationContext, StateProvider<Application,ApplicationState>

public class Application extends Object implements Lifecycle, ApplicationContext, StateProvider<Application,ApplicationState>
2D application using the LWJGL library.
  • Field Details

    • initializedOpenGL

      public static boolean initializedOpenGL
      True if OpenGL has been initialized
    • shouldStop

      protected boolean shouldStop
    • isPreview

      protected boolean isPreview
    • currentScene

      protected Scene currentScene
    • config

      protected final Config config
    • logger

      protected final AppLogger logger
    • timer

      protected final ApplicationTimer timer
    • renderer

      protected final Renderer renderer
    • window

      protected final Window window
    • input

      protected Input input
    • tracker

      protected final Tracker tracker
    • modManager

      protected final ModManager modManager
    • stateMachine

      protected final StateMachine<Application,ApplicationState> stateMachine
    • applicationManager

      protected ApplicationManager applicationManager
    • DEFAULT_TITLE

      public static final String DEFAULT_TITLE
      See Also:
    • DEFAULT_TARGET_FPS

      public static final int DEFAULT_TARGET_FPS
      See Also:
  • Constructor Details

    • Application

      public Application(int width, int height)
      Creates an application titled "Application".
      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
  • 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 Lifecycle
      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.
      Specified by:
      start in interface Lifecycle
    • input

      public void input(float deltaTime)
      Handles input for the application.
      Specified by:
      input in interface Lifecycle
      Parameters:
      deltaTime - Delta time in seconds
    • update

      public void update(float deltaTime)
      Updates the application.
      Specified by:
      update in interface Lifecycle
      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 Lifecycle
      Parameters:
      renderer - Reference to the renderer
    • 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 Lifecycle
    • printVersions

      public static void printVersions()
      Logs versions of libraries to the console
    • addScene

      public int addScene(Scene scene)
      Adds a scene and returns its ID.
      Parameters:
      scene - Scene
      Returns:
      Scene ID
    • reloadScene

      public void reloadScene()
      Reloads the current scene.
    • loadScene

      public void loadScene(Scene scene)
      Loads a scene by reference.
      Parameters:
      scene - Reference to the scene
    • nextScene

      public void nextScene()
      Loads the next scene.
    • previousScene

      public void previousScene()
      Loads the previous scene.
    • loadScene

      public void loadScene(int id)
      Loads a scene by ID.
      Parameters:
      id - Scene ID
    • 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.
    • resize

      public void resize()
      Resizes the application window.
    • isPreview

      public boolean isPreview()
    • isStandalone

      public boolean isStandalone()
    • 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 ApplicationTimer 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
    • requireOpenGL

      public static void requireOpenGL() throws IllegalStateException
      Throws:
      IllegalStateException - If OpenGL has not been initialized yet.