Half done with Scene Component Parsing
This commit is contained in:
@ -42,4 +42,7 @@ target_compile_definitions(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_DEBUG_BUILD=${DAWN_DEBUG_BUILD}
|
||||
)
|
||||
)
|
||||
|
||||
# Common Prefabs
|
||||
tool_prefab("prefabs/ui/debug/FPSLabel.xml")
|
@ -1,32 +0,0 @@
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(debug)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(example)
|
||||
add_subdirectory(physics)
|
||||
|
10
src/dawn/scene/components/debug/CMakeLists.txt
Normal file
10
src/dawn/scene/components/debug/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
FPSLabelComponent.cpp
|
||||
)
|
23
src/dawn/scene/components/debug/FPSLabelComponent.cpp
Normal file
23
src/dawn/scene/components/debug/FPSLabelComponent.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "FPSLabelComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
FPSLabelComponent::FPSLabelComponent(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FPSLabelComponent::onStart() {
|
||||
useEvent([&](float_t delta){
|
||||
if(this->label == nullptr) return;
|
||||
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)";
|
||||
}, this->item->scene->eventSceneUnpausedUpdate);
|
||||
}
|
16
src/dawn/scene/components/debug/FPSLabelComponent.hpp
Normal file
16
src/dawn/scene/components/debug/FPSLabelComponent.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/ui/UILabel.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class FPSLabelComponent : public SceneItemComponent {
|
||||
public:
|
||||
UILabel *label;
|
||||
FPSLabelComponent(SceneItem *item);
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -29,11 +29,17 @@ namespace Dawn {
|
||||
void updateMesh();
|
||||
|
||||
public:
|
||||
//@optional
|
||||
StateProperty<std::string> text;
|
||||
// @optional
|
||||
StateProperty<float_t> fontSize;
|
||||
/* @optional */
|
||||
StateProperty<Font*> font;
|
||||
/* @optional */
|
||||
StateProperty<float_t> maxWidth;
|
||||
/* @optional */
|
||||
struct Color textColor = COLOR_WHITE;
|
||||
|
||||
struct FontMeasure measure;
|
||||
int32_t startQuad = 0;
|
||||
int32_t quadCount = -1;
|
||||
|
Reference in New Issue
Block a user