From 2b5be4c732242461b5b20e0342f1a305a5f23aa3 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 11 Aug 2024 21:07:53 +0200 Subject: [PATCH] extract PTK_LIST_STATIC_INIT into PTK_ARRAY --- src/ptk_array.h | 18 ++++++++++++++++++ src/ptk_list.h | 7 ------- src/ptk_vk/init.c | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/ptk_array.h diff --git a/src/ptk_array.h b/src/ptk_array.h new file mode 100644 index 0000000..6f5ab79 --- /dev/null +++ b/src/ptk_array.h @@ -0,0 +1,18 @@ +#ifndef PTK_PTK_ARRAY_H_ +#define PTK_PTK_ARRAY_H_ + +#define PTK_ARRAY(T) struct PtkArray_##T + +#define PTK_ARRAY_DEFINE(T) \ + PTK_ARRAY(T) {\ + T *data;\ + uint32_t size;\ + }\ + +#define PTK_ARRAY_NEW(T, ...) \ + (PTK_ARRAY(T)){\ + .data = (T []) __VA_ARGS__ ,\ + .size = sizeof((T []) __VA_ARGS__) / sizeof(T),\ + } + +#endif // PTK_PTK_ARRAY_H_ diff --git a/src/ptk_list.h b/src/ptk_list.h index 9fde387..44feffa 100644 --- a/src/ptk_list.h +++ b/src/ptk_list.h @@ -37,13 +37,6 @@ bool _remove_at_PtkList(void *data, uint32_t *size, size_t index, size_t element .allocated = _size,\ } -#define PTK_LIST_STATIC_INIT(T, ...) \ - (PTK_LIST(T)){\ - .data = (T []) __VA_ARGS__ ,\ - .size = sizeof((T []) __VA_ARGS__) / sizeof(T),\ - .allocated = sizeof((T []) __VA_ARGS__) / sizeof(T),\ - } - #define PTK_LIST_FREE(list) \ free(list.data) diff --git a/src/ptk_vk/init.c b/src/ptk_vk/init.c index b645d9e..4ab8996 100644 --- a/src/ptk_vk/init.c +++ b/src/ptk_vk/init.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -18,7 +19,7 @@ PTK_OPTION_DEFINE(uint32_t); PTK_LIST_DEFINE(VkSurfaceFormatKHR); PTK_LIST_DEFINE(VkPresentModeKHR); PTK_LIST_DEFINE(VkFramebuffer); -PTK_LIST_DEFINE(VkVertexInputAttributeDescription); +PTK_ARRAY_DEFINE(VkVertexInputAttributeDescription); PTK_LIST_DEFINE(VkExtensionProperties); PTK_LIST_DEFINE(VkQueueFamilyProperties); PTK_OPTION_DEFINE(VkShaderModule); @@ -85,7 +86,7 @@ static const VkVertexInputBindingDescription m_vertex_binding_description = { .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, }; -PTK_LIST(VkVertexInputAttributeDescription) m_vertex_attribute_descriptions = PTK_LIST_STATIC_INIT(VkVertexInputAttributeDescription, { +PTK_ARRAY(VkVertexInputAttributeDescription) m_vertex_attribute_descriptions = PTK_ARRAY_NEW(VkVertexInputAttributeDescription, { (VkVertexInputAttributeDescription){ .location = 0, .binding = 0,