Package org.xjge.core

Class XJGE

java.lang.Object
org.xjge.core.XJGE

public final class XJGE
extends java.lang.Object
Represents the game engine in its broadest sense and provides a point at which its functionality may be extended to better suit the individual requirements of the implementation.

More specifically this class provides the following features:

  • The ability to change how the screen will be divided during split screen mode.
  • Convenient access to the default shader program used internally by the engine.
  • The ability to provide the engine with supplemental terminal commands and shader programs.
  • Control over which Camera object each viewport will use to display the scene from their perspective.
  • The ability to add and remove UI widgets from viewports.

Before the engines features can be used init() must be called followed by changing whichever settings the implementation needs to before exposing the game window with start().

Since:
2.0.0
See Also:
Hardware, Input, Monitor, Logger, Terminal, Viewport, Window
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.nio.file.Path PWD  
    static java.lang.String VERSION  
  • Method Summary

    Modifier and Type Method Description
    static void addCommand​(java.lang.String name, TerminalCommand command)
    Adds a new user-defined command that can be accessed through the engines Terminal and used to debug the application at runtime.
    static void addGLProgram​(java.lang.String name, GLProgram glProgram)
    Adds a custom GLProgram to an immutable collection which can be accessed through a scenes render() method to draw the various objects and entities within it.
    static void addUIWidget​(int viewportID, java.lang.String name, Widget widget)
    Adds a new Widget to the specified viewport.
    static void changeFramebufferFilter​(int viewportID, boolean useLinearFilter)
    Changes the filter type applied to the framebuffer texture of a viewport.
    static float clampValue​(float minValue, float maxValue, float userValue)
    Restricts an input value from a user to one between the minimum and maximum ranges specified.
    static void clearWidgets​(int viewportID)
    Removes every widget currently attached to the specified viewport.
    static java.lang.String getAssetsFilepath()
    Obtains a user-provided string denoting the location of the sounds, images, .glsl files, and whatever other assets are used by the implementation.
    static double getCursorPosX()
    Obtains the current position of the mouse cursor within the game windows content area.
    static double getCursorPosY()
    Obtains the current position of the mouse cursor within the game windows content area.
    static GLProgram getDefaultGLProgram()
    Provides convenient access to the engines default shader program.
    static int getResolutionX()
    Obtains the width of the engines internal resolution (if one exists).
    static int getResolutionY()
    Obtains the height of the engines internal resolution (if one exists).
    static java.lang.String getScenesFilepath()
    Obtains a user-provided string that tells the engine where to search for implementations of the Scene superclass.
    static Split getScreenSplit()
    Obtains the current split value used to divide the screen.
    static void init​(java.lang.String assetsFilepath, java.lang.String scenesFilepath, org.joml.Vector2i resolution)
    Simplified variant of the main init(java.lang.String,java.lang.String,org.joml.Vector2i,boolean,boolean,boolean,boolean,boolean) method that will initialize the engine using its default configuration.
    static void init​(java.lang.String assetsFilepath, java.lang.String scenesFilepath, org.joml.Vector2i resolution, boolean createOpenGLLog, boolean debugEnabled, boolean restrict4K, boolean retainFullscreen, boolean windowResizable)
    Initializes the engines assets, compiles the default shader programs, and searches for connected peripheral devices.
    static void removeUIWidget​(int viewportID, java.lang.String name)
    Removes a widget from the specified viewports user interface.
    static void setNoclipSpeedFactor​(float factor)
    Sets the speed at which the camera will move while noclip mode is enabled.
    static void setScreenSplit​(Split split)
    Sets the current split value the engine will use to divide the screen during split screen mode.
    static void setViewportCamera​(int viewportID, Camera camera)
    Sets the current camera object a viewport will use.
    static void start()
    Exposes the window to the user and starts running the applications main loop.
    static void usePostProcessShader​(int viewportID, PostProcessShader postProcessShader)
    Applies post-processing effects to the desired viewport by changing which shader program its framebuffer object will use during rendering.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PWD

      public static final java.nio.file.Path PWD
    • VERSION

      public static final java.lang.String VERSION
      See Also:
      Constant Field Values
  • Method Details

    • init

      public static void init​(java.lang.String assetsFilepath, java.lang.String scenesFilepath, org.joml.Vector2i resolution, boolean createOpenGLLog, boolean debugEnabled, boolean restrict4K, boolean retainFullscreen, boolean windowResizable)
      Initializes the engines assets, compiles the default shader programs, and searches for connected peripheral devices. This method must be called once before the engine can be used.

      NOTE: If a resolution is provided the value of windowResizable will be ignored. Additionally, the scenesFilepath should use periods for separators instead of slashes akin to how it appears in your IDEs package explorer. A call to this method might look something like the following:

       init("/dev/theskidster/game/assets/", "dev.theskidster.game.scenes.", null, ...);
       
      Parameters:
      assetsFilepath - the relative filepath to the folder that contains all of the games assets
      scenesFilepath - the relative filepath to the package that contains all of the games scene subclasses
      resolution - the internal resolution the engine will display the game at or null to copy the resolution of the window
      createOpenGLLog - if true, the engine will create a text file containing messages sent by the OpenGL API
      debugEnabled - if true, the engine will provide debugging utilities at runtime
      restrict4K - if true, the engine will not permit the use of video modes whos resolution is greater than 1920x1080
      retainFullscreen - if true, the game window will retain its mode (fullscreen or windowed) between runtime sessions
      windowResizable - if true, the user will be allowed to freely alter the size of the window at runtime
    • init

      public static void init​(java.lang.String assetsFilepath, java.lang.String scenesFilepath, org.joml.Vector2i resolution)
      Simplified variant of the main init(java.lang.String,java.lang.String,org.joml.Vector2i,boolean,boolean,boolean,boolean,boolean) method that will initialize the engine using its default configuration. This method must be called before the engine can be used.
      Parameters:
      assetsFilepath - the relative filepath to the folder that contains all of the games assets
      scenesFilepath - the relative filepath to the package that contains all of the games scene subclasses
      resolution - the internal resolution the engine will display the game at or null to copy the resolution of the window
    • start

      public static void start()
      Exposes the window to the user and starts running the applications main loop.

      NOTE: This should be called after setting the initial scene with Game.setScene(Scene) and supplying whatever additional shader programs and terminal commands the implementation requires.

      See Also:
      Game, Window
    • clampValue

      public static float clampValue​(float minValue, float maxValue, float userValue)
      Restricts an input value from a user to one between the minimum and maximum ranges specified.
      Parameters:
      minValue - the minimum permitted value
      maxValue - the maximum permitted value
      userValue - the value entered by the user
      Returns:
      a value between desired minimum and maximum ranges
    • addGLProgram

      public static void addGLProgram​(java.lang.String name, GLProgram glProgram)
      Adds a custom GLProgram to an immutable collection which can be accessed through a scenes render() method to draw the various objects and entities within it.
      Parameters:
      name - the name that will be used to refer to the program
      glProgram - the object representing the compiled shader program
    • addCommand

      public static void addCommand​(java.lang.String name, TerminalCommand command)
      Adds a new user-defined command that can be accessed through the engines Terminal and used to debug the application at runtime.
      Parameters:
      name - the name the terminal will use to refer to the command
      command - an object used to organize the commands internal logic
    • addUIWidget

      public static final void addUIWidget​(int viewportID, java.lang.String name, Widget widget)
      Adds a new Widget to the specified viewport. Widgets will be rendered in the order of their z-positions with lower numbers denoting a higher priority. For example, a component with a z-position of 0 will be rendered in front of a component with a z-position of 1.
      Parameters:
      viewportID - the ID number of the viewport to add the widget to
      name - the name that will be used to identify and remove the widget later
      widget - the widget object to add
      See Also:
      Viewport
    • removeUIWidget

      public static final void removeUIWidget​(int viewportID, java.lang.String name)
      Removes a widget from the specified viewports user interface.
      Parameters:
      viewportID - the ID number of the viewport to remove the widget from
      name - the name of the widget to remove
      See Also:
      Viewport, Widget
    • clearWidgets

      public static final void clearWidgets​(int viewportID)
      Removes every widget currently attached to the specified viewport.
      Parameters:
      viewportID - the ID number of the viewport that will clear its UI of all widgets
    • usePostProcessShader

      public static final void usePostProcessShader​(int viewportID, PostProcessShader postProcessShader)
      Applies post-processing effects to the desired viewport by changing which shader program its framebuffer object will use during rendering.
      Parameters:
      viewportID - the ID number of the viewport to apply the filter to
      postProcessShader - an object containing the custom shader program to use or null to use the engines default shaders
    • changeFramebufferFilter

      public static final void changeFramebufferFilter​(int viewportID, boolean useLinearFilter)
      Changes the filter type applied to the framebuffer texture of a viewport.
      Parameters:
      viewportID - the ID number of the viewport who's framebuffer texture we want to change
      useLinearFilter - if true, the textures will be filtered without hard edges
    • getResolutionX

      public static int getResolutionX()
      Obtains the width of the engines internal resolution (if one exists).
      Returns:
      the width of the framebuffer texture being rendered
    • getResolutionY

      public static int getResolutionY()
      Obtains the height of the engines internal resolution (if one exists).
      Returns:
      the height of the framebuffer texture being rendered
    • getCursorPosX

      public static final double getCursorPosX()
      Obtains the current position of the mouse cursor within the game windows content area.

      NOTE: If the engine was supplied with a resolution during initialization the value returned by this method will be converted to correspond to the coordinate system of the resolution.

      Returns:
      the current x-coordinate of the mouse cursor
    • getCursorPosY

      public static final double getCursorPosY()
      Obtains the current position of the mouse cursor within the game windows content area.

      NOTE: If the engine was supplied with a resolution during initialization the value returned by this method will be converted to correspond to the coordinate system of the resolution.

      Returns:
      the current y-coordinate of the mouse cursor
    • getScreenSplit

      public static Split getScreenSplit()
      Obtains the current split value used to divide the screen.
      Returns:
      a value indicating how the screen is being divided
    • getAssetsFilepath

      public static java.lang.String getAssetsFilepath()
      Obtains a user-provided string denoting the location of the sounds, images, .glsl files, and whatever other assets are used by the implementation.
      Returns:
      a filepath to the location containing the games assets
    • getScenesFilepath

      public static java.lang.String getScenesFilepath()
      Obtains a user-provided string that tells the engine where to search for implementations of the Scene superclass.
      Returns:
      a filepath to the location containing the games scene subclasses
    • getDefaultGLProgram

      public static GLProgram getDefaultGLProgram()
      Provides convenient access to the engines default shader program.
      Returns:
      a shader program that can be used to render most objects
    • setScreenSplit

      public static final void setScreenSplit​(Split split)
      Sets the current split value the engine will use to divide the screen during split screen mode.
      Parameters:
      split - a value that determines how the screen will be divided. One of:
      NONEHORIZONTAL VERTICAL
      TRISECTQUARTER
    • setViewportCamera

      public static final void setViewportCamera​(int viewportID, Camera camera)
      Sets the current camera object a viewport will use.
      Parameters:
      viewportID - the ID number of the viewport whos camera we want to set
      camera - the camera object being assigned to the viewport
    • setNoclipSpeedFactor

      public static void setNoclipSpeedFactor​(float factor)
      Sets the speed at which the camera will move while noclip mode is enabled. This includes base speed and boost speed.

      More specifically, the factor number provided here will influence the base speed of the camera. That is, lower values will make the camera move slower, whereas higher values will make it move faster. By default the cameras speed factor is 1.

      Parameters:
      factor - the value that will effect the cameras movement speed