Putting it all together and testing it.
This commit is contained in:
		@@ -8,6 +8,5 @@ out vec4 FragColor;
 | 
			
		||||
 | 
			
		||||
void main() {
 | 
			
		||||
  vec4 color = texture(u_Text, TexCoord);
 | 
			
		||||
  FragColor = color + vec4(0.25, 0.25, 0.25, 1);
 | 
			
		||||
  // FragColor = vec4(1, 0, 0, 1);
 | 
			
		||||
  FragColor = color + vec4(0.1, 0.1, 0.1, 1);
 | 
			
		||||
}
 | 
			
		||||
@@ -7,9 +7,11 @@
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "../card.h"
 | 
			
		||||
#include "../../display/render.h"
 | 
			
		||||
#include "../../display/spritebatch.h"
 | 
			
		||||
#include "../../display/texture.h"
 | 
			
		||||
#include "../../display/tileset.h"
 | 
			
		||||
#include "../../display/framebuffer.h"
 | 
			
		||||
 | 
			
		||||
/** How many cards a player can hold in their hand */
 | 
			
		||||
#define HOLDEM_PLAYER_HAND 2
 | 
			
		||||
@@ -23,6 +25,13 @@
 | 
			
		||||
/** State for whether or not a player is showing their hand */
 | 
			
		||||
#define HOLDEM_STATE_SHOWING 0x02
 | 
			
		||||
 | 
			
		||||
#define HOLDEM_GAME_FRAME_HEIGHT RENDER_STATE.height
 | 
			
		||||
#define HOLDEM_GAME_FRAME_LEFT_WIDTH RENDER_STATE.width*0.75
 | 
			
		||||
#define HOLDEM_GAME_FRAME_RIGHT_WIDTH (\
 | 
			
		||||
  RENDER_STATE.width - HOLDEM_GAME_FRAME_LEFT_WIDTH\
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** Texas Hold'em Player State */
 | 
			
		||||
typedef struct {
 | 
			
		||||
  /** Cards in the players' hand */
 | 
			
		||||
@@ -39,7 +48,7 @@ typedef struct {
 | 
			
		||||
  uint32_t currentBet;
 | 
			
		||||
} holdemplayer_t;
 | 
			
		||||
 | 
			
		||||
/** Representation of a Texas Hold'em Game State */
 | 
			
		||||
/** Representation of a Texas Hold'em Match State */
 | 
			
		||||
typedef struct {
 | 
			
		||||
  /** Current Card Deck */
 | 
			
		||||
  card_t deck[CARD_DECK_SIZE];
 | 
			
		||||
@@ -60,10 +69,23 @@ typedef struct {
 | 
			
		||||
 | 
			
		||||
  /** Player States */
 | 
			
		||||
  holdemplayer_t players[HOLDEM_PLAYER_COUNT];
 | 
			
		||||
} holdemgame_t;
 | 
			
		||||
} holdemmatch_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  spritebatch_t *batch;
 | 
			
		||||
  holdemmatch_t match;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  primitive_t *cube;
 | 
			
		||||
  texture_t *texture;
 | 
			
		||||
  tileset_t *tileset;
 | 
			
		||||
} holdemrender_t;
 | 
			
		||||
 | 
			
		||||
  /** Game Render Frames */
 | 
			
		||||
  framebuffer_t *frameLeft;
 | 
			
		||||
  framebuffer_t *frameRight;
 | 
			
		||||
  primitive_t *quadLeft;
 | 
			
		||||
  primitive_t *quadRight;
 | 
			
		||||
  camera_t cameraLeft;
 | 
			
		||||
  camera_t cameraRight;
 | 
			
		||||
} holdemgame_t;
 | 
			
		||||
 | 
			
		||||
extern holdemgame_t HOLDEM_GAME_STATE;
 | 
			
		||||
@@ -7,17 +7,17 @@
 | 
			
		||||
 | 
			
		||||
#include "holdem.h"
 | 
			
		||||
 | 
			
		||||
void holdemGameInit(holdemgame_t *game) {
 | 
			
		||||
void holdemMatchInit(holdemmatch_t *match) {
 | 
			
		||||
  uint8_t i;
 | 
			
		||||
  holdemplayer_t *player;
 | 
			
		||||
 | 
			
		||||
  // Set Blinds to nil.
 | 
			
		||||
  game->blindBig = 0;
 | 
			
		||||
  game->blindSmall = 0;
 | 
			
		||||
  match->blindBig = 0;
 | 
			
		||||
  match->blindSmall = 0;
 | 
			
		||||
 | 
			
		||||
  // Reset the players
 | 
			
		||||
  for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
 | 
			
		||||
    player = game->players + i;
 | 
			
		||||
    player = match->players + i;
 | 
			
		||||
 | 
			
		||||
    // Set their state to 0
 | 
			
		||||
    player->state = 0x00;
 | 
			
		||||
@@ -27,23 +27,23 @@ void holdemGameInit(holdemgame_t *game) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemRoundInit(holdemgame_t *game) {
 | 
			
		||||
void holdemRoundInit(holdemmatch_t *match) {
 | 
			
		||||
  uint8_t i;
 | 
			
		||||
  holdemplayer_t *player;
 | 
			
		||||
 | 
			
		||||
  // Refill the deck
 | 
			
		||||
  cardDeckFill(game->deck);
 | 
			
		||||
  game->deckSize = CARD_DECK_SIZE;
 | 
			
		||||
  cardDeckFill(match->deck);
 | 
			
		||||
  match->deckSize = CARD_DECK_SIZE;
 | 
			
		||||
 | 
			
		||||
  // Reset the pot
 | 
			
		||||
  game->pot = 0;
 | 
			
		||||
  match->pot = 0;
 | 
			
		||||
 | 
			
		||||
  // Reset the cards
 | 
			
		||||
  game->cardsFacing = 0;
 | 
			
		||||
  match->cardsFacing = 0;
 | 
			
		||||
  
 | 
			
		||||
  // Reset the players
 | 
			
		||||
  for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
 | 
			
		||||
    player = game->players + i;
 | 
			
		||||
    player = match->players + i;
 | 
			
		||||
 | 
			
		||||
    // Clear Round State(s)
 | 
			
		||||
    player->state &= ~(
 | 
			
		||||
@@ -58,112 +58,43 @@ void holdemRoundInit(holdemgame_t *game) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemDeal(holdemgame_t *game, holdemplayer_t *player) {
 | 
			
		||||
  cardDeal(game->deck, player->cards, game->deckSize, player->cardCount);
 | 
			
		||||
  game->deckSize--;
 | 
			
		||||
void holdemDeal(holdemmatch_t *match, holdemplayer_t *player) {
 | 
			
		||||
  cardDeal(match->deck, player->cards, match->deckSize, player->cardCount);
 | 
			
		||||
  match->deckSize--;
 | 
			
		||||
  player->cardCount++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemDealAll(holdemgame_t *game, uint8_t count) {
 | 
			
		||||
void holdemDealAll(holdemmatch_t *match, uint8_t count) {
 | 
			
		||||
  uint8_t i, j;
 | 
			
		||||
  for(i = 0; i < count; i++) {
 | 
			
		||||
    for(j = 0; j < HOLDEM_PLAYER_COUNT; j++) {
 | 
			
		||||
      holdemDeal(game, game->players + j);
 | 
			
		||||
      holdemDeal(match, match->players + j);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemFlop(holdemgame_t *game) {
 | 
			
		||||
  if(game->cardsFacing >= HOLDEM_DEALER_HAND) return;
 | 
			
		||||
void holdemFlop(holdemmatch_t *match) {
 | 
			
		||||
  if(match->cardsFacing >= HOLDEM_DEALER_HAND) return;
 | 
			
		||||
  uint8_t i, count;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // Burn the card off the top
 | 
			
		||||
  game->deckSize -= 1;
 | 
			
		||||
  match->deckSize -= 1;
 | 
			
		||||
 | 
			
		||||
  // Change count depending on facing
 | 
			
		||||
  count = game->cardsFacing == 0 ? 0x03 : 0x01;
 | 
			
		||||
  count = match->cardsFacing == 0 ? 0x03 : 0x01;
 | 
			
		||||
 | 
			
		||||
  // Deal
 | 
			
		||||
  for(i = 0; i < count; i++) {
 | 
			
		||||
    cardDeal(game->deck, game->cards, game->deckSize, game->cardsFacing);
 | 
			
		||||
    game->deckSize -= 1;
 | 
			
		||||
    game->cardsFacing += 1;
 | 
			
		||||
    cardDeal(match->deck, match->cards, match->deckSize, match->cardsFacing);
 | 
			
		||||
    match->deckSize -= 1;
 | 
			
		||||
    match->cardsFacing += 1;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemRenderInit(holdemrender_t *render) {
 | 
			
		||||
  render->batch = spriteBatchCreate(
 | 
			
		||||
    CARD_DECK_SIZE + (HOLDEM_PLAYER_COUNT * HOLDEM_PLAYER_HAND)
 | 
			
		||||
  );
 | 
			
		||||
  render->texture = assetTextureLoad("cards_normal.png");
 | 
			
		||||
  render->tileset = tilesetCreate(
 | 
			
		||||
    CARD_COUNT_PER_SUIT, 6,
 | 
			
		||||
    render->texture->width, render->texture->height,
 | 
			
		||||
    0, 0, 0, 0
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemRenderCard(holdemrender_t *render, card_t card, bool faceUp, float x, float y, float z) {
 | 
			
		||||
  int32_t i;
 | 
			
		||||
  
 | 
			
		||||
  if(faceUp) {
 | 
			
		||||
    uint8_t suit = card / CARD_COUNT_PER_SUIT;
 | 
			
		||||
    uint8_t num = card % CARD_COUNT_PER_SUIT;
 | 
			
		||||
    i = num + ((
 | 
			
		||||
      suit == 0 ? 2 :
 | 
			
		||||
      suit == 1 ? 3 : 
 | 
			
		||||
      suit == 2 ? 1 :
 | 
			
		||||
      0
 | 
			
		||||
    ) * CARD_COUNT_PER_SUIT);
 | 
			
		||||
  } else {
 | 
			
		||||
    i = 4 * render->tileset->columns;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  tilesetdiv_t *div = render->tileset->divisions + i;
 | 
			
		||||
 | 
			
		||||
  spriteBatchQuad(render->batch, -1,
 | 
			
		||||
    x, y, z,
 | 
			
		||||
    3, 4,
 | 
			
		||||
    div->x0, div->y0, div->x1, div->y1
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemRender(holdemrender_t *render, holdemgame_t *game) {
 | 
			
		||||
  uint8_t i, j;
 | 
			
		||||
  holdemplayer_t *player;
 | 
			
		||||
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, render->texture);
 | 
			
		||||
 | 
			
		||||
  // Flush
 | 
			
		||||
  spriteBatchFlush(render->batch);
 | 
			
		||||
 | 
			
		||||
  // Render Deck
 | 
			
		||||
  for(i = 0; i < game->deckSize; i++) {
 | 
			
		||||
    holdemRenderCard(render, game->deck[i], false, 0, 6, i * 0.05f);
 | 
			
		||||
  }
 | 
			
		||||
  for(i = 0; i < game->cardsFacing; i++) {
 | 
			
		||||
    holdemRenderCard(render, game->cards[i], true, 0, -i*1.5, i * 0.05f);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Render each players's hand
 | 
			
		||||
  for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
 | 
			
		||||
    player = game->players + i;
 | 
			
		||||
 | 
			
		||||
    for(j = 0; j < player->cardCount; j++) {
 | 
			
		||||
      holdemRenderCard(render, player->cards[j], true,
 | 
			
		||||
        4*(i+1), -(j * 1), j * 0.05f
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Draw
 | 
			
		||||
  spriteBatchDraw(render->batch, 0, -1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t holdemBet(holdemgame_t *game, holdemplayer_t *player, uint32_t amount) {
 | 
			
		||||
uint32_t holdemBet(holdemmatch_t *match, holdemplayer_t *player, uint32_t amount) {
 | 
			
		||||
  uint32_t realAmount = mathMin(player->chips, amount);
 | 
			
		||||
  game->pot += realAmount;
 | 
			
		||||
  match->pot += realAmount;
 | 
			
		||||
  player->chips -= realAmount;
 | 
			
		||||
  return realAmount;
 | 
			
		||||
}
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
 * 
 | 
			
		||||
 * @param game Game to initialize.
 | 
			
		||||
 */
 | 
			
		||||
void holdemGameInit(holdemgame_t *game);
 | 
			
		||||
void holdemMatchInit(holdemmatch_t *match);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initializes a Texas Hold'em Round for the first time. Does not affect the
 | 
			
		||||
@@ -28,7 +28,7 @@ void holdemGameInit(holdemgame_t *game);
 | 
			
		||||
 * 
 | 
			
		||||
 * @param game Game's round you want to initialize.
 | 
			
		||||
 */
 | 
			
		||||
void holdemRoundInit(holdemgame_t *game);
 | 
			
		||||
void holdemRoundInit(holdemmatch_t *match);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Deals a card to the given player, does all the follow up.
 | 
			
		||||
@@ -36,7 +36,7 @@ void holdemRoundInit(holdemgame_t *game);
 | 
			
		||||
 * @param game Game who's deck to deal from.
 | 
			
		||||
 * @param player Player to deal into.
 | 
			
		||||
 */
 | 
			
		||||
void holdemDeal(holdemgame_t *game, holdemplayer_t *player);
 | 
			
		||||
void holdemDeal(holdemmatch_t *match, holdemplayer_t *player);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Deal cards to all players.
 | 
			
		||||
@@ -44,35 +44,14 @@ void holdemDeal(holdemgame_t *game, holdemplayer_t *player);
 | 
			
		||||
 * @param game Game and players to deal around.
 | 
			
		||||
 * @param count Count of cards to deal to each player.
 | 
			
		||||
 */
 | 
			
		||||
void holdemDealAll(holdemgame_t *game, uint8_t count);
 | 
			
		||||
void holdemDealAll(holdemmatch_t *match, uint8_t count);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Draw the flop, turn or river
 | 
			
		||||
 * 
 | 
			
		||||
 * @param game Game to flop/turn/river.
 | 
			
		||||
 */
 | 
			
		||||
void holdemFlop(holdemgame_t *game);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initialize the Texas Hold'em Renderer.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param render Renderer to init.
 | 
			
		||||
 */
 | 
			
		||||
void holdemRenderInit(holdemrender_t *render);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Renders a card.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param render Renderer to render against
 | 
			
		||||
 * @param card Card to render.
 | 
			
		||||
 */
 | 
			
		||||
void holdemRenderCard(holdemrender_t *render, card_t card, bool faceUp, float x, float y, float z);
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
 * Render an entire holdem game.
 | 
			
		||||
 */
 | 
			
		||||
void holdemRender(holdemrender_t *render, holdemgame_t *game);
 | 
			
		||||
void holdemFlop(holdemmatch_t *match);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Takes the given bet from a player
 | 
			
		||||
@@ -82,4 +61,4 @@ void holdemRender(holdemrender_t *render, holdemgame_t *game);
 | 
			
		||||
 * @param amount Amount to try and take.
 | 
			
		||||
 * @return The real amount that was taken, chips considered.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t holdemBet(holdemgame_t *game, holdemplayer_t *player, uint32_t amount);
 | 
			
		||||
uint32_t holdemBet(holdemmatch_t *match, holdemplayer_t *player, uint32_t amount);
 | 
			
		||||
							
								
								
									
										88
									
								
								src/card/poker/holdemgame.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								src/card/poker/holdemgame.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright (c) 2021 Dominic Masters
 | 
			
		||||
 * 
 | 
			
		||||
 * This software is released under the MIT License.
 | 
			
		||||
 * https://opensource.org/licenses/MIT
 | 
			
		||||
 */
 | 
			
		||||
#include "holdemgame.h"
 | 
			
		||||
 | 
			
		||||
holdemgame_t HOLDEM_GAME_STATE;
 | 
			
		||||
 | 
			
		||||
void holdemGameInit() {
 | 
			
		||||
  int32_t lWidth, rWidth, height;
 | 
			
		||||
 | 
			
		||||
  // Create the initial 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);
 | 
			
		||||
 | 
			
		||||
  //TESTING
 | 
			
		||||
  HOLDEM_GAME_STATE.cube = cubeCreate(1, 1, 1);
 | 
			
		||||
  HOLDEM_GAME_STATE.texture = assetTextureLoad("bruh.png");
 | 
			
		||||
 | 
			
		||||
  // Prepare match
 | 
			
		||||
  holdemMatchInit(&HOLDEM_GAME_STATE.match);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void holdemGameUpdate() {
 | 
			
		||||
  int32_t lWidth, rWidth, height;
 | 
			
		||||
 | 
			
		||||
  // Resize Frame buffers.
 | 
			
		||||
  lWidth = HOLDEM_GAME_FRAME_LEFT_WIDTH, rWidth = HOLDEM_GAME_FRAME_RIGHT_WIDTH;
 | 
			
		||||
  height = HOLDEM_GAME_FRAME_HEIGHT;
 | 
			
		||||
  if(HOLDEM_GAME_STATE.frameLeft->texture->width != lWidth) {
 | 
			
		||||
    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, 0, lWidth, height, 1, 1, 0, 0);
 | 
			
		||||
    quadBuffer(HOLDEM_GAME_STATE.quadRight, 0, 0, 0, 0, 0, rWidth, height, 1, 1, 0, 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Render things on the left frame buffer
 | 
			
		||||
  frameBufferUse(HOLDEM_GAME_STATE.frameLeft, true);
 | 
			
		||||
  cameraPerspective(&HOLDEM_GAME_STATE.cameraLeft, 45, 
 | 
			
		||||
    ((float)lWidth/height), 0.25f, 100.0f
 | 
			
		||||
  );
 | 
			
		||||
  cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 5, 5, 5, 0, 0, 0);
 | 
			
		||||
  shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft);
 | 
			
		||||
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.texture);
 | 
			
		||||
  shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, TIME_STATE.current, TIME_STATE.current, 0);
 | 
			
		||||
  primitiveDraw(HOLDEM_GAME_STATE.cube, 0, -1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // Render things on the right frame buffer
 | 
			
		||||
  frameBufferUse(HOLDEM_GAME_STATE.frameRight, true);
 | 
			
		||||
  cameraPerspective(&HOLDEM_GAME_STATE.cameraRight, 45, 
 | 
			
		||||
    ((float)rWidth/height), 0.25f, 100.0f
 | 
			
		||||
  );
 | 
			
		||||
  cameraLookAt(&HOLDEM_GAME_STATE.cameraRight, 2, 0, 2, 0, 0, 0);
 | 
			
		||||
  shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraRight);
 | 
			
		||||
  
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.texture);
 | 
			
		||||
  shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, TIME_STATE.current, TIME_STATE.current, 0);
 | 
			
		||||
  primitiveDraw(HOLDEM_GAME_STATE.cube, 0, -1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // Finally, render the frame buffers to the back buffer.
 | 
			
		||||
  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);
 | 
			
		||||
  // L
 | 
			
		||||
  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);
 | 
			
		||||
  // R
 | 
			
		||||
  shaderUsePosition(GAME_STATE.shaderWorld, lWidth, 0, 0, 0, 0, 0);
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.frameRight->texture);
 | 
			
		||||
  primitiveDraw(HOLDEM_GAME_STATE.quadRight, 0, -1);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								src/card/poker/holdemgame.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/card/poker/holdemgame.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
/**
 | 
			
		||||
 * 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 "holdem.h"
 | 
			
		||||
#include "../../display/framebuffer.h"
 | 
			
		||||
#include "../../display/primitive.h"
 | 
			
		||||
#include "../../display/shader.h"
 | 
			
		||||
#include "../../display/camera.h"
 | 
			
		||||
#include "../../display/primitives/cube.h"
 | 
			
		||||
#include "../../display/primitives/quad.h"
 | 
			
		||||
#include "../../file/asset.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void holdemGameInit();
 | 
			
		||||
 | 
			
		||||
void holdemGameUpdate();
 | 
			
		||||
@@ -102,6 +102,8 @@ void primitiveBufferIndices(primitive_t *primitive,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count) {
 | 
			
		||||
  if(count == -1) count = primitive->indiceCount;
 | 
			
		||||
 | 
			
		||||
  // Re-Bind the buffers
 | 
			
		||||
  glBindBuffer(GL_ARRAY_BUFFER, primitive->vertexBuffer);
 | 
			
		||||
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, primitive->indexBuffer);
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,7 @@ void primitiveBufferIndices(primitive_t *primitive,
 | 
			
		||||
 * Draw a primitive. Primitives are drawn by their indices.
 | 
			
		||||
 * @param primitive Primitive to draw.
 | 
			
		||||
 * @param start Start indice (index) to draw.
 | 
			
		||||
 * @param count Count of indices to draw.
 | 
			
		||||
 * @param count Count of indices to draw. Use -1 to draw all.
 | 
			
		||||
 */
 | 
			
		||||
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,8 @@ void renderInit() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void renderFrameStart() {
 | 
			
		||||
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
  // Clear the frame buffer.
 | 
			
		||||
  frameBufferUse(NULL, true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void renderDispose() {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <dawn/dawn.h>
 | 
			
		||||
#include "framebuffer.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initialize the renderer.
 | 
			
		||||
 
 | 
			
		||||
@@ -46,6 +46,18 @@ void shaderUseCamera(shader_t *shader, camera_t *camera);
 | 
			
		||||
 */
 | 
			
		||||
void shaderUseTexture(shader_t *shader, texture_t *texture);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set's the current translation matrix onto the shader for the next
 | 
			
		||||
 * render to use.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param shader Shader to attach to.
 | 
			
		||||
 * @param x X coordinate (world space).
 | 
			
		||||
 * @param y Y coordinate (world space).
 | 
			
		||||
 * @param z Z coordinate (world space).
 | 
			
		||||
 * @param pitch Pitch of the object (local space).
 | 
			
		||||
 * @param yaw Yaw of the object (local space).
 | 
			
		||||
 * @param roll Roll of the object (local space).
 | 
			
		||||
 */
 | 
			
		||||
void shaderUsePosition(shader_t *shader,
 | 
			
		||||
  float x, float y, float z,
 | 
			
		||||
  float pitch, float yaw, float roll
 | 
			
		||||
 
 | 
			
		||||
@@ -46,15 +46,17 @@ tileset_t * tilesetCreate(
 | 
			
		||||
        borderX + (tileset->divX * x) + (gapX * x)
 | 
			
		||||
      ) / width;
 | 
			
		||||
      tileset->divisions[i].x1 = tileset->divisions[i].x0 + tdivX;
 | 
			
		||||
 | 
			
		||||
      // tileset->divisions[i].y0 = (borderY + (divY * y) + (gapY * y)) / height;
 | 
			
		||||
      // tileset->divisions[i].y1 = tileset->divisions[i].y0 + tdivY;
 | 
			
		||||
 | 
			
		||||
      // Vertically flipped for OpenGL
 | 
			
		||||
      tileset->divisions[i].y1 = (
 | 
			
		||||
      
 | 
			
		||||
      tileset->divisions[i].y0 = (
 | 
			
		||||
        borderY + (tileset->divY * y) + (gapY * y)
 | 
			
		||||
      ) / height;
 | 
			
		||||
      tileset->divisions[i].y0 = tileset->divisions[i].y1 + tdivY;
 | 
			
		||||
      tileset->divisions[i].y1 = tileset->divisions[i].y0 + tdivY;
 | 
			
		||||
 | 
			
		||||
      // Vertically flipped if necessary
 | 
			
		||||
      // tileset->divisions[i].y1 = (
 | 
			
		||||
      //   borderY + (tileset->divY * y) + (gapY * y)
 | 
			
		||||
      // ) / height;
 | 
			
		||||
      // tileset->divisions[i].y0 = tileset->divisions[i].y1 + tdivY;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,6 @@
 | 
			
		||||
 | 
			
		||||
game_t GAME_STATE;
 | 
			
		||||
 | 
			
		||||
primitive_t *prim;
 | 
			
		||||
framebuffer_t *fbo;
 | 
			
		||||
texture_t *text;
 | 
			
		||||
 | 
			
		||||
bool gameInit() {
 | 
			
		||||
  // Init the game
 | 
			
		||||
  GAME_STATE.name = GAME_NAME;
 | 
			
		||||
@@ -21,18 +17,15 @@ bool gameInit() {
 | 
			
		||||
  gameTimeInit();
 | 
			
		||||
  renderInit();
 | 
			
		||||
  inputInit();
 | 
			
		||||
  worldInit();
 | 
			
		||||
 | 
			
		||||
  prim = cubeCreate(1, 1, 1);
 | 
			
		||||
  text = assetTextureLoad("bruh.png");
 | 
			
		||||
 | 
			
		||||
  fbo = frameBufferCreate(128, 128);
 | 
			
		||||
 | 
			
		||||
  // Load the world shader.
 | 
			
		||||
  GAME_STATE.shaderWorld = assetShaderLoad(
 | 
			
		||||
    "shaders/textured.vert", "shaders/textured.frag"
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Send to Texas Game
 | 
			
		||||
  holdemGameInit();
 | 
			
		||||
 | 
			
		||||
  // Init the input manger.
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
@@ -42,27 +35,8 @@ bool gameUpdate(float platformDelta) {
 | 
			
		||||
  renderFrameStart();
 | 
			
		||||
  inputUpdate();
 | 
			
		||||
 | 
			
		||||
  // Set up the camera and shader.
 | 
			
		||||
  shaderUse(GAME_STATE.shaderWorld);
 | 
			
		||||
  frameBufferUse(fbo, true);
 | 
			
		||||
  cameraLookAt(&GAME_STATE.cameraWorld, 2, 2, 2, 0, 0, 0);
 | 
			
		||||
  cameraPerspective(&GAME_STATE.cameraWorld, 45.0f,
 | 
			
		||||
    ((float)fbo->texture->width) / ((float)fbo->texture->height),
 | 
			
		||||
    0.5f, 500.0f
 | 
			
		||||
  );
 | 
			
		||||
  shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld);
 | 
			
		||||
  shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, TIME_STATE.current, TIME_STATE.current, 0);
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, text);
 | 
			
		||||
  primitiveDraw(prim, 0, prim->indiceCount);
 | 
			
		||||
 | 
			
		||||
  frameBufferUse(NULL, true);
 | 
			
		||||
  shaderUseTexture(GAME_STATE.shaderWorld, fbo->texture);
 | 
			
		||||
  cameraPerspective(&GAME_STATE.cameraWorld, 45.0f,
 | 
			
		||||
    ((float)RENDER_STATE.width) / ((float)RENDER_STATE.height),
 | 
			
		||||
    0.5f, 500.0f
 | 
			
		||||
  );
 | 
			
		||||
  shaderUseCamera(GAME_STATE.shaderWorld, &GAME_STATE.cameraWorld);
 | 
			
		||||
  primitiveDraw(prim, 0, prim->indiceCount);
 | 
			
		||||
  shaderUse(GAME_STATE.shaderWorld);// TODO: remove
 | 
			
		||||
  holdemGameUpdate();
 | 
			
		||||
 | 
			
		||||
  if(inputIsPressed(INPUT_NULL)) return false;
 | 
			
		||||
  return true;
 | 
			
		||||
 
 | 
			
		||||
@@ -11,11 +11,7 @@
 | 
			
		||||
#include "../display/shader.h"
 | 
			
		||||
#include "../file/asset.h"
 | 
			
		||||
#include "../input/input.h"
 | 
			
		||||
 | 
			
		||||
#include "../display/primitive.h"
 | 
			
		||||
#include "../display/framebuffer.h"
 | 
			
		||||
#include "../display/primitives/cube.h"
 | 
			
		||||
#include "../display/primitives/quad.h"
 | 
			
		||||
#include "../card/poker/holdemgame.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initialize the game context.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user