diff --git a/IDEA.md b/IDEA.md index 2903e09b..e3d380cf 100644 --- a/IDEA.md +++ b/IDEA.md @@ -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 \ No newline at end of file +- Make a clone of the string into font measure pointing only to real chars? \ No newline at end of file diff --git a/include/dawn/dawn.h b/include/dawn/dawn.h index 46467fde..402f1503 100644 --- a/include/dawn/dawn.h +++ b/include/dawn/dawn.h @@ -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" diff --git a/include/dawn/poker/poker.h b/include/dawn/poker/poker.h index 8b4c5a39..0e67c22a 100644 --- a/include/dawn/poker/poker.h +++ b/include/dawn/poker/poker.h @@ -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; diff --git a/include/dawn/poker/strings.h b/include/dawn/poker/strings.h new file mode 100644 index 00000000..857df1af --- /dev/null +++ b/include/dawn/poker/strings.h @@ -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." \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index ba60fca0..b175ae28 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -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); } \ No newline at end of file diff --git a/src/poker/poker.h b/src/poker/poker.h index ffb39dc8..8f7ae637 100644 --- a/src/poker/poker.h +++ b/src/poker/poker.h @@ -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" diff --git a/src/poker/render/frame.c b/src/poker/render/frame.c index ad9ca0f5..0d07523b 100644 --- a/src/poker/render/frame.c +++ b/src/poker/render/frame.c @@ -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); } \ No newline at end of file diff --git a/src/poker/render/talk.c b/src/poker/render/talk.c index 60fd1356..22cb30a6 100644 --- a/src/poker/render/talk.c +++ b/src/poker/render/talk.c @@ -5,4 +5,47 @@ * https://opensource.org/licenses/MIT */ -#include "talk.h" \ No newline at end of file +#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; +} \ No newline at end of file diff --git a/src/poker/render/talk.h b/src/poker/render/talk.h index 05e74623..27f7116b 100644 --- a/src/poker/render/talk.h +++ b/src/poker/render/talk.h @@ -8,4 +8,15 @@ #pragma once #include #include "../../display/gui/font.h" -#include "../../display/primitive.h" \ No newline at end of file +#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); \ No newline at end of file diff --git a/src/poker/round/match.c b/src/poker/round/match.c index 6803978c..88a2ca14 100644 --- a/src/poker/round/match.c +++ b/src/poker/round/match.c @@ -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) { diff --git a/src/poker/round/match.h b/src/poker/round/match.h index ef2cb1d3..425f1587 100644 --- a/src/poker/round/match.h +++ b/src/poker/round/match.h @@ -9,6 +9,7 @@ #include #include "deal.h" #include "../render/look.h" +#include "../render/talk.h" /** * Init the poker match round.