diff --git a/assets/init.dcf b/assets/init.dcf index 7396103..44844e2 100644 --- a/assets/init.dcf +++ b/assets/init.dcf @@ -13,5 +13,4 @@ bind enter accept; bind q cancel; bind esc quit; -alias test "echo \"test\""; -bind p test; \ No newline at end of file +bind f1 togglefps; \ No newline at end of file diff --git a/src/display/mesh/quad.c b/src/display/mesh/quad.c index 6fef521..4e2b14d 100644 --- a/src/display/mesh/quad.c +++ b/src/display/mesh/quad.c @@ -34,10 +34,7 @@ void quadBuffer( const float_t minY, const float_t maxX, const float_t maxY, - const uint8_t r, - const uint8_t g, - const uint8_t b, - const uint8_t a, + const color_t color, const float_t u0, const float_t v0, const float_t u1, @@ -48,34 +45,34 @@ void quadBuffer( // First triangle vertices[0] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u0, v0 }, // UV { minX, minY, z } // Position }; vertices[1] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u1, v0 }, // UV { maxX, minY, z } // Position }; vertices[2] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u1, v1 }, // UV { maxX, maxY, z } // Position }; // Second triangle vertices[3] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u0, v0 }, // UV { minX, minY, z } // Position }; vertices[4] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u1, v1 }, // UV { maxX, maxY, z } // Position }; vertices[5] = (meshvertex_t) { - { r, g, b, a }, // Color + { color.r, color.g, color.b, color.a }, // Color { u0, v1 }, // UV { minX, maxY, z } // Position }; diff --git a/src/display/mesh/quad.h b/src/display/mesh/quad.h index 860588a..1ee1712 100644 --- a/src/display/mesh/quad.h +++ b/src/display/mesh/quad.h @@ -7,6 +7,7 @@ #pragma once #include "mesh.h" +#include "display/color.h" #define QUAD_VERTEX_COUNT 6 #define QUAD_PRIMITIVE_TYPE MESH_PRIMITIVE_TRIANGLES @@ -42,10 +43,7 @@ void quadBuffer( const float_t minY, const float_t maxX, const float_t maxY, - const uint8_t r, - const uint8_t g, - const uint8_t b, - const uint8_t a, + const color_t color, const float_t u0, const float_t v0, const float_t u1, diff --git a/src/display/spritebatch/spritebatch.c b/src/display/spritebatch/spritebatch.c index 714d57f..46d841d 100644 --- a/src/display/spritebatch/spritebatch.c +++ b/src/display/spritebatch/spritebatch.c @@ -30,10 +30,7 @@ void spriteBatchPush( const float_t minY, const float_t maxX, const float_t maxY, - const uint8_t r, - const uint8_t g, - const uint8_t b, - const uint8_t a, + const color_t color, const float_t u0, const float_t v0, const float_t u1, @@ -51,7 +48,7 @@ void spriteBatchPush( quadBuffer( &SPRITEBATCH.vertices[SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT], minX, minY, maxX, maxY, - r, g, b, a, + color, u0, v0, u1, v1 ); diff --git a/src/display/spritebatch/spritebatch.h b/src/display/spritebatch/spritebatch.h index ad751a3..54fe051 100644 --- a/src/display/spritebatch/spritebatch.h +++ b/src/display/spritebatch/spritebatch.h @@ -42,10 +42,7 @@ void spriteBatchInit(); * @param minY The minimum y coordinate of the sprite. * @param maxX The maximum x coordinate of the sprite. * @param maxY The maximum y coordinate of the sprite. - * @param r The red color component of the sprite. - * @param g The green color component of the sprite. - * @param b The blue color component of the sprite. - * @param a The alpha component of the sprite. + * @param color The color to tint the sprite with. * @param u0 The texture coordinate for the top-left corner of the sprite. * @param v0 The texture coordinate for the top-left corner of the sprite. * @param u1 The texture coordinate for the bottom-right corner of the sprite. @@ -57,10 +54,7 @@ void spriteBatchPush( const float_t minY, const float_t maxX, const float_t maxY, - const uint8_t r, - const uint8_t g, - const uint8_t b, - const uint8_t a, + const color_t color, const float_t u0, const float_t v0, const float_t u1, diff --git a/src/display/ui/CMakeLists.txt b/src/display/ui/CMakeLists.txt index 2e812f4..e7ce66f 100644 --- a/src/display/ui/CMakeLists.txt +++ b/src/display/ui/CMakeLists.txt @@ -8,5 +8,6 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE uitext.c ui.c + uifps.c uiconsole.c ) \ No newline at end of file diff --git a/src/display/ui/ui.c b/src/display/ui/ui.c index be89f0c..8810ceb 100644 --- a/src/display/ui/ui.c +++ b/src/display/ui/ui.c @@ -10,6 +10,7 @@ #include "display/framebuffer/framebuffer.h" #include "display/spritebatch/spritebatch.h" #include "uiconsole.h" +#include "uifps.h" #include "util/memory.h" ui_t UI; @@ -51,6 +52,7 @@ void uiRender(void) { cameraPushMatrix(&UI.camera); uiConsoleRender(); + uiFPSRender(); spriteBatchFlush(); cameraPopMatrix(); diff --git a/src/display/ui/uiconsole.c b/src/display/ui/uiconsole.c index 6906001..220c858 100644 --- a/src/display/ui/uiconsole.c +++ b/src/display/ui/uiconsole.c @@ -20,10 +20,7 @@ void uiConsoleRender(void) { i++; continue; } - uiTextDraw( - 0, i * UI_TEXT_TILE_HEIGHT, line, - 0xFF, 0xFF, 0xFF - ); + uiTextDraw(0, i * UI_TEXT_TILE_HEIGHT, line, COLOR_WHITE); i++; } while(i < CONSOLE_HISTORY_MAX); } \ No newline at end of file diff --git a/src/display/ui/uifps.c b/src/display/ui/uifps.c new file mode 100644 index 0000000..0403839 --- /dev/null +++ b/src/display/ui/uifps.c @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "uifps.h" +#include "display/ui/uitext.h" +#include "time/time.h" + +void uiFPSRender(void) { + float_t fps = TIME.delta > 0.0f ? (1.0f / TIME.delta) : 0.0f; + + char_t buffer[64]; + snprintf( + buffer, + sizeof(buffer), + "FPS: %d", + (int32_t)fps + ); + + color_t color = fps >= 50.0f ? COLOR_GREEN : + (fps >= 30.0f ? COLOR_YELLOW : COLOR_RED); + + uiTextDraw(0, 0, buffer, color); +} \ No newline at end of file diff --git a/src/display/ui/uifps.h b/src/display/ui/uifps.h new file mode 100644 index 0000000..ced375e --- /dev/null +++ b/src/display/ui/uifps.h @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +void uiFPSRender(void); \ No newline at end of file diff --git a/src/display/ui/uitext.c b/src/display/ui/uitext.c index 841870f..75d729d 100644 --- a/src/display/ui/uitext.c +++ b/src/display/ui/uitext.c @@ -32,9 +32,7 @@ void uiTextDrawChar( const float_t x, const float_t y, const char_t c, - const uint8_t r, - const uint8_t g, - const uint8_t b + const color_t color ) { int32_t tileIndex = (int32_t)(c) - UI_TEXT_CHAR_START; if(tileIndex < 0 || tileIndex >= UI_TEXT_TILE_COUNT) { @@ -55,7 +53,7 @@ void uiTextDrawChar( &UI_TEXT.asset->alphaImage.texture, x, y, x + UI_TEXT_TILE_WIDTH, y + UI_TEXT_TILE_HEIGHT, - r, g, b, 0xFF, + color, (tileX * UI_TEXT_TILE_WIDTH) / w, (tileY * UI_TEXT_TILE_HEIGHT) / h, ((tileX + 1) * UI_TEXT_TILE_WIDTH) / w, @@ -67,9 +65,7 @@ void uiTextDraw( const float_t x, const float_t y, const char_t *text, - const uint8_t r, - const uint8_t g, - const uint8_t b + const color_t color ) { assertNotNull(text, "Text cannot be NULL"); @@ -90,7 +86,7 @@ void uiTextDraw( continue; } - uiTextDrawChar(posX, posY, c, r, g, b); + uiTextDrawChar(posX, posY, c, color); posX += UI_TEXT_TILE_WIDTH; } } diff --git a/src/display/ui/uitext.h b/src/display/ui/uitext.h index 13d5bee..e3878d8 100644 --- a/src/display/ui/uitext.h +++ b/src/display/ui/uitext.h @@ -35,17 +35,13 @@ errorret_t uiTextInit(void); * @param x The x-coordinate to draw the character at. * @param y The y-coordinate to draw the character at. * @param c The character to draw. - * @param r The red component of the color (0-255). - * @param g The green component of the color (0-255). - * @param b The blue component of the color (0-255). + * @param color The color to draw the character in. */ void uiTextDrawChar( const float_t x, const float_t y, const char_t c, - const uint8_t r, - const uint8_t g, - const uint8_t b + const color_t color ); /** @@ -54,17 +50,13 @@ void uiTextDrawChar( * @param x The x-coordinate to draw the text at. * @param y The y-coordinate to draw the text at. * @param text The null-terminated string of text to draw. - * @param r The red component of the color (0-255). - * @param g The green component of the color (0-255). - * @param b The blue component of the color (0-255). + * @param color The color to draw the text in. */ void uiTextDraw( const float_t x, const float_t y, const char_t *text, - const uint8_t r, - const uint8_t g, - const uint8_t b + const color_t color ); /**