From 18260920b461619ce99923e1041b3c46d50055b9 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 10 Jan 2022 22:30:48 -0800 Subject: [PATCH] Optimizing --- assets/{images => }/sm.png | Bin assets/{images => }/tileset.png | Bin src/conversation/fade.c | 9 ++-- src/conversation/fade.h | 8 +-- src/conversation/pause.c | 4 +- src/conversation/pause.h | 4 +- src/conversation/queue.c | 84 +++++++++++++++++++++++++------- src/conversation/queue.h | 8 +-- src/conversation/textbox.c | 71 +++++++++++++-------------- src/conversation/textbox.h | 6 +-- src/display/common.c | 2 +- src/display/common.h | 2 +- src/display/tilemap.h | 4 +- src/libs.h | 2 +- src/main.c | 8 --- src/poker/poker.c | 4 +- src/poker/pot.h | 5 +- src/time.c | 4 +- src/time.h | 4 +- 19 files changed, 135 insertions(+), 94 deletions(-) rename assets/{images => }/sm.png (100%) rename assets/{images => }/tileset.png (100%) diff --git a/assets/images/sm.png b/assets/sm.png similarity index 100% rename from assets/images/sm.png rename to assets/sm.png diff --git a/assets/images/tileset.png b/assets/tileset.png similarity index 100% rename from assets/images/tileset.png rename to assets/tileset.png diff --git a/src/conversation/fade.c b/src/conversation/fade.c index 463476d..596385f 100644 --- a/src/conversation/fade.c +++ b/src/conversation/fade.c @@ -7,21 +7,22 @@ #include "fade.h" -void conversationFadeToBlack() { +inline void conversationFadeToBlack() { TIME_FUTURE = TIME_CURRENT; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_BLACK; } -void conversationFadeFromBlack() { +inline void conversationFadeFromBlack() { TIME_FUTURE = TIME_CURRENT; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_BLACK; } -void conversationFadeToWhite() { + +inline void conversationFadeToWhite() { TIME_FUTURE = TIME_CURRENT; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_WHITE; } -void conversationFadeFromWhite() { +inline void conversationFadeFromWhite() { TIME_FUTURE = TIME_CURRENT; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_WHITE; } diff --git a/src/conversation/fade.h b/src/conversation/fade.h index f5e6a3b..2355b6e 100644 --- a/src/conversation/fade.h +++ b/src/conversation/fade.h @@ -14,8 +14,8 @@ // This is how many frames it takes to change each shade. #define FADE_STEP 20 -void conversationFadeToBlack(); -void conversationFadeFromBlack(); -void conversationFadeToWhite(); -void conversationFadeFromWhite(); +inline void conversationFadeToBlack(); +inline void conversationFadeFromBlack(); +inline void conversationFadeToWhite(); +inline void conversationFadeFromWhite(); void conversationFadeUpdate(); \ No newline at end of file diff --git a/src/conversation/pause.c b/src/conversation/pause.c index 4159b3d..89b577a 100644 --- a/src/conversation/pause.c +++ b/src/conversation/pause.c @@ -7,12 +7,12 @@ #include "pause.h" -void conversationPause(uint16_t duration) { +inline void conversationPause(uint16_t duration) { TIME_FUTURE = TIME_CURRENT + (duration * TIME_PER_SECOND); TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_PAUSE; } -void conversationPauseUpdate() { +inline void conversationPauseUpdate() { if(TIME_FUTURE_TYPE != TIME_FUTURE_TYPE_PAUSE || TIME_CURRENT != TIME_FUTURE) { return; } diff --git a/src/conversation/pause.h b/src/conversation/pause.h index ed473a0..b0f0c9f 100644 --- a/src/conversation/pause.h +++ b/src/conversation/pause.h @@ -10,5 +10,5 @@ #include "../time.h" #include "queue.h" -void conversationPause(uint16_t duration); -void conversationPauseUpdate(); \ No newline at end of file +inline void conversationPause(uint16_t duration); +inline void conversationPauseUpdate(); \ No newline at end of file diff --git a/src/conversation/queue.c b/src/conversation/queue.c index f6eba8f..20d77c0 100644 --- a/src/conversation/queue.c +++ b/src/conversation/queue.c @@ -33,14 +33,16 @@ void conversationQueueDealCards() { } void conversationQueueBeginBetting() { - uint8_t i; // Begin the betting process. First we need to decide if the player or the // AI is betting, then based on that we decide what to do next. + QUEUE_ITEM = QUEUE_DEBUG; + conversationTextboxString(DEBUG_WINNER_DECIDED); + return; - // TODO: Next better + // TODO: Actually bet. if(POKER_PLAYER_BETTER == POKER_HUMAN_INDEX) { // This is the human player. - BGB_MESSAGE("Players turn to bet"); + BGB_MESSAGE("Player betting."); POKER_PLAYERS[ POKER_PLAYER_BETTER ].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND; @@ -51,33 +53,73 @@ void conversationQueueBeginBetting() { POKER_PLAYER_BETTER ].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND; } - // TODO: Decide if we need to continue betting or decide a winner + + QUEUE_ITEM = QUEUE_NEXT_BETTER; + conversationQueueNext(); +} + +void conversationQueueNextBetter() { + uint8_t i, j, k; + + // Now we decide the next better. for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) { - // Can the player even do anything? + //In theory I don't think the current better can ever be selected again. + if(i == POKER_PLAYER_BETTER) continue; + + // Next better is the better to the right of the current better. + j = (POKER_PLAYER_BETTER + i) % POKER_PLAYER_COUNT_MAX; + + // Can this player even participate? if( ( - POKER_PLAYERS[POKER_PLAYER_BETTER].state & - (POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT) - ) != 0 || - POKER_PLAYERS[POKER_PLAYER_BETTER].chips == 0 + POKER_PLAYERS[j].state & ( + POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT + ) + ) != 0 || POKER_PLAYERS[j].chips == 0 ) continue; // Has the player bet? If so are they in the current pot? if(( - POKER_PLAYERS[POKER_PLAYER_BETTER].state & + POKER_PLAYERS[j].state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND ) != 0) { - // TODO: confirm uh if they are up to the currently raised pot point or - // not. - continue; + // Check each pot, if the pot is inactive or the player is CALLED/CHECKED + for(k = 0; k < POKER_POT_COUNT_MAX; k++) { + // Is this pot active? + if(POKER_POTS[k].chips == 0) { + k = POKER_POT_COUNT_MAX; + break; + } + + // Is the player called into this pot all the way? + if(POKER_POTS[k].players[j] == POKER_POTS[k].call) continue; + } + + // Then skip to next player. + if(k == POKER_POT_COUNT_MAX) continue; } // They haven't bet yet, make them the "next better" + POKER_PLAYER_BETTER = j; + conversationQueueNext(); + return; } // If we reach this point then we either need to begin the betting round, or - // we are going to move to the winning decider. TODO: Figure out if winning - // phase or turn phase. + // we are going to move to the winning decider. + if( + i == POKER_PLAYER_COUNT_MAX || + POKER_COMMUNITY_SIZE_MAX == POKER_COMMUNITY_SIZE + ) { + QUEUE_ITEM = QUEUE_WINNER_DECIDE; + conversationQueueNext(); + return; + } + + // Reset the players betting state so that they may bet next round. + for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) { + POKER_PLAYERS[i].state &= ~POKER_PLAYER_STATE_HAS_BET_THIS_ROUND; + } QUEUE_ITEM = QUEUE_FLOP; conversationQueueNext(); @@ -158,14 +200,14 @@ queuecallback_t *QUEUE_CALLBACKS[] = { NULL, // 25 - &conversationQueueFlopTurnRiver, + &conversationQueueNextBetter, NULL, NULL, NULL, NULL, // 30 - NULL, + &conversationQueueFlopTurnRiver, NULL, NULL, NULL, @@ -186,6 +228,12 @@ queuecallback_t *QUEUE_CALLBACKS[] = { // NULL, }; -void conversationQueueInit() { +inline void conversationQueueInit() { QUEUE_ITEM = QUEUE_BEGIN; +} + +inline void conversationQueueNext() { + if(QUEUE_ITEM > QUEUE_WINNER_DECIDE) return; + if(QUEUE_CALLBACKS[QUEUE_ITEM] == NULL) return; + QUEUE_CALLBACKS[QUEUE_ITEM](); } \ No newline at end of file diff --git a/src/conversation/queue.h b/src/conversation/queue.h index ac5c9aa..1786702 100644 --- a/src/conversation/queue.h +++ b/src/conversation/queue.h @@ -19,9 +19,9 @@ extern queuecallback_t *QUEUE_CALLBACKS[]; #define QUEUE_TAKE_BLINDS 10 #define QUEUE_DEAL_CARDS 15 #define QUEUE_BEGIN_BETTING 20 -#define QUEUE_FLOP 25 +#define QUEUE_NEXT_BETTER 25 +#define QUEUE_FLOP 30 #define QUEUE_WINNER_DECIDE 40 -#define conversationQueueNext() QUEUE_CALLBACKS[QUEUE_ITEM]() - -void conversationQueueInit(); \ No newline at end of file +inline void conversationQueueInit(); +inline void conversationQueueNext(); \ No newline at end of file diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index 6f37a04..505635e 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -11,10 +11,11 @@ char *TEXTBOX_TEXT; uint8_t TEXTBOX_TEXT_LENGTH; uint8_t TEXTBOX_STATE; uint8_t TEXTBOX_SCROLL; -uint8_t TEXTBOX_TILES[TEXTBOX_TILES_MAX]; +uint8_t TEXTBOX_CHAR_POSITION; -void conversationTextboxInit() { +inline void conversationTextboxInit() { uint8_t i; + uint8_t TEXTBOX_TILES[TEXTBOX_TILES_MAX]; // Reset textbox state TEXTBOX_TEXT = NULL; @@ -42,36 +43,44 @@ void conversationTextboxInit() { TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * i] = BORDER_TILE_CENTER_LEFT; TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * (i+1) - 1] = BORDER_TILE_CENTER_RIGHT; } + + // Setup tiles. + set_win_tiles( + 0, 0, + TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, + TEXTBOX_TILES + ); } void conversationTextboxSetText(char *text, uint8_t length) { uint8_t i, j; + uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW]; // Reset textbox state TEXTBOX_TEXT = text; TEXTBOX_TEXT_LENGTH = length; TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE; TEXTBOX_SCROLL = 0; + TEXTBOX_CHAR_POSITION = 0; // Fill blank characters for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) { for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) { - TEXTBOX_TILES[(i+1) + ((j + 1) * TEXTBOX_WIDTH_IN_TILES)] = ( - TEXTBOX_TILE_BLANK - ); + TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK; } } - set_win_tiles( - 0, 0, - TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, + 1, 1, + TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02, TEXTBOX_TILES ); + + // Show the window layer. SHOW_WIN; } -void conversationTextboxUpdate() { - uint8_t i, j; +inline void conversationTextboxUpdate() { + uint8_t i; // Is the textbox visible? if(!(TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE)) return; @@ -88,35 +97,25 @@ void conversationTextboxUpdate() { } // Move to the next character. - TEXTBOX_SCROLL++; - j = TEXTBOX_WIDTH_IN_TILES + 1; - for(i = 0; i < TEXTBOX_SCROLL; i++) { + if(TEXTBOX_TEXT[TEXTBOX_SCROLL] == ' ') { // Whitespace, do nothing. - if(TEXTBOX_TEXT[i] == ' ') { - j++; - continue; - } - + TEXTBOX_CHAR_POSITION++; + } else if(TEXTBOX_TEXT[TEXTBOX_SCROLL] == '\n') { // Newline character, move the next tile to the next row. - if(TEXTBOX_TEXT[i] == '\n') { - j = ( - (j / TEXTBOX_WIDTH_IN_TILES)*TEXTBOX_WIDTH_IN_TILES - ) + TEXTBOX_WIDTH_IN_TILES + 1; - continue; - } - - // Reveal the next character - TEXTBOX_TILES[j] = TEXTBOX_TEXT[i]; - j++; + TEXTBOX_CHAR_POSITION = ( + (TEXTBOX_CHAR_POSITION / TEXTBOX_CHARS_PER_ROW) + 1 + ) * TEXTBOX_CHARS_PER_ROW; + } else { + // Reveal the next character. TODO: I'll optimize this. + set_win_tiles( + 1 + (TEXTBOX_CHAR_POSITION % TEXTBOX_CHARS_PER_ROW), + 1 + (TEXTBOX_CHAR_POSITION / TEXTBOX_CHARS_PER_ROW), + 1, 1, + TEXTBOX_TEXT + TEXTBOX_SCROLL + ); + TEXTBOX_CHAR_POSITION++; } - - // Update the window tilemap - set_win_tiles( - 0, 0, - TEXTBOX_WIDTH_IN_TILES, - TEXTBOX_HEIGHT_IN_TILES, - TEXTBOX_TILES - ); + TEXTBOX_SCROLL++; // Update state. TODO: I actually don't really need this state, it's just here // incase I want to check if the state has scrolled later on? Doubt it though. diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index 0cbb90a..4f75379 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -45,8 +45,8 @@ extern char *TEXTBOX_TEXT; extern uint8_t TEXTBOX_TEXT_LENGTH; extern uint8_t TEXTBOX_STATE; extern uint8_t TEXTBOX_SCROLL; -extern uint8_t TEXTBOX_TILES[]; +extern uint8_t TEXTBOX_CHAR_POSITION; -void conversationTextboxInit(); +inline void conversationTextboxInit(); void conversationTextboxSetText(char *text, uint8_t length); -void conversationTextboxUpdate(); \ No newline at end of file +inline void conversationTextboxUpdate(); \ No newline at end of file diff --git a/src/display/common.c b/src/display/common.c index 1d3c93a..c959b46 100644 --- a/src/display/common.c +++ b/src/display/common.c @@ -14,6 +14,6 @@ const uint8_t COMMON_TILES[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; -void commonTilesInit() { +inline void commonTilesInit() { set_bkg_data(0x00, COMMON_TILE_COUNT, COMMON_TILES); } \ No newline at end of file diff --git a/src/display/common.h b/src/display/common.h index 5435aa4..99a2a69 100644 --- a/src/display/common.h +++ b/src/display/common.h @@ -34,4 +34,4 @@ extern const uint8_t COMMON_TILES[]; -void commonTilesInit(); \ No newline at end of file +inline void commonTilesInit(); \ No newline at end of file diff --git a/src/display/tilemap.h b/src/display/tilemap.h index ba7e220..ad9424a 100644 --- a/src/display/tilemap.h +++ b/src/display/tilemap.h @@ -8,8 +8,8 @@ #pragma once #include "FONT.h" #include "BORDER.h" -#include "SM.h" +// #include "SM.h" #define FONT_DATA_POSITION 0x04 #define BORDER_DATA_POSITION FONT_DATA_POSITION+FONT_IMAGE_TILES -#define SM_DATA_POSITION BORDER_DATA_POSITION+BORDER_IMAGE_TILES +// #define SM_DATA_POSITION BORDER_DATA_POSITION+BORDER_IMAGE_TILES diff --git a/src/libs.h b/src/libs.h index ee46485..d41e7c4 100644 --- a/src/libs.h +++ b/src/libs.h @@ -9,6 +9,6 @@ #include #include #include -#include +// #include #include #include \ No newline at end of file diff --git a/src/main.c b/src/main.c index 4c30c0e..4476096 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,6 @@ */ #include "main.h" -#include "SM.h" void main() { int16_t j; @@ -37,19 +36,12 @@ void main() { SCX_REG = 0x00; SCY_REG = 0x00; - - set_bkg_data(SM_DATA_POSITION, SM_IMAGE_TILES, SM_IMAGE); - uint8_t sm[SM_IMAGE_TILES]; - for(j = 0; j < SM_IMAGE_TILES; j++) sm[j] = j + SM_DATA_POSITION; - set_bkg_tiles(0x00, 0x00, SM_IMAGE_COLUMNS, SM_IMAGE_ROWS, sm); - // Now turn the screen on DISPLAY_ON; enable_interrupts(); wait_vbl_done(); // Alright begin the game logic here. - BGB_MESSAGE("Begin."); conversationQueueNext(); // Begin the loop diff --git a/src/poker/poker.c b/src/poker/poker.c index 83a6624..3acc9c0 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -56,7 +56,9 @@ void pokerNewRound() { for(i = 0; i < POKER_POT_COUNT_MAX; i++) { POKER_POTS[i].chips = 0; POKER_POTS[i].call = 0; - POKER_POTS[i].playersCount = 0; + for(j = 0; j < POKER_PLAYER_COUNT_MAX; j++) { + POKER_POTS[i].players[j] = 0; + } } // Fill deck diff --git a/src/poker/pot.h b/src/poker/pot.h index 83e958a..62ebee1 100644 --- a/src/poker/pot.h +++ b/src/poker/pot.h @@ -18,9 +18,8 @@ typedef struct { /** Current call value for this pot */ uint16_t call; - /** Players who are participating in the pot */ - uint8_t players[POKER_PLAYER_COUNT_MAX]; - uint8_t playersCount; + /** Players who are participating in the pots current bet (in the pot) */ + uint16_t players[POKER_PLAYER_COUNT_MAX]; } pokerpot_t; extern pokerpot_t POKER_POTS[]; diff --git a/src/time.c b/src/time.c index 9503522..c2efaf6 100644 --- a/src/time.c +++ b/src/time.c @@ -11,12 +11,12 @@ uint16_t TIME_CURRENT; uint16_t TIME_FUTURE; uint8_t TIME_FUTURE_TYPE; -void timeInit() { +inline void timeInit() { TIME_CURRENT = 0; TIME_FUTURE = 0; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL; } -void timeUpdate() { +inline void timeUpdate() { TIME_CURRENT++; } \ No newline at end of file diff --git a/src/time.h b/src/time.h index a9dd81d..fe79f87 100644 --- a/src/time.h +++ b/src/time.h @@ -21,5 +21,5 @@ extern uint16_t TIME_CURRENT; extern uint16_t TIME_FUTURE; extern uint8_t TIME_FUTURE_TYPE; -void timeInit(); -void timeUpdate(); \ No newline at end of file +inline void timeInit(); +inline void timeUpdate(); \ No newline at end of file