Clang format and refactor game.h/c + update Bracket Alignment to BlockIndent (#259)
* Refactor and clang-format game.h/c * Updated clang-format AlignAfterOpenBracket: BlockIndent and ColumnLimit: 100 and refactored all files accordingly --------- Co-authored-by: MeirGavish <meir.gavish@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
+3
-2
@@ -13,7 +13,7 @@ AllowShortLoopsOnASingleLine: false
|
||||
PointerAlignment: Left
|
||||
|
||||
# Column limit
|
||||
ColumnLimit: 120
|
||||
ColumnLimit: 100
|
||||
|
||||
# Case labels
|
||||
IndentCaseLabels: true
|
||||
@@ -42,7 +42,8 @@ BinPackParameters: false
|
||||
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
PenaltyBreakBeforeFirstCallParameter: 0
|
||||
|
||||
ReflowComments: true
|
||||
SpacesInLineCommentPrefix:
|
||||
|
||||
@@ -22,6 +22,7 @@ jobs:
|
||||
include/bitset.h source/bitset.c
|
||||
include/pool.h source/pool.c
|
||||
include/card.h source/card.c
|
||||
include/game.h source/game.c
|
||||
include/hand_analysis.h source/hand_analysis.c
|
||||
include/list.h source/list.c
|
||||
include/sprite.h source/sprite.c
|
||||
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
#define BLIND_H
|
||||
|
||||
#include "sprite.h"
|
||||
// The GBA's max uint value is around 4 billion, so we're going to not add endless mode for simplicity's sake
|
||||
// The GBA's max uint value is around 4 billion, so we're going to not add endless mode for
|
||||
// simplicity's sake
|
||||
#define MAX_ANTE 8
|
||||
|
||||
#define SMALL_BLIND_PB 1
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// (stateEnum, on_init, on_update, on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_SPLASH_SCREEN, splash_screen_on_init, splash_screen_on_update, splash_screen_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_MAIN_MENU, game_main_menu_on_init, game_main_menu_on_update, _noop)
|
||||
DEF_STATE_INFO(GAME_STATE_PLAYING, game_round_on_init, game_playing_on_update, _noop)
|
||||
DEF_STATE_INFO(GAME_STATE_ROUND_END, _noop, game_round_end_on_update, game_round_end_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_SHOP, _noop, game_shop_on_update, game_shop_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_BLIND_SELECT, _noop, game_blind_select_on_update, game_blind_select_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_MAIN_MENU, game_main_menu_on_init, game_main_menu_on_update, noop)
|
||||
DEF_STATE_INFO(GAME_STATE_PLAYING, game_round_on_init, game_playing_on_update, noop)
|
||||
DEF_STATE_INFO(GAME_STATE_ROUND_END, noop, game_round_end_on_update, game_round_end_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_SHOP, noop, game_shop_on_update, game_shop_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_BLIND_SELECT, noop, game_blind_select_on_update, game_blind_select_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_LOSE, game_lose_on_init, game_lose_on_update, game_over_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_WIN, game_win_on_init, game_win_on_update, game_over_on_exit)
|
||||
|
||||
+19
-18
@@ -14,6 +14,22 @@
|
||||
#define MAX_INTEREST 5
|
||||
#define INTEREST_PER_5 1
|
||||
|
||||
// Input bindings
|
||||
#define SELECT_CARD KEY_A
|
||||
#define DESELECT_CARDS KEY_B
|
||||
#define PEEK_DECK KEY_L // Not implemented
|
||||
#define SORT_HAND KEY_R
|
||||
#define PAUSE_GAME KEY_START // Not implemented
|
||||
#define SELL_KEY KEY_L
|
||||
|
||||
struct List;
|
||||
typedef struct List List;
|
||||
|
||||
// Utility functions for other files
|
||||
typedef struct CardObject CardObject;
|
||||
typedef struct Card Card;
|
||||
typedef struct JokerObject JokerObject;
|
||||
|
||||
enum BackgroundId
|
||||
{
|
||||
BG_NONE,
|
||||
@@ -25,14 +41,6 @@ enum BackgroundId
|
||||
BG_MAIN_MENU
|
||||
};
|
||||
|
||||
// Input bindings
|
||||
#define SELECT_CARD KEY_A
|
||||
#define DESELECT_CARDS KEY_B
|
||||
#define PEEK_DECK KEY_L // Not implemented
|
||||
#define SORT_HAND KEY_R
|
||||
#define PAUSE_GAME KEY_START // Not implemented
|
||||
#define SELL_KEY KEY_L
|
||||
|
||||
// Enum value names in ../include/def_state_info_table.h
|
||||
enum GameState
|
||||
{
|
||||
@@ -47,7 +55,9 @@ enum HandState
|
||||
{
|
||||
HAND_DRAW,
|
||||
HAND_SELECT,
|
||||
HAND_SHUFFLING, // This is actually a misnomer because it's used for the deck, but it mechanically makes sense to be a state of the hand
|
||||
// This is actually a misnomer because it's used for the deck
|
||||
// but it mechanically makes sense to be a state of the hand
|
||||
HAND_SHUFFLING,
|
||||
HAND_DISCARD,
|
||||
HAND_PLAY,
|
||||
HAND_PLAYING
|
||||
@@ -98,14 +108,6 @@ void game_init();
|
||||
void game_update();
|
||||
void game_change_state(enum GameState new_game_state);
|
||||
|
||||
struct List;
|
||||
typedef struct List List;
|
||||
|
||||
// Utility functions for other files
|
||||
typedef struct CardObject CardObject; // forward declaration, actually declared in card.h
|
||||
typedef struct Card Card;
|
||||
typedef struct JokerObject JokerObject;
|
||||
|
||||
CardObject** get_hand_array(void);
|
||||
int get_hand_top(void);
|
||||
int hand_get_size(void);
|
||||
@@ -132,7 +134,6 @@ void set_money(int new_money);
|
||||
void display_money();
|
||||
void set_retrigger(bool new_retrigger);
|
||||
|
||||
|
||||
int get_game_speed(void);
|
||||
void set_game_speed(int new_game_speed);
|
||||
|
||||
|
||||
@@ -15,7 +15,13 @@ bool hand_contains_straight(u8* ranks);
|
||||
bool hand_contains_flush(u8* suits);
|
||||
|
||||
int find_flush_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection);
|
||||
int find_straight_in_played_cards(CardObject** played, int top, bool shortcut_active, int min_len, bool* out_selection);
|
||||
int find_straight_in_played_cards(
|
||||
CardObject** played,
|
||||
int top,
|
||||
bool shortcut_active,
|
||||
int min_len,
|
||||
bool* out_selection
|
||||
);
|
||||
void select_paired_cards_in_hand(CardObject** played, int top, bool* selection);
|
||||
|
||||
#endif
|
||||
|
||||
+7
-5
@@ -5,8 +5,8 @@
|
||||
* List Implementation
|
||||
* ===================
|
||||
*
|
||||
* - This @ref List operates as a linked list @ref ListNodes. It operates as a regular doubly-linked list
|
||||
* but doesn't allocate memory and rather gets @ref ListNodes from a pool.
|
||||
* - This @ref List operates as a linked list @ref ListNodes. It operates as a regular
|
||||
* doubly-linked list but doesn't allocate memory and rather gets @ref ListNodes from a pool.
|
||||
*/
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
@@ -23,7 +23,8 @@ typedef struct ListNode ListNode;
|
||||
struct ListNode
|
||||
{
|
||||
/**
|
||||
* @brief The previous @ref ListNode in the associated @ref List, NULL if at the `head` of the list
|
||||
* @brief The previous @ref ListNode in the associated @ref List, NULL if at the `head` of the
|
||||
* list
|
||||
*/
|
||||
ListNode* prev;
|
||||
|
||||
@@ -99,8 +100,9 @@ typedef struct
|
||||
/**
|
||||
* Create a list.
|
||||
*
|
||||
* While this function does not allocate memory for the list itself, the list does allocate memory for each element.
|
||||
* So every created list must be freed with @ref list_clear to ensure the list's nodes are deleted properly.
|
||||
* While this function does not allocate memory for the list itself, the list does allocate memory
|
||||
* for each element. So every created list must be freed with @ref list_clear to ensure the list's
|
||||
* nodes are deleted properly.
|
||||
*
|
||||
* @return A @ref List with head and tail reset.
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ struct SelectionGridRow
|
||||
|
||||
struct SelectionGrid
|
||||
{
|
||||
SelectionGridRow* rows;
|
||||
const SelectionGridRow* rows;
|
||||
const int num_rows;
|
||||
Selection selection;
|
||||
};
|
||||
|
||||
+7
-5
@@ -34,10 +34,11 @@ int bitset_set_next_free_idx(Bitset* bitset)
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Bit-Operation-Builtins.html#index-_005f_005fbuiltin_005fctz
|
||||
//
|
||||
// By using the bitwise inverse of the word, you can skip words that are full
|
||||
// quickly (where the value is 0 or 'false' since all bits are '1', or 'in use'). Any value greater
|
||||
// than 0 indicates there is a free slot. Then, when counting the trailing 0's, you can test very quickly
|
||||
// where the first free slot is. This operation prevents looping through every bit of filled flags, and
|
||||
// will instead operate only on the first word with free slots.
|
||||
// quickly (where the value is 0 or 'false' since all bits are '1', or 'in use'). Any value
|
||||
// greater than 0 indicates there is a free slot. Then, when counting the trailing 0's, you
|
||||
// can test very quickly where the first free slot is. This operation prevents looping
|
||||
// through every bit of filled flags, and will instead operate only on the first word with
|
||||
// free slots.
|
||||
if (inv)
|
||||
{
|
||||
int bit = __builtin_ctz(inv);
|
||||
@@ -100,7 +101,8 @@ int bitset_find_idx_of_nth_set(const Bitset* bitset, int n)
|
||||
if (tracker > n)
|
||||
{
|
||||
// The index is here somewhere
|
||||
// this one is to count the 1's not the offset, underflow to -1 is good for finding the 0 index
|
||||
// this one is to count the 1's not the offset, underflow to -1 is good for finding the
|
||||
// 0 index
|
||||
int base = prev_tracker - 1;
|
||||
// this one is for the actual offset we want to map the id to
|
||||
int offset = bitset->nbits * i;
|
||||
|
||||
+15
-6
@@ -10,7 +10,8 @@
|
||||
#include "pool.h"
|
||||
#include "soundbank.h"
|
||||
|
||||
// Card sprites lookup table. First index is the suit, second index is the rank. The value is the tile index.
|
||||
// Card sprites lookup table. First index is the suit, second index is the rank. The value is the
|
||||
// tile index.
|
||||
const static u16 _card_sprite_lut[NUM_SUITS][NUM_RANKS] = {
|
||||
{0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192},
|
||||
{208, 224, 240, 256, 272, 288, 304, 320, 336, 352, 368, 384, 400},
|
||||
@@ -88,11 +89,19 @@ void card_object_update(CardObject* card_object)
|
||||
void card_object_set_sprite(CardObject* card_object, int layer)
|
||||
{
|
||||
int tile_index = CARD_TID + (layer * CARD_SPRITE_OFFSET);
|
||||
memcpy32(&tile_mem[4][tile_index],
|
||||
&deck_gfxTiles[_card_sprite_lut[card_object->card->suit][card_object->card->rank] * TILE_SIZE],
|
||||
TILE_SIZE * CARD_SPRITE_OFFSET);
|
||||
Sprite* sprite =
|
||||
sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, tile_index, 0, layer + CARD_STARTING_LAYER);
|
||||
memcpy32(
|
||||
&tile_mem[4][tile_index],
|
||||
&deck_gfxTiles
|
||||
[_card_sprite_lut[card_object->card->suit][card_object->card->rank] * TILE_SIZE],
|
||||
TILE_SIZE * CARD_SPRITE_OFFSET
|
||||
);
|
||||
Sprite* sprite = sprite_new(
|
||||
ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF,
|
||||
ATTR1_SIZE_32,
|
||||
tile_index,
|
||||
0,
|
||||
layer + CARD_STARTING_LAYER
|
||||
);
|
||||
sprite_object_set_sprite(card_object->sprite_object, sprite);
|
||||
}
|
||||
|
||||
|
||||
+2308
-1763
File diff suppressed because it is too large
Load Diff
+11
-4
@@ -221,7 +221,8 @@ bool hand_contains_flush(u8* suits)
|
||||
* @param played Array of pointers to CardObject representing played cards.
|
||||
* @param top Index of the top of the played stack.
|
||||
* @param min_len Minimum number of cards required for a flush.
|
||||
* @param out_selection Output array of bools; set to true for cards in the best flush, false otherwise.
|
||||
* @param out_selection Output array of bools; set to true for cards in the best flush, false
|
||||
* otherwise.
|
||||
* @return The number of cards in the best flush found, or 0 if no flush meets min_len.
|
||||
*/
|
||||
int find_flush_in_played_cards(CardObject** played, int top, int min_len, bool* out_selection)
|
||||
@@ -265,9 +266,15 @@ int find_flush_in_played_cards(CardObject** played, int top, int min_len, bool*
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Returns the number of cards in the best straight or 0 if no straight of min_len is found, marks as true them in
|
||||
// out_selection[]. This is mostly from Google Gemini
|
||||
int find_straight_in_played_cards(CardObject** played, int top, bool shortcut_active, int min_len, bool* out_selection)
|
||||
// Returns the number of cards in the best straight or 0 if no straight of min_len is found, marks
|
||||
// as true them in out_selection[]. This is mostly from Google Gemini
|
||||
int find_straight_in_played_cards(
|
||||
CardObject** played,
|
||||
int top,
|
||||
bool shortcut_active,
|
||||
int min_len,
|
||||
bool* out_selection
|
||||
)
|
||||
{
|
||||
if (top < 0)
|
||||
return 0;
|
||||
|
||||
@@ -16,9 +16,11 @@ void splash_screen_on_init()
|
||||
|
||||
tte_printf("#{P:72,8; cx:0xF000}DISCLAIMER");
|
||||
tte_printf(
|
||||
"#{P:8,24; cx:0xF000}This project is NOT endorsed \n by or affiliated with \n Playstack or LocalThunk.\n\n If "
|
||||
"you have paid for this, \n you have been scammed \n and should request a refund \n IMMEDIATELY. \n\n The only "
|
||||
"official place \n to obtain this is from: \n\n 'github.com/\n cellos51/balatro-gba'");
|
||||
"#{P:8,24; cx:0xF000}This project is NOT endorsed \n by or affiliated with \n Playstack or "
|
||||
"LocalThunk.\n\n If you have paid for this, \n you have been scammed \n and should request "
|
||||
"a refund \n IMMEDIATELY. \n\n The only official place \n to obtain this is from: \n\n "
|
||||
"'github.com/\n cellos51/balatro-gba'"
|
||||
);
|
||||
tte_printf("#{P:8,144; cx:0xF000}(Press any key to skip)");
|
||||
}
|
||||
|
||||
@@ -29,10 +31,12 @@ void splash_screen_on_update()
|
||||
if (timer < SPLASH_DURATION_FRAMES)
|
||||
{
|
||||
tte_erase_rect_wrapper(COUNTDOWN_TIMER_RECT);
|
||||
tte_printf("#{P:%d,%d; cx:0xF000}%d",
|
||||
tte_printf(
|
||||
"#{P:%d,%d; cx:0xF000}%d",
|
||||
COUNTDOWN_TIMER_RECT.left,
|
||||
COUNTDOWN_TIMER_RECT.top,
|
||||
1 + (SPLASH_DURATION_FRAMES - timer) / SPLASH_FPS);
|
||||
1 + (SPLASH_DURATION_FRAMES - timer) / SPLASH_FPS
|
||||
);
|
||||
|
||||
if (!key_hit(KEY_ANY))
|
||||
{
|
||||
|
||||
+9
-5
@@ -181,8 +181,8 @@ void sprite_object_update(SpriteObject* sprite_object)
|
||||
|
||||
// set velocity to 0 if it's close enough to the target
|
||||
const FIXED epsilon = float2fx(0.01f);
|
||||
if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon && sprite_object->vy < epsilon &&
|
||||
sprite_object->vy > -epsilon)
|
||||
if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon &&
|
||||
sprite_object->vy < epsilon && sprite_object->vy > -epsilon)
|
||||
{
|
||||
sprite_object->vx = 0;
|
||||
sprite_object->vy = 0;
|
||||
@@ -215,7 +215,8 @@ void sprite_object_update(SpriteObject* sprite_object)
|
||||
if (sprite_object->vrotation < epsilon && sprite_object->vrotation > -epsilon)
|
||||
{
|
||||
sprite_object->vrotation = 0;
|
||||
sprite_object->rotation = sprite_object->trotation; // Set the rotation to the target rotation
|
||||
// Set the rotation to the target rotation
|
||||
sprite_object->rotation = sprite_object->trotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -223,10 +224,13 @@ void sprite_object_update(SpriteObject* sprite_object)
|
||||
sprite_object->rotation += sprite_object->vrotation;
|
||||
}
|
||||
|
||||
obj_aff_rotscale(sprite_object->sprite->aff,
|
||||
// Apply rotation and scale to the sprite
|
||||
obj_aff_rotscale(
|
||||
sprite_object->sprite->aff,
|
||||
sprite_object->scale,
|
||||
sprite_object->scale,
|
||||
-sprite_object->vx + sprite_object->rotation); // Apply rotation and scale to the sprite
|
||||
-sprite_object->vx + sprite_object->rotation
|
||||
);
|
||||
sprite_position(sprite_object->sprite, fx2int(sprite_object->x), fx2int(sprite_object->y));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user