37 * "real" units. The idea is that this class is used with "real" units |
37 * "real" units. The idea is that this class is used with "real" units |
38 * and it uses pixelcoordinates internally. |
38 * and it uses pixelcoordinates internally. |
39 */ |
39 */ |
40 class Terrain { |
40 class Terrain { |
41 protected: |
41 protected: |
42 /** The terrain data is stored as a linear array in row-major order, with width*height elements */ |
42 /** The terrain data is stored as a linear array in row-major order, with width * height elements */ |
43 TerrainPixel *terrain_buf; |
43 TerrainPixel *terrain_buf; |
44 |
44 |
45 /** Terrain dimensions */ |
45 /** Terrain dimensions */ |
46 PixelDimension width, height; |
46 PixelDimension width, height; |
47 |
47 |
49 CL_PixelBuffer pixbuf; |
49 CL_PixelBuffer pixbuf; |
50 |
50 |
51 // XXX: terrain texture |
51 // XXX: terrain texture |
52 std::vector<std::vector<int> > texture; |
52 std::vector<std::vector<int> > texture; |
53 |
53 |
|
54 public: |
54 /** |
55 /** |
55 * Default constructor. The width/height are set to zero and the terrain is invalid until it gets updated |
56 * Default constructor. The width/height are set to zero and the terrain is invalid until it gets updated |
56 */ |
57 */ |
57 Terrain (void); |
58 Terrain (void); |
58 |
59 |
59 /** |
60 /** |
60 * Constructor. |
61 * Construct a randomly generated terrain |
61 * |
62 * |
62 * @param width terrain width |
63 * @param width terrain width |
63 * @param height terrain height |
64 * @param height terrain height |
64 * @param seed andom number generator seed used to generate the random terrain. |
65 * @param seed random number generator seed used to generate the random terrain. |
65 */ |
66 */ |
66 Terrain (PixelDimension width, PixelDimension height, int seed); |
67 Terrain (PixelDimension width, PixelDimension height, int seed); |
67 |
68 |
68 /** |
69 /** |
69 * Destructor |
70 * Construct the terrain using the provided terrain data. The given \a terrain_buf must be a linear array in the |
|
71 * same format as Terrain::terrain_buf, meaning a row-major order array with width * height elements. The buffer |
|
72 * must be allocated on the heap using 'new []', and ownership will be transferred (i.e. the buffer is not copied, |
|
73 * and will eventually be delete []'d). |
|
74 * |
|
75 * @param width terrain width |
|
76 * @param height terrain height |
|
77 * @param terrain_buf dynamically allocated width * height array of terrain data |
|
78 */ |
|
79 Terrain (PixelDimension width, PixelDimension height, TerrainPixel *terrain_buf); |
|
80 |
|
81 /** |
|
82 * Destructor, frees our terrain buffer |
70 */ |
83 */ |
71 ~Terrain (void); |
84 ~Terrain (void); |
72 |
85 |
73 private: |
86 private: |
74 /* No copying */ |
87 /* No copying */ |
133 } |
146 } |
134 |
147 |
135 /** |
148 /** |
136 * Return the terrain dimensions à la a PixelCoordinate |
149 * Return the terrain dimensions à la a PixelCoordinate |
137 */ |
150 */ |
138 inline PixelCoordinate getDimensions (void) const { |
151 PixelCoordinate getDimensions (void) const { |
139 return PixelCoordinate(width, height); |
152 return PixelCoordinate(width, height); |
|
153 } |
|
154 |
|
155 /** |
|
156 * Return dimensions in component form |
|
157 */ |
|
158 PixelDimension getWidth (void) const { |
|
159 return width; |
|
160 } |
|
161 |
|
162 PixelDimension getHeight (void) const { |
|
163 return height; |
140 } |
164 } |
141 |
165 |
142 /** |
166 /** |
143 * Return the type of terrain at given position. Returns TERRAIN_ROCK if given point is not inside terrain area. |
167 * Return the type of terrain at given position. Returns TERRAIN_ROCK if given point is not inside terrain area. |
144 * |
168 * |