Added FPS meter
This commit is contained in:
@@ -419,11 +419,11 @@ errorret_t consoleDraw() {
|
||||
|
||||
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
||||
errorChain(textDraw(
|
||||
0, DEFAULT_FONT_TILESET.tileHeight * i,
|
||||
0, FONT_TILESET_DEFAULT.tileHeight * i,
|
||||
CONSOLE.line[i],
|
||||
COLOR_WHITE,
|
||||
&DEFAULT_FONT_TILESET,
|
||||
&DEFAULT_FONT_TEXTURE
|
||||
&FONT_TILESET_DEFAULT,
|
||||
&FONT_TEXTURE_DEFAULT
|
||||
));
|
||||
}
|
||||
errorChain(spriteBatchFlush());
|
||||
|
||||
@@ -13,19 +13,19 @@
|
||||
#include "asset/loader/display/assettilesetloader.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
|
||||
texture_t DEFAULT_FONT_TEXTURE;
|
||||
tileset_t DEFAULT_FONT_TILESET;
|
||||
texture_t FONT_TEXTURE_DEFAULT;
|
||||
tileset_t FONT_TILESET_DEFAULT;
|
||||
|
||||
errorret_t textInit(void) {
|
||||
errorChain(assetTextureLoad(
|
||||
"ui/minogram.png", &DEFAULT_FONT_TEXTURE, TEXTURE_FORMAT_RGBA
|
||||
"ui/minogram.png", &FONT_TEXTURE_DEFAULT, TEXTURE_FORMAT_RGBA
|
||||
));
|
||||
errorChain(assetTilesetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
|
||||
errorChain(assetTilesetLoad("ui/minogram.dtf", &FONT_TILESET_DEFAULT));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t textDispose(void) {
|
||||
errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
||||
errorChain(textureDispose(&FONT_TEXTURE_DEFAULT));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
#define TEXT_CHAR_START '!'
|
||||
|
||||
extern texture_t DEFAULT_FONT_TEXTURE;
|
||||
extern tileset_t DEFAULT_FONT_TILESET;
|
||||
extern texture_t FONT_TEXTURE_DEFAULT;
|
||||
extern tileset_t FONT_TILESET_DEFAULT;
|
||||
|
||||
/**
|
||||
* Initializes the text system.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define ENTITY_COUNT_MAX 6
|
||||
#define ENTITY_COMPONENT_COUNT_MAX 6
|
||||
#define ENTITY_COUNT_MAX 20
|
||||
#define ENTITY_COMPONENT_COUNT_MAX 8
|
||||
|
||||
typedef uint8_t entityid_t;
|
||||
typedef uint8_t componentid_t;
|
||||
|
||||
@@ -46,6 +46,8 @@ errorret_t sceneUpdate(void) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
dusktimeepoch_t LAST;
|
||||
|
||||
errorret_t sceneRender(void) {
|
||||
entityid_t camEnts[ENTITY_COUNT_MAX];
|
||||
componentid_t camComps[ENTITY_COUNT_MAX];
|
||||
@@ -141,6 +143,23 @@ errorret_t sceneRender(void) {
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
||||
errorChain(consoleDraw());
|
||||
|
||||
// FPS
|
||||
char_t fpsText[32];
|
||||
|
||||
dusktimeepoch_t now = timeGetEpoch();
|
||||
double_t delta = now.time - LAST.time;
|
||||
LAST = now;
|
||||
double_t fps = delta > 0 ? 1.0 / delta : 0.0;
|
||||
snprintf(fpsText, sizeof(fpsText), "FPS: %.2f", fps);
|
||||
|
||||
errorChain(spriteBatchFlush());
|
||||
errorChain(textDraw(
|
||||
0, 0,
|
||||
fpsText, COLOR_WHITE,
|
||||
&FONT_TILESET_DEFAULT, &FONT_TEXTURE_DEFAULT
|
||||
));
|
||||
errorChain(spriteBatchFlush());
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user