Browse Source

using unsigned literals produces better code regarding modulo operations

feature/2015
Christian Kroll 13 years ago
parent
commit
c3bd8e0913
  1. 36
      animations/config.in
  2. 27
      games/snake/snake_game.c

36
animations/config.in

@ -5,41 +5,43 @@ comment "Animations"
bool "Joern1" ANIMATION_JOERN1 bool "Joern1" ANIMATION_JOERN1
dep_bool_menu "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT dep_bool_menu "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT
int "Snake round delay" SNAKE_CYCLE_DELAY 100 int "Snake round delay" SNAKE_CYCLE_DELAY 100
int "Snake termination delay" SNAKE_TERMINATION_DELAY 60 int "Snake termination delay" SNAKE_TERMINATION_DELAY 60
int "Snake max length" SNAKE_MAX_LENGTH 64 uint "Snake max length" SNAKE_MAX_LENGTH 64
int "Snake max apples" SNAKE_MAX_APPLES 10 int "Snake max apples" SNAKE_MAX_APPLES 10
endmenu endmenu
bool "Schachbrett" ANIMATION_SCHACHBRETT bool "Schachbrett" ANIMATION_SCHACHBRETT
dep_bool_menu "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT dep_bool_menu "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT
int "FEUER_S" FEUER_S 30 int "FEUER_S" FEUER_S 30
int "FEUER_N" FEUER_N 5 int "FEUER_N" FEUER_N 5
int "FEUER_DIV" FEUER_DIV 44 int "FEUER_DIV" FEUER_DIV 44
int "FEUER_DELAY" FEUER_DELAY 50 int "FEUER_DELAY" FEUER_DELAY 50
int "Fire number of cycles" FIRE_CYCLES 800 int "Fire number of cycles" FIRE_CYCLES 800
endmenu endmenu
dep_bool_menu "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT dep_bool_menu "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT
int "Number of streamers" MATRIX_STREAMER_NUM 30 int "Number of streamers" MATRIX_STREAMER_NUM 30
int "Run for this number of rounds" MATRIX_CYCLES 500 int "Run for this number of rounds" MATRIX_CYCLES 500
endmenu endmenu
dep_bool "Random Bright" ANIMATION_RANDOM_BRIGHT $RANDOM_SUPPORT dep_bool "Random Bright" ANIMATION_RANDOM_BRIGHT $RANDOM_SUPPORT
dep_bool "Stonefly" ANIMATION_STONEFLY $GAME_TETRIS_CORE dep_bool "Stonefly" ANIMATION_STONEFLY $GAME_TETRIS_CORE
dep_bool "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT dep_bool "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT
dep_bool_menu "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT dep_bool_menu "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT
int "Game of Life round delay (ms)" GOL_DELAY 100 int "Game of Life round delay (ms)" GOL_DELAY 100
int "Game of Life max rounds" GOL_CYCLES 360 int "Game of Life max rounds" GOL_CYCLES 360
endmenu endmenu
dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT
bool "Martin Herweg" ANIMATION_MHERWEG $RANDOM_SUPPORT dep_bool "Martin Herweg" ANIMATION_MHERWEG $RANDOM_SUPPORT
dep_bool "Langton Ant" ANIMATION_LTN_ANT $RANDOM_SUPPORT dep_bool "Langton Ant" ANIMATION_LTN_ANT $RANDOM_SUPPORT
dep_bool_menu "Time Display" ANIMATION_TIME $SCROLLTEXT_SUPPORT $LAP_TIME_EXTENSION dep_bool_menu "Time Display" ANIMATION_TIME $SCROLLTEXT_SUPPORT $LAP_TIME_EXTENSION
int "Time master address (int)" TIME_MASTER_ADDR 00 int "Time master address (int)" TIME_MASTER_ADDR 00
int "Request timeout (ms)" TIME_UPDATE_TIMEOUT 50 int "Request timeout (ms)" TIME_UPDATE_TIMEOUT 50
endmenu endmenu
dep_bool_menu "Bitmap Scroller" ANIMATION_BMSCROLLER y $RANDOM_SUPPORT dep_bool_menu "Bitmap Scroller" ANIMATION_BMSCROLLER y $RANDOM_SUPPORT

27
games/snake/snake_game.c

@ -27,10 +27,13 @@ game_descriptor_t snake_game_descriptor __attribute__((section(".game_descriptor
#define SNAKE_NEWCONTROL #define SNAKE_NEWCONTROL
// limits // limits
#ifndef SNAKE_MAX_LENGTH #ifndef USNAKE_MAX_LENGTH
#define SNAKE_MAX_LENGTH 64u #define USNAKE_MAX_LENGTH 64u
#endif
#ifndef SNAKE_MAX_APPLES
#define SNAKE_MAX_APPLES 10
#endif #endif
#define SNAKE_MAX_APPLES 10
// delays (in milliseconds) // delays (in milliseconds)
#ifndef SNAKE_CYCLE_DELAY #ifndef SNAKE_CYCLE_DELAY
@ -69,10 +72,10 @@ enum snake_dir
*/ */
typedef struct snake_protagonist typedef struct snake_protagonist
{ {
pixel aSegments[SNAKE_MAX_LENGTH]; /**< All segments of the snake. */ pixel aSegments[USNAKE_MAX_LENGTH]; /**< All segments of the snake. */
uint8_t nHeadIndex; /**< Index of the head segment. */ uint8_t nHeadIndex; /**< Index of the head segment. */
uint8_t nTailIndex; /**< Index of the tail segment. */ uint8_t nTailIndex; /**< Index of the tail segment. */
snake_dir_t dir; /**< Direction of the snake. */ snake_dir_t dir; /**< Direction of the snake. */
} snake_protagonist_t; } snake_protagonist_t;
@ -166,8 +169,8 @@ static snake_dir_t snake_queryJoystick(void)
*/ */
static void snake_initGameProtagonist(snake_protagonist_t *pprotSnake) static void snake_initGameProtagonist(snake_protagonist_t *pprotSnake)
{ {
pprotSnake->aSegments[0] = (pixel){4, NUM_ROWS - 2}; pprotSnake->aSegments[0] = (pixel){NUM_COLS / 2, NUM_ROWS / 2};
pprotSnake->aSegments[1] = (pixel){4, NUM_ROWS - 3}; pprotSnake->aSegments[1] = (pixel){NUM_COLS / 2, NUM_ROWS / 2 - 1};
pprotSnake->nTailIndex = 0; pprotSnake->nTailIndex = 0;
pprotSnake->nHeadIndex = 1; pprotSnake->nHeadIndex = 1;
pprotSnake->dir = SNAKE_DIR_UP; pprotSnake->dir = SNAKE_DIR_UP;
@ -299,7 +302,7 @@ static void snake_eliminateProtagonist(snake_protagonist_t *pprotSnake)
while (pprotSnake->nTailIndex != pprotSnake->nHeadIndex) while (pprotSnake->nTailIndex != pprotSnake->nHeadIndex)
{ {
clearpixel(pprotSnake->aSegments[pprotSnake->nTailIndex++]); clearpixel(pprotSnake->aSegments[pprotSnake->nTailIndex++]);
pprotSnake->nTailIndex %= SNAKE_MAX_LENGTH; pprotSnake->nTailIndex %= USNAKE_MAX_LENGTH;
wait(SNAKE_TERMINATION_DELAY); wait(SNAKE_TERMINATION_DELAY);
} }
} }
@ -394,7 +397,7 @@ void snake_engine(uint8_t bDemoMode)
// actually move head // actually move head
pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex]; pixel pxOldHead = protSnake.aSegments[protSnake.nHeadIndex];
protSnake.nHeadIndex = (protSnake.nHeadIndex + 1) % SNAKE_MAX_LENGTH; protSnake.nHeadIndex = (protSnake.nHeadIndex + 1) % USNAKE_MAX_LENGTH;
protSnake.aSegments[protSnake.nHeadIndex] = protSnake.aSegments[protSnake.nHeadIndex] =
snake_applyDirection(pxOldHead, protSnake.dir); snake_applyDirection(pxOldHead, protSnake.dir);
@ -411,7 +414,7 @@ void snake_engine(uint8_t bDemoMode)
// remove last segment // remove last segment
clearpixel(protSnake.aSegments[protSnake.nTailIndex]) clearpixel(protSnake.aSegments[protSnake.nTailIndex])
protSnake.nTailIndex = (protSnake.nTailIndex +1) % SNAKE_MAX_LENGTH; protSnake.nTailIndex = (protSnake.nTailIndex +1) % USNAKE_MAX_LENGTH;
// new apples // new apples
snake_spawnApples(&apples); snake_spawnApples(&apples);

Loading…
Cancel
Save