Class ResourcePool
java.lang.Object
dev.prozilla.pine.common.system.resource.ResourcePool
Represents a pool that manages resources efficiently,
by avoiding loading resources multiple times.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
clear()
Clears the resource pool.static void
static void
Clears the image pool.static void
static void
Clears the pool of texture arrays.static void
Clears the texture pool.static TextureArray
createTextureArray
(int width, int height) Creates a texture array that can be used to load multiple textures with the same resolution into.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.static int
static int
static int
static int
static int
static Font
static Font
static Image
Loads an image from the resource pool or file system.static StyleSheet
loadStyleSheet
(String path) static TextureBase
loadTexture
(String path) Loads a texture from the resource pool or file system.static TextureBase
loadTexture
(String path, TextureArrayPolicy textureArrayPolicy) Loads a texture from the resource pool or file system.static TextureBase
loadTextureInArray
(String path) Loads a texture from the resource pool or file system.static void
printImageStats
(Logger logger) Logs amount of images in the resource pool per resolution.static void
printStats
(Logger logger) Logs the current amounts of different types of resources in the resource pool.static void
printTextureArrayStats
(Logger logger) Logs the dimensions and layer usage of every texture array in the resource pool.static boolean
removeFont
(String path, int size) static boolean
removeImage
(String path) static boolean
removeStyleSheet
(String path) static boolean
removeTexture
(String path) Removes a texture and its corresponding image from the resource pool.static boolean
removeTextureArray
(TextureArray textureArray) Removes a texture array and all its textures from the resource pool.
-
Constructor Details
-
ResourcePool
public ResourcePool()
-
-
Method Details
-
loadImage
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
-
clearImages
public static void clearImages()Clears the image pool. -
loadTextureInArray
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
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 filetextureArrayPolicy
- 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
Removes a texture and its corresponding image from the resource pool.- Parameters:
path
- Path of the texture.
-
createTextureArray
Creates a texture array that can be used to load multiple textures with the same resolution into.- Parameters:
width
- The width of the texturesheight
- The height of the textures
-
removeTextureArray
Removes a texture array and all its textures from the resource pool.- Parameters:
textureArray
- Texture array to remove
-
createTextureArray
Creates a texture array that can be used to load multiple textures with the same resolution into.- Parameters:
width
- The width of the texturesheight
- The height of the textureslayers
- 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
-
loadFont
-
removeFont
-
clearFonts
public static void clearFonts() -
loadStyleSheet
-
removeStyleSheet
-
clearStyleSheets
public static void clearStyleSheets() -
clear
public static void clear()Clears the resource pool. -
printTextureArrayStats
Logs the dimensions and layer usage of every texture array in the resource pool. -
printImageStats
Logs amount of images in the resource pool per resolution. -
printStats
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()
-