Close to done refactoring now.

This commit is contained in:
2021-09-19 22:18:23 -07:00
parent 84e4fc0c00
commit a2c269ab33
7 changed files with 67 additions and 44 deletions

View File

@ -25,9 +25,9 @@ void _pokerGameActionBetOnUpdate(
// Handle as an AI // Handle as an AI
if(isHuman) { if(isHuman) {
if(inputIsPressed(&game->engine->input, INPUT_DOWN)) { if(inputIsPressed(&game->engine.input, INPUT_DOWN)) {
} else if(inputIsPressed(&game->engine->input, INPUT_RIGHT)) { } else if(inputIsPressed(&game->engine.input, INPUT_RIGHT)) {
} else if(inputIsPressed(&game->engine->input, INPUT_UP)) { } else if(inputIsPressed(&game->engine.input, INPUT_UP)) {
} }
} else { } else {
@ -84,7 +84,9 @@ void _pokerGameActionBetOnEnd(
pokergame_t *game = (pokergame_t *)action->data; pokergame_t *game = (pokergame_t *)action->data;
// Get which player is remaining to move. // Get which player is remaining to move.
game->poker.bet.better = pokerBetGetRemainingPlayer(&game->poker); game->poker.bet.better = pokerBetGetRemainingPlayer(
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
);
// Restack // Restack
pokerGameActionRestackAdd(game); pokerGameActionRestackAdd(game);
@ -106,7 +108,9 @@ void _pokerGameActionBetOnEnd(
discussion.poker = game; discussion.poker = game;
pokerDiscussionQueue(&discussion); pokerDiscussionQueue(&discussion);
pokerBetResetBetter(&game->poker); pokerBetResetBetter(
&game->poker, &game->poker.players, game->poker.roundSmallBlind
);
pokerGameActionRestackAdd(game); pokerGameActionRestackAdd(game);
pokerGameActionLookAdd(game, game->poker.bet.better); pokerGameActionLookAdd(game, game->poker.bet.better);
pokerGameActionBetAdd(game); pokerGameActionBetAdd(game);

View File

@ -9,9 +9,11 @@
#include "../../../libs.h" #include "../../../libs.h"
#include "action.h" #include "action.h"
#include "restack.h" #include "restack.h"
#include "../../../input/input.h"
#include "../../../poker/turn.h" #include "../../../poker/turn.h"
#include "../../../poker/bet.h" #include "../../../poker/bet.h"
#include "../../../poker/actions/flop.h" #include "../../../poker/actions/flop.h"
#include "../pokerdiscussion.h"
/** Callback when the bet action is updated. */ /** Callback when the bet action is updated. */
void _pokerGameActionBetOnUpdate( void _pokerGameActionBetOnUpdate(

View File

@ -41,7 +41,9 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
// Begin Betting Round. This will queue for one player only and then the round // Begin Betting Round. This will queue for one player only and then the round
// will take over. // will take over.
pokerBetResetBetter(&game->poker); pokerBetResetBetter(
&game->poker, game->poker.players, game->poker.roundSmallBlind
);
pokerGameActionBetAdd(game); pokerGameActionBetAdd(game);
} }

View File

@ -18,10 +18,10 @@ bool gameInstanceInit(pokergame_t *game) {
); );
// Initialize the world // Initialize the world
pokerWorldInit(game); pokerWorldInit(&game->world, &game->scene, &game->assets);
// Initialize the UI. // Initialize the UI.
pokerUiInit(game); pokerUiInit(&game->ui);
// Add the first action, the game action, and then start the action queue. // Add the first action, the game action, and then start the action queue.
pokerGameActionStartAdd(game); pokerGameActionStartAdd(game);
@ -30,34 +30,40 @@ bool gameInstanceInit(pokergame_t *game) {
return true; return true;
} }
void gameInstanceUpdate(pokergame_t *game, engine_t *engine) { void gameInstanceUpdate(pokergame_t *game) {
// Update the VN Engine. // Update the VN Engine.
vnSceneUpdate(&game->scene, engine); vnSceneUpdate(&game->scene, &game->engine);
// Update the UI // Update the UI
pokerUiUpdate(game, engine); pokerUiUpdate(
&game->ui,
&game->engine,
&game->assets.shader,
game->scene.characters,
game->poker.players
);
// Bind the shader. // Bind the shader.
shaderUse(&game->assets.shader); shaderUse(&game->assets.shader);
// Render the visual novel scene. // Render the visual novel scene.
vnSceneRenderWorld(&game->scene, engine, &game->assets.shader); vnSceneRenderWorld(&game->scene, &game->engine, &game->assets.shader);
pokerWorldRender(&game->world, engine, &game->assets); pokerWorldRender(&game->world, &game->assets);
vnSceneRenderCharacters(&game->scene, &game->assets.shader); vnSceneRenderCharacters(&game->scene, &game->assets.shader);
// Render the UI // Render the UI
vnSceneRenderGui(&game->scene, engine, &game->assets.shader); vnSceneRenderGui(&game->scene, &game->engine, &game->assets.shader);
pokerUiRender(game, engine); pokerUiRender(&game->ui, &game->engine, &game->assets, &game->poker);
} }
void gameInstanceDispose(pokergame_t *game) { void gameInstanceDispose(pokergame_t *game) {
//Cleanup the UI //Cleanup the UI
pokerUiDispose(game); pokerUiDispose(&game->ui);
// Cleanup the world // Cleanup the world
pokerWorldDispose(game); pokerWorldDispose(&game->world);
// Destroy the Visual Novel engine. // Destroy the Visual Novel engine.
vnSceneDispose(&game->scene); vnSceneDispose(&game->scene);

View File

@ -16,6 +16,7 @@
#include "pokerui.h" #include "pokerui.h"
#include "pokerworld.h" #include "pokerworld.h"
#include "pokergameaction.h" #include "pokergameaction.h"
#include "actions/start.h"
/** /**
* Initializes the game state for the poker game. * Initializes the game state for the poker game.

View File

@ -83,7 +83,7 @@ void pokerUiUpdate(
shaderUse(shader); shaderUse(shader);
shaderUseCamera(shader, &camera); shaderUseCamera(shader, &camera);
shaderUsePosition(shader, 0,0,0, 0,0,0); shaderUsePosition(shader, 0,0,0, 0,0,0);
vnCharacterRender(characters + playerIndex, shader); vnCharacterRender(characters + j, shader);
// Increment // Increment
j++; j++;
@ -92,34 +92,35 @@ void pokerUiUpdate(
renderResetFramebuffer(&engine->render); renderResetFramebuffer(&engine->render);
} }
void pokerUiRender(pokerui_t *ui, engine_t *engine, shader_t *shader) { void pokerUiRender(
pokerui_t *ui, engine_t *engine, pokergameassets_t *assets, poker_t *poker
) {
uint8_t i, j; uint8_t i, j;
pokerplayerui_t *ui;
pokerplayer_t *player; pokerplayer_t *player;
char message[128];
float scale; float scale;
align_t align; align_t align;
float gx, gy, gw, gh, x, y; float gx, gy, gw, gh, x, y;
char message[128];
// Get the default font scale size. // Get the default font scale size.
scale = fontGetScale(FONT_SIZE_DEFAULT); scale = fontGetScale(FONT_SIZE_DEFAULT);
// <testing> // <testing>
if(pokerGame->poker.state >= POKER_STATE_DEALING) { if(poker->state >= POKER_STATE_DEALING) {
for(j = 0; j < POKER_PLAYER_COUNT; j++) { for(j = 0; j < POKER_PLAYER_COUNT; j++) {
player = pokerGame->poker.players + j; player = poker->players + j;
for(i = 0; i < player->cardCount; i++) { for(i = 0; i < player->cardCount; i++) {
pokerCardSetImage(&pokerGame->ui.card, &pokerGame->assets.cardTexture, player->cards[i]); pokerCardSetImage(&ui->card, &assets->cardTexture, player->cards[i]);
imageRender(&pokerGame->ui.card, &pokerGame->assets.shader, i * 64.0f, j * 100); imageRender(&ui->card, &assets->shader, i * 64.0f, j * 100.0f);
} }
} }
} }
player = pokerGame->poker.players + POKER_PLAYER_HUMAN_INDEX; player = poker->players + POKER_PLAYER_HUMAN_INDEX;
if(pokerGame->poker.bet.better == POKER_PLAYER_HUMAN_INDEX) { if(poker->bet.better == POKER_PLAYER_HUMAN_INDEX) {
sprintf(message, "Press down to fold, up to bet, right to check/call."); sprintf(message, "Press down to fold, up to bet, right to check/call.");
labelSetText(&pokerGame->ui.player->label, &pokerGame->assets.font, message); labelSetText(&ui->label, &assets->font, message);
labelRender(&pokerGame->ui.player->label, &pokerGame->assets.shader, 300, 100); labelRender(&ui->label, &assets->shader, 300, 100);
} }
// </testing> // </testing>
j = 0; j = 0;
@ -127,7 +128,7 @@ void pokerUiRender(pokerui_t *ui, engine_t *engine, shader_t *shader) {
if(i == POKER_PLAYER_HUMAN_INDEX) continue; if(i == POKER_PLAYER_HUMAN_INDEX) continue;
// Get the player. // Get the player.
player = game->poker.players + i; player = poker->players + i;
// Position the grid itself. // Position the grid itself.
x = 0; x = 0;
@ -135,40 +136,40 @@ void pokerUiRender(pokerui_t *ui, engine_t *engine, shader_t *shader) {
// Render face // Render face
gridGetChild(&ui->grid, 1, 0, 1, 2, &gx, &gy, &gw, &gh); gridGetChild(&ui->grid, 1, 0, 1, 2, &gx, &gy, &gw, &gh);
shaderUseTexture(shader, &ui->frames + j); shaderUseTexture(&assets->shader, &ui->frames + j);
shaderUsePosition(shader, x + gx, y + gy, 0, 0,0,0); shaderUsePosition(&assets->shader, x + gx, y + gy, 0, 0,0,0);
primitiveDraw(&ui->quad, 0, -1); primitiveDraw(&ui->quad, 0, -1);
// Render chips // Render chips
sprintf(buffer, "$%i", player->chips); sprintf(message, "$%i", player->chips);
ui->label.maxWidth = -1; ui->label.maxWidth = -1;
labelSetText(&ui->label, font, buffer); labelSetText(&ui->label, &assets->font, message);
align = gridGetAndAlignChild( align = gridGetAndAlignChild(
&ui->grid, 0, 0, 1, 1, &ui->grid, 0, 0, 1, 1,
ALIGN_POS_END|ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER|ALIGN_SIZE_ORIGINAL, ALIGN_POS_END|ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER|ALIGN_SIZE_ORIGINAL,
ui->label.info.width, ui->label.info.height ui->label.info.width, ui->label.info.height
); );
labelRender(&ui->label, shader, x+align.x, y+align.y); labelRender(&ui->label, &assets->shader, x+align.x, y+align.y);
// Render state // Render state
if(player->state & POKER_PLAYER_STATE_OUT) { if(player->state & POKER_PLAYER_STATE_OUT) {
sprintf(buffer, "Out"); sprintf(message, "Out");
} else if(player->state & POKER_PLAYER_STATE_FOLDED) { } else if(player->state & POKER_PLAYER_STATE_FOLDED) {
sprintf(buffer, "Folded"); sprintf(message, "Folded");
} else if(player->state & POKER_PLAYER_STATE_SHOWING) { } else if(player->state & POKER_PLAYER_STATE_SHOWING) {
sprintf(buffer, "Showing"); sprintf(message, "Showing");
} else if(game->poker.bet.better == playerIndex) { } else if(poker->bet.better == j) {
sprintf(buffer, "Thinking"); sprintf(message, "Thinking");
} else { } else {
sprintf(buffer, "Whatever"); sprintf(message, "Whatever");
} }
labelSetText(&ui->label, font, buffer); labelSetText(&ui->label, &assets->font, message);
align = gridGetAndAlignChild( align = gridGetAndAlignChild(
&ui->grid, 0, 1, 1, 1, &ui->grid, 0, 1, 1, 1,
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL, ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
ui->label.info.width, ui->label.info.height ui->label.info.width, ui->label.info.height
); );
labelRender(&ui->label, shader, x+align.x, y+align.y); labelRender(&ui->label, &assets->shader, x+align.x, y+align.y);
// Increment. // Increment.
j++; j++;

View File

@ -21,7 +21,10 @@
#include "../../ui/align.h" #include "../../ui/align.h"
#include "../../poker/player.h" #include "../../poker/player.h"
#include "../../poker/poker.h" #include "../../poker/poker.h"
#include "../../poker/bet.h"
#include "../../vn/vnscene.h" #include "../../vn/vnscene.h"
#include "pokerworld.h"
#include "pokergameassets.h"
#define POKER_UI_PLAYER_IMAGE_SIZE 64 #define POKER_UI_PLAYER_IMAGE_SIZE 64
#define POKER_UI_PLAYER_WIDTH 300 #define POKER_UI_PLAYER_WIDTH 300
@ -67,8 +70,12 @@ void pokerUiUpdate(
* *
* @param ui UI to render. * @param ui UI to render.
* @param engine Engine to use for the render. * @param engine Engine to use for the render.
* @param assets Poker game assets.
* @param poker Poker instance.
*/ */
void pokerUiRender(pokerui_t *ui, engine_t *engine); void pokerUiRender(
pokerui_t *ui, engine_t *engine, pokergameassets_t *assets, poker_t *poker
);
/** /**
* Cleanup only the UI elements for a poker game. * Cleanup only the UI elements for a poker game.