using unsigned literals produces better code regarding modulo operations
This commit is contained in:
parent
d4cbcb9b7b
commit
c3bd8e0913
|
@ -7,7 +7,7 @@ comment "Animations"
|
||||||
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
|
||||||
|
|
||||||
|
@ -29,12 +29,14 @@ comment "Animations"
|
||||||
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
|
||||||
|
|
|
@ -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
|
#endif
|
||||||
|
|
||||||
|
#ifndef SNAKE_MAX_APPLES
|
||||||
#define SNAKE_MAX_APPLES 10
|
#define SNAKE_MAX_APPLES 10
|
||||||
|
#endif
|
||||||
|
|
||||||
// delays (in milliseconds)
|
// delays (in milliseconds)
|
||||||
#ifndef SNAKE_CYCLE_DELAY
|
#ifndef SNAKE_CYCLE_DELAY
|
||||||
|
@ -69,7 +72,7 @@ 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. */
|
||||||
|
@ -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…
Reference in New Issue