From 7e9d6ebf956e64a573b363432fb9c3b45f29b141 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 8 Dec 2024 12:03:22 +0100 Subject: [PATCH] improved code readability regarding calculation precedence --- src/game.c | 16 ++++++++-------- src/game_sp/Input.c | 16 ++++++++-------- src/libgame/sdl.c | 6 +++--- src/libgame/sound.c | 4 ++-- src/screens.c | 2 +- src/tape.c | 22 +++++++++++----------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/game.c b/src/game.c index ee067b8a..af54fecc 100644 --- a/src/game.c +++ b/src/game.c @@ -5582,8 +5582,8 @@ static void InitMovingField(int x, int y, int direction) void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y) { int direction = MovDir[x][y]; - int newx = x + (direction & MV_LEFT ? -1 : direction & MV_RIGHT ? +1 : 0); - int newy = y + (direction & MV_UP ? -1 : direction & MV_DOWN ? +1 : 0); + int newx = x + ((direction & MV_LEFT) ? -1 : (direction & MV_RIGHT) ? +1 : 0); + int newy = y + ((direction & MV_UP) ? -1 : (direction & MV_DOWN) ? +1 : 0); *goes_to_x = newx; *goes_to_y = newy; @@ -5592,8 +5592,8 @@ void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y) void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y) { int direction = MovDir[x][y]; - int oldx = x + (direction & MV_LEFT ? +1 : direction & MV_RIGHT ? -1 : 0); - int oldy = y + (direction & MV_UP ? +1 : direction & MV_DOWN ? -1 : 0); + int oldx = x + ((direction & MV_LEFT) ? +1 : (direction & MV_RIGHT) ? -1 : 0); + int oldy = y + ((direction & MV_UP) ? +1 : (direction & MV_DOWN) ? -1 : 0); *comes_from_x = oldx; *comes_from_y = oldy; @@ -13091,8 +13091,8 @@ static boolean canFallDown(struct PlayerInfo *player) static boolean canPassField(int x, int y, int move_dir) { int opposite_dir = MV_DIR_OPPOSITE(move_dir); - int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0); - int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0); + int dx = ((move_dir & MV_LEFT) ? -1 : (move_dir & MV_RIGHT) ? +1 : 0); + int dy = ((move_dir & MV_UP) ? -1 : (move_dir & MV_DOWN) ? +1 : 0); int nextx = x + dx; int nexty = y + dy; int element = Tile[x][y]; @@ -13107,8 +13107,8 @@ static boolean canPassField(int x, int y, int move_dir) static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir) { int opposite_dir = MV_DIR_OPPOSITE(move_dir); - int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0); - int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0); + int dx = ((move_dir & MV_LEFT) ? -1 : (move_dir & MV_RIGHT) ? +1 : 0); + int dy = ((move_dir & MV_UP) ? -1 : (move_dir & MV_DOWN) ? +1 : 0); int newx = x + dx; int newy = y + dy; diff --git a/src/game_sp/Input.c b/src/game_sp/Input.c index 5a469575..f800492e 100644 --- a/src/game_sp/Input.c +++ b/src/game_sp/Input.c @@ -9,17 +9,17 @@ int map_key_RND_to_SP(int key) { if (key & KEY_BUTTON) { - return (key & MV_UP ? keySpaceUp : - key & MV_LEFT ? keySpaceLeft : - key & MV_DOWN ? keySpaceDown : - key & MV_RIGHT ? keySpaceRight : keySpace); + return ((key & MV_UP) ? keySpaceUp : + (key & MV_LEFT) ? keySpaceLeft : + (key & MV_DOWN) ? keySpaceDown : + (key & MV_RIGHT) ? keySpaceRight : keySpace); } else { - return (key & MV_UP ? keyUp : - key & MV_LEFT ? keyLeft : - key & MV_DOWN ? keyDown : - key & MV_RIGHT ? keyRight : keyNone); + return ((key & MV_UP) ? keyUp : + (key & MV_LEFT) ? keyLeft : + (key & MV_DOWN) ? keyDown : + (key & MV_RIGHT) ? keyRight : keyNone); } } diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index d664eecc..e401a65c 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -3084,10 +3084,10 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha) if (draw_outlined) { int rect_x = rect.x + - (outline_border & MV_LEFT ? border_size : 0); + ((outline_border & MV_LEFT) ? border_size : 0); int rect_w = rect.w - - (outline_border & MV_LEFT ? border_size : 0) - - (outline_border & MV_RIGHT ? border_size : 0); + ((outline_border & MV_LEFT) ? border_size : 0) - + ((outline_border & MV_RIGHT) ? border_size : 0); if (outline_border & MV_LEFT) RenderFillRectangle(rect.x, rect.y, border_size, rect.h); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 5f497c38..53a05444 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -59,9 +59,9 @@ #define SOUND_VOLUME_LOOPS(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops) #define SOUND_VOLUME_MUSIC(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music) -#define SETUP_SOUND_VOLUME(v, s) ((s) & SND_CTRL_MUSIC ? \ +#define SETUP_SOUND_VOLUME(v, s) (((s) & SND_CTRL_MUSIC) ? \ SOUND_VOLUME_MUSIC(v) : \ - (s) & SND_CTRL_LOOP ? \ + ((s) & SND_CTRL_LOOP) ? \ SOUND_VOLUME_LOOPS(v) : \ SOUND_VOLUME_SIMPLE(v)) diff --git a/src/screens.c b/src/screens.c index 478d5738..d6dda4ac 100644 --- a/src/screens.c +++ b/src/screens.c @@ -8981,7 +8981,7 @@ static int getSetupValueFont(int type, void *value) if (type & TYPE_GHOSTED) return FONT_OPTION_OFF; else if (type & TYPE_KEY) - return (type & TYPE_QUERY ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1); + return ((type & TYPE_QUERY) ? FONT_INPUT_1_ACTIVE : FONT_VALUE_1); else if (type & TYPE_STRING) return FONT_VALUE_2; else if (type & TYPE_ECS_AGA) diff --git a/src/tape.c b/src/tape.c index be363da0..9d729799 100644 --- a/src/tape.c +++ b/src/tape.c @@ -305,8 +305,8 @@ static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value) pos->y == -1) continue; - xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset : - type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0); + xpos = VX + pos->x + ((type & DATETIME_XOFFSET_1) ? pos->xoffset : + (type & DATETIME_XOFFSET_2) ? pos->xoffset2 : 0); ypos = VY + pos->y; if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON)) @@ -319,11 +319,11 @@ static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value) int month = month_index + 1; int day = value % 100; - strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) : - type & DATETIME_DATE_YY ? int2str(year2, 2) : - type & DATETIME_DATE_MON ? month_shortnames[month_index] : - type & DATETIME_DATE_MM ? int2str(month, 2) : - type & DATETIME_DATE_DD ? int2str(day, 2) : "")); + strcpy(s, ((type & DATETIME_DATE_YYYY) ? int2str(year4, 4) : + (type & DATETIME_DATE_YY) ? int2str(year2, 2) : + (type & DATETIME_DATE_MON) ? month_shortnames[month_index] : + (type & DATETIME_DATE_MM) ? int2str(month, 2) : + (type & DATETIME_DATE_DD) ? int2str(day, 2) : "")); DrawText(xpos, ypos, s, pos->font); } @@ -335,10 +335,10 @@ static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value) int mm = (value / 60) % 60; int ss = value % 60; - strcpy(s, (type & DATETIME_TIME_HH ? int2str(hh, 2) : - type & DATETIME_TIME_MIN ? int2str(min, 2) : - type & DATETIME_TIME_MM ? int2str(mm, 2) : - type & DATETIME_TIME_SS ? int2str(ss, 2) : "")); + strcpy(s, ((type & DATETIME_TIME_HH) ? int2str(hh, 2) : + (type & DATETIME_TIME_MIN) ? int2str(min, 2) : + (type & DATETIME_TIME_MM) ? int2str(mm, 2) : + (type & DATETIME_TIME_SS) ? int2str(ss, 2) : "")); DrawText(xpos, ypos, s, pos->font); } -- 2.34.1