measure fps

This commit is contained in:
wgroeneveld 2020-07-10 17:36:13 +02:00
parent 667e2e640f
commit 6855ce19f2
5 changed files with 15 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include <libgba-sprite-engine/gba/tonc_memdef.h>
#include <libgba-sprite-engine/gba_engine.h>
#include <libgba-sprite-engine/background/text_stream.h>
#include "wirescene.h"
@ -19,6 +20,7 @@ Camera WireScene::camera() {
return Camera(VectorFx::fromInt(0, 0, 10), VectorFx::fromInt(0, 0, 0));
}
int msecs = 1;
void WireScene::load() {
foregroundPalette = std::unique_ptr<ForegroundPaletteManager>(new ForegroundPaletteManager());
backgroundPalette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager(pal, sizeof(pal)));
@ -46,9 +48,17 @@ void WireScene::load() {
cube->addFace({ 0, 4, 7});
cube->addFace({ 4, 5, 6});
cube->addFace({ 4, 6, 7});
engine->getTimer()->start();
}
void WireScene::tick(u16 keys) {
int curmsecs = engine->getTimer()->getMsecs();
int elapsed = curmsecs - msecs;
msecs = curmsecs;
TextStream::instance().setText(std::to_string(1000 / elapsed) + std::string(" FPS"), 1, 1);
cube->rotate(2, 2);
if(keys & KEY_A) {

View File

@ -31,10 +31,10 @@ public:
std::string to_string();
int getTotalMsecs();
int getMsecs() { return msecs; }
int getSecs() { return secs; }
int getMinutes() { return minutes; }
int getHours() { return hours; }
inline int getMsecs() { return msecs; }
inline int getSecs() { return secs; }
inline int getMinutes() { return minutes; }
inline int getHours() { return hours; }
friend std::ostream& operator<<(std::ostream& os, Timer& timer);
};

View File

@ -130,12 +130,11 @@ void GBAEngine::update() {
// WARNING - keep amount of instructions as minimal as possible in here!
u16 keys = readKeys();
// main scene update loop call. This *might* take a while.
currentScene->tick(keys);
// TODO use software interrupt Vsyncing instead of 2 wasteful whiles
vsync();
renderClear();
currentScene->tick(keys);
render();
flipPage();
}

BIN
img/wired.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

BIN
img/wireless.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB