00001 #ifndef logic_area_WangAreaGrid_hpp 00002 #define logic_area_WangAreaGrid_hpp 00003 00004 #include "sim/area/Area.hpp" 00005 #include "BasicPre.hpp" 00006 00007 namespace se_basic { 00008 00009 class _SeBasicExport WangAreaGrid { 00010 public: 00011 WangAreaGrid(int xSize, int zSize, const char* name); 00012 ~WangAreaGrid(); 00013 00014 void setTile(char* name, unsigned char* sides); 00015 00016 inline se_core::Area* getArea(int x, int z) { 00017 return areas_[ x + z * xSize_ ].area_; 00018 } 00019 00020 void addDefinition(const se_core::String& a, const unsigned char* wang) { 00021 WangDefinition& w = wangDefinitions_[ definitionCount_++ ]; 00022 w.areaName_.set(a.copyValue()); 00023 for(int i = 0; i < 4; ++i) 00024 w.wang_[i] = wang[i]; 00025 } 00026 00027 void setArea(int x, int z, int defIndex); 00028 int findMatch(const unsigned char* wang, int random); 00029 00030 int getDefinition(int x, int z) { 00031 if(x < 0 || x >= xSize_) return -3; 00032 if(z < 0 || z >= zSize_) return -3; 00033 //if(!areas_[ x + z * xSize_ ].area_) return -1; 00034 return areas_[ x + z * xSize_ ].definitionIndex_; 00035 } 00036 00037 const unsigned char getSide(int x, int z, int side) { 00038 int def = getDefinition(x, z); 00039 if(def == -2) return 0; 00040 if(def == -3) return defaultBorder_; 00041 if(def < 0) return '0'; 00042 Assert(side >= 0 && side < 4 && "Side must be between 0 and 3"); 00043 return wangDefinitions_[def].wang_[side]; 00044 } 00045 00046 void setDefaultBorder(unsigned char db) { 00047 defaultBorder_ = db; 00048 } 00049 void generate(int seed); 00050 00051 void save(const char* filename); 00052 00053 private: 00054 struct WangDefinition { 00055 se_core::String areaName_; 00056 unsigned char wang_[4]; 00057 } * wangDefinitions_; 00058 int definitionCount_; 00059 00060 static const int MAX_DEFINITIONS = 128; 00061 struct Areas { 00062 se_core::Area* area_; 00063 int definitionIndex_; 00064 }* areas_; 00065 short xSize_, zSize_; 00066 short id_; 00067 se_core::DictionaryEntry* dict_; 00068 00069 unsigned char defaultBorder_; 00070 }; 00071 00072 } 00073 00074 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:02 2007 by Doxygen version 1.3.9.1.