Euphoria
generator_cell.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "base/lrud.h"
4 #include "core/table_bool.h"
5 
6 
7 
8 namespace eu
9 {
10  struct Random;
11 }
12 
13 namespace eu::core::generator
14 {
15  using World = BoolTable;
16 
17  // make generation better
18  // http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels
19 
20  struct CellularAutomata;
21 
22  struct Rule
23  {
24  Rule() = default;
25  virtual ~Rule() = default;
26 
27  Rule(const Rule&) = delete;
28  Rule(Rule&&) = delete;
29  void operator=(const Rule&) = delete;
30  void operator=(Rule&&) = delete;
31 
32  virtual void update(CellularAutomata* self) = 0;
33  };
34 
35 
36  struct Rules
37  {
38  std::vector<std::shared_ptr<Rule>> rules;
39 
40  void add_rule(int count, std::shared_ptr<Rule> rule);
41  };
42 
44  {
48  int iteration;
49 
51 
52  void update();
53 
54  [[nodiscard]] bool is_done() const;
55  };
56 
57  using ChangeFunction = std::function
58  <
59  std::optional<bool>
60  (bool, const WallCounter&)
61  >;
62 
63  // todo(Gustav): rename rules to make it clearer what they do
64 
66  void
68  (
69  Rules* cell,
70  Random* random,
71  float random_fill = 0.5,
73  {
75  }
76  );
77 
79  void
81  (
82  Rules* ca,
83  int times,
84  int count,
85  int range,
86  bool include_self,
87  NeighborhoodAlgorithm algorithm
88  );
89 
90  void
92  (
93  Rules* ca,
94  int times,
95  ChangeFunction change
96  );
97 
99  void
101  (
102  Rules* ca,
103  int times,
104  int count,
105  bool include_self,
106  NeighborhoodAlgorithm algorithm
107  );
108 
110  void
112  (
113  Rules* ca,
114  int y,
115  int height
116  );
117 
119  void
121  (
122  Rules* ca,
123  int times,
124  int count,
125  bool include_self,
126  NeighborhoodAlgorithm algorithm
127  );
128 
130  void
132  (
133  Rules* ca,
134  int times,
135  int count,
136  int big_count,
137  bool include_self,
138  NeighborhoodAlgorithm algorithm
139  );
140 
142  void
143  add_fill_small_holes_rule(Rules* rules, bool allow_diagonals, int min_count);
144 
146  void
147  add_fill_all_holes_rule(Rules* rules, bool allow_diagonals, int holes_to_keep);
148 }
void add_spiky_rules(Rules *ca, int times, int count, bool include_self, NeighborhoodAlgorithm algorithm)
simple smoothing, but always set the cell, seems to provide spikes
void add_combo_rules(Rules *ca, int times, int count, int big_count, bool include_self, NeighborhoodAlgorithm algorithm)
smooth but 'big_count' is applied for R(2)
void add_random_fill(Rules *cell, Random *random, float random_fill, Lrud< BorderSetupRule > border_control)
fills the world with random data
void add_fill_small_holes_rule(Rules *rules, bool allow_diagonals, int min_count)
fills all open areas that are less than 'min_count'
void add_fill_all_holes_rule(Rules *rules, bool allow_diagonals, int holes_to_keep)
fills all open areas, but keeps 'holes_to_keep'
void add_clear_rules(Rules *ca, int times, int count, int range, bool include_self, NeighborhoodAlgorithm algorithm)
'clears' cells with less than 'count' neighbours, good for removing 'blobs'
void add_simple_rules(Rules *ca, int times, int count, bool include_self, NeighborhoodAlgorithm algorithm)
simple smoothing, less than count neighbours are removed, more -> solid
void add_complex_rules(Rules *ca, int times, ChangeFunction change)
void add_horizontal_blank_rule(Rules *ca, int y, int height)
blanks out cells at 'y' and 'height' down
std::function< std::optional< bool >(bool, const WallCounter &) > ChangeFunction
NeighborhoodAlgorithm
Definition: table_bool.h:85
Table< bool > BoolTable
Definition: table_bool.h:15
Definition: assert.h:90
WEL512 Random Number Generator.
Definition: random.h:21
Lrud< core::OutsideRule > outside_rule
CellularAutomata(generator::Rules *r, generator::World *w, const Lrud< core::OutsideRule > &fw)
virtual ~Rule()=default
void operator=(const Rule &)=delete
void operator=(Rule &&)=delete
virtual void update(CellularAutomata *self)=0
Rule(const Rule &)=delete
std::vector< std::shared_ptr< Rule > > rules
void add_rule(int count, std::shared_ptr< Rule > rule)