diff --git a/include/dawn/dawn.h b/include/dawn/dawn.h index a5aba906..c52c29be 100644 --- a/include/dawn/dawn.h +++ b/include/dawn/dawn.h @@ -60,6 +60,7 @@ #include "poker/winner.h" // User Interface Objects +#include "ui/frame.h" #include "ui/label.h" // Utility Objects diff --git a/include/dawn/game/poker/pokergameassets.h b/include/dawn/game/poker/pokergameassets.h index 8f9b2eb3..bb84fd4d 100644 --- a/include/dawn/game/poker/pokergameassets.h +++ b/include/dawn/game/poker/pokergameassets.h @@ -14,4 +14,5 @@ typedef struct { font_t font; shader_t shader; language_t language; + texture_t testTexture; } pokergameassets_t; \ No newline at end of file diff --git a/include/dawn/ui/frame.h b/include/dawn/ui/frame.h new file mode 100644 index 00000000..0c9b55fe --- /dev/null +++ b/include/dawn/ui/frame.h @@ -0,0 +1,20 @@ +/** + * 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 "../display/gui/font.h" + +#define FRAME_BORDER_SIZE 16 +#define FRAME_PRIMITIVE_COUNT 9 + +typedef struct { + float x, y, z; + texture_t *texture; + primitive_t primitive; +} frame_t; \ No newline at end of file diff --git a/include/dawn/util/string.h b/include/dawn/util/string.h index 3bc43162..bc3d9fec 100644 --- a/include/dawn/util/string.h +++ b/include/dawn/util/string.h @@ -9,8 +9,10 @@ #include "../libs.h" #define STRING_HANDLEBAR_KEY_MAXLENGTH 32 -#define STRING_HANDLEBAR_LIST_VARIABLE_SIZE 512 -#define STRING_HANDLEBAR_LIST_VARIABLE_COUNT 64 + +#define STRING_STACK_STRING_SIZE 256 +#define STRING_STACK_STRING_COUNT 128 +#define STRING_STACK_BUFFER STRING_STACK_STRING_SIZE * STRING_STACK_STRING_COUNT /** Representation of a String Handlebar Variable */ typedef struct { @@ -20,9 +22,12 @@ typedef struct { char *value; } stringhandlebarvariable_t; +/** Definition of a string stack to push and pop strings from. */ typedef struct { - char buffer[ - STRING_HANDLEBAR_LIST_VARIABLE_SIZE * STRING_HANDLEBAR_LIST_VARIABLE_COUNT - ]; - stringhandlebarvariable_t variables[STRING_HANDLEBAR_LIST_VARIABLE_COUNT]; -} stringhandlebarvariablelist_t; \ No newline at end of file + /** Raw char buffer, for holding strings */ + char buffer[STRING_STACK_BUFFER]; + /** Strings themselves */ + char *strings[STRING_STACK_STRING_COUNT]; + /** How many strings are on the stack */ + int32_t size; +} stringstack_t; \ No newline at end of file diff --git a/src/game/game.c b/src/game/game.c index f0c39eaf..fe90b578 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -7,8 +7,6 @@ #include "game.h" -language_t language; - bool gameInit(game_t *game) { // Init the engine and the rendering pipeline engineInit(&game->engine, game); diff --git a/src/game/poker/pokergame.c b/src/game/poker/pokergame.c index 0993973f..9011a86e 100644 --- a/src/game/poker/pokergame.c +++ b/src/game/poker/pokergame.c @@ -7,6 +7,8 @@ #include "pokergame.h" +frame_t frame; + bool pokerGameInit(game_t *game) { pokergame_t *pokerGame = &game->pokerGame; @@ -18,11 +20,16 @@ bool pokerGameInit(game_t *game) { // Initialize the UI. pokerUiInit(pokerGame); + + frameInit(&frame); + frame.texture = &pokerGame->assets.testTexture; // Prep the VN Conversation Engine. vnSceneInit(&pokerGame->scene, &pokerGame->assets.font); - pokerGameActionStartAdd(pokerGame); - queueNext(&pokerGame->scene.conversation.actionQueue); + // pokerGameActionStartAdd(pokerGame); + // queueNext(&pokerGame->scene.conversation.actionQueue); + + return true; } @@ -37,11 +44,12 @@ void pokerGameUpdate(game_t *game) { // Bind the shader. shaderUse(&pokerGame->assets.shader); - // Render the visual novel scene - vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); + // Render the visual novel scene + // vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); - pokerUiRender(pokerGame); + frameRender(&frame, &pokerGame->assets.shader); + // pokerUiRender(pokerGame); } void pokerGameDispose(game_t *game) { diff --git a/src/game/poker/pokergame.h b/src/game/poker/pokergame.h index f9219192..c600f3df 100644 --- a/src/game/poker/pokergame.h +++ b/src/game/poker/pokergame.h @@ -14,6 +14,8 @@ #include "actions/start.h" #include "pokerui.h" +#include "../../ui/frame.h" + /** * Initializes the game state for the poker game. * diff --git a/src/game/poker/pokergameassets.c b/src/game/poker/pokergameassets.c index 9bcd0f82..302dd805 100644 --- a/src/game/poker/pokergameassets.c +++ b/src/game/poker/pokergameassets.c @@ -11,7 +11,8 @@ bool pokerGameAssetsInit(pokergameassets_t *assets) { assetShaderLoad(&assets->shader, "shaders/textured.vert", "shaders/textured.frag" ); - languageInit(&assets->language, "locales/language/en-US.csv"); + languageInit(&assets->language, "locale/language/en-US.csv"); + assetTextureLoad(&assets->testTexture, "test_texture.png"); return true; } diff --git a/src/ui/frame.c b/src/ui/frame.c new file mode 100644 index 00000000..336431d6 --- /dev/null +++ b/src/ui/frame.c @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "frame.h" + +void frameInit(frame_t *frame) { + frame->x = 0; + frame->y = 0; + frame->z = 0; + + primitiveInit( + &frame->primitive, + QUAD_VERTICE_COUNT * FRAME_PRIMITIVE_COUNT, + QUAD_INDICE_COUNT * FRAME_PRIMITIVE_COUNT + ); + + frameSetInnerSize(frame, FRAME_BORDER_SIZE*3, FRAME_BORDER_SIZE*3); +} + +void frameSetSize(frame_t *frame, float width, float height) { + frameSetInnerSize(frame, + width - (FRAME_BORDER_SIZE * 2), + height - (FRAME_BORDER_SIZE * 2) + ); +} + +void frameSetInnerSize(frame_t *frame, float width, float height) { + float rightStart = FRAME_BORDER_SIZE + width; + float rightEnd = rightStart + FRAME_BORDER_SIZE; + + float bottomStart = FRAME_BORDER_SIZE + height; + float bottomEnd = bottomStart + FRAME_BORDER_SIZE; + + float tw = 0.33333; + float th = tw; + + // Buffer the top left edge + quadBuffer(&frame->primitive, 0, + 0, 0, 0, 0, + FRAME_BORDER_SIZE, FRAME_BORDER_SIZE, tw, th, + 0, 0 + ); + + // Buffer the top edge. + quadBuffer(&frame->primitive, 0, + FRAME_BORDER_SIZE, 0, tw, 0, + rightStart, FRAME_BORDER_SIZE, tw*2, th, + QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT + ); + + // Buffer the top right edge. + quadBuffer(&frame->primitive, 0, + rightStart, 0, tw*2, 0, + rightEnd, FRAME_BORDER_SIZE, tw*3, th, + QUAD_VERTICE_COUNT*2, QUAD_INDICE_COUNT*2 + ); + + + // Buffer the left edge + quadBuffer(&frame->primitive, 0, + 0, FRAME_BORDER_SIZE, 0, th, + FRAME_BORDER_SIZE, bottomStart, tw, th*2, + QUAD_VERTICE_COUNT*3, QUAD_INDICE_COUNT*3 + ); + + // Buffer the center + quadBuffer(&frame->primitive, 0, + FRAME_BORDER_SIZE, FRAME_BORDER_SIZE, tw, th, + rightStart, bottomStart, tw*2, th*2, + QUAD_VERTICE_COUNT*4, QUAD_INDICE_COUNT*4 + ); + + // Buffer the right edge. + quadBuffer(&frame->primitive, 0, + rightStart, FRAME_BORDER_SIZE, tw*2, th, + rightEnd, bottomStart, tw*3, th*2, + QUAD_VERTICE_COUNT*5, QUAD_INDICE_COUNT*5 + ); + + + // Buffer the bottom left edge. + quadBuffer(&frame->primitive, 0, + 0, bottomStart, 0, th*2, + FRAME_BORDER_SIZE, bottomEnd, tw, th*3, + QUAD_VERTICE_COUNT*6, QUAD_INDICE_COUNT*6 + ); + + // Buffer the bottom edge. + quadBuffer(&frame->primitive, 0, + FRAME_BORDER_SIZE, bottomStart, tw, th*2, + rightStart, bottomEnd, tw*2, th*3, + QUAD_VERTICE_COUNT*7, QUAD_INDICE_COUNT*7 + ); + + // Buffer the bottom right edge. + quadBuffer(&frame->primitive, 0, + rightStart, bottomStart, tw*2, th*2, + rightEnd, bottomEnd, tw*3, th*3, + QUAD_VERTICE_COUNT*8, QUAD_INDICE_COUNT*8 + ); +} + +void frameRender(frame_t *frame, shader_t *shader) { + shaderUsePosition(shader, frame->x, frame->y, frame->z, 0, 0, 0); + shaderUseTexture(shader, frame->texture); + primitiveDraw(&frame->primitive, 0, -1); +} + +void frameDispose(frame_t *frame) { + primitiveDispose(&frame->primitive); +} \ No newline at end of file diff --git a/src/ui/frame.h b/src/ui/frame.h new file mode 100644 index 00000000..f70d6fb9 --- /dev/null +++ b/src/ui/frame.h @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include +#include "../display/shader.h" +#include "../display/primitive.h" +#include "../display/primitives/quad.h" +#include "../display/gui/font.h" + +void frameInit(frame_t *frame); + +void frameSetSize(frame_t *frame, float width, float height); + +void frameSetInnerSize(frame_t *frame, float width, float height); + +void frameRender(frame_t *frame, shader_t *shader); + +void frameDispose(frame_t *frame); \ No newline at end of file diff --git a/src/ui/label.h b/src/ui/label.h index 40f2ba1a..82ecc4f7 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -9,10 +9,32 @@ #include "../display/primitive.h" #include "../display/gui/font.h" +/** + * Initialize a Label UI Element. + * @param label Label to initialize. + */ void labelInit(label_t *label); +/** + * Sets the text for a given label. + * + * @param label Label to update. + * @param font Font to use. + * @param text Text to set. + */ void labelSetText(label_t *label, font_t *font, char *text); +/** + * Render a label UI element. + * + * @param label Label to render. + * @param shader Shader to use while rendering. + */ void labelRender(label_t *label, shader_t *shader); +/** + * Dispose a previously created label. + * + * @param label Label to dispose. + */ void labelDispose(label_t *label); \ No newline at end of file diff --git a/src/util/string.c b/src/util/string.c index 51aadd6e..1a7e940c 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -97,4 +97,19 @@ int32_t stringHandlebarsBuffer(char *source, // Return the count of chars we wrote to the buffer. -1 due to null term. return l - 1; +} + +void stringStackInit(stringstack_t *stack) { + stack->size = 0; +} + +void stringStackPush(stringstack_t *stack, char *string) { + size_t offset = stack->size * STRING_STACK_STRING_SIZE; + arrayCopy(sizeof(char), string, strlen(string) + 1, stack->strings + offset); + stack->strings[stack->size] = stack->buffer + offset; + stack->size++; +} + +void stringStackPop(stringstack_t *stack) { + stack->size -= 1; } \ No newline at end of file diff --git a/src/util/string.h b/src/util/string.h index 126444bc..4454a844 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -5,6 +5,7 @@ #pragma once #include +#include "array.h" /** * Replaces handlebars within the string with items from the list of variables. @@ -21,4 +22,24 @@ */ int32_t stringHandlebarsBuffer(char *source, stringhandlebarvariable_t *variables, int32_t variableCount, char *buffer -); \ No newline at end of file +); + +/** + * Initializes a string stack for pushing strings on to. + * @param stack Stack to initialize. + */ +void stringStackInit(stringstack_t *stack); + +/** + * Push a string onto the stack. The source string will be copied so you can + * change the original pointer after this push operation. + * @param stack Stack to push onto. + * @param string String to copy and push. + */ +void stringStackPush(stringstack_t *stack, char *string); + +/** + * Pop an element off the end of a string stack. + * @param stack Stack to pop from. + */ +void stringStackPop(stringstack_t *stack); \ No newline at end of file