Roughing talk logic

This commit is contained in:
2021-05-25 09:52:57 -07:00
parent 6e6497ca43
commit ffaaa91a9e
11 changed files with 86 additions and 19 deletions

View File

@ -1,7 +1,2 @@
- Make font measure take in a pointer to a primitive to offer auto buffering of verts
- Make a clone of the string into font measure pointing only to real chars?
- How to do text wrapping efficiently?
- Two pointers, one for current char and one for the last known text position.
- Start by measuring whole string, this will give me n chars and let me know straight away if text fits
- Half divide the pointer to try and find the mid point and figure out if I should go up or down, keep halfing until finding the below then iterate up
- Make a clone of the string into font measure pointing only to real chars?

View File

@ -42,6 +42,7 @@
#include "poker/player.h"
#include "poker/poker.h"
#include "poker/render.h"
#include "poker/strings.h"
// Utility Objects
#include "util/list.h"

View File

@ -80,11 +80,18 @@ typedef struct {
/** Rendering Assets */
framebuffer_t frameWorld;
framebuffer_t frameGui;
font_t font;
shader_t shader;
camera_t cameraWorld;
camera_t cameraGui;
/** Talk related */
float lastWidth, lastHeight;
primitive_t talkPrimitive;
char *talkText;
fonttextinfo_t *talkTextInfo;
texture_t dealerTexture;
tileset_t dealerTileset;
primitive_t dealerPrimitive;

View File

@ -0,0 +1,11 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#define POKER_TALK_MATCH_START "The game is no-limits Texas Hold'em."

View File

@ -21,6 +21,7 @@ void pokerInit(poker_t *poker, render_t *render) {
pokerWorldInit(poker);
pokerCardInit(poker);
pokerPlayerInit(poker);
pokerTalkInit(poker);
// Hand over to the deal for the first time.
pokerMatchInit(poker);
@ -46,9 +47,11 @@ void pokerUpdate(poker_t *poker, render_t *render) {
}
pokerFrameGui(poker, render);
pokerTalkRender(poker, render);
}
void pokerDispose(poker_t * poker) {
pokerTalkDispose(poker);
pokerWorldDispose(poker);
shaderDispose(&poker->shader);
}

View File

@ -14,6 +14,7 @@
#include "render/card.h"
#include "render/player.h"
#include "render/look.h"
#include "render/talk.h"
#include "../file/asset.h"
#include "../display/shader.h"

View File

@ -7,16 +7,14 @@
#include "frame.h"
primitive_t bruh;
void pokerFrameInit(poker_t *poker, render_t *render) {
frameBufferInit(&poker->frameWorld, render->width, render->height);
frameBufferInit(&poker->frameGui, render->width, render->height);
fonttextinfo_t *info;
char *text = "Hello world how are you today? I'm doing fine myself.";
info = fontTextClamp(&poker->font, text, 16, 500);
fontTextInit(&poker->font, &bruh, info);
// fonttextinfo_t *info;
// char *text = "Hello world how are you today? I'm doing fine myself.";
// info = fontTextClamp(&poker->font, text, 16, 500);
// fontTextInit(&poker->font, &bruh, info);
}
void pokerFrameWorld(poker_t *poker, render_t *render) {
@ -44,8 +42,4 @@ void pokerFrameGui(poker_t *poker, render_t *render) {
);
cameraLookAt(&poker->cameraGui, 0, 0, 5, 0, 0, 0);
shaderUseCamera(&poker->shader, &poker->cameraGui);
shaderUsePosition(&poker->shader, 0,0,0, 0,0,0);
shaderUseTexture(&poker->shader, &poker->font.texture);
primitiveDraw(&bruh, 0, -1);
}

View File

@ -5,4 +5,47 @@
* https://opensource.org/licenses/MIT
*/
#include "talk.h"
#include "talk.h"
#define SCALE 16
void pokerTalkInit(poker_t *poker) {
poker->talkText = NULL;
poker->talkTextInfo = NULL;
poker->lastWidth = 0, poker->lastHeight = 0;
}
void pokerTalkDispose(poker_t *poker) {
if(poker->talkTextInfo == NULL) return;
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
}
void pokerTalkTextRebuffer(poker_t *poker, render_t *render) {
// Check if we need to force a redraw or not.
if(poker->talkText == NULL || poker->lastWidth != render->width) {
if(poker->talkTextInfo != NULL) {
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
}
}
if(poker->talkText == NULL) return;
// Rebuffer
poker->talkTextInfo = fontTextClamp(&poker->font, poker->talkText, SCALE,
render->width
);
fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo);
}
void pokerTalkRender(poker_t *poker, render_t *render) {
pokerTalkTextRebuffer(poker, render);
if(poker->talkTextInfo == NULL) return;
shaderUsePosition(&poker->shader, 0,0,0, 0,0,0);
shaderUseTexture(&poker->shader, &poker->font.texture);
primitiveDraw(&poker->talkPrimitive, 0, -1);
}
void pokerTalk(poker_t *poker, char *text) {
poker->talkText = text;
}

View File

@ -8,4 +8,15 @@
#pragma once
#include <dawn/dawn.h>
#include "../../display/gui/font.h"
#include "../../display/primitive.h"
#include "../../display/primitive.h"
#include "../../display/shader.h"
void pokerTalkInit(poker_t *poker);
void pokerTalkDispose(poker_t *poker);
void pokerTalkTextRebuffer(poker_t *poker, render_t *render);
void pokerTalkRender(poker_t *poker, render_t *render);
void pokerTalk(poker_t *poker, char *text);

View File

@ -22,7 +22,7 @@ void pokerMatchInit(poker_t *poker) {
poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT;
}
printf("Match start\n");
pokerTalk(poker, POKER_TALK_MATCH_START);
}
void pokerMatchUpdate(poker_t *poker) {

View File

@ -9,6 +9,7 @@
#include <dawn/dawn.h>
#include "deal.h"
#include "../render/look.h"
#include "../render/talk.h"
/**
* Init the poker match round.