Even more refactoring

This commit is contained in:
2021-09-19 20:50:35 -07:00
parent 3ed24da3b6
commit e87e04decf
22 changed files with 120 additions and 114 deletions

View File

@ -51,7 +51,7 @@ void renderListRenderPass(
item->onRender(list, renderPass, engine, i);
}
frameBufferUnbind(&engine->render, false);
frameBufferUnbind(engine->render.width, engine->render.height, false);
}
void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) {
@ -79,5 +79,5 @@ void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) {
}
// Unbind the framebuffer.
frameBufferUnbind(&engine->render, false);
frameBufferUnbind(engine->render.width, engine->render.height, false);
}

View File

@ -7,11 +7,11 @@
#pragma once
#include "../libs.h"
#include "../game/game.h"
#include "framebuffer.h"
#include "primitive.h"
#include "shader.h"
#include "camera.h"
#include "../engine/engine.h"
#include "primitives/quad.h"
#include "../util/dynarray.h"

View File

@ -10,7 +10,7 @@
#include "../game.h"
typedef struct {
int32_t INeedSomePropertyToStopCompilerComplaining;
engine_t engine;
} dawngame_t;
/**

View File

@ -8,28 +8,18 @@
#include "../engine/engine.h"
#include "../locale/language.h"
/** Describes the current game */
#if SETTING_GAME == SETTING_GAME_POKER
#include "poker/pokergame.h"
typedef pokergame_t game_t;
#elif SETTING_GAME == SETTING_GAME_DAWN
#include "dawn/dawngame.h"
typedef dawngame_t game_t;
#elif SETTING_GAME == SETTING_GAME_SANDBOX
#include "sandbox/sandboxscene.h"
typedef sandboxscene_t game_t;
#endif
/** Describes the current game */
typedef struct {
/** Engine for the game */
engine_t engine;
#if SETTING_GAME == SETTING_GAME_POKER
pokergame_t pokerGame;
#elif SETTING_GAME == SETTING_GAME_DAWN
dawngame_t dawnGame;
#elif SETTING_GAME == SETTING_GAME_SANDBOX
sandboxscene_t sandboxScene;
#endif
} game_t;
/**
* Initialize the game context.
*

View File

@ -6,8 +6,8 @@
*/
#pragma once
#include "../../../libs.h"
#include "action.h"
#include "../../../libs.h"
#include "../../../display/animation/queue.h"
#include "../pokerworld.h"

View File

@ -10,9 +10,7 @@
#include "../../../vn/conversation/talk.h"
#include "../../../display/animation/queue.h"
#include "../../../poker/actions/match.h"
#include "../discussion/pokerdiscussion.h"
#include "action.h"
#include "round.h"
/** Callback fired when the game action first starts */
void _pokerGameActionStartOnStart(

View File

@ -12,10 +12,9 @@
#include "../../vn/conversation/talk.h"
#include "../../vn/vnscene.h"
#include "../../util/array.h"
#include "actions/start.h"
#include "ui/pokerui.h"
#include "pokerworld.h"
#include "actions/start.h"
#include "pokergameaction.h"
#define POKER_GAME_SEAT_COUNT 8
#define POKER_GAME_SEAT_FOR_PLAYER(p) (p - (POKER_PLAYER_COUNT/2))
@ -40,6 +39,9 @@
#define POKER_GAME_PENNY_FACE_HEIGHT 280
typedef struct {
/** Game Engine Instance */
engine_t engine;
/** Poker Game State */
poker_t poker;
@ -57,9 +59,6 @@ typedef struct {
/** Data for the actions */
pokergameactiondata_t actionData[ANIMATION_QUEUE_ITEM_MAX];
/** Pointer back to the game engine */
engine_t *engine;
} pokergame_t;
/**

View File

@ -6,7 +6,7 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
typedef struct {
uint8_t lookAtPlayer;

View File

@ -12,6 +12,8 @@
#include "../../display/primitives/skywall.h"
#include "../../vn/vnscene.h"
#include "../../vn/vncharacter.h"
#include "pokergame.h"
#include "pokergameassets.h"
#define POKER_WORLD_SEAT_DISTANCE -1
#define POKER_WORLD_SEAT_ROTATION(n) (n * mathDeg2Rad(45.0f))

View File

@ -13,10 +13,13 @@
#include "../../../display/primitive.h"
#include "../../../display/primitives/quad.h"
#include "../../../display/primitives/cube.h"
#include "../../../display/shader.h"
#include "../../../engine/engine.h"
#include "../../../display/camera.h"
#include "../../../vn/vncharacter.h"
#include "../../../ui/grid.h"
#include "../../../ui/align.h"
#include "../pokergame.h"
#define POKER_PLAYER_UI_IMAGE_SIZE 64
#define POKER_PLAYER_UI_WIDTH 300

View File

@ -10,6 +10,7 @@
#include "../../../ui/label.h"
#include "pokerplayerui.h"
#include "pokercardui.h"
#include "../pokergame.h"
typedef struct {
pokerplayerui_t player[POKER_PLAYER_COUNT];

View File

@ -7,9 +7,7 @@
#include "sandboxscene.h"
scripter_t scripter;
bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine) {
bool sandboxSceneInit(sandboxscene_t *game) {
assetFontLoad(&game->font, "fonts/opensans/OpenSans-Regular.ttf");
assetTextureLoad(&game->texture, "test_texture.png");
assetShaderLoad(&game->shader,
@ -19,11 +17,11 @@ bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine) {
return true;
}
void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine) {
void sandboxSceneUpdate(sandboxscene_t *game) {
cameraLookAt(&game->camera, 3,3,3, 0,0,0);
cameraPerspective(&game->camera, 45,
engine->render.width/engine->render.height,
game->engine.render.width/game->engine.render.height,
0.01f, 1000.0f
);

View File

@ -27,6 +27,7 @@
#include "../../ui/framedtextmenu.h"
typedef struct {
engine_t engine;
camera_t camera;
primitive_t primitive;
@ -42,7 +43,7 @@ typedef struct {
* @param engine Engine to use during init.
* @return True if successful, otherwise false.
*/
bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine);
bool sandboxSceneInit(sandboxscene_t *game);
/**
* Update a sandbox scene.
@ -50,7 +51,7 @@ bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine);
* @param game Game to update.
* @param engine Engine to use when updating.
*/
void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine);
void sandboxSceneUpdate(sandboxscene_t *game);
/**
* Dispose a previously created scene game.

View File

@ -17,21 +17,27 @@ void pokerBetReset(pokerbet_t *bet) {
bet->currentBet = 0;
}
void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips) {
poker->bet.pot += chips;
player->chips -= chips;
player->currentBet += chips;
poker->bet.currentBet = mathMax(poker->bet.currentBet, player->currentBet);
uint8_t pokerBetGetRoundPlayerDefault(uint8_t roundSmallBlind) {
return (roundSmallBlind + 1) % POKER_PLAYER_COUNT;
}
void pokerBetResetBetter(poker_t *poker) {
void pokerBetPlayer(pokerbet_t *bet, pokerplayer_t *player, int32_t chips) {
bet->pot += chips;
player->chips -= chips;
player->currentBet += chips;
bet->currentBet = mathMax(bet->currentBet, player->currentBet);
}
void pokerBetResetBetter(
pokerbet_t *poker, pokerplayer_t *players, uint8_t roundSmallBlind
) {
uint8_t i;
pokerplayer_t *player;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
player = poker->players + i;
player = players + i;
player->state = flagOff(player->state, POKER_PLAYER_STATE_ROUND_MOVE);
}
poker->bet.better = POKER_BET_ROUND_PLAYER_DEFAULT(poker);
bet->better = pokerBetGetRoundPlayerDefault(roundSmallBlind);
}
bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player) {
@ -43,22 +49,24 @@ bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player) {
return true;
}
uint8_t pokerBetGetRemainingPlayer(poker_t *poker) {
uint8_t pokerBetGetRemainingPlayer(
pokerbet_t *bet, pokerplayer_t *players, uint8_t roundSmallBlind
) {
uint8_t def, j, pi;
def = POKER_BET_ROUND_PLAYER_DEFAULT(poker);
def = pokerBetGetRoundPlayerDefault(roundSmallBlind);
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
pi = ((def + j) % POKER_PLAYER_COUNT);
if(!pokerBetPlayerCanBet(&poker->bet, poker->players + pi)) continue;
if(!pokerBetPlayerCanBet(bet, players + pi)) continue;
return pi;
}
return 0xFF;
}
void pokerBetTakeBlinds(poker_t *poker) {
pokerBetPlayer(poker, poker->players + poker->roundSmallBlind,
poker->bet.blindSmall
);
pokerBetPlayer(poker, poker->players + poker->roundBigBlind,
poker->bet.blindBig
);
void pokerBetTakeBlinds(
pokerbet_t *bet, pokerplayer_t *players,
uint8_t roundSmallBlind, uint8_t roundBigBlind,
int32_t blindSmall, int32_t blindBig
) {
pokerBetPlayer(bet, players + roundSmallBlind, blindSmall);
pokerBetPlayer(bet, players + roundBigBlind, blindBig);
}

View File

@ -5,6 +5,7 @@
#pragma once
#include "../libs.h"
#include "player.h"
/** How many chips each player has by defautl */
#define POKER_BET_PLAYER_CHIPS_DEFAULT 10000
@ -15,16 +16,6 @@
/** The default blind cost for the small blind. (Defaults half big blind) */
#define POKER_BET_BLIND_SMALL_DEFAULT (POKER_BET_BLIND_BIG_DEFAULT/2)
/**
* The default betting player for the round.
*
* @param poker Pointer to the poker instance.
* @return The Poker round default betting player.
*/
#define POKER_BET_ROUND_PLAYER_DEFAULT(poker) ( \
((poker)->roundSmallBlind + 1) % POKER_PLAYER_COUNT \
)
typedef struct {
/** Blinds */
int32_t blindSmall, blindBig;
@ -53,22 +44,34 @@ void pokerBetInit(pokerbet_t *bet);
*/
void pokerBetReset(pokerbet_t *bet);
/**
* The default betting player for the round.
*
* @param roundSmallBlind Current round small blind player index.
* @return The Poker round default betting player index.
*/
uint8_t pokerBetGetRoundPlayerDefault(uint8_t roundSmallBlind);
/**
* Let a player bet chips into the pot.
*
* @param poker Poker game instance.
* @param bet Poker bet instance.
* @param player Poker player instance.
* @param chips Chips to bet.
*/
void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips);
void pokerBetPlayer(pokerbet_t *bet, pokerplayer_t *player, int32_t chips);
/**
* Reset the current better back to the round/turns default. The better will
* always be the player to the right of the small blind player.
*
* @param poker Poker game to update for.
* @param bet Poker betting structure.
* @param player Array of poker players.
* @param roundSmallBlind Current round small blind player index.
*/
void pokerBetResetBetter(poker_t *poker);
void pokerBetResetBetter(
pokerbet_t *poker, pokerplayer_t *players, uint8_t roundSmallBlind
);
/**
* Returns whether or not a player can bet for the current round.
@ -83,14 +86,22 @@ bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player);
* Returns the index of the first player that remains to bet for the current
* round.
*
* @param poker Poker instance to fetch from.
* @param bet Poker betting structure.
* @param player Array of poker players.
* @param roundSmallBlind Current round small blind player index.
* @return The player index of the remaining player, otherwise 0xFF.
*/
uint8_t pokerBetGetRemainingPlayer(poker_t *poker);
uint8_t pokerBetGetRemainingPlayer(
pokerbet_t *bet, pokerplayer_t *players, uint8_t roundSmallBlind
);
/**
* Takes the current blinds from the correct players.
*
* @param poker Poker game to take the blinds from.
*/
void pokerBetTakeBlinds(poker_t *poker);
void pokerBetTakeBlinds(
pokerbet_t *bet, pokerplayer_t *players,
uint8_t roundSmallBlind, uint8_t roundBigBlind,
int32_t blindSmall, int32_t blindBig
);

View File

@ -39,15 +39,17 @@ void pokerDealerDeal(pokerdealer_t *dealer, pokerplayer_t *player) {
cardDeal(dealer->deck, &dealer->deckSize, player->cards, &player->cardCount);
}
void pokerDealerDealAll(poker_t *poker, uint8_t count) {
void pokerDealerDealAll(
pokerdealer_t *dealer, pokerplayer_t *players, uint8_t count
) {
uint8_t x, y;
pokerplayer_t *player;
for(y = 0; y < count; y++) {
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
player = poker->players + x;
player = players + x;
if(!pokerPlayerIsAlive(player)) continue;
pokerDealerDeal(&poker->dealer, player);
pokerDealerDeal(dealer, player);
}
}
}

View File

@ -5,7 +5,6 @@
#pragma once
#include "../libs.h"
#include "poker.h"
#include "card.h"
#include "player.h"
@ -68,7 +67,10 @@ void pokerDealerDeal(pokerdealer_t *dealer, pokerplayer_t *player);
/**
* Deal card(s) to every active player.
*
* @param poker Poker game instance.
* @param dealer Poker dealer instance.
* @param players Array of poker players.
* @param count Count of cards to deal.
*/
void pokerDealerDealAll(poker_t *poker, uint8_t count);
void pokerDealerDealAll(
pokerdealer_t *dealer, pokerplayer_t *players, uint8_t count
);

View File

@ -11,10 +11,6 @@ bool pokerPlayerIsAlive(pokerplayer_t *player) {
return !(player->state & (POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT));
}
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) {
return (poker->players + POKER_PLAYER_HUMAN_INDEX) == player;
}
void pokerPlayerReset(pokerplayer_t *player) {
player->cardCount = 0;
player->currentBet = 0;

View File

@ -7,8 +7,8 @@
#pragma once
#include "../libs.h"
#include "../util/flags.h"
#include "card.h"
#include "poker.h"
/** How many cards a player can hold in their hand */
#define POKER_PLAYER_HAND 2
@ -64,15 +64,6 @@ typedef struct {
*/
bool pokerPlayerIsAlive(pokerplayer_t *player);
/**
* Returns true if the player provided is human or not.
*
* @param poker Poker game instance.
* @param player Player instance.
* @returns True if the player is human.
*/
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player);
/**
* Resets a poker player's state (for a new round).
*

View File

@ -7,27 +7,27 @@
#include "winner.h"
void pokerWinnerHandGetFull(poker_t *poker, pokerplayer_t *player,
card_t *cards
void pokerWinnerHandGetFull(
pokerdealer_t *dealer, pokerplayer_t *player, card_t *cards
) {
uint8_t i;
// Add the dealer hand
for(i = 0; i < poker->dealer.cardsFacing; i++) {
cards[i] = poker->dealer.cards[i];
for(i = 0; i < dealer->cardsFacing; i++) {
cards[i] = dealer->cards[i];
}
// Add the player hand
for(i = 0; i < player->cardCount; i++) {
cards[i+poker->dealer.cardsFacing] = player->cards[i];
cards[i+dealer->cardsFacing] = player->cards[i];
}
// Sort by card value
cardHandSort(cards, poker->dealer.cardsFacing + player->cardCount);
cardHandSort(cards, dealer->cardsFacing + player->cardCount);
}
void pokerWinnerPlayerGet(
poker_t *poker, pokerplayer_t *player, pokerplayerwinning_t *winning
pokerdealer_t *dealer, pokerplayer_t *player, pokerplayerwinning_t *winning
) {
uint8_t i, j, l;
int32_t index;
@ -36,8 +36,8 @@ void pokerWinnerPlayerGet(
int32_t pairs[CARD_SUIT_COUNT];
// Get the full poker hand (should be a 7 card hand, but MAY not be)
winning->fullSize = poker->dealer.cardsFacing + player->cardCount;
pokerWinnerHandGetFull(poker, player, winning->full);
winning->fullSize = dealer->cardsFacing + player->cardCount;
pokerWinnerHandGetFull(dealer, player, winning->full);
// Reset the winning status.
winning->setSize = 0;
@ -284,26 +284,26 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ
return highCardLeft;//Greater or Equal to.
}
void pokerWinnerCalculate(poker_t *poker) {
void pokerWinnerCalculate(
pokerwinner_t *winner, pokerdealer_t *dealer, pokerplayer_t *players
) {
uint8_t i, j, number, highNumber;
pokerwinner_t *winner;
pokerplayerwinning_t *left, *right;
pokerplayer_t *player;
card_t card, highCard;
bool isWinner;
winner = &poker->winner;
winner->winnerCount = 0;
// Get winning sets
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
left = winner->winnings + i;
left->type = POKER_WINNING_TYPE_NULL;
player = poker->players + i;
player = players + i;
if(!pokerPlayerIsAlive(player)) continue;
// Get the players' winning state.
pokerWinnerPlayerGet(poker, player, left);
pokerWinnerPlayerGet(dealer, player, left);
}
// Compare against each player

View File

@ -10,7 +10,7 @@
#include "card.h"
#include "player.h"
#include "winner.h"
#include "poker.h"
#include "dealer.h"
/** Size of the FULL hand used to calculate a winning. */
#define POKER_WINNING_FULL_SIZE POKER_PLAYER_HAND+POKER_DEALER_HAND_SIZE
@ -59,24 +59,24 @@ typedef struct {
* Returns the full hand for a given player including the best cards on the
* bench.
*
* @param poker Poker game instance.
* @param dealer Poker game dealer instance.
* @param player Poker player game instance.
* @param cards Array of at least 7 length to store the array.
*/
void pokerWinnerHandGetFull(poker_t *poker, pokerplayer_t *player,
card_t *cards
void pokerWinnerHandGetFull(
pokerdealer_t *dealer, pokerplayer_t *player, card_t *cards
);
/**
* Calculates and returns the winning state for a given player
*
* @param poker Poker game instance.
* @param player Player game instance.
* @param dealer Poker game dealer instance.
* @param players Array of poker players.
* @param winning Pointer to the poker winning to fill out.
* @return The winning state for this player.
*/
void pokerWinnerPlayerGet(
poker_t *poker, pokerplayer_t *player, pokerplayerwinning_t *winning
pokerdealer_t *dealer, pokerplayer_t *player, pokerplayerwinning_t *winning
);
/**
@ -102,6 +102,10 @@ card_t pokerWinnerCompare(
* Determines the winning player for the game. Values will be stored back into
* the poker winning state.
*
* @param poker Poker game instance.
* @param winner Location to store the winner state.
* @param dealer Poker game dealer instance.
* @param players Array of poker players.
*/
void pokerWinnerCalculate(poker_t *poker);
void pokerWinnerCalculate(
pokerwinner_t *winner, pokerdealer_t *dealer, pokerplayer_t *players
);