Optimizing

This commit is contained in:
2022-01-10 22:30:48 -08:00
parent cc9e50c4ab
commit 18260920b4
19 changed files with 135 additions and 94 deletions

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 119 B

View File

@@ -7,21 +7,22 @@
#include "fade.h" #include "fade.h"
void conversationFadeToBlack() { inline void conversationFadeToBlack() {
TIME_FUTURE = TIME_CURRENT; TIME_FUTURE = TIME_CURRENT;
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_BLACK; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_BLACK;
} }
void conversationFadeFromBlack() { inline void conversationFadeFromBlack() {
TIME_FUTURE = TIME_CURRENT; TIME_FUTURE = TIME_CURRENT;
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_BLACK; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_BLACK;
} }
void conversationFadeToWhite() {
inline void conversationFadeToWhite() {
TIME_FUTURE = TIME_CURRENT; TIME_FUTURE = TIME_CURRENT;
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_WHITE; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_TO_WHITE;
} }
void conversationFadeFromWhite() { inline void conversationFadeFromWhite() {
TIME_FUTURE = TIME_CURRENT; TIME_FUTURE = TIME_CURRENT;
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_WHITE; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_FADE_FROM_WHITE;
} }

View File

@@ -14,8 +14,8 @@
// This is how many frames it takes to change each shade. // This is how many frames it takes to change each shade.
#define FADE_STEP 20 #define FADE_STEP 20
void conversationFadeToBlack(); inline void conversationFadeToBlack();
void conversationFadeFromBlack(); inline void conversationFadeFromBlack();
void conversationFadeToWhite(); inline void conversationFadeToWhite();
void conversationFadeFromWhite(); inline void conversationFadeFromWhite();
void conversationFadeUpdate(); void conversationFadeUpdate();

View File

@@ -7,12 +7,12 @@
#include "pause.h" #include "pause.h"
void conversationPause(uint16_t duration) { inline void conversationPause(uint16_t duration) {
TIME_FUTURE = TIME_CURRENT + (duration * TIME_PER_SECOND); TIME_FUTURE = TIME_CURRENT + (duration * TIME_PER_SECOND);
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_PAUSE; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_PAUSE;
} }
void conversationPauseUpdate() { inline void conversationPauseUpdate() {
if(TIME_FUTURE_TYPE != TIME_FUTURE_TYPE_PAUSE || TIME_CURRENT != TIME_FUTURE) { if(TIME_FUTURE_TYPE != TIME_FUTURE_TYPE_PAUSE || TIME_CURRENT != TIME_FUTURE) {
return; return;
} }

View File

@@ -10,5 +10,5 @@
#include "../time.h" #include "../time.h"
#include "queue.h" #include "queue.h"
void conversationPause(uint16_t duration); inline void conversationPause(uint16_t duration);
void conversationPauseUpdate(); inline void conversationPauseUpdate();

View File

@@ -33,14 +33,16 @@ void conversationQueueDealCards() {
} }
void conversationQueueBeginBetting() { void conversationQueueBeginBetting() {
uint8_t i;
// Begin the betting process. First we need to decide if the player or the // 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. // 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) { if(POKER_PLAYER_BETTER == POKER_HUMAN_INDEX) {
// This is the human player. // This is the human player.
BGB_MESSAGE("Players turn to bet"); BGB_MESSAGE("Player betting.");
POKER_PLAYERS[ POKER_PLAYERS[
POKER_PLAYER_BETTER POKER_PLAYER_BETTER
].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND; ].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
@@ -51,33 +53,73 @@ void conversationQueueBeginBetting() {
POKER_PLAYER_BETTER POKER_PLAYER_BETTER
].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND; ].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++) { 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( if(
( (
POKER_PLAYERS[POKER_PLAYER_BETTER].state & POKER_PLAYERS[j].state & (
(POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT) POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT
) != 0 || )
POKER_PLAYERS[POKER_PLAYER_BETTER].chips == 0 ) != 0 || POKER_PLAYERS[j].chips == 0
) continue; ) continue;
// Has the player bet? If so are they in the current pot? // Has the player bet? If so are they in the current pot?
if(( if((
POKER_PLAYERS[POKER_PLAYER_BETTER].state & POKER_PLAYERS[j].state &
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
) != 0) { ) != 0) {
// TODO: confirm uh if they are up to the currently raised pot point or // Check each pot, if the pot is inactive or the player is CALLED/CHECKED
// not. for(k = 0; k < POKER_POT_COUNT_MAX; k++) {
continue; // 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" // 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 // 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 // we are going to move to the winning decider.
// phase or turn phase. 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; QUEUE_ITEM = QUEUE_FLOP;
conversationQueueNext(); conversationQueueNext();
@@ -158,14 +200,14 @@ queuecallback_t *QUEUE_CALLBACKS[] = {
NULL, NULL,
// 25 // 25
&conversationQueueFlopTurnRiver, &conversationQueueNextBetter,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
// 30 // 30
NULL, &conversationQueueFlopTurnRiver,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@@ -186,6 +228,12 @@ queuecallback_t *QUEUE_CALLBACKS[] = {
// NULL, // NULL,
}; };
void conversationQueueInit() { inline void conversationQueueInit() {
QUEUE_ITEM = QUEUE_BEGIN; 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]();
}

View File

@@ -19,9 +19,9 @@ extern queuecallback_t *QUEUE_CALLBACKS[];
#define QUEUE_TAKE_BLINDS 10 #define QUEUE_TAKE_BLINDS 10
#define QUEUE_DEAL_CARDS 15 #define QUEUE_DEAL_CARDS 15
#define QUEUE_BEGIN_BETTING 20 #define QUEUE_BEGIN_BETTING 20
#define QUEUE_FLOP 25 #define QUEUE_NEXT_BETTER 25
#define QUEUE_FLOP 30
#define QUEUE_WINNER_DECIDE 40 #define QUEUE_WINNER_DECIDE 40
#define conversationQueueNext() QUEUE_CALLBACKS[QUEUE_ITEM]() inline void conversationQueueInit();
inline void conversationQueueNext();
void conversationQueueInit();

View File

@@ -11,10 +11,11 @@ char *TEXTBOX_TEXT;
uint8_t TEXTBOX_TEXT_LENGTH; uint8_t TEXTBOX_TEXT_LENGTH;
uint8_t TEXTBOX_STATE; uint8_t TEXTBOX_STATE;
uint8_t TEXTBOX_SCROLL; 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 i;
uint8_t TEXTBOX_TILES[TEXTBOX_TILES_MAX];
// Reset textbox state // Reset textbox state
TEXTBOX_TEXT = NULL; 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] = BORDER_TILE_CENTER_LEFT;
TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * (i+1) - 1] = BORDER_TILE_CENTER_RIGHT; 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) { void conversationTextboxSetText(char *text, uint8_t length) {
uint8_t i, j; uint8_t i, j;
uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW];
// Reset textbox state // Reset textbox state
TEXTBOX_TEXT = text; TEXTBOX_TEXT = text;
TEXTBOX_TEXT_LENGTH = length; TEXTBOX_TEXT_LENGTH = length;
TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE; TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE;
TEXTBOX_SCROLL = 0; TEXTBOX_SCROLL = 0;
TEXTBOX_CHAR_POSITION = 0;
// Fill blank characters // Fill blank characters
for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) { for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) {
for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) { for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) {
TEXTBOX_TILES[(i+1) + ((j + 1) * TEXTBOX_WIDTH_IN_TILES)] = ( TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK;
TEXTBOX_TILE_BLANK
);
} }
} }
set_win_tiles( set_win_tiles(
0, 0, 1, 1,
TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02,
TEXTBOX_TILES TEXTBOX_TILES
); );
// Show the window layer.
SHOW_WIN; SHOW_WIN;
} }
void conversationTextboxUpdate() { inline void conversationTextboxUpdate() {
uint8_t i, j; uint8_t i;
// Is the textbox visible? // Is the textbox visible?
if(!(TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE)) return; if(!(TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE)) return;
@@ -88,35 +97,25 @@ void conversationTextboxUpdate() {
} }
// Move to the next character. // Move to the next character.
TEXTBOX_SCROLL++; if(TEXTBOX_TEXT[TEXTBOX_SCROLL] == ' ') {
j = TEXTBOX_WIDTH_IN_TILES + 1;
for(i = 0; i < TEXTBOX_SCROLL; i++) {
// Whitespace, do nothing. // Whitespace, do nothing.
if(TEXTBOX_TEXT[i] == ' ') { TEXTBOX_CHAR_POSITION++;
j++; } else if(TEXTBOX_TEXT[TEXTBOX_SCROLL] == '\n') {
continue;
}
// Newline character, move the next tile to the next row. // Newline character, move the next tile to the next row.
if(TEXTBOX_TEXT[i] == '\n') { TEXTBOX_CHAR_POSITION = (
j = ( (TEXTBOX_CHAR_POSITION / TEXTBOX_CHARS_PER_ROW) + 1
(j / TEXTBOX_WIDTH_IN_TILES)*TEXTBOX_WIDTH_IN_TILES ) * TEXTBOX_CHARS_PER_ROW;
) + TEXTBOX_WIDTH_IN_TILES + 1; } else {
continue; // Reveal the next character. TODO: I'll optimize this.
} set_win_tiles(
1 + (TEXTBOX_CHAR_POSITION % TEXTBOX_CHARS_PER_ROW),
// Reveal the next character 1 + (TEXTBOX_CHAR_POSITION / TEXTBOX_CHARS_PER_ROW),
TEXTBOX_TILES[j] = TEXTBOX_TEXT[i]; 1, 1,
j++; TEXTBOX_TEXT + TEXTBOX_SCROLL
);
TEXTBOX_CHAR_POSITION++;
} }
TEXTBOX_SCROLL++;
// Update the window tilemap
set_win_tiles(
0, 0,
TEXTBOX_WIDTH_IN_TILES,
TEXTBOX_HEIGHT_IN_TILES,
TEXTBOX_TILES
);
// Update state. TODO: I actually don't really need this state, it's just here // 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. // incase I want to check if the state has scrolled later on? Doubt it though.

View File

@@ -45,8 +45,8 @@ extern char *TEXTBOX_TEXT;
extern uint8_t TEXTBOX_TEXT_LENGTH; extern uint8_t TEXTBOX_TEXT_LENGTH;
extern uint8_t TEXTBOX_STATE; extern uint8_t TEXTBOX_STATE;
extern uint8_t TEXTBOX_SCROLL; 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 conversationTextboxSetText(char *text, uint8_t length);
void conversationTextboxUpdate(); inline void conversationTextboxUpdate();

View File

@@ -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 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); set_bkg_data(0x00, COMMON_TILE_COUNT, COMMON_TILES);
} }

View File

@@ -34,4 +34,4 @@
extern const uint8_t COMMON_TILES[]; extern const uint8_t COMMON_TILES[];
void commonTilesInit(); inline void commonTilesInit();

View File

@@ -8,8 +8,8 @@
#pragma once #pragma once
#include "FONT.h" #include "FONT.h"
#include "BORDER.h" #include "BORDER.h"
#include "SM.h" // #include "SM.h"
#define FONT_DATA_POSITION 0x04 #define FONT_DATA_POSITION 0x04
#define BORDER_DATA_POSITION FONT_DATA_POSITION+FONT_IMAGE_TILES #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

View File

@@ -9,6 +9,6 @@
#include <gb/gb.h> #include <gb/gb.h>
#include <gb/bgb_emu.h> #include <gb/bgb_emu.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> // #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <rand.h> #include <rand.h>

View File

@@ -6,7 +6,6 @@
*/ */
#include "main.h" #include "main.h"
#include "SM.h"
void main() { void main() {
int16_t j; int16_t j;
@@ -37,19 +36,12 @@ void main() {
SCX_REG = 0x00; SCX_REG = 0x00;
SCY_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 // Now turn the screen on
DISPLAY_ON; DISPLAY_ON;
enable_interrupts(); enable_interrupts();
wait_vbl_done(); wait_vbl_done();
// Alright begin the game logic here. // Alright begin the game logic here.
BGB_MESSAGE("Begin.");
conversationQueueNext(); conversationQueueNext();
// Begin the loop // Begin the loop

View File

@@ -56,7 +56,9 @@ void pokerNewRound() {
for(i = 0; i < POKER_POT_COUNT_MAX; i++) { for(i = 0; i < POKER_POT_COUNT_MAX; i++) {
POKER_POTS[i].chips = 0; POKER_POTS[i].chips = 0;
POKER_POTS[i].call = 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 // Fill deck

View File

@@ -18,9 +18,8 @@ typedef struct {
/** Current call value for this pot */ /** Current call value for this pot */
uint16_t call; uint16_t call;
/** Players who are participating in the pot */ /** Players who are participating in the pots current bet (in the pot) */
uint8_t players[POKER_PLAYER_COUNT_MAX]; uint16_t players[POKER_PLAYER_COUNT_MAX];
uint8_t playersCount;
} pokerpot_t; } pokerpot_t;
extern pokerpot_t POKER_POTS[]; extern pokerpot_t POKER_POTS[];

View File

@@ -11,12 +11,12 @@ uint16_t TIME_CURRENT;
uint16_t TIME_FUTURE; uint16_t TIME_FUTURE;
uint8_t TIME_FUTURE_TYPE; uint8_t TIME_FUTURE_TYPE;
void timeInit() { inline void timeInit() {
TIME_CURRENT = 0; TIME_CURRENT = 0;
TIME_FUTURE = 0; TIME_FUTURE = 0;
TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL; TIME_FUTURE_TYPE = TIME_FUTURE_TYPE_NULL;
} }
void timeUpdate() { inline void timeUpdate() {
TIME_CURRENT++; TIME_CURRENT++;
} }

View File

@@ -21,5 +21,5 @@ extern uint16_t TIME_CURRENT;
extern uint16_t TIME_FUTURE; extern uint16_t TIME_FUTURE;
extern uint8_t TIME_FUTURE_TYPE; extern uint8_t TIME_FUTURE_TYPE;
void timeInit(); inline void timeInit();
void timeUpdate(); inline void timeUpdate();