Remove old disabled implementation
This commit is contained in:
parent
1cd528e7ef
commit
f7869150bb
@ -288,223 +288,6 @@ public:
|
|||||||
uint32_t generation_num() const { return m_gen_num; }
|
uint32_t generation_num() const { return m_gen_num; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
class generator_t {
|
|
||||||
private:
|
|
||||||
static constexpr size_t g_max_groups = 32;
|
|
||||||
static constexpr size_t g_max_weighted_groups = 32;
|
|
||||||
static constexpr size_t g_max_tokens = 32;
|
|
||||||
static constexpr size_t g_max_leafs_per_gen = 1024; // Maximum leafs per generation
|
|
||||||
static constexpr size_t g_max_rules_basic = 16;
|
|
||||||
static constexpr size_t g_max_rules_marking = 4;
|
|
||||||
|
|
||||||
// We are creating two buffers are leafs. One for the current generation
|
|
||||||
// and one for the next generation. These will be accessed through current/next
|
|
||||||
// ivectors that will point to different buffers as they are swapped.
|
|
||||||
etl::vector<leaf_t, g_max_leafs_per_gen> m_leaf_buf1;
|
|
||||||
etl::vector<leaf_t, g_max_leafs_per_gen> m_leaf_buf2;
|
|
||||||
|
|
||||||
etl::vector<token_t, g_max_tokens> m_tokens;
|
|
||||||
|
|
||||||
etl::vector<group_characteristic_t, g_max_groups> m_group_characteristics;
|
|
||||||
etl::vector<group_t, g_max_groups> m_groups;
|
|
||||||
etl::vector<weighted_group_t, g_max_weighted_groups> m_weighted_groups;
|
|
||||||
|
|
||||||
etl::vector<branch_rule_basic_t, g_max_rules_basic> m_basic_branch_rules;
|
|
||||||
etl::vector<branch_rule_marking_t, g_max_rules_marking> m_marking_branch_rules;
|
|
||||||
|
|
||||||
etl::ivector<leaf_t>* m_leafs_cur;
|
|
||||||
etl::ivector<leaf_t>* m_leafs_next;
|
|
||||||
|
|
||||||
bool m_processed;
|
|
||||||
uint32_t m_generation;
|
|
||||||
|
|
||||||
mtl::fixed m_scale_factor;
|
|
||||||
|
|
||||||
weighted_group_id_t m_axiom;
|
|
||||||
mtl::vec2 m_init_position;
|
|
||||||
mtl::fixed m_init_orientation;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
generator_t() noexcept :
|
|
||||||
m_leafs_cur(&m_leaf_buf1),
|
|
||||||
m_leafs_next(&m_leaf_buf2),
|
|
||||||
m_axiom(0),
|
|
||||||
m_generation(0),
|
|
||||||
m_scale_factor(1),
|
|
||||||
m_processed(false) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add new token variable that can be used in this generator's group characteristics.
|
|
||||||
*
|
|
||||||
* @param type Type of the token to add
|
|
||||||
* @param value Value of the token. Unused if @p type is @c token_type_e::generate. Defaults to 0
|
|
||||||
*
|
|
||||||
* @ret @c token_id_t of the newly added token, local to this generator.
|
|
||||||
*
|
|
||||||
* @pre preprocess() has not been called on this generator.
|
|
||||||
*
|
|
||||||
* @exception mtl::system_error If the generator has already been preprocessed.
|
|
||||||
* @exception mtl::invalid_argument If the given token type is invalid.
|
|
||||||
* @exception mtl::length_error If the maximum number of tokens is reached.
|
|
||||||
*/
|
|
||||||
token_id_t add_token(token_type_e type, mtl::fixed value = 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add new group charateristic.
|
|
||||||
*
|
|
||||||
* After all tokens, groups, and rules have been added, the generator's groups
|
|
||||||
* must be processed by calling preprocess(). Once this is done, no new
|
|
||||||
* groups may be added. If an exception occurs, no data is modified.
|
|
||||||
*
|
|
||||||
* @param factor The number of times the group is repeated. Treats the group as if @p tokens was repeated @p factor number of times.
|
|
||||||
* @param tokens @c etl::ivector of @token_id_t that describe how the group functions. Processed in order, front to back.
|
|
||||||
*
|
|
||||||
* @ret @c group_id_t of the newly added group, local to this generator.
|
|
||||||
*
|
|
||||||
* @pre preprocess() has not been called on this generator.
|
|
||||||
*
|
|
||||||
* @exception mtl::system_error If the generator has already been preprocessed.
|
|
||||||
* @exception mtl::invalid_argument If an invalid token was encountered.
|
|
||||||
* @exception mtl::length_error If the maximum number of groups is reached.
|
|
||||||
*/
|
|
||||||
group_id_t add_group_characteristic(uint32_t factor, const etl::ivector<token_id_t>& tokens);
|
|
||||||
/**
|
|
||||||
* @overload
|
|
||||||
*
|
|
||||||
* Convience overload, defaulting to a group with factor 1.
|
|
||||||
*/
|
|
||||||
group_id_t add_group_characteristic(const etl::ivector<token_id_t>& tokens);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add a weighted group to the generator.
|
|
||||||
*
|
|
||||||
* Adds weighted group of groups, where each subgroup has a
|
|
||||||
* <tt>(weight) / (total weight)</tt> chance of being selected. Weights
|
|
||||||
* are represented as @c uint32_t. If an exception occurs, no data is modified.
|
|
||||||
*
|
|
||||||
* @param weights @c etl::ivector of @c etl::pair s of @c group_id_it and their corresponding weights.
|
|
||||||
*
|
|
||||||
* @ret @c weighted_group_id_t of the newly added group, local to this generator.
|
|
||||||
*
|
|
||||||
* @pre preprocess() has not been called on this generator.
|
|
||||||
*
|
|
||||||
* @exception mtl::invalid_argument If no groups were supplied, or an invalid group was encountered.
|
|
||||||
* @exception mtl::system_error If the generator has already been preprocessed.
|
|
||||||
* @exception mtl::length_error If the maximum number of weighted groups is reached.
|
|
||||||
*/
|
|
||||||
weighted_group_id_t add_weighted_group(const etl::ivector<etl::pair<group_id_t, uint32_t>>& group_weights);
|
|
||||||
/**
|
|
||||||
* @overload
|
|
||||||
*
|
|
||||||
* Convenience overload. Creates a weighted group for a group with only
|
|
||||||
* one possibility.
|
|
||||||
*/
|
|
||||||
weighted_group_id_t add_weighted_group(group_id_t group);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add a basic (non-marking) branch rule to the generator.
|
|
||||||
*
|
|
||||||
* Basic branch rules describe how this generator will create new leafs
|
|
||||||
* each generation.
|
|
||||||
*
|
|
||||||
* @param match Token to match and generate the group in place of.
|
|
||||||
* @param wgroup Weighted group to generate. Only one subgroup will be selected to generate.
|
|
||||||
*
|
|
||||||
* @ret @c branch_rule_basic_id_t of the newly added branch rule, local to this generator.
|
|
||||||
*
|
|
||||||
* @pre preprocess() has not been called on this generator.
|
|
||||||
*
|
|
||||||
* @exception mtl::invalid_argument If no groups were supplied, or an invalid group was encountered.
|
|
||||||
* @exception mtl::system_error If the generator has already been preprocessed.
|
|
||||||
* @exception mtl::length_error If the maximum number of basic branch rules is reached.
|
|
||||||
*/
|
|
||||||
branch_rule_basic_id_t add_basic_branch_rule(token_id_t match, weighted_group_id_t wgroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Add a marking branch rule to the generator.
|
|
||||||
*
|
|
||||||
* Marking branch rules describe what points (markers) this generator
|
|
||||||
* will output to the caller each generator.
|
|
||||||
*
|
|
||||||
* @param match Token to match and mark.
|
|
||||||
* @param marker_id ID to mark the point with.
|
|
||||||
*
|
|
||||||
* @ret @c branch_rule_marking_id_t of the newly added branch rule, local to this generator.
|
|
||||||
*
|
|
||||||
* @pre preprocess() has not been called on this generator.
|
|
||||||
*
|
|
||||||
* @exception mtl::invalid_argument If an invalid token was supplied.
|
|
||||||
* @exception mtl::system_error If the generator has already been preprocessed.
|
|
||||||
* @exception mtl::length_error If the maximum number of marking branch rules is reached.
|
|
||||||
*/
|
|
||||||
branch_rule_marking_id_t add_marking_branch_rule(token_id_t match, uint32_t marker_id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the axiom used in this generator.
|
|
||||||
*
|
|
||||||
* The "axiom" is used to generate the very first generation of leafs.
|
|
||||||
* Only one subgroup from the weighted group is selected.
|
|
||||||
*
|
|
||||||
* @exception mtl::invalid If an invalid weighted group ID was suppied.
|
|
||||||
*/
|
|
||||||
void set_axiom(weighted_group_id_t wgroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Perform preprocessing on the supplied group characteristics.
|
|
||||||
*
|
|
||||||
* Transforms each group, producing a list of child leafs and markers
|
|
||||||
* that should be generated for each group characteristic. Has no effect
|
|
||||||
* if called more than once.
|
|
||||||
*
|
|
||||||
* @pre All tokens, groups characteristics, weighted groups, and branch
|
|
||||||
* rules have been added.
|
|
||||||
*
|
|
||||||
* @exception mtl::length_error If the number of resulting child leafs
|
|
||||||
* or markers exceeds the maximum allowed for one group.
|
|
||||||
*/
|
|
||||||
void preprocess();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the scale factor used each generation.
|
|
||||||
*
|
|
||||||
* Each time the generation is stepped, the length of each walk is scaled
|
|
||||||
* by @p scale_factor. Can be set to a new value at any time.
|
|
||||||
*
|
|
||||||
* @param scale_factor The new scale factor to use
|
|
||||||
*/
|
|
||||||
void set_scale_factor(mtl::fixed scale_factor) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set the initial position the axiom is generated in.
|
|
||||||
*
|
|
||||||
* @param position The initial position to use.
|
|
||||||
*/
|
|
||||||
void set_initial_position(mtl::vec2 position) noexcept;
|
|
||||||
/**
|
|
||||||
* @brief Set the initial orientation the axiom is generated in.
|
|
||||||
*
|
|
||||||
* @param orientation The initial orientation to use. Given in radians.
|
|
||||||
*/
|
|
||||||
void set_initial_orientation(mtl::fixed orientation) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Steps one generation in the fractal, generating a vector of markers.
|
|
||||||
*
|
|
||||||
* The vector of markers will NOT be cleared at the beginning of generation.
|
|
||||||
*
|
|
||||||
* @param out_markers An @c etl::ivector of @c marker_t. Each marker
|
|
||||||
* encountered will be appended to this list in the order encountered.
|
|
||||||
*
|
|
||||||
* @ret true if the maximum number of markers was reached, otherwise false.
|
|
||||||
*/
|
|
||||||
bool step_generation(const etl::ivector<marker_t>& out_markers) noexcept;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename CONTGROUP_T, typename CONTWGROUP_T>
|
template <typename CONTGROUP_T, typename CONTWGROUP_T>
|
||||||
void ruleset_t::find_token_matches(token_id_t token, CONTGROUP_T& out_groups, CONTWGROUP_T& out_wgroups) const {
|
void ruleset_t::find_token_matches(token_id_t token, CONTGROUP_T& out_groups, CONTWGROUP_T& out_wgroups) const {
|
||||||
for (auto rule : m_branch_rules) {
|
for (auto rule : m_branch_rules) {
|
||||||
|
|||||||
194
src/fractal.cpp
194
src/fractal.cpp
@ -206,199 +206,5 @@ void generator_t::parse_group_characteristic(group_id_t id, group_output_t& outp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) {
|
|
||||||
log::debug << "Adding token with type " << (int)type << endl;
|
|
||||||
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add token, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_tokens.full()) {
|
|
||||||
log::error << "Failed to add token, tokens full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case token_type_e::walk:
|
|
||||||
case token_type_e::rotate:
|
|
||||||
case token_type_e::generate:
|
|
||||||
m_tokens.push_back(token_t{type, value});
|
|
||||||
return m_tokens.size() - 1; // IDs are simply index into vector
|
|
||||||
default:
|
|
||||||
log::error << "Failed to add token, invalid token type" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
group_id_t generator_t::add_group_characteristic(uint32_t factor, const etl::ivector<token_id_t>& tokens) {
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add characteristic, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_group_characteristics.full()) {
|
|
||||||
log::error << "Failed to add characteristic, vector full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to look for invalid tokens AOT, because we only modify the
|
|
||||||
// generator if the supplied data is valid.
|
|
||||||
size_t num_tokens = m_tokens.size();
|
|
||||||
for (token_id_t token : tokens) {
|
|
||||||
if (token >= num_tokens) {
|
|
||||||
log::error << "Failed to add characteristic, invalid token found: " << token << " >= " << num_tokens << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_group_characteristics.push_back(group_characteristic_t());
|
|
||||||
|
|
||||||
group_characteristic_t& characteristic = m_group_characteristics.back();
|
|
||||||
characteristic.m_factor = factor;
|
|
||||||
characteristic.m_token_ids.assign(tokens.begin(), tokens.end());
|
|
||||||
|
|
||||||
return m_group_characteristics.size() - 1; // IDs are just the index into vector
|
|
||||||
}
|
|
||||||
|
|
||||||
group_id_t generator_t::add_group_characteristic(const etl::ivector<token_id_t>& tokens) {
|
|
||||||
return add_group_characteristic(1, tokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
weighted_group_id_t generator_t::add_weighted_group(const etl::ivector<etl::pair<group_id_t, uint32_t>>& group_weights) {
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add weighted group, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_weighted_groups.full()) {
|
|
||||||
log::error << "Failed to add weighted group, vector full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t num_groups = m_group_characteristics.size();
|
|
||||||
for (etl::pair<group_id_t, uint32_t> pair : group_weights) {
|
|
||||||
if (pair.first >= num_groups) {
|
|
||||||
log::error << "Failed to add weighted group, invalid group found: " << pair.first << " >= " << num_groups << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_weighted_groups.push_back(weighted_group_t());
|
|
||||||
|
|
||||||
weighted_group_t& wgroup = m_weighted_groups.back();
|
|
||||||
|
|
||||||
uint32_t weight_total = 0;
|
|
||||||
|
|
||||||
for (etl::pair<group_id_t, uint32_t> pair : group_weights) {
|
|
||||||
wgroup.m_groups.push_back(pair.first);
|
|
||||||
wgroup.m_weights.push_back(pair.second);
|
|
||||||
wgroup.m_weight_total += pair.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
wgroup.m_weight_total = weight_total;
|
|
||||||
|
|
||||||
return m_weighted_groups.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
weighted_group_id_t generator_t::add_weighted_group(group_id_t group) {
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add weighted group, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_weighted_groups.full()) {
|
|
||||||
log::error << "Failed to add weighted group, vector full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group >= m_group_characteristics.size()) {
|
|
||||||
log::error << "Failed to add weighted group, invalid group encountered" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_weighted_groups.push_back(weighted_group_t());
|
|
||||||
|
|
||||||
weighted_group_t& wgroup = m_weighted_groups.back();
|
|
||||||
wgroup.m_groups.push_back(group);
|
|
||||||
wgroup.m_weights.push_back(1); // We still need to supply a weight
|
|
||||||
wgroup.m_weight_total = 1;
|
|
||||||
|
|
||||||
return m_weighted_groups.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
branch_rule_basic_id_t generator_t::add_basic_branch_rule(token_id_t match, weighted_group_id_t wgroup) {
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add basic branch rule, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_basic_branch_rules.full()) {
|
|
||||||
log::error << "Failed to add basic branch rule, vector full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match >= m_tokens.size()) {
|
|
||||||
log::error << "Failed to add basic branch rule, invalid match token" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wgroup >= m_weighted_groups.size()) {
|
|
||||||
log::error << "Failed to add basic branch rule, invalid weighted group" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_basic_branch_rules.push_back(branch_rule_basic_t{match, wgroup});
|
|
||||||
|
|
||||||
return m_basic_branch_rules.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
branch_rule_marking_id_t generator_t::add_marking_branch_rule(token_id_t match, uint32_t marker_id) {
|
|
||||||
if (m_processed) {
|
|
||||||
log::error << "Failed to add marking branch rule, already preprocessed" << endl;
|
|
||||||
throw mtl::system_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_basic_branch_rules.full()) {
|
|
||||||
log::error << "Failed to add marking branch rule, vector full" << endl;
|
|
||||||
throw mtl::length_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match >= m_tokens.size()) {
|
|
||||||
log::error << "Failed to add marking branch rule, invalid match token" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_marking_branch_rules.push_back(branch_rule_marking_t{match, marker_id});
|
|
||||||
|
|
||||||
return m_marking_branch_rules.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void generator_t::set_axiom(weighted_group_id_t wgroup) {
|
|
||||||
if (wgroup >= m_weighted_groups.size()) {
|
|
||||||
log::error << "Failed to set axiom, invalid weighted group" << endl;
|
|
||||||
throw mtl::invalid_argument();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_axiom = wgroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
void generator_t::preprocess() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void generator_t::set_scale_factor(mtl::fixed scale_factor) noexcept {
|
|
||||||
}
|
|
||||||
|
|
||||||
void generator_t::set_initial_position(mtl::vec2 position) noexcept {
|
|
||||||
}
|
|
||||||
|
|
||||||
void generator_t::set_initial_orientation(mtl::fixed orientation) noexcept {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool generator_t::step_generation(const etl::ivector<marker_t>& out_markers) noexcept {
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace fractal
|
} // namespace fractal
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user