Cleaned some of the repo
This commit is contained in:
@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "action.h"
|
||||
|
||||
void pokerActionInit() {
|
||||
// Free up all actions
|
||||
memset(GAME_STATE.actionQueue, (int32_t)NULL,
|
||||
sizeof(pokeraction_t) * POKER_ACTION_QUEUE_SIZE
|
||||
);
|
||||
|
||||
// Free up all data
|
||||
memset(GAME_STATE.actionData, (int32_t)NULL, sizeof(void *) *
|
||||
POKER_ACTION_DATA_SIZE * POKER_ACTION_QUEUE_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
int32_t pokerActionAdd(pokeraction_t action) {
|
||||
int32_t i = -1;
|
||||
int32_t j = -1;
|
||||
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
if(GAME_STATE.actionQueue[i].init != NULL) continue;
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
if(j == -1) return j;
|
||||
|
||||
GAME_STATE.actionQueue[j] = action;
|
||||
GAME_STATE.actionInitState[j] = false;
|
||||
return j;
|
||||
}
|
||||
|
||||
void pokerActionRemove(int32_t index) {
|
||||
if(GAME_STATE.actionQueue[index].dispose != NULL) {
|
||||
GAME_STATE.actionQueue[index].dispose(
|
||||
index, GAME_STATE.actionData + index
|
||||
);
|
||||
}
|
||||
|
||||
memset(GAME_STATE.actionQueue+index, (int32_t)NULL,
|
||||
sizeof(pokeraction_t)
|
||||
);
|
||||
|
||||
memset(GAME_STATE.actionData+index, (int32_t)NULL,
|
||||
sizeof(void *) * POKER_ACTION_DATA_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
void pokerActionUpdate() {
|
||||
int32_t i;
|
||||
void **data;
|
||||
pokeraction_t *action;
|
||||
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
action = GAME_STATE.actionQueue + i;
|
||||
data = GAME_STATE.actionData + i;
|
||||
|
||||
if(action->init != NULL && !GAME_STATE.actionInitState[i]) {
|
||||
GAME_STATE.actionInitState[i] = true;
|
||||
action->init(i, data);
|
||||
}
|
||||
|
||||
if(action->update != NULL) {
|
||||
action->update(i, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pokerActionDispose() {
|
||||
int32_t i;
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
if(GAME_STATE.actionQueue[i].dispose == NULL) continue;
|
||||
GAME_STATE.actionQueue[i].dispose(i, GAME_STATE.actionData+i);
|
||||
}
|
||||
}
|
@ -1,40 +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>
|
||||
|
||||
/**
|
||||
* Initializes the action manager.
|
||||
*/
|
||||
void pokerActionInit();
|
||||
|
||||
/**
|
||||
* Adds an action to the action queue.
|
||||
*
|
||||
* @param action Action to add to the queue.
|
||||
* @returns The index of the action within the queue, or -1 if failure occured.
|
||||
*/
|
||||
int32_t pokerActionAdd(pokeraction_t action);
|
||||
|
||||
/**
|
||||
* Removes an action from the action queue.
|
||||
*
|
||||
* @param index Action to remove (by index in the queue).
|
||||
*/
|
||||
void pokerActionRemove(int32_t index);
|
||||
|
||||
/**
|
||||
* Updates the action manager, which (in turn) updates all actions that are
|
||||
* currently running.
|
||||
*/
|
||||
void pokerActionUpdate();
|
||||
|
||||
/**
|
||||
* Cleans up the action manager and all actions.
|
||||
*/
|
||||
void pokerActionDispose();
|
@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "ai.h"
|
||||
|
||||
pokeraction_t actionAi() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionAiInit,
|
||||
.update = &actionAiUpdate,
|
||||
.dispose = &actionAiDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionAiInit(int32_t index, void *data) {
|
||||
logText("AI Round start");
|
||||
|
||||
/*
|
||||
Current theory for the AI code will be;
|
||||
1 - Determine weight of my cards+flop as %
|
||||
2 - Determine current bet, compare against [something] and then determine if
|
||||
worth the risk. I may need history of the game to make informed decision
|
||||
*/
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionAiUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionAiDispose(int32_t index, void *data) {
|
||||
// Do we need to do a flop?
|
||||
if(GAME_STATE.cardsFacing < POKER_DEALER_HAND) {
|
||||
pokerActionAdd(actionFlop());
|
||||
}
|
||||
}
|
@ -1,22 +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 "action.h"
|
||||
#include "flop.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
typdef struct {
|
||||
uint8_t player;
|
||||
} actionaidata_t;
|
||||
|
||||
pokeraction_t actionAi();
|
||||
|
||||
void actionAiInit(int32_t index, void *data);
|
||||
void actionAiUpdate(int32_t index, void *data);
|
||||
void actionAiDispose(int32_t index, void *data);
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "deal.h"
|
||||
|
||||
pokeraction_t actionDeal() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionDealInit,
|
||||
.update = &actionDealUpdate,
|
||||
.dispose = &actionDealDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionDealInit(int32_t index, void *data) {
|
||||
uint8_t i, j;
|
||||
pokerplayer_t *player;
|
||||
logText("Dealing Cards");
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
|
||||
player = GAME_STATE.players + j;
|
||||
cardDeal(GAME_STATE.deck,
|
||||
player->cards,
|
||||
GAME_STATE.deckSize,
|
||||
player->cardCount
|
||||
);
|
||||
GAME_STATE.deckSize--;
|
||||
player->cardCount++;
|
||||
}
|
||||
}
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionDealUpdate(int32_t i, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionDealDispose(int32_t i, void *data) {
|
||||
int32_t newI = pokerActionAdd(actionAi());
|
||||
}
|
@ -1,18 +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 "../../debug/log.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
|
||||
pokeraction_t actionDeal();
|
||||
|
||||
void actionDealInit(int32_t i, void *data);
|
||||
void actionDealUpdate(int32_t i, void *data);
|
||||
void actionDealDispose(int32_t i, void *data);
|
@ -1,50 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "flop.h"
|
||||
|
||||
pokeraction_t actionFlop() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionFlopInit,
|
||||
.update = &actionFlopUpdate,
|
||||
.dispose = &actionFlopDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionFlopInit(int32_t index, void *data) {
|
||||
uint8_t i, count;
|
||||
logText("Flop");
|
||||
|
||||
// Look at the dealer
|
||||
|
||||
// Do the flop
|
||||
// if(match->cardsFacing >= HOLDEM_DEALER_HAND) return;
|
||||
|
||||
// Burn the card off the top
|
||||
GAME_STATE.deckSize -= 1;
|
||||
|
||||
// Change count depending on facing
|
||||
count = GAME_STATE.cardsFacing == 0 ? 0x03 : 0x01;
|
||||
|
||||
// Deal
|
||||
for(i = 0; i < count; i++) {
|
||||
cardDeal(GAME_STATE.deck, GAME_STATE.cards, GAME_STATE.deckSize, GAME_STATE.cardsFacing);
|
||||
GAME_STATE.deckSize -= 1;
|
||||
GAME_STATE.cardsFacing += 1;
|
||||
}
|
||||
|
||||
// Next action
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionFlopUpdate(int32_t index, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionFlopDispose(int32_t index, void *data) {
|
||||
pokerActionAdd(actionAi());
|
||||
}
|
@ -1,19 +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 "../../debug/log.h"
|
||||
#include "../render/look.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
|
||||
pokeraction_t actionFlop();
|
||||
|
||||
void actionFlopInit(int32_t index, void *data);
|
||||
void actionFlopUpdate(int32_t index, void *data);
|
||||
void actionFlopDispose(int32_t index, void *data);
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "round.h"
|
||||
|
||||
pokeraction_t actionRound() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionRoundInit,
|
||||
.update = &actionRoundUpdate,
|
||||
.dispose = &actionRoundDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionRoundInit(int32_t index, void *data) {
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
|
||||
logText("Round Start");
|
||||
|
||||
// Look at the dealer.
|
||||
holdemRenderLookHand(&GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_PLAYER0);
|
||||
|
||||
// Init the round and shuffle the deck
|
||||
cardDeckFill(GAME_STATE.deck);
|
||||
GAME_STATE.deckSize = CARD_DECK_SIZE;
|
||||
GAME_STATE.pot = 0;
|
||||
GAME_STATE.cardsFacing = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = GAME_STATE.players + i;
|
||||
|
||||
// Clear Round State(s)
|
||||
player->state &= ~(
|
||||
POKER_PLAYER_STATE_FOLDED |
|
||||
POKER_PLAYER_STATE_SHOWING
|
||||
);
|
||||
|
||||
player->cardCount = 0;
|
||||
player->currentBet = 0;
|
||||
|
||||
player->chips = 1000;
|
||||
player->currentBet = 1000;
|
||||
}
|
||||
|
||||
// Next action
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionRoundUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionRoundAfterShuffle() {
|
||||
logText("Shuffle Done");
|
||||
int32_t i = pokerActionAdd(actionDeal());
|
||||
}
|
||||
|
||||
void actionRoundDispose(int32_t index, void *data) {
|
||||
int32_t newI = pokerActionAdd(actionShuffle());
|
||||
shuffledata_t *newData=(shuffledata_t *)(GAME_STATE.actionData + newI);
|
||||
newData->done = &actionRoundAfterShuffle;
|
||||
}
|
@ -1,23 +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 "../render/look.h"
|
||||
#include "../../debug/log.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
#include "shuffle.h"
|
||||
#include "deal.h"
|
||||
|
||||
pokeraction_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();
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "shuffle.h"
|
||||
|
||||
pokeraction_t actionShuffle() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionShuffleInit,
|
||||
.update = &actionShuffleUpdate,
|
||||
.dispose = &actionShuffleDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data) {
|
||||
logText("Shuffle Deck");
|
||||
cardShuffle(GAME_STATE.deck, GAME_STATE.deckSize);
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionShuffleUpdate(int32_t index, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionShuffleDispose(int32_t index, void *data) {
|
||||
if(((shuffledata_t *)data) != NULL) ((shuffledata_t *)data)->done();
|
||||
}
|
@ -1,23 +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 "action.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
typedef struct {
|
||||
void (*done)();
|
||||
} shuffledata_t;
|
||||
|
||||
pokeraction_t actionShuffle();
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data);
|
||||
|
||||
void actionShuffleUpdate(int32_t index, void *data);
|
||||
|
||||
void actionShuffleDispose(int32_t index, void *data);
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "start.h"
|
||||
|
||||
pokeraction_t actionStart() {
|
||||
pokeraction_t action = {
|
||||
.init = &actionStartInit,
|
||||
.update = &actionStartUpdate,
|
||||
.dispose = &actionStartDispose
|
||||
};
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
void actionStartInit(int32_t index, void *data) {
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
logText("Holdem Starting");
|
||||
|
||||
// Prepare the match
|
||||
GAME_STATE.blindBig = 0;
|
||||
GAME_STATE.blindSmall = 0;
|
||||
GAME_STATE.pot = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = GAME_STATE.players + i;
|
||||
player->state = 0x00;
|
||||
player->chips = 0;
|
||||
}
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionStartUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionStartDispose(int32_t index, void *data) {
|
||||
// Begin the first round
|
||||
pokerActionAdd(actionRound());
|
||||
}
|
@ -1,18 +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 "action.h"
|
||||
#include "round.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
pokeraction_t actionStart();
|
||||
|
||||
void actionStartInit(int32_t index, void *data);
|
||||
void actionStartUpdate(int32_t index, void *data);
|
||||
void actionStartDispose(int32_t index, void *data);
|
@ -1,79 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/spritebatch.h"
|
||||
#include "../../display/texture.h"
|
||||
#include "../../display/tileset.h"
|
||||
|
||||
/** Entity Texture Information */
|
||||
#define ENTITY_ASSET_TEXTURE "world/entity.png"
|
||||
#define ENTITY_WIDTH 32
|
||||
#define ENTITY_HEIGHT ENTITY_WIDTH
|
||||
|
||||
/** Entity ID Definitions */
|
||||
#define ENTITY_TYPE_NULL 0x00
|
||||
#define ENTITY_TYPE_PLAYER 0x01
|
||||
|
||||
/** Max count of entities in the world */
|
||||
#define ENTITY_COUNT 64
|
||||
|
||||
/** Count of different types of entities */
|
||||
#define ENTITY_TYPE_COUNT ENTITY_TYPE_PLAYER + 1
|
||||
|
||||
#define ENTITY_DIRECTION_SOUTH 0x00
|
||||
#define ENTITY_DIRECTION_NORTH 0x01
|
||||
#define ENTITY_DIRECTION_WEST 0x02
|
||||
#define ENTITY_DIRECTION_EAST 0x03
|
||||
|
||||
#define ENTITY_STATE_WALKING 0x01
|
||||
|
||||
/** Unique Entity ID */
|
||||
typedef uint8_t entityid_t;
|
||||
|
||||
/** Unique Entity ID for the Entity Type */
|
||||
typedef uint8_t entitytypeid_t;
|
||||
|
||||
/** Entity Definition */
|
||||
typedef struct {
|
||||
entitytypeid_t type;
|
||||
int32_t gridX, gridY, gridZ;
|
||||
int32_t oldGridX, oldGridY, oldGridZ;
|
||||
float positionX, positionY, positionZ;
|
||||
uint8_t direction;
|
||||
uint32_t state;
|
||||
} entity_t;
|
||||
|
||||
/** Definition for an entity type */
|
||||
typedef struct {
|
||||
void (*entityInit)(entityid_t entityId, entity_t *entity);
|
||||
void (*entityUpdate)(entityid_t entityId, entity_t *entity);
|
||||
void (*entityRender)(entityid_t entityId, entity_t *entity);
|
||||
void (*entityDispose)(entityid_t entityId, entity_t *entity);
|
||||
} entitytype_t;
|
||||
|
||||
/** Entity State Management */
|
||||
typedef struct {
|
||||
/** Entities within the state */
|
||||
entity_t entities[ENTITY_COUNT];
|
||||
|
||||
/** Sprite Batch in the state */
|
||||
spritebatch_t *spriteBatch;
|
||||
|
||||
/** Texture for entities */
|
||||
texture_t *texture;
|
||||
|
||||
/** Divided Tileset for entities */
|
||||
tileset_t *tileset;
|
||||
} entitystate_t;
|
||||
|
||||
/** Global Entity State */
|
||||
extern entitystate_t ENTITY_STATE;
|
||||
|
||||
/** Global Entity Type Definitions */
|
||||
extern entitytype_t ENTITY_TYPES[ENTITY_TYPE_COUNT];
|
@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/primitive.h"
|
||||
#include "tile.h"
|
||||
|
||||
/** When loading a chunk, how many chars to offset (ASCII char to byte) */
|
||||
#define CHUNK_TILE_LOAD_ASCII 48
|
||||
|
||||
/** Width (in tiles) of chunks. */
|
||||
#define CHUNK_WIDTH 16
|
||||
/** Height (in tiles) of chunks. */
|
||||
#define CHUNK_HEIGHT 16
|
||||
/** Depth (in tiles) of chunks. */
|
||||
#define CHUNK_DEPTH 8
|
||||
/** Count of tiles in the chunk. */
|
||||
#define CHUNK_TILE_COUNT CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH
|
||||
|
||||
/** Representation of a chunk, a group of tiles that can be buffered around. */
|
||||
typedef struct {
|
||||
/** Position (in absolute chunk coordinates) of this chunk */
|
||||
int32_t x, y, z;
|
||||
|
||||
/** Array of tiles within the chunk */
|
||||
tileid_t tiles[CHUNK_TILE_COUNT];
|
||||
|
||||
/** Ready to be rendered chunk 3d primitive */
|
||||
primitive_t *primitive;
|
||||
} chunk_t;
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "tile.h"
|
||||
#include "chunk.h"
|
||||
#include "../../display/texture.h"
|
||||
#include "../../display/tileset.h"
|
||||
|
||||
/** Width of map (in chunks) */
|
||||
#define MAP_WIDTH 3
|
||||
/** Height of map (in chunks) */
|
||||
#define MAP_HEIGHT MAP_WIDTH
|
||||
/** Depth of map (in chunks) */
|
||||
#define MAP_DEPTH 2
|
||||
/** Count of chunks in the world */
|
||||
#define MAP_CHUNK_COUNT MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH
|
||||
|
||||
#define MAP_ASSET_TEXTURE "world/tileset.png"
|
||||
|
||||
typedef struct {
|
||||
/** Tile definitions */
|
||||
tiledef_t *tileDefinitions;
|
||||
|
||||
/** Tileset predivided */
|
||||
tileset_t *tileset;
|
||||
|
||||
/** Texture of the tileset */
|
||||
texture_t *texture;
|
||||
|
||||
/** Current (chunk) coordinates of the first chunk in the chunk list */
|
||||
int32_t x, y, z;
|
||||
|
||||
/** Current chunk list, ordered */
|
||||
chunk_t *chunkList[MAP_CHUNK_COUNT];
|
||||
|
||||
/** Chunk array, unordered */
|
||||
chunk_t chunks[MAP_CHUNK_COUNT];
|
||||
} map_t;
|
||||
|
||||
extern map_t MAP_STATE;
|
@ -1,29 +0,0 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
/** Width of a tile (in pixels) */
|
||||
#define TILE_WIDTH 16
|
||||
/** Height of a tile (in pixels) */
|
||||
#define TILE_HEIGHT 16
|
||||
/** What a NULL tile is represented as. */
|
||||
#define TILE_NULL 0x00
|
||||
|
||||
/** Bitwise Flags from tiles. */
|
||||
typedef uint8_t tileflag_t;
|
||||
|
||||
/** Tile ID */
|
||||
typedef uint8_t tileid_t;
|
||||
|
||||
/** Representation of the information of a tile within a tilemap. */
|
||||
typedef struct {
|
||||
/** Flags of the tile */
|
||||
tileflag_t flags;
|
||||
|
||||
/** How many indices and vertices a tile with this definition has. */
|
||||
int32_t indiceCount, verticeCount;
|
||||
} tiledef_t;
|
@ -1,9 +0,0 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "map/chunk.h"
|
||||
#include "map/map.h"
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "card.h"
|
||||
|
||||
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;
|
||||
}
|
@ -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);
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "poker.h"
|
||||
|
||||
void pokerInit(poker_t *poker) {
|
||||
uint8_t x;
|
||||
|
||||
// Prepare the initial game state
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
poker->roundPlayer = 0x00;
|
||||
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;
|
||||
}
|
||||
|
||||
pokerRoundInit(poker);
|
||||
}
|
||||
|
||||
void pokerRoundInit(poker_t *poker) {
|
||||
uint8_t x;
|
||||
|
||||
// Refill the deck
|
||||
cardDeckFill(poker->deck);
|
||||
poker->deckSize = CARD_DECK_SIZE;
|
||||
|
||||
// Reset the players
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].cardCount = 0;
|
||||
poker->players[x].currentBet = 0;
|
||||
}
|
||||
}
|
@ -1,25 +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 "card.h"
|
||||
|
||||
/**
|
||||
* Initializes the poker match for the first time.
|
||||
*
|
||||
* @param poker Poker game to init.
|
||||
*/
|
||||
void pokerInit(poker_t *poker);
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the round for a poker game.
|
||||
*
|
||||
* @param poker Poker game to init a new round for.
|
||||
*/
|
||||
void pokerRoundInit(poker_t *poker);
|
@ -1,95 +0,0 @@
|
||||
/**
|
||||
* 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
|
||||
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
|
||||
);
|
||||
|
||||
// Cards Primitive
|
||||
cardBack = GAME_STATE.cardTileset->divisions+(
|
||||
GAME_STATE.cardTileset->columns * 4
|
||||
);
|
||||
GAME_STATE.cardPrimitive = primitiveCreate(
|
||||
QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2
|
||||
);
|
||||
quadBuffer(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
|
||||
);
|
||||
}
|
||||
|
||||
pokerposition_t holdemRenderCardGetPosition(uint8_t seat, uint8_t slot) {
|
||||
pokerposition_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;
|
||||
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;
|
||||
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 = GAME_STATE.cardTileset->divisions + card;
|
||||
quadBuffer(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, GAME_STATE.cardTexture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, x,y,z, pitch,yaw,roll);
|
||||
primitiveDraw(GAME_STATE.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);
|
||||
}
|
@ -1,53 +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 "../../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.
|
||||
*/
|
||||
pokerposition_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);
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
@ -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);
|
||||
}
|
@ -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();
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* 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(&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(&GAME_STATE.cameraLeft,
|
||||
x*0.1, 0.8, z*0.1,
|
||||
-x*0.5, 0.2, -z*0.5
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
/**
|
||||
* 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);
|
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "player.h"
|
||||
|
||||
void holdemRenderPlayerInit(poker_t *poker) {
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)GAME_STATE.kagamiTileset->divY /
|
||||
(float)GAME_STATE.kagamiTileset->divX
|
||||
) * w;
|
||||
|
||||
// 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
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, GAME_STATE.kagamiTexture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld,
|
||||
x, 0.34, z,
|
||||
0, angle, 0
|
||||
);
|
||||
primitiveDraw(GAME_STATE.kagamiQuad, 0, -1);
|
||||
}
|
@ -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>
|
||||
#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.
|
||||
*/
|
||||
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);
|
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "world.h"
|
||||
|
||||
void holdemRenderWorldInit() {
|
||||
GAME_STATE.tablePrimitive = pokerTableCreate();
|
||||
GAME_STATE.tableTexture = assetTextureLoad("pokertable.png");
|
||||
}
|
||||
|
||||
void holdemRenderWorld() {
|
||||
uint8_t i, j;
|
||||
pokerplayer_t *player;
|
||||
uint8_t seat;
|
||||
|
||||
// Poker Table
|
||||
shaderUsePositionAndScale(GAME_STATE.shaderWorld,
|
||||
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);
|
||||
|
||||
// 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();
|
||||
}
|
@ -1,23 +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 "player.h"
|
||||
#include "card.h"
|
||||
#include "chip.h"
|
||||
#include "../../assets/models/pokertable.h"
|
||||
|
||||
/**
|
||||
* Initializes the world renderer.
|
||||
*/
|
||||
void holdemRenderWorldInit();
|
||||
|
||||
/**
|
||||
* Renders the world.
|
||||
*/
|
||||
void holdemRenderWorld();
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void entityCommonMoveUpdate(entityid_t id, entity_t *entity) {
|
||||
float x, y, z, delta;
|
||||
x = entity->gridX - entity->positionX;
|
||||
y = entity->gridY - entity->positionY;
|
||||
z = entity->gridZ - entity->positionZ;
|
||||
|
||||
if(mathAbs(x) <= 0.05 && mathAbs(y) <= 0.05 && mathAbs(z) <= 0.05) {
|
||||
entity->positionX = entity->gridX;
|
||||
entity->positionY = entity->gridY;
|
||||
entity->positionZ = entity->gridZ;
|
||||
entity->state -= ENTITY_STATE_WALKING;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Change this from easing curve to linear.
|
||||
delta = TIME_STATE.delta * ENTITY_COMMON_MOVE_SPEED;
|
||||
entity->positionX += x == 0 ? 0 : x > 0 ? delta : -delta;
|
||||
entity->positionY += y == 0 ? 0 : y > 0 ? delta : -delta;
|
||||
entity->positionZ += z == 0 ? 0 : z > 0 ? delta : -delta;
|
||||
}
|
||||
|
||||
void entityCommonMove(entityid_t id, entity_t *entity, int32_t x, int32_t y, int32_t z) {
|
||||
int32_t newX, newY, newZ, chunkIndex, tileIndex;
|
||||
tileid_t tileId;
|
||||
|
||||
// Update state.
|
||||
entity->state |= ENTITY_STATE_WALKING;
|
||||
|
||||
// Determine the new coordinates.
|
||||
newX = entity->gridX + x;
|
||||
newY = entity->gridY + y;
|
||||
newZ = entity->gridZ + z;
|
||||
|
||||
// Can we move there, tile check first then entity check.
|
||||
tilegetresult_t result = tileGet(newX, newY, newZ);
|
||||
chunkIndex = chunkGet(result.chunkX, result.chunkY, result.chunkZ);
|
||||
if(chunkIndex == -1) return;
|
||||
tileIndex = chunkGetTile(result.localX, result.localY, result.localZ);
|
||||
|
||||
tileId = MAP_STATE.chunkList[chunkIndex]->tiles[tileIndex];
|
||||
if(tileId == TILE_NULL) return;
|
||||
|
||||
// Update the old and new positions
|
||||
entity->oldGridX = entity->gridX;
|
||||
entity->oldGridY = entity->gridY;
|
||||
entity->oldGridZ = entity->gridZ;
|
||||
entity->gridX = newX;
|
||||
entity->gridY = newY;
|
||||
entity->gridZ = newZ;
|
||||
}
|
||||
|
||||
void entityCommonRender(entityid_t id, entity_t *entity) {
|
||||
tilesetdiv_t div = tilesetGetDivision(ENTITY_STATE.tileset, 0, entity->direction);
|
||||
|
||||
// Render sprite
|
||||
spriteBatchQuad(ENTITY_STATE.spriteBatch, -1,
|
||||
entity->positionX, entity->positionY, entity->positionZ + 0.01,
|
||||
1, 1,
|
||||
div.x0, div.y0, div.x1, div.y1
|
||||
);
|
||||
}
|
||||
|
||||
void entityCommonTurn(entityid_t id, entity_t *entity, uint8_t dir) {
|
||||
if(entity->direction == dir) return;
|
||||
entity->direction = dir;
|
||||
entity->state = ENTITY_STATE_WALKING;
|
||||
}
|
@ -1,20 +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/spritebatch.h"
|
||||
#include "../../display/tileset.h"
|
||||
#include "../map/tile.h"
|
||||
#include "../map/chunk.h"
|
||||
|
||||
#define ENTITY_COMMON_MOVE_SPEED 3
|
||||
|
||||
void entityCommonMoveUpdate(entityid_t id, entity_t *entity);
|
||||
void entityCommonMove(entityid_t id, entity_t *entity, int32_t x, int32_t y, int32_t z);
|
||||
void entityCommonRender(entityid_t id, entity_t *entity);
|
||||
void entityCommonTurn(entityid_t id, entity_t *entity, uint8_t dir);
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "player.h"
|
||||
|
||||
void playerInit(entityid_t id, entity_t *entity) {
|
||||
}
|
||||
|
||||
void playerUpdate(entityid_t id, entity_t *entity) {
|
||||
// Movement
|
||||
if(entity->state & ENTITY_STATE_WALKING) {
|
||||
entityCommonMoveUpdate(id, entity);
|
||||
} else {
|
||||
if(inputIsPressed(INPUT_UP)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_NORTH);
|
||||
} else if(inputIsPressed(INPUT_DOWN)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_SOUTH);
|
||||
} else if(inputIsPressed(INPUT_LEFT)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_WEST);
|
||||
} else if(inputIsPressed(INPUT_RIGHT)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_EAST);
|
||||
|
||||
} else if(inputIsDown(INPUT_UP)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_NORTH);
|
||||
entityCommonMove(id, entity, 0, 1, 0);
|
||||
} else if(inputIsDown(INPUT_DOWN)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_SOUTH);
|
||||
entityCommonMove(id, entity, 0, -1, 0);
|
||||
} else if(inputIsDown(INPUT_LEFT)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_WEST);
|
||||
entityCommonMove(id, entity, -1, 0, 0);
|
||||
} else if(inputIsDown(INPUT_RIGHT)) {
|
||||
entityCommonTurn(id, entity, ENTITY_DIRECTION_EAST);
|
||||
entityCommonMove(id, entity, 1, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playerRender(entityid_t id, entity_t *entity) {
|
||||
entityCommonRender(id, entity);
|
||||
}
|
||||
|
||||
void playerDispose(entityid_t id, entity_t *entity) {
|
||||
}
|
@ -1,16 +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 "../common.h"
|
||||
#include "../../../input/input.h"
|
||||
|
||||
void playerInit(entityid_t entityId, entity_t *entity);
|
||||
void playerUpdate(entityid_t entityId, entity_t *entity);
|
||||
void playerRender(entityid_t entityId, entity_t *entity);
|
||||
void playerDispose(entityid_t entityId, entity_t *entity);
|
@ -1,84 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
entitystate_t ENTITY_STATE;
|
||||
|
||||
void entityStateInit() {
|
||||
// Reset the entities
|
||||
memset(ENTITY_STATE.entities, 0, sizeof(entity_t) * ENTITY_COUNT);
|
||||
|
||||
// Prepare the spritebatch.
|
||||
ENTITY_STATE.spriteBatch = spriteBatchCreate(ENTITY_COUNT);
|
||||
|
||||
// Load the texture
|
||||
ENTITY_STATE.texture = assetTextureLoad(ENTITY_ASSET_TEXTURE);
|
||||
|
||||
// Divide the tileset
|
||||
ENTITY_STATE.tileset = tilesetCreate(
|
||||
ENTITY_STATE.texture->width/ENTITY_WIDTH,
|
||||
ENTITY_STATE.texture->height/ENTITY_HEIGHT,
|
||||
ENTITY_STATE.texture->width, ENTITY_STATE.texture->height,
|
||||
0,0,0,0
|
||||
);
|
||||
}
|
||||
|
||||
void entityStateRender() {
|
||||
entityid_t i;
|
||||
entity_t *entity;
|
||||
|
||||
// Flush the batch.
|
||||
spriteBatchFlush(ENTITY_STATE.spriteBatch);
|
||||
|
||||
// Update and Render the entities.
|
||||
for(i = 0; i < ENTITY_COUNT; i++) {
|
||||
entity = ENTITY_STATE.entities + i;
|
||||
if(entity->type == ENTITY_TYPE_NULL) break;
|
||||
ENTITY_TYPES[entity->type].entityUpdate(i, entity);
|
||||
ENTITY_TYPES[entity->type].entityRender(i, entity);
|
||||
}
|
||||
|
||||
// Draw the sprite batch.
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, ENTITY_STATE.texture);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, 0, 0, 0, 0, 0, 0);
|
||||
spriteBatchDraw(ENTITY_STATE.spriteBatch, 0, -1);
|
||||
}
|
||||
|
||||
void entityStateDispose() {
|
||||
entityid_t i;
|
||||
entity_t *entity;
|
||||
|
||||
for(i = 0; i < ENTITY_COUNT; i++) {
|
||||
entity = ENTITY_STATE.entities + i;
|
||||
if(entity->type == ENTITY_TYPE_NULL) break;
|
||||
entityDispose(i);
|
||||
}
|
||||
|
||||
spriteBatchDispose(ENTITY_STATE.spriteBatch);
|
||||
}
|
||||
|
||||
void entityInit(entityid_t id, entitytypeid_t type) {
|
||||
entity_t *entity = ENTITY_STATE.entities + id;
|
||||
entity->type = type;
|
||||
|
||||
// Reset values
|
||||
entity->gridX = entity->gridY = entity->gridZ = 0;
|
||||
entity->oldGridX = entity->oldGridY = entity->oldGridZ = 0;
|
||||
entity->positionX = entity->positionY = entity->positionZ = 0;
|
||||
|
||||
// Init
|
||||
if(ENTITY_TYPES[type].entityInit == NULL) return;
|
||||
ENTITY_TYPES[type].entityInit(id, entity);
|
||||
}
|
||||
|
||||
void entityDispose(entityid_t id) {
|
||||
entity_t *entity = ENTITY_STATE.entities + id;
|
||||
entity->type = ENTITY_TYPE_NULL;
|
||||
if(ENTITY_TYPES[entity->type].entityDispose == NULL) return;
|
||||
ENTITY_TYPES[entity->type].entityDispose(id, entity);
|
||||
}
|
@ -1,45 +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 "entitytypes.h"
|
||||
#include "../../file/asset.h"
|
||||
#include "../../display/spritebatch.h"
|
||||
#include "../../display/shader.h"
|
||||
#include "../../display/texture.h"
|
||||
#include "../../display/tileset.h"
|
||||
|
||||
/**
|
||||
* Initializes the entity state system.
|
||||
*/
|
||||
void entityStateInit();
|
||||
|
||||
/**
|
||||
* Render the entity state system.
|
||||
*/
|
||||
void entityStateRender();
|
||||
|
||||
/**
|
||||
* Dispose and clean up the entity state system.
|
||||
*/
|
||||
void entityStateDispose();
|
||||
|
||||
/**
|
||||
* Initializes an entity into the entity state.
|
||||
*
|
||||
* @param id The Entity ID within the entity state system.
|
||||
* @param type The Entity type to initialize.
|
||||
*/
|
||||
void entityInit(entityid_t id, entitytypeid_t type);
|
||||
|
||||
/**
|
||||
* Disposes the entity from the entity state.
|
||||
*
|
||||
* @param id The entity id to dispose.
|
||||
*/
|
||||
void entityDispose(entityid_t id);
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "entitytypes.h"
|
||||
|
||||
entitytype_t ENTITY_TYPES[ENTITY_TYPE_COUNT] = {
|
||||
// ENTITY_TYPE_NULL
|
||||
{
|
||||
.entityInit = NULL,
|
||||
.entityUpdate = NULL,
|
||||
.entityRender = NULL,
|
||||
.entityDispose = NULL
|
||||
},
|
||||
|
||||
// ENTITY_TYPE_PLAYER
|
||||
{
|
||||
.entityInit = &playerInit,
|
||||
.entityUpdate = &playerUpdate,
|
||||
.entityRender = &playerRender,
|
||||
.entityDispose = &playerDispose
|
||||
}
|
||||
};
|
@ -1,10 +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 "entities/player.h"
|
@ -1,90 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "chunk.h"
|
||||
|
||||
void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z) {
|
||||
tileid_t tileId;
|
||||
tiledef_t *tileDef;
|
||||
int32_t i, indiceCount, verticeCount, tx, ty, tz;
|
||||
|
||||
for(ty = 0; ty < CHUNK_HEIGHT; ty++) {
|
||||
for(tx = 0; tx < CHUNK_WIDTH; tx++) {
|
||||
if(z != 0) break;
|
||||
chunk->tiles[ty*CHUNK_WIDTH + tx] = ty == 5 ? 2 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Start by loading the tiles and figuring out how big we need to make the
|
||||
// primitive that the chunk uses.
|
||||
indiceCount = 0, verticeCount = 0;
|
||||
for(i = 0; i < CHUNK_TILE_COUNT; i++) {
|
||||
//TODO: Actually load the tileId here
|
||||
tileId = chunk->tiles[i];
|
||||
if(tileId == TILE_NULL) continue;
|
||||
|
||||
// Increment the primitive size.
|
||||
tileDef = MAP_STATE.tileDefinitions + tileId;
|
||||
verticeCount += tileDef->verticeCount;
|
||||
indiceCount += tileDef->indiceCount;
|
||||
}
|
||||
|
||||
// Do we even need to create a primitive?
|
||||
if(indiceCount == 0) return;
|
||||
chunk->primitive = primitiveCreate(verticeCount, indiceCount);
|
||||
|
||||
// Render each tile. The ZYX order is important for ordering.
|
||||
i = 0;
|
||||
verticeCount = 0, indiceCount = 0;
|
||||
for(tz = 0; tz < CHUNK_DEPTH; tz++) {
|
||||
for(ty = 0; ty < CHUNK_HEIGHT; ty++) {
|
||||
for(tx = 0; tx < CHUNK_WIDTH; tx++) {
|
||||
tileId = chunk->tiles[i];
|
||||
if(tileId == TILE_NULL) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
tileDef = MAP_STATE.tileDefinitions + tileId;
|
||||
|
||||
tileRender(
|
||||
chunk, tileId, tileDef,
|
||||
i, tx, ty, tz,
|
||||
verticeCount, indiceCount
|
||||
);
|
||||
|
||||
// Prepare for the next render.
|
||||
verticeCount += tileDef->verticeCount;
|
||||
indiceCount += tileDef->indiceCount;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void chunkUnload(chunk_t *chunk) {
|
||||
// Load chunks to zero. TODO: Necessary?
|
||||
memset(chunk->tiles, TILE_NULL, CHUNK_TILE_COUNT);
|
||||
|
||||
// Unload the primitive. TODO: Can we salvage this and resize instead?
|
||||
if(chunk->primitive == NULL) return;
|
||||
primitiveDispose(chunk->primitive);
|
||||
chunk->primitive = NULL;
|
||||
}
|
||||
|
||||
int32_t chunkGet(int32_t x, int32_t y, int32_t z) {
|
||||
int32_t i = (
|
||||
mathMod(x - MAP_STATE.x, MAP_WIDTH) +
|
||||
(mathMod(y - MAP_STATE.y, MAP_HEIGHT) * MAP_WIDTH) +
|
||||
(mathMod(z - MAP_STATE.z, MAP_DEPTH) * MAP_WIDTH * MAP_HEIGHT)
|
||||
);
|
||||
if(i < 0 || i > MAP_CHUNK_COUNT) return -1;
|
||||
return i;
|
||||
}
|
||||
|
||||
int32_t chunkGetTile(int32_t x, int32_t y, int32_t z) {
|
||||
return x + (y * CHUNK_WIDTH) + (z * CHUNK_WIDTH * CHUNK_HEIGHT);
|
||||
}
|
@ -1,48 +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/primitive.h"
|
||||
#include "tile.h"
|
||||
|
||||
/**
|
||||
* Loads a given chunk.
|
||||
*
|
||||
* @param chunk The chunk to load.
|
||||
* @param x X of the chunk.
|
||||
* @param y Y of the chunk.
|
||||
* @param z Z of the chunk.
|
||||
*/
|
||||
void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z);
|
||||
|
||||
/**
|
||||
* Unload a given chunk.
|
||||
*
|
||||
* @param chunk Chunk to unload.
|
||||
*/
|
||||
void chunkUnload(chunk_t *chunk);
|
||||
|
||||
/**
|
||||
* Gets the chunk index from an absolute coordinate.
|
||||
*
|
||||
* @param x Absolute chunk X.
|
||||
* @param y Absolute chunk Y.
|
||||
* @param z Absolute chunk Z.
|
||||
* @returns The index for that chunk. -1 if out of bounds of the current list.
|
||||
*/
|
||||
int32_t chunkGet(int32_t x, int32_t y, int32_t z);
|
||||
|
||||
/**
|
||||
* Gets the tile index from a local tile coordinate.
|
||||
*
|
||||
* @param x The local X coordinate of the tile.
|
||||
* @param y The local Y coordinate of the tile.
|
||||
* @param z The local Z coordinate of the tile.
|
||||
* @return The index within the chunk that the tile resides.
|
||||
*/
|
||||
int32_t chunkGetTile(int32_t x, int32_t y, int32_t z);
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "map.h"
|
||||
|
||||
map_t MAP_STATE;
|
||||
|
||||
void mapInit() {
|
||||
int32_t i, z, x, y;
|
||||
chunk_t *chunk;
|
||||
|
||||
// Reset map
|
||||
MAP_STATE.x = MAP_STATE.y = MAP_STATE.z = 0;
|
||||
|
||||
// Load the texture
|
||||
MAP_STATE.texture = assetTextureLoad(MAP_ASSET_TEXTURE);
|
||||
|
||||
// Load the tileset
|
||||
MAP_STATE.tileset = tilesetCreate(
|
||||
MAP_STATE.texture->width/TILE_WIDTH, MAP_STATE.texture->height/TILE_HEIGHT,
|
||||
MAP_STATE.texture->width, MAP_STATE.texture->height,
|
||||
0, 0, 0, 0
|
||||
);
|
||||
|
||||
// Prepare the tile definitions
|
||||
MAP_STATE.tileDefinitions = calloc(
|
||||
MAP_STATE.tileset->count,sizeof(tiledef_t)
|
||||
);
|
||||
|
||||
// TODO: Load the tile definitions here.
|
||||
for(i = 0; i < MAP_STATE.tileset->count; i++) {
|
||||
(MAP_STATE.tileDefinitions+i)->verticeCount = 4;
|
||||
(MAP_STATE.tileDefinitions+i)->indiceCount = 6;
|
||||
}
|
||||
|
||||
// Load each of the chunks. The ZYX order is important for ordering.
|
||||
i = 0;
|
||||
for(z = 0; z < MAP_DEPTH; z++) {
|
||||
for(y = 0; y < MAP_HEIGHT; y++) {
|
||||
for(x = 0; x < MAP_WIDTH; x++) {
|
||||
chunk = MAP_STATE.chunks + i;
|
||||
MAP_STATE.chunkList[i] = chunk;
|
||||
|
||||
// Load initial chunk state.
|
||||
chunk->x = x;
|
||||
chunk->y = y;
|
||||
chunk->z = z;
|
||||
chunk->primitive = NULL;
|
||||
|
||||
// Load the chunk.
|
||||
chunkLoad(chunk, x, y, z);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mapRender() {
|
||||
int32_t i;
|
||||
float x, y, z;
|
||||
chunk_t *chunk;
|
||||
|
||||
// Bind the texture
|
||||
shaderUseTexture(GAME_STATE.shaderWorld, MAP_STATE.texture);
|
||||
|
||||
// Render each chunk.
|
||||
// TODO: Do we need to render every chunk? (screen area)
|
||||
for(i = 0; i < MAP_CHUNK_COUNT; i++) {
|
||||
chunk = MAP_STATE.chunkList[i];
|
||||
if(chunk->primitive == NULL) continue;
|
||||
|
||||
// Offset the primitive (into world space)
|
||||
x = (chunk->x * CHUNK_WIDTH);
|
||||
y = (chunk->y * CHUNK_HEIGHT);
|
||||
z = (chunk->z * CHUNK_DEPTH);
|
||||
shaderUsePosition(GAME_STATE.shaderWorld, x, y, z, 0, 0, 0);
|
||||
primitiveDraw(chunk->primitive, 0, chunk->primitive->indiceCount);
|
||||
}
|
||||
}
|
||||
|
||||
void mapDispose() {
|
||||
int32_t i;
|
||||
chunk_t *chunk;
|
||||
|
||||
// Unload the chunks
|
||||
for(i = 0; i < MAP_CHUNK_COUNT; i++) {
|
||||
chunk = MAP_STATE.chunkList[i];
|
||||
chunkUnload(chunk);
|
||||
}
|
||||
|
||||
tilesetDispose(MAP_STATE.tileset);
|
||||
textureDispose(MAP_STATE.texture);
|
||||
}
|
||||
|
||||
void mapShift(int32_t x, int32_t y, int32_t z) {
|
||||
int32_t i,
|
||||
/** New List Coordinates */
|
||||
lx, ly, lz,
|
||||
/** New Local Chunk Coordinates */
|
||||
nx, ny, nz,
|
||||
/** New Absolute Chunk Coordinates */
|
||||
ax, ay, az,
|
||||
/** New Chunk Index */
|
||||
ni,
|
||||
/** Precalculated width * height */
|
||||
wh
|
||||
;
|
||||
chunk_t *chunk;
|
||||
chunk_t *chunkList[MAP_CHUNK_COUNT];
|
||||
|
||||
// Calculate the new chunklist coordinates
|
||||
lx = MAP_STATE.x + x;
|
||||
ly = MAP_STATE.y + y;
|
||||
lz = MAP_STATE.z + z;
|
||||
|
||||
// Precalc width * height.
|
||||
wh = MAP_WIDTH * MAP_HEIGHT;
|
||||
|
||||
for(i = 0; i < MAP_CHUNK_COUNT; i++) {
|
||||
chunk = MAP_STATE.chunkList[i];
|
||||
|
||||
// Calculate the new local positions for the chunk.
|
||||
nx = mathMod(chunk->x - MAP_STATE.x - x, MAP_WIDTH);
|
||||
ny = mathMod(chunk->y - MAP_STATE.y - y, MAP_HEIGHT);
|
||||
nz = mathMod(chunk->z - MAP_STATE.z - z, MAP_DEPTH);
|
||||
|
||||
// Load the chunk if we need to. We also use this to calculate new absolutes
|
||||
if(
|
||||
(ax = lx + nx) != chunk->x ||
|
||||
(ly + ny) != chunk->y ||
|
||||
(lz + nz) != chunk->z
|
||||
) {
|
||||
// Calculate those things that may have not been done within the if
|
||||
ay = ly + ny;
|
||||
az = lz + nz;
|
||||
|
||||
// Load new chunk.
|
||||
chunkUnload(chunk);
|
||||
chunkLoad(chunk, ax, ay, az);
|
||||
|
||||
// Update the absolute coordinates.
|
||||
chunk->x = ax;
|
||||
chunk->y = ay;
|
||||
chunk->z = az;
|
||||
}
|
||||
|
||||
// Now, based off those new local positions, calculate the new index.
|
||||
ni = (
|
||||
nx +
|
||||
(ny * MAP_WIDTH) +
|
||||
(nz * wh)
|
||||
);
|
||||
chunkList[ni] = chunk;
|
||||
}
|
||||
|
||||
// Update Absolutes.
|
||||
MAP_STATE.x = lx;
|
||||
MAP_STATE.y = ly;
|
||||
MAP_STATE.z = lz;
|
||||
|
||||
// Now copy that array over.
|
||||
memcpy(MAP_STATE.chunkList, chunkList, sizeof(chunk_t *) * MAP_CHUNK_COUNT);
|
||||
}
|
||||
|
||||
void mapAlign(int32_t x, int32_t y, int32_t z) {
|
||||
mapShift(x - MAP_STATE.x, y - MAP_STATE.y, z - MAP_STATE.z);
|
||||
}
|
@ -1,45 +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/tileset.h"
|
||||
#include "../../file/asset.h"
|
||||
#include "chunk.h"
|
||||
|
||||
/**
|
||||
* Initializes the world map.
|
||||
*/
|
||||
void mapInit();
|
||||
|
||||
/**
|
||||
* Renders the map object to the graphics device.
|
||||
*/
|
||||
void mapRender();
|
||||
|
||||
/**
|
||||
* Cleans the previously loaded world map.
|
||||
*/
|
||||
void mapDispose();
|
||||
|
||||
/**
|
||||
* Shift the map chunk list along a set of axis (in absolute space).
|
||||
*
|
||||
* @param x X movement to shift chunks along.
|
||||
* @param y Y movement to shift chunks along.
|
||||
* @param z Z movement to shift chunks along.
|
||||
*/
|
||||
void mapShift(int32_t x, int32_t y, int32_t z);
|
||||
|
||||
/**
|
||||
* Align the map chunk list (in absolute space).
|
||||
*
|
||||
* @param x X movement to shift chunks along.
|
||||
* @param y Y movement to shift chunks along.
|
||||
* @param z Z movement to shift chunks along.
|
||||
*/
|
||||
void mapAlign(int32_t x, int32_t y, int32_t z);
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "tile.h"
|
||||
|
||||
void tileRender(
|
||||
chunk_t *chunk, tileid_t id, tiledef_t *tileDef,
|
||||
int32_t i, int32_t x, int32_t y, int32_t z,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
tilesetdiv_t *div = (MAP_STATE.tileset->divisions + id);
|
||||
quadBuffer(chunk->primitive, z,
|
||||
x, y, div->x0, div->y0,
|
||||
x+1, y+1, div->x1, div->y1,
|
||||
verticeStart, indiceStart
|
||||
);
|
||||
}
|
||||
|
||||
tilegetresult_t tileGet(int32_t x, int32_t y, int32_t z) {
|
||||
tilegetresult_t result;
|
||||
|
||||
// First, determine the chunk that I belong to.
|
||||
result.chunkX = x / CHUNK_WIDTH;
|
||||
result.chunkY = y / CHUNK_HEIGHT;
|
||||
result.chunkZ = z / CHUNK_DEPTH;
|
||||
|
||||
// And determine the local coordinates
|
||||
result.localX = mathMod(x, CHUNK_WIDTH);
|
||||
result.localY = mathMod(y, CHUNK_HEIGHT);
|
||||
result.localZ = mathMod(z, CHUNK_DEPTH);
|
||||
|
||||
return result;
|
||||
}
|
@ -1,22 +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/primitives/quad.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t chunkX, chunkY, chunkZ, localX, localY, localZ;
|
||||
} tilegetresult_t;
|
||||
|
||||
void tileRender(
|
||||
chunk_t *chunk, tileid_t id, tiledef_t *tileDef,
|
||||
int32_t i, int32_t x, int32_t y, int32_t z,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
);
|
||||
|
||||
tilegetresult_t tileGet(int32_t x, int32_t y, int32_t z);
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "world.h"
|
||||
|
||||
void worldInit() {
|
||||
mapInit();
|
||||
entityStateInit();
|
||||
}
|
||||
|
||||
void worldRender() {
|
||||
if(ENTITY_STATE.entities[0].type != ENTITY_TYPE_NULL) {
|
||||
cameraLookAt(&GAME_STATE.cameraMain,
|
||||
ENTITY_STATE.entities[0].positionX,
|
||||
ENTITY_STATE.entities[0].positionY - 0.5,
|
||||
ENTITY_STATE.entities[0].positionZ + 7,
|
||||
|
||||
ENTITY_STATE.entities[0].positionX,
|
||||
ENTITY_STATE.entities[0].positionY,
|
||||
ENTITY_STATE.entities[0].positionZ
|
||||
);
|
||||
}
|
||||
mapRender();
|
||||
entityStateRender();
|
||||
}
|
||||
|
||||
void worldDispose() {
|
||||
entityStateDispose();
|
||||
mapDispose();
|
||||
}
|
@ -1,16 +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 "map/map.h"
|
||||
#include "entity/entity.h"
|
||||
#include "../display/camera.h"
|
||||
|
||||
void worldInit();
|
||||
void worldRender();
|
||||
void worldDispose();
|
Reference in New Issue
Block a user