equal
deleted
inserted
replaced
2 #define TERRAIN_HH |
2 #define TERRAIN_HH |
3 |
3 |
4 #include "Vector.hh" |
4 #include "Vector.hh" |
5 #include "Types.hh" |
5 #include "Types.hh" |
6 #include "Config.hh" |
6 #include "Config.hh" |
|
7 #include "Configuration.hh" |
7 |
8 |
8 #include "Graphics/Drawable.hh" |
9 #include "Graphics/Drawable.hh" |
|
10 |
|
11 #include <vector> |
9 |
12 |
10 /** |
13 /** |
11 * Different types of terrain available |
14 * Different types of terrain available |
12 */ |
15 */ |
13 enum TerrainType { |
16 enum TerrainType { |
18 TERRAIN_DIRT = 0x01, |
21 TERRAIN_DIRT = 0x01, |
19 |
22 |
20 /** Indestructible rock */ |
23 /** Indestructible rock */ |
21 TERRAIN_ROCK = 0x02 |
24 TERRAIN_ROCK = 0x02 |
22 }; |
25 }; |
23 |
|
24 /** |
|
25 * Terrain "pixel" type |
|
26 */ |
|
27 typedef uint8_t TerrainPixel; |
|
28 |
|
29 /** |
|
30 * Terrain configuration |
|
31 */ |
|
32 struct TerrainConfig { |
|
33 /** Size of the terrain field*/ |
|
34 PixelDimensions dimensions; |
|
35 |
|
36 /** Set to nonzero to generate random map */ |
|
37 int random_seed; |
|
38 |
|
39 /** Defaults */ |
|
40 TerrainConfig (void) : dimensions(TERRAIN_WIDTH, TERRAIN_HEIGHT), random_seed(TERRAIN_RANDOM_SEED) { } |
|
41 }; |
|
42 |
|
43 #include <vector> |
|
44 |
26 |
45 /** |
27 /** |
46 * Terrain class. Represents game terrain and contains member |
28 * Terrain class. Represents game terrain and contains member |
47 * functions to manipulate terrain and get info about it. |
29 * functions to manipulate terrain and get info about it. |
48 * |
30 * |
57 /** The terrain data is stored as a linear array in row-major order, with width * height elements */ |
39 /** The terrain data is stored as a linear array in row-major order, with width * height elements */ |
58 TerrainPixel *terrain_buf; |
40 TerrainPixel *terrain_buf; |
59 |
41 |
60 /** Terrain dimensions */ |
42 /** Terrain dimensions */ |
61 PixelDimension width, height; |
43 PixelDimension width, height; |
62 |
44 |
|
45 #if GRAPHICS_ENABLED |
63 /** We pre-render the textured terrain data for display */ |
46 /** We pre-render the textured terrain data for display */ |
64 CL_PixelBuffer pixbuf; |
47 CL_PixelBuffer pixbuf; |
|
48 |
|
49 #endif |
65 |
50 |
66 // XXX: terrain texture |
51 // XXX: terrain texture |
67 std::vector<std::vector<int> > texture; |
52 std::vector<std::vector<int> > texture; |
68 |
53 |
69 public: |
54 public: |
101 * Set induvidual pixel value, updates both terrain_buf and pixbuf |
86 * Set induvidual pixel value, updates both terrain_buf and pixbuf |
102 */ |
87 */ |
103 inline void setType (PixelDimension x, PixelDimension y, TerrainType t) { |
88 inline void setType (PixelDimension x, PixelDimension y, TerrainType t) { |
104 terrain_buf[y * width + x] = (TerrainPixel) t; |
89 terrain_buf[y * width + x] = (TerrainPixel) t; |
105 |
90 |
|
91 #if GRAPHICS_ENABLED |
106 // XXX: locking? |
92 // XXX: locking? |
107 pixbuf.draw_pixel(x, y, getTexturePixel(x, y)); |
93 pixbuf.draw_pixel(x, y, getTexturePixel(x, y)); |
|
94 #endif |
108 } |
95 } |
109 |
96 |
110 /** |
97 /** |
111 * Generate random terrain using given seed |
98 * Generate random terrain using given seed |
112 * |
99 * |
239 * @param prevPoint position in air where we were before the collision |
226 * @param prevPoint position in air where we were before the collision |
240 * @return direction ormal vector, or (0,0) if there's no terrain |
227 * @return direction ormal vector, or (0,0) if there's no terrain |
241 */ |
228 */ |
242 Vector getNormal (Vector point, Vector prevPoint) const; |
229 Vector getNormal (Vector point, Vector prevPoint) const; |
243 |
230 |
|
231 #if GRAPHICS_ENABLED |
244 /** |
232 /** |
245 * Draw the terrain onto the given graphics context |
233 * Draw the terrain onto the given graphics context |
246 * |
234 * |
247 * @param gc Graphics to draw on |
235 * @param gc Graphics to draw on |
248 * @param camera view position |
236 * @param camera view position |
249 */ |
237 */ |
250 virtual void draw (graphics::Display &display, PixelCoordinate camera = PixelCoordinate(0, 0)); |
238 virtual void draw (graphics::Display &display, PixelCoordinate camera = PixelCoordinate(0, 0)); |
|
239 #endif |
251 }; |
240 }; |
252 |
241 |
253 #endif |
242 #endif |