Did a lot of work on the engine
This commit is contained in:
@ -25,14 +25,37 @@
|
|||||||
/** State for whether or not a player is showing their hand */
|
/** State for whether or not a player is showing their hand */
|
||||||
#define HOLDEM_STATE_SHOWING 0x02
|
#define HOLDEM_STATE_SHOWING 0x02
|
||||||
|
|
||||||
|
/** Size of the Render frames */
|
||||||
#define HOLDEM_GAME_FRAME_HEIGHT RENDER_STATE.height
|
#define HOLDEM_GAME_FRAME_HEIGHT RENDER_STATE.height
|
||||||
#define HOLDEM_GAME_FRAME_LEFT_WIDTH RENDER_STATE.width*0.65
|
#define HOLDEM_GAME_FRAME_LEFT_WIDTH RENDER_STATE.width*0.65
|
||||||
#define HOLDEM_GAME_FRAME_RIGHT_WIDTH (\
|
#define HOLDEM_GAME_FRAME_RIGHT_WIDTH (\
|
||||||
RENDER_STATE.width - HOLDEM_GAME_FRAME_LEFT_WIDTH - 1\
|
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_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 */
|
/** How many actions the queue can hold */
|
||||||
#define HOLDEM_GAME_ACTION_QUEUE_SIZE 12
|
#define HOLDEM_GAME_ACTION_QUEUE_SIZE 12
|
||||||
@ -40,6 +63,7 @@
|
|||||||
/** How much data (in length of sizeof size_t) each action has available */
|
/** How much data (in length of sizeof size_t) each action has available */
|
||||||
#define HOLDEM_GAME_ACTION_DATA_SIZE 256
|
#define HOLDEM_GAME_ACTION_DATA_SIZE 256
|
||||||
|
|
||||||
|
|
||||||
/** Texas Hold'em Player State */
|
/** Texas Hold'em Player State */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Cards in the players' hand */
|
/** Cards in the players' hand */
|
||||||
@ -99,6 +123,7 @@ typedef struct {
|
|||||||
/** Action and Allocated Data Space */
|
/** Action and Allocated Data Space */
|
||||||
holdemaction_t actionQueue[HOLDEM_GAME_ACTION_QUEUE_SIZE];
|
holdemaction_t actionQueue[HOLDEM_GAME_ACTION_QUEUE_SIZE];
|
||||||
void *actionData[HOLDEM_GAME_ACTION_DATA_SIZE*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 */
|
/** Poker Table */
|
||||||
primitive_t *tablePrimitive;
|
primitive_t *tablePrimitive;
|
||||||
@ -121,4 +146,10 @@ typedef struct {
|
|||||||
camera_t cameraRight;
|
camera_t cameraRight;
|
||||||
} holdemgame_t;
|
} holdemgame_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x, z;
|
||||||
|
float yaw;
|
||||||
|
} holdemrenderposition_t;
|
||||||
|
|
||||||
extern holdemgame_t HOLDEM_GAME_STATE;
|
extern holdemgame_t HOLDEM_GAME_STATE;
|
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
// Utility Objects
|
// Utility Objects
|
||||||
#include "util/list.h"
|
#include "util/list.h"
|
||||||
|
#include "util/math.h"
|
||||||
|
#include "util/rand.h"
|
||||||
|
|
||||||
// 3D Tile Game World
|
// 3D Tile Game World
|
||||||
#include "world/entity/entity.h"
|
#include "world/entity/entity.h"
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#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 mathMod(a,b) (a%b+b)%b
|
||||||
#define mathMax(a,b) (a<b?b:a)
|
#define mathMax(a,b) (a<b?b:a)
|
||||||
#define mathMin(a,b) (a>b?b:a)
|
#define mathMin(a,b) (a>b?b:a)
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../util/rand.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills a deck with a standard set of cards (unshuffled)
|
* Fills a deck with a standard set of cards (unshuffled)
|
||||||
|
@ -19,7 +19,7 @@ void holdemActionInit() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void holdemActionAdd(holdemaction_t action) {
|
int32_t holdemActionAdd(holdemaction_t action) {
|
||||||
int32_t i = -1;
|
int32_t i = -1;
|
||||||
int32_t j = -1;
|
int32_t j = -1;
|
||||||
|
|
||||||
@ -28,16 +28,46 @@ void holdemActionAdd(holdemaction_t action) {
|
|||||||
j = i;
|
j = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(j == -1) return j;
|
||||||
|
|
||||||
HOLDEM_GAME_STATE.actionQueue[j] = action;
|
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() {
|
void holdemActionUpdate() {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
void **data;
|
||||||
|
holdemaction_t *action;
|
||||||
|
|
||||||
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
|
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
|
||||||
if(HOLDEM_GAME_STATE.actionQueue[i].update == NULL) continue;
|
action = HOLDEM_GAME_STATE.actionQueue + i;
|
||||||
HOLDEM_GAME_STATE.actionQueue[i].update(i, HOLDEM_GAME_STATE.actionData+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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,16 @@ void holdemActionInit();
|
|||||||
* Adds an action to the action queue.
|
* Adds an action to the action queue.
|
||||||
*
|
*
|
||||||
* @param action Action to add to the 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
|
* Updates the action manager, which (in turn) updates all actions that are
|
||||||
|
30
src/card/poker/action/ai.c
Normal file
30
src/card/poker/action/ai.c
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
17
src/card/poker/action/ai.h
Normal file
17
src/card/poker/action/ai.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
30
src/card/poker/action/deal.c
Normal file
30
src/card/poker/action/deal.c
Normal file
@ -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()
|
||||||
|
}
|
17
src/card/poker/action/deal.h
Normal file
17
src/card/poker/action/deal.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
35
src/card/poker/action/flop.c
Normal file
35
src/card/poker/action/flop.c
Normal file
@ -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());
|
||||||
|
}
|
19
src/card/poker/action/flop.h
Normal file
19
src/card/poker/action/flop.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
64
src/card/poker/action/round.c
Normal file
64
src/card/poker/action/round.c
Normal file
@ -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;
|
||||||
|
}
|
24
src/card/poker/action/round.h
Normal file
24
src/card/poker/action/round.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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();
|
30
src/card/poker/action/shuffle.c
Normal file
30
src/card/poker/action/shuffle.c
Normal file
@ -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();
|
||||||
|
}
|
23
src/card/poker/action/shuffle.h
Normal file
23
src/card/poker/action/shuffle.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
@ -18,18 +18,30 @@ holdemaction_t actionStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void actionStartInit(int32_t index, void *data) {
|
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
|
// Prepare the match
|
||||||
holdemMatchInit(&HOLDEM_GAME_STATE.match);
|
match = &HOLDEM_GAME_STATE.match;
|
||||||
holdemRoundInit(&HOLDEM_GAME_STATE.match);
|
match->blindBig = 0;
|
||||||
cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize);
|
match->blindSmall = 0;
|
||||||
holdemFlop(&HOLDEM_GAME_STATE.match);
|
|
||||||
|
// 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 actionStartUpdate(int32_t index, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void actionStartDispose(int32_t index, void *data) {
|
void actionStartDispose(int32_t index, void *data) {
|
||||||
|
// Begin the first round
|
||||||
|
holdemActionAdd(actionRound());
|
||||||
}
|
}
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
|
#include "action.h"
|
||||||
|
#include "round.h"
|
||||||
|
#include "../../../debug/log.h"
|
||||||
|
|
||||||
holdemaction_t actionStart();
|
holdemaction_t actionStart();
|
||||||
|
|
||||||
|
@ -7,57 +7,6 @@
|
|||||||
|
|
||||||
#include "holdem.h"
|
#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) {
|
void holdemDeal(holdemmatch_t *match, holdemplayer_t *player) {
|
||||||
cardDeal(match->deck, player->cards, match->deckSize, player->cardCount);
|
cardDeal(match->deck, player->cards, match->deckSize, player->cardCount);
|
||||||
match->deckSize--;
|
match->deckSize--;
|
||||||
|
@ -8,28 +8,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../card.h"
|
#include "../card.h"
|
||||||
#include "../../util/rand.h"
|
|
||||||
#include "../../display/spritebatch.h"
|
#include "../../display/spritebatch.h"
|
||||||
#include "../../display/texture.h"
|
#include "../../display/texture.h"
|
||||||
#include "../../display/tileset.h"
|
#include "../../display/tileset.h"
|
||||||
#include "../../display/shader.h"
|
#include "../../display/shader.h"
|
||||||
#include "../../file/asset.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.
|
* Deals a card to the given player, does all the follow up.
|
||||||
*
|
*
|
||||||
|
94
src/card/poker/render/card.c
Normal file
94
src/card/poker/render/card.c
Normal file
@ -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);
|
||||||
|
}
|
53
src/card/poker/render/card.h
Normal file
53
src/card/poker/render/card.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
93
src/card/poker/render/frame.c
Normal file
93
src/card/poker/render/frame.c
Normal file
@ -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);
|
||||||
|
}
|
41
src/card/poker/render/frame.h
Normal file
41
src/card/poker/render/frame.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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();
|
@ -8,18 +8,6 @@
|
|||||||
#include "holdemrender.h"
|
#include "holdemrender.h"
|
||||||
|
|
||||||
void holdemRenderInit() {
|
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
|
// Font
|
||||||
HOLDEM_GAME_STATE.fontTexture = assetTextureLoad("font.png");
|
HOLDEM_GAME_STATE.fontTexture = assetTextureLoad("font.png");
|
||||||
HOLDEM_GAME_STATE.fontTileset = tilesetCreate(20, 20,
|
HOLDEM_GAME_STATE.fontTileset = tilesetCreate(20, 20,
|
||||||
@ -29,249 +17,54 @@ void holdemRenderInit() {
|
|||||||
);
|
);
|
||||||
HOLDEM_GAME_STATE.fontBatch = spriteBatchCreate(1024);
|
HOLDEM_GAME_STATE.fontBatch = spriteBatchCreate(1024);
|
||||||
|
|
||||||
// Poker Table
|
holdemRenderFrameInit();
|
||||||
HOLDEM_GAME_STATE.tablePrimitive = pokerTableCreate();
|
holdemRenderSceneInit();
|
||||||
HOLDEM_GAME_STATE.tableTexture = assetTextureLoad("pokertable.png");
|
holdemRenderPlayerInit();
|
||||||
|
holdemRenderCardInit();
|
||||||
// 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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void holdemRender() {
|
void holdemRender() {
|
||||||
int32_t lWidth, rWidth, height;
|
holdemRenderFrameUpdate();
|
||||||
|
|
||||||
// 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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render things on the left frame buffer
|
// Render things on the left frame buffer
|
||||||
glClearColor(0.3, 0, 0, 1);
|
holdemRenderFrameUseLeft();
|
||||||
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);
|
|
||||||
holdemRenderWorld();
|
holdemRenderWorld();
|
||||||
|
|
||||||
// Render things on the right frame buffer
|
// Render things on the right frame buffer
|
||||||
glClearColor(0.3, 0.3, 0, 1);
|
holdemRenderFrameUseRight();
|
||||||
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);
|
|
||||||
holdemRenderWorld();
|
holdemRenderWorld();
|
||||||
|
|
||||||
// Finally, render the frame buffers to the back buffer.
|
// Finally, render the frame buffers to the back buffer.
|
||||||
glClearColor(0, 0, 0, 1);
|
holdemRenderFrameBack();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void holdemRenderWorld() {
|
void holdemRenderWorld() {
|
||||||
uint8_t i, j;
|
uint8_t i, j;
|
||||||
float pitch;
|
|
||||||
holdemplayer_t *player;
|
holdemplayer_t *player;
|
||||||
char name[16];
|
uint8_t seat;
|
||||||
|
|
||||||
// Poker Table
|
holdemRenderScene();
|
||||||
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);
|
|
||||||
|
|
||||||
holdemRenderCard(0x00, CARD_HEARTS_QUEEN);
|
// Render the dealer and her hand
|
||||||
holdemRenderCard(0x01, CARD_HEARTS_QUEEN);
|
holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER);
|
||||||
holdemRenderCard(0x02, CARD_HEARTS_QUEEN);
|
for(i = 0x00; i < HOLDEM_GAME_STATE.match.cardsFacing; i++) {
|
||||||
holdemRenderCard(0x03, CARD_HEARTS_QUEEN);
|
holdemRenderCardForSeat(
|
||||||
holdemRenderCard(0x04, CARD_HEARTS_QUEEN);
|
HOLDEM_GAME_SEAT_DEALER,
|
||||||
holdemRenderCard(0x05, CARD_HEARTS_QUEEN);
|
HOLDEM_GAME_STATE.match.cards[i],
|
||||||
holdemRenderCard(0x06, CARD_HEARTS_QUEEN);
|
HOLDEM_GAME_CARD_SLOT_FLOP0 + i
|
||||||
holdemRenderCard(0x07, CARD_HEARTS_QUEEN);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Players
|
// Test
|
||||||
holdemRenderPlayer(0x00);
|
for(i = 0x00; i < HOLDEM_PLAYER_COUNT; i++) {
|
||||||
holdemRenderPlayer(0x01);
|
player = HOLDEM_GAME_STATE.match.players + i;
|
||||||
holdemRenderPlayer(0x02);
|
seat = holdemRenderPlayerGetSeatForPlayer(i);
|
||||||
holdemRenderPlayer(0x03);
|
holdemRenderPlayer(seat);
|
||||||
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);
|
|
||||||
|
|
||||||
// shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture);
|
if(player->state & HOLDEM_STATE_FOLDED) continue;
|
||||||
// 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);
|
|
||||||
|
|
||||||
|
for(j = 0x00; j < player->cardCount; j++) {
|
||||||
|
holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,14 @@
|
|||||||
#include "../../../display/camera.h"
|
#include "../../../display/camera.h"
|
||||||
#include "../../../display/primitives/cube.h"
|
#include "../../../display/primitives/cube.h"
|
||||||
#include "../../../display/tileset.h"
|
#include "../../../display/tileset.h"
|
||||||
#include "../../../util/math.h"
|
|
||||||
#include "../model/pokertable.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.
|
* Prepare the Hold'em Game Renderer.
|
||||||
*/
|
*/
|
||||||
@ -29,33 +34,4 @@ void holdemRenderInit();
|
|||||||
*/
|
*/
|
||||||
void holdemRender();
|
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();
|
void holdemRenderWorld();
|
30
src/card/poker/render/look.c
Normal file
30
src/card/poker/render/look.c
Normal file
@ -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
|
||||||
|
);
|
||||||
|
}
|
25
src/card/poker/render/look.h
Normal file
25
src/card/poker/render/look.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dawn/dawn.h>
|
||||||
|
#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);
|
69
src/card/poker/render/player.c
Normal file
69
src/card/poker/render/player.c
Normal file
@ -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);
|
||||||
|
}
|
32
src/card/poker/render/player.h
Normal file
32
src/card/poker/render/player.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
24
src/card/poker/render/scene.c
Normal file
24
src/card/poker/render/scene.c
Normal file
@ -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);
|
||||||
|
}
|
23
src/card/poker/render/scene.h
Normal file
23
src/card/poker/render/scene.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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();
|
23
src/debug/log.c
Normal file
23
src/debug/log.c
Normal file
@ -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);
|
||||||
|
}
|
20
src/debug/log.h
Normal file
20
src/debug/log.h
Normal file
@ -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 <dawn/dawn.h>
|
||||||
|
#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);
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a camera look at a position in world space while itself being positioned
|
* Make a camera look at a position in world space while itself being positioned
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "../spritebatch.h"
|
#include "../spritebatch.h"
|
||||||
#include "../shader.h"
|
#include "../shader.h"
|
||||||
#include "../../input/input.h"
|
#include "../../input/input.h"
|
||||||
#include "../../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a position debug tool.
|
* Creates a position debug tool.
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../spritebatch.h"
|
#include "../spritebatch.h"
|
||||||
#include "../../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the division for a given character.
|
* Get the division for a given character.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "primitive.h"
|
#include "primitive.h"
|
||||||
#include "primitives/quad.h"
|
#include "primitives/quad.h"
|
||||||
#include "../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Sprite Batch made of standard quads.
|
* Creates a new Sprite Batch made of standard quads.
|
||||||
|
@ -13,7 +13,10 @@ bool gameInit() {
|
|||||||
// Init the game
|
// Init the game
|
||||||
GAME_STATE.name = GAME_NAME;
|
GAME_STATE.name = GAME_NAME;
|
||||||
|
|
||||||
// Init the renderer.
|
logInit();
|
||||||
|
logText("Starting Game");
|
||||||
|
|
||||||
|
// Init
|
||||||
gameTimeInit();
|
gameTimeInit();
|
||||||
renderInit();
|
renderInit();
|
||||||
inputInit();
|
inputInit();
|
||||||
|
@ -12,11 +12,7 @@
|
|||||||
#include "../file/asset.h"
|
#include "../file/asset.h"
|
||||||
#include "../input/input.h"
|
#include "../input/input.h"
|
||||||
#include "../card/poker/holdemgame.h"
|
#include "../card/poker/holdemgame.h"
|
||||||
|
#include "../debug/log.h"
|
||||||
#include "../display/primitive.h"
|
|
||||||
#include "../display/primitives/cube.h"
|
|
||||||
#include "../display/texture.h"
|
|
||||||
#include "../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the game context.
|
* Initialize the game context.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../util/math.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the gametime global time tracking.
|
* Initializes the gametime global time tracking.
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "../../display/tileset.h"
|
#include "../../display/tileset.h"
|
||||||
#include "../map/tile.h"
|
#include "../map/tile.h"
|
||||||
#include "../map/chunk.h"
|
#include "../map/chunk.h"
|
||||||
#include "../../util/math.h"
|
|
||||||
|
|
||||||
#define ENTITY_COMMON_MOVE_SPEED 3
|
#define ENTITY_COMMON_MOVE_SPEED 3
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../../display/primitive.h"
|
#include "../../display/primitive.h"
|
||||||
#include "../../util/math.h"
|
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../../util/math.h"
|
|
||||||
#include "../../display/tileset.h"
|
#include "../../display/tileset.h"
|
||||||
#include "../../file/asset.h"
|
#include "../../file/asset.h"
|
||||||
#include "chunk.h"
|
#include "chunk.h"
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../../display/primitives/quad.h"
|
#include "../../display/primitives/quad.h"
|
||||||
#include "../../util/math.h"
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t chunkX, chunkY, chunkZ, localX, localY, localZ;
|
int32_t chunkX, chunkY, chunkZ, localX, localY, localZ;
|
||||||
|
Reference in New Issue
Block a user