Half done with Scene Component Parsing

This commit is contained in:
2023-03-23 21:43:02 -07:00
parent 3782e731b2
commit 8c50c10be0
19 changed files with 308 additions and 411 deletions

View File

@ -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")

View File

@ -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);
}
};
}

View File

@ -4,6 +4,7 @@
# https://opensource.org/licenses/MIT
# Subdirs
add_subdirectory(debug)
add_subdirectory(display)
add_subdirectory(example)
add_subdirectory(physics)

View 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
)

View 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);
}

View 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;
};
}

View File

@ -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;