From 7e2da2339853c216a3db0fab46d83bcc52fe39bb Mon Sep 17 00:00:00 2001 From: bailwillharr Date: Sat, 27 May 2023 13:07:25 +0100 Subject: [PATCH] some testing --- include/systems/custom_behaviour.h | 1 + src/gfx_device_vulkan.cpp | 6 ++++-- src/resources/texture.cpp | 5 ++++- src/systems/custom_behaviour.cpp | 5 +++++ test/src/game.cpp | 23 +++++++++++++++++++---- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/include/systems/custom_behaviour.h b/include/systems/custom_behaviour.h index aa6f917..89a17f5 100644 --- a/include/systems/custom_behaviour.h +++ b/include/systems/custom_behaviour.h @@ -14,6 +14,7 @@ namespace engine { ~CustomBehaviourSystem(); void OnUpdate(float ts) override; + void OnComponentInsert(uint32_t entity) override; private: diff --git a/src/gfx_device_vulkan.cpp b/src/gfx_device_vulkan.cpp index 087dffe..f616b49 100644 --- a/src/gfx_device_vulkan.cpp +++ b/src/gfx_device_vulkan.cpp @@ -1135,7 +1135,7 @@ namespace engine { void GFXDevice::UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet *set, uint32_t binding, const gfx::Image* image, const gfx::Sampler* sampler) { - assert(pimpl->FRAMECOUNT == 0); + //assert(pimpl->FRAMECOUNT == 0); VkDescriptorImageInfo imageInfo{}; imageInfo.sampler = sampler->sampler; @@ -1310,7 +1310,9 @@ namespace engine { gfx::Image* GFXDevice::CreateImage(uint32_t w, uint32_t h, const void* imageData) { assert(imageData != nullptr); - assert(pimpl->FRAMECOUNT == 0); + if (pimpl->FRAMECOUNT != 0) { + //throw std::runtime_error("Framecount must be 0 when creating a texture"); + } gfx::Image* out = new gfx::Image{}; diff --git a/src/resources/texture.cpp b/src/resources/texture.cpp index 75b75e4..e569984 100644 --- a/src/resources/texture.cpp +++ b/src/resources/texture.cpp @@ -98,6 +98,9 @@ Texture::Texture(RenderData* render_data, const uint8_t* bitmap, int width, LOG_INFO("Loaded texture: BITMAP, width: {} height: {}", width, height); } -Texture::~Texture() { gfx_->DestroyImage(image_); } +Texture::~Texture() { + LOG_INFO("Destroying texture..."); + gfx_->DestroyImage(image_); +} } // namespace engine::resources diff --git a/src/systems/custom_behaviour.cpp b/src/systems/custom_behaviour.cpp index 9322bd7..625f0c9 100644 --- a/src/systems/custom_behaviour.cpp +++ b/src/systems/custom_behaviour.cpp @@ -24,4 +24,9 @@ void CustomBehaviourSystem::OnUpdate(float ts) { } } +void CustomBehaviourSystem::OnComponentInsert(uint32_t entity) +{ + (void)entity; +} + } // namespace engine \ No newline at end of file diff --git a/test/src/game.cpp b/test/src/game.cpp index f4cd098..e13667a 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -130,8 +130,8 @@ void PlayGame(GameSettings settings) { floor_collider->aabb = {{0.0f, 0.0f, 0.0f}, {10000.0f, 1.0f, 10000.0f}}; } - //engine::util::LoadMeshFromFile( - // my_scene, app.GetResourcePath("models/astronaut/astronaut.dae")); + // engine::util::LoadMeshFromFile( + // my_scene, app.GetResourcePath("models/astronaut/astronaut.dae")); /* skybox */ { @@ -169,8 +169,23 @@ void PlayGame(GameSettings settings) { (float)height / (float)width; my_scene->AddComponent(textbox)->onUpdate = - [](float ts) { - /* LOG_INFO("Time step: {}", ts); */ + [&](float ts) { + (void)ts; + static float time_elapsed; + time_elapsed += ts; + if (time_elapsed >= 1.0f) { + time_elapsed = 0; + LOG_INFO("Time step: {}", ts); + + int fpsWidth, fpsHeight; + auto fpsBitmap = + app.GetResource("builtin.mono") + ->GetTextBitmap("fps", 768.0f, fpsWidth, fpsHeight); + textbox_renderable->material->texture_ = + std::make_unique( + &app.render_data_, fpsBitmap->data(), fpsWidth, fpsHeight, + engine::resources::Texture::Filtering::kBilinear); + } }; }