Specialize GroupCommand and CustomCommand, change generateCommand to new.

This commit is contained in:
boyu0 2013-12-26 15:41:47 +08:00
parent 963d637198
commit f878864794
22 changed files with 75 additions and 43 deletions

View File

@ -151,7 +151,7 @@ void AtlasNode::draw(void)
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
QuadCommand* cmd = new QuadCommand();
cmd->init(0,
_vertexZ,
_textureAtlas->getTexture()->getName(),

View File

@ -209,20 +209,20 @@ void ClippingNode::visit()
Renderer* renderer = Director::getInstance()->getRenderer();
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
GroupCommand* groupCommand = new GroupCommand();
groupCommand->init(0,_vertexZ);
renderer->addCommand(groupCommand);
renderer->pushGroup(groupCommand->getRenderQueueID());
CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* beforeVisitCmd = new CustomCommand();
beforeVisitCmd->init(0,_vertexZ);
beforeVisitCmd->func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
renderer->addCommand(beforeVisitCmd);
_stencil->visit();
CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* afterDrawStencilCmd = new CustomCommand();
afterDrawStencilCmd->init(0,_vertexZ);
afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
renderer->addCommand(afterDrawStencilCmd);
@ -253,7 +253,7 @@ void ClippingNode::visit()
this->draw();
}
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* afterVisitCmd = new CustomCommand();
afterVisitCmd->init(0,_vertexZ);
afterVisitCmd->func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
renderer->addCommand(afterVisitCmd);

View File

@ -241,7 +241,7 @@ void DrawNode::render()
void DrawNode::draw()
{
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(DrawNode::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -564,7 +564,7 @@ void LayerColor::updateColor()
void LayerColor::draw()
{
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -358,7 +358,7 @@ void MotionStreak::draw()
if(_nuPoints <= 1)
return;
kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV);
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0,_vertexZ);
cmd->func = CC_CALLBACK_0(MotionStreak::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -92,7 +92,7 @@ void NodeGrid::visit()
Renderer* renderer = Director::getInstance()->getRenderer();
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
GroupCommand* groupCommand = new GroupCommand();
groupCommand->init(0,_vertexZ);
renderer->addCommand(groupCommand);
renderer->pushGroup(groupCommand->getRenderQueueID());
@ -105,7 +105,7 @@ void NodeGrid::visit()
_nodeGrid->set2DProjection();
}
CustomCommand* gridBeginCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* gridBeginCmd = new CustomCommand();
gridBeginCmd->init(0,_vertexZ);
gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this);
renderer->addCommand(gridBeginCmd);
@ -154,7 +154,7 @@ void NodeGrid::visit()
director->setProjection(beforeProjectionType);
}
CustomCommand* gridEndCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* gridEndCmd = new CustomCommand();
gridEndCmd->init(0,_vertexZ);
gridEndCmd->func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this);
renderer->addCommand(gridEndCmd);

View File

@ -392,7 +392,7 @@ void ParticleBatchNode::draw(void)
kmMat4 mv;
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
QuadCommand* cmd = new QuadCommand();
cmd->init(0,
_vertexZ,
_textureAtlas->getTexture()->getName(),

View File

@ -443,7 +443,7 @@ void ParticleSystemQuad::draw()
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
QuadCommand* cmd = new QuadCommand();
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
Director::getInstance()->getRenderer()->addCommand(cmd);
}

View File

@ -532,7 +532,7 @@ void ProgressTimer::draw()
if( ! _vertexData || ! _sprite)
return;
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -329,7 +329,7 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep
this->begin();
//clear screen
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* clearCmd = new CustomCommand();
clearCmd->init(0, _vertexZ);
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
Director::getInstance()->getRenderer()->addCommand(clearCmd);
@ -348,7 +348,7 @@ void RenderTexture::clearDepth(float depthValue)
this->begin();
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this);
@ -614,7 +614,7 @@ void RenderTexture::draw()
begin();
//clear screen
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* clearCmd = new CustomCommand();
clearCmd->init(0, _vertexZ);
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
Director::getInstance()->getRenderer()->addCommand(clearCmd);
@ -643,14 +643,14 @@ void RenderTexture::begin()
kmGLPushMatrix();
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
GroupCommand* groupCommand = new GroupCommand();
groupCommand->init(0, _vertexZ);
Renderer *renderer = Director::getInstance()->getRenderer();
renderer->addCommand(groupCommand);
renderer->pushGroup(groupCommand->getRenderQueueID());
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* beginCmd = new CustomCommand();
beginCmd->init(0, _vertexZ);
beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this);
@ -659,7 +659,7 @@ void RenderTexture::begin()
void RenderTexture::end()
{
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* endCmd = new CustomCommand();
endCmd->init(0, _vertexZ);
endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this);

View File

@ -360,7 +360,7 @@ void SpriteBatchNode::draw()
kmMat4 mv;
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
QuadCommand* cmd = new QuadCommand();
cmd->init(0,
_vertexZ,
_textureAtlas->getTexture()->getName(),

View File

@ -33,6 +33,10 @@ NS_CC_BEGIN
class CustomCommand : public RenderCommand
{
public:
CustomCommand();
~CustomCommand();
public:
static RenderCommandPool<CustomCommand>& getCommandPool() { return _commandPool; }
@ -52,9 +56,6 @@ public:
std::function<void()> func;
protected:
CustomCommand();
~CustomCommand();
int _viewport;
int32_t _depth;
static RenderCommandPool<CustomCommand> _commandPool;
@ -62,6 +63,21 @@ protected:
friend class RenderCommandPool<CustomCommand>;
};
template <>
class RenderCommandPool<CustomCommand>
{
public:
CustomCommand* generateCommand()
{
return new CustomCommand();
}
void pushBackCommand(CustomCommand* ptr)
{
delete ptr;
}
};
NS_CC_END
#endif //_CC_CUSTOMCOMMAND_H_

View File

@ -52,6 +52,10 @@ protected:
class GroupCommand : public RenderCommand
{
public:
GroupCommand();
~GroupCommand();
public:
static RenderCommandPool<GroupCommand>& getCommandPool() { return _commandPool; }
@ -69,9 +73,6 @@ public:
virtual void releaseToCommandPool() override;
protected:
GroupCommand();
~GroupCommand();
int _viewport;
int32_t _depth;
int _renderQueueID;
@ -80,6 +81,21 @@ protected:
friend class RenderCommandPool<GroupCommand>;
};
template <>
class RenderCommandPool<GroupCommand>
{
public:
GroupCommand* generateCommand()
{
return new GroupCommand();
}
void pushBackCommand(GroupCommand* ptr)
{
delete ptr;
}
};
NS_CC_END
#endif //_CC_GROUPCOMMAND_H_

View File

@ -147,7 +147,7 @@ void BatchNode::draw()
void BatchNode::generateGroupCommand()
{
Renderer* renderer = Director::getInstance()->getRenderer();
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
GroupCommand* groupCommand = new GroupCommand();
groupCommand->init(0,_vertexZ);
renderer->addCommand(groupCommand);

View File

@ -219,7 +219,7 @@ void Skin::draw()
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
//TODO implement z order
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
QuadCommand* renderCommand = new QuadCommand();
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
Director::getInstance()->getRenderer()->addCommand(renderCommand);
}

View File

@ -1289,7 +1289,7 @@ void ActionFollow::onEnter()
void ActionFollow::draw()
{
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ActionFollow::onDraw, this);
@ -1606,7 +1606,7 @@ void ActionCatmullRomStacked::draw()
kmGLPopMatrix();
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -1722,7 +1722,7 @@ void ActionCardinalSplineStacked::draw()
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
kmGLPopMatrix();
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -2085,7 +2085,7 @@ void ActionCatmullRom::draw()
kmGLPopMatrix();
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -2186,7 +2186,7 @@ void ActionCardinalSpline::draw()
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2);
kmGLPopMatrix();
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand* cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -149,7 +149,7 @@ void Box2DTestLayer::draw()
kmGLPushMatrix();
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV);
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -116,7 +116,7 @@ DrawPrimitivesTest::DrawPrimitivesTest()
void DrawPrimitivesTest::draw()
{
CustomCommand * cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand * cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -1094,7 +1094,7 @@ std::string TestBoundingBox::title() const
}
void TestBoundingBox::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(TestBoundingBox::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -209,7 +209,7 @@ void Atlas1::draw()
// GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// GL_TEXTURE_2D
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(Atlas1::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -526,7 +526,7 @@ Atlas4::Atlas4()
void Atlas4::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(Atlas4::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -1613,7 +1613,7 @@ std::string LabelBMFontBounds::subtitle() const
void LabelBMFontBounds::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -589,7 +589,7 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea
void SpriteRenderTextureBug::SimpleSprite::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);

View File

@ -196,7 +196,7 @@ void ShaderNode::setPosition(const Point &newPosition)
void ShaderNode::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ShaderNode::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
@ -532,7 +532,7 @@ void SpriteBlur::initProgram()
void SpriteBlur::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
CustomCommand *cmd = new CustomCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(SpriteBlur::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);