From 683b1baeef606f9807df0d8a163f3d3e0140531d Mon Sep 17 00:00:00 2001 From: Benualdo Date: Mon, 16 Sep 2024 22:02:04 +0200 Subject: [PATCH] Add ResourceList helper class --- data/Prefabs/Benualdo.prefab | 182 +++++++-------- data/Prefabs/Billboard.prefab | 84 +++---- data/Prefabs/Cone.prefab | 95 ++++---- data/Prefabs/Floor/Concrete_3x3.prefab | 69 +++--- .../Floor/Concrete_Horizontal_3x3.prefab | 4 +- data/Prefabs/Floor/Grass_3x3.prefab | 90 ++++---- data/Prefabs/Football.prefab | 7 +- data/Prefabs/GJ.prefab | 210 ++++++++++-------- data/Prefabs/Goal.prefab | 160 ++++++------- data/Prefabs/Pablo.prefab | 182 +++++++-------- data/Prefabs/Romeo.prefab | 182 +++++++-------- src/core/Object/Factory.cpp | 2 + .../ImGuiAnimationResourceListHandler.hpp | 2 +- .../ImGuiResourceListHandler.hpp | 2 +- .../ImGuiMaterialResourceListHandler.hpp | 2 +- src/editor/ImGui/Window/ImGuiWindow.cpp | 6 + .../Animation/AnimationComponent.cpp | 12 +- .../Animation/AnimationResourceList.h | 19 +- .../Animation/AnimationResourceList.hpp | 61 +---- .../Component/Mesh/MaterialResourceList.h | 15 +- .../Component/Mesh/MaterialResourceList.hpp | 44 +--- src/engine/Component/Mesh/MeshComponent.cpp | 8 +- src/engine/Engine.vcxproj.filters | 3 + src/engine/IResourceList.h | 2 +- src/engine/Resource/ResourceList.h | 96 ++++++++ src/engine/World/GameObjectHierarchy.hpp | 2 +- src/engine/engine.vcxproj | 1 + 27 files changed, 780 insertions(+), 762 deletions(-) create mode 100644 src/engine/Resource/ResourceList.h diff --git a/data/Prefabs/Benualdo.prefab b/data/Prefabs/Benualdo.prefab index d3f150fa9..6a3352d53 100644 --- a/data/Prefabs/Benualdo.prefab +++ b/data/Prefabs/Benualdo.prefab @@ -1,34 +1,34 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + @@ -43,18 +43,18 @@ - - - + + + - - - + + + @@ -62,19 +62,19 @@ - - - + + + - + - + @@ -82,63 +82,63 @@ - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -149,103 +149,103 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/data/Prefabs/Billboard.prefab b/data/Prefabs/Billboard.prefab index 0a97f64e3..29ff38bab 100644 --- a/data/Prefabs/Billboard.prefab +++ b/data/Prefabs/Billboard.prefab @@ -1,45 +1,46 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - - - + + + + @@ -48,51 +49,52 @@ - - - + + + - - - + + + + - + - - - + + + - - - + + + - - - - + + + + - - - + + + diff --git a/data/Prefabs/Cone.prefab b/data/Prefabs/Cone.prefab index 6c31ef2e3..4e6b0ab5b 100644 --- a/data/Prefabs/Cone.prefab +++ b/data/Prefabs/Cone.prefab @@ -1,45 +1,46 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - - + + + @@ -48,74 +49,74 @@ - - - + + + - - - + + + - + - - - + + + - - - + + + - + - - - + + + - - - + + + - - - - + + + + - - - + + + diff --git a/data/Prefabs/Floor/Concrete_3x3.prefab b/data/Prefabs/Floor/Concrete_3x3.prefab index f9f1f7a3f..88ab8e7e2 100644 --- a/data/Prefabs/Floor/Concrete_3x3.prefab +++ b/data/Prefabs/Floor/Concrete_3x3.prefab @@ -1,45 +1,46 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - - - + + + + @@ -48,33 +49,33 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + diff --git a/data/Prefabs/Floor/Concrete_Horizontal_3x3.prefab b/data/Prefabs/Floor/Concrete_Horizontal_3x3.prefab index cea2c2a78..22131abf4 100644 --- a/data/Prefabs/Floor/Concrete_Horizontal_3x3.prefab +++ b/data/Prefabs/Floor/Concrete_Horizontal_3x3.prefab @@ -4,7 +4,7 @@ - + @@ -83,7 +83,7 @@ - + diff --git a/data/Prefabs/Floor/Grass_3x3.prefab b/data/Prefabs/Floor/Grass_3x3.prefab index a4a4ab04b..567f428be 100644 --- a/data/Prefabs/Floor/Grass_3x3.prefab +++ b/data/Prefabs/Floor/Grass_3x3.prefab @@ -1,45 +1,46 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - - - + + + + @@ -48,28 +49,29 @@ - - - + + + - - - + + + + - + - - - + + + @@ -79,33 +81,33 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + diff --git a/data/Prefabs/Football.prefab b/data/Prefabs/Football.prefab index 816197f5d..ef3096b51 100644 --- a/data/Prefabs/Football.prefab +++ b/data/Prefabs/Football.prefab @@ -4,7 +4,7 @@ - + @@ -89,7 +89,8 @@ - + + @@ -113,7 +114,7 @@ - + diff --git a/data/Prefabs/GJ.prefab b/data/Prefabs/GJ.prefab index 212876629..fc0257ecf 100644 --- a/data/Prefabs/GJ.prefab +++ b/data/Prefabs/GJ.prefab @@ -1,34 +1,34 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + @@ -39,18 +39,18 @@ - - - + + + - - - + + + @@ -58,19 +58,19 @@ - - - + + + - + - + @@ -78,53 +78,53 @@ - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -134,34 +134,52 @@ + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - + + + + - - - + + + @@ -172,26 +190,26 @@ - - - + + + - + - - - + + + - - - + + + @@ -205,18 +223,18 @@ - - - + + + - - - + + + @@ -224,10 +242,10 @@ - - - + + + @@ -235,26 +253,26 @@ - - - + + + - + - - - + + + - - - + + + @@ -268,18 +286,18 @@ - - - + + + - - - + + + @@ -287,10 +305,10 @@ - - - + + + diff --git a/data/Prefabs/Goal.prefab b/data/Prefabs/Goal.prefab index 5c8bf72f0..c14ed1fb5 100644 --- a/data/Prefabs/Goal.prefab +++ b/data/Prefabs/Goal.prefab @@ -1,41 +1,41 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + - - - + + + @@ -49,18 +49,18 @@ - - - + + + - - - + + + @@ -68,18 +68,18 @@ - - - + + + - - - + + + @@ -87,18 +87,18 @@ - - - + + + - - - + + + @@ -106,18 +106,18 @@ - - - + + + - - - + + + @@ -125,47 +125,47 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + @@ -176,26 +176,26 @@ - - - + + + - + - - - + + + - - - + + + @@ -209,18 +209,18 @@ - - - + + + - - - + + + @@ -228,10 +228,10 @@ - - - + + + diff --git a/data/Prefabs/Pablo.prefab b/data/Prefabs/Pablo.prefab index f32332664..fff5df62c 100644 --- a/data/Prefabs/Pablo.prefab +++ b/data/Prefabs/Pablo.prefab @@ -1,34 +1,34 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + @@ -43,18 +43,18 @@ - - - + + + - - - + + + @@ -62,19 +62,19 @@ - - - + + + - + - + @@ -82,63 +82,63 @@ - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -149,103 +149,103 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/data/Prefabs/Romeo.prefab b/data/Prefabs/Romeo.prefab index 002a540cf..68114a41a 100644 --- a/data/Prefabs/Romeo.prefab +++ b/data/Prefabs/Romeo.prefab @@ -1,34 +1,34 @@ - - - - + + + + - - - + + + - + - - - + + + - + - - - + + + @@ -43,18 +43,18 @@ - - - + + + - - - + + + @@ -62,19 +62,19 @@ - - - + + + - + - + @@ -82,63 +82,63 @@ - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -149,103 +149,103 @@ - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/src/core/Object/Factory.cpp b/src/core/Object/Factory.cpp index 571f32eb8..0a04935e2 100644 --- a/src/core/Object/Factory.cpp +++ b/src/core/Object/Factory.cpp @@ -33,6 +33,8 @@ namespace vg::core // TODO : make proper API to register deprecated property names names for each class m_oldPropertyNames.insert(std::pair("m_world", "m_local")); m_oldPropertyNames.insert(std::pair("m_radius", "m_bottomRadius")); + m_oldPropertyNames.insert(std::pair("m_materialResources", "m_resources")); + m_oldPropertyNames.insert(std::pair("m_animationResources", "m_resources")); // TODO: make proper API blah m_oldClassNames.insert(std::pair("RigidBodyComponent", "PhysicsBodyComponent")); diff --git a/src/editor/ImGui/ObjectHandler/Animation/ImGuiAnimationResourceListHandler.hpp b/src/editor/ImGui/ObjectHandler/Animation/ImGuiAnimationResourceListHandler.hpp index fe7bf811b..1cfcdaf53 100644 --- a/src/editor/ImGui/ObjectHandler/Animation/ImGuiAnimationResourceListHandler.hpp +++ b/src/editor/ImGui/ObjectHandler/Animation/ImGuiAnimationResourceListHandler.hpp @@ -13,7 +13,7 @@ namespace vg::editor //-------------------------------------------------------------------------------------- bool displayObject(IObject * _object, ObjectContext & _objectContext) final { - return displayResourceList(_object, "Animation", "m_animationResources"); + return displayResourceList(_object, "Animation", "m_resources"); } }; diff --git a/src/editor/ImGui/ObjectHandler/ImGuiResourceListHandler.hpp b/src/editor/ImGui/ObjectHandler/ImGuiResourceListHandler.hpp index 9085692a2..fd026d78f 100644 --- a/src/editor/ImGui/ObjectHandler/ImGuiResourceListHandler.hpp +++ b/src/editor/ImGui/ObjectHandler/ImGuiResourceListHandler.hpp @@ -32,7 +32,7 @@ namespace vg::editor ImVec2 collapsingHeaderPos = ImGui::GetCursorPos(); - string label = fmt::sprintf("%s[%u])", _label.c_str(), resourceCount); + string label = fmt::sprintf("%ss (%u)", _label.c_str(), resourceCount); ImGuiStyle & style = ImGui::GetStyle(); diff --git a/src/editor/ImGui/ObjectHandler/Material/ImGuiMaterialResourceListHandler.hpp b/src/editor/ImGui/ObjectHandler/Material/ImGuiMaterialResourceListHandler.hpp index b99234289..a69f77bf8 100644 --- a/src/editor/ImGui/ObjectHandler/Material/ImGuiMaterialResourceListHandler.hpp +++ b/src/editor/ImGui/ObjectHandler/Material/ImGuiMaterialResourceListHandler.hpp @@ -13,7 +13,7 @@ namespace vg::editor //-------------------------------------------------------------------------------------- bool displayObject(IObject * _object, ObjectContext & _objectContext) final { - return displayResourceList(_object, "Material", "m_materialResources"); + return displayResourceList(_object, "Material", "m_resources"); } }; diff --git a/src/editor/ImGui/Window/ImGuiWindow.cpp b/src/editor/ImGui/Window/ImGuiWindow.cpp index 61d56b0ed..8e0ff13d1 100644 --- a/src/editor/ImGui/Window/ImGuiWindow.cpp +++ b/src/editor/ImGui/Window/ImGuiWindow.cpp @@ -1583,6 +1583,12 @@ namespace vg::editor if (debugInspector) componentShortName += fmt::sprintf(" (0x%016X)", (u64)pComponent); + //if (auto * nameProp = pComponent->GetClassDesc()->GetPropertyByName("m_name")) + //{ + // if (!asBool(core::PropertyFlags::NotVisible & nameProp->GetFlags())) + // componentShortName += " - " + *nameProp->GetPropertyString(pComponent); + //} + ImVec2 collapsingHeaderPos = ImGui::GetCursorPos(); const bool isOpen = asBool(ObjectFlags::Opened & pComponent->GetObjectFlags()); diff --git a/src/engine/Component/Animation/AnimationComponent.cpp b/src/engine/Component/Animation/AnimationComponent.cpp index c375ab25d..3cb811e5d 100644 --- a/src/engine/Component/Animation/AnimationComponent.cpp +++ b/src/engine/Component/Animation/AnimationComponent.cpp @@ -43,7 +43,7 @@ namespace vg::engine //-------------------------------------------------------------------------------------- void AnimationComponent::Update(const Context & _context) { - auto & animResources = m_animations.getAnimationResources(); + auto & animResources = m_animations.getResources(); if (_context.m_world->IsPlaying() && !_context.m_world->IsPaused()) // TODO: check if running from prefab world using context instead? Or include play/stop/paused state in context maybe? { @@ -138,7 +138,7 @@ namespace vg::engine MeshComponent * meshComponent = getMeshComponent(); if (meshComponent) { - auto & animResources = m_animations.getAnimationResources(); + auto & animResources = m_animations.getResources(); for (uint i = 0; i < animResources.size(); ++i) { AnimationResource & animRes = animResources[i]; @@ -173,7 +173,7 @@ namespace vg::engine //-------------------------------------------------------------------------------------- IAnimationResource * AnimationComponent::GetAnimation(core::uint _index) const { - auto & anims = m_animations.getAnimationResources(); + auto & anims = m_animations.getResources(); if (_index < GetAnimationCount()) return (IAnimationResource *) &anims[_index]; else @@ -183,7 +183,7 @@ namespace vg::engine //-------------------------------------------------------------------------------------- core::uint AnimationComponent::GetAnimationIndex(const core::string & _name) const { - auto & anims = m_animations.getAnimationResources(); + auto & anims = m_animations.getResources(); for (uint i = 0; i < anims.size(); ++i) { auto & anim = anims[i]; @@ -197,13 +197,13 @@ namespace vg::engine //-------------------------------------------------------------------------------------- core::uint AnimationComponent::GetAnimationCount() const { - return (uint)m_animations.getAnimationResources().size(); + return (uint)m_animations.getResources().size(); } //-------------------------------------------------------------------------------------- bool AnimationComponent::PlayAnimation(core::uint _index, float _blendTime, bool _loop) { - auto & anims = m_animations.getAnimationResources(); + auto & anims = m_animations.getResources(); if (_index != m_currentIndex) { diff --git a/src/engine/Component/Animation/AnimationResourceList.h b/src/engine/Component/Animation/AnimationResourceList.h index 3f1929553..1296cd710 100644 --- a/src/engine/Component/Animation/AnimationResourceList.h +++ b/src/engine/Component/Animation/AnimationResourceList.h @@ -1,29 +1,16 @@ #pragma once -#include "engine/IResourceList.h" +#include "engine/Resource/ResourceList.h" #include "engine/Resource/Animation/AnimationResource.h" namespace vg::engine { - class AnimationResourceList : public IResourceList + class AnimationResourceList : public ResourceList { public: - VG_CLASS_DECL(AnimationResourceList, core::Object); + VG_CLASS_DECL(AnimationResourceList, ResourceList); AnimationResourceList(const core::string & _name, core::IObject * _parent); ~AnimationResourceList(); - - void OnEnable () override; - void OnDisable () override; - - bool Add () final override; - bool Remove () final override; - size_t Size () const final override; - - const core::vector & getAnimationResources () const { return m_animationResources; } - core::vector & getAnimationResources () { return m_animationResources; } - - private: - core::vector m_animationResources; }; } \ No newline at end of file diff --git a/src/engine/Component/Animation/AnimationResourceList.hpp b/src/engine/Component/Animation/AnimationResourceList.hpp index 4e4c48397..4e51a0915 100644 --- a/src/engine/Component/Animation/AnimationResourceList.hpp +++ b/src/engine/Component/Animation/AnimationResourceList.hpp @@ -8,10 +8,9 @@ namespace vg::engine //-------------------------------------------------------------------------------------- AnimationResourceList::AnimationResourceList(const core::string & _name, core::IObject * _parent) : - IResourceList(_name, _parent) + super(_name, _parent) { - // resize of vector not supported because owner changes its address - m_animationResources.reserve(256); + } //-------------------------------------------------------------------------------------- @@ -24,60 +23,6 @@ namespace vg::engine bool AnimationResourceList::registerProperties(vg::core::IClassDesc & _desc) { super::registerProperties(_desc); - - registerPropertyObjectVectorEx(AnimationResourceList, m_animationResources, AnimationResource, "Animation", PropertyFlags::Resource); - - return true; - } - - //-------------------------------------------------------------------------------------- - void AnimationResourceList::OnEnable() - { - super::OnEnable(); - for (uint i = 0; i < m_animationResources.size(); ++i) - m_animationResources[i].OnEnable(); - } - - //-------------------------------------------------------------------------------------- - void AnimationResourceList::OnDisable() - { - for (uint i = 0; i < m_animationResources.size(); ++i) - m_animationResources[i].OnDisable(); - super::OnDisable(); - } - - //-------------------------------------------------------------------------------------- - bool AnimationResourceList::Add() - { - AnimationResource & animRes = m_animationResources.emplace_back(); - - // Update resource owners - for (auto & animRes : m_animationResources) - animRes.SetParent(this); - return true; - } - - //-------------------------------------------------------------------------------------- - bool AnimationResourceList::Remove() - { - if (m_animationResources.size() > 0) - { - m_animationResources.pop_back(); - - // Update resource owners - for (auto & animRes : m_animationResources) - animRes.SetParent(this); - - return true; - } - - return false; - } - - //-------------------------------------------------------------------------------------- - size_t AnimationResourceList::Size() const - { - return m_animationResources.size(); - } + } } \ No newline at end of file diff --git a/src/engine/Component/Mesh/MaterialResourceList.h b/src/engine/Component/Mesh/MaterialResourceList.h index 1e8a7dc7a..e8a4cc94e 100644 --- a/src/engine/Component/Mesh/MaterialResourceList.h +++ b/src/engine/Component/Mesh/MaterialResourceList.h @@ -1,25 +1,16 @@ #pragma once -#include "engine/IResourceList.h" +#include "engine/Resource/ResourceList.h" #include "engine/Resource/Material/MaterialResource.h" namespace vg::engine { - class MaterialResourceList : public IResourceList + class MaterialResourceList : public ResourceList { public: - VG_CLASS_DECL(MaterialResourceList, core::Object); + VG_CLASS_DECL(MaterialResourceList, ResourceList); MaterialResourceList(const core::string & _name, core::IObject * _parent); ~MaterialResourceList(); - - bool Add() final override; - bool Remove() final override; - size_t Size() const final override; - - const core::vector & getMaterialResources() const { return m_materialResources; } - - private: - core::vector m_materialResources; }; } \ No newline at end of file diff --git a/src/engine/Component/Mesh/MaterialResourceList.hpp b/src/engine/Component/Mesh/MaterialResourceList.hpp index 8ef46393b..3c8be733f 100644 --- a/src/engine/Component/Mesh/MaterialResourceList.hpp +++ b/src/engine/Component/Mesh/MaterialResourceList.hpp @@ -11,57 +11,19 @@ namespace vg::engine bool MaterialResourceList::registerProperties(vg::core::IClassDesc & _desc) { super::registerProperties(_desc); - - registerPropertyObjectVectorEx(MaterialResourceList, m_materialResources, MaterialResource, "Material", PropertyFlags::Resource); - return true; } //-------------------------------------------------------------------------------------- MaterialResourceList::MaterialResourceList(const core::string & _name, core::IObject * _parent) : - IResourceList(_name, _parent) - { - // resize of vector not supported because owner changes its address - m_materialResources.reserve(256); - } - - //-------------------------------------------------------------------------------------- - MaterialResourceList::~MaterialResourceList() + super(_name, _parent) { } //-------------------------------------------------------------------------------------- - bool MaterialResourceList::Add() - { - MaterialResource & matRes = m_materialResources.emplace_back(); - - // Update resource owners - for (auto & matRes : m_materialResources) - matRes.SetParent(this); - - return true; - } - - //-------------------------------------------------------------------------------------- - bool MaterialResourceList::Remove() + MaterialResourceList::~MaterialResourceList() { - if (m_materialResources.size() > 0) - { - m_materialResources.pop_back(); - - // Update resource owners - for (auto & matRes : m_materialResources) - matRes.SetParent(this); - return true; - } - return false; - } - - //-------------------------------------------------------------------------------------- - size_t MaterialResourceList::Size() const - { - return m_materialResources.size(); - } + } } \ No newline at end of file diff --git a/src/engine/Component/Mesh/MeshComponent.cpp b/src/engine/Component/Mesh/MeshComponent.cpp index 42bf33e53..965561fb2 100644 --- a/src/engine/Component/Mesh/MeshComponent.cpp +++ b/src/engine/Component/Mesh/MeshComponent.cpp @@ -144,7 +144,7 @@ namespace vg::engine VG_ASSERT(matResData); MaterialResource * matRes = dynamic_cast(matResData->GetParent()); VG_ASSERT(matRes); - const auto & matResources = m_meshMaterials.getMaterialResources(); + const auto & matResources = m_meshMaterials.getResources(); for (uint i = 0; i < matResources.size(); ++i) { if (&matResources[i] == matRes) @@ -162,7 +162,7 @@ namespace vg::engine VG_ASSERT(matResData); MaterialResource * matRes = dynamic_cast(matResData->GetParent()); VG_ASSERT(matRes); - const auto & matResources = m_meshMaterials.getMaterialResources(); + const auto & matResources = m_meshMaterials.getResources(); for (uint i = 0; i < matResources.size(); ++i) { if (&matResources[i] == matRes) @@ -211,7 +211,7 @@ namespace vg::engine else if (auto matRes = dynamic_cast(_resource)) { // Material resource loaded - const auto & matResources = m_meshMaterials.getMaterialResources(); + const auto & matResources = m_meshMaterials.getResources(); for (uint i = 0; i < matResources.size(); ++i) { if (&matResources[i] == matRes) @@ -246,7 +246,7 @@ namespace vg::engine else if (auto matRes = dynamic_cast(_resource)) { // Material resource loaded - const auto & matResources = m_meshMaterials.getMaterialResources(); + const auto & matResources = m_meshMaterials.getResources(); for (uint i = 0; i < matResources.size(); ++i) { if (&matResources[i] == matRes) diff --git a/src/engine/Engine.vcxproj.filters b/src/engine/Engine.vcxproj.filters index e7ce248b5..08d4a0d3f 100644 --- a/src/engine/Engine.vcxproj.filters +++ b/src/engine/Engine.vcxproj.filters @@ -337,6 +337,9 @@ Resource\Audio + + Resource + diff --git a/src/engine/IResourceList.h b/src/engine/IResourceList.h index b7d7769ca..53046d434 100644 --- a/src/engine/IResourceList.h +++ b/src/engine/IResourceList.h @@ -7,7 +7,7 @@ namespace vg::engine class IResourceList : public core::Object { public: - VG_CLASS_DECL_PASSTHROUGH(IResourceList, core::Object) + VG_CLASS_DECL_ABSTRACT(IResourceList, core::Object) virtual bool Add() = 0; virtual bool Remove() = 0; diff --git a/src/engine/Resource/ResourceList.h b/src/engine/Resource/ResourceList.h new file mode 100644 index 000000000..cba0f37a1 --- /dev/null +++ b/src/engine/Resource/ResourceList.h @@ -0,0 +1,96 @@ +#pragma once + +#include "engine/IResourceList.h" + +namespace vg::engine +{ + template class ResourceList : public IResourceList + { + public: + VG_CLASS_DECL(ResourceList, IResourceList); + + ResourceList(const core::string & _name, core::IObject * _parent) : + super(_name, _parent) + { + m_resources.reserve(256); + } + + ~ResourceList() + { + + } + + //-------------------------------------------------------------------------------------- + bool Add() override + { + T & res = m_resources.emplace_back(); + + for (auto & res : m_resources) + res.SetParent(this); + + return true; + } + + //-------------------------------------------------------------------------------------- + bool Remove() override + { + if (m_resources.size() > 0) + { + m_resources.pop_back(); + + for (auto & res : m_resources) + res.SetParent(this); + + return true; + } + return false; + } + + //-------------------------------------------------------------------------------------- + size_t Size() const override + { + return m_resources.size(); + } + + //-------------------------------------------------------------------------------------- + const core::vector & getResources() const + { + return m_resources; + } + + //-------------------------------------------------------------------------------------- + core::vector & getResources() + { + return m_resources; + } + + //-------------------------------------------------------------------------------------- + void OnEnable() + { + super::OnEnable(); + for (auto i = 0; i < m_resources.size(); ++i) + m_resources[i].OnEnable(); + } + + //-------------------------------------------------------------------------------------- + void OnDisable() + { + for (auto i = 0; i < m_resources.size(); ++i) + m_resources[i].OnDisable(); + super::OnDisable(); + } + + protected: + core::vector m_resources; + }; + + //-------------------------------------------------------------------------------------- + template bool ResourceList::registerProperties(vg::core::IClassDesc & _desc) + { + super::registerProperties(_desc); + + registerPropertyObjectVectorEx(ResourceList, m_resources, T, "Resources", core::PropertyFlags::Resource); + + return true; + } +} \ No newline at end of file diff --git a/src/engine/World/GameObjectHierarchy.hpp b/src/engine/World/GameObjectHierarchy.hpp index fef3d8ed5..24d9f1d08 100644 --- a/src/engine/World/GameObjectHierarchy.hpp +++ b/src/engine/World/GameObjectHierarchy.hpp @@ -40,7 +40,7 @@ namespace vg::engine { super::registerProperties(_desc); - registerPropertyObjectPtr(Scene, m_root, "Root"); + registerPropertyObjectPtrEx(Scene, m_root, "Root", core::PropertyFlags::NotVisible); return true; } diff --git a/src/engine/engine.vcxproj b/src/engine/engine.vcxproj index e682f7782..de3f9a9c4 100644 --- a/src/engine/engine.vcxproj +++ b/src/engine/engine.vcxproj @@ -70,6 +70,7 @@ +