Polyinfo is no longer a pointer

This commit is contained in:
WuHao 2015-06-04 16:20:00 +08:00
parent 0a51c9bd27
commit 5b572ab803
5 changed files with 21 additions and 20 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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(); });