Restored some of the rendering

This commit is contained in:
2021-05-22 14:18:23 -07:00
parent 58e86d160e
commit d84e760c34
36 changed files with 813 additions and 331 deletions

View File

@ -7,7 +7,7 @@
#include "pokertable.h"
void pokerTableCreate(primitive_t *primitive) {
void pokerTableInit(primitive_t *primitive) {
vertice_t vertices[POKER_TABLE_VERTICE_COUNT] = {
{ .x = 0.12437210000000001, .y = 0, .z = -0.30026090000000005, .u = 0.836914, .v = 0.265625 },
{ .x = 0.29349590000000003, .y = 0.0176777, .z = -0.12157000000000001, .u = 0.853516, .v = 0.06445299999999998 },

View File

@ -10,72 +10,28 @@
bool gameInit(game_t *game) {
// Init the game
game->name = GAME_NAME;
// Init the engine and the rendering pipeline
engineInit(&game->engine, game);
// assetShaderLoad(&game->shader,"shaders/textured.vert","shaders/textured.frag");
// assetTextureLoad(&game->texture, "cards_normal.png");
// cubeInit(&game->primitive, 1, 1, 1);
// Hand off to the poker logic.
pokerInit(&game->poker);
// // Load the world shader.
// GAME_STATE.shaderWorld = assetShaderLoad(
// "shaders/textured.vert", "shaders/textured.frag"
// );
// // Font
// GAME_STATE.fontTexture = assetTextureLoad("font.png");
// GAME_STATE.fontTileset = tilesetCreate(20, 20,
// GAME_STATE.fontTexture->width,
// GAME_STATE.fontTexture->height,
// 1, 1, 1, 1
// );
// GAME_STATE.fontBatch = spriteBatchCreate(1024);
// // Prepare the renderer.
// pokerInit(&GAME_STATE.poker);
// holdemRenderFrameInit();
// holdemRenderWorldInit();
// holdemRenderPlayerInit();
// holdemRenderCardInit();
// holdemRenderChipInit();
// Init the input manger.
return true;
}
bool gameUpdate(game_t *game, float platformDelta) {
// Let the engine do its thing.
engineUpdateStart(&game->engine, game, platformDelta);
cameraPerspective(&game->camera, 75,
((float)game->engine.render.width)/((float)game->engine.render.height),
0.01, 1000
);
cameraLookAt(&game->camera, 3, 3, 3, 0, 0, 0);
shaderUse(&game->shader);
shaderUseTexture(&game->shader, &game->texture);
shaderUseCamera(&game->shader, &game->camera);
shaderUsePosition(&game->shader, 0, 0, 0, 0, game->engine.time.current, 0);
primitiveDraw(&game->primitive, 0, -1);
// Hand off to the poker logic
pokerUpdate(&game->poker, &game->engine.render);
// shaderUse(GAME_STATE.shaderWorld);// TODO: remove
// // Update the frame buffers and action queue
// holdemRenderFrameUpdate();
// pokerActionUpdate();
// // Render things on each frame, then render those frames.
// holdemRenderFrameUseLeft();
// holdemRenderWorld();
// holdemRenderFrameUseRight();
// holdemRenderWorld();
// holdemRenderFrameBack();
// Hand back to the engine.
return engineUpdateEnd(&game->engine, game);
}
void gameDispose(game_t *game) {
pokerDispose(&game->poker);
engineDispose(&game->engine, game);
// pokerActionDispose();
// shaderDispose(GAME_STATE.shaderWorld);
}

View File

@ -6,14 +6,7 @@
#pragma once
#include <dawn/dawn.h>
#include "../engine/engine.h"
#include "../file/asset.h"
#include "../display/render.h"
#include "../display/primitive.h"
#include "../display/primitives/cube.h"
#include "../display/texture.h"
#include "../display/shader.h"
#include "../display/camera.h"
#include "../poker/poker.h"
/**
* Initialize the game context.

View File

@ -1,34 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "card.h"
void cardDeckFill(card_t *deck) {
uint8_t i;
for(i = 0; i < CARD_DECK_SIZE; i++) {
deck[i] = i;
}
}
void cardShuffle(card_t *hand, uint8_t cardCount) {
uint8_t i, j;
card_t temporary;
for(i = 0; i < cardCount - 1; i++) {
// Select random element from remaining elements.
j = u8randRange(i, cardCount);
temporary = hand[j];// Take out other card
hand[j] = hand[i];// Move my card there
hand[i] = temporary;// Put other card here.
}
}
void cardDeal(card_t *deck, card_t *hand, uint8_t deckSize, uint8_t handSize) {
card_t card;
card = deck[deckSize-1];
deck[deckSize-1] = 0x00;
hand[handSize] = card;
}

View File

@ -1,34 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Fills a deck with a standard set of cards (unshuffled)
*
* @param deck Deck to fill. Must be at least 52 elements.
*/
void cardDeckFill(card_t *deck);
/**
* Shuffles the given hand or deck.
*
* @param hand The hand/deck to shuffle.
* @param cardCount The amount of cards that are in that deck/hand.
*/
void cardShuffle(card_t *hand, uint8_t cardCount);
/**
* Deals a card of the top of the deck into the given hand.
*
* @param deck Deck to take from.
* @param hand Hand to put into.
* @param deckSize Size of the current deck.
* @param handSize Size of the current hand.
*/
void cardDeal(card_t *deck, card_t *hand, uint8_t deckSize, uint8_t handSize);

View File

@ -10,33 +10,49 @@
void pokerInit(poker_t *poker) {
uint8_t x;
// Prepare the initial game state
poker->round = POKER_ROUND_DEAL;
poker->roundPlayer = 0x00;
// Load the main shader
assetShaderLoad(&poker->shader,
"shaders/textured.vert", "shaders/textured.frag"
);
// Initialize the render stuffs.
pokerWorldInit(poker);
pokerCardInit(poker);
pokerPlayerInit(poker);
// Reset the main game state. This does not init the round.
poker->blindBig = POKER_BLIND_BIG_DEFAULT;
poker->blindSmall = POKER_BLIND_SMALL_DEFAULT;
poker->roundDealer = 0x00;
poker->blindSmall = 0;
poker->blindBig = 0;
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
poker->players[x].state = 0x00;
poker->players[x].chips = 0;
poker->players[x].cardCount = 0;
poker->players[x].currentBet = 0;
poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT;
}
pokerRoundInit(poker);
// Hand over to the deal for the first time.
pokerDealInit(poker);
}
void pokerRoundInit(poker_t *poker) {
uint8_t x;
void pokerUpdate(poker_t *poker, render_t *render) {
// Game Logic
// Refill the deck
cardDeckFill(poker->deck);
poker->deckSize = CARD_DECK_SIZE;
// TEMP
cameraPerspective(&poker->camera, 20,render->width/render->height,0.001,1000);
pokerLookAtPlayer(&poker->camera, pokerPlayerGetSeatForPlayer(0x00));
// Reset the players
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
poker->players[x].cardCount = 0;
poker->players[x].currentBet = 0;
// Render Logic
shaderUse(&poker->shader);
shaderUseCamera(&poker->shader, &poker->camera);
pokerWorldRender(poker);
for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) {
uint8_t seat = pokerPlayerGetSeatForPlayer(pi);
pokerPlayerRender(poker, poker->players + pi, seat);
}
}
void pokerDispose(poker_t * poker) {
pokerWorldDispose(poker);
shaderDispose(&poker->shader);
}

View File

@ -7,19 +7,31 @@
#pragma once
#include <dawn/dawn.h>
#include "card.h"
#include "round/deal.h"
#include "render/world.h"
#include "render/card.h"
#include "render/player.h"
#include "render/look.h"
#include "../file/asset.h"
#include "../display/shader.h"
#include "../display/camera.h"
/**
* Initializes the poker match for the first time.
*
* @param poker Poker game to init.
* Initializes the poker context for the first time.
* @param poker Poker context to initialize.
*/
void pokerInit(poker_t *poker);
/**
* Updates the poker context.
* @param poker Poker game to update.
* @param render Render manager to use.
*/
void pokerUpdate(poker_t *poker, render_t *render);
/**
* Initializes the round for a poker game.
*
* @param poker Poker game to init a new round for.
* Cleans an existing poker game instance.
* @param poker Poker instance to cleanup
*/
void pokerRoundInit(poker_t *poker);
void pokerDispose(poker_t *poker);

View File

@ -5,61 +5,62 @@
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "card.h"
void holdemRenderCardInit() {
void pokerCardInit(poker_t *poker) {
tilesetdiv_t *cardBack;
// Load Cards Texture
GAME_STATE.cardTexture = assetTextureLoad("cards_normal.png");
GAME_STATE.cardTileset = tilesetCreate(CARD_COUNT_PER_SUIT, 6,
GAME_STATE.cardTexture->width, GAME_STATE.cardTexture->height,
0, 0, 0, 0
assetTextureLoad(&poker->cardTexture, "cards_normal.png");
tilesetInit(&poker->cardTileset,
CARD_COUNT_PER_SUIT, 6,
poker->cardTexture.width, poker->cardTexture.height,
0, 0,
0, 0
);
// Cards Primitive
cardBack = GAME_STATE.cardTileset->divisions+(
GAME_STATE.cardTileset->columns * 4
);
GAME_STATE.cardPrimitive = primitiveCreate(
cardBack = poker->cardTileset.divisions+(poker->cardTileset.columns * 4);
primitiveInit(&poker->cardPrimitive,
QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2
);
quadBuffer(GAME_STATE.cardPrimitive, -HOLDEM_GAME_CARD_DEPTH,
-HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT,
quadBuffer(&poker->cardPrimitive, -POKER_CARD_DEPTH,
-POKER_CARD_WIDTH, -POKER_CARD_HEIGHT,
cardBack->x0, cardBack->y1,
HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT,
POKER_CARD_WIDTH, POKER_CARD_HEIGHT,
cardBack->x1, cardBack->y0,
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
);
}
pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) {
pokerposition_t pokerCardGetPosition(uint8_t seat, uint8_t slot) {
pokerposition_t position;
float t, t2;
position.yaw = HOLDEM_GAME_SEAT_ANGLE(seat);
position.yaw = POKER_SEAT_ANGLE(seat);
position.x = sin(position.yaw) * -0.75;
position.z = cos(position.yaw) * -0.75;
t = position.yaw + mathDeg2Rad(90);
switch (slot) {
case HOLDEM_GAME_CARD_SLOT_HAND0:
case HOLDEM_GAME_CARD_SLOT_HAND1:
t2 = HOLDEM_GAME_CARD_WIDTH+HOLDEM_GAME_CARD_PADDING;
if(slot == HOLDEM_GAME_CARD_SLOT_HAND0) t2 = -t2;
case POKER_CARD_SLOT_HAND0:
case POKER_CARD_SLOT_HAND1:
t2 = POKER_CARD_WIDTH+POKER_CARD_PADDING;
if(slot == POKER_CARD_SLOT_HAND0) t2 = -t2;
t2 += 0.1;
break;
case HOLDEM_GAME_CARD_SLOT_FLOP0:
case HOLDEM_GAME_CARD_SLOT_FLOP1:
case HOLDEM_GAME_CARD_SLOT_FLOP2:
case HOLDEM_GAME_CARD_SLOT_FLOP3:
case HOLDEM_GAME_CARD_SLOT_FLOP4:
t2 = HOLDEM_GAME_CARD_WIDTH*2+HOLDEM_GAME_CARD_PADDING;
case POKER_CARD_SLOT_FLOP0:
case POKER_CARD_SLOT_FLOP1:
case POKER_CARD_SLOT_FLOP2:
case POKER_CARD_SLOT_FLOP3:
case POKER_CARD_SLOT_FLOP4:
t2 = POKER_CARD_WIDTH*2+POKER_CARD_PADDING;
t2 = (
-t2 * ( HOLDEM_GAME_CARD_SLOT_FLOP4-HOLDEM_GAME_CARD_SLOT_FLOP0)
)/2 + t2*(slot-HOLDEM_GAME_CARD_SLOT_FLOP0);
-t2 * ( POKER_CARD_SLOT_FLOP4-POKER_CARD_SLOT_FLOP0)
)/2 + t2*(slot-POKER_CARD_SLOT_FLOP0);
break;
default:
@ -72,24 +73,27 @@ pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) {
return position;
}
void holdemRenderCard(card_t card, float x, float y, float z,
void pokerCardRender(poker_t *poker, card_t card, float x, float y, float z,
float pitch, float yaw, float roll
) {
tilesetdiv_t *cardFront = GAME_STATE.cardTileset->divisions + card;
quadBuffer(GAME_STATE.cardPrimitive, HOLDEM_GAME_CARD_DEPTH,
-HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT,
tilesetdiv_t *cardFront = poker->cardTileset.divisions + card;
quadBuffer(&poker->cardPrimitive, POKER_CARD_DEPTH,
-POKER_CARD_WIDTH, -POKER_CARD_HEIGHT,
cardFront->x0, cardFront->y1,
HOLDEM_GAME_CARD_WIDTH, HOLDEM_GAME_CARD_HEIGHT,
POKER_CARD_WIDTH, POKER_CARD_HEIGHT,
cardFront->x1, cardFront->y0,
0, 0
);
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.cardTexture);
shaderUsePosition(GAME_STATE.shaderWorld, x,y,z, pitch,yaw,roll);
primitiveDraw(GAME_STATE.cardPrimitive, 0, -1);
shaderUseTexture(&poker->shader, &poker->cardTexture);
shaderUsePosition(&poker->shader, x,y,z, pitch,yaw,roll);
primitiveDraw(&poker->cardPrimitive, 0, -1);
}
void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot) {
pokerposition_t position = holdemRenderCardGetPosition(seat, slot);
holdemRenderCard(card, position.x, 0, position.z, mathDeg2Rad(-90), position.yaw, 0);
void pokerCardRenderForSeat(poker_t *poker, uint8_t seat, card_t card, uint8_t slot) {
pokerposition_t position = pokerCardGetPosition(seat, slot);
pokerCardRender(poker, card,
position.x, 0, position.z,
mathDeg2Rad(-90), position.yaw, 0
);
}

View File

@ -15,8 +15,9 @@
/**
* Initializes the Card Renderer.
* @param poker The poker game context.
*/
void holdemRenderCardInit();
void pokerCardInit(poker_t *poker);
/**
* Returns the position a card "naturally" sits at for a given seat and slot.
@ -25,12 +26,13 @@ void holdemRenderCardInit();
* @param slot Slot within the player/dealers' hand that the card belongs to.
* @return A struct containing X, Z and YAW properties.
*/
pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot);
pokerposition_t pokerCardGetPosition(uint8_t seat, uint8_t slot);
/**
* Render's a given card at the specified coordinates. Card is a reused quad
* and is re-buffered to for every draw call.
*
* @param poker The poker game context.
* @param card Card to render.
* @param x X Position (world space).
* @param y Y Position (world space).
@ -39,15 +41,15 @@ pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot);
* @param yaw Yaw angle.
* @param roll Roll angle.
*/
void holdemRenderCard(card_t card, float x, float y, float z,
void pokerCardRender(poker_t *poker, card_t card, float x, float y, float z,
float pitch, float yaw, float roll
);
/**
* Render's a card at a given seat and slot.
*
* @param poker The poker game context.
* @param seat Seat the card is for.
* @param card Card to render.
* @param slot Slot the card is for.
*/
void holdemRenderCardForSeat(uint8_t seat, card_t card, uint8_t slot);
void pokerCardRenderForSeat(poker_t *poker, uint8_t seat, card_t card, uint8_t slot);

View File

@ -1,46 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "chip.h"
void holdemRenderChipSet(int32_t count,float x,float y,float z,float yaw) {
shaderUsePositionAndScale(GAME_STATE.shaderWorld,
x, y, z,
0, yaw, 0,
0.2, 0.2, 0.2
);
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.chipTexture);
primitiveDraw(GAME_STATE.chipPrimitive, 0, -1);
}
pokerposition_t holdemRenderChipGetPosition(uint8_t seat) {
pokerposition_t position;
float t, t2;
position.yaw = HOLDEM_GAME_SEAT_ANGLE(seat);
position.x = sin(position.yaw) * -0.675;
position.z = cos(position.yaw) * -0.675;
t = position.yaw + mathDeg2Rad(90);
t2 = -0.175;
position.x += t2 * sin(t);
position.z += t2 * cos(t);
return position;
}
void holdemRenderChipInit() {
GAME_STATE.chipPrimitive = pokerChipCreate();
GAME_STATE.chipTexture = assetTextureLoad("pokerchip.png");
}
void holdemRenderChip() {
for(uint8_t seat = 0; seat < 0x08; seat++) {
pokerposition_t position = holdemRenderChipGetPosition(HOLDEM_GAME_SEAT_PLAYER0);
holdemRenderChipSet(0, position.x, 0.05, position.z, position.yaw);
}
}

View File

@ -1,42 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../assets/models/pokerchip.h"
#include "../../file/asset.h"
#include "../../display/shader.h"
#include "../../display/texture.h"
/**
* Renders a stack of chips at a position.
*
* @param count Count of chips to render (Determines the stack size).
* @param x X position of the stack.
* @param y Y position of the stack.
* @param z Z position of the stack.
* @param yaw Rotation (YAW) of the chips.
*/
void holdemRenderChipSet(int32_t count,float x,float y,float z,float yaw);
/**
* Get the position for a stack of chips based on a seat.
*
* @param seat Seat to get the position for.
* @return Position for the seat that the chips should render to.
*/
pokerposition_t holdemRenderChipGetPosition(uint8_t seat);
/**
* Init the poker chips renderer for each player.
*/
void holdemRenderChipInit();
/**
* Render the poker chips.
*/
void holdemRenderChip();

View File

@ -1,103 +0,0 @@
/**
* 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;
GAME_STATE.frameLeft = frameBufferCreate(lWidth, height);
GAME_STATE.frameRight = frameBufferCreate(rWidth, height);
GAME_STATE.quadLeft = quadCreate(0, 0, 0, 0, 0, lWidth, height, 1, 1);
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((
GAME_STATE.frameLeft->texture->width == lWidth &&
GAME_STATE.frameLeft->texture->height == height
)) return;
// Recreate frame buffers.
frameBufferDispose(GAME_STATE.frameLeft);
frameBufferDispose(GAME_STATE.frameRight);
GAME_STATE.frameLeft = frameBufferCreate(lWidth, height);
GAME_STATE.frameRight = frameBufferCreate(rWidth, height);
quadBuffer(GAME_STATE.quadLeft, 0,
0, 0, 0, 1,
lWidth, height, 1, 0,
0, 0
);
quadBuffer(GAME_STATE.quadRight, 0,
0, 0, 0, 1,
rWidth, height, 1, 0,
0, 0
);
}
void holdemRenderFrameUseLeft() {
glClearColor(0.3, 0, 0, 1);
frameBufferUse(GAME_STATE.frameLeft, true);
cameraPerspective(&GAME_STATE.cameraLeft, 35,
(
(float)GAME_STATE.frameLeft->texture->width /
(float)GAME_STATE.frameLeft->texture->height
), 0.2f, 1000.0f
);
shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraLeft);
}
void holdemRenderFrameUseRight() {
glClearColor(0.3, 0.3, 0, 1);
frameBufferUse(GAME_STATE.frameRight, true);
cameraPerspective(&GAME_STATE.cameraRight, 45,
(
(float)GAME_STATE.frameRight->texture->width /
(float)GAME_STATE.frameRight->texture->height
), 0.2f, 1000.0f
);
cameraLookAt(&GAME_STATE.cameraRight, 0, 3, 3, 0, 0, 0);
// cameraPerspective(&GAME_STATE.cameraRight, 15,
// (
// (float)GAME_STATE.frameRight->texture->width /
// (float)GAME_STATE.frameRight->texture->height
// ), 0.2f, 1000.0f
// );
// cameraLookAt(&GAME_STATE.cameraRight, 0, 1, -8, 0, 0, 0);
shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraRight);
}
void holdemRenderFrameBack() {
glClearColor(0, 0, 0, 1);
frameBufferUse(NULL, true);
cameraOrtho(&GAME_STATE.cameraMain, 0,
RENDER_STATE.width, RENDER_STATE.height, 1, 0, 1
);
cameraLookAt(&GAME_STATE.cameraMain, 0, 0, 0.5f, 0, 0, 0);
shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraMain);
shaderUsePosition(GAME_STATE.shaderWorld,
0, 0, 0, 0, 0, 0
);
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.frameLeft->texture);
primitiveDraw(GAME_STATE.quadLeft, 0, -1);
shaderUsePosition(GAME_STATE.shaderWorld,
RENDER_STATE.width - GAME_STATE.frameRight->texture->width,
0, 0, 0, 0, 0
);
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.frameRight->texture);
primitiveDraw(GAME_STATE.quadRight, 0, -1);
}

View File

@ -1,41 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/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();

View File

@ -7,23 +7,23 @@
#include "look.h"
void holdemRenderLookSeat(camera_t *camera, uint8_t seat) {
void pokerLookAtPlayer(camera_t *camera, uint8_t seat) {
float x, z, angle;
angle = HOLDEM_GAME_SEAT_ANGLE(seat);
angle = POKER_SEAT_ANGLE(seat);
x = sin(angle);
z = cos(angle);
cameraLookAt(&GAME_STATE.cameraLeft,
cameraLookAt(camera,
x, 0.2, z,
-x, 0.2, -z
);
}
void holdemRenderLookHand(camera_t *camera, uint8_t seat) {
void pokerLookAtHand(camera_t *camera, uint8_t seat) {
float x, z, angle;
angle = HOLDEM_GAME_SEAT_ANGLE(seat);
angle = POKER_SEAT_ANGLE(seat);
x = sin(angle);
z = cos(angle);
cameraLookAt(&GAME_STATE.cameraLeft,
cameraLookAt(camera,
x*0.1, 0.8, z*0.1,
-x*0.5, 0.2, -z*0.5
);

View File

@ -9,17 +9,17 @@
#include "../../display/camera.h"
/**
* Look at a specific seat
* Look at a specific seats' player.
*
* @param camera Camera to adjust.
* @param seat Seat to look at.
*/
void holdemRenderLookSeat(camera_t *camera, uint8_t seat);
void pokerLookAtPlayer(camera_t *camera, uint8_t seat);
/**
* Look at a specific seats hand.
* Look at a specific seats' hand.
*
* @param camera Camera to adjust.
* @param seat Seats hand to look at.
*/
void holdemRenderLookHand(camera_t *camera, uint8_t seat);
void pokerLookAtHand(camera_t *camera, uint8_t seat);

View File

@ -7,63 +7,62 @@
#include "player.h"
void holdemRenderPlayerInit() {
GAME_STATE.kagamiTexture = assetTextureLoad("kagami.png");
GAME_STATE.kagamiTileset = tilesetCreate(3, 2,
GAME_STATE.kagamiTexture->width,
GAME_STATE.kagamiTexture->height,
0, 0, 0, 0
);
GAME_STATE.kagamiQuad = quadCreate(0, 0, 0, 0, 0, 1, 1, 1, 1);
}
void pokerPlayerInit(poker_t *poker) {
uint8_t i;
pokerplayer_t *player;
float w, h;
uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player) {
switch(player) {
case 0x01:
return HOLDEM_GAME_SEAT_PLAYER1;
case 0x02:
return HOLDEM_GAME_SEAT_PLAYER2;
case 0x03:
return HOLDEM_GAME_SEAT_PLAYER3;
case 0x04:
return HOLDEM_GAME_SEAT_PLAYER4;
default:
return HOLDEM_GAME_SEAT_PLAYER0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
player = poker->players + i;
assetTextureLoad(&player->bodyTexture, "characters/penny/body.png");
assetTextureLoad(&player->faceTexture, "characters/penny/face.png");
w = 0.6;
h=((float)player->faceTexture.width)/((float)player->faceTexture.height)*w;
w = w / 2;
h = h / 2;
quadInit(&player->bodyPrimitive, 0,
-w, -h, 0, 1,
w, h, 1, 0
);
quadInit(&player->facePrimitive, 0,
-w, -h, 0, 1,
w, h, 1, 0
);
}
}
void holdemRenderPlayer(uint8_t seat) {
uint8_t pokerPlayerGetSeatForPlayer(uint8_t player) {
switch(player) {
case 0x01:
return POKER_SEAT_PLAYER1;
case 0x02:
return POKER_SEAT_PLAYER2;
case 0x03:
return POKER_SEAT_PLAYER3;
case 0x04:
return POKER_SEAT_PLAYER4;
default:
return POKER_SEAT_PLAYER0;
}
}
void pokerPlayerRender(poker_t* poker, pokerplayer_t *player, uint8_t seat) {
float x, z, angle;
float w, h;
// Determine position
angle = HOLDEM_GAME_SEAT_ANGLE(seat);
angle = POKER_SEAT_ANGLE(seat);
x = sin(angle) * -1;
z = cos(angle) * -1;
// Determine size
float w, h;
w = 0.6, h = (
(float)GAME_STATE.kagamiTileset->divY /
(float)GAME_STATE.kagamiTileset->divX
) * w;
shaderUsePosition(&poker->shader, x,0.34,z, 0,angle,0);
// Animation
int i = (int32_t)(TIME_STATE.current*10)%GAME_STATE.kagamiTileset->count;
quadBuffer(GAME_STATE.kagamiQuad, 0,
-w/2, -h/2,
GAME_STATE.kagamiTileset->divisions[i].x0,
GAME_STATE.kagamiTileset->divisions[i].y1,
w/2, h/2,
GAME_STATE.kagamiTileset->divisions[i].x1,
GAME_STATE.kagamiTileset->divisions[i].y0,
0, 0
);
// Render Body
shaderUseTexture(&poker->shader, &player->bodyTexture);
primitiveDraw(&player->bodyPrimitive, 0, -1);
// Render
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.kagamiTexture);
shaderUsePosition(GAME_STATE.shaderWorld,
x, 0.34, z,
0, angle, 0
);
primitiveDraw(GAME_STATE.kagamiQuad, 0, -1);
// Render Face
shaderUseTexture(&poker->shader, &player->faceTexture);
primitiveDraw(&player->facePrimitive, 0, -1);
}

View File

@ -15,20 +15,20 @@
/**
* Initializes the player renderer.
* @param poker Poker game context.
*/
void holdemRenderPlayerInit();
void pokerPlayerInit(poker_t *poker);
/**
* Returns the seat index for a given player.
*
* @param player Player to get the seat for.
* @return Seat ID for the given player.
*/
uint8_t holdemRenderPlayerGetSeatForPlayer(uint8_t player);
uint8_t pokerPlayerGetSeatForPlayer(uint8_t player);
/**
* Render's a player at a seat.
*
* @param poker Poker game context.
* @param seat Seat to render the player at.
*/
void holdemRenderPlayer(uint8_t seat);
void pokerPlayerRender(poker_t *poker, pokerplayer_t *player, uint8_t seat);

View File

@ -7,47 +7,24 @@
#include "world.h"
void holdemRenderWorldInit() {
GAME_STATE.tablePrimitive = pokerTableCreate();
GAME_STATE.tableTexture = assetTextureLoad("pokertable.png");
void pokerWorldInit(poker_t *poker) {
// Poker Table
pokerTableInit(&poker->tablePrimitive);
assetTextureLoad(&poker->tableTexture, "pokertable.png");
}
void holdemRenderWorld() {
uint8_t i, j;
pokerplayer_t *player;
uint8_t seat;
void pokerWorldRender(poker_t *poker) {
// Poker Table
shaderUsePositionAndScale(GAME_STATE.shaderWorld,
shaderUsePositionAndScale(&poker->shader,
0, -0.01, 0,
0, 0, 0,
3.4, 3.4, 3.4
);
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.tableTexture);
primitiveDraw(GAME_STATE.tablePrimitive, 0, -1);
shaderUseTexture(&poker->shader, &poker->tableTexture);
primitiveDraw(&poker->tablePrimitive, 0, -1);
}
// Render the dealer and her hand
holdemRenderPlayer(HOLDEM_GAME_SEAT_DEALER);
for(i = 0x00; i < GAME_STATE.cardsFacing; i++) {
holdemRenderCardForSeat(
HOLDEM_GAME_SEAT_DEALER,
GAME_STATE.cards[i],
HOLDEM_GAME_CARD_SLOT_FLOP0 + i
);
}
// Test
for(i = 0x00; i < POKER_PLAYER_COUNT; i++) {
player = GAME_STATE.players + i;
seat = holdemRenderPlayerGetSeatForPlayer(i);
holdemRenderPlayer(seat);
if(player->state & POKER_PLAYER_STATE_SHOWING) continue;
for(j = 0x00; j < player->cardCount; j++) {
holdemRenderCardForSeat(seat, player->cards[j], HOLDEM_GAME_CARD_SLOT_HAND0+j);
}
}
holdemRenderChip();
void pokerWorldDispose(poker_t *poker) {
textureDispose(&poker->tableTexture);
primitiveDispose(&poker->tablePrimitive);
}

View File

@ -7,17 +7,26 @@
#pragma once
#include <dawn/dawn.h>
#include "player.h"
#include "card.h"
#include "chip.h"
#include "../../assets/models/pokertable.h"
#include "../../display/shader.h"
#include "../../display/primitive.h"
#include "../../display/texture.h"
#include "../../file/asset.h"
/**
* Initializes the world renderer.
* @param poker Poker scene to initialize.
*/
void holdemRenderWorldInit();
void pokerWorldInit(poker_t *poker);
/**
* Renders the world.
* @param poker Poker scene to render.
*/
void holdemRenderWorld();
void pokerWorldRender(poker_t *poker);
/**
* Disposes a poker world.
* @param poker Poker game to cleanup the world for.
*/
void pokerWorldDispose(poker_t *poker);

44
src/poker/round/deal.c Normal file
View File

@ -0,0 +1,44 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "deal.h"
void pokerDealInit(poker_t *poker) {
uint8_t x, y;
card_t temporary;
// Prepare the initial game state
poker->round = POKER_ROUND_DEAL;
poker->pot = 0;
poker->roundBet = 0;
poker->graveSize = 0;
poker->cardsFacing = 0;
poker->deckSize = CARD_DECK_SIZE;
for(x = 0; x < CARD_DECK_SIZE; x++) poker->deck[x] = x;
// Reset the players
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
poker->players[x].cardCount = 0;
poker->players[x].currentBet = 0;
// Invert then bitwise AND to turn off.
poker->players[x].state &= ~(
POKER_PLAYER_STATE_FOLDED |
POKER_PLAYER_STATE_SHOWING
);
}
// Hard look at the dealer
// Shuffle the deck
for(x = 0; x < CARD_DECK_SIZE - 1; x++) {
// Select random element from remaining elements.
y = u8randRange(x, CARD_DECK_SIZE);
temporary = poker->deck[y];// Take out other card
poker->deck[y] = poker->deck[x];// Move my card there
poker->deck[x] = temporary;// Put other card here.
}
}

15
src/poker/round/deal.h Normal file
View File

@ -0,0 +1,15 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Resets a poker game for the new round.
* @param poker Poker game to reset to a new round.
*/
void pokerDealInit(poker_t *poker);