Skip to content

Commit abfdd70

Browse files
committed
Merge pull request #4 from dabingnn/newRendererCommandPool
New renderer command pool
2 parents 815ca2b + 49375e7 commit abfdd70

16 files changed

+153
-23
lines changed

cocos/2d/CCLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ void LayerColor::updateColor()
695695
void LayerColor::draw()
696696
{
697697
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
698-
CustomCommand* cmd = new CustomCommand();
698+
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
699699
cmd->init(0, _vertexZ);
700700
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
701701
Renderer::getInstance()->addCommand(cmd);

cocos/2d/CCParticleSystemQuad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void ParticleSystemQuad::draw()
415415
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
416416
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
417417

418-
CustomCommand* cmd = new CustomCommand();
418+
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
419419
cmd->init(0, _vertexZ);
420420
cmd->func = CC_CALLBACK_0(ParticleSystemQuad::onDraw, this);
421421
Renderer::getInstance()->addCommand(cmd);

cocos/2d/CCSprite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ void Sprite::draw(void)
663663
{
664664
updateQuadVertices();
665665
//TODO implement z order
666-
QuadCommand* renderCommand = new QuadCommand();
666+
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
667667
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1);
668668
Renderer::getInstance()->addCommand(renderCommand);
669669
}

cocos/2d/renderer/CCNewDrawNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void NewDrawNode::draw()
4444
{
4545
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
4646

47-
CustomCommand* cmd = new CustomCommand();
47+
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
4848
cmd->init(0, _vertexZ);
4949
cmd->func = CC_CALLBACK_0(NewDrawNode::onDraw, this);
5050
Renderer::getInstance()->addCommand(cmd);

cocos/2d/renderer/CCNewSprite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void NewSprite::draw(void)
140140
}
141141

142142
//TODO implement z order
143-
QuadCommand* renderCommand = new QuadCommand();
143+
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
144144
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1);
145145

146146
Renderer::getInstance()->addCommand(renderCommand);

cocos/2d/renderer/CCNewSpriteBatchNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void NewSpriteBatchNode::draw()
6060

6161
arrayMakeObjectsPerformSelector(_children, updateTransform, NewSprite*);
6262

63-
QuadCommand* cmd = new QuadCommand();
63+
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
6464
cmd->init(0, _vertexZ, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc, _textureAtlas->getQuads(), _textureAtlas->getTotalQuads());
6565
Renderer::getInstance()->addCommand(cmd);
6666
}

cocos/2d/renderer/CustomCommand.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "CustomCommand.h"
77

88
NS_CC_BEGIN
9+
RenderCommandPool<CustomCommand> CustomCommand::_commandPool;
910

1011
CustomCommand::CustomCommand()
1112
:RenderCommand()
@@ -46,4 +47,9 @@ void CustomCommand::execute()
4647
}
4748
}
4849

50+
void CustomCommand::releaseToCommandPool()
51+
{
52+
getCommandPool().pushBackCommand(this);
53+
}
54+
4955
NS_CC_END

cocos/2d/renderer/CustomCommand.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
#define _CC_CUSTOMCOMMAND_H_
99

1010
#include "RenderCommand.h"
11+
#include "RenderCommandPool.h"
1112

1213
NS_CC_BEGIN
1314
using namespace std;
1415

1516
class CustomCommand : public RenderCommand
1617
{
17-
public:
18+
protected:
1819
CustomCommand();
19-
void init(int viewport, int32_t depth);
2020
~CustomCommand();
21+
22+
public:
23+
void init(int viewport, int32_t depth);
2124

2225
// +----------+----------+-----+-----------------------------------+
2326
// | | | | | |
@@ -29,6 +32,7 @@ class CustomCommand : public RenderCommand
2932
void execute();
3033

3134
inline bool isTranslucent() { return true; }
35+
virtual void releaseToCommandPool() override;
3236

3337
public:
3438
function<void()> func;
@@ -37,6 +41,12 @@ class CustomCommand : public RenderCommand
3741
int _viewport;
3842

3943
int32_t _depth;
44+
45+
public:
46+
friend class RenderCommandPool<CustomCommand>;
47+
static RenderCommandPool<CustomCommand>& getCommandPool() { return _commandPool; }
48+
protected:
49+
static RenderCommandPool<CustomCommand> _commandPool;
4050

4151
};
4252

cocos/2d/renderer/GroupCommand.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Renderer.h"
88

99
NS_CC_BEGIN
10+
RenderCommandPool<GroupCommand> GroupCommand::_commandPool;
1011

1112
static GroupCommandManager* s_instance;
1213
GroupCommandManager *GroupCommandManager::getInstance()
@@ -96,5 +97,10 @@ int64_t GroupCommand::generateID()
9697
return _id;
9798
}
9899

100+
void GroupCommand::releaseToCommandPool()
101+
{
102+
getCommandPool().pushBackCommand(this);
103+
}
104+
99105

100106
NS_CC_END

cocos/2d/renderer/GroupCommand.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "CCPlatformMacros.h"
1111
#include "RenderCommand.h"
12+
#include "RenderCommandPool.h"
1213
#include <map>
1314

1415
NS_CC_BEGIN
@@ -33,11 +34,11 @@ class GroupCommandManager : public Object
3334

3435
class GroupCommand : public RenderCommand
3536
{
36-
37-
public:
37+
protected:
3838
GroupCommand();
39-
void init(int viewport, int32_t depth);
4039
~GroupCommand();
40+
public:
41+
void init(int viewport, int32_t depth);
4142

4243
// +----------+----------+-----+-----------------------------------+
4344
// | | | | | |
@@ -48,11 +49,18 @@ class GroupCommand : public RenderCommand
4849

4950
inline bool isTranslucent() {return true;}
5051
inline int getRenderQueueID() {return _renderQueueID;}
51-
52+
virtual void releaseToCommandPool() override;
53+
5254
protected:
5355
int _viewport;
5456
int32_t _depth;
5557
int _renderQueueID;
58+
59+
public:
60+
friend class RenderCommandPool<GroupCommand>;
61+
static RenderCommandPool<GroupCommand>& getCommandPool() { return _commandPool; }
62+
protected:
63+
static RenderCommandPool<GroupCommand> _commandPool;
5664
};
5765

5866
NS_CC_END

0 commit comments

Comments
 (0)