Playing around with talking and input

This commit is contained in:
2021-05-26 08:10:37 -07:00
parent b81c4ca604
commit 62928b7c69
9 changed files with 61 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#define INPUT_DOWN (inputbind_t)0x81 #define INPUT_DOWN (inputbind_t)0x81
#define INPUT_LEFT (inputbind_t)0x82 #define INPUT_LEFT (inputbind_t)0x82
#define INPUT_RIGHT (inputbind_t)0x83 #define INPUT_RIGHT (inputbind_t)0x83
#define INPUT_ACCEPT (inputbind_t)0x84
#define INPUT_BIND_COUNT 0xFF #define INPUT_BIND_COUNT 0xFF

View File

@ -15,13 +15,7 @@ bool gameInit(game_t *game) {
engineInit(&game->engine, game); engineInit(&game->engine, game);
// Hand off to the poker logic. // Hand off to the poker logic.
pokerInit(&game->poker, &game->engine.render); pokerInit(&game->poker, &game->engine);
// char *text = "Ayy\nNice meme";
// fonttextinfo_t info = fontGetTextInfo(&font, text);
// fontmeasure_t *measure = fontTextMeasure(&font, text, &info);
// fontTextInitFromMeasure(&font, &quad, text, &info, measure);
// fontTextMeasureDispose(measure);
return true; return true;
} }
@ -31,7 +25,7 @@ bool gameUpdate(game_t *game, float platformDelta) {
engineUpdateStart(&game->engine, game, platformDelta); engineUpdateStart(&game->engine, game, platformDelta);
// Hand off to the poker logic // Hand off to the poker logic
pokerUpdate(&game->poker, &game->engine.render); pokerUpdate(&game->poker, &game->engine);
// Hand back to the engine. // Hand back to the engine.
return engineUpdateEnd(&game->engine, game); return engineUpdateEnd(&game->engine, game);

View File

@ -63,6 +63,9 @@ int32_t main() {
inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_S); inputBind(input, INPUT_DOWN, (inputsource_t)GLFW_KEY_S);
inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_A); inputBind(input, INPUT_LEFT, (inputsource_t)GLFW_KEY_A);
inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_D); inputBind(input, INPUT_RIGHT, (inputsource_t)GLFW_KEY_D);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_E);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_ENTER);
inputBind(input, INPUT_ACCEPT, (inputsource_t)GLFW_KEY_SPACE);
// Init the render resolution // Init the render resolution
renderSetResolution(&game->engine.render, renderSetResolution(&game->engine.render,

View File

@ -7,7 +7,7 @@
#include "poker.h" #include "poker.h"
void pokerInit(poker_t *poker, render_t *render) { void pokerInit(poker_t *poker, engine_t *engine) {
// Load the main shader // Load the main shader
assetShaderLoad(&poker->shader, assetShaderLoad(&poker->shader,
"shaders/textured.vert", "shaders/textured.frag" "shaders/textured.vert", "shaders/textured.frag"
@ -17,7 +17,7 @@ void pokerInit(poker_t *poker, render_t *render) {
assetFontLoad(&poker->font, "fonts/opensans/OpenSans-Bold.ttf"); assetFontLoad(&poker->font, "fonts/opensans/OpenSans-Bold.ttf");
// Initialize the render stuffs. // Initialize the render stuffs.
pokerFrameInit(poker, render); pokerFrameInit(poker, &engine->render);
pokerWorldInit(poker); pokerWorldInit(poker);
pokerCardInit(poker); pokerCardInit(poker);
pokerPlayerInit(poker); pokerPlayerInit(poker);
@ -27,7 +27,7 @@ void pokerInit(poker_t *poker, render_t *render) {
pokerMatchInit(poker); pokerMatchInit(poker);
} }
void pokerUpdate(poker_t *poker, render_t *render) { void pokerUpdate(poker_t *poker, engine_t *engine) {
// Game Logic // Game Logic
switch(poker->round) { switch(poker->round) {
case POKER_ROUND_MATCH: case POKER_ROUND_MATCH:
@ -39,15 +39,15 @@ void pokerUpdate(poker_t *poker, render_t *render) {
// Rendering // Rendering
shaderUse(&poker->shader); shaderUse(&poker->shader);
pokerFrameWorld(poker, render); pokerFrameWorld(poker, &engine->render);
pokerWorldRender(poker); pokerWorldRender(poker);
for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) { for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) {
uint8_t seat = pokerPlayerGetSeatForPlayer(pi); uint8_t seat = pokerPlayerGetSeatForPlayer(pi);
pokerPlayerRender(poker, poker->players + pi, seat); pokerPlayerRender(poker, poker->players + pi, seat);
} }
pokerFrameGui(poker, render); pokerFrameGui(poker, &engine->render);
pokerTalkRender(poker); pokerTalkRender(poker, &engine->input);
poker->textLastWidth = poker->guiWidth; poker->textLastWidth = poker->guiWidth;
} }

View File

@ -24,16 +24,16 @@
/** /**
* Initializes the poker context for the first time. * Initializes the poker context for the first time.
* @param poker Poker context to initialize. * @param poker Poker context to initialize.
* @param render Rendering context. * @param engine Rendering context.
*/ */
void pokerInit(poker_t *poker, render_t *render); void pokerInit(poker_t *poker, engine_t *engine);
/** /**
* Updates the poker context. * Updates the poker context.
* @param poker Poker game to update. * @param poker Poker game context.
* @param render Render manager to use. * @param engine Engine that is running the game.
*/ */
void pokerUpdate(poker_t *poker, render_t *render); void pokerUpdate(poker_t *poker, engine_t *engine);
/** /**
* Cleans an existing poker game instance. * Cleans an existing poker game instance.

View File

@ -25,6 +25,7 @@ void pokerTalkTextRebuffer(poker_t *poker) {
if(poker->talkTextInfo != NULL) { if(poker->talkTextInfo != NULL) {
fontTextInfoDispose(poker->talkTextInfo); fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive); primitiveDispose(&poker->talkPrimitive);
poker->talkTextInfo = NULL;
} }
} }
@ -35,7 +36,7 @@ void pokerTalkTextRebuffer(poker_t *poker) {
fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo); fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo);
} }
void pokerTalkRender(poker_t *poker) { void pokerTalkRender(poker_t *poker, input_t *input) {
pokerTalkTextRebuffer(poker); pokerTalkTextRebuffer(poker);
if(poker->talkTextInfo == NULL) return; if(poker->talkTextInfo == NULL) return;
@ -46,8 +47,14 @@ void pokerTalkRender(poker_t *poker) {
); );
shaderUseTexture(&poker->shader, &poker->font.texture); shaderUseTexture(&poker->shader, &poker->font.texture);
primitiveDraw(&poker->talkPrimitive, 0, -1); primitiveDraw(&poker->talkPrimitive, 0, -1);
if(inputIsPressed(input, INPUT_ACCEPT)) poker->talkText = NULL;
} }
void pokerTalk(poker_t *poker, char *text) { void pokerTalk(poker_t *poker, char *text) {
poker->talkText = text; poker->talkText = text;
}
bool pokerTalkIsTalking(poker_t *poker) {
return poker->talkTextInfo != NULL;
} }

View File

@ -10,13 +10,44 @@
#include "../../display/gui/font.h" #include "../../display/gui/font.h"
#include "../../display/primitive.h" #include "../../display/primitive.h"
#include "../../display/shader.h" #include "../../display/shader.h"
#include "../../input/input.h"
/**
* Initializes the talk manager.
* @param poker The poker game context.
*/
void pokerTalkInit(poker_t *poker); void pokerTalkInit(poker_t *poker);
/**
* Disposes and cleans the talk manager context.
* @param poker Poker instance.
*/
void pokerTalkDispose(poker_t *poker); void pokerTalkDispose(poker_t *poker);
/**
* Internal method. Checks for changes and rebuffers the talk text information
* when scene changes occur.
* @param poker Poker game context to buffer for.
*/
void pokerTalkTextRebuffer(poker_t *poker); void pokerTalkTextRebuffer(poker_t *poker);
void pokerTalkRender(poker_t *poker); /**
* Tick render method for the poker talk manager.
* @param poker Poker manager context.
* @param input Input manager to listen to.
*/
void pokerTalkRender(poker_t *poker, input_t *input);
void pokerTalk(poker_t *poker, char *text); /**
* Requests the talk manager to begin speaking some text.
* @param poker Poker game context
* @param text Text to speak. Please ensure this is kept alive during talk.
*/
void pokerTalk(poker_t *poker, char *text);
/**
* Returns true if the poker text manager is still running the talk.
* @param poker Poker manager.
* @returns True while the game is still running active text.
*/
bool pokerTalkIsTalking(poker_t *poker);

View File

@ -42,4 +42,5 @@ void pokerDealInit(poker_t *poker) {
poker->deck[y] = poker->deck[x];// Move my card there poker->deck[y] = poker->deck[x];// Move my card there
poker->deck[x] = temporary;// Put other card here. poker->deck[x] = temporary;// Put other card here.
} }
printf("Deal\n");
} }

View File

@ -26,5 +26,6 @@ void pokerMatchInit(poker_t *poker) {
} }
void pokerMatchUpdate(poker_t *poker) { void pokerMatchUpdate(poker_t *poker) {
if(pokerTalkIsTalking(poker)) return;
pokerDealInit(poker);
} }