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.13 by root, Sat Jul 3 01:52:52 2010 UTC vs.
Revision 1.14 by root, Sat Jul 3 02:19:10 2010 UTC

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
49layout::layout (int w, int h) 48layout::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
60layout::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
61layout::~layout () 74layout::~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
68void 79void
69layout::fill (char fill) 80layout::fill (char fill)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines