diff options
| author | 2024-10-24 14:47:35 -0400 | |
|---|---|---|
| committer | 2024-10-24 14:47:35 -0400 | |
| commit | e6b1631d27f9fe54f3cdd3d7ee1e65d726927e3c (patch) | |
| tree | 188853796d25d53c1dbf1296ab29d18bfa7613b3 | |
| parent | f85bfe4cfdc6b03ff66a874d4d1028e291bccda4 (diff) | |
| download | cetris-e6b1631d27f9fe54f3cdd3d7ee1e65d726927e3c.tar.gz cetris-e6b1631d27f9fe54f3cdd3d7ee1e65d726927e3c.tar.bz2 cetris-e6b1631d27f9fe54f3cdd3d7ee1e65d726927e3c.zip | |
consistent formatting plus cleanup
| -rwxr-xr-x | .clang-format | 127 | ||||
| -rw-r--r-- | .editorconfig | 11 | ||||
| -rw-r--r--[-rwxr-xr-x] | .gitignore | 3 | ||||
| -rw-r--r--[-rwxr-xr-x] | LICENSE | 0 | ||||
| -rwxr-xr-x | lib/cetris.h | 382 | ||||
| -rwxr-xr-x | lib/meson.build | 10 | ||||
| -rwxr-xr-x | lib/rules.h | 8 | ||||
| -rw-r--r--[-rwxr-xr-x] | lib/test.h | 0 | ||||
| -rwxr-xr-x | meson.build | 34 | ||||
| -rwxr-xr-x | meson_options.txt | 3 | ||||
| -rw-r--r--[-rwxr-xr-x] | notes.txt | 10 | ||||
| -rwxr-xr-x | test/line_count.sh | 6 | ||||
| -rwxr-xr-x | test/memory_test.c | 4 | ||||
| -rwxr-xr-x | test/meson.build | 4 | ||||
| -rwxr-xr-x | test/sdl_audio.c | 12 |
15 files changed, 224 insertions, 390 deletions
diff --git a/.clang-format b/.clang-format deleted file mode 100755 index 838938d..0000000 --- a/.clang-format +++ /dev/null @@ -1,127 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Right -AlignOperands: true -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: false -IndentPPDirectives: None -IndentWidth: 2 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseTab: Never -... - diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1f473a9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[/.git/**] +max_line_length = unset + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index 1b2211d..31e83e4 100755..100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build* +.cache/ +build*/ diff --git a/lib/cetris.h b/lib/cetris.h index 6f3ea77..a400779 100755 --- a/lib/cetris.h +++ b/lib/cetris.h @@ -18,12 +18,12 @@ typedef struct typedef unsigned char ctrs_matrix[4]; -enum +enum { CTRS_SLOT_OCCUPIED = 1, }; -typedef enum +typedef enum { MINO_Z, MINO_L, @@ -35,14 +35,14 @@ typedef enum } ctrs_mino_type; typedef enum -{ - INIT, - ONCE_RIGHT, - TWICE, - ONCE_LEFT +{ + INIT, + ONCE_RIGHT, + TWICE, + ONCE_LEFT } ctrs_srs; -typedef enum +typedef enum { DOWN, RIGHT, @@ -52,14 +52,14 @@ typedef enum HARD_DROP } ctrs_dir; -typedef struct +typedef struct { ctrs_vec2 pos; ctrs_matrix m; ctrs_mino_type t; ctrs_srs r; - bool locked; + bool locked; bool held; unsigned long lock_tick; @@ -68,7 +68,7 @@ typedef struct char ghost_y; } ctrs_mino; -typedef struct +typedef struct { ctrs_vec2 pos; ctrs_matrix m; @@ -79,7 +79,7 @@ typedef struct typedef struct ctrs_game ctrs_game; -typedef struct +typedef struct { unsigned long drop_period; unsigned long next_piece_delay; @@ -88,10 +88,10 @@ typedef struct unsigned long force_lock; #if CETRIS_ENABLE_DAS - unsigned long das_arr; + unsigned long das_arr; unsigned long das_das; #endif - + unsigned char board_x; unsigned char board_y; unsigned char board_visible; @@ -185,11 +185,11 @@ struct ctrs_game { const ctrs_matrix ctrs_default_matrices[7] = { - { 0b0000, 0b1100, 0b0110, 0b0000}, + { 0b0000, 0b1100, 0b0110, 0b0000}, { 0b0000, 0b0010, 0b1110, 0b0000}, - { 0b0000, 0b0110, 0b0110, 0b0000}, + { 0b0000, 0b0110, 0b0110, 0b0000}, { 0b0000, 0b0110, 0b1100, 0b0000}, - { 0b0000, 0b1111, 0b0000, 0b0000}, + { 0b0000, 0b1111, 0b0000, 0b0000}, { 0b0000, 0b1000, 0b1110, 0b0000}, { 0b0000, 0b0100, 0b1110, 0b0000} }; @@ -218,12 +218,12 @@ static const ctrs_vec2 srs_wall_kicks_i[8][5] = { }; static const ctrs_vec2 basic_movements[3] = { - {0, 1}, {1, 0}, {-1, 0} // DOWN, RIGHT, LEFT + {0, 1}, {1, 0}, {-1, 0} // DOWN, RIGHT, LEFT }; static void update_board(ctrs_game *g); -static void +static void set_piece(ctrs_game *g, unsigned char type, ctrs_mino* mino) { memset(mino, 0, sizeof(ctrs_mino)); @@ -240,11 +240,11 @@ set_piece(ctrs_game *g, unsigned char type, ctrs_mino* mino) if (type == MINO_I) mino->pos.y++; } -static inline void +static inline void shuffle_queue(ctrs_game *g) { unsigned char i, r, t; - for (i = 0; i < 7; i++) + for (i = 0; i < 7; i++) { r = rand() % 7; t = g->next_queue[i]; @@ -254,24 +254,26 @@ shuffle_queue(ctrs_game *g) } } -static inline int -check_matrix(ctrs_game *g, ctrs_matrix *m) +static inline int +check_matrix(ctrs_game *g, ctrs_matrix *m) { ctrs_vec2 r; for (int j = 0; j < 4; j++) - for (int s = 0; s < 4; s++) { - r = (ctrs_vec2){j + g->current.pos.x, s + g->current.pos.y}; - if (r.y < 0) continue; - if (((*m)[s]>>(3 - j))&1) + for (int s = 0; s < 4; s++) { - if (r.x >= g->config.board_x || r.x < 0) - return 0; - if (r.y >= g->config.board_y) - return -1; - if (g->board[r.x][r.y] & CTRS_SLOT_OCCUPIED) - return -1; + r = (ctrs_vec2){j + g->current.pos.x, s + g->current.pos.y}; + if (r.y < 0) continue; + if (((*m)[s]>>(3 - j))&1) + { + if (r.x >= g->config.board_x || r.x < 0) + return 0; + if (r.y >= g->config.board_y) + return -1; + if (g->board[(unsigned char)r.x][(unsigned char)r.y] & CTRS_SLOT_OCCUPIED) + return -1; + } } } @@ -279,82 +281,82 @@ check_matrix(ctrs_game *g, ctrs_matrix *m) } // TODO: hard score -static void -add_score(ctrs_game *g, int lines) +static void +add_score(ctrs_game *g, int lines) { - if (!g->tspin && !g->mini_tspin) + if (!g->tspin && !g->mini_tspin) { - switch (lines) + switch (lines) { - case 1: - g->score += 100 * g->level; - break; - case 2: - g->score += 300 * g->level; - break; - case 3: - g->score += 500 * g->level; - break; - case 4: - g->score += 800 * g->level; - break; + case 1: + g->score += 100 * g->level; + break; + case 2: + g->score += 300 * g->level; + break; + case 3: + g->score += 500 * g->level; + break; + case 4: + g->score += 800 * g->level; + break; } } - else if (g->tspin) + else if (g->tspin) { switch (lines) { - case 0: - g->score += 400 * g->level; - break; - case 1: - g->score += 800 * g->level; - break; - case 2: - g->score += 1200 * g->level; - break; - case 3: - g->score += 1600 * g->level; - break; + case 0: + g->score += 400 * g->level; + break; + case 1: + g->score += 800 * g->level; + break; + case 2: + g->score += 1200 * g->level; + break; + case 3: + g->score += 1600 * g->level; + break; } g->tspin = false; - } - else if (g->mini_tspin) + } + else if (g->mini_tspin) { switch (lines) { - case 0: - g->score += 100 * g->level; - break; - case 1: - g->score += 200 * g->level; - break; - case 2: - g->score += 400 * g->level; - break; - } + case 0: + g->score += 100 * g->level; + break; + case 1: + g->score += 200 * g->level; + break; + case 2: + g->score += 400 * g->level; + break; + } g->mini_tspin = false; } } -static void -make_ghosts(ctrs_game *g) +static void +make_ghosts(ctrs_game *g) { int orig_y = g->current.pos.y; - while (check_matrix(g, &g->current.m) > 0) + while (check_matrix(g, &g->current.m) > 0) g->current.pos.y++; if (g->current.pos.y == orig_y) g->current.ghost_y = orig_y; - else + else g->current.ghost_y = g->current.pos.y - 1; - + g->current.pos.y = orig_y; } -static void -move_current(ctrs_game *g, unsigned char move) +static void +move_current(ctrs_game *g, unsigned char move) { if (g->game_over || g->next_piece_tick) return; @@ -368,18 +370,18 @@ move_current(ctrs_game *g, unsigned char move) g->current.pos.y -= basic_movements[move].y; g->current.pos.x -= basic_movements[move].x; - if (move == DOWN && check == -1) + if (move == DOWN && check == -1) { if (!g->current.force_lock_tick && g->config.force_lock) g->current.force_lock_tick = g->tick + g->config.force_lock; if (!g->current.lock_tick) g->current.lock_tick = g->tick + g->config.lock_delay; } - } - else + } + else { g->events.move_event++; - if (g->current.lock_tick) + if (g->current.lock_tick) g->current.lock_tick = g->tick + g->config.lock_delay; if (move == DOWN && g->held_moves[DOWN]) g->score++; @@ -388,7 +390,7 @@ move_current(ctrs_game *g, unsigned char move) update_board(g); } -static void +static void next_piece(ctrs_game *g) { g->next_drop_tick = 0; @@ -396,17 +398,17 @@ next_piece(ctrs_game *g) set_piece(g, g->piece_queue[g->current_index], &g->current); - if (check_matrix(g, &g->current.m) <= 0) + if (check_matrix(g, &g->current.m) <= 0) { g->game_over = true; g->events.stop_game = 1; } - if (!g->game_over) + if (!g->game_over) move_current(g, DOWN); - + g->current_index++; - if (g->current_index == 7) + if (g->current_index == 7) { g->current_index = 0; @@ -417,16 +419,18 @@ next_piece(ctrs_game *g) update_board(g); } -static void -lock_current(ctrs_game *g) +static void +lock_current(ctrs_game *g) { for (int j = 0; j < 4; j++) - for (int s = 0; s < 4; s++) { - if ((g->current.m[s]>>(3 - j))&1) + for (int s = 0; s < 4; s++) { - g->board[g->current.pos.x + j][g->current.pos.y + s] |= CTRS_SLOT_OCCUPIED; - g->board[g->current.pos.x + j][g->current.pos.y + s] |= g->current.t << 5; + if ((g->current.m[s]>>(3 - j))&1) + { + g->board[g->current.pos.x + j][g->current.pos.y + s] |= CTRS_SLOT_OCCUPIED; + g->board[g->current.pos.x + j][g->current.pos.y + s] |= g->current.t << 5; + } } } @@ -443,14 +447,14 @@ lock_current(ctrs_game *g) update_board(g); } -static void -hard_drop(ctrs_game *g) +static void +hard_drop(ctrs_game *g) { if (g->game_over || g->next_piece_tick) return; int drop_count = 0; - while (check_matrix(g, &g->current.m) > 0) + while (check_matrix(g, &g->current.m) > 0) { g->current.pos.y++; drop_count++; @@ -464,41 +468,43 @@ hard_drop(ctrs_game *g) lock_current(g); } -static inline void -rotate_matrix(ctrs_game *g, ctrs_matrix *m, bool clockwise) +static inline void +rotate_matrix(ctrs_game *g, ctrs_matrix *m, bool clockwise) { for (int j = 0; j < 4; j++) - for (int s = 0; s < 4; s++) { - if ((g->current.m[s]>>(3 - j))&1) + for (int s = 0; s < 4; s++) { - unsigned char new_x = (clockwise) ? 1 - (s - 2) : 1 + (s - 2); - unsigned char new_y = (clockwise) ? 2 + (j - 1) : 2 - (j - 1); + if ((g->current.m[s]>>(3 - j))&1) + { + unsigned char new_x = (clockwise) ? 1 - (s - 2) : 1 + (s - 2); + unsigned char new_y = (clockwise) ? 2 + (j - 1) : 2 - (j - 1); + + if (g->current.t == MINO_I) + clockwise ? new_y-- : new_x++; - if (g->current.t == MINO_I) - clockwise ? new_y-- : new_x++; - - (*m)[new_y] |= (unsigned char)0b1000 >> (new_x); + (*m)[new_y] |= (unsigned char)0b1000 >> (new_x); + } } } } -static void -rotate_piece(ctrs_game *g, bool clockwise) +static void +rotate_piece(ctrs_game *g, bool clockwise) { if (g->game_over || g->next_piece_tick) return; - + if (g->current.t == MINO_O) return; - + unsigned char next = 0, wall_kick = 0; - if (clockwise) + if (clockwise) { next = (g->current.r + 1) % 4; wall_kick = g->current.r * 2; - } - else + } + else { next = ((g->current.r - 1) + 4) % 4; wall_kick = (next * 2) + 1; @@ -513,15 +519,15 @@ rotate_piece(ctrs_game *g, bool clockwise) bool set_current = false, did_kick = false; for (int i = 0; i < 4; i++) { - if (g->current.t == MINO_I) + if (g->current.t == MINO_I) kick = srs_wall_kicks_i[wall_kick][i]; - else + else kick = srs_wall_kicks[wall_kick][i]; g->current.pos.x += kick.x; g->current.pos.y -= kick.y; - if (check_matrix(g, &m) > 0) + if (check_matrix(g, &m) > 0) { set_current = true; if (i > 0) did_kick = true; @@ -532,13 +538,13 @@ rotate_piece(ctrs_game *g, bool clockwise) g->current.pos.y += kick.y; } - if (set_current) + if (set_current) { /* check for tspin */ - if (g->current.t == MINO_T) + if (g->current.t == MINO_T) { bool did_tspin = true; - for (int i = 1; i < 3; i++) + for (int i = 1; i < 3; i++) { g->current.pos.x += basic_movements[i].x; g->current.pos.y += basic_movements[i].y; @@ -550,7 +556,7 @@ rotate_piece(ctrs_game *g, bool clockwise) g->current.pos.y -= basic_movements[i].y; } - if (did_tspin) + if (did_tspin) { if (did_kick) g->mini_tspin = true; else g->tspin = true; @@ -566,72 +572,74 @@ rotate_piece(ctrs_game *g, bool clockwise) } } -static inline void -clear_line(ctrs_game *g, int y) +static inline void +clear_line(ctrs_game *g, int y) { for (int s = y - 1; s >= 0; s--) - for (int x = 0; x < g->config.board_x; x++) - g->board[x][s + 1] = g->board[x][s]; + { + for (int x = 0; x < g->config.board_x; x++) + g->board[x][s + 1] = g->board[x][s]; + } } -static void +static void update_board(ctrs_game *g) { if (g->game_over) return; int lines_cleared = 0; - for (int y = g->highest_line; y < g->config.board_y; y++) + for (int y = g->highest_line; y < g->config.board_y; y++) { bool should_clear_line = true; - for (int x = 0; x < g->config.board_x; x++) + for (int x = 0; x < g->config.board_x; x++) { - if (!(g->board[x][y] & CTRS_SLOT_OCCUPIED) - || g->line_remove_tick[y] > 0) + if (!(g->board[x][y] & CTRS_SLOT_OCCUPIED) + || g->line_remove_tick[y] > 0) should_clear_line = false; } - if (g->config.wait_on_clear) + if (g->config.wait_on_clear) { // remove tick only tracked on first block of line - if (g->line_remove_tick[y] && g->line_remove_tick[y] <= g->tick) + if (g->line_remove_tick[y] && g->line_remove_tick[y] <= g->tick) { g->line_remove_tick[y] = 0; clear_line(g, y); } - if (should_clear_line) + if (should_clear_line) { g->line_remove_tick[y] = g->tick + g->config.line_delay_clear; lines_cleared++; } - } + } else if (should_clear_line) { - clear_line(g, y); + clear_line(g, y); lines_cleared++; } } make_ghosts(g); - if (g->current.locked && !g->next_piece_tick) + if (g->current.locked && !g->next_piece_tick) { - if (lines_cleared > 0) + if (lines_cleared > 0) g->next_piece_tick = g->tick + g->config.next_piece_delay; - else + else { next_piece(g); g->line_combo = 0; } } - - if (g->tspin || g->mini_tspin) + + if (g->tspin || g->mini_tspin) add_score(g, lines_cleared); - else if (lines_cleared > 0) + else if (lines_cleared > 0) add_score(g, lines_cleared); g->lines += lines_cleared; - if (lines_cleared > 0) + if (lines_cleared > 0) { g->events.line_event = lines_cleared; if (lines_cleared == 4) @@ -644,11 +652,11 @@ update_board(ctrs_game *g) if (g->lines >= (g->level * 10)) g->level++; } -void -ctrs_hold_piece(ctrs_game *g) +void +ctrs_hold_piece(ctrs_game *g) { if (g->current.held) return; - if (g->piece_held) + if (g->piece_held) { unsigned char tmp = g->current.t; g->current = g->held; @@ -668,24 +676,24 @@ ctrs_hold_piece(ctrs_game *g) } #if CETRIS_ENABLE_DAS -void +void ctrs_unhold_move(ctrs_game* g, unsigned char move) { if (!g->held_moves[move]) return; if (g->das_move == move) { - if (move == LEFT && g->held_moves[RIGHT]) + if (move == LEFT && g->held_moves[RIGHT]) { g->das_move = RIGHT; g->das_wait = g->tick + g->config.das_das; - } + } else if (move == RIGHT && g->held_moves[LEFT]) { g->das_move = LEFT; g->das_wait = g->tick + g->config.das_das; - } - else + } + else g->das_wait = 0; g->next_das_move = 0; @@ -698,17 +706,17 @@ ctrs_unhold_move(ctrs_game* g, unsigned char move) } #endif -void -ctrs_move_piece(ctrs_game *g, unsigned char move) +void +ctrs_move_piece(ctrs_game *g, unsigned char move) { #if CETRIS_ENABLE_DAS if (g->held_moves[move]) return; - if (move == LEFT || move == RIGHT) + if (move == LEFT || move == RIGHT) { - if ((move != g->das_move) || !g->das_wait) + if ((move != g->das_move) || !g->das_wait) { g->das_move = move; - if (!g->waiting) + if (!g->waiting) { g->das_wait = g->tick + g->config.das_das; g->next_das_move = 0; @@ -722,29 +730,29 @@ ctrs_move_piece(ctrs_game *g, unsigned char move) g->held_moves[move] = 1; #endif - + if (g->waiting) return; - switch (move) + switch (move) { - case LEFT: - case RIGHT: - case DOWN: - move_current(g, move); - break; - case HARD_DROP: - hard_drop(g); - break; - case ROTATE_CW: - rotate_piece(g, 1); - break; - case ROTATE_CCW: - rotate_piece(g, 0); - break; + case LEFT: + case RIGHT: + case DOWN: + move_current(g, move); + break; + case HARD_DROP: + hard_drop(g); + break; + case ROTATE_CW: + rotate_piece(g, 1); + break; + case ROTATE_CCW: + rotate_piece(g, 0); + break; } } -void +void ctrs_init_game(ctrs_game *g) { srand(time(NULL)); @@ -759,7 +767,7 @@ ctrs_init_game(ctrs_game *g) memset(g, 0, sizeof(ctrs_game) - sizeof(ctrs_config)); g->board = (unsigned char **)calloc(g->config.board_x, sizeof(unsigned char *)); - for (int i = 0; i < g->config.board_x; i++) + for (int i = 0; i < g->config.board_x; i++) g->board[i] = (unsigned char *)calloc(g->config.board_y, sizeof(unsigned char)); g->line_remove_tick = (unsigned long *)calloc(g->config.board_y, sizeof(unsigned long)); @@ -779,7 +787,7 @@ ctrs_init_game(ctrs_game *g) next_piece(g); } -bool +bool ctrs_update_game_tick(ctrs_game *g) { if (g->game_over) @@ -792,31 +800,31 @@ ctrs_update_game_tick(ctrs_game *g) return true; bool did_move = false; - if (g->next_drop_tick && g->tick >= g->next_drop_tick) + if (g->next_drop_tick && g->tick >= g->next_drop_tick) { move_current(g, DOWN); g->next_drop_tick = 0; did_move = true; } - if (!g->next_drop_tick) + if (!g->next_drop_tick) { - if (g->held_moves[DOWN]) + if (g->held_moves[DOWN]) { g->next_drop_tick = g->tick + g->config.drop_period; } - else + else { - if (g->level <= 20) + if (g->level <= 20) g->next_drop_tick = g->tick + g->config.levels[g->level - 1]; - else + else g->next_drop_tick = g->tick + g->config.levels[19]; } } /* lock piece if it was hovering for CETRIS_LOCK_DELAY */ - if (((g->current.lock_tick && g->current.lock_tick <= g->tick) - || (g->current.force_lock_tick && g->current.force_lock_tick <= g->tick))) + if (((g->current.lock_tick && g->current.lock_tick <= g->tick) + || (g->current.force_lock_tick && g->current.force_lock_tick <= g->tick))) { g->current.pos.y++; char res = check_matrix(g, &g->current.m); @@ -832,14 +840,14 @@ ctrs_update_game_tick(ctrs_game *g) } #if CETRIS_ENABLE_DAS - if ((g->next_das_move && g->tick >= g->next_das_move) || g->next_das_move == 1) + if ((g->next_das_move && g->tick >= g->next_das_move) || g->next_das_move == 1) { - if (!g->waiting) + if (!g->waiting) move_current(g, g->das_move); g->next_das_move = g->tick + g->config.das_arr; } - else if (!g->next_das_move && g->das_wait && g->tick >= g->das_wait) + else if (!g->next_das_move && g->das_wait && g->tick >= g->das_wait) g->next_das_move = g->tick + g->config.das_arr; #endif diff --git a/lib/meson.build b/lib/meson.build deleted file mode 100755 index eb2e989..0000000 --- a/lib/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -src = ['cetris.c', 'rules.c'] -src += is_windows ? 'timer_windows.c' : 'timer_linux.c' - -threads = dependency('threads') - -cetris_lib = static_library('cetris', src, dependencies: threads, - include_directories: cetris_inc, install: false) - -cetris = declare_dependency(include_directories: cetris_inc, - link_with: cetris_lib) diff --git a/lib/rules.h b/lib/rules.h index ed68d54..c18104e 100755 --- a/lib/rules.h +++ b/lib/rules.h @@ -3,23 +3,23 @@ #include "cetris.h" -bool twenty_line_sprint(ctrs_game *g) +bool twenty_line_sprint(ctrs_game *g) { return g->lines >= 20; } -bool forty_line_sprint(ctrs_game *g) +bool forty_line_sprint(ctrs_game *g) { return g->lines >= 40; } -bool marathon(ctrs_game *g) +bool marathon(ctrs_game *g) { return false; } // https://tetris.fandom.com/wiki/Tetris_Worlds -unsigned long tetris_worlds_levels[20] = +unsigned long tetris_worlds_levels[20] = { 1000, 793, 618, 473, 355, 262, 189, 134, 94, 64, 43, 28, 18, 11, 7, 4, 2, 1, 1, 1 diff --git a/lib/test.h b/lib/test.h index 67f6388..67f6388 100755..100644 --- a/lib/test.h +++ b/lib/test.h diff --git a/meson.build b/meson.build index 1c8f575..1c62504 100755 --- a/meson.build +++ b/meson.build @@ -1,34 +1,6 @@ -project('cetris', 'c', - version : '0.3', +project('cetris', 'c', version : '0.3', default_options : ['warning_level=2', 'c_std=c99']) -compiler = meson.get_compiler('c') +cetris_inc = include_directories(['lib']) -is_windows = host_machine.system() == 'windows' -root_dir = meson.current_source_dir() - -cetris_inc = include_directories(['lib', 'ini']) - -if get_option('debug') - if is_windows - add_global_arguments('/DBUILD_TESTS', language : 'c') - else - add_global_arguments('-DBUILD_TESTS', language : 'c') - endif -endif - -if get_option('debug') - subdir('test') -endif - -if get_option('curses-frontend') - subdir('frontends/curses') -endif - -if get_option('gl-frontend') - subdir('frontends/gl') -endif - -if get_option('sdl-frontend') - subdir('frontends/sdl') -endif +subdir('test') diff --git a/meson_options.txt b/meson_options.txt deleted file mode 100755 index 7422cea..0000000 --- a/meson_options.txt +++ /dev/null @@ -1,3 +0,0 @@ -option('curses-frontend', type : 'boolean', value : false) -option('gl-frontend', type : 'boolean', value : false) -option('sdl-frontend', type : 'boolean', value : false) diff --git a/notes.txt b/notes.txt index c7a9ec6..502710f 100755..100644 --- a/notes.txt +++ b/notes.txt @@ -49,12 +49,12 @@ gl optimization notes: - make a structured clear even in the gameplay code use this to update the vao array as well as animations - stuctued lock event for animation in gl frontend -- store static skin elements in a seperate vao array - update on screen resize -- make ui element for the current piece which is copied +- store static skin elements in a seperate vao array + update on screen resize +- make ui element for the current piece which is copied the board array on a lock event which leaves time to edit the vertex buffer before copying it if it needs an - animation + animation FIXES: - hold needs to trigger update @@ -66,6 +66,6 @@ MUTEX: TODO: - make scene system, then generic tetris board seperate - fix ordering of main scene -- more structured event system in the core lib +- more structured event system in the core lib - add more sounds/skin elements and match them up to the new events - new minimal skin diff --git a/test/line_count.sh b/test/line_count.sh deleted file mode 100755 index 7f2d1a9..0000000 --- a/test/line_count.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -wc -l frontends/curses/curses_ui.c frontends/curses/meson.build \ - frontends/sdl/cetris_sdl.c frontends/sdl/cetris_sdl.h frontends/gl/drawable.c frontends/gl/drawable.h \ - frontends/gl/skin.c frontends/gl/skin.h frontends/gl/main.c frontends/gl/shader.c frontends/gl/shader.h \ - frontends/gl/ui.c frontends/gl/ui.h frontends/gl/audio.c frontends/gl/audio.c frontends/gl/events.c frontends/gl/tetris.c frontends/gl/tetris.h \ - frontends/gl/events.h frontends/gl/meson.build lib/* diff --git a/test/memory_test.c b/test/memory_test.c index e740848..d12614f 100755 --- a/test/memory_test.c +++ b/test/memory_test.c @@ -2,7 +2,9 @@ #include "../lib/cetris.h" -int main(void) { +int +main(void) +{ ctrs_game game; ctrs_init_game(&game); diff --git a/test/meson.build b/test/meson.build index 5d4c8b3..c0aff8f 100755 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,3 @@ mem_test = ['memory_test.c'] -executable('mem_test', mem_test, - include_directories: cetris_inc, - install: false) +executable('mem_test', mem_test, include_directories: cetris_inc, install: false) diff --git a/test/sdl_audio.c b/test/sdl_audio.c deleted file mode 100755 index 53f2514..0000000 --- a/test/sdl_audio.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <SDL2/SDL.h> - -int main(void) { - int i, count = SDL_GetNumAudioDevices(0); - - printf("count: %i\n", count); - for (i = 0; i < count; ++i) { - SDL_Log("Audio device %d: %s", i, SDL_GetAudioDeviceName(i, 0)); - printf("Audio device %d: %s", i, SDL_GetAudioDeviceName(i, 0)); - } - return 0; -} |