mirror of
https://github.com/cellos51/balatro-gba.git
synced 2026-04-24 23:30:17 -05:00
Clang Format Blinds (#253)
* Quick cleanup on bitset docs * Clang format blind.h/c * Replace `_` with `s_` for functions * Fix newline size for macros. * Fix format for ci * Add macro for "unused" attribute
This commit is contained in:
parent
2c32ff69e3
commit
09dd996181
|
|
@ -50,3 +50,4 @@ SpacesInLineCommentPrefix:
|
|||
Maximum: 1
|
||||
|
||||
PenaltyReturnTypeOnItsOwnLine: 99999999
|
||||
AlignEscapedNewlines: Left
|
||||
|
|
|
|||
1
.github/workflows/run_tests_ci_workflow.yml
vendored
1
.github/workflows/run_tests_ci_workflow.yml
vendored
|
|
@ -24,6 +24,7 @@ jobs:
|
|||
include/list.h source/list.c
|
||||
include/sprite.h source/sprite.c
|
||||
include/splash_screen.h source/splash_screen.c
|
||||
include/blind.h source/blind.c
|
||||
# Currently contains only the code that has been formatted to conform
|
||||
# When all existing code conforms, change to this:
|
||||
# run: clang-format --dry-run -Werror include/*.h source/*.c
|
||||
|
|
|
|||
|
|
@ -110,10 +110,14 @@ void bitset_set_idx(Bitset* bitset, int idx, bool on);
|
|||
*/
|
||||
bool bitset_get_idx(Bitset* bitset, int idx);
|
||||
|
||||
// Get the next free (set to 0) index in the bitset.
|
||||
// It also sets the bit which it maybe should do... It really shouldn't do two things
|
||||
// But it's such a fast operation idk. // TODO: decide what you wanna do
|
||||
int bitset_allocate_idx(Bitset* bitset);
|
||||
/**
|
||||
* @brief Set the next free index in the bitset and return the index value
|
||||
*
|
||||
* @param bitset A @ref Bitset to operate on
|
||||
*
|
||||
* @return The index of the bit that was set
|
||||
*/
|
||||
int bitset_set_next_free_idx(Bitset* bitset);
|
||||
|
||||
/**
|
||||
* @brief Clear the bitset, all to 0
|
||||
|
|
@ -190,13 +194,13 @@ int bitset_itr_next(BitsetItr* itr);
|
|||
* @param name the name of the bitset
|
||||
* @param capacity the capacity of the bitset
|
||||
*/
|
||||
#define BITSET_DEFINE(name, capacity) \
|
||||
static uint32_t name##_w[BITSET_ARRAY_SIZE] = {0}; \
|
||||
static Bitset name = { \
|
||||
.w = name##_w, \
|
||||
.nbits = BITSET_BITS_PER_WORD, \
|
||||
.nwords = BITSET_ARRAY_SIZE, \
|
||||
.cap = capacity, \
|
||||
#define BITSET_DEFINE(name, capacity) \
|
||||
static uint32_t name##_w[BITSET_ARRAY_SIZE] = {0}; \
|
||||
static Bitset name = { \
|
||||
.w = name##_w, \
|
||||
.nbits = BITSET_BITS_PER_WORD, \
|
||||
.nwords = BITSET_ARRAY_SIZE, \
|
||||
.cap = capacity, \
|
||||
};
|
||||
|
||||
#endif // BITSET_H
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
#define BLIND_H
|
||||
|
||||
#include "sprite.h"
|
||||
|
||||
#define MAX_ANTE 8 // 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
|
||||
#define BIG_BLIND_PB 2
|
||||
#define BOSS_BLIND_PB 3
|
||||
#define BIG_BLIND_PB 2
|
||||
#define BOSS_BLIND_PB 3
|
||||
|
||||
#define BLIND_SPRITE_OFFSET 16
|
||||
#define BLIND_SPRITE_OFFSET 16
|
||||
#define BLIND_SPRITE_COPY_SIZE BLIND_SPRITE_OFFSET * 8 // 8 ints per tile
|
||||
#define SMALL_BLIND_TID 960
|
||||
#define BIG_BLIND_TID (BLIND_SPRITE_OFFSET + SMALL_BLIND_TID)
|
||||
#define BOSS_BLIND_TID (BLIND_SPRITE_OFFSET + BIG_BLIND_TID)
|
||||
#define SMALL_BLIND_TID 960
|
||||
#define BIG_BLIND_TID (BLIND_SPRITE_OFFSET + SMALL_BLIND_TID)
|
||||
#define BOSS_BLIND_TID (BLIND_SPRITE_OFFSET + BIG_BLIND_TID)
|
||||
|
||||
enum BlindColorIndex
|
||||
{
|
||||
|
|
@ -26,19 +26,21 @@ enum BlindColorIndex
|
|||
BLIND_BACKGROUND_SHADOW_COLOR_INDEX = 7,
|
||||
};
|
||||
|
||||
#define BLIND_TYPE_INFO_TABLE \
|
||||
BLIND_INFO(SMALL, small, FIX_ONE, 3) \
|
||||
BLIND_INFO(BIG, big, (FIX_ONE * 3) / 2, 4) \
|
||||
#define BLIND_TYPE_INFO_TABLE \
|
||||
BLIND_INFO(SMALL, small, FIX_ONE, 3) \
|
||||
BLIND_INFO(BIG, big, (FIX_ONE * 3) / 2, 4) \
|
||||
BLIND_INFO(BOSS, boss, FIX_ONE * 2, 5)
|
||||
|
||||
// clang-format off
|
||||
enum BlindType
|
||||
{
|
||||
#define BLIND_INFO(NAME, name, multi, reward) \
|
||||
BLIND_TYPE_##NAME ,
|
||||
#define BLIND_INFO(NAME, name, multi, reward) \
|
||||
BLIND_TYPE_##NAME,
|
||||
BLIND_TYPE_INFO_TABLE
|
||||
BLIND_TYPE_MAX,
|
||||
#undef BLIND_INFO
|
||||
BLIND_TYPE_MAX,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
enum BlindState
|
||||
{
|
||||
|
|
@ -74,6 +76,6 @@ int blind_get_requirement(enum BlindType type, int ante);
|
|||
int blind_get_reward(enum BlindType type);
|
||||
u16 blind_get_color(enum BlindType type, enum BlindColorIndex index);
|
||||
|
||||
Sprite *blind_token_new(enum BlindType type, int x, int y, int sprite_index);
|
||||
Sprite* blind_token_new(enum BlindType type, int x, int y, int sprite_index);
|
||||
|
||||
#endif // BLIND_H
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
}; \
|
||||
type * pool_get_##type() \
|
||||
{ \
|
||||
int free_offset = bitset_allocate_idx(type##_pool.bitset); \
|
||||
int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \
|
||||
if(free_offset == -1) return NULL; \
|
||||
return &type##_pool.objects[free_offset]; \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define GBLA_UNUSED __attribute__((unused))
|
||||
|
||||
static inline int get_digits(int n) // https://stackoverflow.com/questions/1068849/how-do-i-determine-the-number-of-digits-of-an-integer-in-c
|
||||
{
|
||||
if (n < 10) return 1;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ void bitset_set_idx(Bitset* bitset, int idx, bool on)
|
|||
}
|
||||
}
|
||||
|
||||
int bitset_allocate_idx(Bitset* bitset)
|
||||
int bitset_set_next_free_idx(Bitset* bitset)
|
||||
{
|
||||
for (uint32_t i = 0; i < bitset->nwords; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,52 +1,50 @@
|
|||
#include <tonc.h>
|
||||
|
||||
#include "blind.h"
|
||||
#include "small_blind_gfx.h"
|
||||
|
||||
#include "big_blind_gfx.h"
|
||||
#include "boss_blind_gfx.h"
|
||||
#include "graphic_utils.h"
|
||||
#include "small_blind_gfx.h"
|
||||
#include "util.h"
|
||||
|
||||
// +1 is added because we'll actually be indexing at 1, but if something causes you to go to ante 0, there will still be a value there.
|
||||
#include <tonc.h>
|
||||
|
||||
// +1 is added because we'll actually be indexing at 1, but if something causes you to go to ante 0, there will still be
|
||||
// a value there.
|
||||
static const int ante_lut[MAX_ANTE + 1] = {100, 300, 800, 2000, 5000, 11000, 20000, 35000, 50000};
|
||||
|
||||
// Palettes for the blinds (Transparency, Text Color, Shadow, Highlight, Main Color) Use this: http://www.budmelvin.com/dev/15bitconverter.html
|
||||
static const u16 small_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x7FFF, 0x34A1, 0x5DCB, 0x5104, 0x55A0, 0x2D01, 0x34E0};
|
||||
static const u16 big_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2527, 0x15F5, 0x36FC, 0x1E9C, 0x01B4, 0x0D0A, 0x010E};
|
||||
static const u16 boss_blind_token_palette[PAL_ROW_LEN] = {0x0000, 0x2CC9, 0x3D0D, 0x5E14, 0x5171, 0x4D0F, 0x2CC8, 0x3089}; // This variable is temporary, each boss blind will have its own unique palette
|
||||
// Palettes for the blinds (Transparency, Text Color, Shadow, Highlight, Main Color) Use this:
|
||||
// http://www.budmelvin.com/dev/15bitconverter.html
|
||||
static const u16 small_blind_token_palette[PAL_ROW_LEN] =
|
||||
{0x0000, 0x7FFF, 0x34A1, 0x5DCB, 0x5104, 0x55A0, 0x2D01, 0x34E0};
|
||||
static const u16 big_blind_token_palette[PAL_ROW_LEN] =
|
||||
{0x0000, 0x2527, 0x15F5, 0x36FC, 0x1E9C, 0x01B4, 0x0D0A, 0x010E};
|
||||
// This variable is temporary, each boss blind will have its own unique palette
|
||||
static const u16 boss_blind_token_palette[PAL_ROW_LEN] =
|
||||
{0x0000, 0x2CC9, 0x3D0D, 0x5E14, 0x5171, 0x4D0F, 0x2CC8, 0x3089};
|
||||
|
||||
|
||||
static Blind _blind_type_map[BLIND_TYPE_MAX] =
|
||||
{
|
||||
#define BLIND_INFO(NAME, name, multi, _reward) \
|
||||
{ \
|
||||
.type = BLIND_TYPE_##NAME , \
|
||||
.gfx_info = \
|
||||
{ \
|
||||
.tiles = name##_blind_gfxTiles, \
|
||||
.palette = name##_blind_token_palette, \
|
||||
.tid = NAME##_BLIND_TID, \
|
||||
.pb = NAME##_BLIND_PB, \
|
||||
}, \
|
||||
.score_req_multipler = multi , \
|
||||
.reward = _reward , \
|
||||
},
|
||||
// clang-format off
|
||||
static Blind _blind_type_map[BLIND_TYPE_MAX] = {
|
||||
#define BLIND_INFO(NAME, name, multi, _reward) \
|
||||
{ \
|
||||
.type = BLIND_TYPE_##NAME, \
|
||||
.gfx_info = \
|
||||
{ \
|
||||
.tiles = name##_blind_gfxTiles, \
|
||||
.palette = name##_blind_token_palette, \
|
||||
.tid = NAME##_BLIND_TID, \
|
||||
.pb = NAME##_BLIND_PB, \
|
||||
}, \
|
||||
.score_req_multipler = multi, \
|
||||
.reward = _reward, \
|
||||
},
|
||||
BLIND_TYPE_INFO_TABLE
|
||||
#undef BLIND_INFO
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static void blind_gfx_init(enum BlindType type)
|
||||
{
|
||||
// TODO: Re-add grit copy. You need to decouple the blind graphics first.
|
||||
// This will allow this function to change the boss graphics info
|
||||
//GRIT_CPY(&tile_mem[4][_blind_type_map[type].pal_info.tid], tiles);
|
||||
BlindGfxInfo* p_gfx = &_blind_type_map[type].gfx_info;
|
||||
memcpy32(&tile_mem[4][p_gfx->tid], p_gfx->tiles, BLIND_SPRITE_COPY_SIZE);
|
||||
memcpy16(&pal_obj_bank[p_gfx->pb], p_gfx->palette, PAL_ROW_LEN);
|
||||
}
|
||||
static void s_blind_gfx_init(enum BlindType type);
|
||||
|
||||
|
||||
__attribute__((unused))
|
||||
void blind_set_boss_graphics(const unsigned int* tiles, const u16* palette)
|
||||
GBLA_UNUSED void blind_set_boss_graphics(const unsigned int* tiles, const u16* palette)
|
||||
{
|
||||
// TODO: This function is unused and not fully fleshed out.
|
||||
// We need to support more boss blind graphics in the future.
|
||||
|
|
@ -55,18 +53,17 @@ void blind_set_boss_graphics(const unsigned int* tiles, const u16* palette)
|
|||
//
|
||||
// This will eventually be in it's own map mapping graphic data to
|
||||
// boss types.
|
||||
|
||||
|
||||
_blind_type_map[BLIND_TYPE_BOSS].gfx_info.tiles = tiles;
|
||||
_blind_type_map[BLIND_TYPE_BOSS].gfx_info.palette = palette;
|
||||
blind_gfx_init(BLIND_TYPE_BOSS);
|
||||
s_blind_gfx_init(BLIND_TYPE_BOSS);
|
||||
}
|
||||
|
||||
void blind_init()
|
||||
{
|
||||
for(int i = 0; i < BLIND_TYPE_MAX; i++)
|
||||
for (int i = 0; i < BLIND_TYPE_MAX; i++)
|
||||
{
|
||||
blind_gfx_init(i);
|
||||
|
||||
s_blind_gfx_init(i);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -74,7 +71,9 @@ void blind_init()
|
|||
|
||||
int blind_get_requirement(enum BlindType type, int ante)
|
||||
{
|
||||
if (ante < 0 || ante > MAX_ANTE) ante = 0; // Ensure ante is within valid range
|
||||
// Ensure ante is within valid range
|
||||
if (ante < 0 || ante > MAX_ANTE)
|
||||
ante = 0;
|
||||
|
||||
return fx2int(_blind_type_map[type].score_req_multipler * ante_lut[ante]);
|
||||
}
|
||||
|
|
@ -89,7 +88,7 @@ u16 blind_get_color(enum BlindType type, enum BlindColorIndex index)
|
|||
return _blind_type_map[type].gfx_info.palette[index];
|
||||
}
|
||||
|
||||
Sprite *blind_token_new(enum BlindType type, int x, int y, int sprite_index)
|
||||
Sprite* blind_token_new(enum BlindType type, int x, int y, int sprite_index)
|
||||
{
|
||||
u16 a0 = ATTR0_SQUARE | ATTR0_4BPP;
|
||||
u16 a1 = ATTR1_SIZE_32x32;
|
||||
|
|
@ -101,3 +100,13 @@ Sprite *blind_token_new(enum BlindType type, int x, int y, int sprite_index)
|
|||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
static void s_blind_gfx_init(enum BlindType type)
|
||||
{
|
||||
// TODO: Re-add grit copy. You need to decouple the blind graphics first.
|
||||
// This will allow this function to change the boss graphics info
|
||||
// GRIT_CPY(&tile_mem[4][_blind_type_map[type].pal_info.tid], tiles);
|
||||
BlindGfxInfo* p_gfx = &_blind_type_map[type].gfx_info;
|
||||
memcpy32(&tile_mem[4][p_gfx->tid], p_gfx->tiles, BLIND_SPRITE_COPY_SIZE);
|
||||
memcpy16(&pal_obj_bank[p_gfx->pb], p_gfx->palette, PAL_ROW_LEN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ static inline void _set_shop_joker_avail(int joker_id, bool avail)
|
|||
bitset_set_idx(&_avail_jokers_bitset, joker_id, avail);
|
||||
}
|
||||
|
||||
__attribute__((unused))
|
||||
GBLA_UNUSED
|
||||
static inline bool _get_shop_joker_avail(int joker_id)
|
||||
{
|
||||
return bitset_get_idx(&_avail_jokers_bitset, joker_id);
|
||||
|
|
|
|||
|
|
@ -733,10 +733,10 @@ static JokerEffect bootstraps_joker_effect(Joker *joker, Card *scored_card, enum
|
|||
}
|
||||
|
||||
|
||||
// Using __attribute__((unused)) for jokers with no sprites yet to avoid warning
|
||||
// Using GBLA_UNUSED, aka __attribute__((unused)), for jokers with no sprites yet to avoid warning
|
||||
// Remove the attribute once they have sprites
|
||||
// no graphics available but ready to be used if wanted when graphics available
|
||||
__attribute__((unused))
|
||||
GBLA_UNUSED
|
||||
static JokerEffect shoot_the_moon_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
|
|
@ -752,7 +752,7 @@ static JokerEffect shoot_the_moon_joker_effect(Joker *joker, Card *scored_card,
|
|||
}
|
||||
|
||||
|
||||
__attribute__((unused))
|
||||
GBLA_UNUSED
|
||||
static JokerEffect photograph_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
|
|
@ -787,7 +787,7 @@ static JokerEffect photograph_joker_effect(Joker *joker, Card *scored_card, enum
|
|||
|
||||
|
||||
// no graphics available but ready to be used if wanted when graphics available
|
||||
__attribute__((unused))
|
||||
GBLA_UNUSED
|
||||
static JokerEffect triboulet_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
|
|
@ -956,7 +956,7 @@ static JokerEffect hack_joker_effect(Joker *joker, Card *scored_card, enum Joker
|
|||
|
||||
|
||||
// Note: Joker expiration is not yet implemented so Seltzer cannot be made active before it does.
|
||||
__attribute__((unused))
|
||||
GBLA_UNUSED
|
||||
static JokerEffect seltzer_joker_effect(Joker *joker, Card *scored_card, enum JokerEvent joker_event)
|
||||
{
|
||||
JokerEffect effect = {0};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user