diff --git a/include/fractal.hpp b/include/fractal.hpp index cec7352..601b5e6 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -16,6 +16,8 @@ constexpr size_t g_max_branch_rules = 8; constexpr size_t g_max_mark_rules = 4; constexpr size_t g_max_cgroup_tokens = 16; constexpr size_t g_max_wgroup_weights = 8; +constexpr size_t g_max_match_groups = 8; +constexpr size_t g_max_match_wgroups = 4; using token_id_t = uint32_t; using group_id_t = uint32_t; @@ -56,7 +58,7 @@ struct weighted_leaf_t { mtl::mat<2, 2> m_orientation; }; -struct group_t { +struct group_output_t { static constexpr size_t g_max_child_leafs = 16; static constexpr size_t g_max_child_markers = 8; @@ -64,6 +66,11 @@ struct group_t { etl::vector m_child_markers; }; +struct token_match_t { + etl::vector m_groups; + etl::vector m_wgroups; +}; + struct weighted_group_t { etl::vector m_groups; etl::vector m_weights; @@ -239,6 +246,38 @@ public: mark_rule_id_t add_mark_rule(token_id_t match, uint32_t tag); }; +class generator_t { + etl::vector m_weighted_groups; + etl::vector m_group_outputs; + etl::vector m_token_matches; + group_id_t m_axiom; + + uint32_t m_gen_num; + +public: + generator_t(const ruleset_t& ruleset); + + /** + * @brief Steps one generation, outputting generated markers + * + * @tparam CONTAINER_T Container type of @c marker_t that supplies an @c insert member + * function taking an iterator and value, @c size , and @c max_size functions + * + * @param out_markers Reference to a container to append generated markers to + * + * @ret false if there is not enough room for the child leafs (internally) + * or there is not enough room for the generated markers in @p out_markers, true otherwise + * + * Steps one generation of the fractal, and appends any child markers of + * the current generation to @p out_markers. If there is not enough room + * for all of the child markers, @p out_markers is unmodified. + */ + template + bool step_generation(CONTAINER_T& out_markers); + + uint32_t generation_num() const { return m_gen_num; } +}; + #if 0 class generator_t { private: diff --git a/src/main.cpp b/src/main.cpp index 96baa8f..a9f43cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,17 @@ int main(void) { return 0; } + generator_t gen(rules); + etl::vector output; + + while (gen.step_generation(output)) { + log::debug << "Stepped generation" << gen.generation_num() << endl; + + for (const marker_t& m : output) { + log::debug << ' ' << m.m_id << ", " << m.m_pos << endl; + } + } + while (true) { vid_vsync(); }