stmm-games-doc  0.32.0
Classes | Public Member Functions | List of all members
stmg::Block Class Reference

Classes

struct  Contact
 A contact. More...
 

Public Member Functions

 Block () noexcept
 Empty constructor. More...
 
 Block (int32_t nTotBricks, const std::vector< Tile > &aBrick, int32_t nTotShapes, const std::vector< std::vector< std::tuple< bool, int32_t, int32_t > > > &aShapeBrickPos) noexcept
 Constructor. More...
 
 Block (int32_t nTotBricks, const std::vector< Tile > &aBrick, const std::vector< std::tuple< bool, int32_t, int32_t > > &aBrickPos, int32_t nWH) noexcept
 Automatically rotated four shapes constructor. More...
 
 Block (int32_t nFirstShapeId, const Block &oFirst, int32_t nSecondShapeId, const Block &oSecond, int32_t nRelX, int32_t nRelY, int32_t &nFirstPosXDelta, int32_t &nFirstPosYDelta, std::unordered_map< int32_t, int32_t > &oFirstBrickIds, std::unordered_map< int32_t, int32_t > &oSecondBrickIds) noexcept
 Automatically rotated four shapes constructor fusing two blocks. More...
 
void swap (Block &oBlock) noexcept
 Swap two blocks. More...
 
 Block (const Block &oSource) noexcept
 Copy constructor. More...
 
Blockoperator= (const Block &oSource) noexcept
 Assignment. More...
 
bool isEmpty () const noexcept
 Whether the block has any bricks. More...
 
int32_t totBricks () const noexcept
 The total number of bricks in the block. More...
 
int32_t totShapes () const noexcept
 The total number of shapes in the block. More...
 
const std::vector< int32_t > & brickIds () const noexcept
 The brick ids of the block. More...
 
std::vector< int32_t > shapeIds () const noexcept
 The shape ids (in ascending order). More...
 
bool isBrickId (int32_t nBrickId) const noexcept
 Whether the brick id is valid. More...
 
bool isShapeId (int32_t nShapeId) const noexcept
 Whether the shape id is valid. More...
 
const Tilebrick (int32_t nBrickId) const noexcept
 The tile of the block's brick. More...
 
int32_t shapeBrickPosX (int32_t nShapeId, int32_t nBrickId) const noexcept
 The x position of a brick in a shape. More...
 
int32_t shapeBrickPosY (int32_t nShapeId, int32_t nBrickId) const noexcept
 The y position of a brick in a shape. More...
 
NPoint shapeBrickPos (int32_t nShapeId, int32_t nBrickId) const noexcept
 The position of a brick in a shape. More...
 
bool shapeBrickVisible (int32_t nShapeId, int32_t nBrickId) const noexcept
 Tells whether a brick is visible in the given shape. More...
 
int32_t shapeTotVisibleBricks (int32_t nShapeId) const noexcept
 Total number of visible bricks of a shape. More...
 
int32_t shapeBrickVisiblePosition (int32_t nShapeId, int32_t nX, int32_t nY) const noexcept
 Tells whether at the given position in the shape there is a visible brick. More...
 
bool shapeBrickSetVisible (int32_t nShapeId, int32_t nBrickId, bool bVisible) noexcept
 Sets the visibility of a brick in a shape. More...
 
bool shapeBrickSetPosVisible (int32_t nShapeId, int32_t nBrickId, int32_t nX, int32_t nY, bool bVisible) noexcept
 Sets the position and visibility of a brick in a shape. More...
 
bool shapeModifyBricks (int32_t nShapeId, const std::vector< std::tuple< int32_t, int32_t, int32_t, bool > > &aBrickPosition) noexcept
 Modifies the given bricks: tuple<nBrickId, nX, nY, bVisible> The positions are set even if couldn't set the visibility of one or more bricks. More...
 
const std::vector< ContactshapeContacts (int32_t nShapeId, Direction::VALUE eDir) const noexcept
 The contacts for a certain shape and direction. More...
 
int32_t brickAdd (const Tile &oTile, int32_t nX, int32_t nY, bool bVisible) noexcept
 Adds a brick at the given position in each shape. More...
 
void brickModify (int32_t nBrickId, const Tile &oTile) noexcept
 Modify the tile of a brick. More...
 
void brickRemove (int32_t nBrickId) noexcept
 Removes a brick. More...
 
int32_t shapeInsert (int32_t nBeforeShapeId) noexcept
 Inserts a shape into the block. More...
 
int32_t shapeInsert (int32_t nBeforeShapeId, int32_t nCopyOfShapeId) noexcept
 Inserts a copy of another shape into the block. More...
 
void shapeRemove (int32_t nShapeId) noexcept
 Removes a shape. More...
 
int32_t shapeRemoveAllInvisible () noexcept
 Remove all shapes that have no visible bricks. More...
 
int32_t shapeFirst () const noexcept
 The first shape id. More...
 
int32_t shapeLast () const noexcept
 The last shape id. More...
 
int32_t shapePrec (int32_t nShapeId) const noexcept
 The shape id of the shape preceding another. More...
 
int32_t shapeNext (int32_t nShapeId) const noexcept
 The shape id of the shape following another. More...
 
int32_t shapeMinX (int32_t nShapeId) const noexcept
 The minimum x position of the visible bricks in a shape. More...
 
int32_t shapeMinY (int32_t nShapeId) const noexcept
 The minimum y position of the visible bricks in a shape. More...
 
NPoint shapeMinPos (int32_t nShapeId) const noexcept
 The minimum position of the visible bricks in a shape. More...
 
int32_t shapeMaxX (int32_t nShapeId) const noexcept
 The maximum x position of the visible bricks in a shape. More...
 
int32_t shapeMaxY (int32_t nShapeId) const noexcept
 The maximum y position of the visible bricks in a shape. More...
 
NPoint shapeMaxPos (int32_t nShapeId) const noexcept
 The maximum position of the visible bricks in a shape. More...
 
int32_t maxWidth () const noexcept
 The maximum width of all shapes. More...
 
int32_t maxHeight () const noexcept
 The maximum height of all shapes. More...
 
int32_t shapeWidth (int32_t nShapeId) const noexcept
 The width of a given shape. More...
 
int32_t shapeHeight (int32_t nShapeId) const noexcept
 The height of a given shape. More...
 
NSize shapeSize (int32_t nShapeId) const noexcept
 The size of a given shape. More...
 
int32_t widestShapeId () const noexcept
 The widest shape of the block. More...
 
int32_t highestShapeId () const noexcept
 The highest shape of the block. More...
 
void dump () const noexcept
 
void dump (int32_t nIndent) const noexcept
 

Constructor & Destructor Documentation

◆ Block() [1/5]

stmg::Block::Block ( )
noexcept

Empty constructor.

Creates a block with no shapes and no bricks.

◆ Block() [2/5]

stmg::Block::Block ( int32_t  nTotBricks,
const std::vector< Tile > &  aBrick,
int32_t  nTotShapes,
const std::vector< std::vector< std::tuple< bool, int32_t, int32_t > > > &  aShapeBrickPos 
)
noexcept

Constructor.

aBrick[0 .. nTotBricks-1]: Tile aShapeBrickPos[0 .. nTotShapes-1][0.. nTotBricks-1]: tuple(bVisible, nPosX, nPosY)

Empty Tiles are not allowed and are replaced with some unusual non-empty tile. Missing tiles (aBrick parameter) also are filled with some non-empty tile. Undefined positions within a shape make bricks invisible.

For each shape a position can only have a visible brick, those in excess are set to not visible.

The created bricks start from id 0 and increment. The created shapes start from id 0 and increment.

Parameters
nTotBricksThe number of bricks. Must be > 0.
aBrickThe bricks (tiles).
nTotShapesThe number of shapes. Must be > 0.
aShapeBrickPosThe visibility and position of each brick and shape.

◆ Block() [3/5]

stmg::Block::Block ( int32_t  nTotBricks,
const std::vector< Tile > &  aBrick,
const std::vector< std::tuple< bool, int32_t, int32_t > > &  aBrickPos,
int32_t  nWH 
)
noexcept

Automatically rotated four shapes constructor.

Block is generated automatically from 1 shape, adding 3 shapes rotated 90, 180, 270 degrees.

aBrick[0 .. nTotBricks-1]: Tile
aBrickPos[0 .. nTotBricks-1]: tuple(bVisible, nPosX, nPosY)

Empty Tiles are not allowed and are replaced with some unusual non-empty tile. Missing tiles (aBrick parameter) also are filled with some non-empty tile. Undefined positions within a shape make bricks invisible.

For each shape a position can only have a visible brick, those in excess are set to not visible.

The created bricks start from id 0 and increment. The created shapes start from id 0 and increment.

Parameters
nTotBricksThe number of bricks. Must be > 0.
aBrickThe bricks (tiles).
aBrickPosThe visibility and position of each brick within the first shape.
nWHThe value that defines the center of rotation (nWH / 2, nWH / 2). Example: 3 -> (1.5, 1.5).

◆ Block() [4/5]

stmg::Block::Block ( int32_t  nFirstShapeId,
const Block oFirst,
int32_t  nSecondShapeId,
const Block oSecond,
int32_t  nRelX,
int32_t  nRelY,
int32_t &  nFirstPosXDelta,
int32_t &  nFirstPosYDelta,
std::unordered_map< int32_t, int32_t > &  oFirstBrickIds,
std::unordered_map< int32_t, int32_t > &  oSecondBrickIds 
)
noexcept

Automatically rotated four shapes constructor fusing two blocks.

Only the visible bricks of the given shapes are used to build the result block.

Add (nFirstPosXDelta, nFirstPosYDelta) to the position of the first block to get the position of the result block to make it coincide with the fused blocks.

The result Block is generated automatically from the fused shapes, adding 3 additional shapes rotated counterclockwise 90, 180 and 270 degrees around the "geometric" center.

The created bricks start from id 0 and increment. The created shapes start from id 0 and increment.

Parameters
nFirstShapeIdThe shape of the first block to be used.
oFirstThe first block.
nSecondShapeIdThe shape of the second block to be used.
oSecondThe second block.
nRelXThe x position of the second block relative to the first.
nRelYThe y position of the second block relative to the first.
nFirstPosXDeltaThe delta x position of the first block to the result block.
nFirstPosYDeltaThe delta y position of the first block to the result block.
oFirstBrickIdsThe mapping from the first block's brick ids to the result's brick ids.
oSecondBrickIdsThe mapping from the second block's brick ids to the result's brick ids.

◆ Block() [5/5]

stmg::Block::Block ( const Block oSource)
noexcept

Copy constructor.

Parameters
oSourceThe source block.

Member Function Documentation

◆ brick()

const Tile& stmg::Block::brick ( int32_t  nBrickId) const
noexcept

The tile of the block's brick.

Parameters
nBrickIdThe brick id. Must be valid.
Returns
The tile.

◆ brickAdd()

int32_t stmg::Block::brickAdd ( const Tile oTile,
int32_t  nX,
int32_t  nY,
bool  bVisible 
)
noexcept

Adds a brick at the given position in each shape.

If bVisible is true the added brick might still not be visible in a shape because its position is already occupied by another visible brick.

If the block has no shapes, one is created.

If the tile is empty, some non empty tile is used.

Parameters
oTileThe tile of the brick.
nXThe x coord of the brick.
nYThe y coord of the brick.
bVisibleWhether the brick is visible.
Returns
The brick id.

◆ brickIds()

const std::vector<int32_t>& stmg::Block::brickIds ( ) const
inlinenoexcept

The brick ids of the block.

Returns
The brick ids.

◆ brickModify()

void stmg::Block::brickModify ( int32_t  nBrickId,
const Tile oTile 
)
noexcept

Modify the tile of a brick.

If the tile is empty, some non empty tile is used.

Parameters
nBrickIdThe brick id.
oTileThe new tile.

◆ brickRemove()

void stmg::Block::brickRemove ( int32_t  nBrickId)
noexcept

Removes a brick.

Parameters
nBrickIdThe brick id.

◆ dump() [1/2]

void stmg::Block::dump ( ) const
noexcept

◆ dump() [2/2]

void stmg::Block::dump ( int32_t  nIndent) const
noexcept

◆ highestShapeId()

int32_t stmg::Block::highestShapeId ( ) const
noexcept

The highest shape of the block.

Returns
The highest shape id or -1 if block has no visible bricks or has no shapes.

◆ isBrickId()

bool stmg::Block::isBrickId ( int32_t  nBrickId) const
noexcept

Whether the brick id is valid.

Parameters
nBrickIdThe brick id.
Returns
Whether brick exists in block.

◆ isEmpty()

bool stmg::Block::isEmpty ( ) const
inlinenoexcept

Whether the block has any bricks.

Note: the block with bricks but no shapes is considered non empty.

Returns
Whether empty.

◆ isShapeId()

bool stmg::Block::isShapeId ( int32_t  nShapeId) const
noexcept

Whether the shape id is valid.

Parameters
nShapeIdThe shape id.
Returns
Whether shape exists in block.

◆ maxHeight()

int32_t stmg::Block::maxHeight ( ) const
noexcept

The maximum height of all shapes.

Returns 0 if no visible bricks or no shapes.

Returns
The maximum height.

◆ maxWidth()

int32_t stmg::Block::maxWidth ( ) const
noexcept

The maximum width of all shapes.

Returns 0 if no visible bricks or no shapes.

Returns
The maximum width.

◆ operator=()

Block& stmg::Block::operator= ( const Block oSource)
noexcept

Assignment.

Parameters
oSourceThe source block.
Returns
This block.

◆ shapeBrickPos()

NPoint stmg::Block::shapeBrickPos ( int32_t  nShapeId,
int32_t  nBrickId 
) const
noexcept

The position of a brick in a shape.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
Returns
The position.

◆ shapeBrickPosX()

int32_t stmg::Block::shapeBrickPosX ( int32_t  nShapeId,
int32_t  nBrickId 
) const
noexcept

The x position of a brick in a shape.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
Returns
The x position.

◆ shapeBrickPosY()

int32_t stmg::Block::shapeBrickPosY ( int32_t  nShapeId,
int32_t  nBrickId 
) const
noexcept

The y position of a brick in a shape.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
Returns
The y position.

◆ shapeBrickSetPosVisible()

bool stmg::Block::shapeBrickSetPosVisible ( int32_t  nShapeId,
int32_t  nBrickId,
int32_t  nX,
int32_t  nY,
bool  bVisible 
)
noexcept

Sets the position and visibility of a brick in a shape.

The position is set even if couldn't set the visibility.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
nXThe x position.
nYThe y position.
bVisibleThe visibility.
Returns
Returns false if couldn't make visible because position already occupied by another brick.

◆ shapeBrickSetVisible()

bool stmg::Block::shapeBrickSetVisible ( int32_t  nShapeId,
int32_t  nBrickId,
bool  bVisible 
)
noexcept

Sets the visibility of a brick in a shape.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
bVisibleThe visibility.
Returns
Returns false if couldn't make visible because position already occupied by another brick.

◆ shapeBrickVisible()

bool stmg::Block::shapeBrickVisible ( int32_t  nShapeId,
int32_t  nBrickId 
) const
noexcept

Tells whether a brick is visible in the given shape.

Parameters
nShapeIdThe shape id. Must be valid.
nBrickIdThe brick id. Must be valid.
Returns
Whether visible.

◆ shapeBrickVisiblePosition()

int32_t stmg::Block::shapeBrickVisiblePosition ( int32_t  nShapeId,
int32_t  nX,
int32_t  nY 
) const
noexcept

Tells whether at the given position in the shape there is a visible brick.

Parameters
nShapeIdThe shape id. Must be valid.
nXThe x position.
nYThe y position.
Returns
The visible brick id at the position or -q if nothing there.

◆ shapeContacts()

const std::vector< Contact > stmg::Block::shapeContacts ( int32_t  nShapeId,
Direction::VALUE  eDir 
) const
noexcept

The contacts for a certain shape and direction.

Parameters
nShapeIdThe shape id. Must be valid.
eDirThe direction.
Returns
The vector containing all the contacts.

◆ shapeFirst()

int32_t stmg::Block::shapeFirst ( ) const
noexcept

The first shape id.

Is (sort of) same as shapeIds()[0], but more efficient.

Returns
The id of the first shape or -1 if block has no shapes.

◆ shapeHeight()

int32_t stmg::Block::shapeHeight ( int32_t  nShapeId) const
noexcept

The height of a given shape.

Parameters
nShapeIdThe shape id.
Returns
The shape's height or 0 if no visible bricks.

◆ shapeIds()

std::vector<int32_t> stmg::Block::shapeIds ( ) const
inlinenoexcept

The shape ids (in ascending order).

Returns
The shape ids.

◆ shapeInsert() [1/2]

int32_t stmg::Block::shapeInsert ( int32_t  nBeforeShapeId)
noexcept

Inserts a shape into the block.

If nBeforeShapeId is -1 added as last shape.

All bricks will be set at position (0,0) and be not visible.

Parameters
nBeforeShapeIdThe shape id before which the shape must be inserted or -1.
Returns
The newly inserted shape id.

◆ shapeInsert() [2/2]

int32_t stmg::Block::shapeInsert ( int32_t  nBeforeShapeId,
int32_t  nCopyOfShapeId 
)
noexcept

Inserts a copy of another shape into the block.

If nBeforeShapeId is -1 added as last shape.

Parameters
nBeforeShapeIdThe shape id before which the shape must be inserted or -1.
nCopyOfShapeIdThe shape the inserted shouuld be copied from.
Returns
The newly inserted shape id.

◆ shapeLast()

int32_t stmg::Block::shapeLast ( ) const
noexcept

The last shape id.

Returns
The id of the last shape or -1 if block has no shapes.

◆ shapeMaxPos()

NPoint stmg::Block::shapeMaxPos ( int32_t  nShapeId) const
noexcept

The maximum position of the visible bricks in a shape.

If the shape has no visible bricks the return value is {std::numeric_limits<int32_t>::lowest(), std::numeric_limits<int32_t>::lowest()}. The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The maximum position (relative to block's origin).

◆ shapeMaxX()

int32_t stmg::Block::shapeMaxX ( int32_t  nShapeId) const
noexcept

The maximum x position of the visible bricks in a shape.

If the shape has no visible bricks the return value is std::numeric_limits<int32_t>::lowest(). The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The maximum x position (relative to block's origin).

◆ shapeMaxY()

int32_t stmg::Block::shapeMaxY ( int32_t  nShapeId) const
noexcept

The maximum y position of the visible bricks in a shape.

If the shape has no visible bricks the return value is std::numeric_limits<int32_t>::lowest(). The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The maximum y position (relative to block's origin).

◆ shapeMinPos()

NPoint stmg::Block::shapeMinPos ( int32_t  nShapeId) const
noexcept

The minimum position of the visible bricks in a shape.

If the shape has no visible bricks the return value is {std::numeric_limits<int32_t>::max(), std::numeric_limits<int32_t>::max()}. The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The minimum position (relative to block's origin).

◆ shapeMinX()

int32_t stmg::Block::shapeMinX ( int32_t  nShapeId) const
noexcept

The minimum x position of the visible bricks in a shape.

If the shape has no visible bricks the return value is std::numeric_limits<int32_t>::max(). The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The minimum x position (relative to block's origin).

◆ shapeMinY()

int32_t stmg::Block::shapeMinY ( int32_t  nShapeId) const
noexcept

The minimum y position of the visible bricks in a shape.

If the shape has no visible bricks the return value is std::numeric_limits<int32_t>::max(). The value is cached (not calculated for each call).

Parameters
nShapeIdThe shape id.
Returns
The minimum y position (relative to block's origin).

◆ shapeModifyBricks()

bool stmg::Block::shapeModifyBricks ( int32_t  nShapeId,
const std::vector< std::tuple< int32_t, int32_t, int32_t, bool > > &  aBrickPosition 
)
noexcept

Modifies the given bricks: tuple<nBrickId, nX, nY, bVisible> The positions are set even if couldn't set the visibility of one or more bricks.

Parameters
nShapeIdThe shape id. Must be valid.
aBrickPositionThe modified bricks as tuple<nBrickId, nX, nY, bVisible>.
Returns
Returns false if any of the modified bricks couldn't be turned visible.

◆ shapeNext()

int32_t stmg::Block::shapeNext ( int32_t  nShapeId) const
noexcept

The shape id of the shape following another.

Parameters
nShapeIdThe shape id the following of which is returned.
Returns
The following shape id or -1 if nShapeId is the last.

◆ shapePrec()

int32_t stmg::Block::shapePrec ( int32_t  nShapeId) const
noexcept

The shape id of the shape preceding another.

Parameters
nShapeIdThe shape id the preceding of which is returned.
Returns
The preceding shape id or -1 if nShapeId is the first.

◆ shapeRemove()

void stmg::Block::shapeRemove ( int32_t  nShapeId)
noexcept

Removes a shape.

Parameters
nShapeIdThe shape to remove.

◆ shapeRemoveAllInvisible()

int32_t stmg::Block::shapeRemoveAllInvisible ( )
noexcept

Remove all shapes that have no visible bricks.

Returns
The number of removed shapes.

◆ shapeSize()

NSize stmg::Block::shapeSize ( int32_t  nShapeId) const
noexcept

The size of a given shape.

Parameters
nShapeIdThe shape id.
Returns
The shape's size or (0, 0) if no visible bricks.

◆ shapeTotVisibleBricks()

int32_t stmg::Block::shapeTotVisibleBricks ( int32_t  nShapeId) const
noexcept

Total number of visible bricks of a shape.

Parameters
nShapeIdThe shape id. Must be valid.
Returns
The number of visible bricks.

◆ shapeWidth()

int32_t stmg::Block::shapeWidth ( int32_t  nShapeId) const
noexcept

The width of a given shape.

Parameters
nShapeIdThe shape id.
Returns
The shape's width or 0 if no visible bricks.

◆ swap()

void stmg::Block::swap ( Block oBlock)
noexcept

Swap two blocks.

Parameters
oBlockThe other block.

◆ totBricks()

int32_t stmg::Block::totBricks ( ) const
inlinenoexcept

The total number of bricks in the block.

Returns
The number of bricks. Can be 0 if block empty.

◆ totShapes()

int32_t stmg::Block::totShapes ( ) const
inlinenoexcept

The total number of shapes in the block.

Returns
The number of shapes. Can be 0 if block empty.

◆ widestShapeId()

int32_t stmg::Block::widestShapeId ( ) const
noexcept

The widest shape of the block.

Returns
The widest shape id or -1 if block has no visible bricks or has no shapes.