Class ResourcePool

java.lang.Object
dev.prozilla.pine.common.system.resource.ResourcePool

public final class ResourcePool extends Object
Represents a pool that manages resources efficiently, by avoiding loading resources multiple times.
  • Constructor Details

    • ResourcePool

      public ResourcePool()
  • Method Details

    • loadImage

      public static Image loadImage(String path) throws RuntimeException
      Loads an image from the resource pool or file system.
      Parameters:
      path - Path of the image file
      Returns:
      Image
      Throws:
      RuntimeException - If the image file fails to load.
    • removeImage

      public static boolean removeImage(String path)
    • clearImages

      public static void clearImages()
      Clears the image pool.
    • loadTextureInArray

      public static TextureBase loadTextureInArray(String path) throws RuntimeException
      Loads a texture from the resource pool or file system. If the texture has not been pooled yet, it will be loaded into a texture array.
      Parameters:
      path - Path of the texture's image file
      Throws:
      RuntimeException - If the image file fails to load.
      IllegalStateException - If OpenGL hasn't been initialized yet.
    • loadTexture

      public static TextureBase loadTexture(String path) throws RuntimeException
      Loads a texture from the resource pool or file system.
      Parameters:
      path - Path of the texture's image file
      Throws:
      RuntimeException - If the image file fails to load.
      IllegalStateException - If OpenGL hasn't been initialized yet.
    • loadTexture

      public static TextureBase loadTexture(String path, TextureArrayPolicy textureArrayPolicy) throws IllegalStateException, RuntimeException
      Loads a texture from the resource pool or file system.
      Parameters:
      path - Path of the texture's image file
      textureArrayPolicy - Policy that determines when to load the texture into a texture array.
      Throws:
      RuntimeException - If the image file fails to load.
      IllegalStateException - If OpenGL hasn't been initialized yet.
    • removeTexture

      public static boolean removeTexture(String path)
      Removes a texture and its corresponding image from the resource pool.
      Parameters:
      path - Path of the texture.
    • createTextureArray

      public static TextureArray createTextureArray(int width, int height)
      Creates a texture array that can be used to load multiple textures with the same resolution into.
      Parameters:
      width - The width of the textures
      height - The height of the textures
    • removeTextureArray

      public static boolean removeTextureArray(TextureArray textureArray)
      Removes a texture array and all its textures from the resource pool.
      Parameters:
      textureArray - Texture array to remove
    • createTextureArray

      public static TextureArray createTextureArray(int width, int height, int layers)
      Creates a texture array that can be used to load multiple textures with the same resolution into.
      Parameters:
      width - The width of the textures
      height - The height of the textures
      layers - The amount of textures to fit into the texture array
    • clearTextures

      public static void clearTextures()
      Clears the texture pool.
    • clearTextureArrays

      public static void clearTextureArrays()
      Clears the pool of texture arrays.
    • loadFont

      public static Font loadFont(String path)
    • loadFont

      public static Font loadFont(String path, int size)
    • removeFont

      public static boolean removeFont(String path, int size)
    • clearFonts

      public static void clearFonts()
    • loadStyleSheet

      public static StyleSheet loadStyleSheet(String path)
    • removeStyleSheet

      public static boolean removeStyleSheet(String path)
    • clearStyleSheets

      public static void clearStyleSheets()
    • clear

      public static void clear()
      Clears the resource pool.
    • printTextureArrayStats

      public static void printTextureArrayStats(Logger logger)
      Logs the dimensions and layer usage of every texture array in the resource pool.
    • printImageStats

      public static void printImageStats(Logger logger)
      Logs amount of images in the resource pool per resolution.
    • printStats

      public static void printStats(Logger logger)
      Logs the current amounts of different types of resources in the resource pool.
    • getImageCount

      public static int getImageCount()
    • getTextureCount

      public static int getTextureCount()
    • getTextureArrayCount

      public static int getTextureArrayCount()
    • getFontCount

      public static int getFontCount()
    • getStyleSheetCount

      public static int getStyleSheetCount()