ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/layout.C
(Generate patch)

Comparing deliantra/server/random_maps/layout.C (file contents):
Revision 1.32 by root, Sun Jan 29 02:47:05 2017 UTC vs.
Revision 1.33 by root, Sat Nov 17 23:33:18 2018 UTC

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
28void noinline 28ecb_noinline void
29layout::alloc (int w, int h) 29layout::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;
74layout::~layout () 74layout::~layout ()
75{ 75{
76 sfree ((char *)data, size); 76 sfree ((char *)data, size);
77} 77}
78 78
79void noinline 79ecb_noinline void
80layout::fill (char fill) 80layout::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
86void noinline 86ecb_noinline void
87layout::replace (char from, char to) 87layout::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
95void noinline 95ecb_noinline void
96layout::rect (int x1, int y1, int x2, int y2, char fill) 96layout::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
107void noinline 107ecb_noinline void
108layout::fill_rect (int x1, int y1, int x2, int y2, char fill) 108layout::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}
115layout::border (char fill) 115layout::border (char fill)
116{ 116{
117 rect (0, 0, w, h, fill); 117 rect (0, 0, w, h, fill);
118} 118}
119 119
120void noinline 120ecb_noinline void
121layout::fill_rand (int percent) 121layout::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
133void noinline 133ecb_noinline void
134layout::erode_1_2 (int c1, int c2, int repeat) 134layout::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
207typedef fixed_stack<point> pointlist; 207typedef fixed_stack<point> pointlist;
208 208
209static void noinline 209ecb_noinline static void
210push_flood_fill (layout &dist, pointlist &seeds, int x, int y) 210push_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
280static void noinline 280ecb_noinline static void
281isolation_remover (layout &dist, unsigned int perturb = 2) 281isolation_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 */
538static int noinline 538ecb_noinline static int
539calc_pattern (char ch, layout &maze, int i, int j) 539calc_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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines