Refactoring structs Part 1
This commit is contained in:
1 parent
17ddb4246a
commit
9bcf6223b6
56 files changed
+484
-422
No files matched your search
+10
-6
@@ -7,6 +7,10 @@
|
||||
#include "libs.h"
|
||||
|
||||
// Display / Rendering
|
||||
#include "display/debug/grid.h"
|
||||
|
||||
#include "display/gui/font.h"
|
||||
|
||||
#include "display/camera.h"
|
||||
#include "display/framebuffer.h"
|
||||
#include "display/primitive.h"
|
||||
@@ -16,26 +20,26 @@
|
||||
#include "display/texture.h"
|
||||
#include "display/tileset.h"
|
||||
|
||||
#include "display/debug/grid.h"
|
||||
#include "display/debug/position.h"
|
||||
// Game Engine
|
||||
#include "engine/engine.h"
|
||||
|
||||
#include "display/gui/font.h"
|
||||
// Time Management
|
||||
#include "epoch/epoch.h"
|
||||
|
||||
// File / Asset Management
|
||||
#include "file/asset.h"
|
||||
|
||||
// Game Logic / Game Time Management
|
||||
// Game Logic
|
||||
#include "game/game.h"
|
||||
#include "game/gametime.h"
|
||||
|
||||
// Player Input
|
||||
#include "input/input.h"
|
||||
|
||||
// Poker Game Logic
|
||||
#include "poker/action.h"
|
||||
#include "poker/card.h"
|
||||
#include "poker/chip.h"
|
||||
#include "poker/player.h"
|
||||
#include "poker/poker.h"
|
||||
#include "poker/render.h"
|
||||
|
||||
// Utility Objects
|
||||
|
||||
@@ -1,27 +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 "../primitive.h"
|
||||
#include "../texture.h"
|
||||
#include "../tileset.h"
|
||||
|
||||
#define POSITION_DEBUG_FONT_CHARS_MAX 256
|
||||
|
||||
/** Struct representing a positionable object in space */
|
||||
typedef struct {
|
||||
primitive_t *primitive;
|
||||
|
||||
spritebatch_t *textBatch;
|
||||
texture_t *textTexture;
|
||||
tileset_t *textTileset;
|
||||
|
||||
float x, y, z;
|
||||
float pitch, yaw, roll;
|
||||
float scaleX, scaleY, scaleZ;
|
||||
} positiondebug_t;
|
||||
@@ -12,5 +12,5 @@
|
||||
typedef struct {
|
||||
GLuint fboId;
|
||||
GLuint rboId;
|
||||
texture_t *texture;
|
||||
texture_t texture;
|
||||
} framebuffer_t;
|
||||
@@ -13,7 +13,4 @@
|
||||
typedef struct {
|
||||
/** Resolution (in pixels) */
|
||||
int32_t width, height;
|
||||
} render_t;
|
||||
|
||||
/** Current render state */
|
||||
extern render_t RENDER_STATE;
|
||||
} render_t;
|
||||
@@ -17,5 +17,5 @@ typedef struct {
|
||||
int32_t currentSprite;
|
||||
|
||||
/** Internal primitive */
|
||||
primitive_t *primitive;
|
||||
primitive_t primitive;
|
||||
} spritebatch_t;
|
||||
@@ -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 "../display/render.h"
|
||||
#include "../input/input.h"
|
||||
#include "../epoch/epoch.h"
|
||||
|
||||
typedef struct {
|
||||
/** Time Manager for the game */
|
||||
epoch_t time;
|
||||
|
||||
/** Render Manager for the game */
|
||||
render_t render;
|
||||
|
||||
/** Input Manager for the game */
|
||||
input_t input;
|
||||
} engine_t;
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define GAMETIME_FIXED_STEP 0.016
|
||||
#define GAMETIME_SMALLEST_STEP 0.001
|
||||
|
||||
#define EPOCH_FIXED_STEP 0.016
|
||||
#define EPOCH_SMALLEST_STEP 0.001
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
@@ -39,6 +38,4 @@ typedef struct {
|
||||
* Fixed timestep that is not affected by framerate but remains consistent.
|
||||
*/
|
||||
float fixedDelta;
|
||||
} gametime_t;
|
||||
|
||||
extern gametime_t TIME_STATE;
|
||||
} epoch_t;
|
||||
@@ -5,72 +5,22 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/camera.h"
|
||||
#include "../poker/card.h"
|
||||
#include "../poker/player.h"
|
||||
#include "../poker/render.h"
|
||||
#include "../poker/action.h"
|
||||
#include "../display/render.h"
|
||||
#include "../display/spritebatch.h"
|
||||
#include "../display/texture.h"
|
||||
#include "../display/tileset.h"
|
||||
#include "../display/framebuffer.h"
|
||||
#include "../engine/engine.h"
|
||||
#include "../poker/poker.h"
|
||||
|
||||
/** Name of the current game */
|
||||
#define GAME_NAME "Dawn"
|
||||
|
||||
|
||||
/** Describes the current game */
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
||||
/** Current Card Deck */
|
||||
card_t deck[CARD_DECK_SIZE];
|
||||
uint8_t deckSize;
|
||||
|
||||
/** Dealer Money */
|
||||
uint32_t blindSmall;
|
||||
uint32_t blindBig;
|
||||
uint32_t pot;
|
||||
/** Engine for the game */
|
||||
engine_t engine;
|
||||
|
||||
/** Dealer Hand */
|
||||
card_t cards[HOLDEM_DEALER_HAND];
|
||||
uint8_t cardsFacing;
|
||||
|
||||
/** Player States */
|
||||
pokerplayer_t players[POKER_PLAYER_COUNT];
|
||||
|
||||
/** Action Queue */
|
||||
pokeraction_t actionQueue[POKER_ACTION_QUEUE_SIZE];
|
||||
void *actionData[POKER_ACTION_DATA_SIZE*POKER_ACTION_QUEUE_SIZE];
|
||||
bool actionInitState[POKER_ACTION_DATA_SIZE];
|
||||
|
||||
/** Rendering Assets */
|
||||
texture_t *kagamiTexture;
|
||||
tileset_t *kagamiTileset;
|
||||
primitive_t *kagamiQuad;
|
||||
|
||||
primitive_t *chipPrimitive;
|
||||
texture_t *chipTexture;
|
||||
primitive_t *tablePrimitive;
|
||||
texture_t *tableTexture;
|
||||
|
||||
texture_t *cardTexture;
|
||||
tileset_t *cardTileset;
|
||||
primitive_t *cardPrimitive;
|
||||
|
||||
texture_t *fontTexture;
|
||||
tileset_t *fontTileset;
|
||||
spritebatch_t *fontBatch;
|
||||
|
||||
shader_t *shaderWorld;
|
||||
framebuffer_t *frameLeft;
|
||||
framebuffer_t *frameRight;
|
||||
primitive_t *quadLeft;
|
||||
primitive_t *quadRight;
|
||||
camera_t cameraMain;
|
||||
camera_t cameraLeft;
|
||||
camera_t cameraRight;
|
||||
/** Poker Game State */
|
||||
poker_t poker;
|
||||
} game_t;
|
||||
|
||||
/** The current running game state. */
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "../libs.h"
|
||||
#include "../util/list.h"
|
||||
|
||||
|
||||
/** Debug Inputs */
|
||||
#define INPUT_NULL (inputbind_t)0x00
|
||||
#define INPUT_DEBUG_UP (inputbind_t)0x01
|
||||
@@ -75,7 +74,4 @@ typedef struct {
|
||||
|
||||
/** Float of the GameTime that the input was actuated last. */
|
||||
float times[INPUT_BIND_COUNT];
|
||||
} input_t;
|
||||
|
||||
/** The current input state */
|
||||
extern input_t INPUT_STATE;
|
||||
} input_t;
|
||||
@@ -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 "../libs.h"
|
||||
|
||||
/** How many actions the queue can hold */
|
||||
#define POKER_ACTION_QUEUE_SIZE 12
|
||||
|
||||
/** How much data (in length of sizeof size_t) each action has available */
|
||||
#define POKER_ACTION_DATA_SIZE 256
|
||||
|
||||
/** Callback for actions to use */
|
||||
typedef void (*pokerActionCallback)(int32_t index, void *data);
|
||||
|
||||
/** Poker Game action that can be queued and executed */
|
||||
typedef struct {
|
||||
pokerActionCallback init;
|
||||
pokerActionCallback update;
|
||||
pokerActionCallback dispose;
|
||||
} pokeraction_t;
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/** How many cards the dealer can hold in their hand */
|
||||
#define HOLDEM_DEALER_HAND 5
|
||||
#include "card.h"
|
||||
|
||||
/** How many cards a player can hold in their hand */
|
||||
#define POKER_PLAYER_HAND 2
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "player.h"
|
||||
#include "card.h"
|
||||
|
||||
#include "../display/tileset.h"
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/texture.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/camera.h"
|
||||
#include "../display/spritebatch.h"
|
||||
|
||||
/** Rounds that the game can be in */
|
||||
#define POKER_ROUND_DEAL 0x00
|
||||
#define POKER_ROUND_BLINDS 0x01
|
||||
#define POKER_ROUND_BET0 0x02
|
||||
#define POKER_ROUND_FLOP 0X03
|
||||
#define POKER_ROUND_BET1 0x04
|
||||
#define POKER_ROUND_TURN 0x05
|
||||
#define POKER_ROUND_BET2 0x06
|
||||
#define POKER_ROUND_RIVER 0x07
|
||||
#define POKER_ROUND_BET3 0x08
|
||||
#define POKER_ROUND_WINNER 0x09
|
||||
|
||||
/** How many cards the dealer can hold in their hand */
|
||||
#define POKER_DEALER_HAND 5
|
||||
|
||||
typedef struct {
|
||||
/** Current Card Deck */
|
||||
card_t deck[CARD_DECK_SIZE];
|
||||
uint8_t deckSize;
|
||||
|
||||
/** Dealer Money */
|
||||
uint32_t blindSmall;
|
||||
uint32_t blindBig;
|
||||
|
||||
/** Dealer Hand */
|
||||
card_t cards[POKER_DEALER_HAND];
|
||||
uint8_t cardsFacing;
|
||||
|
||||
/** Player States */
|
||||
pokerplayer_t players[POKER_PLAYER_COUNT];
|
||||
|
||||
/** Game State */
|
||||
uint8_t round;
|
||||
uint8_t roundPlayer;
|
||||
uint8_t roundDealer;
|
||||
uint32_t pot;
|
||||
uint32_t roundBet;
|
||||
|
||||
/** Rendering Assets */
|
||||
texture_t *kagamiTexture;
|
||||
tileset_t *kagamiTileset;
|
||||
primitive_t *kagamiQuad;
|
||||
|
||||
primitive_t *chipPrimitive;
|
||||
texture_t *chipTexture;
|
||||
primitive_t *tablePrimitive;
|
||||
texture_t *tableTexture;
|
||||
|
||||
texture_t *cardTexture;
|
||||
tileset_t *cardTileset;
|
||||
primitive_t *cardPrimitive;
|
||||
|
||||
texture_t *fontTexture;
|
||||
tileset_t *fontTileset;
|
||||
spritebatch_t *fontBatch;
|
||||
|
||||
shader_t *shaderWorld;
|
||||
framebuffer_t *frameLeft;
|
||||
framebuffer_t *frameRight;
|
||||
primitive_t *quadLeft;
|
||||
primitive_t *quadRight;
|
||||
camera_t cameraMain;
|
||||
camera_t cameraLeft;
|
||||
camera_t cameraRight;
|
||||
} poker_t;
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
list_t *logBuffer;
|
||||
|
||||
void logInit() {
|
||||
logBuffer = listCreate();
|
||||
}
|
||||
|
||||
void logText(char *string) {
|
||||
// Clone the string
|
||||
int32_t len = strlen(string);
|
||||
char *newString = malloc(sizeof(char) * (len+1));
|
||||
memcpy(newString, string, len+1);
|
||||
listAdd(logBuffer, newString);
|
||||
printf("%s\n", newString);
|
||||
}
|
||||
@@ -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 "../util/list.h"
|
||||
|
||||
/** Primary Log Buffer. */
|
||||
extern list_t *logBuffer;
|
||||
|
||||
/**
|
||||
* Writes a string to the log buffer.
|
||||
*
|
||||
* @param string String to log.
|
||||
*/
|
||||
void logText(char *string);
|
||||
+14
-19
@@ -7,26 +7,19 @@
|
||||
|
||||
#include "framebuffer.h"
|
||||
|
||||
framebuffer_t * frameBufferCreate(int32_t w, int32_t h) {
|
||||
framebuffer_t *fb = malloc(sizeof(framebuffer_t));
|
||||
if(fb == NULL) return NULL;
|
||||
|
||||
void frameBufferInit(framebuffer_t *fb, int32_t w, int32_t h) {
|
||||
// At least one pixel
|
||||
if(w <= 0) w = 1;
|
||||
if(h <= 0) h = 1;
|
||||
|
||||
// Create Color Attachment texture.
|
||||
fb->texture = textureCreate(w, h, NULL);
|
||||
if(fb->texture == NULL) {
|
||||
free(fb);
|
||||
return NULL;
|
||||
}
|
||||
textureInit(&fb->texture, w, h, NULL);
|
||||
|
||||
// Create Frame Buffer
|
||||
glGenFramebuffers(1, &fb->fboId);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb->fboId);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, fb->texture->id, 0
|
||||
GL_TEXTURE_2D, fb->texture.id, 0
|
||||
);
|
||||
|
||||
// Render Buffer
|
||||
@@ -44,18 +37,20 @@ framebuffer_t * frameBufferCreate(int32_t w, int32_t h) {
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
return fb;
|
||||
}
|
||||
|
||||
void frameBufferUse(framebuffer_t *frameBuffer, bool clear) {
|
||||
if(frameBuffer == NULL) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, RENDER_STATE.width, RENDER_STATE.height);
|
||||
} else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->fboId);
|
||||
glViewport(0, 0, frameBuffer->texture->width, frameBuffer->texture->height);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->fboId);
|
||||
glViewport(0, 0, frameBuffer->texture.width, frameBuffer->texture.height);
|
||||
|
||||
if(clear) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void frameBufferUnbind(render_t *render, bool clear) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, render->width, render->height);
|
||||
|
||||
if(clear) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -67,6 +62,6 @@ void frameBufferDispose(framebuffer_t *frameBuffer) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glDeleteRenderbuffers(1, &frameBuffer->rboId);
|
||||
glDeleteFramebuffers(1, &frameBuffer->fboId);
|
||||
textureDispose(frameBuffer->texture);
|
||||
textureDispose(&frameBuffer->texture);
|
||||
free(frameBuffer);
|
||||
}
|
||||
@@ -10,22 +10,30 @@
|
||||
#include "texture.h"
|
||||
|
||||
/**
|
||||
* Creates a new frame buffer that can be rendered to.
|
||||
*
|
||||
* Initializes frame buffer that can be rendered to.
|
||||
* @param frameBuffer Frame buffer to initialize.
|
||||
* @param width Width of the frame buffer (in pixels).
|
||||
* @param height Height of the frame buffer (in pixels).
|
||||
* @return A renderable frame buffer.
|
||||
*/
|
||||
framebuffer_t * frameBufferCreate(int32_t width, int32_t height);
|
||||
void frameBufferInit(framebuffer_t *buffer, int32_t width, int32_t height);
|
||||
|
||||
/**
|
||||
* Use a given frame buffer as the current rendering context.
|
||||
*
|
||||
* @param frameBuffer Frame buffer to use, or NULL to not use any.
|
||||
* @param frameBuffer Frame buffer to use.
|
||||
* @param clear Whether or not to clear the frame buffer prior to rendering.
|
||||
*/
|
||||
void frameBufferUse(framebuffer_t *frameBuffer, bool clear);
|
||||
|
||||
/**
|
||||
* Unbind the currently bound frame buffer.
|
||||
*
|
||||
* @param render Render manager
|
||||
* @param clear Whether or not to clear the back buffer.
|
||||
*/
|
||||
void frameBufferUnbind(render_t *render, bool clear);
|
||||
|
||||
/**
|
||||
* Dispose/cleanup a previously created frame buffer.
|
||||
*
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#include "primitive.h"
|
||||
|
||||
primitive_t * primitiveCreate(int32_t verticeCount, int32_t indiceCount) {
|
||||
primitive_t *primitive = malloc(sizeof(primitive_t));
|
||||
|
||||
void primitiveInit(primitive_t *primitive, int32_t verticeCount, int32_t indiceCount) {
|
||||
primitive->verticeCount = verticeCount;
|
||||
primitive->indiceCount = indiceCount;
|
||||
|
||||
@@ -44,8 +42,6 @@ primitive_t * primitiveCreate(int32_t verticeCount, int32_t indiceCount) {
|
||||
GL_FALSE, 0, (void *)offset
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
void primitiveBufferVertices(primitive_t *primitive,
|
||||
@@ -131,5 +127,4 @@ void primitiveDispose(primitive_t *primitive) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &primitive->vertexBuffer);
|
||||
glDeleteBuffers(1, &primitive->indexBuffer);
|
||||
free(primitive);
|
||||
}
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
/**
|
||||
* Creates a new primitive.
|
||||
* @param primitive Primitive to initialize.
|
||||
* @param verticeCount How many vertices can the primitive hold.
|
||||
* @param indiceCount How many indices can the primitive hold.
|
||||
* @return The newly created primitive ready to be buffered to.
|
||||
*/
|
||||
primitive_t * primitiveCreate(int32_t verticeCount, int32_t indiceCount);
|
||||
void primitiveInit(primitive_t *primitive, int32_t verticeCount, int32_t indiceCount);
|
||||
|
||||
/**
|
||||
* Buffer Vertices to a primitive for use in rendering.
|
||||
@@ -47,7 +47,7 @@ void primitiveBufferIndices(primitive_t *primitive,
|
||||
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count);
|
||||
|
||||
/**
|
||||
* Cleanup a previously created primitive.
|
||||
* Cleanup a previously initialized primitive.
|
||||
* @param primitive Primitive to cleanup.
|
||||
*/
|
||||
void primitiveDispose(primitive_t *primitive);
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#include "render.h"
|
||||
|
||||
render_t RENDER_STATE;
|
||||
|
||||
void renderInit() {
|
||||
// Enable GL things.
|
||||
glEnable(GL_BLEND);
|
||||
@@ -29,7 +27,7 @@ void renderFrameStart() {
|
||||
void renderDispose() {
|
||||
}
|
||||
|
||||
void renderSetResolution(int32_t width, int32_t height) {
|
||||
RENDER_STATE.width = width;
|
||||
RENDER_STATE.height = height;
|
||||
void renderSetResolution(render_t *render, int32_t width, int32_t height) {
|
||||
render->width = width;
|
||||
render->height = height;
|
||||
}
|
||||
@@ -26,7 +26,8 @@ void renderDispose();
|
||||
/**
|
||||
* Sets the internal display resolution.
|
||||
*
|
||||
* @param render Render context to resize.
|
||||
* @param width Width of the display (in pixels).
|
||||
* @param height Height of the display (in pixels).
|
||||
*/
|
||||
void renderSetResolution(int32_t width, int32_t height);
|
||||
void renderSetResolution(render_t *render, int32_t width, int32_t height);
|
||||
@@ -7,22 +7,13 @@
|
||||
|
||||
#include "spritebatch.h"
|
||||
|
||||
spritebatch_t * spriteBatchCreate(int32_t maxSprites) {
|
||||
spritebatch_t *batch = malloc(sizeof(spritebatch_t));
|
||||
if(batch == NULL) return NULL;
|
||||
|
||||
void spriteBatchInit(spritebatch_t *batch, int32_t maxSprites) {
|
||||
batch->maxSprites = maxSprites;
|
||||
batch->currentSprite = 0;
|
||||
|
||||
batch->primitive = primitiveCreate(
|
||||
primitiveInit(&batch->primitive,
|
||||
maxSprites*QUAD_VERTICE_COUNT, maxSprites*QUAD_INDICE_COUNT
|
||||
);
|
||||
if(batch == NULL) {
|
||||
free(batch);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return batch;
|
||||
}
|
||||
|
||||
void spriteBatchQuad(spritebatch_t *spriteBatch, int32_t index,
|
||||
@@ -35,7 +26,7 @@ void spriteBatchQuad(spritebatch_t *spriteBatch, int32_t index,
|
||||
spriteBatch->currentSprite = mathMax(index, spriteBatch->currentSprite);
|
||||
}
|
||||
|
||||
quadBuffer(spriteBatch->primitive, z,
|
||||
quadBuffer(&spriteBatch->primitive, z,
|
||||
x, y, u0, v0,
|
||||
x+width, y+height, u1, v1,
|
||||
index*QUAD_VERTICE_COUNT, index*QUAD_INDICE_COUNT
|
||||
@@ -48,12 +39,11 @@ void spriteBatchFlush(spritebatch_t *spriteBatch) {
|
||||
|
||||
void spriteBatchDraw(spritebatch_t *spriteBatch, int32_t index, int32_t count) {
|
||||
if(count == -1) count = spriteBatch->currentSprite;
|
||||
primitiveDraw(spriteBatch->primitive,
|
||||
primitiveDraw(&spriteBatch->primitive,
|
||||
index*QUAD_INDICE_COUNT, count*QUAD_INDICE_COUNT
|
||||
);
|
||||
}
|
||||
|
||||
void spriteBatchDispose(spritebatch_t *spriteBatch) {
|
||||
primitiveDispose(spriteBatch->primitive);
|
||||
free(spriteBatch);
|
||||
primitiveDispose(&spriteBatch->primitive);
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
/**
|
||||
* Creates a new Sprite Batch made of standard quads.
|
||||
*
|
||||
* @param batch Sprite batch to init.
|
||||
* @param maxSprites The maxiumum number of sprites the batch can hold.
|
||||
* @returns A new quad Sprite Batch.
|
||||
*/
|
||||
spritebatch_t * spriteBatchCreate(int32_t maxSprites);
|
||||
void spriteBatchInit(spritebatch_t *batch, int32_t maxSprites);
|
||||
|
||||
/**
|
||||
* Renders a sprite onto a given Sprite Batch.
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
texture_t * textureCreate(int32_t width, int32_t height, pixel_t *pixels) {
|
||||
texture_t *texture = malloc(sizeof(texture_t));
|
||||
if(texture == NULL) return NULL;
|
||||
|
||||
void textureInit(texture_t *texture, int32_t width, int32_t height,
|
||||
pixel_t *pixels
|
||||
) {
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
|
||||
@@ -27,13 +26,12 @@ texture_t * textureCreate(int32_t width, int32_t height, pixel_t *pixels) {
|
||||
|
||||
// Start by buffering all transparent black pixels.
|
||||
if(pixels == NULL) {
|
||||
// TODO: I can optimize this, I think the GPU can default this somehow
|
||||
pixels = calloc(width * height, sizeof(pixel_t));
|
||||
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, pixels
|
||||
);
|
||||
|
||||
free(pixels);
|
||||
} else {
|
||||
glTexImage2D(
|
||||
@@ -59,5 +57,4 @@ void textureBufferPixels(texture_t *texture,
|
||||
|
||||
void textureDispose(texture_t *texture) {
|
||||
glDeleteTextures(1, &texture->id);
|
||||
free(texture);
|
||||
}
|
||||
@@ -7,14 +7,16 @@
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Creates a new texture that can be written in to.
|
||||
* Initializes a texture that can be written in to.
|
||||
*
|
||||
* @param texture Texture to initialize.
|
||||
* @param width Width of the texture (in pixels).
|
||||
* @param height Height of the texture (in pixels).
|
||||
* @param pixels Default pixel array, set to NULL to set all pixel data to 0.
|
||||
* @return The newly created texture instance.
|
||||
*/
|
||||
texture_t * textureCreate(int32_t width, int32_t height, pixel_t *pixels);
|
||||
void textureInit(texture_t *texture, int32_t width, int32_t height,
|
||||
pixel_t *pixels
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so avoid
|
||||
@@ -33,6 +35,7 @@ void textureBufferPixels(texture_t *texture,
|
||||
|
||||
/**
|
||||
* Clean a previously created texture.
|
||||
*
|
||||
* @param texture Texture to clean up.
|
||||
*/
|
||||
void textureDispose(texture_t *texture);
|
||||
+2
-15
@@ -7,19 +7,15 @@
|
||||
|
||||
#include "tileset.h"
|
||||
|
||||
tileset_t * tilesetCreate(
|
||||
tileset_t * tilesetInit(tileset_t *tileset,
|
||||
int32_t columns, int32_t rows,
|
||||
int32_t width, int32_t height,
|
||||
int32_t gapX, int32_t gapY,
|
||||
int32_t borderX, int32_t borderY
|
||||
) {
|
||||
tileset_t *tileset;
|
||||
float tdivX, tdivY;
|
||||
int32_t x, y, i;
|
||||
|
||||
tileset = malloc(sizeof(tileset_t));
|
||||
if(tileset == NULL) return NULL;
|
||||
|
||||
tileset->count = rows * columns;
|
||||
tileset->divisions = malloc(sizeof(tilesetdiv_t) * tileset->count);
|
||||
if(tileset->divisions == NULL) {
|
||||
@@ -51,21 +47,13 @@ tileset_t * tilesetCreate(
|
||||
borderY + (tileset->divY * y) + (gapY * y)
|
||||
) / height;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return tileset;
|
||||
}
|
||||
|
||||
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,
|
||||
int32_t column, int32_t row
|
||||
) {
|
||||
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,int32_t column,int32_t row) {
|
||||
return tileset->divisions[
|
||||
(column % tileset->columns) + (row * tileset->columns)
|
||||
];
|
||||
@@ -73,5 +61,4 @@ tilesetdiv_t tilesetGetDivision(tileset_t *tileset,
|
||||
|
||||
void tilesetDispose(tileset_t *tileset) {
|
||||
free(tileset->divisions);
|
||||
free(tileset);
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
/**
|
||||
* Create a tileset. Tilesets will be pre-divided to save performance later.
|
||||
*
|
||||
* @param tileset Tileset to init into.
|
||||
* @param columns Count of columns.
|
||||
* @param rows Count of rows.
|
||||
* @param width Width of the tileset.
|
||||
@@ -17,9 +18,8 @@
|
||||
* @param gapY Space between each row.
|
||||
* @param borderX Space around the edge of the tileset.
|
||||
* @param borderY Space around the edge of the tileset.
|
||||
* @returns The tileset.
|
||||
*/
|
||||
tileset_t * tilesetCreate(
|
||||
void tilesetInit(tileset_t *tileset,
|
||||
int32_t columns, int32_t rows,
|
||||
int32_t width, int32_t height,
|
||||
int32_t gapX, int32_t gapY,
|
||||
@@ -34,9 +34,7 @@ tileset_t * tilesetCreate(
|
||||
* @param row Y axis of the tileset.
|
||||
* @returns The Tileset division.
|
||||
*/
|
||||
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,
|
||||
int32_t column, int32_t row
|
||||
);
|
||||
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,int32_t column, int32_t row);
|
||||
|
||||
/**
|
||||
* Cleans a previously created tileset
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
void engineInit(engine_t *engine, game_t *game) {
|
||||
epochInit(&engine->time);
|
||||
renderInit();
|
||||
inputInit(&engine->input);
|
||||
}
|
||||
|
||||
void engineUpdateStart(engine_t *engine, game_t *game, float delta) {
|
||||
epochUpdate(&engine->time, delta);
|
||||
inputUpdate(&engine->input);
|
||||
renderFrameStart();
|
||||
}
|
||||
|
||||
bool engineUpdateEnd(engine_t *engine, game_t *game) {
|
||||
if(inputIsPressed(INPUT_NULL)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void engineDispose(engine_t *engine, game_t *game) {
|
||||
inputDispose(&engine->input);
|
||||
renderDispose();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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 "../input/input.h"
|
||||
#include "../epoch/epoch.h"
|
||||
#include "../display/render.h"
|
||||
|
||||
/**
|
||||
* Initializes the provided engine. This will initialize all of the various
|
||||
* managers for the game to use.
|
||||
*
|
||||
* @param engine Engine to initialize.
|
||||
* @param game Game that intiialized this engine.
|
||||
*/
|
||||
void engineInit(engine_t *engine, game_t *game);// TODO: This needs to return valid state.
|
||||
|
||||
/**
|
||||
* Updates the given engine at the start of a frame.
|
||||
*
|
||||
* @param engine Engine that is being updated
|
||||
* @param game Game that initialized the engine update
|
||||
* @param delta Delta tick provided by the game's platform.
|
||||
*/
|
||||
void engineUpdateStart(engine_t *engine, game_t *game, float delta);
|
||||
|
||||
/**
|
||||
* Updates the given engine at the end of a frame.
|
||||
*
|
||||
* @param engine Engine to update.
|
||||
* @param game Game that called this update.
|
||||
*/
|
||||
bool engineUpdateEnd(engine_t *engine, game_t *game);
|
||||
|
||||
/**
|
||||
* Cleanup the engine context.
|
||||
*
|
||||
* @param engine Engine to clean up.
|
||||
* @param game Game that initialized the cleanup.
|
||||
*/
|
||||
void engineDispose(engine_t *engine, game_t *game);
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "epoch.h"
|
||||
|
||||
void epochInit(epoch_t *epoch) {
|
||||
epoch->delta = EPOCH_FIXED_STEP;
|
||||
epoch->last = EPOCH_FIXED_STEP;
|
||||
epoch->current = EPOCH_FIXED_STEP + EPOCH_FIXED_STEP;
|
||||
}
|
||||
|
||||
void epochUpdate(epoch_t *epoch, float platformDelta) {
|
||||
platformDelta = mathMax(
|
||||
mathMin(platformDelta, EPOCH_FIXED_STEP),
|
||||
0
|
||||
);
|
||||
|
||||
epoch->last = epoch->current;
|
||||
epoch->current = epoch->current + platformDelta;
|
||||
epoch->delta = epoch->current - epoch->last;
|
||||
epoch->fixedDelta = EPOCH_FIXED_STEP;
|
||||
}
|
||||
@@ -9,13 +9,16 @@
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initializes the gametime global time tracking.
|
||||
* Initializes the epoch time tracking.
|
||||
*
|
||||
* @param epoch Epoch to initialize.
|
||||
*/
|
||||
void gameTimeInit();
|
||||
void epochInit(epoch_t *epoch);
|
||||
|
||||
/**
|
||||
* Ticks the current game time.
|
||||
* Ticks the current epoch time.
|
||||
*
|
||||
* @param epoch Epoch to update.
|
||||
* @param platformDelta The delta step between frames from the platform engine.
|
||||
*/
|
||||
void gameTimeUpdate(float platformDelta);
|
||||
void epochUpdate(epoch_t *epoch, float platformDelta);
|
||||
+44
-55
@@ -9,74 +9,63 @@
|
||||
|
||||
game_t GAME_STATE;
|
||||
|
||||
bool gameInit() {
|
||||
bool gameInit(game_t *game) {
|
||||
// Init the game
|
||||
GAME_STATE.name = GAME_NAME;
|
||||
|
||||
logInit();
|
||||
logText("Starting Game");
|
||||
game->name = GAME_NAME;
|
||||
|
||||
engineInit(&game->engine, game);
|
||||
|
||||
// Init
|
||||
gameTimeInit();
|
||||
renderInit();
|
||||
inputInit();
|
||||
// gameTimeInit();
|
||||
// renderInit();
|
||||
// inputInit();
|
||||
|
||||
// Load the world shader.
|
||||
GAME_STATE.shaderWorld = assetShaderLoad(
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
// // Load the world shader.
|
||||
// GAME_STATE.shaderWorld = assetShaderLoad(
|
||||
// "shaders/textured.vert", "shaders/textured.frag"
|
||||
// );
|
||||
|
||||
// Font
|
||||
GAME_STATE.fontTexture = assetTextureLoad("font.png");
|
||||
GAME_STATE.fontTileset = tilesetCreate(20, 20,
|
||||
GAME_STATE.fontTexture->width,
|
||||
GAME_STATE.fontTexture->height,
|
||||
1, 1, 1, 1
|
||||
);
|
||||
GAME_STATE.fontBatch = spriteBatchCreate(1024);
|
||||
// // Font
|
||||
// GAME_STATE.fontTexture = assetTextureLoad("font.png");
|
||||
// GAME_STATE.fontTileset = tilesetCreate(20, 20,
|
||||
// GAME_STATE.fontTexture->width,
|
||||
// GAME_STATE.fontTexture->height,
|
||||
// 1, 1, 1, 1
|
||||
// );
|
||||
// GAME_STATE.fontBatch = spriteBatchCreate(1024);
|
||||
|
||||
// Prepare the renderer.
|
||||
holdemRenderFrameInit();
|
||||
holdemRenderWorldInit();
|
||||
holdemRenderPlayerInit();
|
||||
holdemRenderCardInit();
|
||||
holdemRenderChipInit();
|
||||
|
||||
// Prepare the action manager
|
||||
pokerActionInit();
|
||||
|
||||
// Start the first action
|
||||
pokerActionAdd(actionStart());
|
||||
// // Prepare the renderer.
|
||||
// pokerInit(&GAME_STATE.poker);
|
||||
// holdemRenderFrameInit();
|
||||
// holdemRenderWorldInit();
|
||||
// holdemRenderPlayerInit();
|
||||
// holdemRenderCardInit();
|
||||
// holdemRenderChipInit();
|
||||
|
||||
// Init the input manger.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gameUpdate(float platformDelta) {
|
||||
gameTimeUpdate(platformDelta);
|
||||
renderFrameStart();
|
||||
inputUpdate();
|
||||
|
||||
shaderUse(GAME_STATE.shaderWorld);// TODO: remove
|
||||
|
||||
// Update the frame buffers and action queue
|
||||
holdemRenderFrameUpdate();
|
||||
pokerActionUpdate();
|
||||
bool gameUpdate(game_t *game, float platformDelta) {
|
||||
engineUpdateStart(&game->engine, game, platformDelta);
|
||||
engineUpdateEnd(&game->engine, game);
|
||||
|
||||
// Render things on each frame, then render those frames.
|
||||
holdemRenderFrameUseLeft();
|
||||
holdemRenderWorld();
|
||||
holdemRenderFrameUseRight();
|
||||
holdemRenderWorld();
|
||||
holdemRenderFrameBack();
|
||||
// shaderUse(GAME_STATE.shaderWorld);// TODO: remove
|
||||
|
||||
// // Update the frame buffers and action queue
|
||||
// holdemRenderFrameUpdate();
|
||||
// pokerActionUpdate();
|
||||
|
||||
if(inputIsPressed(INPUT_NULL)) return false;
|
||||
return true;
|
||||
// // Render things on each frame, then render those frames.
|
||||
// holdemRenderFrameUseLeft();
|
||||
// holdemRenderWorld();
|
||||
// holdemRenderFrameUseRight();
|
||||
// holdemRenderWorld();
|
||||
// holdemRenderFrameBack();
|
||||
}
|
||||
|
||||
void gameDispose() {
|
||||
pokerActionDispose();
|
||||
shaderDispose(GAME_STATE.shaderWorld);
|
||||
inputDispose();
|
||||
renderDispose();
|
||||
void gameDispose(game_t *game) {
|
||||
engineDispose(&game->engine, game);
|
||||
// pokerActionDispose();
|
||||
// shaderDispose(GAME_STATE.shaderWorld);
|
||||
}
|
||||
+4
-19
@@ -5,29 +5,14 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "gametime.h"
|
||||
#include "../display/render.h"
|
||||
#include "../display/camera.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/gui/font.h"
|
||||
#include "../file/asset.h"
|
||||
#include "../input/input.h"
|
||||
#include "../debug/log.h"
|
||||
#include "../poker/action/action.h"
|
||||
#include "../poker/action/start.h"
|
||||
#include "../poker/render/player.h"
|
||||
#include "../poker/render/card.h"
|
||||
#include "../poker/render/chip.h"
|
||||
#include "../poker/render/frame.h"
|
||||
#include "../poker/render/look.h"
|
||||
#include "../poker/render/world.h"
|
||||
#include "../engine/engine.h"
|
||||
|
||||
/**
|
||||
* Initialize the game context.
|
||||
*
|
||||
* @return True if successful, otherwise false.
|
||||
*/
|
||||
bool gameInit();
|
||||
bool gameInit(game_t *game);
|
||||
|
||||
/**
|
||||
* Tick the main game loop.
|
||||
@@ -35,9 +20,9 @@ bool gameInit();
|
||||
* @param platformDelta The platform tick delta between the last render.
|
||||
* @return True if successful, false if safe exit requested..
|
||||
*/
|
||||
bool gameUpdate(float platformDelta);
|
||||
bool gameUpdate(game_t *game, float platformDelta);
|
||||
|
||||
/**
|
||||
* Cleanup the game instance.
|
||||
*/
|
||||
void gameDispose();
|
||||
void gameDispose(game_t *game);
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "gametime.h"
|
||||
|
||||
gametime_t TIME_STATE;
|
||||
|
||||
void gameTimeInit() {
|
||||
TIME_STATE.delta = GAMETIME_FIXED_STEP;
|
||||
TIME_STATE.last = GAMETIME_FIXED_STEP;
|
||||
TIME_STATE.current = GAMETIME_FIXED_STEP + GAMETIME_FIXED_STEP;
|
||||
}
|
||||
|
||||
void gameTimeUpdate(float platformDelta) {
|
||||
platformDelta = mathMax(
|
||||
mathMin(platformDelta, GAMETIME_FIXED_STEP),
|
||||
0
|
||||
);
|
||||
|
||||
TIME_STATE.last = TIME_STATE.current;
|
||||
TIME_STATE.current = TIME_STATE.current + platformDelta;
|
||||
TIME_STATE.delta = TIME_STATE.current - TIME_STATE.last;
|
||||
TIME_STATE.fixedDelta = GAMETIME_FIXED_STEP;
|
||||
}
|
||||
+33
-35
@@ -7,96 +7,94 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
input_t INPUT_STATE;
|
||||
|
||||
void inputInit() {
|
||||
void inputInit(input_t *input) {
|
||||
int32_t i;
|
||||
|
||||
// Setup the bind lists
|
||||
for(i = 0; i < INPUT_BIND_COUNT; i++) {
|
||||
INPUT_STATE.bindMap[i] = listCreate();
|
||||
input->bindMap[i] = listCreate();
|
||||
}
|
||||
|
||||
INPUT_STATE.current = INPUT_STATE.inputsA;
|
||||
INPUT_STATE.previous = INPUT_STATE.inputsB;
|
||||
input->current = input->inputsA;
|
||||
input->previous = input->inputsB;
|
||||
|
||||
// Create the buffer, zero all the values out.
|
||||
memset(&INPUT_STATE.buffer, 0, sizeof(inputval_t)*INPUT_SOURCE_COUNT);
|
||||
memset(&input->buffer, 0, sizeof(inputval_t)*INPUT_SOURCE_COUNT);
|
||||
}
|
||||
|
||||
void inputUpdate() {
|
||||
void inputUpdate(input_t *input) {
|
||||
int32_t i;
|
||||
listentry_t *item;
|
||||
inputval_t value;
|
||||
|
||||
// Flip the states to save memory.
|
||||
inputval_t *currentCurrent = INPUT_STATE.current;
|
||||
INPUT_STATE.current = INPUT_STATE.previous;
|
||||
INPUT_STATE.previous = currentCurrent;
|
||||
inputval_t *currentCurrent = input->current;
|
||||
input->current = input->previous;
|
||||
input->previous = currentCurrent;
|
||||
|
||||
// Now look at each bind...
|
||||
for(i = 0; i < INPUT_BIND_COUNT; i++) {
|
||||
// Now get the list of input sources bound to this input
|
||||
item = INPUT_STATE.bindMap[i]->start;
|
||||
item = input->bindMap[i]->start;
|
||||
value = 0;
|
||||
|
||||
// For each input source, add the value from the buffer
|
||||
while(item != NULL) {
|
||||
value += INPUT_STATE.buffer[(inputsource_t)item->data];
|
||||
value += input->buffer[(inputsource_t)item->data];
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
// Set to the current state.
|
||||
INPUT_STATE.current[i] = value;
|
||||
input->current[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void inputDispose() {
|
||||
void inputDispose(input_t *input) {
|
||||
int32_t i;
|
||||
|
||||
// Free up the bind lists
|
||||
for(i = 0; i < INPUT_BIND_COUNT; i++) {
|
||||
listDispose(INPUT_STATE.bindMap[i], false);
|
||||
listDispose(input->bindMap[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
void inputBind(inputbind_t bind, inputsource_t source) {
|
||||
listAdd(INPUT_STATE.bindMap[bind], (void *)source);
|
||||
void inputBind(input_t *input, inputbind_t bind, inputsource_t source) {
|
||||
listAdd(input->bindMap[bind], (void *)source);
|
||||
}
|
||||
|
||||
void inputUnbind(inputbind_t bind, inputsource_t source) {
|
||||
listRemove(INPUT_STATE.bindMap[bind], (void *)source);
|
||||
void inputUnbind(input_t *input, inputbind_t bind, inputsource_t source) {
|
||||
listRemove(input->bindMap[bind], (void *)source);
|
||||
}
|
||||
|
||||
bool inputIsDown(inputbind_t binding) {
|
||||
return INPUT_STATE.current[binding] != 0;
|
||||
bool inputIsDown(input_t *input, inputbind_t binding) {
|
||||
return input->current[binding] != 0;
|
||||
}
|
||||
|
||||
bool inputIsUp(inputbind_t binding) {
|
||||
return INPUT_STATE.current[binding] == 0;
|
||||
bool inputIsUp(input_t *input, inputbind_t binding) {
|
||||
return input->current[binding] == 0;
|
||||
}
|
||||
|
||||
bool inputIsPressed(inputbind_t binding) {
|
||||
bool inputIsPressed(input_t *input, inputbind_t binding) {
|
||||
return (
|
||||
INPUT_STATE.previous[binding] == 0 &&
|
||||
INPUT_STATE.current[binding] != 0
|
||||
input->previous[binding] == 0 &&
|
||||
input->current[binding] != 0
|
||||
);
|
||||
}
|
||||
|
||||
bool inputIsReleased(inputbind_t binding) {
|
||||
return INPUT_STATE.current[binding]==0 && INPUT_STATE.previous[binding] != 0;
|
||||
bool inputIsReleased(input_t *input, inputbind_t binding) {
|
||||
return input->current[binding]==0 && input->previous[binding] != 0;
|
||||
}
|
||||
|
||||
inputval_t inputGetAxis(inputbind_t binding) {
|
||||
return INPUT_STATE.current[binding];
|
||||
inputval_t inputGetAxis(input_t *input, inputbind_t binding) {
|
||||
return input->current[binding];
|
||||
}
|
||||
|
||||
float inputGetFullAxis(inputbind_t positive,
|
||||
float inputGetFullAxis(input_t *input, inputbind_t positive,
|
||||
inputbind_t negative
|
||||
) {
|
||||
return -INPUT_STATE.current[negative] + INPUT_STATE.current[positive];
|
||||
return -input->current[negative] + input->current[positive];
|
||||
}
|
||||
|
||||
float inputGetAccuated(inputbind_t binding) {
|
||||
return INPUT_STATE.times[binding];
|
||||
float inputGetAccuated(input_t *input, inputbind_t binding) {
|
||||
return input->times[binding];
|
||||
}
|
||||
+27
-12
@@ -9,78 +9,91 @@
|
||||
|
||||
/**
|
||||
* Initializes the input manager.
|
||||
*
|
||||
* @param input The input manager to initialize.
|
||||
*/
|
||||
void inputInit();
|
||||
void inputInit(input_t *input);
|
||||
|
||||
/**
|
||||
* Tick the input manager.
|
||||
*
|
||||
* @param input The input manager to update.
|
||||
*/
|
||||
void inputUpdate();
|
||||
void inputUpdate(input_t *input);
|
||||
|
||||
/**
|
||||
* Destroy the input manager and cleanup.
|
||||
*
|
||||
* @param input The input manager to dispose.
|
||||
*/
|
||||
void inputDispose();
|
||||
void inputDispose(input_t *input);
|
||||
|
||||
/**
|
||||
* Binds the given input binding to the input source. Essentially allowing any
|
||||
* time we fetch the state of bind, we will read the value from source.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param bind The binding to bind against.
|
||||
* @param source The source that is being bound.
|
||||
*/
|
||||
void inputBind(inputbind_t bind, inputsource_t source);
|
||||
void inputBind(input_t *input, inputbind_t bind, inputsource_t source);
|
||||
|
||||
/**
|
||||
* Unbind a previously bound input source from a binding. This method is costly.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param bind The binding to unbind from.
|
||||
* @param source The source that is being unbound.
|
||||
*/
|
||||
void inputUnbind(inputbind_t bind, inputsource_t source);
|
||||
void inputUnbind(input_t *input, inputbind_t bind, inputsource_t source);
|
||||
|
||||
/**
|
||||
* Is the current input "down", being pressed, being moved, not in a state
|
||||
* of rest.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return True if the input vector is non-zero.
|
||||
*/
|
||||
bool inputIsDown(inputbind_t binding);
|
||||
bool inputIsDown(input_t *input, inputbind_t binding);
|
||||
|
||||
/**
|
||||
* Is the current input "up", in a state of rest, not being actioned, moved.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return True if input vector is zero
|
||||
*/
|
||||
bool inputIsUp(inputbind_t binding);
|
||||
bool inputIsUp(input_t *input, inputbind_t binding);
|
||||
|
||||
/**
|
||||
* Returns true on the first tick that an input was actioned/downed.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return True if the input vector was non-zeroed this tick but not last.
|
||||
*/
|
||||
bool inputIsPressed(inputbind_t binding);
|
||||
bool inputIsPressed(input_t *input, inputbind_t binding);
|
||||
|
||||
/**
|
||||
* Returns true on the first tick that an input was released/upped.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return True if the input vector was zeroed this tick but not last.
|
||||
*/
|
||||
bool inputIsReleased(inputbind_t binding);
|
||||
bool inputIsReleased(input_t *input, inputbind_t binding);
|
||||
|
||||
/**
|
||||
* Returns the raw input value as a float between 0 and 1. For digital (buttons)
|
||||
* this will typicall be 0 or 1 only. Other analogue inputs will have anywhere
|
||||
* within the range.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return Input state of the axis.
|
||||
*/
|
||||
inputval_t inputGetAxis(inputbind_t binding);
|
||||
inputval_t inputGetAxis(input_t *input, inputbind_t binding);
|
||||
|
||||
/**
|
||||
* Returns a raw input value between -1 and 1 between two axis. This would be
|
||||
@@ -88,17 +101,19 @@ inputval_t inputGetAxis(inputbind_t binding);
|
||||
* for a positive input and another for a negative input, typically a game
|
||||
* controller's analogue sticks.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param postitive The positive axis binding.
|
||||
* @param negative The negative axis binding.
|
||||
* @return A float between -1 and 1 representing the result of both.
|
||||
*/
|
||||
float inputGetFullAxis(inputbind_t positive, inputbind_t negative);
|
||||
float inputGetFullAxis(input_t *input, inputbind_t positive, inputbind_t negative);
|
||||
|
||||
/**
|
||||
* Returns the time that an input was actuated at. Actuate would count as a
|
||||
* non-zero input for analogue inputs.
|
||||
*
|
||||
* @param input The input manager.
|
||||
* @param binding The previously bound input binding.
|
||||
* @return Game Engine time that an input was non-zeroed
|
||||
*/
|
||||
float inputGetAccuated(inputbind_t binding);
|
||||
float inputGetAccuated(input_t *input, inputbind_t binding);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -6,7 +6,6 @@
|
||||
#include "glwfwplatform.h"
|
||||
|
||||
GLFWwindow *window = NULL;
|
||||
game_t *runningGame = NULL;
|
||||
|
||||
int32_t main() {
|
||||
// Attempt to init GLFW
|
||||
@@ -33,10 +32,13 @@ int32_t main() {
|
||||
glfwSetWindowSizeCallback(window, &glfwOnResize);
|
||||
glfwSetKeyCallback(window, &glfwOnKey);
|
||||
|
||||
glfwSetErrorCallback (&glfwOnError);
|
||||
glfwSetErrorCallback(&glfwOnError);
|
||||
|
||||
// Prepare the game
|
||||
game_t *game = &GAME_STATE;
|
||||
|
||||
// Init the game
|
||||
if(gameInit()) {
|
||||
if(gameInit(game)) {
|
||||
// Bind initial keys
|
||||
inputBind(INPUT_NULL, (inputsource_t)GLFW_KEY_ESCAPE);
|
||||
inputBind(INPUT_DEBUG_UP, (inputsource_t)GLFW_KEY_W);
|
||||
@@ -76,13 +78,13 @@ int32_t main() {
|
||||
time = newTime;
|
||||
|
||||
// Tick the engine.
|
||||
if(!gameUpdate(fDelta)) break;
|
||||
if(!gameUpdate(game, fDelta)) break;
|
||||
glfwSwapBuffers(window);
|
||||
sleep(0);//Fixes some weird high CPU bug, not actually necessary.
|
||||
}
|
||||
|
||||
// Game has finished running, cleanup.
|
||||
gameDispose();
|
||||
gameDispose(game);
|
||||
}
|
||||
|
||||
// Terminate the GLFW context.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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);
|
||||
File renamed without changes.
File renamed without changes.
@@ -33,7 +33,7 @@ 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 < HOLDEM_DEALER_HAND) {
|
||||
if(GAME_STATE.cardsFacing < POKER_DEALER_HAND) {
|
||||
pokerActionAdd(actionFlop());
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "flop.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
typdef struct {
|
||||
uint8_t player;
|
||||
} actionaidata_t;
|
||||
|
||||
pokeraction_t actionAi();
|
||||
|
||||
void actionAiInit(int32_t index, void *data);
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user