From 291c90ccf63d17089aba8275770308df712ab538 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Sun, 6 Feb 2011 22:56:26 +0000 Subject: [PATCH] squeezed another 80 bytes --- games/tetris/bucket.c | 57 +++++++++-------------------------- games/tetris/bucket.h | 8 ++++- games/tetris/input.c | 7 ----- games/tetris/input.h | 6 +++- games/tetris/piece.c | 7 ----- games/tetris/piece.h | 6 +++- games/tetris/tetris_main.c | 5 ++- games/tetris/variant_bastet.c | 13 ++------ games/tetris/variant_bastet.h | 4 +-- games/tetris/variant_std.c | 5 ++- games/tetris/variant_std.h | 4 +-- games/tetris/variants.h | 5 +-- games/tetris/view.c | 7 ----- games/tetris/view.h | 6 +++- 14 files changed, 47 insertions(+), 93 deletions(-) diff --git a/games/tetris/bucket.c b/games/tetris/bucket.c index 580ca7a..c5515d2 100644 --- a/games/tetris/bucket.c +++ b/games/tetris/bucket.c @@ -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)); + assert(pBucket != NULL); + pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t)); + assert(pBucket->dump != NULL); - if (pBucket != NULL) - { - // allocating memory for dump array - pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t)); + // setting requested attributes + pBucket->nHeight = pBucket->nFirstTaintedRow = nHeight; + pBucket->nWidth = nWidth; - 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); + // bit mask of a full row + pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth); - tetris_bucket_reset(pBucket); + tetris_bucket_reset(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); + 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)); } diff --git a/games/tetris/bucket.h b/games/tetris/bucket.h index bccbd99..b4849c8 100644 --- a/games/tetris/bucket.h +++ b/games/tetris/bucket.h @@ -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); +} /******************************* diff --git a/games/tetris/input.c b/games/tetris/input.c index 4e63012..47f203c 100644 --- a/games/tetris/input.c +++ b/games/tetris/input.c @@ -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 * ***************************/ diff --git a/games/tetris/input.h b/games/tetris/input.h index d8a2e02..565c7f7 100644 --- a/games/tetris/input.h +++ b/games/tetris/input.h @@ -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); +} /*************************** diff --git a/games/tetris/piece.c b/games/tetris/piece.c index a12ed68..4be2adf 100644 --- a/games/tetris/piece.c +++ b/games/tetris/piece.c @@ -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 * ****************************/ diff --git a/games/tetris/piece.h b/games/tetris/piece.h index 70ca93c..77d1967 100644 --- a/games/tetris/piece.h +++ b/games/tetris/piece.h @@ -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); +} /*************************** diff --git a/games/tetris/tetris_main.c b/games/tetris/tetris_main.c index e60cc2f..fa0220d 100644 --- a/games/tetris/tetris_main.c +++ b/games/tetris/tetris_main.c @@ -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; diff --git a/games/tetris/variant_bastet.c b/games/tetris/variant_bastet.c index 17b66dd..9005896 100644 --- a/games/tetris/variant_bastet.c +++ b/games/tetris/variant_bastet.c @@ -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; } diff --git a/games/tetris/variant_bastet.h b/games/tetris/variant_bastet.h index a99f378..bd25295 100644 --- a/games/tetris/variant_bastet.h +++ b/games/tetris/variant_bastet.h @@ -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); /** diff --git a/games/tetris/variant_std.c b/games/tetris/variant_std.c index f641752..02b61d2 100644 --- a/games/tetris/variant_std.c +++ b/games/tetris/variant_std.c @@ -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; } diff --git a/games/tetris/variant_std.h b/games/tetris/variant_std.h index 2d6b611..f062eab 100644 --- a/games/tetris/variant_std.h +++ b/games/tetris/variant_std.h @@ -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); /** diff --git a/games/tetris/variants.h b/games/tetris/variants.h index 1814e10..ef58c35 100644 --- a/games/tetris/variants.h +++ b/games/tetris/variants.h @@ -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 diff --git a/games/tetris/view.c b/games/tetris/view.c index a1dcb2b..0f0ce5a 100644 --- a/games/tetris/view.c +++ b/games/tetris/view.c @@ -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 * ***************************/ diff --git a/games/tetris/view.h b/games/tetris/view.h index 7d62929..d7b59e1 100644 --- a/games/tetris/view.h +++ b/games/tetris/view.h @@ -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); +} /***************************