Class RenderCell
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.Renderable
-
- com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
-
- com.bombinggames.wurfelengine.core.map.rendering.RenderCell
-
- Direct Known Subclasses:
AnimatedBlock
public class RenderCell extends AbstractGameObject
Something which can be rendered and therefore saves render information shared across cameras. A RenderCell should not use the event system. The class extends/wraps the plain data of the block with a position andAbstractGameObject
class methods. The wrapped cell is not referenced.
The block id in teh map can have different id then used for rendering. The rendering sprite id's are set in the constructor or later manualy.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RenderCell.Channel
-
Field Summary
Fields Modifier and Type Field Description static int
GAME_DIAGLENGTH
The game space dimension size's aequivalent to VIEW_DEPTH or VIEW_WIDTH.static int
GAME_DIAGLENGTH2
Half (1/2) of GAME_DIAGLENGTH.static int
GAME_EDGELENGTH
Pixels per game spaces meter (edge length).
1 game meter ^= 1 GAME_EDGELENGTHstatic int
GAME_EDGELENGTH2
Half (1/2) of GAME_EDGELENGTH.static int
OBJECTTYPESNUM
the max. amount of different object typesstatic float
PROJECTIONFACTORY
The factor by what the Y axis is distorted when game to view projection is applied.static float
PROJECTIONFACTORZ
The factor by what the Z axis is distorted when game to view projection is applied.static int
VALUESNUM
the max. amount of different valuesstatic int
VIEW_DEPTH
Screen depth of a block/object sprite in pixels.static int
VIEW_DEPTH2
The half (1/2) of VIEW_DEPTH.static int
VIEW_DEPTH4
A quarter (1/4) of VIEW_DEPTH.static int
VIEW_HEIGHT
The height (y-axis) of the sprite size.static int
VIEW_HEIGHT2
The half (1/2) of VIEW_HEIGHT.static int
VIEW_HEIGHT4
A quarter (1/4) of VIEW_HEIGHT.static int
VIEW_WIDTH
The width (x-axis) of the sprite size.static int
VIEW_WIDTH2
The half (1/2) of VIEW_WIDTH.static int
VIEW_WIDTH4
A quarter (1/4) of VIEW_WIDTH.-
Fields inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
sprite
-
-
Constructor Summary
Constructors Constructor Description RenderCell(byte id)
For direct creation.RenderCell(byte id, byte value)
For direct creation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLightlevel(float lightlevel, Side side, RenderCell.Channel channel, byte vertex)
int
getAOFlags()
byte 0: left side, byte 1: top side, byte 2: right side.
In each byte bit order:
7 \ 0 / 1
-------
6 | - | 2
-------
5 / 4 \ 3static com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion
getBlockSprite(byte id, byte value, Side side)
Returns a sprite sprite of a specific side of the blockstatic com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion[][][]
getBlocksprites()
byte
getClipping()
a block is only clipped if every side is clippedCoordinate
getCoord()
not copy saveint
getDimensionZ()
The height of the object for depth sorting.byte
getHealth()
get the health byte from the map.static byte
getHealth(int block)
The health is stored in a byte in the range [0;100]byte
getId()
game logic value.float
getLightlevel(Side side, byte vertex, RenderCell.Channel channel)
float
getLightlevelB()
How bright is the object?float
getLightlevelG()
How bright is the object?float
getLightlevelR()
How bright is the object?java.lang.String
getName()
Returns the name of the objectstatic java.lang.String
getName(byte id, byte value)
get the name of a combination of id and valuePoint
getPoint()
Can be internal reference or shared object.Coordinate
getPosition()
Return the coordinates of the object in the game world.static com.badlogic.gdx.graphics.Color
getRepresentingColor(byte id, byte value)
Returns a color representing the block.char
getSpriteCategory()
Get the category letter for accessing sprites.byte
getSpriteId()
the id of the sprite using for rendering.
By default is the same as the block id but in some cases some objects share one sprite so they can have the same id.byte
getSpriteValue()
Get the value.TopoGraphNode
getTopoNode()
byte
getValue()
game logic value.boolean
hasSides()
Is the block a true block with three sides or does it get rendered by a single sprite?boolean
hidingPastBlock()
boolean
isFullyClipped()
a block is only clipped if every side is clippedboolean
isIndestructible()
boolean
isLiquid()
static boolean
isLiquid(int block)
Check if the block is liquid.boolean
isObstacle()
static boolean
isSpriteDefined(byte spriteId, byte spriteValue)
checks if a sprite is defined. if not the error sprite will be renderedboolean
isTransparent()
Can light travel through object?static boolean
isTransparent(int spriteIdValue)
static RenderCell
newInstance(byte id, byte value)
creates a new RenderCell instance based on the datavoid
render(GameView view)
Draws an object if it is not hidden and not clipped.void
render(GameView view, int xPos, int yPos)
Render the whole block at a custom position.void
render(GameView view, int xPos, int yPos, boolean staticShade)
Renders the whole block at a custom position.void
renderSide(GameView view, int xPos, int yPos, Side side, com.badlogic.gdx.graphics.Color color)
uses heap, projection spacevoid
renderSide(GameView view, Side side, boolean staticShade)
Render a side of a block at the position of the internal coordinates.void
renderSide(GameView view, Point pos, Side side, com.badlogic.gdx.graphics.Color color)
Draws a side of a cell at a custom position.void
resetLight()
sets the light to 1void
setAOFlagFalse(int side)
Set flags for the ambient occlusion algorithm to falsevoid
setAoFlags(int aoFlags)
Set all flags at oncevoid
setAOFlagTrue(int side)
Set flags for the ambient occlusion algorithm to truevoid
setClippedLeft()
void
setClippedRight()
void
setClippedTop()
void
setLightlevel(float lightlevel)
Stores the lightlevel factor for the whole cell and thereby overriding values for each side.void
setLightlevel(float lightlevel, Side side)
void
setLightlevel(float lightlevel, Side side, byte vertex)
void
setLightlevel(float lightlevel, Side side, RenderCell.Channel channel, byte vertex)
void
setPosition(Coordinate coord)
keeps referencevoid
setPosition(Position pos)
Set the coordinates without safety check.static void
setStaticShade(boolean shade)
Indicate whether the blocks should get shaded independent of the light engine by default.void
setUnclipped()
Makes every side visiblevoid
setValue(byte value)
It is advised to only change this value if the data stored in the map also changes.boolean
shouldBeRendered(Camera camera)
Gives information if object should be rendered.RenderCell
spawn(RenderStorage rS, Coordinate coord)
places the object on the map.static void
staticDispose()
dipsose the static fieldsjava.lang.String
toString()
void
update(float dt)
Update the block.void
updateSpriteCache()
Updates the saved vertex data with the engine default configuration (category, sprite id and sprite value).-
Methods inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
getColor, getDepth, getPixmap, getRotation, getScaling, getSprite, getSprite, getSpritesheet, getSpritesheetPath, getTextureDiffuse, getTextureNormal, isHidden, loadSheet, setColor, setCustomSpritesheet, setHidden, setRotation, setScaling
-
-
-
-
Field Detail
-
VIEW_DEPTH
public static final transient int VIEW_DEPTH
Screen depth of a block/object sprite in pixels. This is the length from the top to the middle border of the block.- See Also:
- Constant Field Values
-
VIEW_DEPTH2
public static final transient int VIEW_DEPTH2
The half (1/2) of VIEW_DEPTH. The short form of: VIEW_DEPTH/2- See Also:
- Constant Field Values
-
VIEW_DEPTH4
public static final transient int VIEW_DEPTH4
A quarter (1/4) of VIEW_DEPTH. The short form of: VIEW_DEPTH/4- See Also:
- Constant Field Values
-
VIEW_WIDTH
public static final transient int VIEW_WIDTH
The width (x-axis) of the sprite size.- See Also:
- Constant Field Values
-
VIEW_WIDTH2
public static final transient int VIEW_WIDTH2
The half (1/2) of VIEW_WIDTH. The short form of: VIEW_WIDTH/2- See Also:
- Constant Field Values
-
VIEW_WIDTH4
public static final transient int VIEW_WIDTH4
A quarter (1/4) of VIEW_WIDTH. The short form of: VIEW_WIDTH/4- See Also:
- Constant Field Values
-
VIEW_HEIGHT
public static final transient int VIEW_HEIGHT
The height (y-axis) of the sprite size.- See Also:
- Constant Field Values
-
VIEW_HEIGHT2
public static final transient int VIEW_HEIGHT2
The half (1/2) of VIEW_HEIGHT. The short form of: VIEW_WIDTH/2- See Also:
- Constant Field Values
-
VIEW_HEIGHT4
public static final transient int VIEW_HEIGHT4
A quarter (1/4) of VIEW_HEIGHT. The short form of: VIEW_WIDTH/4- See Also:
- Constant Field Values
-
GAME_DIAGLENGTH
public static final transient int GAME_DIAGLENGTH
The game space dimension size's aequivalent to VIEW_DEPTH or VIEW_WIDTH. Because the x axis is not shortened those two are equal.- See Also:
- Constant Field Values
-
GAME_DIAGLENGTH2
public static final transient int GAME_DIAGLENGTH2
Half (1/2) of GAME_DIAGLENGTH.- See Also:
- Constant Field Values
-
GAME_EDGELENGTH
public static final transient int GAME_EDGELENGTH
Pixels per game spaces meter (edge length).
1 game meter ^= 1 GAME_EDGELENGTH- See Also:
- Constant Field Values
-
GAME_EDGELENGTH2
public static final transient int GAME_EDGELENGTH2
Half (1/2) of GAME_EDGELENGTH.- See Also:
- Constant Field Values
-
PROJECTIONFACTORZ
public static final transient float PROJECTIONFACTORZ
The factor by what the Z axis is distorted when game to view projection is applied. Usually not 1 because of the angle of projection.- See Also:
- Constant Field Values
-
PROJECTIONFACTORY
public static final transient float PROJECTIONFACTORY
The factor by what the Y axis is distorted when game to view projection is applied. Usually not 1 because of the angle of projection.- See Also:
- Constant Field Values
-
OBJECTTYPESNUM
public static final transient int OBJECTTYPESNUM
the max. amount of different object types- See Also:
- Constant Field Values
-
VALUESNUM
public static final transient int VALUESNUM
the max. amount of different values- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RenderCell
public RenderCell(byte id)
For direct creation. You should use the factory method instead.- Parameters:
id
-- See Also:
newInstance(byte, byte)
-
RenderCell
public RenderCell(byte id, byte value)
For direct creation. You should use the factory method instead.- Parameters:
id
-value
-- See Also:
newInstance(byte, byte)
-
-
Method Detail
-
getHealth
public static byte getHealth(int block)
The health is stored in a byte in the range [0;100]- Parameters:
block
-- Returns:
-
newInstance
public static RenderCell newInstance(byte id, byte value)
creates a new RenderCell instance based on the data- Parameters:
id
-value
-- Returns:
-
isTransparent
public static boolean isTransparent(int spriteIdValue)
- Parameters:
spriteIdValue
- id and value in one int- Returns:
-
isLiquid
public static boolean isLiquid(int block)
Check if the block is liquid.- Parameters:
block
- first byte id, second value, third health- Returns:
- true if liquid, false if not
-
getName
public static java.lang.String getName(byte id, byte value)
get the name of a combination of id and value- Parameters:
id
-value
-- Returns:
-
setStaticShade
public static void setStaticShade(boolean shade)
Indicate whether the blocks should get shaded independent of the light engine by default.- Parameters:
shade
-
-
getBlockSprite
public static com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion getBlockSprite(byte id, byte value, Side side)
Returns a sprite sprite of a specific side of the block- Parameters:
id
- the id of the blockvalue
- the value of teh blockside
- Which side?- Returns:
- an sprite of the side
-
isSpriteDefined
public static boolean isSpriteDefined(byte spriteId, byte spriteValue)
checks if a sprite is defined. if not the error sprite will be rendered- Parameters:
spriteId
-spriteValue
-- Returns:
-
getRepresentingColor
public static com.badlogic.gdx.graphics.Color getRepresentingColor(byte id, byte value)
Returns a color representing the block. Picks from the sprite sprite.- Parameters:
id
- id of the RenderCellvalue
- the value of the block.- Returns:
- copy of a color representing the block
-
getBlocksprites
public static com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion[][][] getBlocksprites()
- Returns:
-
staticDispose
public static void staticDispose()
dipsose the static fields
-
getId
public byte getId()
game logic value. Sprite Id may differ.- Returns:
- See Also:
getSpriteId()
-
getValue
public byte getValue()
game logic value. Sprite value may differ.- Returns:
- See Also:
getSpriteValue()
-
isObstacle
public boolean isObstacle()
- Returns:
-
getName
public java.lang.String getName()
Description copied from class:AbstractGameObject
Returns the name of the object- Specified by:
getName
in classAbstractGameObject
- Returns:
- the name of the object
-
getPoint
public Point getPoint()
Description copied from class:AbstractGameObject
Can be internal reference or shared object.- Specified by:
getPoint
in classAbstractGameObject
- Returns:
- See Also:
AbstractGameObject.getPosition()
-
getCoord
public Coordinate getCoord()
Description copied from class:AbstractGameObject
not copy save- Specified by:
getCoord
in classAbstractGameObject
- Returns:
- See Also:
AbstractGameObject.getPosition()
-
getDimensionZ
public int getDimensionZ()
Description copied from class:AbstractGameObject
The height of the object for depth sorting.- Specified by:
getDimensionZ
in classAbstractGameObject
- Returns:
- game space
-
getPosition
public final Coordinate getPosition()
Description copied from class:AbstractGameObject
Return the coordinates of the object in the game world. Not copy safe as it points to the interaly used object.- Specified by:
getPosition
in classAbstractGameObject
- Returns:
- Reference to the position object which points to the location in the game world.
- See Also:
AbstractGameObject.getPoint()
-
setPosition
public void setPosition(Position pos)
Description copied from class:AbstractGameObject
Set the coordinates without safety check. May use different object pointing to the same position.- Specified by:
setPosition
in classAbstractGameObject
- Parameters:
pos
- the coordinates you want to set
-
spawn
public RenderCell spawn(RenderStorage rS, Coordinate coord)
places the object on the map. You can extend this to get the coordinate. RenderCell may be placed without this method call. A regular renderblock is not spawned expect explicitely called.- Parameters:
rS
-coord
- the position on the map- Returns:
- itself
- See Also:
setPosition(com.bombinggames.wurfelengine.core.map.Position)
-
render
public void render(GameView view)
Description copied from class:AbstractGameObject
Draws an object if it is not hidden and not clipped. in game space- Overrides:
render
in classAbstractGameObject
-
render
public void render(GameView view, int xPos, int yPos)
Render the whole block at a custom position. Checks if hidden.- Overrides:
render
in classAbstractGameObject
- Parameters:
view
- the view using this render methodxPos
- rendering position projection space of centeryPos
- rendering position projection space of center
-
render
public void render(GameView view, int xPos, int yPos, boolean staticShade)
Renders the whole block at a custom position.- Parameters:
view
- the view using this render methodxPos
- projection space of centeryPos
- projection space of centerstaticShade
- makes one side brighter, opposite side darker
-
renderSide
public void renderSide(GameView view, Side side, boolean staticShade)
Render a side of a block at the position of the internal coordinates.- Parameters:
view
-side
- The number identifying the side. 0=left, 1=top, 2=rightstaticShade
-
-
renderSide
public void renderSide(GameView view, int xPos, int yPos, Side side, com.badlogic.gdx.graphics.Color color)
uses heap, projection space- Parameters:
view
- the view using this render methodxPos
- projection positionyPos
- projection positionside
- The number identifying the side. 0=left, 1=top, 2=rightcolor
- when set overwrites value from light engine
-
renderSide
public void renderSide(GameView view, Point pos, Side side, com.badlogic.gdx.graphics.Color color)
Draws a side of a cell at a custom position. Applies color before rendering and takes the lightlevel into account.- Parameters:
view
- the view using this render methodpos
- world space positionside
- The number identifying the side. 0=left, 1=top, 2=rightcolor
- a tint in which the sprite gets rendered. If null color gets ignored
-
update
public void update(float dt)
Update the block. Should only be used for cosmetic logic because this is only called for blocks which are covered by a camera.- Parameters:
dt
- time in ms since last update
-
updateSpriteCache
public void updateSpriteCache()
Description copied from class:AbstractGameObject
Updates the saved vertex data with the engine default configuration (category, sprite id and sprite value).- Overrides:
updateSpriteCache
in classAbstractGameObject
-
getSpriteCategory
public char getSpriteCategory()
Description copied from class:AbstractGameObject
Get the category letter for accessing sprites.- Specified by:
getSpriteCategory
in classAbstractGameObject
- Returns:
-
setPosition
public void setPosition(Coordinate coord)
keeps reference- Parameters:
coord
-
-
isTransparent
public boolean isTransparent()
Can light travel through object?- Returns:
-
isIndestructible
public boolean isIndestructible()
- Returns:
-
hasSides
public boolean hasSides()
Is the block a true block with three sides or does it get rendered by a single sprite?
This field is only used for representation (view) related data.
Only used for blocks. Entities should return false.- Returns:
- true if it has sides, false if is rendered as a single sprite
-
isLiquid
public boolean isLiquid()
- Returns:
-
getLightlevelR
public float getLightlevelR()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelR
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelG
public float getLightlevelG()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelG
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelB
public float getLightlevelB()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelB
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
getLightlevel
public float getLightlevel(Side side, byte vertex, RenderCell.Channel channel)
- Parameters:
side
-vertex
- 0-3channel
-- Returns:
- range 0-2.
-
setLightlevel
public void setLightlevel(float lightlevel)
Stores the lightlevel factor for the whole cell and thereby overriding values for each side.- Specified by:
setLightlevel
in classAbstractGameObject
- Parameters:
lightlevel
- range 0-2 where 1 is default
-
resetLight
public void resetLight()
sets the light to 1
-
setLightlevel
public void setLightlevel(float lightlevel, Side side)
- Parameters:
lightlevel
- a factor in range [0-2]side
-
-
setLightlevel
public void setLightlevel(float lightlevel, Side side, byte vertex)
- Parameters:
lightlevel
- a factor in range [0-2]side
-vertex
- id [0-3]
-
setLightlevel
public void setLightlevel(float lightlevel, Side side, RenderCell.Channel channel, byte vertex)
- Parameters:
lightlevel
- a factor in range [0-2]side
-channel
- 0 = Red, 1 = Green, 2 = Bluevertex
-
-
addLightlevel
public void addLightlevel(float lightlevel, Side side, RenderCell.Channel channel, byte vertex)
- Parameters:
lightlevel
- a factor in range [0-2]side
-channel
- 0 = Red, 1 = Green, 2 = Bluevertex
-
-
hidingPastBlock
public boolean hidingPastBlock()
- Returns:
- true if it hides the block behind and below
-
setAOFlagTrue
public void setAOFlagTrue(int side)
Set flags for the ambient occlusion algorithm to true- Parameters:
side
-
-
setAOFlagFalse
public void setAOFlagFalse(int side)
Set flags for the ambient occlusion algorithm to false- Parameters:
side
-
-
getAOFlags
public int getAOFlags()
byte 0: left side, byte 1: top side, byte 2: right side.
In each byte bit order:
7 \ 0 / 1
-------
6 | - | 2
-------
5 / 4 \ 3- Returns:
- four bytes in an int
-
setAoFlags
public void setAoFlags(int aoFlags)
Set all flags at once- Parameters:
aoFlags
-
-
getClipping
public byte getClipping()
a block is only clipped if every side is clipped- Returns:
-
isFullyClipped
public boolean isFullyClipped()
a block is only clipped if every side is clipped- Returns:
-
setClippedLeft
public void setClippedLeft()
-
setClippedTop
public void setClippedTop()
-
setClippedRight
public void setClippedRight()
-
setUnclipped
public void setUnclipped()
Makes every side visible
-
shouldBeRendered
public boolean shouldBeRendered(Camera camera)
Description copied from class:AbstractGameObject
Gives information if object should be rendered.- Overrides:
shouldBeRendered
in classAbstractGameObject
- Returns:
-
getHealth
public byte getHealth()
get the health byte from the map.- Returns:
- if no coordiante returns 100
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getSpriteId
public byte getSpriteId()
Description copied from class:AbstractGameObject
the id of the sprite using for rendering.
By default is the same as the block id but in some cases some objects share one sprite so they can have the same id.- Specified by:
getSpriteId
in classAbstractGameObject
- Returns:
- in range [0;
OBJECTTYPESNUM
].
-
getSpriteValue
public byte getSpriteValue()
Description copied from class:AbstractGameObject
Get the value. It is like a sub-id and can identify the status.- Specified by:
getSpriteValue
in classAbstractGameObject
- Returns:
- in range [0;
VALUESNUM
]. Is -1 if about to destroyed.
-
setValue
public void setValue(byte value)
It is advised to only change this value if the data stored in the map also changes.- Parameters:
value
- game data value.
-
getTopoNode
public TopoGraphNode getTopoNode()
- Returns:
- null if outside chunk
-
-