From f4f497194af175a56238a4e3d791cfb2994d437c Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 11 Apr 2025 18:15:39 +0200 Subject: [PATCH] Slight changes to accomodate game --- CMakeSettings.json | 2 +- src/Engine/Containers/Array.h | 24 +++++++++++------------- src/Engine/Graphics/VertexData.cpp | 14 ++++++++------ src/Engine/Graphics/VertexData.h | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index a95c7d1..0d03d3c 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -41,7 +41,7 @@ "buildCommandArgs": "", "ctestCommandArgs": "", "configurationType": "Debug", - "generator": "Ninja Multi-Config", + "generator": "Ninja", "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index be9e799..cd534d4 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -8,10 +8,6 @@ #include #include -#ifndef DEFAULT_ALLOC_SIZE -#define DEFAULT_ALLOC_SIZE 16 -#endif - namespace Seele { template struct Array { public: @@ -84,10 +80,7 @@ template struct Array { using const_reverse_iterator = std::reverse_iterator; constexpr Array(const allocator_type& alloc = allocator_type()) noexcept - : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) { - _data = allocateArray(DEFAULT_ALLOC_SIZE); - assert(_data != nullptr); - } + : arraySize(0), allocated(0), _data(nullptr), allocator(alloc) {} constexpr Array(size_type size, const value_type& value, const allocator_type& alloc = allocator_type()) : arraySize(size), allocated(size), allocator(alloc) { _data = allocateArray(size); @@ -313,7 +306,7 @@ template struct Array { } constexpr void resize(size_type newSize) { resizeInternal(newSize, T()); } constexpr void resize(size_type newSize, const value_type& value) { resizeInternal(newSize, value); } - constexpr void clear() noexcept { + constexpr void clear(bool preserveAllocation = false) noexcept { if (_data == nullptr) { return; } @@ -322,10 +315,12 @@ template struct Array { std::allocator_traits::destroy(allocator, &_data[i]); } } - deallocateArray(_data, allocated); - _data = nullptr; + if (!preserveAllocation) { + deallocateArray(_data, allocated); + _data = nullptr; + allocated = 0; + } arraySize = 0; - allocated = 0; } [[nodiscard]] constexpr size_type indexOf(iterator iterator) { return iterator - begin(); } [[nodiscard]] constexpr size_type indexOf(const_iterator iterator) const { return iterator.p - begin().p; } @@ -400,7 +395,10 @@ template struct Array { for (size_type i = 0; i < arraySize; ++i) { std::allocator_traits::construct(allocator, &tempArray[i], std::forward(_data[i])); } - deallocateArray(_data, arraySize); + if (_data != nullptr) + { + deallocateArray(_data, arraySize); + } _data = tempArray; } std::allocator_traits::construct(allocator, &_data[arraySize], std::forward(t)); diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index b690a82..30ef637 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -16,14 +16,16 @@ uint64 VertexData::meshletCount = 0; void VertexData::resetMeshData() { std::unique_lock l(materialDataLock); - instanceData.clear(); - instanceMeshData.clear(); - rayTracingScene.clear(); - transparentData.clear(); + instanceData.clear(true); + instanceMeshData.clear(true); + rayTracingScene.clear(true); + transparentData.clear(true); for (auto& mat : materialData) { for (auto& inst : mat.instances) { - inst.instanceData.clear(); - inst.instanceMeshData.clear(); + inst.instanceData.clear(true); + inst.instanceMeshData.clear(true); + inst.cullingOffsets.clear(true); + inst.rayTracingData.clear(true); } if (mat.material != nullptr) { mat.material->getDescriptorLayout()->reset(); diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 20007b9..e615674 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -56,7 +56,7 @@ class VertexData { }; void resetMeshData(); void updateMesh(uint32 meshletOffset, PMesh mesh, Component::Transform& transform); - void createDescriptors(); + virtual void createDescriptors(); void loadMesh(MeshId id, Array indices, Array meshlets); void commitMeshes(); MeshId allocateVertexData(uint64 numVertices);