From 5b572ab8031df6e819778a9913c37b0eb9b2ab40 Mon Sep 17 00:00:00 2001 From: WuHao Date: Thu, 4 Jun 2015 16:20:00 +0800 Subject: [PATCH] Polyinfo is no longer a pointer --- cocos/2d/CCSprite.cpp | 32 +++++++++---------- cocos/2d/CCSprite.h | 2 +- cocos/3d/CCBillBoard.cpp | 2 +- .../Classes/ShaderTest/ShaderTest2.cpp | 2 +- tests/cpp-tests/Classes/controller.cpp | 3 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 5708f134ba..b4847788f9 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -227,8 +227,8 @@ bool Sprite::initWithPolygon(const cocos2d::PolygonInfo &info) bool res = false; if(initWithTexture(texture)); { - _polyInfo = new PolygonInfo(info); - setContentSize(_polyInfo->rect.size/Director::getInstance()->getContentScaleFactor()); + _polyInfo = info; + setContentSize(_polyInfo.rect.size/Director::getInstance()->getContentScaleFactor()); res = true; } return res; @@ -275,7 +275,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) setTexture(texture); setTextureRect(rect, rotated, rect.size); - _polyInfo = new PolygonInfo(&_quad); + _polyInfo = PolygonInfo(&_quad); // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" setBatchNode(nullptr); @@ -306,7 +306,7 @@ Sprite::~Sprite(void) { CC_SAFE_RELEASE(_spriteFrame); CC_SAFE_RELEASE(_texture); - delete _polyInfo; +// delete _polyInfo; } /* @@ -451,20 +451,20 @@ void Sprite::debugDraw(bool on) draw->setVisible(true); draw->clear(); //draw all points - auto positions = new (std::nothrow) Vec2[_polyInfo->triangles.vertCount]; + auto positions = new (std::nothrow) Vec2[_polyInfo.triangles.vertCount]; Vec2 *pos = &positions[0]; - auto verts = _polyInfo->triangles.verts; - auto end = &verts[_polyInfo->triangles.vertCount]; + auto verts = _polyInfo.triangles.verts; + auto end = &verts[_polyInfo.triangles.vertCount]; for(V3F_C4B_T2F *v = verts; v != end; pos++, v++) { pos->x = v->vertices.x; pos->y = v->vertices.y; } - draw->drawPoints(positions, (unsigned int)_polyInfo->triangles.vertCount, 8, Color4F(0.0f, 1.0f, 1.0f, 1.0f)); + draw->drawPoints(positions, (unsigned int)_polyInfo.triangles.vertCount, 8, Color4F(0.0f, 1.0f, 1.0f, 1.0f)); //draw lines - auto last = _polyInfo->triangles.indexCount/3; - auto _indices = _polyInfo->triangles.indices; - auto _verts = _polyInfo->triangles.verts; + auto last = _polyInfo.triangles.indexCount/3; + auto _indices = _polyInfo.triangles.indices; + auto _verts = _polyInfo.triangles.verts; for(unsigned int i = 0; i < last; i++) { //draw 3 lines @@ -681,7 +681,7 @@ void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) if(_insideBounds) #endif { - _trianglesCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo->triangles, transform, flags); + _trianglesCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo.triangles, transform, flags); renderer->addCommand(&_trianglesCommand); } } @@ -1115,7 +1115,7 @@ void Sprite::updateBlendFunc(void) { CCASSERT(! _batchNode, "CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a SpriteBatchNode"); - // it is possible to have an untextured sprite + // it is possible to have an untextured spritec if (! _texture || ! _texture->hasPremultipliedAlpha()) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; @@ -1140,13 +1140,13 @@ std::string Sprite::getDescription() const PolygonInfo Sprite::getPolygonInfo() const { - return PolygonInfo(*_polyInfo); + return _polyInfo; } void Sprite::setPolygonInfo(const PolygonInfo& info) { - delete _polyInfo; - _polyInfo = new PolygonInfo(info); +// delete _polyInfo; + _polyInfo = info; } NS_CC_END diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 33266fac45..41ae4f7674 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -617,7 +617,7 @@ protected: // vertex coords, texture coords and color info V3F_C4B_T2F_Quad _quad; - PolygonInfo * _polyInfo; + PolygonInfo _polyInfo; // opacity and RGB protocol bool _opacityModifyRGB; diff --git a/cocos/3d/CCBillBoard.cpp b/cocos/3d/CCBillBoard.cpp index 9ae4f71cc6..dd5b4b5652 100644 --- a/cocos/3d/CCBillBoard.cpp +++ b/cocos/3d/CCBillBoard.cpp @@ -230,7 +230,7 @@ void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { //FIXME: frustum culling here flags |= Node::FLAGS_RENDER_AS_3D; - _trianglesCommand.init(0, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo->triangles, _modelViewTransform, flags); + _trianglesCommand.init(0, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo.triangles, _modelViewTransform, flags); _trianglesCommand.setTransparent(true); _trianglesCommand.set3D(true); renderer->addCommand(&_trianglesCommand); diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp index af03b813f6..2c4ce7a629 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp @@ -101,7 +101,7 @@ public: } // normal effect: order == 0 - _trianglesCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo->triangles, transform, flags); + _trianglesCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo.triangles, transform, flags); renderer->addCommand(&_trianglesCommand); // postive effects: oder >= 0 diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index 8baf84845c..4910a543f8 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -16,6 +16,7 @@ class RootTests : public TestList public: RootTests() { + addTest("Node: SpritePolygon", [](){return new (std::nothrow) SpritePolygonTest(); }); addTest("Node: Scene3D", [](){return new (std::nothrow) Scene3DTests(); }); addTest("ActionManager", [](){return new (std::nothrow) ActionManagerTests(); }); addTest("Actions - Basic", [](){ return new (std::nothrow) ActionsTests(); }); @@ -67,7 +68,7 @@ public: addTest("Node: Spine", [](){return new SpineTests(); }); addTest("Node: Sprite", [](){return new SpriteTests(); }); addTest("Node: Sprite3D", [](){ return new Sprite3DTests(); }); - addTest("Node: SpritePolygon", [](){return new (std::nothrow) SpritePolygonTest(); }); +// addTest("Node: SpritePolygon", [](){return new (std::nothrow) SpritePolygonTest(); }); addTest("Node: Terrain", [](){ return new TerrainTests(); }); addTest("Node: TileMap", [](){return new TileMapTests(); }); addTest("Node: FastTileMap", [](){return new FastTileMapTests(); });