src/Terrain.hh
changeset 408 e6cfc44266af
parent 406 a2e35ca66c74
child 409 1a03ff151abc
--- a/src/Terrain.hh	Tue Jan 20 23:24:04 2009 +0200
+++ b/src/Terrain.hh	Tue Jan 20 23:30:18 2009 +0200
@@ -39,7 +39,7 @@
  */ 
 class Terrain {
 protected:
-    /** The terrain data is stored as a linear array in row-major order, with width*height elements */
+    /** The terrain data is stored as a linear array in row-major order, with width * height elements */
     TerrainPixel *terrain_buf;
 
     /** Terrain dimensions */
@@ -51,22 +51,35 @@
     // XXX: terrain texture
     std::vector<std::vector<int> > texture;
 
+public:    
     /**
      * Default constructor. The width/height are set to zero and the terrain is invalid until it gets updated
      */
     Terrain (void);
 
     /**
-     * Constructor.
+     * Construct a randomly generated terrain
      *
      * @param width terrain width
      * @param height terrain height
-     * @param seed andom number generator seed used to generate the random terrain.
+     * @param seed random number generator seed used to generate the random terrain.
      */
     Terrain (PixelDimension width, PixelDimension height, int seed);
 
     /**
-     * Destructor
+     * Construct the terrain using the provided terrain data. The given \a terrain_buf must be a linear array in the
+     * same format as Terrain::terrain_buf, meaning a row-major order array with width * height elements. The buffer
+     * must be allocated on the heap using 'new []', and ownership will be transferred (i.e. the buffer is not copied,
+     * and will eventually be delete []'d).
+     *
+     * @param width terrain width
+     * @param height terrain height
+     * @param terrain_buf dynamically allocated width * height array of terrain data
+     */
+    Terrain (PixelDimension width, PixelDimension height, TerrainPixel *terrain_buf);
+
+    /**
+     * Destructor, frees our terrain buffer
      */
     ~Terrain (void);
 
@@ -135,11 +148,22 @@
     /**
      * Return the terrain dimensions à la a PixelCoordinate
      */
-    inline PixelCoordinate getDimensions (void) const {
+    PixelCoordinate getDimensions (void) const {
         return PixelCoordinate(width, height);
     }
 
     /**
+     * Return dimensions in component form
+     */
+    PixelDimension getWidth (void) const {
+        return width;
+    }
+
+    PixelDimension getHeight (void) const {
+        return height;
+    }
+
+    /**
      * Return the type of terrain at given position. Returns TERRAIN_ROCK if given point is not inside terrain area.
      *
      * @param x terrain x coordinate