Package gaiasky.util
Class GlobalResources
- java.lang.Object
-
- gaiasky.util.GlobalResources
-
public class GlobalResources extends java.lang.Object
Holds and initialises resources utilised globally.
-
-
Field Summary
Fields Modifier and Type Field Description static com.badlogic.gdx.graphics.Cursor
emptyCursor
Cursorsstatic ExtSpriteBatch
extSpriteBatch
Sprite batch using int indicesstatic ExtShaderProgram
extSpriteShader
static com.badlogic.gdx.graphics.Cursor
linkCursor
Cursorsstatic com.badlogic.gdx.graphics.Cursor
resizeXCursor
Cursorsstatic com.badlogic.gdx.graphics.Cursor
resizeYCursor
Cursorsstatic com.badlogic.gdx.scenes.scene2d.ui.Skin
skin
The global skinstatic com.badlogic.gdx.graphics.g2d.SpriteBatch
spriteBatch
Global all-purpose sprite batchstatic com.badlogic.gdx.graphics.glutils.ShaderProgram
spriteShader
-
Constructor Summary
Constructors Constructor Description GlobalResources()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float
angle2d(com.badlogic.gdx.math.Vector3 v1, com.badlogic.gdx.math.Vector3 v2)
Gets the angle in degrees between the two vectorsstatic Vector3d
applyRelativisticAberration(Vector3d pos, ICamera cam)
static <T> java.util.List<java.util.List<T>>
combination(java.util.List<T> values, int size)
Generates all combinations of the given size using the elements in values.static java.lang.String[]
combinations(java.lang.String[] values)
Generates all combinations of all sizes of all the strings given in valuesstatic void
copyFile(java.nio.file.Path sourceFile, java.nio.file.Path destFile, boolean ow)
static int
countOccurrences(java.lang.String haystack, char needle)
static void
deleteRecursively(java.nio.file.Path path)
Deletes recursively all non-partial files from the path.static void
doneLoading(com.badlogic.gdx.assets.AssetManager manager)
static Pair<java.lang.Double,java.lang.String>
doubleToDistanceString(double d)
Converts this double to the string representation of a distancestatic Pair<java.lang.Double,java.lang.String>
doubleToVelocityString(double d)
Converts the double to the string representation of a velocity (always in seconds)static boolean
endsWith(java.lang.String s, java.lang.String[] endings)
Returns true if the string ends with any of the endingsstatic boolean
equal(java.lang.String buf, char[] compareTo, boolean ignoreCase)
Compares a given buffer with another buffer.static long
fileCount(java.nio.file.Path dir)
Recursively count files in a directorystatic long
fileCount(java.nio.file.Path dir, java.lang.String[] extensions)
Count files matching a certain ending in a directory, recursivelystatic Pair<java.lang.Float,java.lang.String>
floatToDistanceString(float f)
Converts this float to the string representation of a distancestatic java.lang.String
getGLExtensions()
static java.lang.String
humanReadableByteCount(long bytes, boolean si)
Converts bytes to a human readable formatstatic void
initialize(com.badlogic.gdx.assets.AssetManager manager)
static <T,U>
java.util.Map<U,java.util.List<T>>invertMap(java.util.Map<T,U> map)
Inverts a mapstatic boolean
isAnyInView(Vector3d[] points, float coneAngle, Vector3d dir)
Computes whether any of the given points is visible by a camera with the given direction and the given cone angle.static boolean
isInView(com.badlogic.gdx.math.Vector3 point, double len, float coneAngle, com.badlogic.gdx.math.Vector3 dir)
static boolean
isInView(Vector3d point, double len, float coneAngle, Vector3d dir)
Computes whether a body with the given position is visible by a camera with the given direction and angle.static boolean
isInView(Vector3d point, float coneAngle, Vector3d dir)
Computes whether a body with the given position is visible by a camera with the given direction and angle.static boolean
isNumeric(java.lang.String str)
static com.badlogic.gdx.utils.Array<java.nio.file.Path>
listRec(java.nio.file.Path f, com.badlogic.gdx.utils.Array<java.nio.file.Path> l, java.lang.String... extensions)
Gets all the files with the given extension in the given path f.static com.badlogic.gdx.utils.Array<java.nio.file.Path>
listRec(java.nio.file.Path f, com.badlogic.gdx.utils.Array<java.nio.file.Path> l, java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter)
static java.lang.String
nObjectsToString(long objs)
static int
nthIndexOf(java.lang.String text, char needle, int n)
static java.lang.String[]
parseWhitespaceSeparatedList(java.lang.String str)
Parses the string and creates a string array.static long
size(java.nio.file.Path path)
Attempts to calculate the size of a file or directory.static <K,V extends java.lang.Comparable<? super V>>
java.util.Map<K,V>sortByValue(java.util.Map<K,V> map)
static com.badlogic.gdx.graphics.Pixmap
textureToPixmap(com.badlogic.gdx.graphics.g2d.TextureRegion tex)
Converts a texture to a pixmap by drawing it to a frame buffer and getting the datastatic float[]
toFloatArray(double[] array)
Transforms the given double array into a float array by casting each of its numbersstatic java.lang.String
toString(java.lang.String[] l, java.lang.String quote, java.lang.String separator)
Converts a string array into a string, optionally quoting each entry and with a given separator.static java.lang.String
toWhitespaceSeparatedList(java.lang.String[] l)
Converts the string array into a whitespace-separated string where each element is double quoted.static java.lang.String
unpackAssetPath(java.lang.String tex)
static java.lang.String
unpackAssetPath(java.lang.String path, GlobalConf.SceneConf.GraphicsQuality gq)
static java.lang.String
unpackSkyboxSide(java.lang.String skyboxLoc, java.lang.String side)
static void
updateSkin()
-
-
-
Field Detail
-
spriteShader
public static com.badlogic.gdx.graphics.glutils.ShaderProgram spriteShader
-
spriteBatch
public static com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch
Global all-purpose sprite batch
-
extSpriteShader
public static ExtShaderProgram extSpriteShader
-
extSpriteBatch
public static ExtSpriteBatch extSpriteBatch
Sprite batch using int indices
-
linkCursor
public static com.badlogic.gdx.graphics.Cursor linkCursor
Cursors
-
resizeXCursor
public static com.badlogic.gdx.graphics.Cursor resizeXCursor
Cursors
-
resizeYCursor
public static com.badlogic.gdx.graphics.Cursor resizeYCursor
Cursors
-
emptyCursor
public static com.badlogic.gdx.graphics.Cursor emptyCursor
Cursors
-
skin
public static com.badlogic.gdx.scenes.scene2d.ui.Skin skin
The global skin
-
-
Method Detail
-
initialize
public static void initialize(com.badlogic.gdx.assets.AssetManager manager)
-
updateSkin
public static void updateSkin()
-
doneLoading
public static void doneLoading(com.badlogic.gdx.assets.AssetManager manager)
-
doubleToDistanceString
public static Pair<java.lang.Double,java.lang.String> doubleToDistanceString(double d)
Converts this double to the string representation of a distance- Parameters:
d
- In internal units- Returns:
- An array containing the float number and the string units
-
doubleToVelocityString
public static Pair<java.lang.Double,java.lang.String> doubleToVelocityString(double d)
Converts the double to the string representation of a velocity (always in seconds)- Parameters:
d
- In internal units- Returns:
- Array containing the number and the units
-
floatToDistanceString
public static Pair<java.lang.Float,java.lang.String> floatToDistanceString(float f)
Converts this float to the string representation of a distance- Parameters:
f
- In internal units- Returns:
- An array containing the float number and the string units
-
toFloatArray
public static float[] toFloatArray(double[] array)
Transforms the given double array into a float array by casting each of its numbers- Parameters:
array
- The array of doubles- Returns:
- The array of floats
-
isInView
public static boolean isInView(Vector3d point, float coneAngle, Vector3d dir)
Computes whether a body with the given position is visible by a camera with the given direction and angle. Coordinates are assumed to be in the camera-origin system- Parameters:
point
- The position of the body in the reference system of the camera (i.e. camera is at origin)coneAngle
- The cone angle of the cameradir
- The direction- Returns:
- True if the body is visible
-
isInView
public static boolean isInView(Vector3d point, double len, float coneAngle, Vector3d dir)
Computes whether a body with the given position is visible by a camera with the given direction and angle. Coordinates are assumed to be in the camera-origin system- Parameters:
point
- The position of the body in the reference system of the camera (i.e. camera is at origin)len
- The point lengthconeAngle
- The cone angle of the cameradir
- The direction- Returns:
- True if the body is visible
-
isInView
public static boolean isInView(com.badlogic.gdx.math.Vector3 point, double len, float coneAngle, com.badlogic.gdx.math.Vector3 dir)
-
isAnyInView
public static boolean isAnyInView(Vector3d[] points, float coneAngle, Vector3d dir)
Computes whether any of the given points is visible by a camera with the given direction and the given cone angle. Coordinates are assumed to be in the camera-origin system- Parameters:
points
- The array of points to checkconeAngle
- The cone angle of the camera (field of view)dir
- The direction- Returns:
- True if any of the points is in the camera view cone
-
equal
public static boolean equal(java.lang.String buf, char[] compareTo, boolean ignoreCase)
Compares a given buffer with another buffer.- Parameters:
buf
- Buffer to compare againstcompareTo
- Buffer to compare to (content should be ASCII lowercase if possible)- Returns:
- True if the buffers compare favourably, false otherwise
-
countOccurrences
public static int countOccurrences(java.lang.String haystack, char needle)
-
nthIndexOf
public static int nthIndexOf(java.lang.String text, char needle, int n)
-
listRec
public static com.badlogic.gdx.utils.Array<java.nio.file.Path> listRec(java.nio.file.Path f, com.badlogic.gdx.utils.Array<java.nio.file.Path> l, java.lang.String... extensions)
Gets all the files with the given extension in the given path f.- Parameters:
f
- The directory to get all the filesl
- The list with the resultsextensions
- The allowed extensions- Returns:
- The list l
-
deleteRecursively
public static void deleteRecursively(java.nio.file.Path path) throws java.io.IOException
Deletes recursively all non-partial files from the path.- Parameters:
path
- The path to delete.- Throws:
java.io.IOException
-
copyFile
public static void copyFile(java.nio.file.Path sourceFile, java.nio.file.Path destFile, boolean ow) throws java.io.IOException
- Throws:
java.io.IOException
-
listRec
public static com.badlogic.gdx.utils.Array<java.nio.file.Path> listRec(java.nio.file.Path f, com.badlogic.gdx.utils.Array<java.nio.file.Path> l, java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter)
-
fileCount
public static long fileCount(java.nio.file.Path dir) throws java.io.IOException
Recursively count files in a directory- Parameters:
dir
- The directory- Returns:
- The number of files
- Throws:
java.io.IOException
-
fileCount
public static long fileCount(java.nio.file.Path dir, java.lang.String[] extensions) throws java.io.IOException
Count files matching a certain ending in a directory, recursively- Parameters:
dir
- The directory- Returns:
- The number of files
- Throws:
java.io.IOException
-
endsWith
public static boolean endsWith(java.lang.String s, java.lang.String[] endings)
Returns true if the string ends with any of the endings- Parameters:
s
- The stringendings
- The endings- Returns:
- True if the string ends with any of the endings
-
isNumeric
public static boolean isNumeric(java.lang.String str)
-
sortByValue
public static <K,V extends java.lang.Comparable<? super V>> java.util.Map<K,V> sortByValue(java.util.Map<K,V> map)
-
textureToPixmap
public static com.badlogic.gdx.graphics.Pixmap textureToPixmap(com.badlogic.gdx.graphics.g2d.TextureRegion tex)
Converts a texture to a pixmap by drawing it to a frame buffer and getting the data- Parameters:
tex
- The texture to convert- Returns:
- The resulting pixmap
-
invertMap
public static final <T,U> java.util.Map<U,java.util.List<T>> invertMap(java.util.Map<T,U> map)
Inverts a map- Parameters:
map
- The map to invert- Returns:
- The inverted map
-
angle2d
public static float angle2d(com.badlogic.gdx.math.Vector3 v1, com.badlogic.gdx.math.Vector3 v2)
Gets the angle in degrees between the two vectors
-
applyRelativisticAberration
public static Vector3d applyRelativisticAberration(Vector3d pos, ICamera cam)
-
humanReadableByteCount
public static java.lang.String humanReadableByteCount(long bytes, boolean si)
Converts bytes to a human readable format- Parameters:
bytes
- The bytessi
- Whether to use SI units or binary- Returns:
- The size in a human readable form
-
size
public static long size(java.nio.file.Path path) throws java.io.IOException
Attempts to calculate the size of a file or directory.Since the operation is non-atomic, the returned value may be inaccurate. However, this method is quick and does its best.
- Throws:
java.io.IOException
-
parseWhitespaceSeparatedList
public static java.lang.String[] parseWhitespaceSeparatedList(java.lang.String str)
Parses the string and creates a string array. The string is a list of whitespace-separated tokens, each surrounded by double qutotes '"': str = '"a" "bc" "d" "efghi"'- Parameters:
str
- The string- Returns:
- The resulting array
-
toWhitespaceSeparatedList
public static java.lang.String toWhitespaceSeparatedList(java.lang.String[] l)
Converts the string array into a whitespace-separated string where each element is double quoted.- Parameters:
l
- The string array- Returns:
- The resulting string
-
toString
public static java.lang.String toString(java.lang.String[] l, java.lang.String quote, java.lang.String separator)
Converts a string array into a string, optionally quoting each entry and with a given separator.- Parameters:
l
- The listquote
- The quote string to useseparator
- The separator- Returns:
- The resulting string
-
unpackAssetPath
public static java.lang.String unpackAssetPath(java.lang.String path, GlobalConf.SceneConf.GraphicsQuality gq)
-
unpackAssetPath
public static java.lang.String unpackAssetPath(java.lang.String tex)
-
unpackSkyboxSide
public static java.lang.String unpackSkyboxSide(java.lang.String skyboxLoc, java.lang.String side) throws java.lang.RuntimeException
- Throws:
java.lang.RuntimeException
-
getGLExtensions
public static java.lang.String getGLExtensions()
-
combinations
public static java.lang.String[] combinations(java.lang.String[] values)
Generates all combinations of all sizes of all the strings given in values- Parameters:
values
- The input strings to combine- Returns:
- The combinations
-
combination
public static <T> java.util.List<java.util.List<T>> combination(java.util.List<T> values, int size)
Generates all combinations of the given size using the elements in values.- Type Parameters:
T
- The type- Parameters:
values
- The elements to combinesize
- The size of the combinations- Returns:
- The combinations
-
nObjectsToString
public static java.lang.String nObjectsToString(long objs)
-
-