From 546ac9bb0008bd0c66bd54481e06dc0e75f44384 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 24 Feb 2023 15:02:41 +0800 Subject: [PATCH] Gets the resource manager to pre-Load the textures when we set button texture asset ids --- SHADE_Engine/src/UI/SHButtonComponent.cpp | 3 +++ SHADE_Engine/src/UI/SHToggleButtonComponent.cpp | 5 ++++- SHADE_Engine/src/UI/SHUISystem.cpp | 15 ++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp index cbc36ce3..5cc31841 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -28,16 +28,19 @@ namespace SHADE void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept { defaultTexture = texture; + SHResourceManager::LoadOrGet(texture); } void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept { hoveredTexture = texture; + SHResourceManager::LoadOrGet(texture);\ } void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept { clickedTexture = texture; + SHResourceManager::LoadOrGet(texture); } diff --git a/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp index 1ae0e9e0..546a2a26 100644 --- a/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHToggleButtonComponent.cpp @@ -1,6 +1,7 @@ #include "SHpch.h" #include "SHToggleButtonComponent.h" - +#include "Resource/SHResourceManager.h" +#include "Graphics/MiddleEnd/Textures/SHTextureLibrary.h" namespace SHADE { @@ -28,11 +29,13 @@ namespace SHADE void SHToggleButtonComponent::SetDefaultTexture(AssetID texture) noexcept { defaultTexture = texture; + SHResourceManager::LoadOrGet(texture); } void SHToggleButtonComponent::SetToggledTexture(AssetID texture) noexcept { toggledTexture = texture; + SHResourceManager::LoadOrGet(texture); } void SHToggleButtonComponent::SetValue(bool value) noexcept diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index b42e71a6..e27c00a2 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -313,8 +313,8 @@ namespace SHADE { auto material = renderable->GetModifiableMaterial(); comp.currentTexture = textureID; - material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet(textureID)); - loadTexture = true; + material->SetProperty("data.textureIndex", SHResourceManager::Get(textureID)->TextureArrayIndex); + } @@ -368,8 +368,8 @@ namespace SHADE { auto material = renderable->GetModifiableMaterial(); comp.currentTexture = textureID; - material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet(textureID)); - loadTexture = true; + material->SetProperty("data.textureIndex", SHResourceManager::Get(textureID)->TextureArrayIndex); + } @@ -381,6 +381,8 @@ namespace SHADE { SHUISystem* system = (SHUISystem*)GetSystem(); auto& dense = SHComponentManager::GetDense(); + //We ensure that the textures are loaded before we do the update. + SHResourceManager::FinaliseChanges(); for (auto& comp : dense) { if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) @@ -393,11 +395,6 @@ namespace SHADE if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) system->UpdateToggleButtonComponent(comp); } - if (system->loadTexture == true) - { - system->loadTexture = false; - SHResourceManager::FinaliseChanges(); - } } SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept -- 2.40.1