From 9ef90ac44b2032e076deeb90b39c86aa98a0c77f Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 16 May 2021 11:22:45 -0700 Subject: [PATCH] Did a lot of work on the engine --- include/dawn/cards/poker/holdem.h | 35 +++- include/dawn/dawn.h | 2 + {src => include/dawn}/util/math.h | 5 + {src => include/dawn}/util/rand.h | 0 src/card/card.h | 1 - src/card/poker/action/action.c | 38 +++- src/card/poker/action/action.h | 10 +- src/card/poker/action/ai.c | 30 +++ src/card/poker/action/ai.h | 17 ++ src/card/poker/action/deal.c | 30 +++ src/card/poker/action/deal.h | 17 ++ src/card/poker/action/flop.c | 35 ++++ src/card/poker/action/flop.h | 19 ++ src/card/poker/action/round.c | 64 +++++++ src/card/poker/action/round.h | 24 +++ src/card/poker/action/shuffle.c | 30 +++ src/card/poker/action/shuffle.h | 23 +++ src/card/poker/action/start.c | 24 ++- src/card/poker/action/start.h | 3 + src/card/poker/holdem.c | 51 ------ src/card/poker/holdem.h | 16 -- src/card/poker/render/card.c | 94 ++++++++++ src/card/poker/render/card.h | 53 ++++++ src/card/poker/render/frame.c | 93 ++++++++++ src/card/poker/render/frame.h | 41 +++++ src/card/poker/render/holdemrender.c | 265 +++------------------------ src/card/poker/render/holdemrender.h | 36 +--- src/card/poker/render/look.c | 30 +++ src/card/poker/render/look.h | 25 +++ src/card/poker/render/player.c | 69 +++++++ src/card/poker/render/player.h | 32 ++++ src/card/poker/render/scene.c | 24 +++ src/card/poker/render/scene.h | 23 +++ src/debug/log.c | 23 +++ src/debug/log.h | 20 ++ src/display/camera.h | 1 - src/display/debug/position.h | 1 - src/display/gui/font.h | 1 - src/display/spritebatch.h | 1 - src/game/game.c | 5 +- src/game/game.h | 6 +- src/game/gametime.h | 1 - src/world/entity/common.h | 1 - src/world/map/chunk.h | 1 - src/world/map/map.h | 1 - src/world/map/tile.h | 1 - 46 files changed, 960 insertions(+), 362 deletions(-) rename {src => include/dawn}/util/math.h (67%) rename {src => include/dawn}/util/rand.h (100%) create mode 100644 src/card/poker/action/ai.c create mode 100644 src/card/poker/action/ai.h create mode 100644 src/card/poker/action/deal.c create mode 100644 src/card/poker/action/deal.h create mode 100644 src/card/poker/action/flop.c create mode 100644 src/card/poker/action/flop.h create mode 100644 src/card/poker/action/round.c create mode 100644 src/card/poker/action/round.h create mode 100644 src/card/poker/action/shuffle.c create mode 100644 src/card/poker/action/shuffle.h create mode 100644 src/card/poker/render/card.c create mode 100644 src/card/poker/render/card.h create mode 100644 src/card/poker/render/frame.c create mode 100644 src/card/poker/render/frame.h create mode 100644 src/card/poker/render/look.c create mode 100644 src/card/poker/render/look.h create mode 100644 src/card/poker/render/player.c create mode 100644 src/card/poker/render/player.h create mode 100644 src/card/poker/render/scene.c create mode 100644 src/card/poker/render/scene.h create mode 100644 src/debug/log.c create mode 100644 src/debug/log.h diff --git a/include/dawn/cards/poker/holdem.h b/include/dawn/cards/poker/holdem.h index 88be079f..07d87a1d 100644 --- a/include/dawn/cards/poker/holdem.h +++ b/include/dawn/cards/poker/holdem.h @@ -25,14 +25,37 @@ /** State for whether or not a player is showing their hand */ #define HOLDEM_STATE_SHOWING 0x02 +/** 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 HOLDEM_GAME_CARD_WIDTH 0.05 -#define HOLDEM_GAME_CARD_HEIGHT 0.07 + +/** 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 + +/** 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 + +/** Macro for the angle (Yaw) that the seat has */ +#define HOLDEM_GAME_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 /** How many actions the queue can hold */ #define HOLDEM_GAME_ACTION_QUEUE_SIZE 12 @@ -40,6 +63,7 @@ /** How much data (in length of sizeof size_t) each action has available */ #define HOLDEM_GAME_ACTION_DATA_SIZE 256 + /** Texas Hold'em Player State */ typedef struct { /** Cards in the players' hand */ @@ -99,6 +123,7 @@ typedef struct { /** Action and Allocated Data Space */ holdemaction_t actionQueue[HOLDEM_GAME_ACTION_QUEUE_SIZE]; void *actionData[HOLDEM_GAME_ACTION_DATA_SIZE*HOLDEM_GAME_ACTION_QUEUE_SIZE]; + bool actionInitState[HOLDEM_GAME_ACTION_DATA_SIZE]; /** Poker Table */ primitive_t *tablePrimitive; @@ -121,4 +146,10 @@ typedef struct { camera_t cameraRight; } holdemgame_t; + +typedef struct { + float x, z; + float yaw; +} holdemrenderposition_t; + extern holdemgame_t HOLDEM_GAME_STATE; \ No newline at end of file diff --git a/include/dawn/dawn.h b/include/dawn/dawn.h index 9e5e50ab..4e5a5c11 100644 --- a/include/dawn/dawn.h +++ b/include/dawn/dawn.h @@ -37,6 +37,8 @@ // Utility Objects #include "util/list.h" +#include "util/math.h" +#include "util/rand.h" // 3D Tile Game World #include "world/entity/entity.h" diff --git a/src/util/math.h b/include/dawn/util/math.h similarity index 67% rename from src/util/math.h rename to include/dawn/util/math.h index e202a65d..21a575b9 100644 --- a/src/util/math.h +++ b/include/dawn/util/math.h @@ -5,6 +5,11 @@ #pragma once +/** + * Returns the modulous a result for b. Consdiders negative numbers correctly. + * @param a Number to modulo against. (a % b) + * @param b Number to modulo with. (a % b) + */ #define mathMod(a,b) (a%b+b)%b #define mathMax(a,b) (ab?b:a) diff --git a/src/util/rand.h b/include/dawn/util/rand.h similarity index 100% rename from src/util/rand.h rename to include/dawn/util/rand.h diff --git a/src/card/card.h b/src/card/card.h index 8bae312d..ab0f17c2 100644 --- a/src/card/card.h +++ b/src/card/card.h @@ -7,7 +7,6 @@ #pragma once #include -#include "../util/rand.h" /** * Fills a deck with a standard set of cards (unshuffled) diff --git a/src/card/poker/action/action.c b/src/card/poker/action/action.c index 9683bd52..b864c16a 100644 --- a/src/card/poker/action/action.c +++ b/src/card/poker/action/action.c @@ -19,7 +19,7 @@ void holdemActionInit() { ); } -void holdemActionAdd(holdemaction_t action) { +int32_t holdemActionAdd(holdemaction_t action) { int32_t i = -1; int32_t j = -1; @@ -28,16 +28,46 @@ void holdemActionAdd(holdemaction_t action) { j = i; break; } + if(j == -1) return j; HOLDEM_GAME_STATE.actionQueue[j] = action; - action.init(j, HOLDEM_GAME_STATE.actionData + j); + HOLDEM_GAME_STATE.actionInitState[j] = false; + return j; +} + +void holdemActionRemove(int32_t index) { + if(HOLDEM_GAME_STATE.actionQueue[index].dispose != NULL) { + HOLDEM_GAME_STATE.actionQueue[index].dispose( + index, HOLDEM_GAME_STATE.actionData + index + ); + } + + memset(HOLDEM_GAME_STATE.actionQueue+index, (int32_t)NULL, + sizeof(holdemaction_t) + ); + + memset(HOLDEM_GAME_STATE.actionData+index, (int32_t)NULL, + sizeof(void *) * HOLDEM_GAME_ACTION_DATA_SIZE + ); } void holdemActionUpdate() { int32_t i; + void **data; + holdemaction_t *action; + for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) { - if(HOLDEM_GAME_STATE.actionQueue[i].update == NULL) continue; - HOLDEM_GAME_STATE.actionQueue[i].update(i, HOLDEM_GAME_STATE.actionData+i); + action = HOLDEM_GAME_STATE.actionQueue + i; + data = HOLDEM_GAME_STATE.actionData + i; + + if(action->init != NULL && !HOLDEM_GAME_STATE.actionInitState[i]) { + HOLDEM_GAME_STATE.actionInitState[i] = true; + action->init(i, data); + } + + if(action->update != NULL) { + action->update(i, data); + } } } diff --git a/src/card/poker/action/action.h b/src/card/poker/action/action.h index 353df42e..b6023d23 100644 --- a/src/card/poker/action/action.h +++ b/src/card/poker/action/action.h @@ -17,8 +17,16 @@ void holdemActionInit(); * Adds an action to the action queue. * * @param action Action to add to the queue. + * @returns The index of the action within the queue, or -1 if failure occured. */ -void holdemActionAdd(holdemaction_t action); +int32_t holdemActionAdd(holdemaction_t action); + +/** + * Removes an action from the action queue. + * + * @param index Action to remove (by index in the queue). + */ +void holdemActionRemove(int32_t index); /** * Updates the action manager, which (in turn) updates all actions that are diff --git a/src/card/poker/action/ai.c b/src/card/poker/action/ai.c new file mode 100644 index 00000000..ae80f889 --- /dev/null +++ b/src/card/poker/action/ai.c @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "ai.h" + +holdemaction_t actionAi() { + return (holdemaction_t){ + .init = &actionAiInit, + .update = &actionAiUpdate, + .dispose = &actionAiDispose + }; +} + +void actionAiInit(int32_t index, void *data) { + holdemActionRemove(index); +} + +void actionAiUpdate(int32_t index, void *data) { +} + +void actionAiDispose(int32_t index, void *data) { + // Do we need to do a flop? + if(HOLDEM_GAME_STATE.match.cardsFacing < HOLDEM_DEALER_HAND) { + holdemActionAdd(actionFlop()); + } +} \ No newline at end of file diff --git a/src/card/poker/action/ai.h b/src/card/poker/action/ai.h new file mode 100644 index 00000000..cfe9bd9f --- /dev/null +++ b/src/card/poker/action/ai.h @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "action.h" +#include "flop.h" + +holdemaction_t actionAi(); + +void actionAiInit(int32_t index, void *data); +void actionAiUpdate(int32_t index, void *data); +void actionAiDispose(int32_t index, void *data); \ No newline at end of file diff --git a/src/card/poker/action/deal.c b/src/card/poker/action/deal.c new file mode 100644 index 00000000..e2502233 --- /dev/null +++ b/src/card/poker/action/deal.c @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "deal.h" + +holdemaction_t actionDeal() { + return (holdemaction_t){ + .init = &actionDealInit, + .update = &actionDealUpdate, + .dispose = &actionDealDispose + }; +} + +void actionDealInit(int32_t i, void *data) { + logText("Dealing Cards"); + holdemDealAll(&HOLDEM_GAME_STATE.match, HOLDEM_PLAYER_HAND); + holdemActionRemove(i); +} + +void actionDealUpdate(int32_t i, void *data) { + +} + +void actionDealDispose(int32_t i, void *data) { + holdemActionAdd() +} \ No newline at end of file diff --git a/src/card/poker/action/deal.h b/src/card/poker/action/deal.h new file mode 100644 index 00000000..3665a83f --- /dev/null +++ b/src/card/poker/action/deal.h @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../../debug/log.h" +#include "action.h" + +holdemaction_t actionDeal(); + +void actionDealInit(int32_t i, void *data); +void actionDealUpdate(int32_t i, void *data); +void actionDealDispose(int32_t i, void *data); \ No newline at end of file diff --git a/src/card/poker/action/flop.c b/src/card/poker/action/flop.c new file mode 100644 index 00000000..2d50c677 --- /dev/null +++ b/src/card/poker/action/flop.c @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "flop.h" + +holdemaction_t actionFlop() { + return (holdemaction_t){ + .init = &actionFlopInit, + .update = &actionFlopUpdate, + .dispose = &actionFlopDispose + }; +} + +void actionFlopInit(int32_t index, void *data) { + // Look at the dealer + holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_DEALER); + + // Do the flop + holdemFlop(&HOLDEM_GAME_STATE.match); + + // Next action + holdemActionRemove(index); +} + +void actionFlopUpdate(int32_t index, void *data) { + +} + +void actionFlopDispose(int32_t index, void *data) { + holdemActionAdd(actionAi()); +} \ No newline at end of file diff --git a/src/card/poker/action/flop.h b/src/card/poker/action/flop.h new file mode 100644 index 00000000..bf961fcd --- /dev/null +++ b/src/card/poker/action/flop.h @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "action.h" +#include "../holdem.h" +#include "../render/look.h" +#include "ai.h" + +holdemaction_t actionFlop(); + +void actionFlopInit(int32_t index, void *data); +void actionFlopUpdate(int32_t index, void *data); +void actionFlopDispose(int32_t index, void *data); \ No newline at end of file diff --git a/src/card/poker/action/round.c b/src/card/poker/action/round.c new file mode 100644 index 00000000..995c25ad --- /dev/null +++ b/src/card/poker/action/round.c @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "round.h" + +holdemaction_t actionRound() { + return (holdemaction_t){ + .init = &actionRoundInit, + .update = &actionRoundUpdate, + .dispose = &actionRoundDispose + }; +} + +void actionRoundInit(int32_t index, void *data) { + uint8_t i; + holdemplayer_t *player; + holdemmatch_t *match = &HOLDEM_GAME_STATE.match; + + logText("Round Start"); + + // Look at the dealer. + holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_DEALER); + + // Init the round and shuffle the deck + cardDeckFill(match->deck); + match->deckSize = CARD_DECK_SIZE; + match->pot = 0; + match->cardsFacing = 0; + + // Reset the players + for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) { + player = match->players + i; + + // Clear Round State(s) + player->state &= ~( + HOLDEM_STATE_FOLDED | + HOLDEM_STATE_SHOWING + ); + + player->cardCount = 0; + player->currentBet = 0; + } + + // Next action + holdemActionRemove(index); +} + +void actionRoundUpdate(int32_t index, void *data) { +} + +void actionRoundAfterShuffle() { + logText("Shuffle Done"); + int32_t i = holdemActionAdd(actionDeal()); +} + +void actionRoundDispose(int32_t index, void *data) { + int32_t newI = holdemActionAdd(actionShuffle()); + shuffledata_t *newData=(shuffledata_t *)(HOLDEM_GAME_STATE.actionData + newI); + newData->done = &actionRoundAfterShuffle; +} \ No newline at end of file diff --git a/src/card/poker/action/round.h b/src/card/poker/action/round.h new file mode 100644 index 00000000..48abcade --- /dev/null +++ b/src/card/poker/action/round.h @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../render/holdemrender.h" +#include "../../../debug/log.h" +#include "../holdem.h" +#include "action.h" +#include "ai.h" +#include "shuffle.h" +#include "deal.h" + +holdemaction_t actionRound(); + +void actionRoundInit(int32_t index, void *data); +void actionRoundUpdate(int32_t index, void *data); +void actionRoundDispose(int32_t index, void *data); + +void actionRoundAfterShuffle(); \ No newline at end of file diff --git a/src/card/poker/action/shuffle.c b/src/card/poker/action/shuffle.c new file mode 100644 index 00000000..b3e8556c --- /dev/null +++ b/src/card/poker/action/shuffle.c @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "shuffle.h" + +holdemaction_t actionShuffle() { + return (holdemaction_t){ + .init = &actionShuffleInit, + .update = &actionShuffleUpdate, + .dispose = &actionShuffleDispose + }; +} + +void actionShuffleInit(int32_t index, void *data) { + logText("Shuffle Deck"); + cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize); + holdemActionRemove(index); +} + +void actionShuffleUpdate(int32_t index, void *data) { + +} + +void actionShuffleDispose(int32_t index, void *data) { + if(((shuffledata_t *)data) != NULL) ((shuffledata_t *)data)->done(); +} \ No newline at end of file diff --git a/src/card/poker/action/shuffle.h b/src/card/poker/action/shuffle.h new file mode 100644 index 00000000..7db8e888 --- /dev/null +++ b/src/card/poker/action/shuffle.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 "action.h" +#include "../../../debug/log.h" + +typedef struct { + void (*done)(); +} shuffledata_t; + +holdemaction_t actionShuffle(); + +void actionShuffleInit(int32_t index, void *data); + +void actionShuffleUpdate(int32_t index, void *data); + +void actionShuffleDispose(int32_t index, void *data); \ No newline at end of file diff --git a/src/card/poker/action/start.c b/src/card/poker/action/start.c index 76aa27c4..fc1de337 100644 --- a/src/card/poker/action/start.c +++ b/src/card/poker/action/start.c @@ -18,18 +18,30 @@ holdemaction_t actionStart() { } void actionStartInit(int32_t index, void *data) { - // holdemactionstart_t *convData = data; + uint8_t i; + holdemplayer_t *player; + holdemmatch_t *match; + logText("Holdem Starting"); // Prepare the match - holdemMatchInit(&HOLDEM_GAME_STATE.match); - holdemRoundInit(&HOLDEM_GAME_STATE.match); - cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize); - holdemFlop(&HOLDEM_GAME_STATE.match); + match = &HOLDEM_GAME_STATE.match; + match->blindBig = 0; + match->blindSmall = 0; + + // Reset the players + for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) { + player = match->players + i; + player->state = 0x00; + player->chips = 0; + } + + holdemActionRemove(index); } void actionStartUpdate(int32_t index, void *data) { } void actionStartDispose(int32_t index, void *data) { - + // Begin the first round + holdemActionAdd(actionRound()); } \ No newline at end of file diff --git a/src/card/poker/action/start.h b/src/card/poker/action/start.h index 15107b8a..330d12d6 100644 --- a/src/card/poker/action/start.h +++ b/src/card/poker/action/start.h @@ -7,6 +7,9 @@ #pragma once #include +#include "action.h" +#include "round.h" +#include "../../../debug/log.h" holdemaction_t actionStart(); diff --git a/src/card/poker/holdem.c b/src/card/poker/holdem.c index 7f3e91fc..fc3b7070 100644 --- a/src/card/poker/holdem.c +++ b/src/card/poker/holdem.c @@ -7,57 +7,6 @@ #include "holdem.h" -void holdemMatchInit(holdemmatch_t *match) { - uint8_t i; - holdemplayer_t *player; - - // Set Blinds to nil. - match->blindBig = 0; - match->blindSmall = 0; - - // Reset the players - for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) { - player = match->players + i; - - // Set their state to 0 - player->state = 0x00; - - // Set their chips to zero - player->chips = 0; - } -} - -void holdemRoundInit(holdemmatch_t *match) { - uint8_t i; - holdemplayer_t *player; - - // Refill the deck - cardDeckFill(match->deck); - match->deckSize = CARD_DECK_SIZE; - - // Reset the pot - match->pot = 0; - - // Reset the cards - match->cardsFacing = 0; - - // Reset the players - for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) { - player = match->players + i; - - // Clear Round State(s) - player->state &= ~( - HOLDEM_STATE_FOLDED | - HOLDEM_STATE_SHOWING - ); - - player->cardCount = 0; - - // Set the players' current bet to zero. - player->currentBet = 0; - } -} - void holdemDeal(holdemmatch_t *match, holdemplayer_t *player) { cardDeal(match->deck, player->cards, match->deckSize, player->cardCount); match->deckSize--; diff --git a/src/card/poker/holdem.h b/src/card/poker/holdem.h index f91f4eb5..42d6f1bb 100644 --- a/src/card/poker/holdem.h +++ b/src/card/poker/holdem.h @@ -8,28 +8,12 @@ #pragma once #include #include "../card.h" -#include "../../util/rand.h" #include "../../display/spritebatch.h" #include "../../display/texture.h" #include "../../display/tileset.h" #include "../../display/shader.h" #include "../../file/asset.h" -/** - * Initializes a Teax Hold'em Game for the first time. - * - * @param game Game to initialize. - */ -void holdemMatchInit(holdemmatch_t *match); - -/** - * Initializes a Texas Hold'em Round for the first time. Does not affect the - * global game state. - * - * @param game Game's round you want to initialize. - */ -void holdemRoundInit(holdemmatch_t *match); - /** * Deals a card to the given player, does all the follow up. * diff --git a/src/card/poker/render/card.c b/src/card/poker/render/card.c new file mode 100644 index 00000000..8fad28ac --- /dev/null +++ b/src/card/poker/render/card.c @@ -0,0 +1,94 @@ +/** + * 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 + HOLDEM_GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png"); + HOLDEM_GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6, + HOLDEM_GAME_STATE.cardTexture->width, HOLDEM_GAME_STATE.cardTexture->height, + 0, 0, 0, 0 + ); + + // Cards Primitive + cardBack = HOLDEM_GAME_STATE.cardTileset->divisions+( + HOLDEM_GAME_STATE.cardTileset->columns * 4 + ); + HOLDEM_GAME_STATE.cardPrimitive = primitiveCreate( + QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 + ); + quadBuffer(HOLDEM_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 + ); +} + +holdemrenderposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) { + holdemrenderposition_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; + 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 = HOLDEM_GAME_STATE.cardTileset->divisions + card; + quadBuffer(HOLDEM_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, HOLDEM_GAME_STATE.cardTexture); + shaderUsePosition(GAME_STATE.shaderWorld, x,y,z, pitch,yaw,roll); + primitiveDraw(HOLDEM_GAME_STATE.cardPrimitive, 0, -1); +} + +void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot) { + holdemrenderposition_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/src/card/poker/render/card.h b/src/card/poker/render/card.h new file mode 100644 index 00000000..075f39c1 --- /dev/null +++ b/src/card/poker/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. + */ +holdemrenderposition_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/card/poker/render/frame.c b/src/card/poker/render/frame.c new file mode 100644 index 00000000..2042a810 --- /dev/null +++ b/src/card/poker/render/frame.c @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "frame.h" + +void holdemRenderFrameInit() { + int32_t lWidth, rWidth, height; + + // Prepare the two frame buffers. + lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; + height = HOLDEM_GAME_FRAME_HEIGHT; + HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); + HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); + HOLDEM_GAME_STATE.quadLeft = quadCreate(0, 0, 0, 0, 0, lWidth, height, 1, 1); + HOLDEM_GAME_STATE.quadRight = quadCreate(0, 0, 0, 0, 0, rWidth, height, 1, 1); +} + +void holdemRenderFrameUpdate() { + int32_t lWidth, rWidth, height; + + lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; + height = HOLDEM_GAME_FRAME_HEIGHT; + if(( + HOLDEM_GAME_STATE.frameLeft->texture->width == lWidth && + HOLDEM_GAME_STATE.frameLeft->texture->height == height + )) return; + + // Recreate frame buffers. + frameBufferDispose(HOLDEM_GAME_STATE.frameLeft); + frameBufferDispose(HOLDEM_GAME_STATE.frameRight); + HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); + HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); + quadBuffer(HOLDEM_GAME_STATE.quadLeft, 0, + 0, 0, 0, 1, + lWidth, height, 1, 0, + 0, 0 + ); + quadBuffer(HOLDEM_GAME_STATE.quadRight, 0, + 0, 0, 0, 1, + rWidth, height, 1, 0, + 0, 0 + ); +} + +void holdemRenderFrameUseLeft() { + glClearColor(0.3, 0, 0, 1); + frameBufferUse(HOLDEM_GAME_STATE.frameLeft, true); + cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 35, + ( + (float)HOLDEM_GAME_STATE.frameLeft->texture->width / + (float)HOLDEM_GAME_STATE.frameLeft->texture->height + ), 0.2f, 1000.0f + ); + shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft); +} + +void holdemRenderFrameUseRight() { + glClearColor(0.3, 0.3, 0, 1); + frameBufferUse(HOLDEM_GAME_STATE.frameRight, true); + cameraPerspective(&HOLDEM_GAME_STATE.cameraRight, 45, + ( + (float)HOLDEM_GAME_STATE.frameRight->texture->width / + (float)HOLDEM_GAME_STATE.frameRight->texture->height + ), 0.2f, 1000.0f + ); + cameraLookAt(&HOLDEM_GAME_STATE.cameraRight, 0, 3, 3, 0, 0, 0); + shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraRight); +} + +void holdemRenderFrameBack() { + glClearColor(0, 0, 0, 1); + frameBufferUse(NULL, true); + cameraOrtho(&GAME_STATE.cameraWorld, 0, + RENDER_STATE.width, RENDER_STATE.height, 1, 0, 1 + ); + cameraLookAt(&GAME_STATE.cameraWorld, 0, 0, 0.5f, 0, 0, 0); + shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld); + shaderUsePosition(GAME_STATE.shaderWorld, + 0, 0, 0, 0, 0, 0 + ); + shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameLeft->texture); + primitiveDraw(HOLDEM_GAME_STATE.quadLeft, 0, -1); + shaderUsePosition(GAME_STATE.shaderWorld, + RENDER_STATE.width - HOLDEM_GAME_STATE.frameRight->texture->width, + 0, 0, 0, 0, 0 + ); + shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameRight->texture); + primitiveDraw(HOLDEM_GAME_STATE.quadRight, 0, -1); +} \ No newline at end of file diff --git a/src/card/poker/render/frame.h b/src/card/poker/render/frame.h new file mode 100644 index 00000000..51dff444 --- /dev/null +++ b/src/card/poker/render/frame.h @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../../display/shader.h" +#include "../../../display/primitive.h" +#include "../../../display/primitives/quad.h" +#include "../../../display/framebuffer.h" +#include "../../../display/camera.h" + +/** + * Initializes the frame buffers to be rendered to later. + */ +void holdemRenderFrameInit(); + +/** + * Update the frame buffers at the start of a rendering cycle. + */ +void holdemRenderFrameUpdate(); + +/** + * Binds the left frame buffer, clears it, and corrects its camera's + * perspective. + */ +void holdemRenderFrameUseLeft(); + +/** + * Binds the right frame buffer, clears it, and corrects its camera's + * perspective. + */ +void holdemRenderFrameUseRight(); + +/** + * Renders both the left and right frames to the backbuffer. + */ +void holdemRenderFrameBack(); \ No newline at end of file diff --git a/src/card/poker/render/holdemrender.c b/src/card/poker/render/holdemrender.c index 1485a40e..122e97f2 100644 --- a/src/card/poker/render/holdemrender.c +++ b/src/card/poker/render/holdemrender.c @@ -8,18 +8,6 @@ #include "holdemrender.h" void holdemRenderInit() { - int32_t lWidth, rWidth, height; - card_t card; - tilesetdiv_t *cardBack; - - // Prepare the two frame buffers. - lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; - height = HOLDEM_GAME_FRAME_HEIGHT; - HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); - HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); - HOLDEM_GAME_STATE.quadLeft = quadCreate(0, 0, 0, 0, 0, lWidth, height, 1, 1); - HOLDEM_GAME_STATE.quadRight = quadCreate(0, 0, 0, 0, 0, rWidth, height, 1, 1); - // Font HOLDEM_GAME_STATE.fontTexture = assetTextureLoad("font.png"); HOLDEM_GAME_STATE.fontTileset = tilesetCreate(20, 20, @@ -29,249 +17,54 @@ void holdemRenderInit() { ); HOLDEM_GAME_STATE.fontBatch = spriteBatchCreate(1024); - // Poker Table - HOLDEM_GAME_STATE.tablePrimitive = pokerTableCreate(); - HOLDEM_GAME_STATE.tableTexture = assetTextureLoad("pokertable.png"); - - // Kagami - HOLDEM_GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png"); - HOLDEM_GAME_STATE.kagamiTileset = tilesetCreate(3, 2, - HOLDEM_GAME_STATE.kagamiTexture->width, - HOLDEM_GAME_STATE.kagamiTexture->height, - 0, 0, 0, 0 - ); - HOLDEM_GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1); - - // Load Cards Texture - HOLDEM_GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png"); - HOLDEM_GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6, - HOLDEM_GAME_STATE.cardTexture->width, HOLDEM_GAME_STATE.cardTexture->height, - 0, 0, 0, 0 - ); - - // Cards Primitive - cardBack = HOLDEM_GAME_STATE.cardTileset->divisions+( - HOLDEM_GAME_STATE.cardTileset->columns * 4 - ); - HOLDEM_GAME_STATE.cardPrimitive = primitiveCreate( - QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 - ); - quadBuffer(HOLDEM_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 - ); + holdemRenderFrameInit(); + holdemRenderSceneInit(); + holdemRenderPlayerInit(); + holdemRenderCardInit(); } void holdemRender() { - int32_t lWidth, rWidth, height; - - // Resize Frame buffers. - lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH; - height = HOLDEM_GAME_FRAME_HEIGHT; - if( - HOLDEM_GAME_STATE.frameLeft->texture->width != lWidth || - HOLDEM_GAME_STATE.frameLeft->texture->height != height - ) { - frameBufferDispose(HOLDEM_GAME_STATE.frameLeft); - frameBufferDispose(HOLDEM_GAME_STATE.frameRight); - HOLDEM_GAME_STATE.frameLeft = frameBufferCreate(lWidth, height); - HOLDEM_GAME_STATE.frameRight = frameBufferCreate(rWidth, height); - quadBuffer(HOLDEM_GAME_STATE.quadLeft, 0, - 0, 0, 0, 1, - lWidth, height, 1, 0, - 0, 0 - ); - quadBuffer(HOLDEM_GAME_STATE.quadRight, 0, - 0, 0, 0, 1, - rWidth, height, 1, 0, - 0, 0 - ); - } + holdemRenderFrameUpdate(); // Render things on the left frame buffer - glClearColor(0.3, 0, 0, 1); - frameBufferUse(HOLDEM_GAME_STATE.frameLeft, true); - cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 25, - ((float)lWidth/height), 0.2f, 1000.0f - ); - // cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 2, 2, 2, 0, 0, 0); - holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, 0x00); - shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft); + holdemRenderFrameUseLeft(); holdemRenderWorld(); // Render things on the right frame buffer - glClearColor(0.3, 0.3, 0, 1); - frameBufferUse(HOLDEM_GAME_STATE.frameRight, true); - cameraPerspective(&HOLDEM_GAME_STATE.cameraRight, 45, - ((float)rWidth/height), 0.25f, 100.0f - ); - cameraLookAt(&HOLDEM_GAME_STATE.cameraRight, 0, 3, 3, 0, 0, 0); - shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraRight); + holdemRenderFrameUseRight(); holdemRenderWorld(); // Finally, render the frame buffers to the back buffer. - glClearColor(0, 0, 0, 1); - frameBufferUse(NULL, true); - cameraOrtho(&GAME_STATE.cameraWorld, 0, - RENDER_STATE.width, RENDER_STATE.height, 1, 0, 1 - ); - cameraLookAt(&GAME_STATE.cameraWorld, 0, 0, 0.5f, 0, 0, 0); - shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld); - shaderUsePosition(GAME_STATE.shaderWorld, - 0, 0, 0, 0, 0, 0 - ); - shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameLeft->texture); - primitiveDraw(HOLDEM_GAME_STATE.quadLeft, 0, -1); - shaderUsePosition(GAME_STATE.shaderWorld, - RENDER_STATE.width-rWidth, 0, 0, 0, 0, 0 - ); - shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameRight->texture); - primitiveDraw(HOLDEM_GAME_STATE.quadRight, 0, -1); -} - -void holdemRenderLookSeat(camera_t *camera, uint8_t seat) { - float x, z, angle; - angle = mathDeg2Rad(-45*seat); - x = sin(angle); - z = cos(angle); - cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, - x, 0.2, z, - -x, 0.2, -z - ); -} - -void holdemRenderLookHand(camera_t *camera, uint8_t seat) { - float x, z, angle; - angle = mathDeg2Rad(-45*seat); - x = sin(angle); - z = cos(angle); - cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, - x*0.1, 0.8, z*0.1, - -x*0.5, 0.2, -z*0.5 - ); -} - -void holdemRenderPlayer(uint8_t seat) { - float x, z, angle; - angle = mathDeg2Rad(-45*seat); - x = sin(angle) * -1; - z = cos(angle) * -1; - - float w, h; - w = 0.6, h = ( - (float)HOLDEM_GAME_STATE.kagamiTileset->divY / - (float)HOLDEM_GAME_STATE.kagamiTileset->divX - ) * w; - - int i = (int32_t)(TIME_STATE.current*10)%HOLDEM_GAME_STATE.kagamiTileset->count; - quadBuffer(HOLDEM_GAME_STATE.kagamiQuad, 0, - -w/2, -h/2, - HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x0, - HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y1, - w/2, h/2, - HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x1, - HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y0, - 0, 0 - ); - - shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.kagamiTexture); - shaderUsePosition(GAME_STATE.shaderWorld, - x, 0.34, z, - 0, mathDeg2Rad(-45*seat), 0 - ); - primitiveDraw(HOLDEM_GAME_STATE.kagamiQuad, 0, -1); -} - -void holdemRenderCard(uint8_t seat, card_t card) { - float x, z, angle; - angle = mathDeg2Rad(-45*seat); - x = sin(angle) * -0.75; - z = cos(angle) * -0.75; - - tilesetdiv_t *cardFront = HOLDEM_GAME_STATE.cardTileset->divisions + card; - quadBuffer(HOLDEM_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, HOLDEM_GAME_STATE.cardTexture); - shaderUsePosition(GAME_STATE.shaderWorld, x,0,z, mathDeg2Rad(90),angle,0); - primitiveDraw(HOLDEM_GAME_STATE.cardPrimitive, 0, -1); + holdemRenderFrameBack(); } void holdemRenderWorld() { uint8_t i, j; - float pitch; holdemplayer_t *player; - char name[16]; + 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, HOLDEM_GAME_STATE.tableTexture); - primitiveDraw(HOLDEM_GAME_STATE.tablePrimitive, 0, -1); + holdemRenderScene(); - holdemRenderCard(0x00, CARD_HEARTS_QUEEN); - holdemRenderCard(0x01, CARD_HEARTS_QUEEN); - holdemRenderCard(0x02, CARD_HEARTS_QUEEN); - holdemRenderCard(0x03, CARD_HEARTS_QUEEN); - holdemRenderCard(0x04, CARD_HEARTS_QUEEN); - holdemRenderCard(0x05, CARD_HEARTS_QUEEN); - holdemRenderCard(0x06, CARD_HEARTS_QUEEN); - holdemRenderCard(0x07, CARD_HEARTS_QUEEN); + // Render the dealer and her hand + holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER); + for(i = 0x00; i < HOLDEM_GAME_STATE.match.cardsFacing; i++) { + holdemRenderCardForSeat( + HOLDEM_GAME_SEAT_DEALER, + HOLDEM_GAME_STATE.match.cards[i], + HOLDEM_GAME_CARD_SLOT_FLOP0 + i + ); + } - // Players - holdemRenderPlayer(0x00); - holdemRenderPlayer(0x01); - holdemRenderPlayer(0x02); - holdemRenderPlayer(0x03); - holdemRenderPlayer(0x04); - holdemRenderPlayer(0x05); - holdemRenderPlayer(0x06); - holdemRenderPlayer(0x07); - - // pitch = mathDeg2Rad(-90); - // for(j = 0; j < HOLDEM_GAME_STATE.match.cardsFacing; j++) { - // holdemRenderCard(HOLDEM_GAME_STATE.match.cards[j], j*0.2, 0, -0.2, pitch, 0, 0); - // } - // for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) { - // player = HOLDEM_GAME_STATE.match.players + i; - // if(player->state & HOLDEM_STATE_FOLDED) continue; - // sprintf(name, "Player %i", i); + // Test + for(i = 0x00; i < HOLDEM_PLAYER_COUNT; i++) { + player = HOLDEM_GAME_STATE.match.players + i; + seat = holdemRenderPlayerGetSeatForPlayer(i); + holdemRenderPlayer(seat); - // shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture); - // spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch); - // shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,i*0.2, mathDeg2Rad(-90),0,0); - // fontSpriteBatchBuffer( - // HOLDEM_GAME_STATE.fontBatch, - // HOLDEM_GAME_STATE.fontTileset, - // name, FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1 - // ); - // spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1); - - // for(j = 0; j < HOLDEM_PLAYER_HAND; j++) { - // // pitch = mathDeg2Rad(player->state & HOLDEM_STATE_SHOWING ? -90 : 90); - // holdemRenderCard(player->cards[j], j*0.2, 0, i*0.2, pitch, 0, 0); - // } - // } - - // shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture); - // spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch); - // shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,-0.2, mathDeg2Rad(-90),0,0); - // fontSpriteBatchBuffer( - // HOLDEM_GAME_STATE.fontBatch, - // HOLDEM_GAME_STATE.fontTileset, - // "Dealer", FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1 - // ); - // spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1); + if(player->state & HOLDEM_STATE_FOLDED) continue; + for(j = 0x00; j < player->cardCount; j++) { + holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j); + } + } } diff --git a/src/card/poker/render/holdemrender.h b/src/card/poker/render/holdemrender.h index 19b7b486..d5711608 100644 --- a/src/card/poker/render/holdemrender.h +++ b/src/card/poker/render/holdemrender.h @@ -16,9 +16,14 @@ #include "../../../display/camera.h" #include "../../../display/primitives/cube.h" #include "../../../display/tileset.h" -#include "../../../util/math.h" #include "../model/pokertable.h" +#include "player.h" +#include "card.h" +#include "frame.h" +#include "look.h" +#include "scene.h" + /** * Prepare the Hold'em Game Renderer. */ @@ -29,33 +34,4 @@ void holdemRenderInit(); */ void holdemRender(); -/** - * 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); - -/** - * Renders a Teax Hold'em player - * - * @param seat Seat that the player sits at. - */ -void holdemRenderPlayer(uint8_t seat); - -// void holdemRenderCard(card_t card, -// float x, float y, float z, float pitch, float yaw, float roll -// ); - -void holdemRenderCard(uint8_t seat, card_t card); - void holdemRenderWorld(); \ No newline at end of file diff --git a/src/card/poker/render/look.c b/src/card/poker/render/look.c new file mode 100644 index 00000000..3a2b61df --- /dev/null +++ b/src/card/poker/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(&HOLDEM_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(&HOLDEM_GAME_STATE.cameraLeft, + x*0.1, 0.8, z*0.1, + -x*0.5, 0.2, -z*0.5 + ); +} diff --git a/src/card/poker/render/look.h b/src/card/poker/render/look.h new file mode 100644 index 00000000..7ed4dee4 --- /dev/null +++ b/src/card/poker/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/src/card/poker/render/player.c b/src/card/poker/render/player.c new file mode 100644 index 00000000..b1369c22 --- /dev/null +++ b/src/card/poker/render/player.c @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "player.h" + +void holdemRenderPlayerInit() { + HOLDEM_GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png"); + HOLDEM_GAME_STATE.kagamiTileset = tilesetCreate(3, 2, + HOLDEM_GAME_STATE.kagamiTexture->width, + HOLDEM_GAME_STATE.kagamiTexture->height, + 0, 0, 0, 0 + ); + HOLDEM_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)HOLDEM_GAME_STATE.kagamiTileset->divY / + (float)HOLDEM_GAME_STATE.kagamiTileset->divX + ) * w; + + // Animation + int i = (int32_t)(TIME_STATE.current*10)%HOLDEM_GAME_STATE.kagamiTileset->count; + quadBuffer(HOLDEM_GAME_STATE.kagamiQuad, 0, + -w/2, -h/2, + HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x0, + HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y1, + w/2, h/2, + HOLDEM_GAME_STATE.kagamiTileset->divisions[i].x1, + HOLDEM_GAME_STATE.kagamiTileset->divisions[i].y0, + 0, 0 + ); + + // Render + shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.kagamiTexture); + shaderUsePosition(GAME_STATE.shaderWorld, + x, 0.34, z, + 0, angle, 0 + ); + primitiveDraw(HOLDEM_GAME_STATE.kagamiQuad, 0, -1); +} \ No newline at end of file diff --git a/src/card/poker/render/player.h b/src/card/poker/render/player.h new file mode 100644 index 00000000..89944101 --- /dev/null +++ b/src/card/poker/render/player.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../../display/shader.h" +#include "../../../display/primitive.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/src/card/poker/render/scene.c b/src/card/poker/render/scene.c new file mode 100644 index 00000000..08ac52e0 --- /dev/null +++ b/src/card/poker/render/scene.c @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "scene.h" + +void holdemRenderSceneInit() { + HOLDEM_GAME_STATE.tablePrimitive = pokerTableCreate(); + HOLDEM_GAME_STATE.tableTexture = assetTextureLoad("pokertable.png"); +} + +void holdemRenderScene() { + // Poker Table + shaderUsePositionAndScale(GAME_STATE.shaderWorld, + 0, -0.01, 0, + 0, 0, 0, + 3.4, 3.4, 3.4 + ); + shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.tableTexture); + primitiveDraw(HOLDEM_GAME_STATE.tablePrimitive, 0, -1); +} \ No newline at end of file diff --git a/src/card/poker/render/scene.h b/src/card/poker/render/scene.h new file mode 100644 index 00000000..149c91ad --- /dev/null +++ b/src/card/poker/render/scene.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 "../../../display/shader.h" +#include "../../../display/primitive.h" +#include "../../../file/asset.h" +#include "../model/pokertable.h" + +/** + * Initializes the scene renderer. + */ +void holdemRenderSceneInit(); + +/** + * Renders the scene for the holdem game (including table, chairs, etc.) + */ +void holdemRenderScene(); \ No newline at end of file diff --git a/src/debug/log.c b/src/debug/log.c new file mode 100644 index 00000000..cefc3360 --- /dev/null +++ b/src/debug/log.c @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "log.h" + +list_t *logBuffer; + +void logInit() { + logBuffer = listCreate(); +} + +void logText(char *string) { + // Clone the string + int32_t len = strlen(string); + char *newString = malloc(sizeof(char) * (len+1)); + memcpy(newString, string, len+1); + listAdd(logBuffer, newString); + printf("%s\n", newString); +} \ No newline at end of file diff --git a/src/debug/log.h b/src/debug/log.h new file mode 100644 index 00000000..d49a81c4 --- /dev/null +++ b/src/debug/log.h @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../util/list.h" + +/** Primary Log Buffer. */ +extern list_t *logBuffer; + +/** + * Writes a string to the log buffer. + * + * @param string String to log. + */ +void logText(char *string); \ No newline at end of file diff --git a/src/display/camera.h b/src/display/camera.h index bbb7ce47..ccc8ce85 100644 --- a/src/display/camera.h +++ b/src/display/camera.h @@ -5,7 +5,6 @@ #pragma once #include -#include "../util/math.h" /** * Make a camera look at a position in world space while itself being positioned diff --git a/src/display/debug/position.h b/src/display/debug/position.h index a8438896..1ee08a17 100644 --- a/src/display/debug/position.h +++ b/src/display/debug/position.h @@ -15,7 +15,6 @@ #include "../spritebatch.h" #include "../shader.h" #include "../../input/input.h" -#include "../../util/math.h" /** * Creates a position debug tool. diff --git a/src/display/gui/font.h b/src/display/gui/font.h index d6e3dff5..26a05f3a 100644 --- a/src/display/gui/font.h +++ b/src/display/gui/font.h @@ -8,7 +8,6 @@ #pragma once #include #include "../spritebatch.h" -#include "../../util/math.h" /** * Get the division for a given character. diff --git a/src/display/spritebatch.h b/src/display/spritebatch.h index 4682b92a..8b18851b 100644 --- a/src/display/spritebatch.h +++ b/src/display/spritebatch.h @@ -7,7 +7,6 @@ #include #include "primitive.h" #include "primitives/quad.h" -#include "../util/math.h" /** * Creates a new Sprite Batch made of standard quads. diff --git a/src/game/game.c b/src/game/game.c index c1f48c6b..16dda858 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -13,7 +13,10 @@ bool gameInit() { // Init the game GAME_STATE.name = GAME_NAME; - // Init the renderer. + logInit(); + logText("Starting Game"); + + // Init gameTimeInit(); renderInit(); inputInit(); diff --git a/src/game/game.h b/src/game/game.h index dc3416d0..934f2161 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -12,11 +12,7 @@ #include "../file/asset.h" #include "../input/input.h" #include "../card/poker/holdemgame.h" - -#include "../display/primitive.h" -#include "../display/primitives/cube.h" -#include "../display/texture.h" -#include "../util/math.h" +#include "../debug/log.h" /** * Initialize the game context. diff --git a/src/game/gametime.h b/src/game/gametime.h index 5dfceba8..ed5ee216 100644 --- a/src/game/gametime.h +++ b/src/game/gametime.h @@ -7,7 +7,6 @@ #pragma once #include -#include "../util/math.h" /** * Initializes the gametime global time tracking. diff --git a/src/world/entity/common.h b/src/world/entity/common.h index 8e373c0b..f4797e0e 100644 --- a/src/world/entity/common.h +++ b/src/world/entity/common.h @@ -11,7 +11,6 @@ #include "../../display/tileset.h" #include "../map/tile.h" #include "../map/chunk.h" -#include "../../util/math.h" #define ENTITY_COMMON_MOVE_SPEED 3 diff --git a/src/world/map/chunk.h b/src/world/map/chunk.h index 9c0b9141..94ca7ba0 100644 --- a/src/world/map/chunk.h +++ b/src/world/map/chunk.h @@ -8,7 +8,6 @@ #pragma once #include #include "../../display/primitive.h" -#include "../../util/math.h" #include "tile.h" /** diff --git a/src/world/map/map.h b/src/world/map/map.h index e05322be..dc277009 100644 --- a/src/world/map/map.h +++ b/src/world/map/map.h @@ -7,7 +7,6 @@ #pragma once #include -#include "../../util/math.h" #include "../../display/tileset.h" #include "../../file/asset.h" #include "chunk.h" diff --git a/src/world/map/tile.h b/src/world/map/tile.h index 5ce21dd6..0163c362 100644 --- a/src/world/map/tile.h +++ b/src/world/map/tile.h @@ -8,7 +8,6 @@ #pragma once #include #include "../../display/primitives/quad.h" -#include "../../util/math.h" typedef struct { int32_t chunkX, chunkY, chunkZ, localX, localY, localZ;