From d84e760c341db12afa65744906b16d9cdd2961af Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 22 May 2021 14:18:23 -0700 Subject: [PATCH] Restored some of the rendering --- include/dawn/display/render.h | 4 +- include/dawn/poker/player.h | 21 +++---- include/dawn/poker/poker.h | 75 +++++++++++++---------- include/dawn/poker/render.h | 53 ++++++++++------- src/assets/models/pokertable.c | 2 +- src/game/game.c | 62 +++---------------- src/game/game.h | 9 +-- src/poker/card.c | 34 ----------- src/poker/poker.c | 52 ++++++++++------ src/poker/poker.h | 28 ++++++--- src/poker/render/card.c | 78 ++++++++++++------------ src/poker/render/card.h | 12 ++-- src/poker/render/look.c | 12 ++-- src/poker/render/look.h | 8 +-- src/poker/render/player.c | 93 +++++++++++++++-------------- src/poker/render/player.h | 10 ++-- src/poker/render/world.c | 47 ++++----------- src/poker/render/world.h | 19 ++++-- src/poker/round/deal.c | 44 ++++++++++++++ src/poker/round/deal.h | 15 +++++ temp/poker/card.c | 15 +++++ {src => temp}/poker/card.h | 0 temp/poker/poker.c | 42 +++++++++++++ temp/poker/poker.h | 25 ++++++++ temp/render/card.c | 95 ++++++++++++++++++++++++++++++ temp/render/card.h | 53 +++++++++++++++++ {src/poker => temp}/render/chip.c | 0 {src/poker => temp}/render/chip.h | 0 {src/poker => temp}/render/frame.c | 0 {src/poker => temp}/render/frame.h | 0 temp/render/look.c | 30 ++++++++++ temp/render/look.h | 25 ++++++++ temp/render/player.c | 71 ++++++++++++++++++++++ temp/render/player.h | 34 +++++++++++ temp/render/world.c | 53 +++++++++++++++++ temp/render/world.h | 23 ++++++++ 36 files changed, 813 insertions(+), 331 deletions(-) delete mode 100644 src/poker/card.c create mode 100644 src/poker/round/deal.c create mode 100644 src/poker/round/deal.h create mode 100644 temp/poker/card.c rename {src => temp}/poker/card.h (100%) create mode 100644 temp/poker/poker.c create mode 100644 temp/poker/poker.h create mode 100644 temp/render/card.c create mode 100644 temp/render/card.h rename {src/poker => temp}/render/chip.c (100%) rename {src/poker => temp}/render/chip.h (100%) rename {src/poker => temp}/render/frame.c (100%) rename {src/poker => temp}/render/frame.h (100%) create mode 100644 temp/render/look.c create mode 100644 temp/render/look.h create mode 100644 temp/render/player.c create mode 100644 temp/render/player.h create mode 100644 temp/render/world.c create mode 100644 temp/render/world.h diff --git a/include/dawn/display/render.h b/include/dawn/display/render.h index d349e7fa..5c1a6ae2 100644 --- a/include/dawn/display/render.h +++ b/include/dawn/display/render.h @@ -11,6 +11,6 @@ * how the renderer is currently set up. */ typedef struct { - /** Resolution (in pixels) */ - int32_t width, height; + /** Resolution (in pixels). Floats to allow subpixels in future. */ + float width, height; } render_t; \ No newline at end of file diff --git a/include/dawn/poker/player.h b/include/dawn/poker/player.h index 72d86e46..a85375ca 100644 --- a/include/dawn/poker/player.h +++ b/include/dawn/poker/player.h @@ -8,26 +8,21 @@ #pragma once #include "../libs.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 -/** How many players in a poker game (excludes dealer) */ -#define POKER_PLAYER_COUNT 5 - /** State for whether or not a player has folded */ #define POKER_PLAYER_STATE_FOLDED 0x01 /** State for whether or not a player is showing their hand */ #define POKER_PLAYER_STATE_SHOWING 0x02 -/** Various seats at the table that people can sit */ -#define HOLDEM_GAME_SEAT_DEALER 0x00 -#define HOLDEM_GAME_SEAT_PLAYER0 0x04 -#define HOLDEM_GAME_SEAT_PLAYER1 0x06 -#define HOLDEM_GAME_SEAT_PLAYER2 0x05 -#define HOLDEM_GAME_SEAT_PLAYER3 0x03 -#define HOLDEM_GAME_SEAT_PLAYER4 0x02 +/** State for whether or not the player is out */ +#define POKER_PLAYER_STATE_OUT 0x04 /** Poker Player State */ typedef struct { @@ -43,4 +38,10 @@ 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; \ No newline at end of file diff --git a/include/dawn/poker/poker.h b/include/dawn/poker/poker.h index 187880c6..539bae16 100644 --- a/include/dawn/poker/poker.h +++ b/include/dawn/poker/poker.h @@ -9,13 +9,12 @@ #include "../libs.h" #include "player.h" #include "card.h" +#include "render.h" -#include "../display/tileset.h" -#include "../display/primitive.h" -#include "../display/texture.h" -#include "../display/shader.h" #include "../display/camera.h" -#include "../display/spritebatch.h" +#include "../display/shader.h" +#include "../display/texture.h" +#include "../display/tileset.h" /** Rounds that the game can be in */ #define POKER_ROUND_DEAL 0x00 @@ -32,14 +31,30 @@ /** How many cards the dealer can hold in their hand */ #define POKER_DEALER_HAND 5 +/** How many cards the grave can hold */ +#define POKER_GRAVE_SIZE CARD_DECK_SIZE + +/** How many players in a poker game (excludes dealer) */ +#define POKER_PLAYER_COUNT 5 + +/** How many chips each player has by defautl */ +#define POKER_PLAYER_CHIPS_DEFAULT 10000 + +/** The default blind cost for the big blind. Small Blind is half this */ +#define POKER_BLIND_BIG_DEFAULT 600 +#define POKER_BLIND_SMALL_DEFAULT (POKER_BLIND_BIG_DEFAULT/2) + typedef struct { /** Current Card Deck */ card_t deck[CARD_DECK_SIZE]; uint8_t deckSize; - /** Dealer Money */ - uint32_t blindSmall; - uint32_t blindBig; + /** Card grave (where spent cards go when burned */ + card_t grave[POKER_GRAVE_SIZE]; + uint8_t graveSize; + + /** Blinds */ + uint32_t blindSmall, blindBig; /** Dealer Hand */ card_t cards[POKER_DEALER_HAND]; @@ -48,37 +63,33 @@ typedef struct { /** Player States */ pokerplayer_t players[POKER_PLAYER_COUNT]; - /** Game State */ + /** The current round the game is on */ uint8_t round; - uint8_t roundPlayer; + + /** The current player that is the dealer */ uint8_t roundDealer; + + /** Current pot of chips */ uint32_t pot; + + /** The current buy-in bet size. */ uint32_t roundBet; /** Rendering Assets */ - texture_t *kagamiTexture; - tileset_t *kagamiTileset; - primitive_t *kagamiQuad; + texture_t dealerTexture; + tileset_t dealerTileset; + primitive_t dealerPrimitive; - primitive_t *chipPrimitive; - texture_t *chipTexture; - primitive_t *tablePrimitive; - texture_t *tableTexture; + texture_t chipTexture; + primitive_t chipPrimitive; + + texture_t tableTexture; + primitive_t tablePrimitive; - texture_t *cardTexture; - tileset_t *cardTileset; - primitive_t *cardPrimitive; + texture_t cardTexture; + tileset_t cardTileset; + primitive_t cardPrimitive; - texture_t *fontTexture; - tileset_t *fontTileset; - spritebatch_t *fontBatch; - - shader_t *shaderWorld; - framebuffer_t *frameLeft; - framebuffer_t *frameRight; - primitive_t *quadLeft; - primitive_t *quadRight; - camera_t cameraMain; - camera_t cameraLeft; - camera_t cameraRight; + shader_t shader; + camera_t camera; } poker_t; \ No newline at end of file diff --git a/include/dawn/poker/render.h b/include/dawn/poker/render.h index 79a1df47..14a84317 100644 --- a/include/dawn/poker/render.h +++ b/include/dawn/poker/render.h @@ -8,34 +8,45 @@ #pragma once #include "../libs.h" -/** Size of the rendered card */ -#define HOLDEM_GAME_CARD_WIDTH 0.04 -#define HOLDEM_GAME_CARD_HEIGHT HOLDEM_GAME_CARD_WIDTH/2.5*3.5 -#define HOLDEM_GAME_CARD_DEPTH 0.0005 -#define HOLDEM_GAME_CARD_PADDING 0.0125 +#include "../display/tileset.h" +#include "../display/primitive.h" +#include "../display/texture.h" +#include "../display/shader.h" +#include "../display/camera.h" +#include "../display/spritebatch.h" /** Size of the Render frames */ -#define HOLDEM_GAME_FRAME_HEIGHT RENDER_STATE.height -#define HOLDEM_GAME_FRAME_LEFT_WIDTH RENDER_STATE.width*0.65 -#define HOLDEM_GAME_FRAME_RIGHT_WIDTH (\ - RENDER_STATE.width - HOLDEM_GAME_FRAME_LEFT_WIDTH - 1\ +#define POKER_FRAME_HEIGHT RENDER_STATE.height +#define POKER_FRAME_LEFT_WIDTH RENDER_STATE.width*0.65 +#define POKER_FRAME_RIGHT_WIDTH (\ + RENDER_STATE.width - POKER_FRAME_LEFT_WIDTH - 1\ ) +/** Size of the rendered card */ +#define POKER_CARD_WIDTH 0.04 +#define POKER_CARD_HEIGHT POKER_CARD_WIDTH/2.5*3.5 +#define POKER_CARD_DEPTH 0.0005 +#define POKER_CARD_PADDING 0.0125 + /** Macro for the angle (Yaw) that the seat has */ -#define HOLDEM_GAME_SEAT_ANGLE(seat) mathDeg2Rad(-45 * seat) +#define POKER_SEAT_ANGLE(seat) mathDeg2Rad(-45 * seat) -#define HOLDEM_GAME_CARD_SLOT_HAND0 0x00 -#define HOLDEM_GAME_CARD_SLOT_HAND1 0x01 -#define HOLDEM_GAME_CARD_SLOT_FLOP0 0x02 -#define HOLDEM_GAME_CARD_SLOT_FLOP1 0x03 -#define HOLDEM_GAME_CARD_SLOT_FLOP2 0x04 -#define HOLDEM_GAME_CARD_SLOT_FLOP3 0x05 -#define HOLDEM_GAME_CARD_SLOT_FLOP4 0x06 +/** Slots where cards can render */ +#define POKER_CARD_SLOT_HAND0 0x00 +#define POKER_CARD_SLOT_HAND1 0x01 +#define POKER_CARD_SLOT_FLOP0 0x02 +#define POKER_CARD_SLOT_FLOP1 0x03 +#define POKER_CARD_SLOT_FLOP2 0x04 +#define POKER_CARD_SLOT_FLOP3 0x05 +#define POKER_CARD_SLOT_FLOP4 0x06 -#define HOLDEM_GAME_CHIP_STACK0 0x00 -#define HOLDEM_GAME_CHIP_STACK1 0x01 -#define HOLDEM_GAME_CHIP_STACK2 0x03 -#define HOLDEM_GAME_CHIP_STACK3 0x04 +/** Various seats at the table that people can sit */ +#define POKER_SEAT_DEALER 0x00 +#define POKER_SEAT_PLAYER0 0x04 +#define POKER_SEAT_PLAYER1 0x06 +#define POKER_SEAT_PLAYER2 0x05 +#define POKER_SEAT_PLAYER3 0x03 +#define POKER_SEAT_PLAYER4 0x02 typedef struct { float x, z; diff --git a/src/assets/models/pokertable.c b/src/assets/models/pokertable.c index 13dab39e..d8d413f1 100644 --- a/src/assets/models/pokertable.c +++ b/src/assets/models/pokertable.c @@ -7,7 +7,7 @@ #include "pokertable.h" -void pokerTableCreate(primitive_t *primitive) { +void pokerTableInit(primitive_t *primitive) { vertice_t vertices[POKER_TABLE_VERTICE_COUNT] = { { .x = 0.12437210000000001, .y = 0, .z = -0.30026090000000005, .u = 0.836914, .v = 0.265625 }, { .x = 0.29349590000000003, .y = 0.0176777, .z = -0.12157000000000001, .u = 0.853516, .v = 0.06445299999999998 }, diff --git a/src/game/game.c b/src/game/game.c index 7d674775..8d97170e 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -10,72 +10,28 @@ bool gameInit(game_t *game) { // Init the game game->name = GAME_NAME; - + + // Init the engine and the rendering pipeline engineInit(&game->engine, game); - // assetShaderLoad(&game->shader,"shaders/textured.vert","shaders/textured.frag"); - // assetTextureLoad(&game->texture, "cards_normal.png"); - // cubeInit(&game->primitive, 1, 1, 1); + // Hand off to the poker logic. + pokerInit(&game->poker); - // // Load the world shader. - // GAME_STATE.shaderWorld = assetShaderLoad( - // "shaders/textured.vert", "shaders/textured.frag" - // ); - - // // Font - // GAME_STATE.fontTexture = assetTextureLoad("font.png"); - // GAME_STATE.fontTileset = tilesetCreate(20, 20, - // GAME_STATE.fontTexture->width, - // GAME_STATE.fontTexture->height, - // 1, 1, 1, 1 - // ); - // GAME_STATE.fontBatch = spriteBatchCreate(1024); - - // // Prepare the renderer. - // pokerInit(&GAME_STATE.poker); - // holdemRenderFrameInit(); - // holdemRenderWorldInit(); - // holdemRenderPlayerInit(); - // holdemRenderCardInit(); - // holdemRenderChipInit(); - - // Init the input manger. return true; } bool gameUpdate(game_t *game, float platformDelta) { + // Let the engine do its thing. engineUpdateStart(&game->engine, game, platformDelta); - - cameraPerspective(&game->camera, 75, - ((float)game->engine.render.width)/((float)game->engine.render.height), - 0.01, 1000 - ); - cameraLookAt(&game->camera, 3, 3, 3, 0, 0, 0); - shaderUse(&game->shader); - shaderUseTexture(&game->shader, &game->texture); - shaderUseCamera(&game->shader, &game->camera); - shaderUsePosition(&game->shader, 0, 0, 0, 0, game->engine.time.current, 0); - primitiveDraw(&game->primitive, 0, -1); + // Hand off to the poker logic + pokerUpdate(&game->poker, &game->engine.render); - // shaderUse(GAME_STATE.shaderWorld);// TODO: remove - - // // Update the frame buffers and action queue - // holdemRenderFrameUpdate(); - // pokerActionUpdate(); - - // // Render things on each frame, then render those frames. - // holdemRenderFrameUseLeft(); - // holdemRenderWorld(); - // holdemRenderFrameUseRight(); - // holdemRenderWorld(); - // holdemRenderFrameBack(); - + // Hand back to the engine. return engineUpdateEnd(&game->engine, game); } void gameDispose(game_t *game) { + pokerDispose(&game->poker); engineDispose(&game->engine, game); - // pokerActionDispose(); - // shaderDispose(GAME_STATE.shaderWorld); } \ No newline at end of file diff --git a/src/game/game.h b/src/game/game.h index 1e165532..1f8154a7 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -6,14 +6,7 @@ #pragma once #include #include "../engine/engine.h" - -#include "../file/asset.h" -#include "../display/render.h" -#include "../display/primitive.h" -#include "../display/primitives/cube.h" -#include "../display/texture.h" -#include "../display/shader.h" -#include "../display/camera.h" +#include "../poker/poker.h" /** * Initialize the game context. diff --git a/src/poker/card.c b/src/poker/card.c deleted file mode 100644 index c5b8ca38..00000000 --- a/src/poker/card.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "card.h" - -void cardDeckFill(card_t *deck) { - uint8_t i; - for(i = 0; i < CARD_DECK_SIZE; i++) { - deck[i] = i; - } -} - -void cardShuffle(card_t *hand, uint8_t cardCount) { - uint8_t i, j; - card_t temporary; - for(i = 0; i < cardCount - 1; i++) { - // Select random element from remaining elements. - j = u8randRange(i, cardCount); - temporary = hand[j];// Take out other card - hand[j] = hand[i];// Move my card there - hand[i] = temporary;// Put other card here. - } -} - -void cardDeal(card_t *deck, card_t *hand, uint8_t deckSize, uint8_t handSize) { - card_t card; - card = deck[deckSize-1]; - deck[deckSize-1] = 0x00; - hand[handSize] = card; -} \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index f7207b27..0256868b 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -10,33 +10,49 @@ void pokerInit(poker_t *poker) { uint8_t x; - // Prepare the initial game state - poker->round = POKER_ROUND_DEAL; - poker->roundPlayer = 0x00; + // Load the main shader + assetShaderLoad(&poker->shader, + "shaders/textured.vert", "shaders/textured.frag" + ); + + // Initialize the render stuffs. + pokerWorldInit(poker); + pokerCardInit(poker); + pokerPlayerInit(poker); + + // Reset the main game state. This does not init the round. + poker->blindBig = POKER_BLIND_BIG_DEFAULT; + poker->blindSmall = POKER_BLIND_SMALL_DEFAULT; poker->roundDealer = 0x00; - poker->blindSmall = 0; - poker->blindBig = 0; for(x = 0; x < POKER_PLAYER_COUNT; x++) { poker->players[x].state = 0x00; - poker->players[x].chips = 0; - poker->players[x].cardCount = 0; - poker->players[x].currentBet = 0; + poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT; } - pokerRoundInit(poker); + // Hand over to the deal for the first time. + pokerDealInit(poker); } -void pokerRoundInit(poker_t *poker) { - uint8_t x; +void pokerUpdate(poker_t *poker, render_t *render) { + // Game Logic - // Refill the deck - cardDeckFill(poker->deck); - poker->deckSize = CARD_DECK_SIZE; + // TEMP + cameraPerspective(&poker->camera, 20,render->width/render->height,0.001,1000); + pokerLookAtPlayer(&poker->camera, pokerPlayerGetSeatForPlayer(0x00)); - // Reset the players - for(x = 0; x < POKER_PLAYER_COUNT; x++) { - poker->players[x].cardCount = 0; - poker->players[x].currentBet = 0; + // Render Logic + shaderUse(&poker->shader); + shaderUseCamera(&poker->shader, &poker->camera); + + pokerWorldRender(poker); + for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) { + uint8_t seat = pokerPlayerGetSeatForPlayer(pi); + pokerPlayerRender(poker, poker->players + pi, seat); } +} + +void pokerDispose(poker_t * poker) { + pokerWorldDispose(poker); + shaderDispose(&poker->shader); } \ No newline at end of file diff --git a/src/poker/poker.h b/src/poker/poker.h index 6c5038a9..01960a73 100644 --- a/src/poker/poker.h +++ b/src/poker/poker.h @@ -7,19 +7,31 @@ #pragma once #include -#include "card.h" +#include "round/deal.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" /** - * Initializes the poker match for the first time. - * - * @param poker Poker game to init. + * Initializes the poker context for the first time. + * @param poker Poker context to initialize. */ void pokerInit(poker_t *poker); +/** + * Updates the poker context. + * @param poker Poker game to update. + * @param render Render manager to use. + */ +void pokerUpdate(poker_t *poker, render_t *render); /** - * Initializes the round for a poker game. - * - * @param poker Poker game to init a new round for. + * Cleans an existing poker game instance. + * @param poker Poker instance to cleanup */ -void pokerRoundInit(poker_t *poker); \ No newline at end of file +void pokerDispose(poker_t *poker); \ No newline at end of file diff --git a/src/poker/render/card.c b/src/poker/render/card.c index 961a342d..0bae081d 100644 --- a/src/poker/render/card.c +++ b/src/poker/render/card.c @@ -5,61 +5,62 @@ * https://opensource.org/licenses/MIT */ +#pragma once #include "card.h" -void holdemRenderCardInit() { +void pokerCardInit(poker_t *poker) { tilesetdiv_t *cardBack; // Load Cards Texture - GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png"); - GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6, - GAME_STATE.cardTexture->width, GAME_STATE.cardTexture->height, - 0, 0, 0, 0 + assetTextureLoad(&poker->cardTexture, "cards_normal.png"); + tilesetInit(&poker->cardTileset, + CARD_COUNT_PER_SUIT, 6, + poker->cardTexture.width, poker->cardTexture.height, + 0, 0, + 0, 0 ); // Cards Primitive - cardBack = GAME_STATE.cardTileset->divisions+( - GAME_STATE.cardTileset->columns * 4 - ); - GAME_STATE.cardPrimitive = primitiveCreate( + cardBack = poker->cardTileset.divisions+(poker->cardTileset.columns * 4); + primitiveInit(&poker->cardPrimitive, QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 ); - quadBuffer(GAME_STATE.cardPrimitive, -HOLDEM_GAME_CARD_DEPTH, - -HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT, + quadBuffer(&poker->cardPrimitive, -POKER_CARD_DEPTH, + -POKER_CARD_WIDTH, -POKER_CARD_HEIGHT, cardBack->x0, cardBack->y1, - HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT, + POKER_CARD_WIDTH, POKER_CARD_HEIGHT, cardBack->x1, cardBack->y0, QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT ); } -pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) { +pokerposition_t pokerCardGetPosition(uint8_t seat, uint8_t slot) { pokerposition_t position; float t, t2; - position.yaw = HOLDEM_GAME_SEAT_ANGLE(seat); + position.yaw = POKER_SEAT_ANGLE(seat); position.x = sin(position.yaw) * -0.75; position.z = cos(position.yaw) * -0.75; t = position.yaw + mathDeg2Rad(90); switch (slot) { - case HOLDEM_GAME_CARD_SLOT_HAND0: - case HOLDEM_GAME_CARD_SLOT_HAND1: - t2 = HOLDEM_GAME_CARD_WIDTH+HOLDEM_GAME_CARD_PADDING; - if(slot == HOLDEM_GAME_CARD_SLOT_HAND0) t2 = -t2; + case POKER_CARD_SLOT_HAND0: + case POKER_CARD_SLOT_HAND1: + t2 = POKER_CARD_WIDTH+POKER_CARD_PADDING; + if(slot == POKER_CARD_SLOT_HAND0) t2 = -t2; t2 += 0.1; break; - case HOLDEM_GAME_CARD_SLOT_FLOP0: - case HOLDEM_GAME_CARD_SLOT_FLOP1: - case HOLDEM_GAME_CARD_SLOT_FLOP2: - case HOLDEM_GAME_CARD_SLOT_FLOP3: - case HOLDEM_GAME_CARD_SLOT_FLOP4: - t2 = HOLDEM_GAME_CARD_WIDTH*2+HOLDEM_GAME_CARD_PADDING; + case POKER_CARD_SLOT_FLOP0: + case POKER_CARD_SLOT_FLOP1: + case POKER_CARD_SLOT_FLOP2: + case POKER_CARD_SLOT_FLOP3: + case POKER_CARD_SLOT_FLOP4: + t2 = POKER_CARD_WIDTH*2+POKER_CARD_PADDING; t2 = ( - -t2 * ( HOLDEM_GAME_CARD_SLOT_FLOP4-HOLDEM_GAME_CARD_SLOT_FLOP0) - )/2 + t2*(slot-HOLDEM_GAME_CARD_SLOT_FLOP0); + -t2 * ( POKER_CARD_SLOT_FLOP4-POKER_CARD_SLOT_FLOP0) + )/2 + t2*(slot-POKER_CARD_SLOT_FLOP0); break; default: @@ -72,24 +73,27 @@ pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) { return position; } -void holdemRenderCard(card_t card, float x, float y, float z, +void pokerCardRender(poker_t *poker, card_t card, float x, float y, float z, float pitch, float yaw, float roll ) { - tilesetdiv_t *cardFront = GAME_STATE.cardTileset->divisions + card; - quadBuffer(GAME_STATE.cardPrimitive, HOLDEM_GAME_CARD_DEPTH, - -HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT, + tilesetdiv_t *cardFront = poker->cardTileset.divisions + card; + quadBuffer(&poker->cardPrimitive, POKER_CARD_DEPTH, + -POKER_CARD_WIDTH, -POKER_CARD_HEIGHT, cardFront->x0, cardFront->y1, - HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT, + POKER_CARD_WIDTH, POKER_CARD_HEIGHT, cardFront->x1, cardFront->y0, 0, 0 ); - shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.cardTexture); - shaderUsePosition(GAME_STATE.shaderWorld, x,y,z, pitch,yaw,roll); - primitiveDraw(GAME_STATE.cardPrimitive, 0, -1); + shaderUseTexture(&poker->shader, &poker->cardTexture); + shaderUsePosition(&poker->shader, x,y,z, pitch,yaw,roll); + primitiveDraw(&poker->cardPrimitive, 0, -1); } -void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot) { - pokerposition_t position = holdemRenderCardGetPosition(seat, slot); - holdemRenderCard(card, position.x, 0, position.z, mathDeg2Rad(-90), position.yaw, 0); +void pokerCardRenderForSeat(poker_t *poker, uint8_t seat, card_t card, uint8_t slot) { + pokerposition_t position = pokerCardGetPosition(seat, slot); + pokerCardRender(poker, card, + position.x, 0, position.z, + mathDeg2Rad(-90), position.yaw, 0 + ); } \ No newline at end of file diff --git a/src/poker/render/card.h b/src/poker/render/card.h index 02afb525..f6dda963 100644 --- a/src/poker/render/card.h +++ b/src/poker/render/card.h @@ -15,8 +15,9 @@ /** * Initializes the Card Renderer. + * @param poker The poker game context. */ -void holdemRenderCardInit(); +void pokerCardInit(poker_t *poker); /** * Returns the position a card "naturally" sits at for a given seat and slot. @@ -25,12 +26,13 @@ void holdemRenderCardInit(); * @param slot Slot within the player/dealers' hand that the card belongs to. * @return A struct containing X, Z and YAW properties. */ -pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot); +pokerposition_t pokerCardGetPosition(uint8_t seat, uint8_t slot); /** * Render's a given card at the specified coordinates. Card is a reused quad * and is re-buffered to for every draw call. * + * @param poker The poker game context. * @param card Card to render. * @param x X Position (world space). * @param y Y Position (world space). @@ -39,15 +41,15 @@ pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot); * @param yaw Yaw angle. * @param roll Roll angle. */ -void holdemRenderCard(card_t card, float x, float y, float z, +void pokerCardRender(poker_t *poker, card_t card, float x, float y, float z, float pitch, float yaw, float roll ); /** * Render's a card at a given seat and slot. - * + * @param poker The poker game context. * @param seat Seat the card is for. * @param card Card to render. * @param slot Slot the card is for. */ -void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot); \ No newline at end of file +void pokerCardRenderForSeat(poker_t *poker, uint8_t seat, card_t card, uint8_t slot); \ No newline at end of file diff --git a/src/poker/render/look.c b/src/poker/render/look.c index ac261b8a..e973e33c 100644 --- a/src/poker/render/look.c +++ b/src/poker/render/look.c @@ -7,23 +7,23 @@ #include "look.h" -void holdemRenderLookSeat(camera_t *camera, uint8_t seat) { +void pokerLookAtPlayer(camera_t *camera, uint8_t seat) { float x, z, angle; - angle = HOLDEM_GAME_SEAT_ANGLE(seat); + angle = POKER_SEAT_ANGLE(seat); x = sin(angle); z = cos(angle); - cameraLookAt(&GAME_STATE.cameraLeft, + cameraLookAt(camera, x, 0.2, z, -x, 0.2, -z ); } -void holdemRenderLookHand(camera_t *camera, uint8_t seat) { +void pokerLookAtHand(camera_t *camera, uint8_t seat) { float x, z, angle; - angle = HOLDEM_GAME_SEAT_ANGLE(seat); + angle = POKER_SEAT_ANGLE(seat); x = sin(angle); z = cos(angle); - cameraLookAt(&GAME_STATE.cameraLeft, + cameraLookAt(camera, x*0.1, 0.8, z*0.1, -x*0.5, 0.2, -z*0.5 ); diff --git a/src/poker/render/look.h b/src/poker/render/look.h index 6b388a5d..4a318c9b 100644 --- a/src/poker/render/look.h +++ b/src/poker/render/look.h @@ -9,17 +9,17 @@ #include "../../display/camera.h" /** - * Look at a specific seat + * Look at a specific seats' player. * * @param camera Camera to adjust. * @param seat Seat to look at. */ -void holdemRenderLookSeat(camera_t *camera, uint8_t seat); +void pokerLookAtPlayer(camera_t *camera, uint8_t seat); /** - * Look at a specific seats hand. + * Look at a specific seats' hand. * * @param camera Camera to adjust. * @param seat Seats hand to look at. */ -void holdemRenderLookHand(camera_t *camera, uint8_t seat); \ No newline at end of file +void pokerLookAtHand(camera_t *camera, uint8_t seat); \ No newline at end of file diff --git a/src/poker/render/player.c b/src/poker/render/player.c index 4a108f42..01308ac2 100644 --- a/src/poker/render/player.c +++ b/src/poker/render/player.c @@ -7,63 +7,62 @@ #include "player.h" -void holdemRenderPlayerInit() { - GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png"); - GAME_STATE.kagamiTileset = tilesetCreate(3, 2, - GAME_STATE.kagamiTexture->width, - GAME_STATE.kagamiTexture->height, - 0, 0, 0, 0 - ); - GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1); -} +void pokerPlayerInit(poker_t *poker) { + uint8_t i; + pokerplayer_t *player; + float w, h; -uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player) { - switch(player) { - case 0x01: - return HOLDEM_GAME_SEAT_PLAYER1; - case 0x02: - return HOLDEM_GAME_SEAT_PLAYER2; - case 0x03: - return HOLDEM_GAME_SEAT_PLAYER3; - case 0x04: - return HOLDEM_GAME_SEAT_PLAYER4; - default: - return HOLDEM_GAME_SEAT_PLAYER0; + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + player = poker->players + i; + assetTextureLoad(&player->bodyTexture, "characters/penny/body.png"); + assetTextureLoad(&player->faceTexture, "characters/penny/face.png"); + + w = 0.6; + h=((float)player->faceTexture.width)/((float)player->faceTexture.height)*w; + w = w / 2; + h = h / 2; + quadInit(&player->bodyPrimitive, 0, + -w, -h, 0, 1, + w, h, 1, 0 + ); + quadInit(&player->facePrimitive, 0, + -w, -h, 0, 1, + w, h, 1, 0 + ); } } -void holdemRenderPlayer(uint8_t seat) { +uint8_t pokerPlayerGetSeatForPlayer(uint8_t player) { + switch(player) { + case 0x01: + return POKER_SEAT_PLAYER1; + case 0x02: + return POKER_SEAT_PLAYER2; + case 0x03: + return POKER_SEAT_PLAYER3; + case 0x04: + return POKER_SEAT_PLAYER4; + default: + return POKER_SEAT_PLAYER0; + } +} + +void pokerPlayerRender(poker_t* poker, pokerplayer_t *player, uint8_t seat) { float x, z, angle; + float w, h; // Determine position - angle = HOLDEM_GAME_SEAT_ANGLE(seat); + angle = POKER_SEAT_ANGLE(seat); x = sin(angle) * -1; z = cos(angle) * -1; - // Determine size - float w, h; - w = 0.6, h = ( - (float)GAME_STATE.kagamiTileset->divY / - (float)GAME_STATE.kagamiTileset->divX - ) * w; + shaderUsePosition(&poker->shader, x,0.34,z, 0,angle,0); - // Animation - int i = (int32_t)(TIME_STATE.current*10)%GAME_STATE.kagamiTileset->count; - quadBuffer(GAME_STATE.kagamiQuad, 0, - -w/2, -h/2, - GAME_STATE.kagamiTileset->divisions[i].x0, - GAME_STATE.kagamiTileset->divisions[i].y1, - w/2, h/2, - GAME_STATE.kagamiTileset->divisions[i].x1, - GAME_STATE.kagamiTileset->divisions[i].y0, - 0, 0 - ); + // Render Body + shaderUseTexture(&poker->shader, &player->bodyTexture); + primitiveDraw(&player->bodyPrimitive, 0, -1); - // Render - shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.kagamiTexture); - shaderUsePosition(GAME_STATE.shaderWorld, - x, 0.34, z, - 0, angle, 0 - ); - primitiveDraw(GAME_STATE.kagamiQuad, 0, -1); + // Render Face + shaderUseTexture(&poker->shader, &player->faceTexture); + primitiveDraw(&player->facePrimitive, 0, -1); } \ No newline at end of file diff --git a/src/poker/render/player.h b/src/poker/render/player.h index 6cf69592..85c57243 100644 --- a/src/poker/render/player.h +++ b/src/poker/render/player.h @@ -15,20 +15,20 @@ /** * Initializes the player renderer. + * @param poker Poker game context. */ -void holdemRenderPlayerInit(); +void pokerPlayerInit(poker_t *poker); /** * Returns the seat index for a given player. - * * @param player Player to get the seat for. * @return Seat ID for the given player. */ -uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player); +uint8_t pokerPlayerGetSeatForPlayer(uint8_t player); /** * Render's a player at a seat. - * + * @param poker Poker game context. * @param seat Seat to render the player at. */ -void holdemRenderPlayer(uint8_t seat); \ No newline at end of file +void pokerPlayerRender(poker_t *poker, pokerplayer_t *player, uint8_t seat); \ No newline at end of file diff --git a/src/poker/render/world.c b/src/poker/render/world.c index e89072cf..26a8f32a 100644 --- a/src/poker/render/world.c +++ b/src/poker/render/world.c @@ -7,47 +7,24 @@ #include "world.h" -void holdemRenderWorldInit() { - GAME_STATE.tablePrimitive = pokerTableCreate(); - GAME_STATE.tableTexture = assetTextureLoad("pokertable.png"); +void pokerWorldInit(poker_t *poker) { + // Poker Table + pokerTableInit(&poker->tablePrimitive); + assetTextureLoad(&poker->tableTexture, "pokertable.png"); } -void holdemRenderWorld() { - uint8_t i, j; - pokerplayer_t *player; - uint8_t seat; - +void pokerWorldRender(poker_t *poker) { // Poker Table - shaderUsePositionAndScale(GAME_STATE.shaderWorld, + shaderUsePositionAndScale(&poker->shader, 0, -0.01, 0, 0, 0, 0, 3.4, 3.4, 3.4 ); - shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.tableTexture); - primitiveDraw(GAME_STATE.tablePrimitive, 0, -1); + shaderUseTexture(&poker->shader, &poker->tableTexture); + primitiveDraw(&poker->tablePrimitive, 0, -1); +} - // Render the dealer and her hand - holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER); - for(i = 0x00; i < GAME_STATE.cardsFacing; i++) { - holdemRenderCardForSeat( - HOLDEM_GAME_SEAT_DEALER, - GAME_STATE.cards[i], - HOLDEM_GAME_CARD_SLOT_FLOP0 + i - ); - } - - // Test - for(i = 0x00; i < POKER_PLAYER_COUNT; i++) { - player = GAME_STATE.players + i; - seat = holdemRenderPlayerGetSeatForPlayer(i); - holdemRenderPlayer(seat); - - if(player->state & POKER_PLAYER_STATE_SHOWING) continue; - - for(j = 0x00; j < player->cardCount; j++) { - holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j); - } - } - - holdemRenderChip(); +void pokerWorldDispose(poker_t *poker) { + textureDispose(&poker->tableTexture); + primitiveDispose(&poker->tablePrimitive); } \ No newline at end of file diff --git a/src/poker/render/world.h b/src/poker/render/world.h index 3458138c..a5e5e895 100644 --- a/src/poker/render/world.h +++ b/src/poker/render/world.h @@ -7,17 +7,26 @@ #pragma once #include -#include "player.h" -#include "card.h" -#include "chip.h" #include "../../assets/models/pokertable.h" +#include "../../display/shader.h" +#include "../../display/primitive.h" +#include "../../display/texture.h" +#include "../../file/asset.h" /** * Initializes the world renderer. + * @param poker Poker scene to initialize. */ -void holdemRenderWorldInit(); +void pokerWorldInit(poker_t *poker); /** * Renders the world. + * @param poker Poker scene to render. */ -void holdemRenderWorld(); \ No newline at end of file +void pokerWorldRender(poker_t *poker); + +/** + * Disposes a poker world. + * @param poker Poker game to cleanup the world for. + */ +void pokerWorldDispose(poker_t *poker); \ No newline at end of file diff --git a/src/poker/round/deal.c b/src/poker/round/deal.c new file mode 100644 index 00000000..be8e1718 --- /dev/null +++ b/src/poker/round/deal.c @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ +#include "deal.h" + +void pokerDealInit(poker_t *poker) { + uint8_t x, y; + card_t temporary; + + // Prepare the initial game state + poker->round = POKER_ROUND_DEAL; + poker->pot = 0; + poker->roundBet = 0; + poker->graveSize = 0; + poker->cardsFacing = 0; + poker->deckSize = CARD_DECK_SIZE; + for(x = 0; x < CARD_DECK_SIZE; x++) poker->deck[x] = x; + + // Reset the players + for(x = 0; x < POKER_PLAYER_COUNT; x++) { + poker->players[x].cardCount = 0; + poker->players[x].currentBet = 0; + + // Invert then bitwise AND to turn off. + poker->players[x].state &= ~( + POKER_PLAYER_STATE_FOLDED | + POKER_PLAYER_STATE_SHOWING + ); + } + + // Hard look at the dealer + + // Shuffle the deck + for(x = 0; x < CARD_DECK_SIZE - 1; x++) { + // Select random element from remaining elements. + y = u8randRange(x, CARD_DECK_SIZE); + temporary = poker->deck[y];// Take out other card + poker->deck[y] = poker->deck[x];// Move my card there + poker->deck[x] = temporary;// Put other card here. + } +} \ No newline at end of file diff --git a/src/poker/round/deal.h b/src/poker/round/deal.h new file mode 100644 index 00000000..491322ff --- /dev/null +++ b/src/poker/round/deal.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include + +/** + * Resets a poker game for the new round. + * @param poker Poker game to reset to a new round. + */ +void pokerDealInit(poker_t *poker); \ No newline at end of file diff --git a/temp/poker/card.c b/temp/poker/card.c new file mode 100644 index 00000000..6e1b369c --- /dev/null +++ b/temp/poker/card.c @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "card.h" + +void cardDeal(card_t *deck, card_t *hand, uint8_t deckSize, uint8_t handSize) { + card_t card; + card = deck[deckSize-1]; + deck[deckSize-1] = 0x00; + hand[handSize] = card; +} \ No newline at end of file diff --git a/src/poker/card.h b/temp/poker/card.h similarity index 100% rename from src/poker/card.h rename to temp/poker/card.h diff --git a/temp/poker/poker.c b/temp/poker/poker.c new file mode 100644 index 00000000..f7207b27 --- /dev/null +++ b/temp/poker/poker.c @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "poker.h" + +void pokerInit(poker_t *poker) { + uint8_t x; + + // Prepare the initial game state + poker->round = POKER_ROUND_DEAL; + poker->roundPlayer = 0x00; + poker->roundDealer = 0x00; + poker->blindSmall = 0; + poker->blindBig = 0; + + for(x = 0; x < POKER_PLAYER_COUNT; x++) { + poker->players[x].state = 0x00; + poker->players[x].chips = 0; + poker->players[x].cardCount = 0; + poker->players[x].currentBet = 0; + } + + pokerRoundInit(poker); +} + +void pokerRoundInit(poker_t *poker) { + uint8_t x; + + // Refill the deck + cardDeckFill(poker->deck); + poker->deckSize = CARD_DECK_SIZE; + + // Reset the players + for(x = 0; x < POKER_PLAYER_COUNT; x++) { + poker->players[x].cardCount = 0; + poker->players[x].currentBet = 0; + } +} \ No newline at end of file diff --git a/temp/poker/poker.h b/temp/poker/poker.h new file mode 100644 index 00000000..6c5038a9 --- /dev/null +++ b/temp/poker/poker.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "card.h" + +/** + * Initializes the poker match for the first time. + * + * @param poker Poker game to init. + */ +void pokerInit(poker_t *poker); + + +/** + * Initializes the round for a poker game. + * + * @param poker Poker game to init a new round for. + */ +void pokerRoundInit(poker_t *poker); \ No newline at end of file diff --git a/temp/render/card.c b/temp/render/card.c new file mode 100644 index 00000000..961a342d --- /dev/null +++ b/temp/render/card.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "card.h" + +void holdemRenderCardInit() { + tilesetdiv_t *cardBack; + + // Load Cards Texture + GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png"); + GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6, + GAME_STATE.cardTexture->width, GAME_STATE.cardTexture->height, + 0, 0, 0, 0 + ); + + // Cards Primitive + cardBack = GAME_STATE.cardTileset->divisions+( + GAME_STATE.cardTileset->columns * 4 + ); + GAME_STATE.cardPrimitive = primitiveCreate( + QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 + ); + quadBuffer(GAME_STATE.cardPrimitive, -HOLDEM_GAME_CARD_DEPTH, + -HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT, + cardBack->x0, cardBack->y1, + HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT, + cardBack->x1, cardBack->y0, + QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT + ); +} + +pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) { + pokerposition_t position; + float t, t2; + + position.yaw = HOLDEM_GAME_SEAT_ANGLE(seat); + position.x = sin(position.yaw) * -0.75; + position.z = cos(position.yaw) * -0.75; + + t = position.yaw + mathDeg2Rad(90); + + switch (slot) { + case HOLDEM_GAME_CARD_SLOT_HAND0: + case HOLDEM_GAME_CARD_SLOT_HAND1: + t2 = HOLDEM_GAME_CARD_WIDTH+HOLDEM_GAME_CARD_PADDING; + if(slot == HOLDEM_GAME_CARD_SLOT_HAND0) t2 = -t2; + t2 += 0.1; + break; + + case HOLDEM_GAME_CARD_SLOT_FLOP0: + case HOLDEM_GAME_CARD_SLOT_FLOP1: + case HOLDEM_GAME_CARD_SLOT_FLOP2: + case HOLDEM_GAME_CARD_SLOT_FLOP3: + case HOLDEM_GAME_CARD_SLOT_FLOP4: + t2 = HOLDEM_GAME_CARD_WIDTH*2+HOLDEM_GAME_CARD_PADDING; + t2 = ( + -t2 * ( HOLDEM_GAME_CARD_SLOT_FLOP4-HOLDEM_GAME_CARD_SLOT_FLOP0) + )/2 + t2*(slot-HOLDEM_GAME_CARD_SLOT_FLOP0); + break; + + default: + break; + } + + position.x += t2 * sin(t); + position.z += t2 * cos(t); + + return position; +} + +void holdemRenderCard(card_t card, float x, float y, float z, + float pitch, float yaw, float roll +) { + tilesetdiv_t *cardFront = GAME_STATE.cardTileset->divisions + card; + quadBuffer(GAME_STATE.cardPrimitive, HOLDEM_GAME_CARD_DEPTH, + -HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT, + cardFront->x0, cardFront->y1, + HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT, + cardFront->x1, cardFront->y0, + 0, 0 + ); + + shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.cardTexture); + shaderUsePosition(GAME_STATE.shaderWorld, x,y,z, pitch,yaw,roll); + primitiveDraw(GAME_STATE.cardPrimitive, 0, -1); +} + +void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot) { + pokerposition_t position = holdemRenderCardGetPosition(seat, slot); + holdemRenderCard(card, position.x, 0, position.z, mathDeg2Rad(-90), position.yaw, 0); +} \ No newline at end of file diff --git a/temp/render/card.h b/temp/render/card.h new file mode 100644 index 00000000..02afb525 --- /dev/null +++ b/temp/render/card.h @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../file/asset.h" +#include "../../display/shader.h" +#include "../../display/primitive.h" +#include "../../display/primitives/quad.h" +#include "../../display/tileset.h" + +/** + * Initializes the Card Renderer. + */ +void holdemRenderCardInit(); + +/** + * Returns the position a card "naturally" sits at for a given seat and slot. + * + * @param seat Seat that the card belongs to + * @param slot Slot within the player/dealers' hand that the card belongs to. + * @return A struct containing X, Z and YAW properties. + */ +pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot); + +/** + * Render's a given card at the specified coordinates. Card is a reused quad + * and is re-buffered to for every draw call. + * + * @param card Card to render. + * @param x X Position (world space). + * @param y Y Position (world space). + * @param z Z Position (world space). + * @param pitch Pitch angle. + * @param yaw Yaw angle. + * @param roll Roll angle. + */ +void holdemRenderCard(card_t card, float x, float y, float z, + float pitch, float yaw, float roll +); + +/** + * Render's a card at a given seat and slot. + * + * @param seat Seat the card is for. + * @param card Card to render. + * @param slot Slot the card is for. + */ +void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot); \ No newline at end of file diff --git a/src/poker/render/chip.c b/temp/render/chip.c similarity index 100% rename from src/poker/render/chip.c rename to temp/render/chip.c diff --git a/src/poker/render/chip.h b/temp/render/chip.h similarity index 100% rename from src/poker/render/chip.h rename to temp/render/chip.h diff --git a/src/poker/render/frame.c b/temp/render/frame.c similarity index 100% rename from src/poker/render/frame.c rename to temp/render/frame.c diff --git a/src/poker/render/frame.h b/temp/render/frame.h similarity index 100% rename from src/poker/render/frame.h rename to temp/render/frame.h diff --git a/temp/render/look.c b/temp/render/look.c new file mode 100644 index 00000000..ac261b8a --- /dev/null +++ b/temp/render/look.c @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "look.h" + +void holdemRenderLookSeat(camera_t *camera, uint8_t seat) { + float x, z, angle; + angle = HOLDEM_GAME_SEAT_ANGLE(seat); + x = sin(angle); + z = cos(angle); + cameraLookAt(&GAME_STATE.cameraLeft, + x, 0.2, z, + -x, 0.2, -z + ); +} + +void holdemRenderLookHand(camera_t *camera, uint8_t seat) { + float x, z, angle; + angle = HOLDEM_GAME_SEAT_ANGLE(seat); + x = sin(angle); + z = cos(angle); + cameraLookAt(&GAME_STATE.cameraLeft, + x*0.1, 0.8, z*0.1, + -x*0.5, 0.2, -z*0.5 + ); +} diff --git a/temp/render/look.h b/temp/render/look.h new file mode 100644 index 00000000..6b388a5d --- /dev/null +++ b/temp/render/look.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include +#include "../../display/camera.h" + +/** + * Look at a specific seat + * + * @param camera Camera to adjust. + * @param seat Seat to look at. + */ +void holdemRenderLookSeat(camera_t *camera, uint8_t seat); + +/** + * Look at a specific seats hand. + * + * @param camera Camera to adjust. + * @param seat Seats hand to look at. + */ +void holdemRenderLookHand(camera_t *camera, uint8_t seat); \ No newline at end of file diff --git a/temp/render/player.c b/temp/render/player.c new file mode 100644 index 00000000..1d341113 --- /dev/null +++ b/temp/render/player.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "player.h" + +void holdemRenderPlayerInit(poker_t *poker) { + + + GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png"); + GAME_STATE.kagamiTileset = tilesetCreate(3, 2, + GAME_STATE.kagamiTexture->width, + GAME_STATE.kagamiTexture->height, + 0, 0, 0, 0 + ); + GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1); +} + +uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player) { + switch(player) { + case 0x01: + return HOLDEM_GAME_SEAT_PLAYER1; + case 0x02: + return HOLDEM_GAME_SEAT_PLAYER2; + case 0x03: + return HOLDEM_GAME_SEAT_PLAYER3; + case 0x04: + return HOLDEM_GAME_SEAT_PLAYER4; + default: + return HOLDEM_GAME_SEAT_PLAYER0; + } +} + +void holdemRenderPlayer(uint8_t seat) { + float x, z, angle; + + // Determine position + angle = HOLDEM_GAME_SEAT_ANGLE(seat); + x = sin(angle) * -1; + z = cos(angle) * -1; + + // Determine size + float w, h; + w = 0.6, h = ( + (float)GAME_STATE.kagamiTileset->divY / + (float)GAME_STATE.kagamiTileset->divX + ) * w; + + // Animation + int i = (int32_t)(TIME_STATE.current*10)%GAME_STATE.kagamiTileset->count; + quadBuffer(GAME_STATE.kagamiQuad, 0, + -w/2, -h/2, + GAME_STATE.kagamiTileset->divisions[i].x0, + GAME_STATE.kagamiTileset->divisions[i].y1, + w/2, h/2, + GAME_STATE.kagamiTileset->divisions[i].x1, + GAME_STATE.kagamiTileset->divisions[i].y0, + 0, 0 + ); + + // Render + shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.kagamiTexture); + shaderUsePosition(GAME_STATE.shaderWorld, + x, 0.34, z, + 0, angle, 0 + ); + primitiveDraw(GAME_STATE.kagamiQuad, 0, -1); +} \ No newline at end of file diff --git a/temp/render/player.h b/temp/render/player.h new file mode 100644 index 00000000..6cf69592 --- /dev/null +++ b/temp/render/player.h @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../file/asset.h" +#include "../../display/shader.h" +#include "../../display/primitive.h" +#include "../../display/tileset.h" +#include "../../display/primitives/quad.h" + +/** + * Initializes the player renderer. + */ +void holdemRenderPlayerInit(); + +/** + * Returns the seat index for a given player. + * + * @param player Player to get the seat for. + * @return Seat ID for the given player. + */ +uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player); + +/** + * Render's a player at a seat. + * + * @param seat Seat to render the player at. + */ +void holdemRenderPlayer(uint8_t seat); \ No newline at end of file diff --git a/temp/render/world.c b/temp/render/world.c new file mode 100644 index 00000000..e89072cf --- /dev/null +++ b/temp/render/world.c @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "world.h" + +void holdemRenderWorldInit() { + GAME_STATE.tablePrimitive = pokerTableCreate(); + GAME_STATE.tableTexture = assetTextureLoad("pokertable.png"); +} + +void holdemRenderWorld() { + uint8_t i, j; + pokerplayer_t *player; + uint8_t seat; + + // Poker Table + shaderUsePositionAndScale(GAME_STATE.shaderWorld, + 0, -0.01, 0, + 0, 0, 0, + 3.4, 3.4, 3.4 + ); + shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.tableTexture); + primitiveDraw(GAME_STATE.tablePrimitive, 0, -1); + + // Render the dealer and her hand + holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER); + for(i = 0x00; i < GAME_STATE.cardsFacing; i++) { + holdemRenderCardForSeat( + HOLDEM_GAME_SEAT_DEALER, + GAME_STATE.cards[i], + HOLDEM_GAME_CARD_SLOT_FLOP0 + i + ); + } + + // Test + for(i = 0x00; i < POKER_PLAYER_COUNT; i++) { + player = GAME_STATE.players + i; + seat = holdemRenderPlayerGetSeatForPlayer(i); + holdemRenderPlayer(seat); + + if(player->state & POKER_PLAYER_STATE_SHOWING) continue; + + for(j = 0x00; j < player->cardCount; j++) { + holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j); + } + } + + holdemRenderChip(); +} \ No newline at end of file diff --git a/temp/render/world.h b/temp/render/world.h new file mode 100644 index 00000000..3458138c --- /dev/null +++ b/temp/render/world.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "player.h" +#include "card.h" +#include "chip.h" +#include "../../assets/models/pokertable.h" + +/** + * Initializes the world renderer. + */ +void holdemRenderWorldInit(); + +/** + * Renders the world. + */ +void holdemRenderWorld(); \ No newline at end of file