Merge pull request #14394 from super626/v3

Terrain: char* to string
This commit is contained in:
pandamicro 2015-11-24 14:53:00 +08:00
commit 378cfa35b6
3 changed files with 19 additions and 20 deletions

View File

@ -223,7 +223,7 @@ void Terrain::onDraw(const Mat4 &transform, uint32_t flags)
#endif #endif
} }
bool Terrain::initHeightMap(const char * heightMap) bool Terrain::initHeightMap(const std::string& heightMap)
{ {
_heightMapImage = new Image(); _heightMapImage = new Image();
_heightMapImage->initWithImageFile(heightMap); _heightMapImage->initWithImageFile(heightMap);
@ -630,7 +630,7 @@ cocos2d::Vec2 Terrain::convertToTerrainSpace(Vec2 worldSpaceXZ) const
return Vec2(image_x,image_y); return Vec2(image_x,image_y);
} }
void Terrain::resetHeightMap(const char * heightMap) void Terrain::resetHeightMap(const std::string& heightMap)
{ {
_heightMapImage->release(); _heightMapImage->release();
_vertices.clear(); _vertices.clear();
@ -857,7 +857,7 @@ bool Terrain::initTextures()
Texture2D::TexParams texParam; Texture2D::TexParams texParam;
texParam.wrapS = GL_REPEAT; texParam.wrapS = GL_REPEAT;
texParam.wrapT = GL_REPEAT; texParam.wrapT = GL_REPEAT;
if(!_terrainData._alphaMapSrc) if(_terrainData._alphaMapSrc.empty())
{ {
auto textImage = new (std::nothrow)Image(); auto textImage = new (std::nothrow)Image();
textImage->initWithImageFile(_terrainData._detailMaps[0]._detailMapSrc); textImage->initWithImageFile(_terrainData._detailMaps[0]._detailMapSrc);
@ -1581,21 +1581,21 @@ Terrain::QuadTree::~QuadTree()
if(_br) delete _br; if(_br) delete _br;
} }
Terrain::TerrainData::TerrainData(const char * heightMapsrc , const char * textureSrc, const Size & chunksize, float height, float scale) Terrain::TerrainData::TerrainData(const std::string& heightMapsrc , const std::string& textureSrc, const Size & chunksize, float height, float scale)
{ {
this->_heightMapSrc = heightMapsrc; this->_heightMapSrc = heightMapsrc;
this->_detailMaps[0]._detailMapSrc = textureSrc; this->_detailMaps[0]._detailMapSrc = textureSrc;
this->_alphaMapSrc = nullptr; this->_alphaMapSrc = "";
this->_chunkSize = chunksize; this->_chunkSize = chunksize;
this->_mapHeight = height; this->_mapHeight = height;
this->_mapScale = scale; this->_mapScale = scale;
_skirtHeightRatio = 1; _skirtHeightRatio = 1;
} }
Terrain::TerrainData::TerrainData(const char * heightMapsrc, const char * alphamap, const DetailMap& detail1, const DetailMap& detail2, const DetailMap& detail3, const DetailMap& detail4, const Size & chunksize, float height, float scale) Terrain::TerrainData::TerrainData(const std::string& heightMapsrc, const std::string& alphamap, const DetailMap& detail1, const DetailMap& detail2, const DetailMap& detail3, const DetailMap& detail4, const Size & chunksize, float height, float scale)
{ {
this->_heightMapSrc = heightMapsrc; this->_heightMapSrc = heightMapsrc;
this->_alphaMapSrc = const_cast<char *>(alphamap); this->_alphaMapSrc = alphamap;
this->_detailMaps[0] = detail1; this->_detailMaps[0] = detail1;
this->_detailMaps[1] = detail2; this->_detailMaps[1] = detail2;
this->_detailMaps[2] = detail3; this->_detailMaps[2] = detail3;
@ -1607,14 +1607,13 @@ Terrain::TerrainData::TerrainData(const char * heightMapsrc, const char * alpham
_skirtHeightRatio = 1; _skirtHeightRatio = 1;
} }
Terrain::TerrainData::TerrainData(const char* heightMapsrc, const char * alphamap, const DetailMap& detail1, const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize /*= Size(32,32)*/, float height /*= 2*/, float scale /*= 0.1*/) Terrain::TerrainData::TerrainData(const std::string& heightMapsrc, const std::string& alphamap, const DetailMap& detail1, const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize /*= Size(32,32)*/, float height /*= 2*/, float scale /*= 0.1*/)
{ {
this->_heightMapSrc = heightMapsrc; this->_heightMapSrc = heightMapsrc;
this->_alphaMapSrc = const_cast<char *>(alphamap); this->_alphaMapSrc = alphamap;
this->_detailMaps[0] = detail1; this->_detailMaps[0] = detail1;
this->_detailMaps[1] = detail2; this->_detailMaps[1] = detail2;
this->_detailMaps[2] = detail3; this->_detailMaps[2] = detail3;
this->_detailMaps[3] = nullptr;
this->_chunkSize = chunksize; this->_chunkSize = chunksize;
this->_mapHeight = height; this->_mapHeight = height;
this->_mapScale = scale; this->_mapScale = scale;
@ -1627,7 +1626,7 @@ Terrain::TerrainData::TerrainData()
} }
Terrain::DetailMap::DetailMap(const char * detailMapPath, float size /*= 35*/) Terrain::DetailMap::DetailMap(const std::string& detailMapPath, float size /*= 35*/)
{ {
this->_detailMapSrc = detailMapPath; this->_detailMapSrc = detailMapPath;
this->_detailMapSize = size; this->_detailMapSize = size;

View File

@ -102,7 +102,7 @@ public:
struct CC_DLL DetailMap{ struct CC_DLL DetailMap{
/*Constructors*/ /*Constructors*/
DetailMap(); DetailMap();
DetailMap(const char * detailMapSrc, float size = 35); DetailMap(const std::string& detailMapSrc, float size = 35);
/*detail Image source file path*/ /*detail Image source file path*/
std::string _detailMapSrc; std::string _detailMapSrc;
/*detailMapSize determine how many tiles that Terrain represent*/ /*detailMapSize determine how many tiles that Terrain represent*/
@ -130,11 +130,11 @@ public:
/**empty constructor*/ /**empty constructor*/
TerrainData(); TerrainData();
/**constructor, this constructor construct a simple terrain which only have 1 detailmap*/ /**constructor, this constructor construct a simple terrain which only have 1 detailmap*/
TerrainData(const char* heightMapsrc, const char * textureSrc, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1); TerrainData(const std::string& heightMapsrc, const std::string& textureSrc, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1);
/**constructor, this constructor construct a terrain which have 4 detailmaps, 1 alpha map*/ /**constructor, this constructor construct a terrain which have 4 detailmaps, 1 alpha map*/
TerrainData(const char* heightMapsrc, const char * alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const DetailMap& detail4, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1); TerrainData(const std::string& heightMapsrc, const std::string& alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const DetailMap& detail4, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1);
/**constructor, this constructor construct a terrain which have 3 detailmaps, 1 alpha map*/ /**constructor, this constructor construct a terrain which have 3 detailmaps, 1 alpha map*/
TerrainData(const char* heightMapsrc, const char * alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1); TerrainData(const std::string& heightMapsrc, const std::string& alphamap, const DetailMap& detail1,const DetailMap& detail2, const DetailMap& detail3, const Size & chunksize = Size(32,32), float mapHeight = 2, float mapScale = 0.1);
/** /**
*determine the chunk size,chunk is the minimal subdivision of the Terrain *determine the chunk size,chunk is the minimal subdivision of the Terrain
*/ */
@ -142,7 +142,7 @@ public:
/**height Map source path*/ /**height Map source path*/
std::string _heightMapSrc; std::string _heightMapSrc;
/**the source path of the alpha map*/ /**the source path of the alpha map*/
char* _alphaMapSrc; std::string _alphaMapSrc;
/**detail maps*/ /**detail maps*/
DetailMap _detailMaps[4]; DetailMap _detailMaps[4];
/**terrain Maximum height*/ /**terrain Maximum height*/
@ -316,7 +316,7 @@ public:
/**initialize all Properties which terrain need */ /**initialize all Properties which terrain need */
bool initProperties(); bool initProperties();
/**initialize heightMap data */ /**initialize heightMap data */
bool initHeightMap(const char* heightMap); bool initHeightMap(const std::string& heightMap);
/**initialize alphaMap ,detailMaps textures*/ /**initialize alphaMap ,detailMaps textures*/
bool initTextures(); bool initTextures();
/**create entry*/ /**create entry*/
@ -392,7 +392,7 @@ public:
/** /**
* reset the heightmap data. * reset the heightmap data.
*/ */
void resetHeightMap(const char * heightMap); void resetHeightMap(const std::string& heightMap);
/** /**
* get the terrain's minimal height. * get the terrain's minimal height.

View File

@ -319,10 +319,10 @@ void terraindata_to_luaval(lua_State* L,const cocos2d::Terrain::TerrainData& inV
lua_rawset(L, -3); lua_rawset(L, -3);
} }
if (nullptr != inValue._alphaMapSrc) if (!inValue._alphaMapSrc.empty())
{ {
lua_pushstring(L, "_alphaMapSrc"); lua_pushstring(L, "_alphaMapSrc");
lua_pushstring(L, inValue._alphaMapSrc); lua_pushstring(L, inValue._alphaMapSrc.c_str());
lua_rawset(L, -3); lua_rawset(L, -3);
} }