src/Terrain.hh
changeset 409 1a03ff151abc
parent 408 e6cfc44266af
child 411 106aaf6eadfe
equal deleted inserted replaced
408:e6cfc44266af 409:1a03ff151abc
     1 #ifndef TERRAIN_HH
     1 #ifndef TERRAIN_HH
     2 #define TERRAIN_HH
     2 #define TERRAIN_HH
     3 
       
     4 #include <vector>
       
     5 
     3 
     6 #include "Vector.hh"
     4 #include "Vector.hh"
     7 #include "GraphicsPointer.hh"
     5 #include "GraphicsPointer.hh"
     8 #include "Types.hh"
     6 #include "Types.hh"
     9 #include "Config.hh"
     7 #include "Config.hh"
    24 
    22 
    25 /**
    23 /**
    26  * Terrain "pixel" type
    24  * Terrain "pixel" type
    27  */
    25  */
    28 typedef uint8_t TerrainPixel;
    26 typedef uint8_t TerrainPixel;
       
    27 
       
    28 /**
       
    29  * Terrain configuration
       
    30  */
       
    31 struct TerrainConfig {
       
    32     /** Size of the terrain field*/
       
    33     PixelCoordinate dimensions;
       
    34 
       
    35     /** Set to nonzero to generate random map */
       
    36     int random_seed;
       
    37     
       
    38     /** Defaults */
       
    39     TerrainConfig (void) : dimensions(TERRAIN_WIDTH, TERRAIN_HEIGHT), random_seed(TERRAIN_RANDOM_SEED) { }
       
    40 };
       
    41 
       
    42 #include <vector>
    29 
    43 
    30 /**
    44 /**
    31  * Terrain class. Represents game terrain and contains member
    45  * Terrain class. Represents game terrain and contains member
    32  * functions to manipulate terrain and get info about it.
    46  * functions to manipulate terrain and get info about it.
    33  * 
    47  * 
    51     // XXX: terrain texture
    65     // XXX: terrain texture
    52     std::vector<std::vector<int> > texture;
    66     std::vector<std::vector<int> > texture;
    53 
    67 
    54 public:    
    68 public:    
    55     /**
    69     /**
    56      * Default constructor. The width/height are set to zero and the terrain is invalid until it gets updated
    70      * Construct a new terrain based on the given configuration
    57      */
    71      *
    58     Terrain (void);
    72      * @param config a TerrainConfig describing how to build the terrain
    59 
    73      */
    60     /**
    74     explicit Terrain (const TerrainConfig &config);
    61      * Construct a randomly generated terrain
       
    62      *
       
    63      * @param width terrain width
       
    64      * @param height terrain height
       
    65      * @param seed random number generator seed used to generate the random terrain.
       
    66      */
       
    67     Terrain (PixelDimension width, PixelDimension height, int seed);
       
    68 
    75 
    69     /**
    76     /**
    70      * Construct the terrain using the provided terrain data. The given \a terrain_buf must be a linear array in the
    77      * 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
    78      * 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,
    79      * must be allocated on the heap using 'new []', and ownership will be transferred (i.e. the buffer is not copied,