… | |
… | |
34 | this->h = h; |
34 | this->h = h; |
35 | |
35 | |
36 | // we store the layout in a single contiguous memory layout |
36 | // we store the layout in a single contiguous memory layout |
37 | // first part consists of pointers to each column, followed |
37 | // first part consists of pointers to each column, followed |
38 | // by the actual columns (not rows!) |
38 | // by the actual columns (not rows!) |
39 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
39 | size = (sizeof (cell *) + sizeof (cell) * h) * w; |
40 | |
|
|
41 | data = (cell **)salloc<char> (size); |
40 | data = (cell **)salloc<char> (size); |
42 | |
41 | |
43 | cell *p = (cell *)(data + w); |
42 | cell *p = (cell *)(data + w); |
44 | |
43 | |
45 | for (int x = w; x--; ) |
44 | for (int x = 0; x < w; ++x) |
46 | data [x] = p + x * h; |
45 | data [x] = p + x * h; |
47 | } |
46 | } |
48 | |
47 | |
49 | layout::layout (int w, int h) |
48 | layout::layout (int w, int h) |
50 | { |
49 | { |
… | |
… | |
56 | alloc (copy.w, copy.h); |
55 | alloc (copy.w, copy.h); |
57 | |
56 | |
58 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
57 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
59 | } |
58 | } |
60 | |
59 | |
|
|
60 | layout::layout (layout &orig, int x1, int y1, int x2, int y2) |
|
|
61 | { |
|
|
62 | w = x2 - x1; |
|
|
63 | h = y2 - y1; |
|
|
64 | |
|
|
65 | // we only allocate space for the pointers |
|
|
66 | size = sizeof (cell *) * w; |
|
|
67 | data = (cell **)salloc<char> (size); |
|
|
68 | |
|
|
69 | // and now we point back into the original layout |
|
|
70 | for (int x = 0; x < w; ++x) |
|
|
71 | data [x] = orig.data [x + x1] + y1; |
|
|
72 | } |
|
|
73 | |
61 | layout::~layout () |
74 | layout::~layout () |
62 | { |
75 | { |
63 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
|
|
64 | |
|
|
65 | sfree ((char *)data, size); |
76 | sfree ((char *)data, size); |
66 | } |
77 | } |
67 | |
78 | |
68 | void |
79 | void |
69 | layout::fill (char fill) |
80 | layout::fill (char fill) |