From c2fa5f2b94389df9750a2e9db88b358bf02c13b2 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 25 Aug 2022 06:27:11 +0000 Subject: [PATCH] Use stl style on stl replacement classes --- include/Orange/Core/Array.h | 6 +-- include/Orange/Core/Bitset.h | 4 +- include/Orange/Core/Hash.h | 12 ++--- include/Orange/Core/Parse.h | 2 +- include/Orange/Core/Span.h | 2 +- include/Orange/Core/Time.h | 8 +-- include/Orange/Core/Vector.h | 64 ++++++++++++------------ include/Orange/Graphics/Mesh.h | 2 +- include/Orange/Math/Swizzle.h | 6 +-- include/Orange/Render/Input.h | 2 +- include/Orange/Render/VulkanHelpers.h | 4 +- src/Apps/Tools/CubeTest.cpp | 30 +++++------ src/Orange/Graphics/Mesh.cpp | 24 ++++----- src/Orange/Render/RenderContext_Init.cpp | 6 +-- src/Orange/Render/Swapchain.cpp | 6 +-- 15 files changed, 89 insertions(+), 89 deletions(-) diff --git a/include/Orange/Core/Array.h b/include/Orange/Core/Array.h index f47de89..2fceaed 100644 --- a/include/Orange/Core/Array.h +++ b/include/Orange/Core/Array.h @@ -28,10 +28,10 @@ namespace orange static_assert(sizeof...(Args) == N); } - constexpr T* Data() { return &m_data[0]; } - constexpr const T* Data() const { return &m_data[0]; } + constexpr T* data() { return &m_data[0]; } + constexpr const T* data() const { return &m_data[0]; } - constexpr size_t Size() const { return N; } + constexpr size_t size() const { return N; } constexpr Array(const Array& other) = default; diff --git a/include/Orange/Core/Bitset.h b/include/Orange/Core/Bitset.h index 0c7e538..176a885 100644 --- a/include/Orange/Core/Bitset.h +++ b/include/Orange/Core/Bitset.h @@ -68,7 +68,7 @@ namespace orange } - constexpr void setAll() + constexpr void set_all() { if constexpr (BitCount % 32u == 0u) { @@ -85,7 +85,7 @@ namespace orange } - constexpr void clearAll() + constexpr void clear_all() { for (size_t i = 0; i < DwordCount; i++) dwords[i] = 0u; diff --git a/include/Orange/Core/Hash.h b/include/Orange/Core/Hash.h index 4ef704c..e9c7127 100644 --- a/include/Orange/Core/Hash.h +++ b/include/Orange/Core/Hash.h @@ -4,24 +4,24 @@ namespace orange { - constexpr uint32_t HashString(const char* s, size_t count) + constexpr uint32_t hash_string(const char* s, size_t count) { - return ((count ? HashString(s, count - 1) : 2166136261u) ^ s[count]) * 16777619u; + return ((count ? hash_string(s, count - 1) : 2166136261u) ^ s[count]) * 16777619u; } constexpr uint32_t operator"" _hash(const char* s, size_t count) { - return HashString(s, count); + return hash_string(s, count); } - inline size_t& hashCombine(size_t& seed) { (void)seed; return seed; } + inline size_t& hash_combine(size_t& seed) { (void)seed; return seed; } template - inline size_t& hashCombine(size_t& seed, const T& v, Rest... rest) + inline size_t& hash_combine(size_t& seed, const T& v, Rest... rest) { std::hash hasher; seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); - hashCombine(seed, rest...); + hash_combine(seed, rest...); return seed; } } diff --git a/include/Orange/Core/Parse.h b/include/Orange/Core/Parse.h index 1a3ed5a..35eeb17 100644 --- a/include/Orange/Core/Parse.h +++ b/include/Orange/Core/Parse.h @@ -75,7 +75,7 @@ namespace orange::stream while (!EndOfStream(first, end) && !CharMatches(*first, delims)) { if (array) - array->PushBack(*first); + array->push_back(*first); first++; count++; } diff --git a/include/Orange/Core/Span.h b/include/Orange/Core/Span.h index adf04dd..fe8116a 100644 --- a/include/Orange/Core/Span.h +++ b/include/Orange/Core/Span.h @@ -50,7 +50,7 @@ namespace orange T& back() { return data[size - 1]; } const T& back() const { return data[size - 1]; } - void Copy(void* dst) + void copy(void* dst) { memcpy(dst, data, sizeof(T) * size); } diff --git a/include/Orange/Core/Time.h b/include/Orange/Core/Time.h index 197f823..db4aebb 100644 --- a/include/Orange/Core/Time.h +++ b/include/Orange/Core/Time.h @@ -21,8 +21,8 @@ namespace orange static inline time_point now() noexcept { // Keep the frequency static, this doesn't change at all. - static const int64_t freq = getFrequency(); - const int64_t counter = getCounter(); + static const int64_t freq = get_frequency(); + const int64_t counter = get_counter(); const int64_t whole = (counter / freq) * period::den; const int64_t part = (counter % freq) * period::den / freq; @@ -30,7 +30,7 @@ namespace orange return time_point(duration(whole + part)); } - static inline int64_t getFrequency() noexcept + static inline int64_t get_frequency() noexcept { LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); @@ -38,7 +38,7 @@ namespace orange return freq.QuadPart; } - static inline int64_t getCounter() noexcept + static inline int64_t get_counter() noexcept { LARGE_INTEGER count; QueryPerformanceCounter(&count); diff --git a/include/Orange/Core/Vector.h b/include/Orange/Core/Vector.h index a7ae8aa..87c182d 100644 --- a/include/Orange/Core/Vector.h +++ b/include/Orange/Core/Vector.h @@ -12,32 +12,32 @@ namespace orange public: SmallVector() {} - SmallVector(size_t size) { Resize(size); } + SmallVector(size_t size) { resize(size); } SmallVector(Span span) { - Reserve(span.size); + reserve(span.size); for (const auto& val : span) - PushBack(val); + push_back(val); } constexpr SmallVector(std::initializer_list list) { - Reserve(list.size()); + reserve(list.size()); for (const auto& val : list) - PushBack(val); + push_back(val); } SmallVector (const SmallVector& x) { - Reserve(x.Size()); + reserve(x.size()); for (const auto& val : x) - PushBack(val); + push_back(val); } SmallVector& operator = (const SmallVector& x) { - Clear(); - Reserve(x.Size()); + clear(); + reserve(x.size()); for (const auto& val : x) - PushBack(val); + push_back(val); } ~SmallVector() @@ -60,7 +60,7 @@ namespace orange return Span(*this) == StringView(x); } - void Reserve(size_t n) + void reserve(size_t n) { n = PickCapacity(n); @@ -82,19 +82,19 @@ namespace orange u.m_ptr = data; } - size_t Size() const { return m_size; } + size_t size() const { return m_size; } - const T* Data() const { return Ptr(0); } - T* Data() { return Ptr(0); } + const T* data() const { return Ptr(0); } + T* data() { return Ptr(0); } - void Clear() + void clear() { - Resize(0); + resize(0); } - void Resize(size_t n) + void resize(size_t n) { - Reserve(n); + reserve(n); for (size_t i = n; i < m_size; i++) Ptr(i)->~T(); @@ -105,29 +105,29 @@ namespace orange m_size = n; } - size_t PushBack(const T& object) + size_t push_back(const T& object) { - Reserve(m_size + 1); + reserve(m_size + 1); new (Ptr(m_size++)) T(object); return m_size - 1; } - size_t PushBack(T&& object) + size_t push_back(T&& object) { - Reserve(m_size + 1); + reserve(m_size + 1); new (Ptr(m_size++)) T(Move(object)); return m_size - 1; } template - size_t EmplaceBack(Args... args) + size_t emplace_back(Args... args) { - Reserve(m_size + 1); + reserve(m_size + 1); new (Ptr(m_size++)) T(Forward(args)...); return m_size - 1; } - void Erase(size_t idx) + void erase(size_t idx) { Ptr(idx)->~T(); @@ -138,19 +138,19 @@ namespace orange } } - void PopBack() + void pop_back() { Ptr(--m_size)->~T(); } - bool Empty() const + bool empty() const { - return Size() == 0; + return size() == 0; } constexpr static size_t InvalidIdx = ~(0zu); - size_t FindIdx(const T& x) const + size_t find_idx(const T& x) const { for (size_t i = 0; i < m_size; i++) { @@ -161,12 +161,12 @@ namespace orange return InvalidIdx; } - bool Contains(const T& x) const + bool contains(const T& x) const { - return FindIdx(x) != InvalidIdx; + return find_idx(x) != InvalidIdx; } - void Copy(void* dst) + void copy(void* dst) { memcpy(dst, Ptr(0), sizeof(T) * m_size); } diff --git a/include/Orange/Graphics/Mesh.h b/include/Orange/Graphics/Mesh.h index 805bb46..98ecafb 100644 --- a/include/Orange/Graphics/Mesh.h +++ b/include/Orange/Graphics/Mesh.h @@ -64,7 +64,7 @@ namespace orange uint32_t VertexCount() const { // Type doesn't matter here, just want to grab m_size. - return uint32_t(vertices.Get>().Size()); + return uint32_t(vertices.Get>().size()); } MeshVertexType vertexType; diff --git a/include/Orange/Math/Swizzle.h b/include/Orange/Math/Swizzle.h index 717ef76..70e3ac7 100644 --- a/include/Orange/Math/Swizzle.h +++ b/include/Orange/Math/Swizzle.h @@ -85,7 +85,7 @@ namespace orange constexpr Swizzle(const T components[2]) { - Copy(&components[0], &components[2], data.begin()); + copy(&components[0], &components[2], data.begin()); } template @@ -128,7 +128,7 @@ namespace orange constexpr Swizzle(const T components[3]) { - Copy(&components[0], &components[3], data.begin()); + copy(&components[0], &components[3], data.begin()); } template @@ -173,7 +173,7 @@ namespace orange constexpr Swizzle(const T components[4]) { - Copy(&components[0], &components[4], data.begin()); + copy(&components[0], &components[4], data.begin()); } template diff --git a/include/Orange/Render/Input.h b/include/Orange/Render/Input.h index 8fe44f0..7200437 100644 --- a/include/Orange/Render/Input.h +++ b/include/Orange/Render/Input.h @@ -182,7 +182,7 @@ namespace orange::Input void flushKeys() { - m_firstPressed.clearAll(); + m_firstPressed.clear_all(); } void addMouseMotionDelta(MouseDelta delta) diff --git a/include/Orange/Render/VulkanHelpers.h b/include/Orange/Render/VulkanHelpers.h index 711d0ce..40c49cf 100644 --- a/include/Orange/Render/VulkanHelpers.h +++ b/include/Orange/Render/VulkanHelpers.h @@ -12,11 +12,11 @@ namespace orange uint32_t count = 0; function(arguments..., &count, nullptr); - outArray.Resize(count); + outArray.resize(count); if (!count) return 0; - function(Forward(arguments)..., &count, outArray.Data()); + function(Forward(arguments)..., &count, outArray.data()); return count; } diff --git a/src/Apps/Tools/CubeTest.cpp b/src/Apps/Tools/CubeTest.cpp index 571257a..7b4dc98 100644 --- a/src/Apps/Tools/CubeTest.cpp +++ b/src/Apps/Tools/CubeTest.cpp @@ -69,8 +69,8 @@ static VulkanResult CreateGraphicsPipeline(VkDevice device, const Mi VkPipelineDynamicStateCreateInfo dynamicStateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .dynamicStateCount = uint32_t(dynamicStates.Size()), - .pDynamicStates = dynamicStates.Data(), + .dynamicStateCount = uint32_t(dynamicStates.size()), + .pDynamicStates = dynamicStates.data(), }; VkVertexInputBindingDescription inputBindingDescription = @@ -239,34 +239,34 @@ int main(int argc, char** argv) auto r_mesh = ParseOBJ(*r_objData); auto newVertexSlice = *pooler.AllocSlice(sizeof(StaticVertex) * r_mesh->vertexData.VertexCount(), sizeof(StaticVertex)); - auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.Size(), sizeof(IndexType)); - r_mesh->vertexData.GetStaticVertices().Copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset); - r_mesh->indices.Copy ((uint8_t*)(r_buffer->ptr) + newIndexSlice.offset); + auto newIndexSlice = *pooler.AllocSlice(sizeof(IndexType) * r_mesh->indices.size(), sizeof(IndexType)); + r_mesh->vertexData.GetStaticVertices().copy((uint8_t*)(r_buffer->ptr) + newVertexSlice.offset); + r_mesh->indices.copy ((uint8_t*)(r_buffer->ptr) + newIndexSlice.offset); - uint32_t meshIdx = uint32_t(g_meshes.EmplaceBack(Mesh + uint32_t meshIdx = uint32_t(g_meshes.emplace_back(Mesh { .textureIdx = 0, .vertexOffset = uint32_t(newVertexSlice.offset / sizeof(StaticVertex)), .indexOffset = uint32_t(newIndexSlice.offset / sizeof(IndexType)), - .indexCount = uint32_t(r_mesh->indices.Size()), + .indexCount = uint32_t(r_mesh->indices.size()), .bounds = r_mesh->bounds, })); - g_renderables.EmplaceBack(Renderable + g_renderables.emplace_back(Renderable { .transform = mat4{}, .meshIdx = meshIdx, .color = 16_vec3, }); - g_renderables.EmplaceBack(Renderable + g_renderables.emplace_back(Renderable { .transform = Math::translate(32_vec3), .meshIdx = meshIdx, .color = 1_vec3, }); - g_renderables.EmplaceBack(Renderable + g_renderables.emplace_back(Renderable { .transform = Math::translate(-32_vec3), .meshIdx = meshIdx, @@ -486,7 +486,7 @@ int main(int argc, char** argv) }; vkUpdateDescriptorSets(r_renderContext->Device(), Size(writeImageDescriptorSet), writeImageDescriptorSet, 0, nullptr); - imageUploads.PushBack(ImageUpload + imageUploads.push_back(ImageUpload { .from = pngLinearSlice, .to = *r_texture, @@ -567,7 +567,7 @@ int main(int argc, char** argv) auto indirectBuffer = *pooler.AllocSlice(1024 * sizeof(VkDrawIndexedIndirectCommand), 256); auto indirectPtr = reinterpret_cast(indirectBuffer.ptr); - for (size_t i = 0; i < g_renderables.Size(); i++) { + for (size_t i = 0; i < g_renderables.size(); i++) { const auto& renderable = g_renderables[i]; const uint32_t meshIdx = 0;//renderable.meshIdx; @@ -583,7 +583,7 @@ int main(int argc, char** argv) auto countBuffer = *pooler.AllocSlice(sizeof(uint32_t), 16); auto countPtr = reinterpret_cast(countBuffer.ptr); - *countPtr = uint32_t(g_renderables.Size()); + *countPtr = uint32_t(g_renderables.size()); auto t1 = Time::now(); while (r_window->Update(handler)) @@ -617,7 +617,7 @@ int main(int argc, char** argv) .view = camera.view(), }; - g_renderables.Copy(gpuRenderables[r_swapchain->CurrentFrame()].renderables); + g_renderables.copy(gpuRenderables[r_swapchain->CurrentFrame()].renderables); const float movementSpeed = handler.get(Input::ButtonCodes::Key_LShift) ? 64.0f : 16.0f; @@ -657,7 +657,7 @@ int main(int argc, char** argv) }; vkCmdCopyBufferToImage(cmdBuf, upload.from.buffer, upload.to, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, ®ion); } - imageUploads.Clear(); + imageUploads.clear(); VkViewport viewport = { diff --git a/src/Orange/Graphics/Mesh.cpp b/src/Orange/Graphics/Mesh.cpp index b325815..07c6c05 100644 --- a/src/Orange/Graphics/Mesh.cpp +++ b/src/Orange/Graphics/Mesh.cpp @@ -14,7 +14,7 @@ namespace orange size_t operator() (const StaticVertex& key) const { size_t hash = 0; - return hashCombine(hash, key.pos.x, key.pos.y, key.pos.z, key.uv.x, key.uv.y, key.normal.x, key.normal.y, key.normal.z); + return hash_combine(hash, key.pos.x, key.pos.y, key.pos.z, key.uv.x, key.uv.y, key.normal.x, key.normal.y, key.normal.z); } }; @@ -47,11 +47,11 @@ namespace orange } if (element == "v") - positions.EmplaceBack(vtx[0], -vtx[2], vtx[1]); // TODO remove hack and make this customizable + positions.emplace_back(vtx[0], -vtx[2], vtx[1]); // TODO remove hack and make this customizable else if (element == "vt") - uvs.EmplaceBack(vtx[0], 1.0f - vtx[1]); // Fix the space from gl -> vk/dx + uvs.emplace_back(vtx[0], 1.0f - vtx[1]); // Fix the space from gl -> vk/dx else if (element == "vn") - normals.EmplaceBack(vtx[0], vtx[1], vtx[2]); + normals.emplace_back(vtx[0], vtx[1], vtx[2]); } else if (element == "g" || element == "o") { @@ -59,11 +59,11 @@ namespace orange SmallVector name; stream::ReadString(obj, end, " #\n", name); - name.PushBack('\0'); + name.push_back('\0'); if (element == "g") - log::info("Group name: %s", name.Data()); + log::info("Group name: %s", name.data()); else - log::info("Object name: %s", name.Data()); + log::info("Object name: %s", name.data()); } else if (element == "f") { @@ -102,20 +102,20 @@ namespace orange if (iter == indexTracker.end()) { data.bounds.Extend(vertex.pos); - vertexIdx = vertices.PushBack(vertex); + vertexIdx = vertices.push_back(vertex); indexTracker.emplace(vertex, vertexIdx); } else vertexIdx = iter->second; Assert(vertexIdx < MaxMeshIndex); - data.indices.PushBack(IndexType(vertexIdx)); + data.indices.push_back(IndexType(vertexIdx)); } } - else if (!element.Empty()) + else if (!element.empty()) { - element.PushBack('\0'); - log::info("Unknown element: %s", element.Data()); + element.push_back('\0'); + log::info("Unknown element: %s", element.data()); } stream::AdvancePast(obj, end, "\n"); diff --git a/src/Orange/Render/RenderContext_Init.cpp b/src/Orange/Render/RenderContext_Init.cpp index fc439e4..d1d77bd 100644 --- a/src/Orange/Render/RenderContext_Init.cpp +++ b/src/Orange/Render/RenderContext_Init.cpp @@ -35,8 +35,8 @@ namespace orange { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &appInfo, - .enabledExtensionCount = uint32_t(instanceExtensions.Size()), - .ppEnabledExtensionNames = instanceExtensions.Data(), + .enabledExtensionCount = uint32_t(instanceExtensions.size()), + .ppEnabledExtensionNames = instanceExtensions.data(), }; VkResult result = VK_SUCCESS; @@ -52,7 +52,7 @@ namespace orange SmallVector queueFamilyProperties; VkEnumerate(vkGetPhysicalDeviceQueueFamilyProperties, queueFamilyProperties, physicalDevice); - for (uint32_t i = 0; i < queueFamilyProperties.Size(); i++) + for (uint32_t i = 0; i < queueFamilyProperties.size(); i++) { const auto& family = queueFamilyProperties[i]; if (family.queueFlags & VK_QUEUE_GRAPHICS_BIT) diff --git a/src/Orange/Render/Swapchain.cpp b/src/Orange/Render/Swapchain.cpp index d36b23e..6418664 100644 --- a/src/Orange/Render/Swapchain.cpp +++ b/src/Orange/Render/Swapchain.cpp @@ -118,8 +118,8 @@ namespace orange if (!VkEnumerate(vkGetSwapchainImagesKHR, swapchainImages, context.Device(), swapchain)) return Result::PrintError("Failed to get swapchain images"); - SmallVector swapchainImageViews{ swapchainImages.Size() }; - for (size_t i = 0; i < swapchainImages.Size(); i++) + SmallVector swapchainImageViews{ swapchainImages.size() }; + for (size_t i = 0; i < swapchainImages.size(); i++) { VkImageViewCreateInfo imageViewInfo = { @@ -144,7 +144,7 @@ namespace orange .commandBufferCount = DefaultFramesInFlight, }; - if (vkAllocateCommandBuffers(context.Device(), &commandBufferInfo, commandBuffers.Data()) != VK_SUCCESS) + if (vkAllocateCommandBuffers(context.Device(), &commandBufferInfo, commandBuffers.data()) != VK_SUCCESS) return Result::PrintError("Failed to get swapchain image view"); }