Browse Source

squeezed another 80 bytes

feature/2015
Christian Kroll 14 years ago
parent
commit
291c90ccf6
  1. 57
      games/tetris/bucket.c
  2. 8
      games/tetris/bucket.h
  3. 7
      games/tetris/input.c
  4. 6
      games/tetris/input.h
  5. 7
      games/tetris/piece.c
  6. 6
      games/tetris/piece.h
  7. 5
      games/tetris/tetris_main.c
  8. 13
      games/tetris/variant_bastet.c
  9. 4
      games/tetris/variant_bastet.h
  10. 5
      games/tetris/variant_std.c
  11. 4
      games/tetris/variant_std.h
  12. 5
      games/tetris/variants.h
  13. 7
      games/tetris/view.c
  14. 6
      games/tetris/view.h

57
games/tetris/bucket.c

@ -114,47 +114,23 @@ 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);
pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t));
assert(pBucket->dump != NULL);
if (pBucket != NULL) // setting requested attributes
{ pBucket->nHeight = pBucket->nFirstTaintedRow = nHeight;
// allocating memory for dump array pBucket->nWidth = nWidth;
pBucket->dump = (uint16_t*) calloc(nHeight, sizeof(uint16_t));
if (pBucket->dump != NULL) // bit mask of a full row
{ pBucket->nFullRow = 0xFFFF >> (16 - pBucket->nWidth);
// 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); tetris_bucket_reset(pBucket);
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));
} }

8
games/tetris/bucket.h

@ -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);
}
/******************************* /*******************************

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

6
games/tetris/input.h

@ -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);
}
/*************************** /***************************

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

6
games/tetris/piece.h

@ -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);
}
/*************************** /***************************

5
games/tetris/tetris_main.c

@ -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;

13
games/tetris/variant_bastet.c

@ -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->pColHeights);
free(pBastetVariant->pColScore);
}
if (pBastetVariant->pColHeights != NULL)
{
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;
} }

4
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 * 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);
/** /**

5
games/tetris/variant_std.c

@ -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;
} }

4
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 * 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);
/** /**

5
games/tetris/variants.h

@ -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

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

6
games/tetris/view.h

@ -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);
}
/*************************** /***************************

Loading…
Cancel
Save