Add beginning of generator declarations and example usage

This commit is contained in:
Maddie Busig 2025-05-06 02:53:31 -07:00
parent 7d660e215d
commit 651596f76f
2 changed files with 51 additions and 1 deletions

View File

@ -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_mark_rules = 4;
constexpr size_t g_max_cgroup_tokens = 16; constexpr size_t g_max_cgroup_tokens = 16;
constexpr size_t g_max_wgroup_weights = 8; 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 token_id_t = uint32_t;
using group_id_t = uint32_t; using group_id_t = uint32_t;
@ -56,7 +58,7 @@ struct weighted_leaf_t {
mtl::mat<2, 2> m_orientation; 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_leafs = 16;
static constexpr size_t g_max_child_markers = 8; static constexpr size_t g_max_child_markers = 8;
@ -64,6 +66,11 @@ struct group_t {
etl::vector<marker_t, g_max_child_markers> m_child_markers; etl::vector<marker_t, g_max_child_markers> m_child_markers;
}; };
struct token_match_t {
etl::vector<group_id_t, g_max_match_groups> m_groups;
etl::vector<weighted_group_id_t, g_max_match_wgroups> m_wgroups;
};
struct weighted_group_t { struct weighted_group_t {
etl::vector<group_id_t, g_max_wgroup_weights> m_groups; etl::vector<group_id_t, g_max_wgroup_weights> m_groups;
etl::vector<uint32_t, g_max_wgroup_weights> m_weights; etl::vector<uint32_t, g_max_wgroup_weights> m_weights;
@ -239,6 +246,38 @@ public:
mark_rule_id_t add_mark_rule(token_id_t match, uint32_t tag); mark_rule_id_t add_mark_rule(token_id_t match, uint32_t tag);
}; };
class generator_t {
etl::vector<weighted_group_t, g_max_wgroups> m_weighted_groups;
etl::vector<group_output_t, g_max_groups> m_group_outputs;
etl::vector<token_match_t, g_max_tokens> 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 <typename CONTAINER_T>
bool step_generation(CONTAINER_T& out_markers);
uint32_t generation_num() const { return m_gen_num; }
};
#if 0 #if 0
class generator_t { class generator_t {
private: private:

View File

@ -58,6 +58,17 @@ int main(void) {
return 0; return 0;
} }
generator_t gen(rules);
etl::vector<marker_t, 100> 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) { while (true) {
vid_vsync(); vid_vsync();
} }