add enumerated versions of each macro and consts

This commit is contained in:
jacekpoz 2024-09-04 20:39:09 +02:00
parent ed9c34e243
commit 3b73c51cb9
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 28 additions and 22 deletions

View file

@ -43,18 +43,24 @@ bool _remove_at_PtkList(void *data, uint32_t *size, size_t index, size_t element
.allocated = _size,\
}
#define PTK_LIST_FOR_EACH(T, list, elem_name, ...) \
for (size_t _i = 0; _i < list.size; ++_i) {\
T elem_name = list.data[_i];\
#define PTK_LIST_FOR_EACH_E(T, list, index_name, elem_name, ...) \
for (size_t index_name = 0; index_name < list.size; ++index_name) {\
T elem_name = list.data[index_name];\
__VA_ARGS__\
}
#define PTK_LIST_FOR_EACH_P(T, list, elem_name, ...) \
for (size_t _i = 0; _i < list.size; ++_i) {\
T *elem_name = &list.data[_i];\
#define PTK_LIST_FOR_EACH_EP(T, list, index_name, elem_name, ...) \
for (size_t index_name = 0; index_name < list.size; ++index_name) {\
T *elem_name = &list.data[index_name];\
__VA_ARGS__\
}
#define PTK_LIST_FOR_EACH(T, list, elem_name, ...) \
PTK_LIST_FOR_EACH_E(T, list, _i, elem_name, __VA_ARGS__)
#define PTK_LIST_FOR_EACH_P(T, list, elem_name, ...) \
PTK_LIST_FOR_EACH_EP(T, list, _i, elem_name, __VA_ARGS__)
#define PTK_LIST_CLEAR(list) \
list.size = 0

View file

@ -152,7 +152,7 @@ inline bool ellipse_intersects(const PtkEllipse e, const PtkPos p) {
bool intersects(const PtkHandle component, const PtkPos point) {
switch (component->type) {
case PTK_COMPONENT_TYPE_BOX: {
PTK_LIST_FOR_EACH(PtkHandle, component->children, child, {
PTK_LIST_FOR_EACH(const PtkHandle, component->children, child, {
if (intersects(child, point)) {
return true;
}

View file

@ -159,7 +159,7 @@ bool check_validation_layers(const char * const *validation_layers, const uint32
bool layer_found = false;
PTK_LIST_FOR_EACH(VkLayerProperties, available_layers, layer_properties, {
PTK_LIST_FOR_EACH(const VkLayerProperties, available_layers, layer_properties, {
if (strcmp(layer_name, layer_properties.layerName) == 0) {
layer_found = true;
break;
@ -292,7 +292,7 @@ bool select_physical_dev(void) {
}
VkSurfaceFormatKHR select_swap_surface_format(const PTK_LIST(VkSurfaceFormatKHR) available_formats) {
PTK_LIST_FOR_EACH(VkSurfaceFormatKHR, available_formats, current_format, {
PTK_LIST_FOR_EACH(const VkSurfaceFormatKHR, available_formats, current_format, {
if (current_format.format == VK_FORMAT_B8G8R8A8_SRGB && current_format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
return current_format;
}
@ -302,7 +302,7 @@ VkSurfaceFormatKHR select_swap_surface_format(const PTK_LIST(VkSurfaceFormatKHR)
}
VkPresentModeKHR select_swap_present_mode(const PTK_LIST(VkPresentModeKHR) available_present_modes) {
PTK_LIST_FOR_EACH(VkPresentModeKHR, available_present_modes, current_present_mode, {
PTK_LIST_FOR_EACH(const VkPresentModeKHR, available_present_modes, current_present_mode, {
if (current_present_mode == VK_PRESENT_MODE_MAILBOX_KHR) {
return current_present_mode;
}
@ -386,7 +386,7 @@ bool are_extensions_supported(const VkPhysicalDevice dev) {
size_t supported_extensions = 0;
for (size_t i = 0; i < m_device_extension_count; ++i) {
PTK_LIST_FOR_EACH(VkExtensionProperties, available_extensions, current_extension, {
PTK_LIST_FOR_EACH(const VkExtensionProperties, available_extensions, current_extension, {
if (strcmp(m_device_extensions[i], current_extension.extensionName) == 0) {
supported_extensions += 1;
break;
@ -407,15 +407,15 @@ bool is_device_suitable(const VkPhysicalDevice dev) {
m_queue_family_indices.graphics = PTK_OPTION_NONE(uint32_t);
m_queue_family_indices.present = PTK_OPTION_NONE(uint32_t);
PTK_LIST_FOR_EACH(VkQueueFamilyProperties, queue_families, queue_family, {
PTK_LIST_FOR_EACH_E(const VkQueueFamilyProperties, queue_families, i, queue_family, {
if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
m_queue_family_indices.graphics = PTK_OPTION_SOME(uint32_t, _i);
m_queue_family_indices.graphics = PTK_OPTION_SOME(uint32_t, i);
}
VkBool32 present_support = VK_FALSE;
vkGetPhysicalDeviceSurfaceSupportKHR(dev, _i, m_surface, &present_support);
vkGetPhysicalDeviceSurfaceSupportKHR(dev, i, m_surface, &present_support);
if (present_support) {
m_queue_family_indices.present = PTK_OPTION_SOME(uint32_t, _i);
m_queue_family_indices.present = PTK_OPTION_SOME(uint32_t, i);
}
})
@ -564,7 +564,7 @@ bool create_swapchain(void) {
bool create_image_views(void) {
m_swapchain_image_views = PTK_LIST_NEW(VkImageView, m_swapchain_images.size);
PTK_LIST_FOR_EACH(VkImage, m_swapchain_images, swapchain_image, {
PTK_LIST_FOR_EACH_E(VkImage, m_swapchain_images, i, swapchain_image, {
VK_TRY(false,
vkCreateImageView(
g_dev,
@ -590,7 +590,7 @@ bool create_image_views(void) {
},
},
NULL,
&m_swapchain_image_views.data[_i]
&m_swapchain_image_views.data[i]
)
);
m_swapchain_image_views.size += 1;
@ -947,7 +947,7 @@ bool create_graphics_pipeline(void) {
bool create_framebuffers(void) {
m_swapchain_framebuffers = PTK_LIST_NEW(VkFramebuffer, m_swapchain_image_views.size);
PTK_LIST_FOR_EACH(VkImageView, m_swapchain_image_views, swapchain_image_view, {
PTK_LIST_FOR_EACH_E(VkImageView, m_swapchain_image_views, i, swapchain_image_view, {
VK_TRY(false,
vkCreateFramebuffer(
g_dev,
@ -957,13 +957,13 @@ bool create_framebuffers(void) {
.flags = 0,
.renderPass = m_render_pass,
.attachmentCount = 1,
.pAttachments = &(VkImageView){swapchain_image_view},
.pAttachments = &swapchain_image_view,
.width = m_swapchain_extent.width,
.height = m_swapchain_extent.height,
.layers = 1,
},
NULL,
&m_swapchain_framebuffers.data[_i]
&m_swapchain_framebuffers.data[i]
)
);
m_swapchain_framebuffers.size += 1;
@ -1113,8 +1113,8 @@ bool copy_buffer(const VkBuffer src, const VkBuffer dst, const VkDeviceSize size
bool vk_transfer_vertex_data(void) {
PTK_DEBUG("vertices updated!");
PTK_LIST_FOR_EACH(Vertex, g_vertices, current, {
PTK_DEBUG("v[%d]:", _i);
PTK_LIST_FOR_EACH_E(const Vertex, g_vertices, i, current, {
PTK_DEBUG("v[%d]:", i);
PTK_DEBUG(" pos: (%f, %f)", current.pos.x, current.pos.y);
PTK_DEBUG(" color: (%f, %f, %f)", current.color.r, current.color.g, current.color.b);
})