diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d2dcdc..6b8d7fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,8 @@ add_executable(1_test src/l1/tests/t1.c) add_executable(codegen_l2 src/l2/codegen/codegen.c) -#add_executable(0_render_test src/l2/tests/r0/r0.c) -#target_link_libraries(0_render_test -lvulkan -lX11 -lm) +add_executable(0_render_test src/l2/tests/r0/r0.c) +target_link_libraries(0_render_test -lvulkan -lX11 -lm) # #add_executable(0_render_test_tex_init_prep src/l2/tests/r0/r0_tex_init_prep.c) #target_link_libraries(0_render_test_tex_init_prep -lm) diff --git a/src/l1/codegen/util_template_inst.h b/src/l1/codegen/util_template_inst.h index 15ee0c8..d52a0a1 100644 --- a/src/l1/codegen/util_template_inst.h +++ b/src/l1/codegen/util_template_inst.h @@ -462,7 +462,7 @@ NODISCARD VecU8 generate_util_templates_instantiation(SpanU8 T, util_templates_i return res; } -/* You want bonus_ns to be cstr(""). But if it isn't, it should end with / */ +/* You want bonus_ns to be cstr("").*/ void generate_eve_header(SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, util_templates_instantiation_options op) { if (op.t_integer) op.t_primitive = true; @@ -485,7 +485,7 @@ void generate_eve_header(SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, util_templates assert(op.vec || op.span || op.option); VecU8 text = vcstr("/*Automatically generated file. Do not edit it */\n\n"); 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, + 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((int)op.vec + (int)op.span + (int)op.option > 1 ? "_" : ""), T); @@ -495,4 +495,16 @@ void generate_eve_header(SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, util_templates VecU8_drop(text); } +void generate_eve_span_garden_for_primitive(SpanU8 layer, SpanU8 ns, SpanU8 T, bool with_vector, bool with_span) { + generate_eve_header(layer, ns, T, (util_templates_instantiation_options){ + .t_primitive = true, .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span + }); +} + +void generate_eve_span_garden_for_non_primitive(SpanU8 layer, SpanU8 ns, SpanU8 T, bool with_vector, bool with_span) { + generate_eve_header(layer, ns, T, (util_templates_instantiation_options){ + .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span + }); +} + #endif diff --git a/src/l2/codegen/codegen.c b/src/l2/codegen/codegen.c index 9250fe3..209fb50 100644 --- a/src/l2/codegen/codegen.c +++ b/src/l2/codegen/codegen.c @@ -6,6 +6,19 @@ // todo: generate here eve headers for margaret and for tests (long asset description files in r0) +void eve_of_l2() { + make_dir_nofail("l2/eve"); + make_dir_nofail("l2/eve/r0"); + /* Needed in r0_assets.h */ + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("GenericMeshVertex"), true, false); + generate_eve_span_garden_for_non_primitive(cstr("l2"), cstr("r0"), cstr("ModelInSceneTemplate"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("GenericMeshInstance"), true, false); + generate_eve_span_garden_for_primitive(cstr("l2"), cstr("r0"), cstr("ShinyMeshVertex"), true, false); + 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); +} + void generate_Vec_cvec_header() { VecU8 res = begin_header(cstr("PROTOTYPE1_GEN_L2_VECANDSPAN_GEOM_CVEC_H")); VecU8_append_span(&res, cstr("#include \"geom.h\"\n")); @@ -36,6 +49,9 @@ void generate_Vec_vec_header() { int main() { make_dir_nofail("l2"); + /* These headers are unordered by their nature */ + eve_of_l2(); + generate_geom_header(); generate_Vec_cvec_header(); diff --git a/src/l2/core/stringop.h b/src/l2/core/stringop.h index b7045dc..8bacac3 100644 --- a/src/l2/core/stringop.h +++ b/src/l2/core/stringop.h @@ -1,7 +1,9 @@ #ifndef PROTOTYPE1_SRC_L2_CORE_STRINGOP_H #define PROTOTYPE1_SRC_L2_CORE_STRINGOP_H -#include "../../l1/core/VecSpan_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_Vec_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_Span_int_primitives.h" U8 U8_to_lowercase(U8 ch) { if ('A' <= ch && ch <= 'Z') @@ -9,42 +11,34 @@ U8 U8_to_lowercase(U8 ch) { return ch; } -void string_to_lowercase(VecU8* str) { - for (size_t i = 0; i < str->len; i++) { - *VecU8_at(str, i) = U8_to_lowercase(*VecU8_cat(str, i)); - } -} - // Worst case time complexity: O(nm) -bool string_contains_string_ignorecase(VecU8 str1, VecU8 str2) { - string_to_lowercase(&str1); - string_to_lowercase(&str2); +bool string_contains_string_ignorecase(SpanU8 str1, SpanU8 str2) { size_t L = str2.len; for (size_t i = 0; i + L <= str1.len; i++) { for (size_t j = 0; j < L; j++) { - if (*VecU8_at(&str1, i + j) != *VecU8_at(&str2, j)) + if (U8_to_lowercase(*SpanU8_at(str1, i + j)) != U8_to_lowercase(*SpanU8_at(str2, j))) goto e; } return true; e: + int u; } return false; } -bool strings_in_spans_equal(ConstSpanU8 a, ConstSpanU8 b) { +bool strings_in_spans_equal(SpanU8 a, SpanU8 b) { if (a.len != b.len) return false; for (size_t i = 0; i < a.len; i++) { - if (*ConstSpanU8_at(a, i) != *ConstSpanU8_at(b, i)) + if (*SpanU8_at(a, i) != *SpanU8_at(b, i)) return false; } return true; } -bool string_in_string_vec(ConstSpanU8 a, const VecVecU8* B) { +bool is_string_in_string_vec(SpanU8 a, const VecVecU8* B) { for (size_t i = 0; i < B->len; i++) { - const VecU8* b = VecVecU8_cat(B, i); - if (strings_in_spans_equal(a, VecU8_to_ConstSpanU8(b))) + if (strings_in_spans_equal(a, VecU8_to_span(VecVecU8_at(B, i)))) return true; } return false; diff --git a/src/l2/margaret/margaret.h b/src/l2/margaret/margaret.h index 165204f..61cc561 100644 --- a/src/l2/margaret/margaret.h +++ b/src/l2/margaret/margaret.h @@ -147,7 +147,7 @@ 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) {} diff --git a/src/l2/tests/r0/r0_assets.h b/src/l2/tests/r0/r0_assets.h index c6bf6ec..af54062 100644 --- a/src/l2/tests/r0/r0_assets.h +++ b/src/l2/tests/r0/r0_assets.h @@ -2,8 +2,7 @@ #define SPLITTER_DRAFT_SRC_L2_TESTS_R0_ASSETS_H #include "../../marie/graphics_geom.h" -#include "../../../l1/core/util.h" -#include "../../../l1/core/VecSpan_int_primitives.h" +#include "../../../../gen/l1/VecAndSpan_int_primitives.h" #include "../../../l1/system/fileio.h" #include #include "../../../../gen/l2/pixel_masses.h" @@ -14,15 +13,7 @@ typedef struct { vec2 tex; } GenericMeshVertex; -#define GenericMeshVertex_drop(vp) {} -#define GenericMeshVertex_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(GenericMeshVertex) -VecT_trivmove_method_Definition(GenericMeshVertex) -VecT_primitive_zeroinit_method_Definition(GenericMeshVertex) -// SpanT_struct_Definition(GenericMeshVertex) -// SpanT_method_Definition(GenericMeshVertex) -// SpanT_VecT_method_Definition(GenericMeshVertex) +#include "../../../../gen/l2/eve/r0/VecGenericMeshVertex.h" typedef struct { VecGenericMeshVertex vertices; @@ -35,7 +26,7 @@ void ModelTopology_drop(ModelTopology self) { } ModelTopology ModelTopology_clone(const ModelTopology* self) { - return (ModelTopology){.vertices = VecGenericMeshVertex_new(&self->vertices), .indexes = VecU32_clone(&self->indexes)}; + return (ModelTopology){.vertices = VecGenericMeshVertex_clone(&self->vertices), .indexes = VecU32_clone(&self->indexes)}; } typedef struct { @@ -51,34 +42,20 @@ ModelInSceneTemplate ModelInSceneTemplate_clone(const ModelInSceneTemplate* self return (ModelInSceneTemplate){.topology = ModelTopology_clone(&self->topology), .max_instance_count = self->max_instance_count}; } -VecT_trivmove_struct_Definition(ModelInSceneTemplate) -VecT_trivmove_method_Definition(ModelInSceneTemplate) -VecT_primitive_zeroinit_method_Definition(ModelInSceneTemplate) +#include "../../../../gen/l2/eve/r0/VecModelInSceneTemplate.h" typedef struct { mat4 model_t; } GenericMeshInstance; -#define GenericMeshInstance_drop(vp) {} -#define GenericMeshInstance_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(GenericMeshInstance) -VecT_trivmove_method_Definition(GenericMeshInstance) -VecT_primitive_zeroinit_method_Definition(GenericMeshInstance) - - +#include "../../../../gen/l2/eve/r0/VecGenericMeshInstance.h" typedef struct { vec3 pos; vec3 normal; } ShinyMeshVertex; -#define ShinyMeshVertex_drop(vp) {} -#define ShinyMeshVertex_clone(vp) (*(vp)) - -VecT_trivmove_struct_Definition(ShinyMeshVertex) -VecT_trivmove_method_Definition(ShinyMeshVertex) -VecT_primitive_zeroinit_method_Definition(ShinyMeshVertex) +#include "../../../../gen/l2/eve/r0/VecShinyMeshVertex.h" typedef struct { mat4 model_t; @@ -86,6 +63,7 @@ typedef struct { vec3 color_on; } ShinyMeshInstance; +#include "../../../../gen/l2/eve/r0/VecShinyMeshInstance.h" typedef struct { vec2 win_scale; @@ -109,12 +87,7 @@ typedef struct { char _padding_3[12]; } Pipeline0Spotlight; -#define Pipeline0Spotlight_drop(x) {} -#define Pipeline0Spotlight_clone(x) (*(x)) - -VecT_trivmove_struct_Definition(Pipeline0Spotlight) -VecT_trivmove_method_Definition(Pipeline0Spotlight) -VecT_primitive_zeroinit_method_Definition(Pipeline0Spotlight) +#include "../../../../gen/l2/eve/r0/VecPipeline0Spotlight.h" typedef struct { vec3 pos; @@ -123,14 +96,7 @@ typedef struct { char _padding_1[4]; } Pipeline0PointLight; -#define Pipeline0PointLight_drop(x) {} -#define Pipeline0PointLight_clone(x) (*(x)) - -VecT_trivmove_struct_Definition(Pipeline0PointLight) -VecT_trivmove_method_Definition(Pipeline0PointLight) -VecT_primitive_zeroinit_method_Definition(Pipeline0PointLight) - - +#include "../../../../gen/l2/eve/r0/VecPipeline0PointLight.h" typedef struct { VecModelInSceneTemplate models; @@ -141,7 +107,7 @@ typedef struct { size_t SceneTemplate_get_space_needed_for_all_instance_attributes(const SceneTemplate* self) { size_t s = 0; for (size_t mi = 0; mi < self->models.len; mi++) { - const ModelInSceneTemplate* M = VecModelInSceneTemplate_cat(&self->models, mi); + const ModelInSceneTemplate* M = VecModelInSceneTemplate_at(&self->models, mi); s += M->max_instance_count * sizeof(GenericMeshInstance); } return s; @@ -157,7 +123,7 @@ size_t SceneTemplate_get_space_needed_for_widest_state_transfer(const SceneTempl size_t SceneTemplate_get_space_for_initial_model_topology_transfer(const SceneTemplate* self) { size_t s = 0; for (size_t mi = 0; mi < self->models.len; mi++) { - const ModelInSceneTemplate* M = VecModelInSceneTemplate_cat(&self->models, mi); + const ModelInSceneTemplate* M = VecModelInSceneTemplate_at(&self->models, mi); s += M->topology.vertices.len * sizeof(GenericMeshVertex) + M->topology.indexes.len * sizeof(U32); } return s; @@ -420,7 +386,7 @@ void Bublazhuzhka_drop(Bublazhuzhka self) { void Bublazhuzhka_TextureDataR8_draw_maxing(const Bublazhuzhka* self, TextureDataR8* canvas, mat3x2 trop) { for (size_t i = 0; i < self->wimbzles.len; i++) { - Wimbzle rect = *VecWimbzle_cat(&self->wimbzles, i); + Wimbzle rect = *VecWimbzle_at(&self->wimbzles, i); vec2 B = {rect.tr.x + rect.brd, rect.tr.y + rect.brd}; vec2 C = {rect.bl.x - rect.brd, rect.bl.y - rect.brd}; vec2 A = {C.x, B.y}; @@ -439,7 +405,7 @@ void Bublazhuzhka_TextureDataR8_draw_maxing(const Bublazhuzhka* self, TextureDat } for (size_t i = 0; i < self->nibzles.len; i++) { - Nibzle sphere = *VecNibzle_cat(&self->nibzles, 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; @@ -471,7 +437,7 @@ Bublazhuzhka fill_rectangle_with_crap(float w, float h) { vec2 Bublazhuzhka_get_derivative(const Bublazhuzhka* self, vec2 v) { vec2 sum = { 0 }; for (size_t i = 0; i < self->wimbzles.len; i++) { - Wimbzle rect = *VecWimbzle_cat(&self->wimbzles, i); + Wimbzle rect = *VecWimbzle_at(&self->wimbzles, i); vec2 B = {rect.tr.x + rect.brd, rect.tr.y + rect.brd}; vec2 C = {rect.bl.x - rect.brd, rect.bl.y - rect.brd}; vec2 A = {C.x, B.y}; @@ -492,7 +458,7 @@ vec2 Bublazhuzhka_get_derivative(const Bublazhuzhka* self, vec2 v) { } } for (size_t i = 0; i < self->nibzles.len; i++) { - Nibzle sphere = *VecNibzle_cat(&self->nibzles, i); + Nibzle sphere = *VecNibzle_at(&self->nibzles, i); float sq_h = pow2f(sphere.rad) - pow2f(v.x - sphere.center.x) - pow2f(v.y - sphere.center.y); if (sq_h <= 0) continue;