Added FPS meter
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
function CubeEntity() {
|
function CubeEntity() {
|
||||||
Entity.call(this);
|
Entity.call(this);
|
||||||
|
|
||||||
this.add(POSITION);
|
this.add(POSITION);
|
||||||
this.position.position = new Vec3(1, 0, 0);
|
|
||||||
this.add(MESH);
|
this.add(MESH);
|
||||||
this.add(MATERIAL);
|
this.add(MATERIAL);
|
||||||
}
|
}
|
||||||
@@ -11,12 +9,12 @@ CubeEntity.prototype = Object.create(Entity.prototype);
|
|||||||
CubeEntity.prototype.constructor = CubeEntity;
|
CubeEntity.prototype.constructor = CubeEntity;
|
||||||
|
|
||||||
CubeEntity.prototype.update = function() {
|
CubeEntity.prototype.update = function() {
|
||||||
var speed = 3.0;
|
// var speed = 3.0;
|
||||||
var move = Input.axis2D(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT, INPUT_ACTION_UP, INPUT_ACTION_DOWN);
|
// var move = Input.axis2D(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT, INPUT_ACTION_UP, INPUT_ACTION_DOWN);
|
||||||
this.position.position.x += move.x * speed * TIME.delta;
|
// this.position.position.x += move.x * speed * TIME.delta;
|
||||||
this.position.position.z += move.y * speed * TIME.delta;
|
// this.position.position.z += move.y * speed * TIME.delta;
|
||||||
this.position.rotation.x += 3 * TIME.delta;
|
// this.position.rotation.x += 3 * TIME.delta;
|
||||||
this.position.rotation.z += 2 * TIME.delta;
|
// this.position.rotation.z += 2 * TIME.delta;
|
||||||
this.material.setColor(Color.rainbow());
|
this.material.setColor(Color.rainbow());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -419,11 +419,11 @@ errorret_t consoleDraw() {
|
|||||||
|
|
||||||
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
for(uint32_t i = 0; i < CONSOLE_HISTORY_MAX; i++) {
|
||||||
errorChain(textDraw(
|
errorChain(textDraw(
|
||||||
0, DEFAULT_FONT_TILESET.tileHeight * i,
|
0, FONT_TILESET_DEFAULT.tileHeight * i,
|
||||||
CONSOLE.line[i],
|
CONSOLE.line[i],
|
||||||
COLOR_WHITE,
|
COLOR_WHITE,
|
||||||
&DEFAULT_FONT_TILESET,
|
&FONT_TILESET_DEFAULT,
|
||||||
&DEFAULT_FONT_TEXTURE
|
&FONT_TEXTURE_DEFAULT
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
errorChain(spriteBatchFlush());
|
errorChain(spriteBatchFlush());
|
||||||
|
|||||||
@@ -13,19 +13,19 @@
|
|||||||
#include "asset/loader/display/assettilesetloader.h"
|
#include "asset/loader/display/assettilesetloader.h"
|
||||||
#include "display/shader/shaderunlit.h"
|
#include "display/shader/shaderunlit.h"
|
||||||
|
|
||||||
texture_t DEFAULT_FONT_TEXTURE;
|
texture_t FONT_TEXTURE_DEFAULT;
|
||||||
tileset_t DEFAULT_FONT_TILESET;
|
tileset_t FONT_TILESET_DEFAULT;
|
||||||
|
|
||||||
errorret_t textInit(void) {
|
errorret_t textInit(void) {
|
||||||
errorChain(assetTextureLoad(
|
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();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t textDispose(void) {
|
errorret_t textDispose(void) {
|
||||||
errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
|
errorChain(textureDispose(&FONT_TEXTURE_DEFAULT));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
#define TEXT_CHAR_START '!'
|
#define TEXT_CHAR_START '!'
|
||||||
|
|
||||||
extern texture_t DEFAULT_FONT_TEXTURE;
|
extern texture_t FONT_TEXTURE_DEFAULT;
|
||||||
extern tileset_t DEFAULT_FONT_TILESET;
|
extern tileset_t FONT_TILESET_DEFAULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the text system.
|
* Initializes the text system.
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
#define ENTITY_COUNT_MAX 6
|
#define ENTITY_COUNT_MAX 20
|
||||||
#define ENTITY_COMPONENT_COUNT_MAX 6
|
#define ENTITY_COMPONENT_COUNT_MAX 8
|
||||||
|
|
||||||
typedef uint8_t entityid_t;
|
typedef uint8_t entityid_t;
|
||||||
typedef uint8_t componentid_t;
|
typedef uint8_t componentid_t;
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ errorret_t sceneUpdate(void) {
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dusktimeepoch_t LAST;
|
||||||
|
|
||||||
errorret_t sceneRender(void) {
|
errorret_t sceneRender(void) {
|
||||||
entityid_t camEnts[ENTITY_COUNT_MAX];
|
entityid_t camEnts[ENTITY_COUNT_MAX];
|
||||||
componentid_t camComps[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(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
||||||
errorChain(consoleDraw());
|
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();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user