Refactoring some of the poker game logic again.

This commit is contained in:
2021-07-27 09:49:54 -07:00
parent 2a4b1fa8da
commit cf4d4cd710
36 changed files with 99 additions and 304 deletions

99
temp/render/card.c Normal file
View File

@ -0,0 +1,99 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "card.h"
void pokerCardInit(poker_t *poker) {
tilesetdiv_t *cardBack;
// Load Cards Texture
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 = poker->cardTileset.divisions+(poker->cardTileset.columns * 4);
primitiveInit(&poker->cardPrimitive,
QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2
);
quadBuffer(&poker->cardPrimitive, -POKER_CARD_DEPTH,
-POKER_CARD_WIDTH, -POKER_CARD_HEIGHT,
cardBack->x0, cardBack->y1,
POKER_CARD_WIDTH, POKER_CARD_HEIGHT,
cardBack->x1, cardBack->y0,
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
);
}
pokerposition_t pokerCardGetPosition(uint8_t seat, uint8_t slot) {
pokerposition_t position;
float t, t2;
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 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 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 * ( POKER_CARD_SLOT_FLOP4-POKER_CARD_SLOT_FLOP0)
)/2 + t2*(slot-POKER_CARD_SLOT_FLOP0);
break;
default:
break;
}
position.x += t2 * sin(t);
position.z += t2 * cos(t);
return position;
}
void pokerCardRender(poker_t *poker, card_t card, float x, float y, float z,
float pitch, float yaw, float roll
) {
tilesetdiv_t *cardFront = poker->cardTileset.divisions + card;
quadBuffer(&poker->cardPrimitive, POKER_CARD_DEPTH,
-POKER_CARD_WIDTH, -POKER_CARD_HEIGHT,
cardFront->x0, cardFront->y1,
POKER_CARD_WIDTH, POKER_CARD_HEIGHT,
cardFront->x1, cardFront->y0,
0, 0
);
shaderUseTexture(&poker->shader, &poker->cardTexture);
shaderUsePosition(&poker->shader, x,y,z, pitch,yaw,roll);
primitiveDraw(&poker->cardPrimitive, 0, -1);
}
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
);
}

55
temp/render/card.h Normal file
View File

@ -0,0 +1,55 @@
/**
* 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.
* @param poker The poker game context.
*/
void pokerCardInit(poker_t *poker);
/**
* Returns the position a card "naturally" sits at for a given seat and slot.
*
* @param seat Seat that the card belongs to
* @param slot Slot within the player/dealers' hand that the card belongs to.
* @return A struct containing X, Z and YAW properties.
*/
pokerposition_t 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).
* @param z Z Position (world space).
* @param pitch Pitch angle.
* @param yaw Yaw angle.
* @param roll Roll angle.
*/
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 pokerCardRenderForSeat(poker_t *poker, uint8_t seat, card_t card, uint8_t slot);

30
temp/render/look.c Normal file
View 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 pokerLookAtPlayer(camera_t *camera, uint8_t seat, float distance) {
float x, z, angle;
angle = POKER_SEAT_ANGLE(seat);
x = sin(angle) * (0.8 + distance);
z = cos(angle) * (0.8 + distance);
cameraLookAt(camera,
x, 0.3, z,
-x, 0.3, -z
);
}
void pokerLookAtHand(camera_t *camera, uint8_t seat) {
float x, z, angle;
angle = POKER_SEAT_ANGLE(seat);
x = sin(angle);
z = cos(angle);
cameraLookAt(camera,
x*0.1, 0.8, z*0.1,
-x*0.5, 0.2, -z*0.5
);
}

26
temp/render/look.h Normal file
View File

@ -0,0 +1,26 @@
/**
* 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 seats' player.
*
* @param camera Camera to adjust.
* @param seat Seat to look at.
* @param distance Distance from the seat to look from. 0 is default.
*/
void pokerLookAtPlayer(camera_t *camera, uint8_t seat, float distance);
/**
* Look at a specific seats' hand.
*
* @param camera Camera to adjust.
* @param seat Seats hand to look at.
*/
void pokerLookAtHand(camera_t *camera, uint8_t seat);

68
temp/render/player.c Normal file
View File

@ -0,0 +1,68 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "player.h"
void pokerPlayerInit(poker_t *poker) {
uint8_t i;
pokerplayer_t *player;
float w, h;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
player = poker->players + i;
assetTextureLoad(&player->bodyTexture, "characters/penny/textures/body.png");
assetTextureLoad(&player->faceTexture, "characters/penny/textures/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
);
}
}
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 = POKER_SEAT_ANGLE(seat);
x = sin(angle) * -1;
z = cos(angle) * -1;
shaderUsePosition(&poker->shader, x,0.34,z, 0,angle,0);
// Render Body
shaderUseTexture(&poker->shader, &player->bodyTexture);
primitiveDraw(&player->bodyPrimitive, 0, -1);
// Render Face
shaderUseTexture(&poker->shader, &player->faceTexture);
primitiveDraw(&player->facePrimitive, 0, -1);
}

34
temp/render/player.h Normal file
View File

@ -0,0 +1,34 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../file/asset.h"
#include "../../display/shader.h"
#include "../../display/primitive.h"
#include "../../display/tileset.h"
#include "../../display/primitives/quad.h"
/**
* Initializes the player renderer.
* @param poker Poker game context.
*/
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 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 pokerPlayerRender(poker_t *poker, pokerplayer_t *player, uint8_t seat);

30
temp/render/world.c Normal file
View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "world.h"
void pokerWorldInit(poker_t *poker) {
// Poker Table
pokerTableInit(&poker->tablePrimitive);
assetTextureLoad(&poker->tableTexture, "pokertable.png");
}
void pokerWorldRender(poker_t *poker) {
// Poker Table
shaderUsePositionAndScale(&poker->shader,
0, -0.01, 0,
0, 0, 0,
3.4, 3.4, 3.4
);
shaderUseTexture(&poker->shader, &poker->tableTexture);
primitiveDraw(&poker->tablePrimitive, 0, -1);
}
void pokerWorldDispose(poker_t *poker) {
textureDispose(&poker->tableTexture);
primitiveDispose(&poker->tablePrimitive);
}

32
temp/render/world.h Normal file
View 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 "../../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 pokerWorldInit(poker_t *poker);
/**
* Renders the world.
* @param poker Poker scene to render.
*/
void pokerWorldRender(poker_t *poker);
/**
* Disposes a poker world.
* @param poker Poker game to cleanup the world for.
*/
void pokerWorldDispose(poker_t *poker);