public class SparseTextMap extends java.lang.Object implements java.lang.Iterable<SparseTextMap.Entry>
draw(Batch, TextCellFactory, Frustum)
.
Modifier and Type | Class and Description |
---|---|
static class |
SparseTextMap.CharValues |
static class |
SparseTextMap.Entries |
static class |
SparseTextMap.Entry |
static class |
SparseTextMap.FloatValues |
static class |
SparseTextMap.Keys |
Modifier and Type | Field and Description |
---|---|
int |
size |
Constructor and Description |
---|
SparseTextMap()
Creates a new map with an initial capacity of 192 and a load factor of 0.75.
|
SparseTextMap(int initialCapacity)
Creates a new map with a load factor of 0.75.
|
SparseTextMap(int initialCapacity,
float loadFactor)
Creates a new map with the specified initial capacity and load factor.
|
SparseTextMap(SparseTextMap map)
Creates a new map identical to the specified map.
|
Modifier and Type | Method and Description |
---|---|
SparseTextMap.CharValues |
charValues()
Returns an iterator for the values in the map.
|
void |
clear() |
void |
clear(int maximumCapacity)
Clears the map and reduces the size of the backing arrays to be the specified capacity if they are larger.
|
boolean |
containsCharValue(char value)
Returns true if the specified char value is in the map.
|
boolean |
containsFloatValue(float value)
Returns true if the specified char value is in the map.
|
boolean |
containsKey(int key) |
static int |
decodeX(int encoded)
Decodes a packed position and gets the x component from it, if it was produced by
encodePosition(int, int) or place(int, int, char, float) . |
static int |
decodeY(int encoded)
Decodes a packed position and gets the y component from it, if it was produced by
encodePosition(int, int) or place(int, int, char, float) . |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
TextCellFactory textFactory)
Draws the contents of this SparseTextMap, using the keys as x,y pairs as they would be entered by calling
place(int, int, char, float) and drawing the associated char at that x,y position. |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
TextCellFactory textFactory,
float screenOffsetX,
float screenOffsetY)
Draws the contents of this SparseTextMap, using the keys as x,y pairs as they would be entered by calling
place(int, int, char, float) and drawing the associated char at that x,y position, potentially with an
offset on x and/or y. |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
TextCellFactory textFactory,
com.badlogic.gdx.math.Frustum frustum)
Draws the contents of this SparseTextMap, using the keys as x,y pairs as they would be entered by calling
place(int, int, char, float) and drawing the associated char at that x,y position. |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
TextCellFactory textFactory,
com.badlogic.gdx.math.Frustum frustum,
float screenOffsetX,
float screenOffsetY)
Draws the contents of this SparseTextMap, using the keys as x,y pairs as they would be entered by calling
place(int, int, char, float) and drawing the associated char at that x,y position, potentially with an
offset on x and/or y. |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
TextCellFactory textFactory,
com.badlogic.gdx.math.Frustum frustum,
float screenOffsetX,
float screenOffsetY,
char replacement)
Draws the contents of this SparseTextMap, using the keys as x,y pairs as they would be entered by calling
place(int, int, char, float) and drawing the char replacement at that x,y position, potentially with an
offset on x and/or y. |
static int |
encodePosition(int x,
int y)
Packs the given x,y position into one int in the type that is used elsewhere in this class.
|
void |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items.
|
SparseTextMap.Entries |
entries()
Returns an iterator for the entries in the map.
|
boolean |
equals(java.lang.Object obj) |
int |
findKey(char value,
int notFound)
Returns the key for the specified char value, or notFound if it is not in the map.
|
int |
findKey(float value,
int notFound)
Returns the key for the specified float value, or notFound if it is not in the map.
|
SparseTextMap.FloatValues |
floatValues()
Returns an iterator for the values in the map.
|
char |
getChar(int key,
char defaultValue) |
char |
getChar(int x,
int y,
char defaultValue) |
float |
getFloat(int key,
float defaultValue) |
float |
getFloat(int x,
int y,
float defaultValue) |
int |
hashCode() |
java.util.Iterator<SparseTextMap.Entry> |
iterator() |
SparseTextMap.Keys |
keys()
Returns an iterator for the keys in the map.
|
int |
place(int x,
int y,
char charValue,
com.badlogic.gdx.graphics.Color color)
Places a char in the given libGDX Color at the requested x, y position in grid cells, where x and y must each be
between 0 and 65535, both inclusive.
|
int |
place(int x,
int y,
char charValue,
float encodedColor)
Places a char in the given encoded color at the requested x, y position in grid cells, where x and y must each be
between 0 and 65535, both inclusive, and the encoded color is one produced by
Color.toFloatBits() or any
of several methods in SColor , such as SColor.floatGetI(int, int, int) ,
SColor.floatGetHSV(float, float, float, float) , or SColor.lerpFloatColors(float, float, float) . |
void |
put(int key,
char charValue,
float floatValue) |
void |
putAll(SparseTextMap map) |
void |
remove(int key) |
char |
remove(int key,
char defaultValue) |
void |
shrink(int maximumCapacity)
Reduces the size of the backing arrays to be the specified capacity or less.
|
java.lang.String |
toString() |
void |
updateChar(int key,
char charValue)
If and only if key is already present, this changes the char associated with it while leaving the float the same.
|
void |
updateFloat(int key,
float floatValue)
If and only if key is already present, this changes the float associated with it while leaving the char the same.
|
public SparseTextMap()
public SparseTextMap(int initialCapacity)
initialCapacity
- If not a power of two, it is increased to the next nearest power of two.public SparseTextMap(int initialCapacity, float loadFactor)
initialCapacity
- If not a power of two, it is increased to the next nearest power of two.public SparseTextMap(SparseTextMap map)
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, TextCellFactory textFactory)
place(int, int, char, float)
and drawing the associated char at that x,y position. Uses a
Frustum
object, usually obtained from the current Camera with
Camera.frustum
, to cull anything that would be drawn out of view. Treats the
float value as a color for the char, using the encoding for colors as floats that Color.toFloatBits()
uses. Relies on the sizing information from the given TextCellFactory (its
TextCellFactory.actualCellWidth
and TextCellFactory.actualCellHeight
, which may differ from its
width and height if either of TextCellFactory.tweakWidth(float)
or
TextCellFactory.tweakHeight(float)
were called). It also, of course, uses the TextCellFactory to
determine what its text will look like (font, size, and so on). The TextCellFactory must have been initialized,
probably with TextCellFactory.initBySize()
after setting the width and height as desired. This method
should be called between batch.begin()
and batch.end()
with the Batch passed to this.batch
- the FilterBatch
or other Batch used to draw this; should have already have had begin() calledtextFactory
- used to determine the font, size, cell size, and other information; must be initializedpublic void draw(com.badlogic.gdx.graphics.g2d.Batch batch, TextCellFactory textFactory, float screenOffsetX, float screenOffsetY)
place(int, int, char, float)
and drawing the associated char at that x,y position, potentially with an
offset on x and/or y. Uses a Frustum
object, usually obtained from the current Camera with
Camera.frustum
, to cull anything that would be drawn out of view. Treats the
float value as a color for the char, using the encoding for colors as floats that Color.toFloatBits()
uses. Relies on the sizing information from the given TextCellFactory (its
TextCellFactory.actualCellWidth
and TextCellFactory.actualCellHeight
, which may differ from its
width and height if either of TextCellFactory.tweakWidth(float)
or
TextCellFactory.tweakHeight(float)
were called). It also, of course, uses the TextCellFactory to
determine what its text will look like (font, size, and so on). The TextCellFactory must have been initialized,
probably with TextCellFactory.initBySize()
after setting the width and height as desired. This method
should be called between batch.begin()
and batch.end()
with the Batch passed to this.batch
- the FilterBatch
or other Batch used to draw this; should have already have had begin() calledtextFactory
- used to determine the font, size, cell size, and other information; must be initializedscreenOffsetX
- offset to apply to the x position of each char rendered; positive moves chars rightscreenOffsetY
- offset to apply to the y position of each char rendered; positive moves chars uppublic void draw(com.badlogic.gdx.graphics.g2d.Batch batch, TextCellFactory textFactory, com.badlogic.gdx.math.Frustum frustum)
place(int, int, char, float)
and drawing the associated char at that x,y position. Uses a
Frustum
object, usually obtained from the current Camera with
Camera.frustum
, to cull anything that would be drawn out of view. Treats the
float value as a color for the char, using the encoding for colors as floats that Color.toFloatBits()
uses. Relies on the sizing information from the given TextCellFactory (its
TextCellFactory.actualCellWidth
and TextCellFactory.actualCellHeight
, which may differ from its
width and height if either of TextCellFactory.tweakWidth(float)
or
TextCellFactory.tweakHeight(float)
were called). It also, of course, uses the TextCellFactory to
determine what its text will look like (font, size, and so on). The TextCellFactory must have been initialized,
probably with TextCellFactory.initBySize()
after setting the width and height as desired. This method
should be called between batch.begin()
and batch.end()
with the Batch passed to this.batch
- the FilterBatch
or other Batch used to draw this; should have already have had begin() calledtextFactory
- used to determine the font, size, cell size, and other information; must be initializedfrustum
- a Frustum
object to determine culling, almost always obtained from Camera.frustum
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, TextCellFactory textFactory, com.badlogic.gdx.math.Frustum frustum, float screenOffsetX, float screenOffsetY)
place(int, int, char, float)
and drawing the associated char at that x,y position, potentially with an
offset on x and/or y. Uses a Frustum
object, usually obtained from the current Camera with
Camera.frustum
, to cull anything that would be drawn out of view. Treats the
float value as a color for the char, using the encoding for colors as floats that Color.toFloatBits()
uses. Relies on the sizing information from the given TextCellFactory (its
TextCellFactory.actualCellWidth
and TextCellFactory.actualCellHeight
, which may differ from its
width and height if either of TextCellFactory.tweakWidth(float)
or
TextCellFactory.tweakHeight(float)
were called). It also, of course, uses the TextCellFactory to
determine what its text will look like (font, size, and so on). The TextCellFactory must have been initialized,
probably with TextCellFactory.initBySize()
after setting the width and height as desired. This method
should be called between batch.begin()
and batch.end()
with the Batch passed to this.batch
- the FilterBatch
or other Batch used to draw this; should have already have had begin() calledtextFactory
- used to determine the font, size, cell size, and other information; must be initializedfrustum
- a Frustum
object to determine culling, almost always obtained from Camera.frustum
screenOffsetX
- offset to apply to the x position of each char rendered; positive moves chars rightscreenOffsetY
- offset to apply to the y position of each char rendered; positive moves chars uppublic void draw(com.badlogic.gdx.graphics.g2d.Batch batch, TextCellFactory textFactory, com.badlogic.gdx.math.Frustum frustum, float screenOffsetX, float screenOffsetY, char replacement)
place(int, int, char, float)
and drawing the char replacement at that x,y position, potentially with an
offset on x and/or y. Uses a Frustum
object, usually obtained from the current Camera with
Camera.frustum
, to cull anything that would be drawn out of view. Treats the
float value as a color for replacement, using the encoding for colors as floats that Color.toFloatBits()
uses. Relies on the sizing information from the given TextCellFactory (its
TextCellFactory.actualCellWidth
and TextCellFactory.actualCellHeight
, which may differ from its
width and height if either of TextCellFactory.tweakWidth(float)
or
TextCellFactory.tweakHeight(float)
were called). It also, of course, uses the TextCellFactory to
determine what its text will look like (font, size, and so on). The TextCellFactory must have been initialized,
probably with TextCellFactory.initBySize()
after setting the width and height as desired. This method
should be called between batch.begin()
and batch.end()
with the Batch passed to this.batch
- the FilterBatch
or other Batch used to draw this; should have already have had begin() calledtextFactory
- used to determine the font, size, cell size, and other information; must be initializedfrustum
- a Frustum
object to determine culling, almost always obtained from Camera.frustum
screenOffsetX
- offset to apply to the x position of each char rendered; positive moves chars rightscreenOffsetY
- offset to apply to the y position of each char rendered; positive moves chars upreplacement
- a char that will be used in place of the normal char values stored in this; often the char
with Unicode value 0, which renders as a solid block.public static int encodePosition(int x, int y)
x
- the x component to encode; this must be between 0 and 65535, both inclusivey
- the y component to encode; this must be between 0 and 65535, both inclusivepublic static int decodeX(int encoded)
encodePosition(int, int)
or place(int, int, char, float)
.encoded
- a packed position that holds x and y componentspublic static int decodeY(int encoded)
encodePosition(int, int)
or place(int, int, char, float)
.encoded
- a packed position that holds x and y componentspublic int place(int x, int y, char charValue, com.badlogic.gdx.graphics.Color color)
x
- the x position of the colorful char; this must be between 0 and 65535, both inclusivey
- the y position of the colorful char; this must be between 0 and 65535, both inclusivecharValue
- the char to put into the SparseTextMapcolor
- the libGDX Color or SColor to use for the charpublic int place(int x, int y, char charValue, float encodedColor)
Color.toFloatBits()
or any
of several methods in SColor
, such as SColor.floatGetI(int, int, int)
,
SColor.floatGetHSV(float, float, float, float)
, or SColor.lerpFloatColors(float, float, float)
.
Returns the int code that can be used to locate the x,y pair as a key in this SparseTextMap.x
- the x position of the colorful char; this must be between 0 and 65535, both inclusivey
- the y position of the colorful char; this must be between 0 and 65535, both inclusivecharValue
- the char to put into the SparseTextMapencodedColor
- the encoded color to use for the char, as produced by Color.toFloatBits()
public void put(int key, char charValue, float floatValue)
public void updateFloat(int key, float floatValue)
key
- the encoded key as produced by encodePosition(int, int)
floatValue
- the float value to set at the given encoded keypublic void updateChar(int key, char charValue)
key
- the encoded key as produced by encodePosition(int, int)
charValue
- the char value to set at the given encoded keypublic void putAll(SparseTextMap map)
public char getChar(int x, int y, char defaultValue)
x
- the x-component of the position to look upy
- the y-component of the position to look updefaultValue
- Returned if the key was not associated with a value.public char getChar(int key, char defaultValue)
key
- the encoded key as produced by encodePosition(int, int)
defaultValue
- Returned if the key was not associated with a value.public float getFloat(int x, int y, float defaultValue)
x
- the x-component of the position to look upy
- the y-component of the position to look updefaultValue
- Returned if the key was not associated with a value.public float getFloat(int key, float defaultValue)
key
- the encoded key as produced by encodePosition(int, int)
defaultValue
- Returned if the key was not associated with a value.public void remove(int key)
public char remove(int key, char defaultValue)
public void shrink(int maximumCapacity)
public void clear(int maximumCapacity)
public void clear()
public boolean containsCharValue(char value)
public boolean containsFloatValue(float value)
public boolean containsKey(int key)
public int findKey(char value, int notFound)
public int findKey(float value, int notFound)
public void ensureCapacity(int additionalCapacity)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Iterator<SparseTextMap.Entry> iterator()
iterator
in interface java.lang.Iterable<SparseTextMap.Entry>
public SparseTextMap.Entries entries()
SparseTextMap.Entries
constructor for nested or multithreaded iteration.public SparseTextMap.CharValues charValues()
SparseTextMap.Entries
constructor for nested or multithreaded iteration.public SparseTextMap.FloatValues floatValues()
SparseTextMap.Entries
constructor for nested or multithreaded iteration.public SparseTextMap.Keys keys()
SparseTextMap.Entries
constructor for nested or multithreaded iteration.Copyright © Eben Howard 2012–2022. All rights reserved.