squeezed another 80 bytes
This commit is contained in:
parent
3affa5c9a3
commit
291c90ccf6
|
@ -114,47 +114,23 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
|
|||
assert((nWidth >= 4) && (nWidth <= 16));
|
||||
assert((nHeight >= 4) && (nHeight <= 124));
|
||||
|
||||
// allocating memory
|
||||
tetris_bucket_t *pBucket =
|
||||
(tetris_bucket_t *)malloc(sizeof(tetris_bucket_t));
|
||||
|
||||
if (pBucket != NULL)
|
||||
{
|
||||
// allocating memory for dump array
|
||||
pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t));
|
||||
|
||||
if (pBucket->dump != NULL)
|
||||
{
|
||||
// setting requested attributes
|
||||
pBucket->nFirstTaintedRow = nHeight;
|
||||
pBucket->nWidth = nWidth;
|
||||
pBucket->nHeight = nHeight;
|
||||
// bit mask of a full row
|
||||
pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth);
|
||||
|
||||
tetris_bucket_reset(pBucket);
|
||||
|
||||
return pBucket;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(pBucket);
|
||||
pBucket = NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void tetris_bucket_destruct(tetris_bucket_t *pBucket)
|
||||
{
|
||||
assert(pBucket != NULL);
|
||||
pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t));
|
||||
assert(pBucket->dump != NULL);
|
||||
|
||||
// if memory for the dump array has been allocated, free it
|
||||
if (pBucket->dump != NULL)
|
||||
{
|
||||
free(pBucket->dump);
|
||||
}
|
||||
free(pBucket);
|
||||
// setting requested attributes
|
||||
pBucket->nHeight = pBucket->nFirstTaintedRow = nHeight;
|
||||
pBucket->nWidth = nWidth;
|
||||
|
||||
// bit mask of a full row
|
||||
pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth);
|
||||
|
||||
tetris_bucket_reset(pBucket);
|
||||
|
||||
return pBucket;
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,19 +141,16 @@ void tetris_bucket_destruct(tetris_bucket_t *pBucket)
|
|||
void tetris_bucket_reset(tetris_bucket_t *pBucket)
|
||||
{
|
||||
assert(pBucket != NULL);
|
||||
assert(pBucket->dump != NULL);
|
||||
|
||||
pBucket->pPiece = NULL;
|
||||
pBucket->nColumn = 0;
|
||||
pBucket->nRow = 0;
|
||||
pBucket->nRowMask = 0;
|
||||
|
||||
// clear dump if it has been allocated in memory
|
||||
if (pBucket->dump != NULL)
|
||||
{
|
||||
memset(pBucket->dump, 0, pBucket->nHeight * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
pBucket->status = TETRIS_BUS_READY;
|
||||
|
||||
// clear dump
|
||||
memset(pBucket->dump, 0, pBucket->nHeight * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -88,7 +88,13 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
|
|||
* destructs a bucket
|
||||
* @param pBucket pointer to the bucket to be destructed
|
||||
*/
|
||||
void tetris_bucket_destruct(tetris_bucket_t *pBucket);
|
||||
inline static void tetris_bucket_destruct(tetris_bucket_t *pBucket)
|
||||
{
|
||||
assert(pBucket != NULL);
|
||||
assert(pBucket->dump != NULL);
|
||||
free(pBucket->dump);
|
||||
free(pBucket);
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
|
|
|
@ -256,13 +256,6 @@ tetris_input_t *tetris_input_construct(void)
|
|||
}
|
||||
|
||||
|
||||
void tetris_input_destruct(tetris_input_t *pIn)
|
||||
{
|
||||
assert(pIn != NULL);
|
||||
free(pIn);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
* input related functions *
|
||||
***************************/
|
||||
|
|
|
@ -152,7 +152,11 @@ tetris_input_t *tetris_input_construct(void);
|
|||
* destructs an input object
|
||||
* @param pIn pointer to the input object which should be destructed
|
||||
*/
|
||||
void tetris_input_destruct(tetris_input_t *pIn);
|
||||
inline static void tetris_input_destruct(tetris_input_t *pIn)
|
||||
{
|
||||
assert(pIn != NULL);
|
||||
free(pIn);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
|
|
|
@ -22,13 +22,6 @@ tetris_piece_t *tetris_piece_construct(tetris_piece_shape_t s,
|
|||
}
|
||||
|
||||
|
||||
void tetris_piece_destruct(tetris_piece_t *pPc)
|
||||
{
|
||||
assert(pPc != NULL);
|
||||
free(pPc);
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
* piece related functions *
|
||||
****************************/
|
||||
|
|
|
@ -84,7 +84,11 @@ tetris_piece_t *tetris_piece_construct(tetris_piece_shape_t s,
|
|||
* destructs a piece
|
||||
* @param pPc pointer to the piece to be destructed
|
||||
*/
|
||||
void tetris_piece_destruct(tetris_piece_t *pPc);
|
||||
inline static void tetris_piece_destruct(tetris_piece_t *pPc)
|
||||
{
|
||||
assert(pPc != NULL);
|
||||
free(pPc);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
void tetris_main(tetris_variant_t const *const pVariantMethods)
|
||||
{
|
||||
// get view dependent dimensions of the bucket
|
||||
int8_t nWidth;
|
||||
int8_t nHeight;
|
||||
int8_t nWidth, nHeight;
|
||||
tetris_view_getDimensions(&nWidth, &nHeight);
|
||||
|
||||
// holds the current user command which should be processed
|
||||
|
@ -104,7 +103,7 @@ void tetris_main(tetris_variant_t const *const pVariantMethods)
|
|||
// if the game still runs, reward the player with extra points
|
||||
if (tetris_bucket_getStatus(pBucket) != TETRIS_BUS_GAMEOVER)
|
||||
{
|
||||
pVariantMethods->singleDrop(pVariantData, 1);
|
||||
pVariantMethods->singleDrop(pVariantData);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -322,14 +322,8 @@ void tetris_bastet_destruct(void *pVariantData)
|
|||
assert(pVariantData != 0);
|
||||
tetris_bastet_variant_t *pBastetVariant =
|
||||
(tetris_bastet_variant_t *)pVariantData;
|
||||
if (pBastetVariant->pColScore != NULL)
|
||||
{
|
||||
free(pBastetVariant->pColScore);
|
||||
}
|
||||
if (pBastetVariant->pColHeights != NULL)
|
||||
{
|
||||
free(pBastetVariant->pColHeights);
|
||||
}
|
||||
free(pBastetVariant->pColScore);
|
||||
free(pBastetVariant->pColHeights);
|
||||
if (pBastetVariant->pPreviewPiece != NULL)
|
||||
{
|
||||
tetris_piece_destruct(pBastetVariant->pPreviewPiece);
|
||||
|
@ -394,8 +388,7 @@ tetris_piece_t* tetris_bastet_choosePiece(void *pVariantData)
|
|||
}
|
||||
|
||||
|
||||
void tetris_bastet_singleDrop(void *pVariantData,
|
||||
uint8_t nLines)
|
||||
void tetris_bastet_singleDrop(void *pVariantData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -92,10 +92,8 @@ tetris_piece_t* tetris_bastet_choosePreviewPiece(void *pBastet);
|
|||
/**
|
||||
* add points which result from single step dropping
|
||||
* @param pVariantData the variant data object we want to modify
|
||||
* @param nLines the number of rows involved
|
||||
*/
|
||||
void tetris_bastet_singleDrop(void *pVariantData,
|
||||
uint8_t nLines);
|
||||
void tetris_bastet_singleDrop(void *pVariantData);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -118,13 +118,12 @@ tetris_piece_t* tetris_std_choosePiece(void *pVariantData)
|
|||
}
|
||||
|
||||
|
||||
void tetris_std_singleDrop(void *pVariantData,
|
||||
uint8_t nLines)
|
||||
void tetris_std_singleDrop(void *pVariantData)
|
||||
{
|
||||
assert(pVariantData != 0);
|
||||
tetris_standard_variant_t *pStdVariant =
|
||||
(tetris_standard_variant_t *)pVariantData;
|
||||
pStdVariant->nScore += nLines;
|
||||
++pStdVariant->nScore;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,10 +76,8 @@ tetris_piece_t* tetris_std_choosePiece(void *pVariantData);
|
|||
/**
|
||||
* add points which result from single step dropping
|
||||
* @param pVariantData the variant data object we want to modify
|
||||
* @param nLines the number of rows involved
|
||||
*/
|
||||
void tetris_std_singleDrop(void *pVariantData,
|
||||
uint8_t nLines);
|
||||
void tetris_std_singleDrop(void *pVariantData);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,11 +36,8 @@ typedef struct tetris_variant_t
|
|||
/**
|
||||
* add points which result from single step dropping
|
||||
* @param pVariantData the variant data object we want to modify
|
||||
* @param nLines the number of rows involved
|
||||
*/
|
||||
void (*singleDrop)(void *pVariantData,
|
||||
uint8_t nLines);
|
||||
|
||||
void (*singleDrop)(void *pVariantData);
|
||||
|
||||
/**
|
||||
* add points which result from a complete drop
|
||||
|
|
|
@ -600,13 +600,6 @@ tetris_view_t *tetris_view_construct(tetris_variant_t const *const pVarMethods,
|
|||
}
|
||||
|
||||
|
||||
void tetris_view_destruct(tetris_view_t *pView)
|
||||
{
|
||||
assert(pView != NULL);
|
||||
free(pView);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
* view related functions *
|
||||
***************************/
|
||||
|
|
|
@ -67,7 +67,11 @@ tetris_view_t *tetris_view_construct(tetris_variant_t const *const pVarMethods,
|
|||
* destructs a view
|
||||
* @param pView: pointer to the view to be destructed
|
||||
*/
|
||||
void tetris_view_destruct(tetris_view_t *pView);
|
||||
inline static void tetris_view_destruct(tetris_view_t *pView)
|
||||
{
|
||||
assert(pView != NULL);
|
||||
free(pView);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
|
|
Loading…
Reference in New Issue