Refactoring some of the poker game logic again.

This commit is contained in:
YourWishes committed 2021-07-27 09:49:54 -07:00
1 parent a63c9d898b
commit 54559e761c
36 files changed
+99 -304

No files matched your search

+1 -4
View File
@@ -36,20 +36,17 @@
// Game Logic
#include "game/game.h"
#include "game/poker/pokergame.h"
// Player Input
#include "input/input.h"
// Poker Game Logic
#include "poker/round/match.h"
#include "poker/bet.h"
#include "poker/card.h"
#include "poker/dealer.h"
#include "poker/player.h"
#include "poker/poker.h"
#include "poker/render.h"
#include "poker/strings.h"
#include "poker/winner.h"
// Utility Objects
+3 -7
View File
@@ -6,11 +6,7 @@
#pragma once
#include "../libs.h"
#include "../engine/engine.h"
#include "../poker/poker.h"
/** Name of the current game */
#define GAME_NAME "Dawn"
#include "poker/pokergame.h"
/** Describes the current game */
typedef struct {
@@ -19,6 +15,6 @@ typedef struct {
/** Engine for the game */
engine_t engine;
/** Poker Game State */
poker_t poker;
/** Poker Game */
pokergame_t pokerGame;
} game_t;
@@ -7,8 +7,12 @@
#pragma once
#include "../../libs.h"
#include "../../poker/poker.h"
/** Name of the Poker Game */
#define POKER_GAME_NAME "Dawn Poker Game"
typedef struct {
// Time when match started (for fade effect)
float time;
} pokerroundmatch_t;
/** Poker Game State */
poker_t poker;
} pokergame_t;
+3
View File
@@ -20,6 +20,9 @@
typedef struct {
/** Blinds */
uint32_t blindSmall, blindBig;
/** For Betting round, which player is currently betting */
uint8_t better;
/** Current pot of chips */
uint32_t pot;
-10
View File
@@ -8,9 +8,6 @@
#pragma once
#include "../libs.h"
#include "card.h"
#include "../display/texture.h"
#include "../display/tileset.h"
#include "../display/primitive.h"
/** How many cards the dealer can hold in their hand */
#define POKER_DEALER_HAND_SIZE 5
@@ -31,11 +28,4 @@ typedef struct {
/** Card grave (where spent cards go when burned */
card_t grave[POKER_DEALER_GRAVE_SIZE];
uint8_t graveSize;
// Rendering assets (unfinished)
texture_t dealerTexture;
tileset_t dealerTileset;
primitive_t dealerPrimitive;
} pokerdealer_t;
-12
View File
@@ -10,10 +10,6 @@
#include "bet.h"
#include "dealer.h"
#include "card.h"
#include "../display/texture.h"
#include "../display/primitive.h"
#include "../display/tileset.h"
/** How many cards a player can hold in their hand */
#define POKER_PLAYER_HAND 2
@@ -56,12 +52,4 @@ typedef struct {
/** Current bet in current round player has placed */
uint32_t currentBet;
// Rendering assets
texture_t bodyTexture;
primitive_t bodyPrimitive;
texture_t faceTexture;
primitive_t facePrimitive;
} pokerplayer_t;
+8 -54
View File
@@ -11,18 +11,8 @@
#include "dealer.h"
#include "player.h"
#include "card.h"
#include "render.h"
#include "winner.h"
#include "round/match.h"
#include "../display/camera.h"
#include "../display/shader.h"
#include "../display/texture.h"
#include "../display/tileset.h"
#include "../display/framebuffer.h"
#include "../display/primitive.h"
/** Rounds that the game can be in */
#define POKER_ROUND_MATCH 0x00
#define POKER_ROUND_START 0x01
@@ -37,69 +27,33 @@
#define POKER_ROUND_BET3 0x0A
#define POKER_ROUND_WINNER 0x0B
/** GUI Height fix (To keep gui scaling nicely we use a fixed height) */
#define POKER_GUI_HEIGHT 2160
/** How many cards to deal each player during the deal round */
#define POKER_DEAL_CARD_EACH 2
/** How many cards are dealt for the flop, turn and river */
#define POKER_FLOP_CARD_COUNT 3
#define POKER_TURN_CARD_COUNT 1
#define POKER_RIVER_CARD_COUNT 1
typedef struct {
//////////////////////////////////////////////////////////////////////////////
// Poker Logic Variables
//////////////////////////////////////////////////////////////////////////////
typedef struct {
/** Poker betting state */
pokerbet_t bet;
/** Player States */
pokerdealer_t dealer;
pokerplayer_t players[POKER_PLAYER_COUNT];
/** Winning player states */
pokerwinner_t winner;
/** The current player that is the dealer */
uint8_t roundDealer;
uint8_t roundSmallBlind;
uint8_t roundBigBlind;
//////////////////////////////////////////////////////////////////////////////
// Round variables
//////////////////////////////////////////////////////////////////////////////
/** The current round the game is on */
uint8_t round;
/** For Betting round, which player is currently betting */
uint8_t roundBetCurrent;
uint32_t roundTextCounter;
pokerroundmatch_t roundMatch;
//////////////////////////////////////////////////////////////////////////////
// Rendering Variables
//////////////////////////////////////////////////////////////////////////////
/** Frames to hold the world and GUI render outputs */
framebuffer_t frameWorld, frameGui;
/** Game's Shader */
shader_t shader;
/** Camera for the world and the GUI */
camera_t cameraWorld, cameraGui;
/** Refer to POKER_GUI_HEIGHT */
float guiWidth;
texture_t chipTexture;
primitive_t chipPrimitive;
texture_t tableTexture;
primitive_t tablePrimitive;
texture_t cardTexture;
tileset_t cardTileset;
primitive_t cardPrimitive;
/** Which player is the small blind for this round */
uint8_t roundSmallBlind;
/** Which player is the big blind for this round */
uint8_t roundBigBlind;
} poker_t;
-12
View File
@@ -1,12 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#define POKER_TALK_MATCH_START "The game is no-limits Texas Hold'em."
#define POKER_TALK_MATCH_BUYIN "The buy-in for this match is $10,000."
+1 -1
View File
@@ -18,9 +18,9 @@ typedef struct {
float x, y, z;
float yaw, pitch, roll;
float scaleX, scaleY;
float blinkStart;
bool talking;
float blinkStart;
tileset_t tilesetEyes;
tileset_t tilesetMouth;
+4 -14
View File
@@ -7,20 +7,12 @@
#include "game.h"
testscene_t testScene;
bool gameInit(game_t *game) {
// Init the game
game->name = GAME_NAME;
// Init the engine and the rendering pipeline
engineInit(&game->engine, game);
// Hand off to the poker logic.
testSceneInit(&testScene, game);
// pokerInit(&game->poker, &game->engine);
return true;
// Send off to the game instance
return pokerGameInit(game);
}
bool gameUpdate(game_t *game, float platformDelta) {
@@ -28,15 +20,13 @@ bool gameUpdate(game_t *game, float platformDelta) {
engineUpdateStart(&game->engine, game, platformDelta);
// Hand off to the poker logic
testSceneRender(&testScene, game);
// pokerUpdate(&game->poker, &game->engine);
pokerGameUpdate(game);
// Hand back to the engine.
return engineUpdateEnd(&game->engine, game);
}
void gameDispose(game_t *game) {
pokerDispose(&game->poker);
pokerGameDispose(game);
engineDispose(&game->engine, game);
}
+1 -2
View File
@@ -6,8 +6,7 @@
#pragma once
#include <dawn/dawn.h>
#include "../engine/engine.h"
#include "../poker/poker.h"
#include "../test/testscene.h"
#include "poker/pokergame.h"
/**
* Initialize the game context.
+23
View File
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pokergame.h"
bool pokerGameInit(game_t *game) {
// Init the game
game->name = POKER_GAME_NAME;
// Hand off to the poker logic.
pokerInit(&game->pokerGame.poker, &game->engine);
}
void pokerGameUpdate(game_t *game) {
}
void pokerGameDispose(game_t *game) {
}
+30
View File
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../poker/poker.h"
/**
* Initializes the game state for the poker game.
*
* @param game Game to initialize.
* @returns True if successful, otherwise false.
*/
bool pokerGameInit(game_t *game);
/**
* Updates the poker game instance.
* @param game Game to update for.
*/
void pokerGameUpdate(game_t *game);
/**
* Disposes a previously initialized poker game instance.
* @param game Game to initialize for.
*/
void pokerGameDispose(game_t *game);
-1
View File
@@ -15,7 +15,6 @@ bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) {
return (poker->players + POKER_PLAYER_HUMAN_INDEX) == player;
}
void pokerPlayerReset(pokerplayer_t *player) {
player->cardCount = 0;
player->currentBet = 0;
+1 -29
View File
@@ -7,21 +7,8 @@
#include "poker.h"
void pokerInit(poker_t *poker, engine_t *engine) {
// Load the main shader
assetShaderLoad(&poker->shader,
"shaders/textured.vert", "shaders/textured.frag"
);
void pokerInit(poker_t *poker) {
// Initialize the render stuffs.
pokerFrameInit(poker, &engine->render);
pokerWorldInit(poker);
pokerCardInit(poker);
pokerPlayerInit(poker);
// pokerTalkInit(poker);
// Hand over to the deal for the first time.
pokerMatchInit(poker, engine);
}
void pokerUpdate(poker_t *poker, engine_t *engine) {
@@ -39,22 +26,7 @@ void pokerUpdate(poker_t *poker, engine_t *engine) {
default:
break;
}
shaderUse(&poker->shader);
pokerFrameWorld(poker, &engine->render);
pokerWorldRender(poker);
for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) {
uint8_t seat = pokerPlayerGetSeatForPlayer(pi);
pokerPlayerRender(poker, poker->players + pi, seat);
}
pokerFrameGui(poker, &engine->render);
// pokerTalkRender(poker, &engine->input);
}
void pokerDispose(poker_t * poker) {
// pokerTalkDispose(poker);
pokerWorldDispose(poker);
shaderDispose(&poker->shader);
}
+1 -13
View File
@@ -7,25 +7,13 @@
#pragma once
#include <dawn/dawn.h>
#include "round/match.h"
#include "render/frame.h"
#include "render/world.h"
#include "render/card.h"
#include "render/player.h"
#include "render/look.h"
#include "../file/asset.h"
#include "../display/shader.h"
#include "../display/camera.h"
#include "../display/gui/font.h"
/**
* Initializes the poker context for the first time.
* @param poker Poker context to initialize.
* @param engine Rendering context.
*/
void pokerInit(poker_t *poker, engine_t *engine);
void pokerInit(poker_t *poker);
/**
* Updates the poker context.
+7 -8
View File
@@ -9,10 +9,10 @@
void pokerRoundBetPlayerNext(poker_t *poker) {
// Go to next player, keep contained.
poker->roundBetCurrent = (poker->roundBetCurrent + 1) % POKER_PLAYER_COUNT;
poker->bet.better = (poker->bet.better + 1) % POKER_PLAYER_COUNT;
// Did we go full circle?
if(poker->roundBetCurrent == poker->roundSmallBlind) {
if(poker->bet.better == poker->roundSmallBlind) {
if(poker->round == POKER_ROUND_BET3) {
pokerWinnerInit(poker);
return;
@@ -23,7 +23,7 @@ void pokerRoundBetPlayerNext(poker_t *poker) {
}
// Init the next player
pokerRoundBetPlayerInit(poker, poker->players + poker->roundBetCurrent);
pokerRoundBetPlayerInit(poker, poker->players + poker->bet.better);
}
@@ -34,7 +34,7 @@ void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player) {
return;
}
printf("Betting round player %u\n", poker->roundBetCurrent);
printf("Betting round player %u\n", poker->bet.better);
if(pokerPlayerIsHuman(poker, player)) {
pokerRoundBetPlayerNext(poker);
return;
@@ -47,7 +47,6 @@ void pokerRoundBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) {
}
void pokerRoundBetInit(poker_t *poker) {
printf("Betting round start\n");
@@ -66,11 +65,11 @@ void pokerRoundBetInit(poker_t *poker) {
}
// Set the inital player
poker->roundBetCurrent = poker->roundSmallBlind;
pokerRoundBetPlayerInit(poker, poker->players+poker->roundBetCurrent);
poker->bet.better = poker->roundSmallBlind;
pokerRoundBetPlayerInit(poker, poker->players + poker->bet.better);
}
void pokerRoundBetUpdate(poker_t *poker) {
// Take the current player
pokerRoundBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent);
pokerRoundBetPlayerUpdate(poker, poker->players + poker->bet.better);
}
-3
View File
@@ -9,9 +9,6 @@
void pokerDealInit(poker_t *poker) {
poker->round = POKER_ROUND_DEAL;
// Hard look at the dealer
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 0);
// Shuffle the deck
cardShuffle(poker->dealer.deck, CARD_DECK_SIZE);
-1
View File
@@ -8,7 +8,6 @@
#pragma once
#include <dawn/dawn.h>
#include "../../util/array.h"
#include "../render/look.h"
#include "../dealer.h"
#include "../card.h"
#include "bet.h"
+1 -10
View File
@@ -9,13 +9,9 @@
void pokerMatchInit(poker_t *poker, engine_t *engine) {
uint8_t x;
// Look at the dealer
poker->roundMatch.time = engine->time.current;
// Reset the main game state. This does not init the round.
pokerBetInit(&poker->bet);
poker->roundDealer = POKER_PLAYER_COUNT-2;
poker->roundTextCounter = 0;
poker->round = POKER_ROUND_MATCH;
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
@@ -23,13 +19,8 @@ void pokerMatchInit(poker_t *poker, engine_t *engine) {
poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT;
}
printf("Match Start\n");
// pokerStartInit(poker);
pokerStartInit(poker);
}
void pokerMatchUpdate(poker_t *poker, engine_t *engine) {
// Ease into the game.
float t = easeTimeToEase(poker->roundMatch.time, engine->time.current, 5);
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_PLAYER0, (
t < 1 ? 1 - easeOutQuart(t) : 0
));
}
-1
View File
@@ -8,7 +8,6 @@
#pragma once
#include <dawn/dawn.h>
#include "start.h"
#include "../render/look.h"
/**
* Init the poker match round.
+2 -2
View File
@@ -45,8 +45,8 @@ void testSceneInit(testscene_t *scene, game_t *game) {
// Add some conversation peices.
vnConversationTalk(&scene->conversation, "Hello World", &scene->character1);
queueDelay(&scene->conversation.actionQueue, 3);
vnConversationTalk(&scene->conversation, "What?", &scene->character1);
queueDelay(&scene->conversation.actionQueue, 1);
vnConversationTalk(&scene->conversation, "What?", &scene->character2);
queueNext(&scene->conversation.actionQueue);
}
+6 -1
View File
@@ -10,13 +10,18 @@
void _vnConversationTalkStart(queue_t *queue,queueaction_t *action,uint8_t i) {
vnconversationitemdata_t *data;
data = (vnconversationitemdata_t *)action->data;
vnTextBoxSetText(&data->conversation->textbox, data->text);
if(data->character != NULL) data->character->talking = true;
if(data->character != NULL) {
data->character->talking = true;
}
}
void _vnConversationTalkUpdate(queue_t *queue,queueaction_t *action,uint8_t i) {
vnconversationitemdata_t *data;
data = (vnconversationitemdata_t *)action->data;
if(data->conversation->textbox.state & VN_TEXTBOX_STATE_CLOSED) {
if(data->character != NULL) data->character->talking = false;
queueNext(queue);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
-63
View File
@@ -1,63 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "talk.h"
void pokerTalkInit(poker_t *poker) {
poker->talkText = NULL;
poker->talkTextInfo = NULL;
poker->textLastWidth = 0;
}
void pokerTalkDispose(poker_t *poker) {
if(poker->talkTextInfo == NULL) return;
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
}
void pokerTalkTextRebuffer(poker_t *poker) {
// Check if we need to force a redraw or not.
if(poker->talkText == NULL || poker->textLastWidth != poker->guiWidth) {
if(poker->talkTextInfo != NULL) {
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
poker->talkTextInfo = NULL;
}
}
if(poker->talkText == NULL) return;
// Rebuffer
poker->talkTextInfo = fontTextClamp(&poker->font, poker->talkText, poker->guiWidth);
fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo);
}
void pokerTalkRender(poker_t *poker, input_t *input) {
pokerTalkTextRebuffer(poker);
if(poker->talkTextInfo == NULL) return;
// Render text
shaderUsePosition(&poker->shader,
0,POKER_GUI_HEIGHT-poker->talkTextInfo->height,0,
0,0,0
);
shaderUseTexture(&poker->shader, &poker->font.texture);
primitiveDraw(&poker->talkPrimitive, 0, -1);
if(inputIsPressed(input, INPUT_ACCEPT)) {
poker->talkText = NULL;
}
}
void pokerTalk(poker_t *poker, char *text) {
poker->talkText = text;
poker->roundTextCounter++;
}
bool pokerTalkIsTalking(poker_t *poker) {
return poker->talkText != NULL || poker->talkTextInfo != NULL;
}
-53
View File
@@ -1,53 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/gui/font.h"
#include "../../display/primitive.h"
#include "../../display/shader.h"
#include "../../input/input.h"
/**
* Initializes the talk manager.
* @param poker The poker game context.
*/
void pokerTalkInit(poker_t *poker);
/**
* Disposes and cleans the talk manager context.
* @param poker Poker instance.
*/
void pokerTalkDispose(poker_t *poker);
/**
* Internal method. Checks for changes and rebuffers the talk text information
* when scene changes occur.
* @param poker Poker game context to buffer for.
*/
void pokerTalkTextRebuffer(poker_t *poker);
/**
* Tick render method for the poker talk manager.
* @param poker Poker manager context.
* @param input Input manager to listen to.
*/
void pokerTalkRender(poker_t *poker, input_t *input);
/**
* Requests the talk manager to begin speaking some text.
* @param poker Poker game context
* @param text Text to speak. Please ensure this is kept alive during talk.
*/
void pokerTalk(poker_t *poker, char *text);
/**
* Returns true if the poker text manager is still running the talk.
* @param poker Poker manager.
* @returns True while the game is still running active text.
*/
bool pokerTalkIsTalking(poker_t *poker);