Class 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 and AbstractGameObject 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
    • 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 block
        value - the value of teh block
        side - 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 RenderCell
        value - 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:
      • 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 class AbstractGameObject
        Parameters:
        pos - the coordinates you want to set
      • render

        public void render​(GameView view,
                           int xPos,
                           int yPos)
        Render the whole block at a custom position. Checks if hidden.
        Overrides:
        render in class AbstractGameObject
        Parameters:
        view - the view using this render method
        xPos - rendering position projection space of center
        yPos - 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 method
        xPos - projection space of center
        yPos - projection space of center
        staticShade - 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=right
        staticShade -
      • 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 method
        xPos - projection position
        yPos - projection position
        side - The number identifying the side. 0=left, 1=top, 2=right
        color - 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 method
        pos - world space position
        side - The number identifying the side. 0=left, 1=top, 2=right
        color - 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 class AbstractGameObject
      • 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 class AbstractGameObject
        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 class AbstractGameObject
        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 class AbstractGameObject
        Returns:
        1 is default bright. 0 is black.
      • getLightlevel

        public float getLightlevel​(Side side,
                                   byte vertex,
                                   RenderCell.Channel channel)
        Parameters:
        side -
        vertex - 0-3
        channel -
        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 class AbstractGameObject
        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 = Blue
        vertex -
      • 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 = Blue
        vertex -
      • 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
      • 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 class java.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 class AbstractGameObject
        Returns:
        in range [0;OBJECTTYPESNUM].
      • 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