From 011bc64bab6eea358258471aac009aa50359791b Mon Sep 17 00:00:00 2001 From: cellos51 Date: Wed, 23 Jul 2025 16:17:24 -0400 Subject: [PATCH 1/5] huge memory save --- include/card.h | 5 +++++ source/card.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/card.h b/include/card.h index 33e052a..eb9a447 100644 --- a/include/card.h +++ b/include/card.h @@ -6,6 +6,11 @@ #include "sprite.h" +#define CARD_TID 0 +#define CARD_SPRITE_OFFSET 16 +#define CARD_PB 0 +#define CARD_STARTING_LAYER 0 + // Card suits #define HEARTS 0 #define CLUBS 1 diff --git a/source/card.c b/source/card.c index fe50fa2..1eaf115 100644 --- a/source/card.c +++ b/source/card.c @@ -4,6 +4,7 @@ #include #include "deck_gfx.h" +#include "graphic_utils.h" // Audio #include "soundbank.h" @@ -18,7 +19,7 @@ const static u16 card_sprite_lut[NUM_SUITS][NUM_RANKS] = { void card_init() { - GRIT_CPY(&tile_mem[4], deck_gfxTiles); + //GRIT_CPY(&tile_mem[4], deck_gfxTiles); GRIT_CPY(pal_obj_mem, deck_gfxPal); } @@ -149,8 +150,10 @@ 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); + memcpy16(&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 * 2); sprite_destroy(&card_object->sprite); // Destroy the old sprite if it exists - card_object->sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, card_sprite_lut[card_object->card->suit][card_object->card->rank], 0, layer); + card_object->sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, tile_index, 0, layer); } void card_object_shake(CardObject *card_object, mm_word sound_id) From d122fde361bcea3d0f05c6918aa1f6697eba0ca5 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Wed, 23 Jul 2025 16:33:18 -0400 Subject: [PATCH 2/5] card layer does something now --- source/card.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/card.c b/source/card.c index 1eaf115..8db0c2f 100644 --- a/source/card.c +++ b/source/card.c @@ -20,7 +20,7 @@ const static u16 card_sprite_lut[NUM_SUITS][NUM_RANKS] = { void card_init() { //GRIT_CPY(&tile_mem[4], deck_gfxTiles); - GRIT_CPY(pal_obj_mem, deck_gfxPal); + GRIT_CPY(&pal_obj_mem[CARD_PB], deck_gfxPal); } // Card methods @@ -153,7 +153,7 @@ void card_object_set_sprite(CardObject *card_object, int layer) int tile_index = CARD_TID + (layer * CARD_SPRITE_OFFSET); memcpy16(&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 * 2); sprite_destroy(&card_object->sprite); // Destroy the old sprite if it exists - card_object->sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, tile_index, 0, layer); + card_object->sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, tile_index, 0, layer + CARD_STARTING_LAYER); } void card_object_shake(CardObject *card_object, mm_word sound_id) From 300e725dfe0804fe7aeca76e9be0063abc505bef Mon Sep 17 00:00:00 2001 From: cellos51 Date: Wed, 23 Jul 2025 17:00:18 -0400 Subject: [PATCH 3/5] made jokers dynamic and changed memcpy to us 32 --- source/card.c | 2 +- source/game.c | 4 ++-- source/joker.c | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/card.c b/source/card.c index 8db0c2f..c1fc94c 100644 --- a/source/card.c +++ b/source/card.c @@ -151,7 +151,7 @@ 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); - memcpy16(&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 * 2); + 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_destroy(&card_object->sprite); // Destroy the old sprite if it exists card_object->sprite = sprite_new(ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, tile_index, 0, layer + CARD_STARTING_LAYER); } diff --git a/source/game.c b/source/game.c index 19e46d2..0dea05b 100644 --- a/source/game.c +++ b/source/game.c @@ -27,7 +27,7 @@ static uint timer = 0; // This might already exist in libtonc but idk so i'm jus static int game_speed = 1; static int background = 0; -static enum GameState game_state = GAME_BLIND_SELECT; // The current game state, this is used to determine what the game is doing at any given time +static enum GameState game_state = GAME_SHOP; // The current game state, this is used to determine what the game is doing at any given time static enum HandState hand_state = HAND_DRAW; static enum PlayState play_state = PLAY_PLAYING; static int state = 0; // General state variable, used for switch statements in each game state related function @@ -51,7 +51,7 @@ static int discards = 0; static int round = 0; static int ante = 1; -static int money = 4; +static int money = 100; static int score = 0; static int temp_score = 0; // This is the score that shows in the same spot as the hand type. static FIXED lerped_score = 0; diff --git a/source/joker.c b/source/joker.c index f76f387..defc29d 100644 --- a/source/joker.c +++ b/source/joker.c @@ -36,7 +36,7 @@ static bool used_layers[MAX_JOKER_OBJECTS] = {false}; // Track used layers for j void joker_init() { - GRIT_CPY(&tile_mem[4][JOKER_TID], joker_gfxTiles); + //GRIT_CPY(&tile_mem[4][JOKER_TID], joker_gfxTiles); memcpy16(&pal_obj_mem[PAL_ROW_LEN * JOKER_PB], joker_gfxPal, sizeof(joker_gfxPal) / 2); } @@ -100,14 +100,18 @@ JokerObject *joker_object_new(Joker *joker) } joker_object->joker = joker; + + int tile_index = JOKER_TID + (layer * JOKER_SPRITE_OFFSET); + memcpy32(&tile_mem[4][tile_index], &joker_gfxTiles[joker->id * TILE_SIZE * JOKER_SPRITE_OFFSET], TILE_SIZE * JOKER_SPRITE_OFFSET); joker_object->sprite = sprite_new ( ATTR0_SQUARE | ATTR0_4BPP | ATTR0_AFF, ATTR1_SIZE_32, - JOKER_TID + (JOKER_SPRITE_OFFSET * joker->id), + tile_index, JOKER_PB, JOKER_STARTING_LAYER + layer ); + joker_object->tx = 0; // Target position joker_object->ty = 0; joker_object->x = 0; From 6a326e27fe659680d1dadb743aa1c11ef71cb264 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Wed, 23 Jul 2025 17:31:21 -0400 Subject: [PATCH 4/5] refactor: update blind and joker definitions; change game state to GAME_BLIND_SELECT --- include/blind.h | 7 ++++--- include/joker.h | 11 ++++++----- source/game.c | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/blind.h b/include/blind.h index 3c113cb..512237b 100644 --- a/include/blind.h +++ b/include/blind.h @@ -18,9 +18,10 @@ static const int ante_lut[MAX_ANTE + 1] = {100, 300, 800, 2000, 5000, 11000, 200 #define BIG_BLIND_PB 2 #define BOSS_BLIND_PB 3 -#define SMALL_BLIND_TID 832 -#define BIG_BLIND_TID (SMALL_BLIND_TID + 16) -#define BOSS_BLIND_TID (BIG_BLIND_TID + 16) +#define BLIND_SPRITE_OFFSET 16 +#define SMALL_BLIND_TID 960 +#define BIG_BLIND_TID (BLIND_SPRITE_OFFSET * BIG_BLIND) +#define BOSS_BLIND_TID (BLIND_SPRITE_OFFSET * BOSS_BLIND) #define BLIND_TEXT_COLOR_INDEX 1 #define BLIND_SHADOW_COLOR_INDEX 2 diff --git a/include/joker.h b/include/joker.h index 63e251b..b29d0a2 100644 --- a/include/joker.h +++ b/include/joker.h @@ -1,15 +1,16 @@ #ifndef JOKER_H #define JOKER_H -#define JOKER_TID 880 // Tile ID for the starting index in the tile memory -#define JOKER_SPRITE_OFFSET 16 // Offset for the joker sprites -#define JOKER_PB 4 // Palette bank for the default jokers -#define JOKER_STARTING_LAYER 27 - #include #include "sprite.h" #include "card.h" +#include "game.h" + +#define JOKER_TID (MAX_HAND_SIZE + MAX_SELECTION_SIZE) * JOKER_SPRITE_OFFSET // Tile ID for the starting index in the tile memory +#define JOKER_SPRITE_OFFSET 16 // Offset for the joker sprites +#define JOKER_PB 4 // Palette bank for the default jokers +#define JOKER_STARTING_LAYER 27 #define BASE_EDITION 0 #define FOIL_EDITION 1 diff --git a/source/game.c b/source/game.c index 0dea05b..19e46d2 100644 --- a/source/game.c +++ b/source/game.c @@ -27,7 +27,7 @@ static uint timer = 0; // This might already exist in libtonc but idk so i'm jus static int game_speed = 1; static int background = 0; -static enum GameState game_state = GAME_SHOP; // The current game state, this is used to determine what the game is doing at any given time +static enum GameState game_state = GAME_BLIND_SELECT; // The current game state, this is used to determine what the game is doing at any given time static enum HandState hand_state = HAND_DRAW; static enum PlayState play_state = PLAY_PLAYING; static int state = 0; // General state variable, used for switch statements in each game state related function @@ -51,7 +51,7 @@ static int discards = 0; static int round = 0; static int ante = 1; -static int money = 100; +static int money = 4; static int score = 0; static int temp_score = 0; // This is the score that shows in the same spot as the hand type. static FIXED lerped_score = 0; From ea5e4d5d1e96ef563e1e42916fd6b12c749795cd Mon Sep 17 00:00:00 2001 From: cellos51 Date: Wed, 23 Jul 2025 17:35:42 -0400 Subject: [PATCH 5/5] refactor: remove commented-out code and simplify joker initialization --- source/card.c | 1 - source/joker.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/source/card.c b/source/card.c index c1fc94c..0db4130 100644 --- a/source/card.c +++ b/source/card.c @@ -19,7 +19,6 @@ const static u16 card_sprite_lut[NUM_SUITS][NUM_RANKS] = { void card_init() { - //GRIT_CPY(&tile_mem[4], deck_gfxTiles); GRIT_CPY(&pal_obj_mem[CARD_PB], deck_gfxPal); } diff --git a/source/joker.c b/source/joker.c index defc29d..767c969 100644 --- a/source/joker.c +++ b/source/joker.c @@ -36,8 +36,7 @@ static bool used_layers[MAX_JOKER_OBJECTS] = {false}; // Track used layers for j void joker_init() { - //GRIT_CPY(&tile_mem[4][JOKER_TID], joker_gfxTiles); - memcpy16(&pal_obj_mem[PAL_ROW_LEN * JOKER_PB], joker_gfxPal, sizeof(joker_gfxPal) / 2); + GRIT_CPY(&pal_obj_mem[PAL_ROW_LEN * JOKER_PB], joker_gfxPal); } Joker *joker_new(u8 id)