… | |
… | |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <rmg.h> |
25 | #include <rmg.h> |
26 | #include <rproto.h> |
26 | #include <rproto.h> |
27 | |
27 | |
28 | void noinline |
28 | ecb_noinline void |
29 | layout::alloc (int w, int h) |
29 | layout::alloc (int w, int h) |
30 | { |
30 | { |
31 | assert (sizeof (cell) == 1); |
31 | assert (sizeof (cell) == 1); |
32 | |
32 | |
33 | this->w = w; |
33 | this->w = w; |
… | |
… | |
74 | layout::~layout () |
74 | layout::~layout () |
75 | { |
75 | { |
76 | sfree ((char *)data, size); |
76 | sfree ((char *)data, size); |
77 | } |
77 | } |
78 | |
78 | |
79 | void noinline |
79 | ecb_noinline void |
80 | layout::fill (char fill) |
80 | layout::fill (char fill) |
81 | { |
81 | { |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
83 | fill_rect (0, 0, w, h, fill); |
83 | fill_rect (0, 0, w, h, fill); |
84 | } |
84 | } |
85 | |
85 | |
86 | void noinline |
86 | ecb_noinline void |
87 | layout::replace (char from, char to) |
87 | layout::replace (char from, char to) |
88 | { |
88 | { |
89 | for (int x = 0; x < w; ++x) |
89 | for (int x = 0; x < w; ++x) |
90 | for (int y = 0; y < h; ++y) |
90 | for (int y = 0; y < h; ++y) |
91 | if (data [x][y] == from) |
91 | if (data [x][y] == from) |
92 | data [x][y] = to; |
92 | data [x][y] = to; |
93 | } |
93 | } |
94 | |
94 | |
95 | void noinline |
95 | ecb_noinline void |
96 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
96 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
97 | { |
97 | { |
98 | --x2; |
98 | --x2; |
99 | |
99 | |
100 | memset (data [x1] + y1, fill, y2 - y1); |
100 | memset (data [x1] + y1, fill, y2 - y1); |
… | |
… | |
102 | |
102 | |
103 | while (++x1 < x2) |
103 | while (++x1 < x2) |
104 | data [x1][y1] = data [x1][y2 - 1] = fill; |
104 | data [x1][y1] = data [x1][y2 - 1] = fill; |
105 | } |
105 | } |
106 | |
106 | |
107 | void noinline |
107 | ecb_noinline void |
108 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
108 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
109 | { |
109 | { |
110 | for (; x1 < x2; ++x1) |
110 | for (; x1 < x2; ++x1) |
111 | memset (data [x1] + y1, fill, y2 - y1); |
111 | memset (data [x1] + y1, fill, y2 - y1); |
112 | } |
112 | } |
… | |
… | |
115 | layout::border (char fill) |
115 | layout::border (char fill) |
116 | { |
116 | { |
117 | rect (0, 0, w, h, fill); |
117 | rect (0, 0, w, h, fill); |
118 | } |
118 | } |
119 | |
119 | |
120 | void noinline |
120 | ecb_noinline void |
121 | layout::fill_rand (int percent) |
121 | layout::fill_rand (int percent) |
122 | { |
122 | { |
123 | percent = lerp (percent, 0, 100, 0, 256); |
123 | percent = lerp (percent, 0, 100, 0, 256); |
124 | |
124 | |
125 | for (int x = 0; x < w; ++x) |
125 | for (int x = 0; x < w; ++x) |
… | |
… | |
128 | } |
128 | } |
129 | |
129 | |
130 | ///////////////////////////////////////////////////////////////////////////// |
130 | ///////////////////////////////////////////////////////////////////////////// |
131 | |
131 | |
132 | // erode by cellular automata |
132 | // erode by cellular automata |
133 | void noinline |
133 | ecb_noinline void |
134 | layout::erode_1_2 (int c1, int c2, int repeat) |
134 | layout::erode_1_2 (int c1, int c2, int repeat) |
135 | { |
135 | { |
136 | layout neu (w, h); |
136 | layout neu (w, h); |
137 | |
137 | |
138 | while (repeat--) |
138 | while (repeat--) |
… | |
… | |
204 | ///////////////////////////////////////////////////////////////////////////// |
204 | ///////////////////////////////////////////////////////////////////////////// |
205 | // isolation remover - ensures single connected area |
205 | // isolation remover - ensures single connected area |
206 | |
206 | |
207 | typedef fixed_stack<point> pointlist; |
207 | typedef fixed_stack<point> pointlist; |
208 | |
208 | |
209 | static void noinline |
209 | ecb_noinline static void |
210 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
210 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
211 | { |
211 | { |
212 | if (dist [x][y]) |
212 | if (dist [x][y]) |
213 | return; |
213 | return; |
214 | |
214 | |
… | |
… | |
275 | seeds.push (point (x, y)); |
275 | seeds.push (point (x, y)); |
276 | } |
276 | } |
277 | |
277 | |
278 | // isolation remover, works on a "distance" map |
278 | // isolation remover, works on a "distance" map |
279 | // the map must be initialised with 0 == rooms, 255 = walls |
279 | // the map must be initialised with 0 == rooms, 255 = walls |
280 | static void noinline |
280 | ecb_noinline static void |
281 | isolation_remover (layout &dist, unsigned int perturb = 2) |
281 | isolation_remover (layout &dist, unsigned int perturb = 2) |
282 | { |
282 | { |
283 | // dist contains |
283 | // dist contains |
284 | // 0 == invisited rooms |
284 | // 0 == invisited rooms |
285 | // 1 == visited rooms |
285 | // 1 == visited rooms |
… | |
… | |
533 | * 1 match on (i+1, j) |
533 | * 1 match on (i+1, j) |
534 | * 2 match on (i, j+1) |
534 | * 2 match on (i, j+1) |
535 | * 4 match on (i+1, j+1) |
535 | * 4 match on (i+1, j+1) |
536 | * and the possible combinations thereof. |
536 | * and the possible combinations thereof. |
537 | */ |
537 | */ |
538 | static int noinline |
538 | ecb_noinline static int |
539 | calc_pattern (char ch, layout &maze, int i, int j) |
539 | calc_pattern (char ch, layout &maze, int i, int j) |
540 | { |
540 | { |
541 | int pattern = 0; |
541 | int pattern = 0; |
542 | |
542 | |
543 | if (i + 1 < maze.w && maze[i + 1][j] == ch) |
543 | if (i + 1 < maze.w && maze[i + 1][j] == ch) |