1 /*************************************************************************** 2 map.h - description 3 ------------------- 4 begin : july 2nd, 2006 5 copyright : (C) 2006-2007 by Fr�d�ric RODRIGO 6 email : f.rodrigo free.fr 7 8 $Id: map.h 373 2008-10-11 21:32:54Z neoneurone $ 9 ***************************************************************************/ 10 11 /*************************************************************************** 12 * * 13 * This program is free software; you can redistribute it and/or modify * 14 * it under the terms of the GNU General Public License as published by * 15 * the Free Software Foundation; either version 2 of the License, or * 16 * any later version. * 17 * * 18 ***************************************************************************/ 19 20 #ifndef _OPENCITY_MAPGEN_MAP_H_ 21 #define _OPENCITY_MAPGEN_MAP_H_ 1 22 23 #define MAP_NDEBUG 1 // Debugging off 24 #undef MAP_NDEBUG 25 26 #include "macros.h" ///< OpenCity debug macro 27 28 #include <string> // C++ string 29 using std::string; 30 31 #ifndef MAP_NDEBUG 32 #define MAP_DEBUG( msg ) OPENCITY_DEBUG( msg ) 33 #define MAP_ERROR( msg ) OPENCITY_ERROR( msg ) 34 #else 35 #define MAP_DEBUG( msg ) 36 #endif 37 38 #define MAP_INFO( msg ) OPENCITY_INFO( msg ) 39 40 namespace MapGen 41 { 42 43 44 //======================================================================== 45 /** Float height map 46 */ 47 class Map { 48 public: 49 Map( 50 const uint w, 51 const uint h ); 52 ~Map(); 53 54 55 //======================================================================== 56 /** Setter */ 57 void setAt( 58 int x, 59 int y, 60 float value ); 61 62 63 //======================================================================== 64 /** Getter */ 65 float getAt( 66 int x, 67 int y ) const; 68 69 #ifdef OPENCITY_PNG_SAVE 70 bool save( const string &file ); 71 #endif 72 getW()73 inline uint getW() const { return _w; } 74 getL()75 inline uint getL() const { return _h; } 76 77 78 //======================================================================== 79 /** Return a sub-map */ 80 Map* crop( 81 const uint w, 82 const uint h ) const; 83 84 85 //======================================================================== 86 /** Convert the private float array to an allocated int array */ 87 int* toIntArray() const; 88 89 90 //======================================================================== 91 /** Return a (w-1)x-(h-1) sized map, each place is average of four corners */ 92 Map* halfShift() const; 93 94 95 private: 96 uint _w; 97 uint _h; 98 float** _map; 99 100 }; 101 102 103 } 104 105 #endif 106