squeezed another 80 bytes

This commit is contained in:
Christian Kroll 2011-02-06 22:56:26 +00:00
parent 3affa5c9a3
commit 291c90ccf6
14 changed files with 49 additions and 95 deletions

View File

@ -114,20 +114,17 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
assert((nWidth >= 4) && (nWidth <= 16)); assert((nWidth >= 4) && (nWidth <= 16));
assert((nHeight >= 4) && (nHeight <= 124)); assert((nHeight >= 4) && (nHeight <= 124));
// allocating memory
tetris_bucket_t *pBucket = tetris_bucket_t *pBucket =
(tetris_bucket_t *)malloc(sizeof(tetris_bucket_t)); (tetris_bucket_t *)malloc(sizeof(tetris_bucket_t));
assert(pBucket != NULL);
if (pBucket != NULL)
{
// allocating memory for dump array
pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t)); pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t));
assert(pBucket->dump != NULL);
if (pBucket->dump != NULL)
{
// setting requested attributes // setting requested attributes
pBucket->nFirstTaintedRow = nHeight; pBucket->nHeight = pBucket->nFirstTaintedRow = nHeight;
pBucket->nWidth = nWidth; pBucket->nWidth = nWidth;
pBucket->nHeight = nHeight;
// bit mask of a full row // bit mask of a full row
pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth); pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth);
@ -135,27 +132,6 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
return pBucket; return pBucket;
} }
else
{
free(pBucket);
pBucket = NULL;
}
}
return NULL;
}
void tetris_bucket_destruct(tetris_bucket_t *pBucket)
{
assert(pBucket != NULL);
// if memory for the dump array has been allocated, free it
if (pBucket->dump != NULL)
{
free(pBucket->dump);
}
free(pBucket);
}
/******************************* /*******************************
@ -165,19 +141,16 @@ void tetris_bucket_destruct(tetris_bucket_t *pBucket)
void tetris_bucket_reset(tetris_bucket_t *pBucket) void tetris_bucket_reset(tetris_bucket_t *pBucket)
{ {
assert(pBucket != NULL); assert(pBucket != NULL);
assert(pBucket->dump != NULL);
pBucket->pPiece = NULL; pBucket->pPiece = NULL;
pBucket->nColumn = 0; pBucket->nColumn = 0;
pBucket->nRow = 0; pBucket->nRow = 0;
pBucket->nRowMask = 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; pBucket->status = TETRIS_BUS_READY;
// clear dump
memset(pBucket->dump, 0, pBucket->nHeight * sizeof(uint16_t));
} }

View File

@ -88,7 +88,13 @@ tetris_bucket_t *tetris_bucket_construct(int8_t nWidth,
* destructs a bucket * destructs a bucket
* @param pBucket pointer to the bucket to be destructed * @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);
}
/******************************* /*******************************

View File

@ -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 * * input related functions *
***************************/ ***************************/

View File

@ -152,7 +152,11 @@ tetris_input_t *tetris_input_construct(void);
* destructs an input object * destructs an input object
* @param pIn pointer to the input object which should be destructed * @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);
}
/*************************** /***************************

View File

@ -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 * * piece related functions *
****************************/ ****************************/

View File

@ -84,7 +84,11 @@ tetris_piece_t *tetris_piece_construct(tetris_piece_shape_t s,
* destructs a piece * destructs a piece
* @param pPc pointer to the piece to be destructed * @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);
}
/*************************** /***************************

View File

@ -14,8 +14,7 @@
void tetris_main(tetris_variant_t const *const pVariantMethods) void tetris_main(tetris_variant_t const *const pVariantMethods)
{ {
// get view dependent dimensions of the bucket // get view dependent dimensions of the bucket
int8_t nWidth; int8_t nWidth, nHeight;
int8_t nHeight;
tetris_view_getDimensions(&nWidth, &nHeight); tetris_view_getDimensions(&nWidth, &nHeight);
// holds the current user command which should be processed // 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 the game still runs, reward the player with extra points
if (tetris_bucket_getStatus(pBucket) != TETRIS_BUS_GAMEOVER) if (tetris_bucket_getStatus(pBucket) != TETRIS_BUS_GAMEOVER)
{ {
pVariantMethods->singleDrop(pVariantData, 1); pVariantMethods->singleDrop(pVariantData);
} }
break; break;

View File

@ -322,14 +322,8 @@ void tetris_bastet_destruct(void *pVariantData)
assert(pVariantData != 0); assert(pVariantData != 0);
tetris_bastet_variant_t *pBastetVariant = tetris_bastet_variant_t *pBastetVariant =
(tetris_bastet_variant_t *)pVariantData; (tetris_bastet_variant_t *)pVariantData;
if (pBastetVariant->pColScore != NULL)
{
free(pBastetVariant->pColScore); free(pBastetVariant->pColScore);
}
if (pBastetVariant->pColHeights != NULL)
{
free(pBastetVariant->pColHeights); free(pBastetVariant->pColHeights);
}
if (pBastetVariant->pPreviewPiece != NULL) if (pBastetVariant->pPreviewPiece != NULL)
{ {
tetris_piece_destruct(pBastetVariant->pPreviewPiece); tetris_piece_destruct(pBastetVariant->pPreviewPiece);
@ -394,8 +388,7 @@ tetris_piece_t* tetris_bastet_choosePiece(void *pVariantData)
} }
void tetris_bastet_singleDrop(void *pVariantData, void tetris_bastet_singleDrop(void *pVariantData)
uint8_t nLines)
{ {
return; return;
} }

View File

@ -92,10 +92,8 @@ tetris_piece_t* tetris_bastet_choosePreviewPiece(void *pBastet);
/** /**
* add points which result from single step dropping * add points which result from single step dropping
* @param pVariantData the variant data object we want to modify * @param pVariantData the variant data object we want to modify
* @param nLines the number of rows involved
*/ */
void tetris_bastet_singleDrop(void *pVariantData, void tetris_bastet_singleDrop(void *pVariantData);
uint8_t nLines);
/** /**

View File

@ -118,13 +118,12 @@ tetris_piece_t* tetris_std_choosePiece(void *pVariantData)
} }
void tetris_std_singleDrop(void *pVariantData, void tetris_std_singleDrop(void *pVariantData)
uint8_t nLines)
{ {
assert(pVariantData != 0); assert(pVariantData != 0);
tetris_standard_variant_t *pStdVariant = tetris_standard_variant_t *pStdVariant =
(tetris_standard_variant_t *)pVariantData; (tetris_standard_variant_t *)pVariantData;
pStdVariant->nScore += nLines; ++pStdVariant->nScore;
} }

View File

@ -76,10 +76,8 @@ tetris_piece_t* tetris_std_choosePiece(void *pVariantData);
/** /**
* add points which result from single step dropping * add points which result from single step dropping
* @param pVariantData the variant data object we want to modify * @param pVariantData the variant data object we want to modify
* @param nLines the number of rows involved
*/ */
void tetris_std_singleDrop(void *pVariantData, void tetris_std_singleDrop(void *pVariantData);
uint8_t nLines);
/** /**

View File

@ -36,11 +36,8 @@ typedef struct tetris_variant_t
/** /**
* add points which result from single step dropping * add points which result from single step dropping
* @param pVariantData the variant data object we want to modify * @param pVariantData the variant data object we want to modify
* @param nLines the number of rows involved
*/ */
void (*singleDrop)(void *pVariantData, void (*singleDrop)(void *pVariantData);
uint8_t nLines);
/** /**
* add points which result from a complete drop * add points which result from a complete drop

View File

@ -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 * * view related functions *
***************************/ ***************************/

View File

@ -67,7 +67,11 @@ tetris_view_t *tetris_view_construct(tetris_variant_t const *const pVarMethods,
* destructs a view * destructs a view
* @param pView: pointer to the view to be destructed * @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);
}
/*************************** /***************************