diff --git a/assets/poker/characters/sammy/design/coppa.psd b/assets/poker/characters/sammy/design/coppa.psd
new file mode 100644
index 00000000..aaf7a5b0
Binary files /dev/null and b/assets/poker/characters/sammy/design/coppa.psd differ
diff --git a/assets/poker/characters/sammy/design/screen_composition.png b/assets/poker/characters/sammy/design/screen_composition.png
new file mode 100644
index 00000000..c4f32562
Binary files /dev/null and b/assets/poker/characters/sammy/design/screen_composition.png differ
diff --git a/assets/poker/characters/sammy/design/sprite_base.png b/assets/poker/characters/sammy/design/sprite_base.png
new file mode 100644
index 00000000..0f05dcac
Binary files /dev/null and b/assets/poker/characters/sammy/design/sprite_base.png differ
diff --git a/assets/poker/characters/sammy/design/sprite_main.png b/assets/poker/characters/sammy/design/sprite_main.png
new file mode 100644
index 00000000..bc4329fb
Binary files /dev/null and b/assets/poker/characters/sammy/design/sprite_main.png differ
diff --git a/assets/test-ui.xml b/assets/test-ui.xml
new file mode 100644
index 00000000..bf6b89c2
--- /dev/null
+++ b/assets/test-ui.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/client/glfwclient/glfwclient.c b/client/glfwclient/glfwclient.c
index 33e06529..643636e2 100644
--- a/client/glfwclient/glfwclient.c
+++ b/client/glfwclient/glfwclient.c
@@ -17,7 +17,7 @@ int32_t main() {
// Attempt to init GLFW
if(!glfwInit()) return 1;
- // Setup window hints
+ // Setup window hints
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
// Create Window
diff --git a/client/glfwclient/glfwclient.h b/client/glfwclient/glfwclient.h
index a5694e2a..cde9d099 100644
--- a/client/glfwclient/glfwclient.h
+++ b/client/glfwclient/glfwclient.h
@@ -9,7 +9,7 @@
#include
#include
#include
-#include
+#include
#define WINDOW_WIDTH_DEFAULT 1280
#define WINDOW_HEIGHT_DEFAULT WINDOW_WIDTH_DEFAULT/16*9
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dd13f312..ccd0341e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,5 +25,5 @@ target_compile_definitions(game PRIVATE
SETTING_GAME_POKER=1
SETTING_GAME_DAWN=2
SETTING_GAME_SANDBOX=3
- SETTING_GAME=1
+ SETTING_GAME=3
)
\ No newline at end of file
diff --git a/src/config.h b/src/config.h
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/display/font.c b/src/display/font.c
index de94c625..e000a51b 100644
--- a/src/display/font.c
+++ b/src/display/font.c
@@ -48,36 +48,31 @@ float fontGetScale(float fontSize) {
return fontSize / FONT_SIZE_DEFAULT * FONT_GLOBAL_SCALE;
}
-void fontTextBuffer(font_t *font, primitive_t *primitive, fonttextinfo_t *info){
- stbtt_aligned_quad *quad;
- int32_t i;
+bool _fontTextBufferAddLine(fonttextinfo_t *info, int32_t start, int32_t len) {
+ info->lineCount++;
- for(i = 0; i < info->realLength; i++) {
- quad = info->quads + i;
- quadBuffer(primitive, 0,
- quad->x0, quad->y0, quad->s0, quad->t0,
- quad->x1, quad->y1, quad->s1, quad->t1,
- i * QUAD_VERTICE_COUNT, i * QUAD_INDICE_COUNT
- );
+ if(info->lineCount >= FONT_TEXT_INFO_LINES_MAX) {
+ return false;
}
+
+ info->lines[info->lineCount].start = start;
+ info->lines[info->lineCount].length = len;
+ return true;
}
-void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info) {
- primitiveInit(primitive,
- QUAD_VERTICE_COUNT * info->realLength,
- QUAD_INDICE_COUNT * info->realLength
- );
- fontTextBuffer(font, primitive, info);
-}
-
-void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
+void fontTextBuffer(
+ font_t *font, primitive_t *primitive, fonttextinfo_t *info, char *text,
float maxWidth, float fontSize
) {
- int32_t i, j;
+ int32_t i, j, wordStart;
char c;
float x, y, wordX, scale;
+ stbtt_aligned_quad *quads;
stbtt_aligned_quad *quad;
+ // Make some space
+ quads = malloc(sizeof(stbtt_aligned_quad) * strlen(text));
+
// Get the font scale
scale = fontGetScale(fontSize);
@@ -85,7 +80,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale);
/** Which index in the original text var is the current word from */
- int32_t wordStart = 0;
+ wordStart = 0;
// Setup Scales
info->length = 0;
@@ -105,6 +100,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
y = FONT_INITIAL_LINE;
wordX = 0;
while(c = text[i++]) {
+ if(info->lineCount >= FONT_TEXT_INFO_LINES_MAX) break;
info->length++;
// When space, start of new word about to begin
@@ -113,10 +109,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
// Did this space cause a newline?
if(x > maxWidth) {
- info->lineCount++;
- info->lines[info->lineCount].start = info->realLength;
- info->lines[info->lineCount].length = 0;
-
+ _fontTextBufferAddLine(info, info->realLength, 0);
y += FONT_LINE_HEIGHT;
x = 0;
}
@@ -127,10 +120,7 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
// New line.
if(c == FONT_NEWLINE) {
- info->lineCount++;
- info->lines[info->lineCount].start = info->realLength;
- info->lines[info->lineCount].length = 0;
-
+ _fontTextBufferAddLine(info, info->realLength, 0);
wordStart = info->realLength;
y += FONT_LINE_HEIGHT;
x = 0;
@@ -138,19 +128,18 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
}
// Generate the quad.
- quad = info->quads + info->realLength;
+ quad = quads + info->realLength;
stbtt_GetBakedQuad(font->characterData,
FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT,
((int32_t)c)-FONT_FIRST_CHAR, &x, &y, quad, FONT_FILL_MODE
);
// Now measure the width of the line (take the right side of that quad)
- // if(x > maxWidth) {
if(quad->x1 > maxWidth) {
// We've exceeded the edge, go back to the start of the word and newline.
x = quad->x1 - wordX;
for(j = wordStart; j <= info->realLength; j++) {
- quad = info->quads + j;
+ quad = quads + j;
quad->x0 -= wordX;
quad->x1 -= wordX;
quad->y0 += FONT_LINE_HEIGHT;
@@ -161,11 +150,10 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
info->lines[info->lineCount].length -= info->realLength - wordStart;
// Next line begins with this word
- info->lineCount++;
- info->lines[info->lineCount].start = wordStart;
- info->lines[info->lineCount].length = info->realLength - wordStart;
-
y += FONT_LINE_HEIGHT;
+ if(!_fontTextBufferAddLine(info, wordStart, info->realLength-wordStart)) {
+ continue;
+ }
wordX = 0;
}
@@ -174,9 +162,15 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
}
info->lineCount++;
+
+ // Initialize primitive
+ primitiveInit(primitive,
+ QUAD_VERTICE_COUNT * info->realLength,
+ QUAD_INDICE_COUNT * info->realLength
+ );
for(j = 0; j < info->realLength; j++) {
- quad = info->quads + j;
+ quad = quads + j;
// Scale the Quad
if(scale != 1.0) {
@@ -189,7 +183,17 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
// Update the dimensions.
info->width = mathMax(info->width, quad->x1);
info->height = mathMax(info->height, quad->y1);
+
+ // Buffer the quad.
+ quadBuffer(primitive, 0,
+ quad->x0, quad->y0, quad->s0, quad->t0,
+ quad->x1, quad->y1, quad->s1, quad->t1,
+ j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
+ );
}
+
+ // Free up
+ free(quads);
}
int32_t fontGetLineCharCount(fonttextinfo_t *info,int32_t start,int32_t count) {
diff --git a/src/display/font.h b/src/display/font.h
index 96697145..85276b70 100644
--- a/src/display/font.h
+++ b/src/display/font.h
@@ -46,11 +46,8 @@
#define FONT_INITIAL_LINE FONT_LINE_HEIGHT * 0.75f
#define FONT_SPACE_SIZE FONT_TEXTURE_SIZE * 0.45f
-/** Maximum number of characters a font text info can hold. */
-#define FONT_TEXT_INFO_CHARS_MAX 1024
-
/** Maximum number of newlines that a font text info can hold. */
-#define FONT_TEXT_INFO_LINES_MAX FONT_TEXT_INFO_CHARS_MAX/50
+#define FONT_TEXT_INFO_LINES_MAX 16
/** Representation of a font that can be used to render text */
typedef struct {
@@ -80,9 +77,6 @@ typedef struct {
/** Dimensions of the string */
float width, height;
-
- /** Array of precalculated quads */
- stbtt_aligned_quad quads[FONT_TEXT_INFO_CHARS_MAX];
} fonttextinfo_t;
/**
@@ -98,25 +92,6 @@ void fontInit(font_t *font, char *data);
*/
void fontDispose(font_t *Font);
-/**
- * Buffers the vertices of a font text onto a primitive. Requires some info
- * about how the font is meant to render from the text info section.
- *
- * @param font Font to render.
- * @param primitive Primitive to render into.
- * @param info The precalculated text info.
- */
-void fontTextBuffer(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
-
-/**
- * Initializes an uninitialized primitive for rendering.
- *
- * @param font Font to render.
- * @param primitive Primitive to render into.
- * @param info Text Info to use while rendering.
- */
-void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
-
/**
* Convert a Font's Size into a Font Scale. The scale is based on the font's
* default size for the given texture size (Refer to FONT_SIZE_DEFAULT).
@@ -126,16 +101,28 @@ void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
*/
float fontGetScale(float fontSize);
+/**
+ * Internal method that adds a line to the text buffer process.
+ *
+ * @param info Info to add to.
+ * @param start Start character index for the next line.
+ * @param len Length of the next line.
+ * @return True if added a line successfully, otherwise false.
+ */
+bool _fontTextBufferAddLine(fonttextinfo_t *info, int32_t start, int32_t len);
+
/**
* Clamps text to a max width, inserting newlines where possible.
*
* @param font Font to use
+ * @param primitive Primitive to buffer the text to.
* @param info Font text info to clamp into.
* @param text Text to clamp.
* @param maxWidth Max width (pixels) to clamp the text to, -1 for no max width.
* @param fontSize Font Size of the text.
*/
-void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
+void fontTextBuffer(
+ font_t *font, primitive_t *primitive, fonttextinfo_t *info, char *text,
float maxWidth, float fontSize
);
diff --git a/src/file/gui.c b/src/file/gui.c
new file mode 100644
index 00000000..965fa8c0
--- /dev/null
+++ b/src/file/gui.c
@@ -0,0 +1,12 @@
+/**
+ * Copyright (c) 2021 Dominic Masters
+ *
+ * This software is released under the MIT License.
+ * https://opensource.org/licenses/MIT
+ */
+
+#include "gui.h"
+
+void guiLoad() {
+
+}
\ No newline at end of file
diff --git a/src/file/gui.h b/src/file/gui.h
new file mode 100644
index 00000000..4a5c6b91
--- /dev/null
+++ b/src/file/gui.h
@@ -0,0 +1,14 @@
+/**
+ * Copyright (c) 2021 Dominic Masters
+ *
+ * This software is released under the MIT License.
+ * https://opensource.org/licenses/MIT
+ */
+
+#pragma once
+#include "../libs.h"
+#include "asset.h"
+#include "csv.h"
+#include "xml.h"
+
+void guiLoad();
diff --git a/src/game/game.h b/src/game/game.h
index 4a48d726..1584f38a 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -8,6 +8,9 @@
#include "../engine/engine.h"
#include "../locale/language.h"
+#define SETTING_GAME_SANDBOX 3
+#define SETTING_GAME SETTING_GAME_SANDBOX
+
/** Describes the current game */
#if SETTING_GAME == SETTING_GAME_POKER
#include "poker/game.h"
diff --git a/src/game/sandbox/sandboxscene.c b/src/game/sandbox/sandboxscene.c
index 9c05b34f..f36529df 100644
--- a/src/game/sandbox/sandboxscene.c
+++ b/src/game/sandbox/sandboxscene.c
@@ -8,29 +8,30 @@
#include "sandboxscene.h"
bool sandboxSceneInit(sandboxscene_t *game) {
- // Init Scripter
- scripterInit(&game->scripter, &game->engine);
- game->scripter.user = game;
-
- // Add APIs
- scriptsApiIo(&game->scripter);
- scriptsApiDisplay(&game->scripter);
- scriptsApiAsset(&game->scripter);
- scriptsApiEpoch(&game->scripter);
-
- // Load main script
- assetScripterAppend(&game->scripter, "scripts/main.js");
-
- // Invoke initialization.
- scripterInvokeMethodSimple(&game->scripter, "init");
-
+ // Init Assets
+ assetShaderLoad(&game->shader,
+ "shared/shaders/textured.vert",
+ "shared/shaders/textured.frag"
+ );
+ assetFontLoad(&game->font, "shared/fonts/opensans/OpenSans-Regular.ttf");
+ assetTextureLoad(&game->texture, "shared/test_texture.png");
+
return true;
}
void sandboxSceneUpdate(sandboxscene_t *game) {
- scripterInvokeMethodSimple(&game->scripter, "update");
+ camera_t camera;
+
+ shaderUse(&game->shader);
+ cameraOrtho(&camera,
+ 0, game->engine.render.width,
+ game->engine.render.height, 0,
+ 0.01f, 1000.0f
+ );
+ cameraLookAt(&camera, 0,0,10, 0,0,0);
+ shaderUseCamera(&game->shader, &camera);
}
void sandboxSceneDispose(sandboxscene_t *game) {
- scripterInvokeMethodSimple(&game->scripter, "dispose");
+ // shaderDispose(&game->shader);
}
\ No newline at end of file
diff --git a/src/game/sandbox/sandboxscene.h b/src/game/sandbox/sandboxscene.h
index 8f8878cd..c985317c 100644
--- a/src/game/sandbox/sandboxscene.h
+++ b/src/game/sandbox/sandboxscene.h
@@ -8,32 +8,17 @@
#pragma once
#include "../../libs.h"
#include "../../display/camera.h"
-#include "../../display/shader.h"
#include "../../display/font.h"
-#include "../../display/primitive.h"
-#include "../../display/primitives/quad.h"
-#include "../../display/primitives/cube.h"
-#include "../../display/renderlist.h"
-#include "../../display/texture.h"
+#include "../../display/shader.h"
#include "../../file/asset.h"
-
-#include "../../file/xml.h"
-#include "../../file/asset.h"
-#include "../../ui/grid.h"
-#include "../../ui/menu.h"
-#include "../../ui/textmenu.h"
-#include "../../ui/image.h"
-#include "../../ui/framedtextmenu.h"
-
-#include "../../script/scripter.h"
-#include "../../script/api/io.h"
-#include "../../script/api/display.h"
-#include "../../script/api/asset.h"
-#include "../../script/api/epoch.h"
+#include "../../ui/label.h"
+#include "../../ui/breakpoint.h"
typedef struct {
engine_t engine;
- scripter_t scripter;
+ shader_t shader;
+ texture_t texture;
+ font_t font;
} sandboxscene_t;
/**
diff --git a/src/ui/frame.c b/src/ui/frame.c
index 4942ef2c..c5cacd28 100644
--- a/src/ui/frame.c
+++ b/src/ui/frame.c
@@ -8,19 +8,19 @@
#include "frame.h"
void frameInit(frame_t *frame) {
+ frame->texture = NULL;
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);
+ frameSetInnerSize(frame, FRAME_BORDER_SIZE, FRAME_BORDER_SIZE);
}
void frameSetSize(frame_t *frame, float width, float height) {
frameSetInnerSize(frame,
- width - (FRAME_BORDER_SIZE * 2),
- height - (FRAME_BORDER_SIZE * 2)
+ width - FRAME_BORDER_SIZE_FULL, height - FRAME_BORDER_SIZE_FULL
);
}
@@ -101,6 +101,7 @@ void frameSetInnerSize(frame_t *frame, float width, float height) {
}
void frameRender(frame_t *frame, shader_t *shader, float x, float y) {
+ if(frame->texture == NULL) return;
shaderUsePosition(shader, x, y, 0, 0, 0, 0);
shaderUseTexture(shader, frame->texture);
primitiveDraw(&frame->primitive, 0, -1);
diff --git a/src/ui/label.c b/src/ui/label.c
index 55ee1bbf..06827a76 100644
--- a/src/ui/label.c
+++ b/src/ui/label.c
@@ -21,8 +21,10 @@ void labelSetText(label_t *label, font_t *font, char *text) {
}
label->font = font;
- fontTextClamp(font, &label->info, text, label->maxWidth, label->fontSize);
- fontTextInit(font, &label->primitive, &label->info);
+ fontTextBuffer(
+ font, &label->primitive, &label->info, text,
+ label->maxWidth, label->fontSize
+ );
}
void labelRender(label_t *label, shader_t *shader, float x, float y) {
diff --git a/src/ui/menu.c b/src/ui/menu.c
index a8b46962..57a1eeb0 100644
--- a/src/ui/menu.c
+++ b/src/ui/menu.c
@@ -84,13 +84,14 @@ void menuUpdate(menu_t *menu, engine_t *engine) {
}
menuitem_t * menuAdd(menu_t *menu) {
- menuitem_t *item = menu->items + menu->itemCount;
-
+ menuitem_t *item;
+
+ if(menu->itemCount >= MENU_ITEMS_MAX) return NULL;
+ item = menu->items + menu->itemCount++;
item->x = 0;
item->y = 0;
item->width = 1;
item->height = 1;
- menu->itemCount++;
return item;
}
\ No newline at end of file
diff --git a/src/vn/ui/vntextbox.c b/src/vn/ui/vntextbox.c
index 2c6be9cc..042cd7e7 100644
--- a/src/vn/ui/vntextbox.c
+++ b/src/vn/ui/vntextbox.c
@@ -41,10 +41,10 @@ void vnTextBoxRebuffer(vntextbox_t *box) {
box->width = box->widthMax;
// Rebuffer the text.
- fontTextClamp(
- box->font, &box->textInfo, box->text, textMaxWidth, VN_TEXTBOX_FONT_SIZE
+ fontTextBuffer(
+ box->font, &box->primitive, &box->textInfo, box->text,
+ textMaxWidth, VN_TEXTBOX_FONT_SIZE
);
- fontTextInit(box->font, &box->primitive, &box->textInfo);
// Resize the frame
box->height = FONT_LINE_HEIGHT * box->linesMax;