diff --git a/src/l1/codegen/codegen.c b/src/l1/codegen/codegen.c index ba26063..63e5927 100644 --- a/src/l1/codegen/codegen.c +++ b/src/l1/codegen/codegen.c @@ -36,6 +36,7 @@ int main() { .vec = true, .vec_extended = true, .span = true, .collab_vec_span = true, .vec_equal = true, })); } + VecU8_append_vec(&head, generate_VecT_new_of_size_method(cstr("VecU8"))); finish_header(head, "l1/VecAndSpan_Vec_int_primitives.h"); } { diff --git a/src/l1/codegen/util_template_inst.h b/src/l1/codegen/util_template_inst.h index d52a0a1..37e0e79 100644 --- a/src/l1/codegen/util_template_inst.h +++ b/src/l1/codegen/util_template_inst.h @@ -487,7 +487,7 @@ void generate_eve_header(SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, util_templates VecU8_append_vec(&text, generate_util_templates_instantiation(T, op)); VecU8 filename = VecU8_fmt("%s/eve/%s/""%s%s%s%s%s""%s%s.h", layer, bonus_ns, cstr(op.vec ? "Vec" : ""), cstr(op.vec && op.span ? "And" : ""), cstr(op.span ? "Span" : ""), - cstr(op.span && op.option ? "And" : ""), cstr(op.option ? "Option" : ""), + cstr((op.span && op.option) || (op.vec && !op.span && op.option) ? "And" : ""), cstr(op.option ? "Option" : ""), cstr((int)op.vec + (int)op.span + (int)op.option > 1 ? "_" : ""), T); VecU8_append(&filename, 0); write_whole_file_or_abort((const char*)filename.buf, VecU8_to_span(&text)); diff --git a/src/l2/codegen/codegen.c b/src/l2/codegen/codegen.c index 209fb50..e763b63 100644 --- a/src/l2/codegen/codegen.c +++ b/src/l2/codegen/codegen.c @@ -17,6 +17,29 @@ void eve_of_l2() { generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("ShinyMeshInstance"), true, false); generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("Pipeline0Spotlight"), true, false); generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("Pipeline0PointLight"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("Wimbzle"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("Nibzle"), true, false); + /* Needed in graphics_geom.h */ + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("MarieTriangle"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("MarieTriangleAttr"), true, false); + /* Needed in r0_scene.h */ + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("ModelOnScene"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("UsedModelOnScene"), true, false); + /* Needed in r0.c */ + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("CSTR"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("MargaretChosenQueueFamilies"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("VkQueueFamilyProperties"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("VkExtensionProperties"), true, false); + generate_eve_header(cstr("l2"), cstr(""), cstr("VkSurfaceFormatKHR"), + (util_templates_instantiation_options){ .t_primitive = true, .vec = true, .option = true }); + generate_eve_header(cstr("l2"), cstr(""), cstr("VkPresentModeKHR"), + (util_templates_instantiation_options){ .t_primitive = true, .vec = true, .option = true }); + generate_eve_header(cstr("l2"), cstr(""), cstr("VkFormat"), + (util_templates_instantiation_options){ .t_primitive = true, .span = true, .option = true }); + generate_eve_header(cstr("l2"), cstr(""), cstr("MargaretScoredPhysicalDevice"), + (util_templates_instantiation_options){ .t_primitive = true, .vec = true, .span = true, + .mut_span = true, .collab_vec_span = true, .span_sort = true}); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr(""), cstr("VkPhysicalDevice"), true, false); } void generate_Vec_cvec_header() { @@ -34,7 +57,7 @@ void generate_Vec_cvec_header() { } void generate_Vec_vec_header() { - VecU8 res = begin_header(cstr("PROTOTYPE1_GEN_L2_VECANDSPAN_GEOM_CVEC_H")); + VecU8 res = begin_header(cstr("PROTOTYPE1_GEN_L2_VECANDSPAN_GEOM_VEC_H")); VecU8_append_span(&res, cstr("#include \"geom.h\"\n")); VecU8_append_span(&res, cstr("#include \"../../src/l1/core/util.h\"\n\n")); SpanU8 T[] = {cstr("vec2"), cstr("vec3"), cstr("vec4")}; diff --git a/src/l2/margaret/margaret.h b/src/l2/margaret/margaret.h index 61cc561..301ddbd 100644 --- a/src/l2/margaret/margaret.h +++ b/src/l2/margaret/margaret.h @@ -1,18 +1,15 @@ #ifndef PROTOTYPE1_SRC_L2_MARGARET_MARGARET_H #define PROTOTYPE1_SRC_L2_MARGARET_MARGARET_H -#include "../../l1/core/util.h" -#include "../../l1/core/Option_int_primitives.h" -#include "../../l1/core/VecSpan_Vec_int_primitives.h" +#include "../../../gen/l1/Option_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_Vec_int_primitives.h" +// todo: rewrite this crap to wayland (fom now on wayland is my best friend in all situations) #include #include #include #include #include "../core/stringop.h" -// #include #include -// #include -#include #include "../../l1/system/fileio.h" typedef struct timespec margaret_ns_time; @@ -30,32 +27,29 @@ int64_t margaret_ns_time_ns_diff(margaret_ns_time from, margaret_ns_time to) { } float margaret_ns_time_sec_diff(margaret_ns_time from, margaret_ns_time to) { - return (float)margaret_ns_time_ns_diff(from, to) / 1e9; + return (float)margaret_ns_time_ns_diff(from, to) / 1e9f; } float margaret_clock_monotonic_raw_diff(margaret_ns_time start) { - return (float)margaret_ns_time_ns_diff(start, margaret_clock_gettime_monotonic_raw()) / 1e9; + return (float)margaret_ns_time_ns_diff(start, margaret_clock_gettime_monotonic_raw()) / 1e9f; } - +// todo: rewrite margaret to use libwayland-client, and get rid of this fucking crap typedef XEvent Xlib_Event; -void Xlib_Event_drop(){} -Xlib_Event Xlib_Event_clone(Xlib_Event* a) {return *a; } - -VecT_trivmove_struct_Definition(Xlib_Event) -VecT_trivmove_method_Definition(Xlib_Event) -VecT_primitive_zeroinit_method_Definition(Xlib_Event) +#include "../../../gen/l2/eve/VecXlib_Event.h" +// todo: AAAAAAAAAAAAA I HATE XLIB SO FUCKINGG MNJUHC AAAASAAAAA AAAAAAA typedef Display Xlib_Display; typedef Window Xlib_Window; typedef Atom Xlib_Atom; -VecXlib_Event margaret_read_x_events(Xlib_Display* dpy) { +// todo: AAAAAAAAAAAAAAAA AAASASDASDASDASDAGAHGFKJG AAAAAAAAAAA FUCK XLIB FUCK XORG FUCK THIS SHIT +NODISCARD VecXlib_Event margaret_read_x_events(Xlib_Display* dpy) { int evh = XEventsQueued(dpy, QueuedAfterReading); VecXlib_Event result = VecXlib_Event_new_zeroinit(evh); for (int i = 0; i < evh; i++) { - XNextEvent(dpy, VecXlib_Event_at(&result, i)); + XNextEvent(dpy, VecXlib_Event_mat(&result, i)); } return result; } @@ -147,15 +141,10 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL margaret_static_debug_callback( fprintf(stderr, "Vk Validation layer: %s\n", pCallbackData->pMessage); return VK_FALSE; } -` + typedef const char* CSTR; -#define CSTR_drop(x) {} -#define CSTR_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(CSTR) -VecT_trivmove_method_Definition(CSTR) -VecT_primitive_zeroinit_method_Definition(CSTR) +#include "../../../gen/l2/eve/VecCSTR.h" typedef struct { VkInstance instance; @@ -240,12 +229,8 @@ typedef struct { U32 for_presentation; } MargaretChosenQueueFamilies; -#define VkQueueFamilyProperties_drop(x) {} -#define VkQueueFamilyProperties_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(VkQueueFamilyProperties) -VecT_trivmove_method_Definition(VkQueueFamilyProperties) -VecT_primitive_zeroinit_method_Definition(VkQueueFamilyProperties) +#include "../../../gen/l2/eve/VecMargaretChosenQueueFamilies.h" +#include "../../../gen/l2/eve/VecVkQueueFamilyProperties.h" /* MargaretChosenQueueFamilies or a static string, describing which part could not be found * (may replace with VecU8 later) */ @@ -253,11 +238,11 @@ typedef struct { Result_variant variant; union { MargaretChosenQueueFamilies ok; - ConstSpanU8 err; + SpanU8 err; }; -} ResultMargaretChosenQueueFamiliesOrConstSpanU8; +} ResultMargaretChosenQueueFamiliesOrSpanU8; -ResultMargaretChosenQueueFamiliesOrConstSpanU8 margaret_choose_good_queue_families(VkPhysicalDevice dev, VkSurfaceKHR surface) { +ResultMargaretChosenQueueFamiliesOrSpanU8 margaret_choose_good_queue_families(VkPhysicalDevice dev, VkSurfaceKHR surface) { uint32_t queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(dev, &queue_family_count, NULL); VecVkQueueFamilyProperties queue_families = VecVkQueueFamilyProperties_new_zeroinit(queue_family_count); @@ -267,7 +252,7 @@ ResultMargaretChosenQueueFamiliesOrConstSpanU8 margaret_choose_good_queue_famili OptionU32 index_for_presentation = None_U32(); for (uint32_t i = 0; i < queue_family_count; i++) { - const VkQueueFamilyProperties* props = VecVkQueueFamilyProperties_cat(&queue_families, i); + const VkQueueFamilyProperties* props = VecVkQueueFamilyProperties_at(&queue_families, i); if (props->queueFlags & VK_QUEUE_GRAPHICS_BIT && props->queueCount >= 1) { index_for_graphics = Some_U32(i); } @@ -279,22 +264,16 @@ ResultMargaretChosenQueueFamiliesOrConstSpanU8 margaret_choose_good_queue_famili } VecVkQueueFamilyProperties_drop(queue_families); // todo: method _is_none will soon be gone - if (OptionU32_is_none(&index_for_graphics)) - return (ResultMargaretChosenQueueFamiliesOrConstSpanU8){ .variant = Result_Err, .err = cstr("No graphics queue family") }; - if (OptionU32_is_none(&index_for_presentation)) - return (ResultMargaretChosenQueueFamiliesOrConstSpanU8){ .variant = Result_Err, .err = cstr("No presentation queue family") }; - return (ResultMargaretChosenQueueFamiliesOrConstSpanU8){ .variant = Result_Ok, .ok = (MargaretChosenQueueFamilies){ + if (index_for_graphics.variant == Option_None) + return (ResultMargaretChosenQueueFamiliesOrSpanU8){ .variant = Result_Err, .err = cstr("No graphics queue family") }; + if (index_for_presentation.variant == Option_None) + return (ResultMargaretChosenQueueFamiliesOrSpanU8){ .variant = Result_Err, .err = cstr("No presentation queue family") }; + return (ResultMargaretChosenQueueFamiliesOrSpanU8){ .variant = Result_Ok, .ok = (MargaretChosenQueueFamilies){ .for_graphics = index_for_graphics.some, .for_presentation = index_for_presentation.some } }; } -#define VkExtensionProperties_drop(x) {} -#define VkExtensionProperties_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(VkExtensionProperties) -VecT_trivmove_method_Definition(VkExtensionProperties) -VecT_primitive_zeroinit_method_Definition(VkExtensionProperties) - +#include "../../../gen/l2/eve/VecVkExtensionProperties.h" // These are not the same as instance extensions VecVecU8 margaret_get_extensions_of_physical_device(VkPhysicalDevice physical_device) { @@ -306,10 +285,9 @@ VecVecU8 margaret_get_extensions_of_physical_device(VkPhysicalDevice physical_de abortf("vkEnumerateDeviceExtensionProperties"); VecVecU8 res = VecVecU8_new_of_size(extensions_count); for (size_t i = 0; i < extensions_count; i++) { - // todo: swap with empty // Previous value here was default (_new). It can be safely discarded // ->extensionName is some null-terminated string, we need to acquire a copy - *VecVecU8_at(&res, i) = vcstr(VecVkExtensionProperties_cat(&extensions, i)->extensionName); + *VecVecU8_mat(&res, i) = vcstr(VecVkExtensionProperties_at(&extensions, i)->extensionName); } VecVkExtensionProperties_drop(extensions); return res; @@ -361,11 +339,8 @@ VkDevice margaret_create_logical_device(VkPhysicalDevice physical_device, Margar return device; } -OptionT_struct_Definition(VkSurfaceFormatKHR) -OptionT_method_Definition(VkSurfaceFormatKHR) - -OptionT_struct_Definition(VkPresentModeKHR) -OptionT_method_Definition(VkPresentModeKHR) +#include "../../../gen/l2/eve/VecAndOption_VkSurfaceFormatKHR.h" +#include "../../../gen/l2/eve/VecAndOption_VkPresentModeKHR.h" /* These variables are in some way enforced by VkSurfaceCapabilitiesKHR (but not completely determined) */ typedef struct { @@ -376,23 +351,9 @@ typedef struct { VkSurfaceTransformFlagBitsKHR surface_pre_transform; } MargaretChosenSwapchainDetails; -#define VkSurfaceFormatKHR_drop(x) {} -#define VkSurfaceFormatKHR_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(VkSurfaceFormatKHR) -VecT_trivmove_method_Definition(VkSurfaceFormatKHR) -VecT_primitive_zeroinit_method_Definition(VkSurfaceFormatKHR) - -#define VkPresentModeKHR_drop(x) {} -#define VkPresentModeKHR_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(VkPresentModeKHR) -VecT_trivmove_method_Definition(VkPresentModeKHR) -VecT_primitive_zeroinit_method_Definition(VkPresentModeKHR) - OptionVkSurfaceFormatKHR margaret_choose_surface_format(const VecVkSurfaceFormatKHR* surface_formats) { for (size_t i = 0; i < surface_formats->len; i++) { - VkSurfaceFormatKHR f = *VecVkSurfaceFormatKHR_cat(surface_formats, i); + VkSurfaceFormatKHR f = *VecVkSurfaceFormatKHR_at(surface_formats, i); if ((f.format == VK_FORMAT_R8G8B8A8_SRGB || f.format == VK_FORMAT_B8G8R8A8_SRGB) && f.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR ) { @@ -405,7 +366,7 @@ OptionVkSurfaceFormatKHR margaret_choose_surface_format(const VecVkSurfaceFormat OptionVkPresentModeKHR margaret_choose_presentation_mode(const VecVkPresentModeKHR* pres_modes) { OptionVkPresentModeKHR res = None_VkPresentModeKHR(); for (size_t i = 0; i < pres_modes->len; i++) { - VkPresentModeKHR mode = *VecVkPresentModeKHR_cat(pres_modes, i); + VkPresentModeKHR mode = *VecVkPresentModeKHR_at(pres_modes, i); if (mode == VK_PRESENT_MODE_MAILBOX_KHR) return Some_VkPresentModeKHR(VK_PRESENT_MODE_MAILBOX_KHR); else if (mode == VK_PRESENT_MODE_FIFO_KHR) @@ -431,12 +392,12 @@ typedef struct { Result_variant variant; union { MargaretChosenSwapchainDetails ok; - ConstSpanU8 err; + SpanU8 err; }; -} ResultMargaretChosenSwapchainDetailsOrConstSpanU8; +} ResultMargaretChosenSwapchainDetailsOrSpanU8; // Both queries swapchain support details and selects needed formats and presentation modes -ResultMargaretChosenSwapchainDetailsOrConstSpanU8 margaret_choose_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface) { +ResultMargaretChosenSwapchainDetailsOrSpanU8 margaret_choose_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface) { /* 1. Getting surface capabilities + formats + presentation modes */ VkSurfaceCapabilitiesKHR surface_capabilities; if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surface_capabilities) != VK_SUCCESS) @@ -458,12 +419,12 @@ ResultMargaretChosenSwapchainDetailsOrConstSpanU8 margaret_choose_swapchain_deta /* 2. Choosing surface format and presentation mode */ OptionVkSurfaceFormatKHR chosen_surface_format = margaret_choose_surface_format(&surface_formats); - if (OptionVkSurfaceFormatKHR_is_none(&chosen_surface_format)) - return (ResultMargaretChosenSwapchainDetailsOrConstSpanU8){ .variant = Result_Err, + if (chosen_surface_format.variant == Option_None) + return (ResultMargaretChosenSwapchainDetailsOrSpanU8){ .variant = Result_Err, .err = cstr("No suitable surface format") }; OptionVkPresentModeKHR chosen_present_mode = margaret_choose_presentation_mode(&pres_modes); - if (OptionVkPresentModeKHR_is_none(&chosen_present_mode)) - return (ResultMargaretChosenSwapchainDetailsOrConstSpanU8){ .variant = Result_Err, + if (chosen_present_mode.variant == Option_None) + return (ResultMargaretChosenSwapchainDetailsOrSpanU8){ .variant = Result_Err, .err = cstr("No suitable swapchain presentation mode") }; VkExtent2D image_extent = margaret_choose_image_extent(&surface_capabilities); @@ -472,7 +433,7 @@ ResultMargaretChosenSwapchainDetailsOrConstSpanU8 margaret_choose_swapchain_deta VecVkSurfaceFormatKHR_drop(surface_formats); VecVkPresentModeKHR_drop(pres_modes); - return (ResultMargaretChosenSwapchainDetailsOrConstSpanU8){ .variant = Result_Ok,\ + return (ResultMargaretChosenSwapchainDetailsOrSpanU8){ .variant = Result_Ok,\ .ok = (MargaretChosenSwapchainDetails){ .surface_format = chosen_surface_format.some, .presentation_mode = chosen_present_mode.some, .image_extent = image_extent, .image_count = image_count, @@ -481,17 +442,13 @@ ResultMargaretChosenSwapchainDetailsOrConstSpanU8 margaret_choose_swapchain_deta }; } -SpanT_struct_Definition(VkFormat) -SpanT_method_Definition(VkFormat) - -OptionT_struct_Definition(VkFormat) -OptionT_method_Definition(VkFormat) +#include "../../../gen/l2/eve/SpanAndOption_VkFormat.h" OptionVkFormat margaret_find_supported_format_for_linear_tiling( - VkPhysicalDevice physical_device, ConstSpanVkFormat candidates, VkFormatFeatureFlags required_features + VkPhysicalDevice physical_device, SpanVkFormat candidates, VkFormatFeatureFlags required_features ) { for (size_t i = 0; i < candidates.len; i++) { - VkFormat format = *ConstSpanVkFormat_at(candidates, i); + VkFormat format = *SpanVkFormat_at(candidates, i); VkFormatProperties properties; vkGetPhysicalDeviceFormatProperties(physical_device, format, &properties); if ((properties.linearTilingFeatures & required_features) == required_features) @@ -501,10 +458,10 @@ OptionVkFormat margaret_find_supported_format_for_linear_tiling( } OptionVkFormat margaret_find_supported_format_for_optimal_tiling( - VkPhysicalDevice physical_device, ConstSpanVkFormat candidates, VkFormatFeatureFlags required_features + VkPhysicalDevice physical_device, SpanVkFormat candidates, VkFormatFeatureFlags required_features ) { for (size_t i = 0; i < candidates.len; i++) { - VkFormat format = *ConstSpanVkFormat_at(candidates, i); + VkFormat format = *SpanVkFormat_at(candidates, i); VkFormatProperties properties; vkGetPhysicalDeviceFormatProperties(physical_device, format, &properties); if ((properties.optimalTilingFeatures & required_features) == required_features) @@ -516,7 +473,7 @@ OptionVkFormat margaret_find_supported_format_for_optimal_tiling( OptionVkFormat margaret_find_supported_zbuffer_format(VkPhysicalDevice physical_device) { VkFormat candidates[3] = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT }; return margaret_find_supported_format_for_optimal_tiling(physical_device, - (ConstSpanVkFormat){.data = candidates, .len = ARRAY_SIZE(candidates)}, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); + (SpanVkFormat){.data = candidates, .len = ARRAY_SIZE(candidates)}, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); } OptionVkFormat margaret_find_supported_hdr_buffer_format(VkPhysicalDevice physical_device) { @@ -524,7 +481,7 @@ OptionVkFormat margaret_find_supported_hdr_buffer_format(VkPhysicalDevice physic VkFormat candidates[] = { /*VK_FORMAT_R16G16B16_SFLOAT, VK_FORMAT_R32G32B32_SFLOAT,*/ VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT }; return margaret_find_supported_format_for_optimal_tiling(physical_device, - (ConstSpanVkFormat){.data = candidates, .len = ARRAY_SIZE(candidates)}, + (SpanVkFormat){.data = candidates, .len = ARRAY_SIZE(candidates)}, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT ); } @@ -538,15 +495,15 @@ typedef struct { VkPhysicalDevice physical_device; S64 score; // static string - ConstSpanU8 disqualification_reason; + SpanU8 disqualification_reason; } MargaretScoredPhysicalDevice; MargaretScoredPhysicalDevice margaret_score_physical_device( - VkPhysicalDevice dev, VkSurfaceKHR surface, VecU8 favourite_word, VecU8 forbidden_word + VkPhysicalDevice dev, VkSurfaceKHR surface, SpanU8 favourite_word, SpanU8 forbidden_word ) { VkPhysicalDeviceProperties properties; vkGetPhysicalDeviceProperties(dev, &properties); - if (string_contains_string_ignorecase(vcstr(properties.deviceName), forbidden_word)) + if (string_contains_string_ignorecase(SpanU8_from_cstr(properties.deviceName), forbidden_word)) return (MargaretScoredPhysicalDevice){ dev, -1, cstr("Bugged gpu") }; VkPhysicalDeviceSynchronization2Features synchronization2_features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES, @@ -560,7 +517,7 @@ MargaretScoredPhysicalDevice margaret_score_physical_device( // , properties.deviceName, properties.limits.maxBoundDescriptorSets, properties.limits.maxPerStageDescriptorUniformBuffers); S64 score = 0; - if (string_contains_string_ignorecase(vcstr(properties.deviceName), favourite_word)) + if (string_contains_string_ignorecase(SpanU8_from_cstr(properties.deviceName), favourite_word)) score += 100000; if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) score += 1000; @@ -572,19 +529,19 @@ MargaretScoredPhysicalDevice margaret_score_physical_device( return (MargaretScoredPhysicalDevice){dev, -1, cstr("No synchronization2")}; if (features2.features.samplerAnisotropy) score += 2; - ResultMargaretChosenQueueFamiliesOrConstSpanU8 queue_families = margaret_choose_good_queue_families(dev, surface); + ResultMargaretChosenQueueFamiliesOrSpanU8 queue_families = margaret_choose_good_queue_families(dev, surface); if (queue_families.variant == Result_Err) return (MargaretScoredPhysicalDevice){dev, -1, queue_families.err}; // Checking device specific extensions (VK_KHR_swapchain required to check swap_chain support details VecVecU8 dev_extensions = margaret_get_extensions_of_physical_device(dev); - ConstSpanU8 required_dev_extensions[] = {cstr("VK_KHR_swapchain"), cstr("VK_KHR_synchronization2")}; + SpanU8 required_dev_extensions[] = {cstr("VK_KHR_swapchain"), cstr("VK_KHR_synchronization2")}; for (size_t ei = 0; ei < ARRAY_SIZE(required_dev_extensions); ei++) { - if (!string_in_string_vec(required_dev_extensions[ei], &dev_extensions)) + if (!is_string_in_string_vec(required_dev_extensions[ei], &dev_extensions)) return (MargaretScoredPhysicalDevice){dev, -1, cstr("Missing some device extensions")}; } VecVecU8_drop(dev_extensions); // Extension VK_KHR_swapchain is present, now we can call query_swap_chain_support - ResultMargaretChosenSwapchainDetailsOrConstSpanU8 swapchain_details = margaret_choose_swapchain_details(dev, surface); + ResultMargaretChosenSwapchainDetailsOrSpanU8 swapchain_details = margaret_choose_swapchain_details(dev, surface); if (swapchain_details.variant == Result_Err) { return (MargaretScoredPhysicalDevice){dev, -1, cstr("Physical device lacks nice swapchain support")}; } @@ -596,28 +553,17 @@ MargaretScoredPhysicalDevice margaret_score_physical_device( return (MargaretScoredPhysicalDevice){dev, -1, cstr("R8G8B8A8_UNORM format can't be used for optimal tiling of textures")}; if (!margaret_is_format_supported_for_textures(dev, VK_FORMAT_R16G16B16A16_SFLOAT)) return (MargaretScoredPhysicalDevice){dev, -1, cstr("VK_FORMAT_R16G16B16A16_SFLOAT format can't be used for optimal tiling of textures")}; - return (MargaretScoredPhysicalDevice){dev, score, ""}; + return (MargaretScoredPhysicalDevice){dev, score, cstr("")}; } -#define MargaretScoredPhysicalDevice_drop(x) {} -#define MargaretScoredPhysicalDevice_clone(vp) (*(vp)) -#define MargaretScoredPhysicalDevice_equal_MargaretScoredPhysicalDevice(a, b) ((a) == (b)) #define MargaretScoredPhysicalDevice_less_MargaretScoredPhysicalDevice(cap, cbp) ((cap)->score < (cbp)->score) -SpanT_VecT_trivmove_COMPLETE_Definition(MargaretScoredPhysicalDevice) -VecT_primitive_zeroinit_method_Definition(MargaretScoredPhysicalDevice) -SpanT_comparable_method_Definition(MargaretScoredPhysicalDevice) - -#define VkPhysicalDevice_drop(x) {} -#define VkPhysicalDevice_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(VkPhysicalDevice) -VecT_trivmove_method_Definition(VkPhysicalDevice) -VecT_primitive_zeroinit_method_Definition(VkPhysicalDevice) +#include "../../../gen/l2/eve/VecAndSpan_MargaretScoredPhysicalDevice.h" +#include "../../../gen/l2/eve/VecVkPhysicalDevice.h" VecMargaretScoredPhysicalDevice margaret_get_physical_devices_scored( VkInstance instance, VkSurfaceKHR surface, - ConstSpanU8 favourite_word, ConstSpanU8 forbidden_word + SpanU8 favourite_word, SpanU8 forbidden_word ) { uint32_t physical_device_count = 0; if (vkEnumeratePhysicalDevices(instance, &physical_device_count, NULL) != VK_SUCCESS) @@ -627,8 +573,9 @@ VecMargaretScoredPhysicalDevice margaret_get_physical_devices_scored( abortf("vkEnumeratePhysicalDevices"); VecMargaretScoredPhysicalDevice scored_devices = VecMargaretScoredPhysicalDevice_new_zeroinit(physical_device_count); for (uint32_t i = 0; i < physical_device_count; i++) { + // todo: 17th. CONTINUE FROM HERE *VecMargaretScoredPhysicalDevice_at(&scored_devices, i) = margaret_score_physical_device( - *VecVkPhysicalDevice_cat(&physical_devices, i), surface, + *VecVkPhysicalDevice_at(&physical_devices, i), surface, VecU8_from_span(favourite_word), VecU8_from_span(forbidden_word) ); } @@ -638,25 +585,25 @@ VecMargaretScoredPhysicalDevice margaret_get_physical_devices_scored( VkPhysicalDevice margaret_select_one_physical_device( VkInstance instance, VkSurfaceKHR surface, - ConstSpanU8 favourite_word, ConstSpanU8 forbidden_word + SpanU8 favourite_word, SpanU8 forbidden_word ) { VecMargaretScoredPhysicalDevice scored_devices = margaret_get_physical_devices_scored(instance, surface, favourite_word, forbidden_word); printf("Physical devices (with scores):\n"); for (size_t i = 0; i < scored_devices.len; i++) { - const MargaretScoredPhysicalDevice* dev = VecMargaretScoredPhysicalDevice_cat(&scored_devices, i); + const MargaretScoredPhysicalDevice* dev = VecMargaretScoredPhysicalDevice_at(&scored_devices, i); VkPhysicalDeviceProperties dev_props; vkGetPhysicalDeviceProperties(dev->physical_device, &dev_props); if (dev->score >= 0) { printf("%s: %ld\n", dev_props.deviceName, dev->score); } else { printf("%s: DISQUALIFIED: ", dev_props.deviceName); - ConstSpanU8_print(dev->disqualification_reason); + SpanU8_print(dev->disqualification_reason); putchar('\n'); } } if (scored_devices.len == 0) abortf("No vulkan devices"); - const MargaretScoredPhysicalDevice* best_dev = VecMargaretScoredPhysicalDevice_cat(&scored_devices, scored_devices.len - 1); + const MargaretScoredPhysicalDevice* best_dev = VecMargaretScoredPhysicalDevice_at(&scored_devices, scored_devices.len - 1); if (best_dev->score < 0) abortf("No suitable vulkan devices"); return best_dev->physical_device; @@ -739,7 +686,7 @@ VecVkImageView margaret_create_swapchain_image_views( for (uint32_t i = 0; i < swapchain_image_count; i++) { VkImageViewCreateInfo imageview_crinfo = { .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, - .image = *VecVkImage_cat(&swapchain_images, i), + .image = *VecVkImage_at(&swapchain_images, i), .viewType = VK_IMAGE_VIEW_TYPE_2D, .format = image_format, .components.r = VK_COMPONENT_SWIZZLE_IDENTITY, @@ -764,7 +711,7 @@ VecVkFramebuffer margaret_create_swapchain_framebuffers( ) { VecVkFramebuffer swapchain_framebuffers = VecVkFramebuffer_new_zeroinit(swapchain_image_views->len); for (uint32_t i = 0; i < swapchain_image_views->len; i++) { - VkImageView attachments[1] = {*VecVkImageView_cat(swapchain_image_views, i)}; + VkImageView attachments[1] = {*VecVkImageView_at(swapchain_image_views, i)}; VkFramebufferCreateInfo framebuffer_crinfo = { .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .renderPass = render_pass, @@ -833,10 +780,10 @@ MargaretSwapchainBundle MargaretSwapchainBundle_new( VkSwapchainKHR MargaretSwapchainBundle_pop_swapchain_drop_rest(VkDevice device, MargaretSwapchainBundle swfb) { for (size_t i = 0; i < swfb.framebuffers.len; i++) { - vkDestroyFramebuffer(device, *VecVkFramebuffer_cat(&swfb.framebuffers, i), NULL); + vkDestroyFramebuffer(device, *VecVkFramebuffer_at(&swfb.framebuffers, i), NULL); } for (size_t i = 0; i < swfb.image_views.len; i++) { - vkDestroyImageView(device, *VecVkImageView_cat(&swfb.image_views, i), NULL); + vkDestroyImageView(device, *VecVkImageView_at(&swfb.image_views, i), NULL); } vkDestroyFence(device, swfb.in_flight_fence, NULL); vkDestroySemaphore(device, swfb.render_finished_semaphore, NULL); diff --git a/src/l2/marie/geom_alg_utils.h b/src/l2/marie/geom_alg_utils.h index f3e1540..4b9ed5c 100644 --- a/src/l2/marie/geom_alg_utils.h +++ b/src/l2/marie/geom_alg_utils.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../../../gen/l2/geom.h" #include "../../l1/core/util.h" @@ -53,12 +54,7 @@ typedef struct { vec2 v2; } MarieTriangle; -#define MarieTriangle_drop(x) {} -#define MarieTriangle_clone(xp) (*(xp)) - -VecT_trivmove_struct_Definition(MarieTriangle) -VecT_trivmove_method_Definition(MarieTriangle) -VecT_primitive_zeroinit_method_Definition(MarieTriangle) +#include "../../../gen/l2/eve/VecMarieTriangle.h" typedef struct { MariePlaneVertAttr v0; @@ -66,12 +62,7 @@ typedef struct { MariePlaneVertAttr v2; } MarieTriangleAttr; -#define MarieTriangleAttr_drop(x) {} -#define MarieTriangleAttr_clone(xp) (*(xp)) - -VecT_trivmove_struct_Definition(MarieTriangleAttr) -VecT_trivmove_method_Definition(MarieTriangleAttr) -VecT_primitive_zeroinit_method_Definition(MarieTriangleAttr) +#include "../../../gen/l2/eve/VecMarieTriangleAttr.h" vec2 marie_intersect_lines(vec2 A1, vec2 B1, vec2 A2, vec2 B2) { vec2 alpha = vec2_minus_vec2(B1, A1); diff --git a/src/l2/marie/rasterization.h b/src/l2/marie/rasterization.h index 39b2789..047bc8d 100644 --- a/src/l2/marie/rasterization.h +++ b/src/l2/marie/rasterization.h @@ -3,7 +3,6 @@ #include "../../../gen/l2/geom.h" #include "../../../gen/l2/pixel_masses.h" -#include "math.h" #include "geom_alg_utils.h" typedef struct { @@ -21,7 +20,7 @@ typedef struct { /* f(y) = (y + 0.5 - a.y) / (b.y - a.y) * (b.x - a.x) + a.x - 0.5 */ MarieLinearFun marie_gen_scanline_borderline(vec2 a, vec2 b) { return (MarieLinearFun){.c1 = (b.x - a.x) / (b.y - a.y), - .c0 = (0.5 - a.y) * (b.x - a.x) / (b.y - a.y) + a.x - 0.5 }; + .c0 = (0.5f - a.y) * (b.x - a.x) / (b.y - a.y) + a.x - 0.5f }; } /* Utility function, that is used by rasterization function. @@ -30,9 +29,9 @@ void marie_rasterize_line_in_triangle_with_attr_sorted( vec2 v0pos, vec2 v1pos, vec2 v2pos, S32 L, S32 R, MarieVertAttr P0, MarieVertAttr P1, MarieVertAttr P2, float S, S32 my, FnMarieRasterizerCallback cb ) { - float E01 = marie_surface(v0pos, v1pos, (vec2){L + 0.5, my + 0.5}); - float E12 = marie_surface(v1pos, v2pos, (vec2){L + 0.5, my + 0.5}); - float E20 = marie_surface(v2pos, v0pos, (vec2){L + 0.5, my + 0.5}); + float E01 = marie_surface(v0pos, v1pos, (vec2){(float)L + 0.5f, (float)my + 0.5f}); + float E12 = marie_surface(v1pos, v2pos, (vec2){(float)L + 0.5f, (float)my + 0.5f}); + float E20 = marie_surface(v2pos, v0pos, (vec2){(float)L + 0.5f, (float)my + 0.5f}); for (S32 x = L; x <= R; x++) { if (marie_same_dir3(E01, E12, E20, S)) { cb.fn(cb.guest, x, my, vec4_add_vec4(vec4_mul_scal(P0, E12), @@ -53,9 +52,9 @@ void marie_scan_rast_line_in_triangle_with_attr_sorted( for (S32 my = below + 1; my < above; my++) { S32 left = (S32)ceilf(left_border.c1 * (float)my + left_border.c0); S32 right = (S32)floorf(right_border.c1 * (float)my + right_border.c0); - MarieVertAttr Q0 = vec4_mul_scal(P0, marie_surface(v1pos, v2pos, (vec2){left + 0.5, (float)my + 0.5})); - MarieVertAttr Q1 = vec4_mul_scal(P1, marie_surface(v2pos, v0pos, (vec2){left + 0.5, (float)my + 0.5})); - MarieVertAttr Q2 = vec4_mul_scal(P2, marie_surface(v0pos, v1pos, (vec2){left + 0.5, (float)my + 0.5})); + MarieVertAttr Q0 = vec4_mul_scal(P0, marie_surface(v1pos, v2pos, (vec2){(float)left + 0.5f, (float)my + 0.5f})); + MarieVertAttr Q1 = vec4_mul_scal(P1, marie_surface(v2pos, v0pos, (vec2){(float)left + 0.5f, (float)my + 0.5f})); + MarieVertAttr Q2 = vec4_mul_scal(P2, marie_surface(v0pos, v1pos, (vec2){(float)left + 0.5f, (float)my + 0.5f})); MarieVertAttr dq0 = vec4_mul_scal(P0, v1pos.y - v2pos.y); MarieVertAttr dq1 = vec4_mul_scal(P1, v2pos.y - v0pos.y); MarieVertAttr dq2 = vec4_mul_scal(P2, v0pos.y - v1pos.y); @@ -72,12 +71,12 @@ void marie_rasterize_triangle_with_attr_sorted( MariePlaneVertAttr v0, MariePlaneVertAttr v1, MariePlaneVertAttr v2, FnMarieRasterizerCallback cb ) { float S = marie_surface(v0.pos, v1.pos, v2.pos); - S32 sx0 = (S32)roundf(v0.pos.x - 0.5); - S32 sy0 = (S32)roundf(v0.pos.y - 0.5); - S32 sx1 = (S32)roundf(v1.pos.x - 0.5); - S32 sy1 = (S32)roundf(v1.pos.y - 0.5); - S32 sx2 = (S32)roundf(v2.pos.x - 0.5); - S32 sy2 = (S32)roundf(v2.pos.y - 0.5); + S32 sx0 = (S32)roundf(v0.pos.x - 0.5f); + S32 sy0 = (S32)roundf(v0.pos.y - 0.5f); + S32 sx1 = (S32)roundf(v1.pos.x - 0.5f); + S32 sy1 = (S32)roundf(v1.pos.y - 0.5f); + S32 sx2 = (S32)roundf(v2.pos.x - 0.5f); + S32 sy2 = (S32)roundf(v2.pos.y - 0.5f); S32 L = MIN_S32(sx0, MIN_S32(sx1, sx2)); S32 R = MAX_S32(sx0, MAX_S32(sx1, sx2)); diff --git a/src/l2/marie/shape_geom.h b/src/l2/marie/shape_geom.h index 59516f1..ed64938 100644 --- a/src/l2/marie/shape_geom.h +++ b/src/l2/marie/shape_geom.h @@ -3,6 +3,7 @@ #include "../../../gen/l2/marie/clipping.h" + // // todo: move to autogenerated files (and autogenerate span and vector definitions) // SpanT_struct_Definition(vec2) // SpanT_method_Definition(vec2) diff --git a/src/l2/tests/r0/r0_assets.h b/src/l2/tests/r0/r0_assets.h index af54062..9a9230f 100644 --- a/src/l2/tests/r0/r0_assets.h +++ b/src/l2/tests/r0/r0_assets.h @@ -5,6 +5,7 @@ #include "../../../../gen/l1/VecAndSpan_int_primitives.h" #include "../../../l1/system/fileio.h" #include +#include "../../../../gen/l2/VecAndSpan_vec.h" #include "../../../../gen/l2/pixel_masses.h" #include "../../marie/rasterization.h" @@ -145,102 +146,19 @@ size_t ModelTopology_get_space_needed_for_staging_buffer(const ModelTopology* se } void TextureDataR8_pixel_maxing(TextureDataR8* self, S32 x, S32 y, U8 val) { - if (x < 0 || y < 0 || x >= self->width) + if (x < 0 || y < 0 || (size_t)x >= self->width) return; size_t p = (size_t)x + (size_t)y * self->width; if (p >= self->pixels.len) return; U8 b = *TextureDataR8_at(self, x, y); - *TextureDataR8_at(self, x, y) = MAX_U8(b, val); + *TextureDataR8_mat(self, x, y) = MAX_U8(b, val); } U8 a_small_cute_gradient(float r_cut, float r_decay, float dist) { return dist > r_cut ? 0 : (dist < r_decay) ? 255 : (U8)roundf( 255.f * (r_cut - dist) / (r_cut - r_decay) ); } -// todo: delete this crap -void TextureDataR8_seg_vertical_strip_maxing(TextureDataR8* self, S32 x, float y_real, float vert_r_cut, float vert_r_decay) { - S32 y = (S32)roundf(y_real - 0.5f); - S32 k = (S32)ceilf(vert_r_cut); - for (S32 j = -k+y; j <= y+k; j++) { - float dist = fabsf(.5f + (float)j - y_real); - TextureDataR8_pixel_maxing(self, x, j, a_small_cute_gradient(vert_r_cut, vert_r_decay, dist)); - } -} - -// todo: delete this crap -void TextureDataR8_seg_horizontal_strip_maxing(TextureDataR8* self, float x_real, S32 y, float hor_r_cut, float hor_r_decay) { - S32 x = (S32)roundf(x_real - 0.5f); - S32 k = (S32)ceilf(hor_r_cut); - for (S32 i = -k+x; i < x+k; i++) { - float dist = fabsf(.5f + (float)i - x_real); - TextureDataR8_pixel_maxing(self, i, y, a_small_cute_gradient(hor_r_cut, hor_r_decay, dist)); - } -} - -// todo: complete rewrite -/* abs(y2 - y1) < abs(x2 - x1) x1 <= x2 */ -void TextureDataR8_draw_horizontal_inner_line_maxing(TextureDataR8* self, - float x1, float y1, float x2, float y2, float r_cut, float r_decay) { - S32 sx1 = (S32)roundf(x1 - 0.5f); - S32 sx2 = (S32)roundf(x2 - 0.5f); - if (sx1 + 1 >= sx2) - return; - float dx = x2 - x1; - float dy = y2 - y1; - float xdds = 1 / dx; - float inv_sin_a = sqrtf(dx*dx + dy*dy) / dx; - float vert_r_cut = r_cut * inv_sin_a; - float vert_r_decay = r_decay * inv_sin_a; - for (S32 x = sx1 + 1; x < sx2; x++) { - float real_x = (float)x + 0.5f; - float real_y = y1 + dy * (real_x - x1) * xdds; - TextureDataR8_seg_vertical_strip_maxing(self, x, real_y, vert_r_cut, vert_r_decay); - } -} - -// todo: delete this crap -/* abs(x2 - x1) < abs(y2 - y1) y1 <= y2 */ -void TextureDataR8_draw_vertical_inner_line_maxing(TextureDataR8* self, - float x1, float y1, float x2, float y2, float r_cut, float r_decay) { - S32 sy1 = (S32)roundf(y1 - 0.5f); - S32 sy2 = (S32)roundf(y2 - 0.5f); - if (sy1 + 1 >= sy2) - return; - float dx = x2 - x1; - float dy = y2 - y1; - float ydds = 1 / dy; - float inv_sin_a = sqrtf(dx*dx + dy*dy) / dy; - float hor_r_cut = r_cut * inv_sin_a; - float hor_r_decay = r_decay * inv_sin_a; - for (S32 y = sy1 + 1; y < sy2; y++) { - float real_y = (float)y + 0.5f; - float real_x = x1 + dx * (real_y - y1) * ydds; - TextureDataR8_seg_horizontal_strip_maxing(self, real_x, y, hor_r_cut, hor_r_decay); - } -} -// todo: delete this crap - -void TextureDataR8_draw_inner_line_maxing(TextureDataR8* self, - vec2 v1, vec2 v2, float r_cut, float r_decay) { - float dx = fabsf(v2.x - v1.x); - float dy = fabsf(v2.y - v1.y); - if (dx > dy) { - if (v1.x < v2.x) { - TextureDataR8_draw_horizontal_inner_line_maxing(self, v1.x, v1.y, v2.x, v2.y, r_cut, r_decay); - } else { - TextureDataR8_draw_horizontal_inner_line_maxing(self, v2.x, v2.y, v1.x, v1.y, r_cut, r_decay); - } - } else { - if (v1.y < v2.y) { - TextureDataR8_draw_vertical_inner_line_maxing(self, v1.x, v1.y, v2.x, v2.y, r_cut, r_decay); - } else { - TextureDataR8_draw_vertical_inner_line_maxing(self, v2.x, v2.y, v1.x, v1.y, r_cut, r_decay); - } - } -} -// todo: delete this crap - void TextureDataR8_draw_spot_maxing(TextureDataR8* self, vec2 v, float r_cut, float r_decay) { S32 sx = (S32)roundf(v.x - .5f); S32 sy = (S32)roundf(v.y - .5f); @@ -254,24 +172,16 @@ void TextureDataR8_draw_spot_maxing(TextureDataR8* self, vec2 v, float r_cut, fl } } } -// todo: delete this crap - -void TextureDataR8_draw_one_segment_maxing(TextureDataR8* self, - vec2 v1, vec2 v2, float r_cut, float r_decay) { - TextureDataR8_draw_spot_maxing(self, v1, r_cut, r_decay); - TextureDataR8_draw_spot_maxing(self, v2, r_cut, r_decay); - TextureDataR8_draw_inner_line_maxing(self, v1, v2, r_cut, r_decay); -} ModelTopology generate_one_fourth_of_a_cylinder(float w, float r, U32 k) { assert(k >= 1); const float a = M_PI_2f / (float)k; - const float l = 2 * r * sin(M_PI_4f / (float)k); - const vec2 v0tex = {r / (2 * r + w), r / (2 * r + k * l)}; - const vec2 v1tex = {(r + w) / (2 * r + w), r / (2 * r + k * l)}; - const vec2 v2tex = {r / (2 * r + w), 2 * r / (2 * r + k * l)}; - const vec2 v3tex = {(r + w) / (2 * r + w), 2 * r / (2 * r + k * l)}; - VecGenericMeshVertex vertices = VecGenericMeshVertex_new(); // todo: reserve 4 * k + 6 + const float l = 2 * r * sinf(M_PI_4f / (float)k); + const vec2 v0tex = {r / (2 * r + w), r / (2 * r + (float)k * l)}; + const vec2 v1tex = {(r + w) / (2 * r + w), r / (2 * r + (float)k * l)}; + const vec2 v2tex = {r / (2 * r + w), 2 * r / (2 * r + (float)k * l)}; + const vec2 v3tex = {(r + w) / (2 * r + w), 2 * r / (2 * r + (float)k * l)}; + VecGenericMeshVertex vertices = VecGenericMeshVertex_new_reserved(4 * k + 6); VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){.pos = {0, 0, 0}, .tex = v0tex}); VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){.pos = {w, 0, 0}, .tex = v1tex}); VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){.pos = {0, r, 0}, .tex = v2tex}); @@ -280,32 +190,32 @@ ModelTopology generate_one_fourth_of_a_cylinder(float w, float r, U32 k) { VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){.pos = {w, 0, -r}, .tex = {(r + w) / (2 * r + w), 0}}); for (U32 i = 1; i <= k; i++) { VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){ - .pos = {0, cosf(a * i) * r, -sinf(a * i) * r}, - .tex = vec2_add_vec2(v0tex, (vec2){r / (2 * r + w) * -sinf(a * i), r / (2 * r + k * l) * cos(a * i)}) + .pos = {0, cosf(a * (float)i) * r, -sinf(a * (float)i) * r}, + .tex = vec2_add_vec2(v0tex, (vec2){r / (2 * r + w) * -sinf(a * (float)i), r / (2*r + (float)k * l) * cosf(a * (float)i)}) }); } for (U32 i = 1; i <= k; i++) { VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){ - .pos = {w, cosf(a * i) * r, -sinf(a * i) * r}, - .tex = vec2_add_vec2(v1tex, (vec2){r / (2 * r + w) * sinf(a * i), r / (2*r + k * l) * cos(a * i)}) + .pos = {w, cosf(a * (float)i) * r, -sinf(a * (float)i) * r}, + .tex = vec2_add_vec2(v1tex, (vec2){r / (2 * r + w) * sinf(a * (float)i), r / (2*r + (float)k * l) * cosf(a * (float)i)}) }); } for (U32 i = 1; i <= k; i++) { VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){ - .pos = {0, cosf(a * i) * r, -sinf(a * i) * r}, - .tex = {v2tex.x, v2tex.y + i * l / (2*r + k * l)} + .pos = {0, cosf(a * (float)i) * r, -sinf(a * (float)i) * r}, + .tex = {v2tex.x, v2tex.y + (float)i * l / (2*r + (float)k * l)} }); } for (U32 i = 1; i <= k; i++) { VecGenericMeshVertex_append(&vertices, (GenericMeshVertex){ - .pos = {w, cosf(a * i) * r, -sinf(a * i) * r}, - .tex = {v3tex.x, v3tex.y + i * l / (2*r + k * l)} + .pos = {w, cosf(a * (float)i) * r, -sinf(a * (float)i) * r}, + .tex = {v3tex.x, v3tex.y + (float)i * l / (2*r + (float)k * l)} }); } - VecU32 indexes = VecU32_new(); // todo: reserve 3 * (2+2+2*k+2*k)< + VecU32 indexes = VecU32_new_reserved(3*(2+2+2*k+2*k)); { U32 _span_0[] = {5, 1, 0, 5, 0, 4, 1, 3, 0, 3, 2, 0}; - VecU32_append_span(&indexes, (ConstSpanU32){.data = _span_0, .len = ARRAY_SIZE(_span_0)}); + VecU32_append_span(&indexes, (SpanU32){.data = _span_0, .len = ARRAY_SIZE(_span_0)}); } for (U32 i = 1; i <= k; i++) { U32 _span_1[] = { @@ -314,34 +224,26 @@ ModelTopology generate_one_fourth_of_a_cylinder(float w, float r, U32 k) { i > 1 ? 5 + 2 * k + i - 1 : 2, i > 1 ? 5 + 3 * k + i - 1 : 3, 5 + 2 * k + i, 5 + 3 * k + i, 5 + 2 * k + i, i > 1 ? 5 + 3 * k + i - 1 : 3, }; - VecU32_append_span(&indexes, (ConstSpanU32){.data = _span_1, .len = ARRAY_SIZE(_span_1)}); + VecU32_append_span(&indexes, (SpanU32){.data = _span_1, .len = ARRAY_SIZE(_span_1)}); } return (ModelTopology){.vertices = vertices, .indexes = indexes}; } -#define vec2_drop(x) {} -#define vec2_clone(x) (*(x)) - -VecT_trivmove_struct_Definition(vec2) -VecT_trivmove_method_Definition(vec2) -VecT_primitive_zeroinit_method_Definition(vec2) -SpanT_struct_Definition(vec2) -SpanT_method_Definition(vec2) -SpanT_VecT_method_Definition(vec2) - -void TextureDataR8_draw_perimeter_maxing(TextureDataR8* self, ConstSpanvec2 P) { +/* todo: write it myself using triangles and LINES +void TextureDataR8_draw_perimeter_maxing(TextureDataR8* self, Spanvec2 P) { float r_cut = 2; float r_decay = 1; size_t S = P.len; for (size_t i = 0; i < S; i++) { - TextureDataR8_draw_spot_maxing(self, *ConstSpanvec2_at(P, i), r_cut, r_decay); + TextureDataR8_draw_spot_maxing(self, *Spanvec2_at(P, i), r_cut, r_decay); } for (size_t i = 1; i < S; i++) { - TextureDataR8_draw_inner_line_maxing(self, *ConstSpanvec2_at(P, i - 1), *ConstSpanvec2_at(P, i), r_cut, r_decay); + TextureDataR8_draw_inner_line_maxing(self, *Spanvec2_at(P, i - 1), *Spanvec2_at(P, i), r_cut, r_decay); } if (S > 2) - TextureDataR8_draw_inner_line_maxing(self, *ConstSpanvec2_at(P, S - 1), *ConstSpanvec2_at(P, 0), r_cut, r_decay); + TextureDataR8_draw_inner_line_maxing(self, *Spanvec2_at(P, S - 1), *Spanvec2_at(P, 0), r_cut, r_decay); } +*/ typedef struct { vec2 bl; @@ -350,12 +252,7 @@ typedef struct { float brd; } Wimbzle; -#define Wimbzle_drop(x) {} -#define Wimbzle_clone(xp) (*(xp)) - -VecT_trivmove_struct_Definition(Wimbzle) -VecT_trivmove_method_Definition(Wimbzle) -VecT_primitive_zeroinit_method_Definition(Wimbzle) +#include "../../../../gen/l2/eve/r0/VecWimbzle.h" typedef struct { vec2 center; @@ -363,12 +260,7 @@ typedef struct { float hc; } Nibzle; -#define Nibzle_drop(x) {} -#define Nibzle_clone(xp) (*(xp)) - -VecT_trivmove_struct_Definition(Nibzle) -VecT_trivmove_method_Definition(Nibzle) -VecT_primitive_zeroinit_method_Definition(Nibzle) +#include "../../../../gen/l2/eve/r0/VecNibzle.h" typedef struct { VecWimbzle wimbzles; @@ -398,38 +290,37 @@ void Bublazhuzhka_TextureDataR8_draw_maxing(const Bublazhuzhka* self, TextureDat vec2 p1[4] = {mat3x2_mul_vec3(trop, vec2_and_one(A)), mat3x2_mul_vec3(trop, vec2_and_one(B)), mat3x2_mul_vec3(trop, vec2_and_one(D)), mat3x2_mul_vec3(trop, vec2_and_one(C))}; - TextureDataR8_draw_perimeter_maxing(canvas, (ConstSpanvec2){.data = p1, ARRAY_SIZE(p1)}); + // TextureDataR8_draw_perimeter_maxing(canvas, (Spanvec2){.data = p1, ARRAY_SIZE(p1)}); vec2 p2[4] = {mat3x2_mul_vec3(trop, vec2_and_one(E)), mat3x2_mul_vec3(trop, vec2_and_one(F)), mat3x2_mul_vec3(trop, vec2_and_one(H)), mat3x2_mul_vec3(trop, vec2_and_one(G))}; - TextureDataR8_draw_perimeter_maxing(canvas, (ConstSpanvec2){.data = p2, ARRAY_SIZE(p2)}); + // TextureDataR8_draw_perimeter_maxing(canvas, (Spanvec2){.data = p2, ARRAY_SIZE(p2)}); } - + // todo: draw all these cool perimeters myself for (size_t i = 0; i < self->nibzles.len; i++) { Nibzle sphere = *VecNibzle_at(&self->nibzles, i); Vecvec2 p = Vecvec2_new_zeroinit(13); for (int j = 0; j < 13; j++) { - float a = (float)j * 2 * M_PI / 13; - *Vecvec2_at(&p, j) = vec2_add_vec2(sphere.center, vec2_mul_scal(marie_trigonom_circle(a), sphere.rad)); + float a = (float)j * 2 * M_PIf / 13; + *Vecvec2_mat(&p, j) = vec2_add_vec2(sphere.center, vec2_mul_scal(marie_trigonom_circle(a), sphere.rad)); } - TextureDataR8_draw_perimeter_maxing(canvas, Vecvec2_to_ConstSpanvec2(&p)); + // TextureDataR8_draw_perimeter_maxing(canvas, Vecvec2_to_Spanvec2(&p)); Vecvec2_drop(p); TextureDataR8_draw_spot_maxing(canvas, mat3x2_mul_vec3(trop, vec2_and_one(sphere.center)), 3, 1); } } Bublazhuzhka fill_rectangle_with_crap(float w, float h) { - // Bublazhuzhka res = Bublazhuzhka_new(); S32 k = MAX_S32(0, (S32)floorf((w/h + 0.1f) / 0.7f)); VecWimbzle wimbzles = VecWimbzle_new_zeroinit(k); VecNibzle nibzles = VecNibzle_new_zeroinit(2 * k); float start = k != 1 ? h * 0.2f : ((w - 0.2f * h) / 2); - float d = k > 1 ? ((w - h * 0.4f - h * 0.2f * k) / (float)(k - 1)) : 0; + float d = k > 1 ? ((w - h * 0.4f - h * 0.2f * (float)k) / (float)(k - 1)) : 0; for (S32 i = 0; i < k; i++) { - float x = start + (d + h * 0.2) * i; - *VecWimbzle_at(&wimbzles, i) = (Wimbzle){.bl = {x + 0.02 * h, 0.27 * h}, .tr = {x + 0.18 * h, h * 0.73}, .height = h * 0.03, .brd = h * 0.03}; + float x = start + (d + h * 0.2f) * (float)i; + *VecWimbzle_mat(&wimbzles, i) = (Wimbzle){.bl = {x + 0.02f * h, 0.27f * h}, .tr = {x + 0.18f * h, h * 0.73f}, .height = h * 0.03f, .brd = h * 0.03f}; /* hc is a height coefficient*/ - *VecNibzle_at(&nibzles, 2 * i) = (Nibzle){.center = {x + 0.10 * h, 0.11 * h}, .rad = h * 0.05, .hc = 0.75}; - *VecNibzle_at(&nibzles, 2 * i + 1) = (Nibzle){.center = {x + 0.10 * h, 0.89 * h}, .rad = h * 0.05, .hc = 0.75}; + *VecNibzle_mat(&nibzles, 2 * i) = (Nibzle){.center = {x + 0.10f * h, 0.11f * h}, .rad = h * 0.05f, .hc = 0.75f}; + *VecNibzle_mat(&nibzles, 2 * i + 1) = (Nibzle){.center = {x + 0.10f * h, 0.89f * h}, .rad = h * 0.05f, .hc = 0.75f}; } return (Bublazhuzhka){.wimbzles = wimbzles, .nibzles = nibzles}; } @@ -487,7 +378,7 @@ typedef struct { void draw_polygon_on_normal_texture_smooth_param_surf_h_draw_cb(void* ug, S32 x, S32 y, vec4 attr) { draw_polygon_on_normal_texture_smooth_param_surf_H_DrawGuest* g = ug; vec3 normal = g->my_client.fn(g->my_client.guest, (vec2){attr.x, attr.y}); - *TextureDataR8G8B8_at(g->tex, x, y) = compress_normal_vec_into_norm_texel(normal); + *TextureDataR8G8B8_mat(g->tex, x, y) = compress_normal_vec_into_norm_texel(normal); } void draw_polygon_on_normal_texture_smooth_param_surf( @@ -516,7 +407,7 @@ typedef struct { void draw_polygon_on_normal_texture_exaggerated_param_surf_draw_cb(void* ug, S32 x, S32 y, vec4 attr) { draw_polygon_on_normal_texture_exaggerated_param_surf_H_DrawGuest* g = ug; vec3 normal = g->my_client.fn(g->my_client.guest, (vec3){attr.x, attr.y, attr.z}); - *TextureDataR8G8B8_at(g->tex, x, y) = compress_normal_vec_into_norm_texel(normal); + *TextureDataR8G8B8_mat(g->tex, x, y) = compress_normal_vec_into_norm_texel(normal); } /* We can't derive texture coordinates from parameter space coordinates, you have to do it yourself */ @@ -540,7 +431,7 @@ typedef struct { void draw_polygon_on_normal_texture_absolutely_flat_h_draw_cb(void* ug, S32 x, S32 y, vec4) { draw_polygon_on_normal_texture_absolutely_flat_H_DrawGuest* g = ug; - *TextureDataR8G8B8_at(g->tex, x, y) = g->normal_compr; + *TextureDataR8G8B8_mat(g->tex, x, y) = g->normal_compr; } void draw_polygon_on_normal_texture_nat_cords_absolutely_flat(TextureDataR8G8B8* tex, @@ -593,10 +484,10 @@ void draw_polygon_on_normal_texture_flat_param_surf(TextureDataR8G8B8* tex, vec2 TextureDataR8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_resol, float w, float r, U32 k) { assert(k >= 1); const float a = M_PI_2f / (float)k; - const float l = 2 * r * sin(M_PI_4f / (float)k); + const float l = 2 * r * sinf(M_PI_4f / (float)k); size_t width_pix = (size_t)ceilf(s_resol * (2 * r + w)); - size_t height_pix = (size_t)ceilf(s_resol * (2 * r + k * l)); - vec2 cord_resol = {(float)width_pix / (2 * r + w), (float)height_pix / (2 * r + k * l)}; + size_t height_pix = (size_t)ceilf(s_resol * (2 * r + (float)k * l)); + vec2 cord_resol = {(float)width_pix / (2 * r + w), (float)height_pix / (2 * r + (float)k * l)}; const vec2 v0tex = {r, r}; const vec2 v1tex = {r + w, r}; const vec2 v2tex = {r, 2 * r}; @@ -608,27 +499,29 @@ TextureDataR8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_resol, Vecvec2_append(&P, (vec2){r + w, 0}); // 5 Vecvec2_append(&P, v1tex); for (size_t i = k; i > 0; i--) { - Vecvec2_append(&P, (vec2){r + w + r * sinf(a * i), r + r * cos(a * i)}); + Vecvec2_append(&P, (vec2){r + w + r * sinf(a * (float)i), r + r * cosf(a * (float)i)}); } Vecvec2_append(&P, v3tex); for (size_t i = 1; i <= k; i++) { - Vecvec2_append(&P, (vec2){r + w, 2 * r + i * l}); + Vecvec2_append(&P, (vec2){r + w, 2 * r + (float)i * l}); } for (size_t i = k; i > 0; i--) { - Vecvec2_append(&P, (vec2){r, 2 * r + i * l}); + Vecvec2_append(&P, (vec2){r, 2 * r + (float)i * l}); } Vecvec2_append(&P, v2tex); for (size_t i = 1; i <= k; i++) { - Vecvec2_append(&P, (vec2){r - r * sinf(a * i), r + r * cos(a * i)}); + Vecvec2_append(&P, (vec2){r - r * sinf(a * (float)i), r + r * cosf(a * (float)i)}); } for (size_t i = 0; i < P.len; i++) { - *Vecvec2_at(&P, i) = vec2_mul_vec2(*Vecvec2_at(&P, i), cord_resol); + *Vecvec2_mat(&P, i) = vec2_mul_vec2(*Vecvec2_at(&P, i), cord_resol); } - TextureDataR8_draw_perimeter_maxing(&res, Vecvec2_to_ConstSpanvec2(&P)); + // todo: actually draw this perimeter + // TextureDataR8_draw_perimeter_maxing(&res, Vecvec2_to_Spanvec2(&P)); Bublazhuzhka crap_on_back_side = fill_rectangle_with_crap(w, r); - Bublazhuzhka_TextureDataR8_draw_maxing(&crap_on_back_side, &res, - (mat3x2){.x.x = cord_resol.x, .y.y = cord_resol.y, .z = vec2_mul_vec2((vec2){r, r}, cord_resol)}); + // todo: draw bublazhuzhka pixel-by-pixel myself + // Bublazhuzhka_TextureDataR8_draw_maxing(&crap_on_back_side, &res, + // (mat3x2){.x.x = cord_resol.x, .y.y = cord_resol.y, .z = vec2_mul_vec2((vec2){r, r}, cord_resol)}); return res; } @@ -642,10 +535,10 @@ vec2 height_map_cb_that_uses_bublazhuzhka(void* ug, vec2 v) { TextureDataR8G8B8 generate_normal_tex_for_one_fourth_of_a_cylinder(float s_resol, float w, float r, U32 k) { assert(k >= 1); const float a = M_PI_2f / (float)k; - const float l = 2 * r * sin(M_PI_4f / (float)k); + const float l = 2 * r * sinf(M_PI_4f / (float)k); size_t width_pix = (size_t)ceilf(s_resol * (2 * r + w)); - size_t height_pix = (size_t)ceilf(s_resol * (2 * r + k * l)); - vec2 cord_resol = {(float)width_pix / (2 * r + w), (float)height_pix / (2 * r + k * l)}; + size_t height_pix = (size_t)ceilf(s_resol * (2 * r + (float)k * l)); + vec2 cord_resol = {(float)width_pix / (2 * r + w), (float)height_pix / (2 * r + (float)k * l)}; const vec2 v0tex = {r, r}; const vec2 v1tex = {r + w, r}; const vec2 v2tex = {r, 2 * r}; @@ -666,21 +559,21 @@ TextureDataR8G8B8 generate_normal_tex_for_one_fourth_of_a_cylinder(float s_resol draw_polygon_on_normal_texture_absolutely_flat(&res, v0tex, v1tex, v4tex, str, (vec3){0, -1, 0}); draw_polygon_on_normal_texture_absolutely_flat(&res, v1tex, v4tex, v5tex, str, (vec3){0, -1, 0}); for (size_t i = 0; i < k; i++) { - vec2 A = {r - sinf(i * a) * r, r + cosf(i * a) * r}; - vec2 B = {r - sinf((i + 1) * a) * r, r + cosf((i + 1) * a) * r}; + vec2 A = {r - sinf((float)i * a) * r, r + cosf((float)i * a) * r}; + vec2 B = {r - sinf((float)(i + 1) * a) * r, r + cosf((float)(i + 1) * a) * r}; draw_polygon_on_normal_texture_absolutely_flat(&res, A, B, (vec2){r, r}, str, (vec3){-1, 0, 0}); } for (size_t i = 0; i < k; i++) { - vec2 A = {r + w + sinf(i * a) * r, r + cos(i * a) * r}; - vec2 B = {r + w + sinf((i + 1) * a) * r, r + cos((i + 1) * a) * r}; + vec2 A = {r + w + sinf((float)i * a) * r, r + cosf((float)i * a) * r}; + vec2 B = {r + w + sinf((float)(i + 1) * a) * r, r + cosf((float)(i + 1) * a) * r}; draw_polygon_on_normal_texture_absolutely_flat(&res, A, B, (vec2){r + w, r}, str, (vec3){1, 0, 0}); } for (size_t i = 0; i < k; i++) { - vec2 A = {r, 2 * r + i * l}; - vec2 B = {r + w, 2 * r + i * l}; - vec2 C = {r, 2 * r + i * l + l}; - vec2 D = {r + w, 2 * r + i * l + l}; - vec3 n = {0, cos(a / 2 + a * i), -sin(a / 2 + a * i)}; + vec2 A = {r, 2 * r + (float)i * l}; + vec2 B = {r + w, 2 * r + (float)i * l}; + vec2 C = {r, 2 * r + (float)i * l + l}; + vec2 D = {r + w, 2 * r + (float)i * l + l}; + vec3 n = {0, cosf(a / 2 + a * (float)i), -sinf(a / 2 + a * i)}; draw_polygon_on_normal_texture_absolutely_flat(&res, A, B, C, str, n); draw_polygon_on_normal_texture_absolutely_flat(&res, D, B, C, str, n); } diff --git a/src/l2/tests/r0/r0_scene.h b/src/l2/tests/r0/r0_scene.h index 7c4cabd..f76e477 100644 --- a/src/l2/tests/r0/r0_scene.h +++ b/src/l2/tests/r0/r0_scene.h @@ -11,12 +11,7 @@ typedef struct { size_t indexes; } ModelOnScene; -#define ModelOnScene_drop(vp) {} -#define ModelOnScene_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(ModelOnScene) -VecT_trivmove_method_Definition(ModelOnScene) -VecT_primitive_zeroinit_method_Definition(ModelOnScene) +#include "../../../../gen/l2/eve/r0/VecModelOnScene.h" /* Contains both data for model instances attributes and buffer (+offset) where it is stored */ typedef struct { @@ -38,10 +33,7 @@ UsedModelOnScene UsedModelOnScene_clone(const UsedModelOnScene* self) { }; } -VecT_trivmove_struct_Definition(UsedModelOnScene) -VecT_trivmove_method_Definition(UsedModelOnScene) -VecT_primitive_zeroinit_method_Definition(UsedModelOnScene) - +#include "../../../../gen/l2/eve/r0/VecUsedModelOnScene.h" typedef struct { float fov; @@ -79,8 +71,8 @@ void CamControlInfo_up(CamControlInfo* self, float fl) { CamControlInfo CamControlInfo_new() { return (CamControlInfo){ - .fov = 1.5, .cam_basis = marie_simple_camera_rot_m_basis_in_cols(0, 0, 0), .pos = {0, 0, 0}, - .speed = 2.7, .sensitivity = 0.5f * M_PIf / 180, .pitch_cap = M_PI * 0.49 + .fov = 1.5f, .cam_basis = marie_simple_camera_rot_m_basis_in_cols(0, 0, 0), .pos = {0, 0, 0}, + .speed = 2.7f, .sensitivity = 0.5f * M_PIf / 180, .pitch_cap = M_PIf * 0.49f }; } @@ -89,9 +81,9 @@ float clamp_float(float a, float l, float r) { } void CamControlInfo_update_direction(CamControlInfo* self, int win_width, int win_height, int pointer_x, int pointer_y) { - float yaw = (float)(win_width / 2 - pointer_x) * self->sensitivity; + float yaw = ((float)win_width / 2 - (float)pointer_x) * self->sensitivity; float pitch = clamp_float( - (float)(win_height / 2 - pointer_y) * self->sensitivity, + ((float)win_height / 2 - (float)pointer_y) * self->sensitivity, -self->pitch_cap, self->pitch_cap ); self->cam_basis = marie_simple_camera_rot_m_basis_in_cols(yaw, pitch, 0); @@ -110,7 +102,7 @@ typedef struct { Scene Scene_new() { return (Scene){.models = VecUsedModelOnScene_new(), .color = {.float32 = {0, 0, 0, 1}}, - .gamma_correction_factor = 2.2, .hdr_factor = 1, .lsd_factor = 0, .anim_time = 0, + .gamma_correction_factor = 2.2f, .hdr_factor = 1, .lsd_factor = 0, .anim_time = 0, .spotlights = VecPipeline0Spotlight_new(), .point_lights = VecPipeline0PointLight_new()}; } @@ -135,8 +127,8 @@ void SceneTemplate_copy_initial_model_topology_and_rerecord_transfer_cmd( // todo: ot use one buffer per all the data // VecVkBufferCopy regions_to_copy = VecVkBufferCopy_new_zeroinit(scene_template->models.len * 2); for (size_t mi = 0; mi < scene_template->models.len; mi++) { - const ModelInSceneTemplate* mt = VecModelInSceneTemplate_cat(&scene_template->models, mi); - const UsedModelOnScene* m_buf = VecUsedModelOnScene_cat(&scene->models, mi); + const ModelInSceneTemplate* mt = VecModelInSceneTemplate_at(&scene_template->models, mi); + const UsedModelOnScene* m_buf = VecUsedModelOnScene_at(&scene->models, mi); size_t vbo_len = mt->topology.vertices.len * sizeof(GenericMeshVertex); memcpy(host_mem_buffer_mem + offset, mt->topology.vertices.buf, vbo_len); VkBufferCopy ra = {.srcOffset = offset, .dstOffset = 0, .size = vbo_len};