FPS Label Implemented

This commit is contained in:
2023-03-21 07:50:21 -07:00
parent 9ea6d600b4
commit cc502591bd
4 changed files with 44 additions and 27 deletions

View File

@ -0,0 +1,32 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "prefab/SceneItemPrefab.hpp"
#include "scene/components/ui/UILabel.hpp"
namespace Dawn {
class FPSLabel : public SceneItemPrefab<FPSLabel>, public StateOwner {
public:
static std::vector<Asset*> prefabAssets(AssetManager *man) {
return {};
}
UILabel *label;
FPSLabel(Scene *s, sceneitemid_t i) : SceneItemPrefab(s, i) {}
void prefabInit(AssetManager *man) override {
label = this->addComponent<UILabel>();
label->text = "No Frame";
useEvent([&](float_t delta){
std::string strFps = std::to_string((int32_t)(1.0f / delta));
std::string strTick = std::to_string((int32_t)(delta * 1000.0f));
label->text = strFps + "FPS (" + strTick + "ms)";
}, scene->eventSceneUnpausedUpdate);
}
};
}