… | |
… | |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <random_map.h> |
25 | #include <random_map.h> |
26 | #include <rproto.h> |
26 | #include <rproto.h> |
27 | |
27 | |
|
|
28 | void |
28 | layout::layout (int w, int h) |
29 | layout::alloc (int w, int h) |
29 | : w(w), h(h) |
|
|
30 | { |
30 | { |
31 | assert (sizeof (cell) == 1); |
31 | assert (sizeof (cell) == 1); |
|
|
32 | |
|
|
33 | this->w = w; |
|
|
34 | this->h = h; |
32 | |
35 | |
33 | // we store the layout in a single contiguous memory layout |
36 | // we store the layout in a single contiguous memory layout |
34 | // first part consists of pointers to each column, followed |
37 | // first part consists of pointers to each column, followed |
35 | // by the actual columns (not rows!) |
38 | // by the actual columns (not rows!) |
36 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
39 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
… | |
… | |
39 | |
42 | |
40 | cell *p = (cell *)(data + w); |
43 | cell *p = (cell *)(data + w); |
41 | |
44 | |
42 | for (int x = w; x--; ) |
45 | for (int x = w; x--; ) |
43 | data [x] = p + x * h; |
46 | data [x] = p + x * h; |
|
|
47 | } |
|
|
48 | |
|
|
49 | layout::layout (int w, int h) |
|
|
50 | { |
|
|
51 | alloc (w, h); |
|
|
52 | } |
|
|
53 | |
|
|
54 | layout::layout (layout ©) |
|
|
55 | { |
|
|
56 | alloc (copy.w, copy.h); |
|
|
57 | |
|
|
58 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
44 | } |
59 | } |
45 | |
60 | |
46 | layout::~layout () |
61 | layout::~layout () |
47 | { |
62 | { |
48 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
63 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |