Skip to content

Commit

Permalink
Merge pull request cocos2d#14394 from super626/v3
Browse files Browse the repository at this point in the history
Terrain: char* to string
  • Loading branch information
pandamicro committed Nov 24, 2015
2 parents 8d1f1a9 + e8d8539 commit 378cfa3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
21 changes: 10 additions & 11 deletions cocos/3d/CCTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void Terrain::onDraw(const Mat4 &transform, uint32_t flags)
#endif
}

bool Terrain::initHeightMap(const char * heightMap)
bool Terrain::initHeightMap(const std::string& heightMap)
{
_heightMapImage = new Image();
_heightMapImage->initWithImageFile(heightMap);
Expand Down Expand Up @@ -630,7 +630,7 @@ cocos2d::Vec2 Terrain::convertToTerrainSpace(Vec2 worldSpaceXZ) const
return Vec2(image_x,image_y);
}

void Terrain::resetHeightMap(const char * heightMap)
void Terrain::resetHeightMap(const std::string& heightMap)
{
_heightMapImage->release();
_vertices.clear();
Expand Down Expand Up @@ -857,7 +857,7 @@ bool Terrain::initTextures()
Texture2D::TexParams texParam;
texParam.wrapS = GL_REPEAT;
texParam.wrapT = GL_REPEAT;
if(!_terrainData._alphaMapSrc)
if(_terrainData._alphaMapSrc.empty())
{
auto textImage = new (std::nothrow)Image();
textImage->initWithImageFile(_terrainData._detailMaps[0]._detailMapSrc);
Expand Down Expand Up @@ -1581,21 +1581,21 @@ Terrain::QuadTree::~QuadTree()
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->_detailMaps[0]._detailMapSrc = textureSrc;
this->_alphaMapSrc = nullptr;
this->_alphaMapSrc = "";
this->_chunkSize = chunksize;
this->_mapHeight = height;
this->_mapScale = scale;
_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->_alphaMapSrc = const_cast<char *>(alphamap);
this->_alphaMapSrc = alphamap;
this->_detailMaps[0] = detail1;
this->_detailMaps[1] = detail2;
this->_detailMaps[2] = detail3;
Expand All @@ -1607,14 +1607,13 @@ Terrain::TerrainData::TerrainData(const char * heightMapsrc, const char * alpham
_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->_alphaMapSrc = const_cast<char *>(alphamap);
this->_alphaMapSrc = alphamap;
this->_detailMaps[0] = detail1;
this->_detailMaps[1] = detail2;
this->_detailMaps[2] = detail3;
this->_detailMaps[3] = nullptr;
this->_chunkSize = chunksize;
this->_mapHeight = height;
this->_mapScale = scale;
Expand All @@ -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->_detailMapSize = size;
Expand Down
14 changes: 7 additions & 7 deletions cocos/3d/CCTerrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CC_DLL Terrain : public Node
struct CC_DLL DetailMap{
/*Constructors*/
DetailMap();
DetailMap(const char * detailMapSrc, float size = 35);
DetailMap(const std::string& detailMapSrc, float size = 35);
/*detail Image source file path*/
std::string _detailMapSrc;
/*detailMapSize determine how many tiles that Terrain represent*/
Expand Down Expand Up @@ -130,19 +130,19 @@ class CC_DLL Terrain : public Node
/**empty constructor*/
TerrainData();
/**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*/
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*/
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
*/
Size _chunkSize;
/**height Map source path*/
std::string _heightMapSrc;
/**the source path of the alpha map*/
char* _alphaMapSrc;
std::string _alphaMapSrc;
/**detail maps*/
DetailMap _detailMaps[4];
/**terrain Maximum height*/
Expand Down Expand Up @@ -316,7 +316,7 @@ class CC_DLL Terrain : public Node
/**initialize all Properties which terrain need */
bool initProperties();
/**initialize heightMap data */
bool initHeightMap(const char* heightMap);
bool initHeightMap(const std::string& heightMap);
/**initialize alphaMap ,detailMaps textures*/
bool initTextures();
/**create entry*/
Expand Down Expand Up @@ -392,7 +392,7 @@ class CC_DLL Terrain : public Node
/**
* reset the heightmap data.
*/
void resetHeightMap(const char * heightMap);
void resetHeightMap(const std::string& heightMap);

/**
* get the terrain's minimal height.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ void terraindata_to_luaval(lua_State* L,const cocos2d::Terrain::TerrainData& inV
lua_rawset(L, -3);
}

if (nullptr != inValue._alphaMapSrc)
if (!inValue._alphaMapSrc.empty())
{
lua_pushstring(L, "_alphaMapSrc");
lua_pushstring(L, inValue._alphaMapSrc);
lua_pushstring(L, inValue._alphaMapSrc.c_str());
lua_rawset(L, -3);
}

Expand Down

0 comments on commit 378cfa3

Please sign in to comment.