Merge pull request #1 from dumganhar/new-label-atlas

issue #3628: Adds missing files for iOS and Mac.
This commit is contained in:
LinWenhai 2014-01-16 19:21:19 -08:00
commit 484f6a8f36
52 changed files with 1286 additions and 210 deletions

View File

@ -718,6 +718,9 @@ Developers:
Pisces000221
Corrected a few mistakes in the README file of project-creator.
hbbalfred
Fixed a bug that crash if file doesn't exist when using FileUtils::getStringFromFile.
Retired Core Developers:
WenSheng Yang

View File

@ -1,9 +1,15 @@
cocos2d-x-3.0final ?.? ?
[All]
[NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use.
[NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands
[NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier.
[NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands
[NEW] GLCache: glActiveTexture() is cached with GL::activeTexture(). All code MUST call the cached version in order to work correctly
[NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use.
[NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10%
[FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work.
[FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile.
[FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong.
[FIX] Label: Crash when using unknown characters.
[FIX] Console: log(format, va_args) is private to prevent possible resolution errors
[FIX] Configuration: dumpInfo() -> getInfo()
[FIX] ControlSlider doesn't support to set selected thumb sprite.
@ -11,9 +17,10 @@ cocos2d-x-3.0final ?.? ?
[FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file.
[FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster
[FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20%
[FIX] Renderer: When note using VAO, call glBufferData() instead of glBufferSubData().
[FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well
[FIX] Tests: TestCpp works with CMake on Windows.
[FIX] Tests: Sprites Performance Test has 3 new tests
[FIX] Tests: Sprites Performance Test has 4 new tests
[FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected
[FIX] TextureCache: dumpCachedTextureInfo() -> getCachedTextureInfo()
[FIX] Websocket doesn't support send/receive data which larger than 4096 bytes.

View File

@ -1 +1 @@
88c095bbe123ab56df3f7870692c6631f4464c8d
e1e5a1169e92834330092c45165660c6cbd03609

View File

@ -1 +1 @@
2efefc01ff97bda1498d1d4a850ea1881f751f7c
1fa58d8cba77ef923c83d2860d5511d28dad6c27

View File

@ -158,7 +158,7 @@ void AtlasNode::draw(void)
shader,
_blendFunc,
_textureAtlas->getQuads(),
_textureAtlas->getTotalQuads(),
_quadsToDraw,
_modelViewTransform);
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);

View File

@ -146,7 +146,7 @@ void Configuration::gatherGPUInfo()
_supportsShareableVAO = checkForGLExtension("vertex_array_object");
_valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO);
CHECK_GL_ERROR_DEBUG();
}

View File

@ -275,8 +275,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch
unsigned long remains = size;
unsigned char version = pData[3];
CCASSERT(version == 3, "Only version 3 is supported");
CCASSERT(pData[3] == 3, "Only version 3 is supported");
pData += 4; remains -= 4;
@ -343,8 +342,7 @@ std::set<unsigned int>* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch
*/
const char *value = (const char *)pData;
size_t len = strlen(value);
CCASSERT(len < blockSize, "Block size should be less then string");
CCASSERT(strlen(value) < blockSize, "Block size should be less then string");
_atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(value, controlFile);
}

View File

@ -73,7 +73,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra)
{
while (arr->max < arr->num + extra)
{
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
CCLOGINFO("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
static_cast<int>(arr->max),
static_cast<int>(arr->max*2));

View File

@ -44,7 +44,6 @@ namespace
static bool s_vertexAttribColor = false;
static bool s_vertexAttribTexCoords = false;
#if CC_ENABLE_GL_STATE_CACHE
#define kMaxActiveTexture 16
@ -55,6 +54,8 @@ namespace
static GLenum s_blendingDest = -1;
static int s_GLServerState = 0;
static GLuint s_VAO = 0;
static GLenum s_activeTexture = -1;
#endif // CC_ENABLE_GL_STATE_CACHE
}
@ -159,7 +160,7 @@ void bindTexture2DN(GLuint textureUnit, GLuint textureId)
if (s_currentBoundTexture[textureUnit] != textureId)
{
s_currentBoundTexture[textureUnit] = textureId;
glActiveTexture(GL_TEXTURE0 + textureUnit);
activeTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, textureId);
}
#else
@ -186,6 +187,18 @@ void deleteTextureN(GLuint textureUnit, GLuint textureId)
glDeleteTextures(1, &textureId);
}
void activeTexture(GLenum texture)
{
#if CC_ENABLE_GL_STATE_CACHE
if(s_activeTexture != texture) {
s_activeTexture = texture;
glActiveTexture(s_activeTexture);
}
#else
glActiveTexture(texture);
#endif
}
void bindVAO(GLuint vaoId)
{
if (Configuration::getInstance()->supportsShareableVAO())

View File

@ -129,6 +129,12 @@ void CC_DLL deleteTexture(GLuint textureId);
*/
void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId);
/** Select active texture unit.
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.
@since v3.0
*/
void CC_DLL activeTexture(GLenum texture);
/** If the vertex array is not already bound, it binds it.
If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
@since v2.0.0

View File

@ -279,7 +279,7 @@ cc_utf8_get_char (const char * p)
unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = nullptr */)
{
unsigned short len = cc_utf8_strlen(str_old, length);
long len = cc_utf8_strlen(str_old, length);
if (rUtf16Size != nullptr) {
*rUtf16Size = len;
}

View File

@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString)
std::string FileUtils::getStringFromFile(const std::string& filename)
{
Data data = getData(filename, true);
if (data.isNull())
return "";
std::string ret((const char*)data.getBytes());
return ret;
}

View File

@ -89,38 +89,43 @@ public class Cocos2dxHelper {
jobs.add(r);
}
private static boolean sInited = false;
public static void init(final Activity activity) {
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
initListener();
try {
// Get the lib_name from AndroidManifest.xml metadata
ActivityInfo ai =
activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA);
if (null != ai.metaData) {
String lib_name = ai.metaData.getString(META_DATA_LIB_NAME);
if (null != lib_name) {
System.loadLibrary(lib_name);
} else {
System.loadLibrary(DEFAULT_LIB_NAME);
if (!sInited) {
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
initListener();
try {
// Get the lib_name from AndroidManifest.xml metadata
ActivityInfo ai =
activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA);
if (null != ai.metaData) {
String lib_name = ai.metaData.getString(META_DATA_LIB_NAME);
if (null != lib_name) {
System.loadLibrary(lib_name);
} else {
System.loadLibrary(DEFAULT_LIB_NAME);
}
}
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("Error getting activity info", e);
}
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("Error getting activity info", e);
}
Cocos2dxHelper.sPackageName = applicationInfo.packageName;
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
Cocos2dxHelper.sAssetManager = activity.getAssets();
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
Cocos2dxBitmap.setContext(activity);
sActivity = activity;
Cocos2dxHelper.sPackageName = applicationInfo.packageName;
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
Cocos2dxHelper.sAssetManager = activity.getAssets();
//Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
Cocos2dxBitmap.setContext(activity);
sActivity = activity;
sInited = true;
}
}
public static void initListener() {

View File

@ -56,7 +56,7 @@ public:
//TODO use material to decide if it is translucent
inline bool isTranslucent() const { return true; }
inline int32_t getMaterialID() const { return _materialID; }
inline uint32_t getMaterialID() const { return _materialID; }
inline GLuint getTextureID() const { return _textureID; }
@ -71,7 +71,7 @@ public:
inline const kmMat4& getModelView() const { return _mv; }
protected:
int32_t _materialID;
uint32_t _materialID;
//Key Data
int _viewport; /// Which view port it belongs to

View File

@ -50,9 +50,10 @@ public:
virtual int64_t generateID() = 0;
/** Get Render Command Id */
virtual inline int64_t getID() { return _id; }
virtual inline Type getType() { return _type; }
inline int64_t getID() { return _id; }
/** Returns the Command type */
inline Type getType() { return _type; }
protected:
RenderCommand();

View File

@ -249,7 +249,7 @@ void Renderer::render()
//Batch quads
if(_numQuads + cmdQuadCount > VBO_SIZE)
{
CCASSERT(cmdQuadCount < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
CCASSERT(cmdQuadCount>=0 && cmdQuadCount<VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
//Draw batched quads if VBO is full
_lastCommand --;
@ -333,41 +333,17 @@ void Renderer::convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quanti
for(ssize_t i=0; i<quantity; ++i) {
V3F_C4B_T2F_Quad *q = &quads[i];
kmVec3 vec1, out1;
vec1.x = q->bl.vertices.x;
vec1.y = q->bl.vertices.y;
vec1.z = q->bl.vertices.z;
kmVec3Transform(&out1, &vec1, &modelView);
q->bl.vertices.x = out1.x;
q->bl.vertices.y = out1.y;
q->bl.vertices.z = out1.z;
kmVec3 *vec1 = (kmVec3*)&q->bl.vertices;
kmVec3Transform(vec1, vec1, &modelView);
kmVec3 vec2, out2;
vec2.x = q->br.vertices.x;
vec2.y = q->br.vertices.y;
vec2.z = q->br.vertices.z;
kmVec3Transform(&out2, &vec2, &modelView);
q->br.vertices.x = out2.x;
q->br.vertices.y = out2.y;
q->br.vertices.z = out2.z;
kmVec3 *vec2 = (kmVec3*)&q->br.vertices;
kmVec3Transform(vec2, vec2, &modelView);
kmVec3 vec3, out3;
vec3.x = q->tr.vertices.x;
vec3.y = q->tr.vertices.y;
vec3.z = q->tr.vertices.z;
kmVec3Transform(&out3, &vec3, &modelView);
q->tr.vertices.x = out3.x;
q->tr.vertices.y = out3.y;
q->tr.vertices.z = out3.z;
kmVec3 *vec3 = (kmVec3*)&q->tr.vertices;
kmVec3Transform(vec3, vec3, &modelView);
kmVec3 vec4, out4;
vec4.x = q->tl.vertices.x;
vec4.y = q->tl.vertices.y;
vec4.z = q->tl.vertices.z;
kmVec3Transform(&out4, &vec4, &modelView);
q->tl.vertices.x = out4.x;
q->tl.vertices.y = out4.y;
q->tl.vertices.z = out4.z;
kmVec3 *vec4 = (kmVec3*)&q->tl.vertices;
kmVec3Transform(vec4, vec4, &modelView);
}
}
@ -405,7 +381,7 @@ void Renderer::drawBatchedQuads()
#define kQuadSize sizeof(_quads[0].bl)
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_quads[0]) * _numQuads , _quads);
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _numQuads , _quads, GL_DYNAMIC_DRAW);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
@ -422,7 +398,7 @@ void Renderer::drawBatchedQuads()
}
//Start drawing verties in batch
for(size_t i = _firstCommand; i <= _lastCommand; i++)
for(ssize_t i = _firstCommand; i <= _lastCommand; i++)
{
RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i];
if (command->getType() == RenderCommand::Type::QUAD_COMMAND)

View File

@ -42,7 +42,7 @@ typedef std::vector<RenderCommand*> RenderQueue;
struct RenderStackElement
{
int renderQueueID;
size_t currentIndex;
ssize_t currentIndex;
};
class Renderer
@ -86,10 +86,10 @@ protected:
std::stack<RenderStackElement> _renderStack;
std::vector<RenderQueue> _renderGroups;
int _lastMaterialID;
uint32_t _lastMaterialID;
size_t _firstCommand;
size_t _lastCommand;
ssize_t _firstCommand;
ssize_t _lastCommand;
V3F_C4B_T2F_Quad _quads[VBO_SIZE];
GLushort _indices[6 * VBO_SIZE];

View File

@ -391,7 +391,7 @@ void Console::commandTextures(int fd, const char *command)
{
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [&](){
mydprintf(fd, "%s", TextureCache::getInstance()->getCachedTextureInfo().c_str());
mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
}
);
}

View File

@ -115,7 +115,7 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty)
anchorPoint = PointApplyTransform(anchorPoint, displayTransform);
displayTransform.mat[12] = anchorPoint.x;
displayTransform.mat[13] = anchorPoint.y;
kmMat4 t = TransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform());
kmMat4 t = TransformConcat( bone->getArmature()->getNodeToParentTransform(),displayTransform);
detector->updateTransform(t);
}
while (0);

View File

@ -197,7 +197,7 @@ void Skin::updateTransform()
kmMat4 Skin::getNodeToWorldTransform() const
{
return TransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform());
return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(), _transform);
}
kmMat4 Skin::getNodeToWorldTransformAR() const

@ -1 +1 @@
Subproject commit bab1d8a7c5d8b29f14c8dc19158a8bb994f0e970
Subproject commit 74cb897b64f7325cf969341e9bc2d87fc7fb1bb7

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -15,7 +15,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -121,6 +121,8 @@ Classes/PerformanceTest/PerformanceTest.cpp \
Classes/PerformanceTest/PerformanceTextureTest.cpp \
Classes/PerformanceTest/PerformanceTouchesTest.cpp \
Classes/PerformanceTest/PerformanceLabelTest.cpp \
Classes/PerformanceTest/PerformanceRendererTest.cpp \
Classes/PerformanceTest/PerformanceContainerTest.cpp \
Classes/PhysicsTest/PhysicsTest.cpp \
Classes/RenderTextureTest/RenderTextureTest.cpp \
Classes/RotateWorldTest/RotateWorldTest.cpp \

View File

@ -116,6 +116,8 @@ set(SAMPLE_SRC
Classes/PerformanceTest/PerformanceTextureTest.cpp
Classes/PerformanceTest/PerformanceTouchesTest.cpp
Classes/PerformanceTest/PerformanceLabelTest.cpp
Classes/PerformanceTest/PerformanceRendererTest.cpp
Classes/PerformanceTest/PerformanceContainerTest.cpp
Classes/PhysicsTest/PhysicsTest.cpp
Classes/RenderTextureTest/RenderTextureTest.cpp
Classes/RotateWorldTest/RotateWorldTest.cpp

View File

@ -1067,8 +1067,22 @@ void TestColliderDetector::update(float delta)
}
void TestColliderDetector::draw()
{
armature2->drawContour();
_customCommand.init(0, _vertexZ);
_customCommand.func = CC_CALLBACK_0(TestColliderDetector::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
}
void TestColliderDetector::onDraw()
{
kmMat4 oldMat;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
kmGLLoadMatrix(&_modelViewTransform);
armature2->drawContour();
kmGLLoadMatrix(&oldMat);
}
#endif

View File

@ -271,6 +271,7 @@ public:
virtual std::string title() const override;
virtual void update(float delta);
virtual void draw();
void onDraw();
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
@ -278,6 +279,7 @@ public:
cocostudio::Armature *armature;
cocostudio::Armature *armature2;
CustomCommand _customCommand; //new render needed this for drawing primitives
cocos2d::Sprite *bullet;
};
#endif

View File

@ -0,0 +1,711 @@
/*
*
*/
#include "PerformanceContainerTest.h"
#include <algorithm>
// Enable profiles for this file
#undef CC_PROFILER_DISPLAY_TIMERS
#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
#undef CC_PROFILER_PURGE_ALL
#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
#undef CC_PROFILER_START
#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
#undef CC_PROFILER_STOP
#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
#undef CC_PROFILER_RESET
#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
#undef CC_PROFILER_START_CATEGORY
#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)
#undef CC_PROFILER_STOP_CATEGORY
#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)
#undef CC_PROFILER_RESET_CATEGORY
#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)
#undef CC_PROFILER_START_INSTANCE
#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_STOP_INSTANCE
#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_RESET_INSTANCE
#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
static std::function<PerformanceContainerScene*()> createFunctions[] =
{
CL(TemplateVectorPerfTest),
CL(ArrayPerfTest)
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
enum {
kTagInfoLayer = 1,
kTagBase = 20000,
};
enum {
kMaxNodes = 15000,
kNodesIncrease = 500,
};
static int g_curCase = 0;
////////////////////////////////////////////////////////
//
// ContainerBasicLayer
//
////////////////////////////////////////////////////////
ContainerBasicLayer::ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
{
}
void ContainerBasicLayer::showCurrentTest()
{
int nodes = ((PerformanceContainerScene*)getParent())->getQuantityOfNodes();
auto scene = createFunctions[_curCase]();
g_curCase = _curCase;
if (scene)
{
scene->initWithQuantityOfNodes(nodes);
Director::getInstance()->replaceScene(scene);
}
}
////////////////////////////////////////////////////////
//
// PerformanceContainerScene
//
////////////////////////////////////////////////////////
void PerformanceContainerScene::initWithQuantityOfNodes(unsigned int nNodes)
{
_type = 0;
//srand(time());
auto s = Director::getInstance()->getWinSize();
// Title
auto label = LabelTTF::create(title().c_str(), "Arial", 40);
addChild(label, 1, TAG_TITLE);
label->setPosition(Point(s.width/2, s.height-32));
label->setColor(Color3B(255,255,40));
// Subtitle
std::string strSubTitle = subtitle();
if(strSubTitle.length())
{
auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16);
addChild(l, 1, TAG_SUBTITLE);
l->setPosition(Point(s.width/2, s.height-80));
}
lastRenderedCount = 0;
currentQuantityOfNodes = 0;
quantityOfNodes = nNodes;
MenuItemFont::setFontSize(65);
auto decrease = MenuItemFont::create(" - ", [&](Object *sender) {
quantityOfNodes -= kNodesIncrease;
if( quantityOfNodes < 0 )
quantityOfNodes = 0;
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL();
srand(0);
});
decrease->setColor(Color3B(0,200,20));
_decrease = decrease;
auto increase = MenuItemFont::create(" + ", [&](Object *sender) {
quantityOfNodes += kNodesIncrease;
if( quantityOfNodes > kMaxNodes )
quantityOfNodes = kMaxNodes;
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL();
srand(0);
});
increase->setColor(Color3B(0,200,20));
_increase = increase;
auto menu = Menu::create(decrease, increase, NULL);
menu->alignItemsHorizontally();
menu->setPosition(Point(s.width/2, s.height/2+15));
addChild(menu, 1);
auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30);
infoLabel->setColor(Color3B(0,200,20));
infoLabel->setPosition(Point(s.width/2, s.height/2-15));
addChild(infoLabel, 1, kTagInfoLayer);
auto menuLayer = new ContainerBasicLayer(true, MAX_LAYER, g_curCase);
addChild(menuLayer);
menuLayer->release();
printf("Size of Node: %lu\n", sizeof(Node));
int oldFontSize = MenuItemFont::getFontSize();
MenuItemFont::setFontSize(24);
Vector<cocos2d::MenuItem *> toggleItems;
generateTestFunctions();
CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions");
for (const auto& f : _testFunctions)
{
toggleItems.pushBack(MenuItemFont::create(f.name));
}
auto toggle = MenuItemToggle::createWithCallback([this](Object* sender){
auto toggle = static_cast<MenuItemToggle*>(sender);
this->_type = toggle->getSelectedIndex();
auto label = static_cast<LabelTTF*>(this->getChildByTag(TAG_SUBTITLE));
label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name));
this->updateProfilerName();
}, toggleItems);
toggle->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
toggle->setPosition(VisibleRect::left());
_toggle = toggle;
auto start = MenuItemFont::create("start", [this](Object* sender){
auto director = Director::getInstance();
auto sched = director->getScheduler();
CC_PROFILER_PURGE_ALL();
sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false);
this->unscheduleUpdate();
this->scheduleUpdate();
this->_startItem->setEnabled(false);
this->_stopItem->setEnabled(true);
this->_toggle->setEnabled(false);
this->_increase->setEnabled(false);
this->_decrease->setEnabled(false);
});
start->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT);
start->setPosition(VisibleRect::right() + Point(0, 40));
_startItem = start;
auto stop = MenuItemFont::create("stop", [this](Object* sender){
auto director = Director::getInstance();
auto sched = director->getScheduler();
sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this);
this->unscheduleUpdate();
this->_startItem->setEnabled(true);
this->_stopItem->setEnabled(false);
this->_toggle->setEnabled(true);
this->_increase->setEnabled(true);
this->_decrease->setEnabled(true);
});
stop->setEnabled(false);
stop->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT);
stop->setPosition(VisibleRect::right() + Point(0, -40));
_stopItem = stop;
auto menu2 = Menu::create(toggle, start, stop, NULL);
menu2->setPosition(Point::ZERO);
addChild(menu2);
MenuItemFont::setFontSize(oldFontSize);
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
}
std::string PerformanceContainerScene::title() const
{
return "No title";
}
std::string PerformanceContainerScene::subtitle() const
{
return "";
}
void PerformanceContainerScene::updateQuantityLabel()
{
if( quantityOfNodes != lastRenderedCount )
{
auto infoLabel = static_cast<LabelTTF*>( getChildByTag(kTagInfoLayer) );
char str[20] = {0};
sprintf(str, "%u nodes", quantityOfNodes);
infoLabel->setString(str);
lastRenderedCount = quantityOfNodes;
}
}
const char * PerformanceContainerScene::profilerName()
{
return _profilerName;
}
void PerformanceContainerScene::updateProfilerName()
{
snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes);
}
void PerformanceContainerScene::onExitTransitionDidStart()
{
Scene::onExitTransitionDidStart();
auto director = Director::getInstance();
auto sched = director->getScheduler();
sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this);
}
void PerformanceContainerScene::onEnterTransitionDidFinish()
{
Scene::onEnterTransitionDidFinish();
auto director = Director::getInstance();
auto sched = director->getScheduler();
CC_PROFILER_PURGE_ALL();
sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false);
}
void PerformanceContainerScene::dumpProfilerInfo(float dt)
{
CC_PROFILER_DISPLAY_TIMERS();
}
void PerformanceContainerScene::update(float dt)
{
_testFunctions[_type].func();
}
void PerformanceContainerScene::updateQuantityOfNodes()
{
currentQuantityOfNodes = quantityOfNodes;
}
const char* PerformanceContainerScene::testName()
{
return _testFunctions[_type].name;
}
////////////////////////////////////////////////////////
//
// TemplateVectorPerfTest
//
////////////////////////////////////////////////////////
void TemplateVectorPerfTest::generateTestFunctions()
{
auto createVector = [this](){
Vector<Node*> ret;
for( int i=0; i<quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(i);
ret.pushBack(node);
}
return ret;
};
TestFunction testFunctions[] = {
{ "pushBack", [=](){
Vector<Node*> nodeVector;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.pushBack(Node::create());
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "insert", [=](){
Vector<Node*> nodeVector;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.insert(0, Node::create());
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "replace", [=](){
Vector<Node*> nodeVector = createVector();
srand(time(nullptr));
ssize_t index = rand() % quantityOfNodes;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.replace(index, Node::create());
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "getIndex", [=](){
Vector<Node*> nodeVector = createVector();
Node* objToGet = nodeVector.at(quantityOfNodes/3);
ssize_t index = 0;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
index = nodeVector.getIndex(objToGet);
CC_PROFILER_STOP(this->profilerName());
// Uses `index` to avoids `getIndex` invoking was optimized in release mode
if (index == quantityOfNodes/3)
{
nodeVector.clear();
}
} } ,
{ "find", [=](){
Vector<Node*> nodeVector = createVector();
Node* objToGet = nodeVector.at(quantityOfNodes/3);
Vector<Node*>::iterator iter;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
iter = nodeVector.find(objToGet);
CC_PROFILER_STOP(this->profilerName());
// Uses `iter` to avoids `find` invoking was optimized in release mode
if (*iter == objToGet)
{
nodeVector.clear();
}
} } ,
{ "at", [=](){
Vector<Node*> nodeVector = createVector();
Node* objToGet = nullptr;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
objToGet = nodeVector.at(quantityOfNodes/3);
CC_PROFILER_STOP(this->profilerName());
// Uses `objToGet` to avoids `at` invoking was optimized in release mode
if (nodeVector.getIndex(objToGet) == quantityOfNodes/3)
{
nodeVector.clear();
}
} } ,
{ "contains", [=](){
Vector<Node*> nodeVector = createVector();
Node* objToGet = nodeVector.at(quantityOfNodes/3);
bool ret = false;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
ret = nodeVector.contains(objToGet);
CC_PROFILER_STOP(this->profilerName());
// Uses `ret` to avoids `contains` invoking was optimized in release mode
if (ret)
{
nodeVector.clear();
}
} } ,
{ "eraseObject", [=](){
Vector<Node*> nodeVector = createVector();
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
for (int i = 0; i < quantityOfNodes; ++i)
{
nodes[i] = nodeVector.at(i);
}
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.eraseObject(nodes[i]);
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector.empty(), "nodeVector was not empty.");
free(nodes);
} } ,
{ "erase", [=](){
Vector<Node*> nodeVector = createVector();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.erase(nodeVector.begin());
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector.empty(), "nodeVector was not empty.");
} } ,
{ "clear", [=](){
Vector<Node*> nodeVector = createVector();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.clear();
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector.empty(), "nodeVector was not empty.");
} } ,
{ "swap by index", [=](){
Vector<Node*> nodeVector = createVector();
int swapIndex1 = quantityOfNodes / 3;
int swapIndex2 = quantityOfNodes / 3 * 2;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.swap(swapIndex1, swapIndex2);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "swap by object", [=](){
Vector<Node*> nodeVector = createVector();
Node* swapNode1 = nodeVector.at(quantityOfNodes / 3);
Node* swapNode2 = nodeVector.at(quantityOfNodes / 3 * 2);
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.swap(swapNode1, swapNode2);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "reverse", [=](){
Vector<Node*> nodeVector = createVector();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector.reverse();
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "c++11 Range Loop", [=](){
Vector<Node*> nodeVector = createVector();
CC_PROFILER_START(this->profilerName());
for (const auto& e : nodeVector)
{
e->setTag(111);
}
CC_PROFILER_STOP(this->profilerName());
} } ,
};
for (const auto& func : testFunctions)
{
_testFunctions.push_back(func);
}
}
std::string TemplateVectorPerfTest::title() const
{
return "Vector<T> Perf test";
}
std::string TemplateVectorPerfTest::subtitle() const
{
return "Test 'pushBack', See console";
}
////////////////////////////////////////////////////////
//
// ArrayPerfTest
//
////////////////////////////////////////////////////////
std::string ArrayPerfTest::title() const
{
return "Array Perf test";
}
std::string ArrayPerfTest::subtitle() const
{
return "Test `addObject`, See console";
}
void ArrayPerfTest::generateTestFunctions()
{
auto createArray = [this](){
Array* ret = Array::create();
for( int i=0; i<quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(i);
ret->addObject(node);
}
return ret;
};
TestFunction testFunctions[] = {
{ "addObject", [=](){
Array* nodeVector = Array::create();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->addObject(Node::create());
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "insertObject", [=](){
Array* nodeVector = Array::create();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->insertObject(Node::create(), 0);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "setObject", [=](){
Array* nodeVector = createArray();
srand(time(nullptr));
ssize_t index = rand() % quantityOfNodes;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->setObject(Node::create(), index);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "getIndexOfObject", [=](){
Array* nodeVector = createArray();
Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3);
ssize_t index = 0;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
index = nodeVector->getIndexOfObject(objToGet);
CC_PROFILER_STOP(this->profilerName());
// Uses `index` to avoids `getIndex` invoking was optimized in release mode
if (index == quantityOfNodes/3)
{
nodeVector->removeAllObjects();
}
} } ,
{ "getObjectAtIndex", [=](){
Array* nodeVector = createArray();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->getObjectAtIndex(quantityOfNodes/3);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "containsObject", [=](){
Array* nodeVector = createArray();
Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3);
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->containsObject(objToGet);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "removeObject", [=](){
Array* nodeVector = createArray();
Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes);
for (int i = 0; i < quantityOfNodes; ++i)
{
nodes[i] = static_cast<Node*>(nodeVector->getObjectAtIndex(i));
}
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->removeObject(nodes[i]);
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector->count() == 0, "nodeVector was not empty.");
free(nodes);
} } ,
{ "removeObjectAtIndex", [=](){
Array* nodeVector = createArray();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->removeObjectAtIndex(0);
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector->count() == 0, "nodeVector was not empty.");
} } ,
{ "removeAllObjects", [=](){
Array* nodeVector = createArray();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->removeAllObjects();
CC_PROFILER_STOP(this->profilerName());
CCASSERT(nodeVector->count() == 0, "nodeVector was not empty.");
} } ,
{ "swap by index", [=](){
Array* nodeVector = createArray();
int swapIndex1 = quantityOfNodes / 3;
int swapIndex2 = quantityOfNodes / 3 * 2;
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->swap(swapIndex1, swapIndex2);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "swap by object", [=](){
Array* nodeVector = createArray();
Object* swapNode1 = nodeVector->getObjectAtIndex(quantityOfNodes / 3);
Object* swapNode2 = nodeVector->getObjectAtIndex(quantityOfNodes / 3 * 2);
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->exchangeObject(swapNode1, swapNode2);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "reverseObjects", [=](){
Array* nodeVector = createArray();
CC_PROFILER_START(this->profilerName());
for( int i=0; i<quantityOfNodes; ++i)
nodeVector->reverseObjects();
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "CCARRAY_FOREACH", [=](){
Array* nodeVector = createArray();
Object* obj;
CC_PROFILER_START(this->profilerName());
CCARRAY_FOREACH(nodeVector, obj)
{
static_cast<Node*>(obj)->setTag(111);
}
CC_PROFILER_STOP(this->profilerName());
} } ,
};
for (const auto& func : testFunctions)
{
_testFunctions.push_back(func);
}
}
///----------------------------------------
void runContainerPerformanceTest()
{
auto scene = createFunctions[g_curCase]();
scene->initWithQuantityOfNodes(kNodesIncrease);
Director::getInstance()->replaceScene(scene);
}

View File

@ -0,0 +1,91 @@
/*
*
*/
#ifndef __PERFORMANCE_CONTAINER_TEST_H__
#define __PERFORMANCE_CONTAINER_TEST_H__
#include "PerformanceTest.h"
#include "CCProfiling.h"
class ContainerBasicLayer : public PerformBasicLayer
{
public:
ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0);
virtual void showCurrentTest();
};
class PerformanceContainerScene : public Scene
{
public:
static const int TAG_TITLE = 100;
static const int TAG_SUBTITLE = 101;
struct TestFunction
{
const char* name;
std::function<void()> func;
};
virtual void initWithQuantityOfNodes(unsigned int nNodes);
virtual void generateTestFunctions() = 0;
virtual std::string title() const;
virtual std::string subtitle() const;
virtual void updateQuantityOfNodes();
const char* profilerName();
void updateProfilerName();
// for the profiler
virtual const char* testName();
void updateQuantityLabel();
int getQuantityOfNodes() { return quantityOfNodes; }
void dumpProfilerInfo(float dt);
// overrides
virtual void onExitTransitionDidStart() override;
virtual void onEnterTransitionDidFinish() override;
virtual void update(float dt) override;
protected:
char _profilerName[256];
int lastRenderedCount;
int quantityOfNodes;
int currentQuantityOfNodes;
unsigned int _type;
std::vector<TestFunction> _testFunctions;
MenuItemFont* _increase;
MenuItemFont* _decrease;
MenuItemFont* _startItem;
MenuItemFont* _stopItem;
MenuItemToggle* _toggle;
};
class TemplateVectorPerfTest : public PerformanceContainerScene
{
public:
CREATE_FUNC(TemplateVectorPerfTest);
virtual void generateTestFunctions() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class ArrayPerfTest : public PerformanceContainerScene
{
public:
CREATE_FUNC(ArrayPerfTest);
virtual void generateTestFunctions() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
void runContainerPerformanceTest();
#endif // __PERFORMANCE_CONTAINER_TEST_H__

View File

@ -0,0 +1,55 @@
//
// PerformanceRendererTest.cpp
// cocos2d_samples
//
// Created by Huabing on 1/10/14.
//
//
#include "PerformanceRendererTest.h"
#include "PerformanceTextureTest.h"
#include "../testResource.h"
RenderTestLayer::RenderTestLayer()
: PerformBasicLayer(true, 1, 1)
{
}
RenderTestLayer::~RenderTestLayer()
{
}
Scene* RenderTestLayer::scene()
{
auto scene = Scene::create();
RenderTestLayer *layer = new RenderTestLayer();
scene->addChild(layer);
layer->release();
return scene;
}
void RenderTestLayer::onEnter()
{
PerformBasicLayer::onEnter();
auto map = TMXTiledMap::create("TileMaps/map/sl.tmx");
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
addChild(map,-1);
//map->setAnchorPoint( Point(0, 0) );
//map->setPosition( Point(-20,-200) );
}
void RenderTestLayer::showCurrentTest()
{
}
void runRendererTest()
{
auto scene = RenderTestLayer::scene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -0,0 +1,28 @@
//
// PerformanceRendererTest.h
// cocos2d_samples
//
// Created by Huabing on 1/10/14.
//
//
#ifndef __PERFORMANCE_RENDERER_TEST_H__
#define __PERFORMANCE_RENDERER_TEST_H__
#include "PerformanceTest.h"
class RenderTestLayer : public PerformBasicLayer
{
public:
RenderTestLayer();
virtual ~RenderTestLayer();
virtual void onEnter() override;
virtual void showCurrentTest() override;
public:
static Scene* scene();
};
void runRendererTest();
#endif

View File

@ -48,11 +48,7 @@ enum {
////////////////////////////////////////////////////////
SubTest::~SubTest()
{
if (_batchNode)
{
_batchNode->release();
_batchNode = NULL;
}
_parentNode->release();
}
void SubTest::initWithSubTest(int subtest, Node* p)
@ -60,12 +56,11 @@ void SubTest::initWithSubTest(int subtest, Node* p)
srand(0);
subtestNumber = subtest;
_parent = p;
_batchNode = nullptr;
_parentNode = nullptr;
/*
* Tests:
* 1: 1 (32-bit) PNG sprite of 52 x 139
* 2: 1 (32-bit) PNG sprite of 52 x 139
* 2: 1 (32-bit) PNG sprite of 52 x 139 (same as 1)
* 3: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
* 4: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
@ -90,73 +85,67 @@ void SubTest::initWithSubTest(int subtest, Node* p)
{
///
case 1:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
break;
case 2:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = Node::create();
break;
case 3:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(_batchNode, 0);
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
break;
case 4:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(_batchNode, 0);
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
break;
///
case 5:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
break;
case 6:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
_parentNode = Node::create();
break;
case 7:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(_batchNode, 0);
break;
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
break;
case 8:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(_batchNode, 0);
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
break;
///
case 9:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
break;
case 10:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
_parentNode = Node::create();
break;
case 11:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(_batchNode, 0);
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
break;
case 12:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(_batchNode, 0);
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
break;
///
case 13:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_parentNode = Node::create();
break;
default:
break;
}
if (_batchNode)
{
_batchNode->retain();
}
p->addChild(_parentNode);
_parentNode->retain();
}
Sprite* SubTest::createSpriteWithTag(int tag)
{
TextureCache *cache = Director::getInstance()->getTextureCache();
Sprite* sprite = NULL;
switch (subtestNumber)
{
@ -165,14 +154,15 @@ Sprite* SubTest::createSpriteWithTag(int tag)
case 2:
{
sprite = Sprite::create("Images/grossinis_sister1.png");
_parent->addChild(sprite, 0, tag+100);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 3:
case 4:
{
sprite = Sprite::createWithTexture(_batchNode->getTexture(), Rect(0, 0, 52, 139));
_batchNode->addChild(sprite, 0, tag+100);
Texture2D *texture = cache->addImage("Images/grossinis_sister1.png");
sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
@ -183,24 +173,10 @@ Sprite* SubTest::createSpriteWithTag(int tag)
char str[32] = {0};
sprintf(str, "Images/grossini_dance_%02d.png", idx);
sprite = Sprite::create(str);
_parent->addChild(sprite, 0, tag+100);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 6:
{
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
y = r / 5;
x = r % 5;
x *= 85;
y *= 121;
sprite = Sprite::createWithTexture(_batchNode->getTexture(), Rect(x,y,85,121));
_parent->addChild(sprite, 0, tag+100);
break;
}
case 7:
case 8:
{
@ -212,8 +188,9 @@ Sprite* SubTest::createSpriteWithTag(int tag)
x *= 85;
y *= 121;
sprite = Sprite::createWithTexture(_batchNode->getTexture(), Rect(x,y,85,121));
_batchNode->addChild(sprite, 0, tag+100);
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
@ -229,25 +206,11 @@ Sprite* SubTest::createSpriteWithTag(int tag)
char str[40] = {0};
sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y);
sprite = Sprite::create(str);
_parent->addChild(sprite, 0, tag+100);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 10:
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
x *= 32;
y *= 32;
sprite = Sprite::createWithTexture(_batchNode->getTexture(), CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parent->addChild(sprite, 0, tag+100);
break;
}
case 11:
case 12:
{
@ -259,10 +222,52 @@ Sprite* SubTest::createSpriteWithTag(int tag)
x *= 32;
y *= 32;
sprite = Sprite::createWithTexture(_batchNode->getTexture(), CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_batchNode->addChild(sprite, 0, tag+100);
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 13:
{
int test = (CCRANDOM_0_1() * 3);
if(test==0) {
// Switch case 1
sprite = Sprite::create("Images/grossinis_sister1.png");
_parentNode->addChild(sprite, 0, tag+100);
}
else if(test==1)
{
// Switch case 6
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
y = r / 5;
x = r % 5;
x *= 85;
y *= 121;
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
_parentNode->addChild(sprite, 0, tag+100);
}
else if(test==2)
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
x *= 32;
y *= 32;
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parentNode->addChild(sprite, 0, tag+100);
}
}
default:
break;
@ -273,30 +278,7 @@ Sprite* SubTest::createSpriteWithTag(int tag)
void SubTest::removeByTag(int tag)
{
switch (subtestNumber)
{
case 1:
case 5:
case 9:
_parent->removeChildByTag(tag+100, true);
break;
case 2:
case 3:
case 4:
case 6:
case 7:
case 8:
case 10:
case 11:
case 12:
_batchNode->removeChildByTag(tag+100, true);
break;
default:
break;
}
_parentNode->removeChildByTag(tag+100, true);
}
////////////////////////////////////////////////////////
@ -443,9 +425,9 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
addChild( menuAutoTest, 3, kTagAutoTestMenu );
// Sub Tests
MenuItemFont::setFontSize(32);
MenuItemFont::setFontSize(28);
auto subMenu = Menu::create();
for (int i = 1; i <= 12; ++i)
for (int i = 1; i <= 13; ++i)
{
char str[10] = {0};
sprintf(str, "%d ", i);
@ -457,8 +439,10 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
itemFont->setColor(Color3B(200,20,20));
else if(i <= 8)
itemFont->setColor(Color3B(0,200,20));
else
else if( i<=12)
itemFont->setColor(Color3B(0,20,200));
else
itemFont->setColor(Color3B::GRAY);
}
subMenu->alignItemsHorizontally();

View File

@ -40,8 +40,7 @@ public:
protected:
int subtestNumber;
SpriteBatchNode *_batchNode;
Node* _parent;
Node *_parentNode;
};
class SpriteMenuLayer : public PerformBasicLayer

View File

@ -7,6 +7,8 @@
#include "PerformanceTouchesTest.h"
#include "PerformanceAllocTest.h"
#include "PerformanceLabelTest.h"
#include "PerformanceRendererTest.h"
#include "PerformanceContainerTest.h"
enum
{
@ -26,6 +28,8 @@ struct {
{ "Texture Perf Test",[](Object*sender){runTextureTest();} },
{ "Touches Perf Test",[](Object*sender){runTouchesTest();} },
{ "Label Perf Test",[](Object*sender){runLabelTest();} },
{ "Renderer Perf Test",[](Object*sender){runRendererTest();} },
{ "Container Perf Test", [](Object* sender ) { runContainerPerformanceTest(); } }
};
static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]);
@ -41,18 +45,83 @@ void PerformanceMainLayer::onEnter()
auto s = Director::getInstance()->getWinSize();
auto menu = Menu::create();
menu->setPosition( Point::ZERO );
_itemMenu = Menu::create();
_itemMenu->setPosition( Point::ZERO );
MenuItemFont::setFontName("Arial");
MenuItemFont::setFontSize(24);
for (int i = 0; i < g_testMax; ++i)
{
auto pItem = MenuItemFont::create(g_testsName[i].name, g_testsName[i].callback);
pItem->setPosition(Point(s.width / 2, s.height - (i + 1) * LINE_SPACE));
menu->addChild(pItem, kItemTagBasic + i);
_itemMenu->addChild(pItem, kItemTagBasic + i);
}
addChild(menu);
addChild(_itemMenu);
// Register Touch Event
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(PerformanceMainLayer::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(PerformanceMainLayer::onTouchMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto mouseListener = EventListenerMouse::create();
mouseListener->onMouseScroll = CC_CALLBACK_1(PerformanceMainLayer::onMouseScroll, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
}
bool PerformanceMainLayer::onTouchBegan(Touch* touches, Event *event)
{
_beginPos = touches->getLocation();
return true;
}
void PerformanceMainLayer::onTouchMoved(Touch* touches, Event *event)
{
auto touchLocation = touches->getLocation();
float nMoveY = touchLocation.y - _beginPos.y;
auto curPos = _itemMenu->getPosition();
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
if (nextPos.y < 0.0f)
{
_itemMenu->setPosition(Point::ZERO);
return;
}
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
{
_itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
return;
}
_itemMenu->setPosition(nextPos);
_beginPos = touchLocation;
}
void PerformanceMainLayer::onMouseScroll(Event *event)
{
auto mouseEvent = static_cast<EventMouse*>(event);
float nMoveY = mouseEvent->getScrollY() * 6;
auto curPos = _itemMenu->getPosition();
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
if (nextPos.y < 0.0f)
{
_itemMenu->setPosition(Point::ZERO);
return;
}
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
{
_itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
return;
}
_itemMenu->setPosition(nextPos);
}
////////////////////////////////////////////////////////

View File

@ -7,6 +7,14 @@ class PerformanceMainLayer : public Layer
{
public:
virtual void onEnter();
bool onTouchBegan(Touch* touches, Event *event);
void onTouchMoved(Touch* touches, Event *event);
void onMouseScroll(Event *event);
protected:
Point _beginPos;
Menu* _itemMenu;
};
class PerformBasicLayer : public Layer

View File

@ -0,0 +1 @@
64ce8a88d0dee73cf5d9fbb8f3c80673c82b9575

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -186,7 +186,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$
<ClCompile Include="..\Classes\NewEventDispatcherTest\NewEventDispatcherTest.cpp" />
<ClCompile Include="..\Classes\NewRendererTest\NewRendererTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceAllocTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceContainerTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceLabelTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceRendererTest.cpp" />
<ClCompile Include="..\Classes\PhysicsTest\PhysicsTest.cpp" />
<ClCompile Include="..\Classes\ShaderTest\ShaderTest2.cpp" />
<ClCompile Include="..\Classes\SpineTest\SpineTest.cpp" />
@ -331,7 +333,10 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$
<ClInclude Include="..\Classes\LabelTest\LabelTestNew.h" />
<ClInclude Include="..\Classes\NewEventDispatcherTest\NewEventDispatcherTest.h" />
<ClInclude Include="..\Classes\NewRendererTest\NewRendererTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceAllocTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceContainerTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceLabelTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceRendererTest.h" />
<ClInclude Include="..\Classes\PhysicsTest\PhysicsTest.h" />
<ClInclude Include="..\Classes\ShaderTest\ShaderTest2.h" />
<ClInclude Include="..\Classes\SpineTest\SpineTest.h" />

View File

@ -715,6 +715,12 @@
<ClCompile Include="..\Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode\cons.cpp">
<Filter>Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode</Filter>
</ClCompile>
<ClCompile Include="..\Classes\PerformanceTest\PerformanceRendererTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\Classes\PerformanceTest\PerformanceContainerTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
@ -1318,5 +1324,14 @@
<ClInclude Include="..\Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode\EventDef.h">
<Filter>Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode</Filter>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceRendererTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceAllocTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceContainerTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -16,7 +16,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -15,7 +15,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -14,7 +14,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize|smallestScreenSize">
android:configChanges="orientation">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"

View File

@ -0,0 +1,79 @@
#Github pull reqest builder for Jenkins
import json
import re
import os
import requests
import sys
import traceback
def main():
#get payload from os env
payload_str = os.environ['payload']
#parse to json obj
payload = json.loads(payload_str)
#get pull number
pr_num = payload['number']
print 'pr_num:' + str(pr_num)
#build for pull request action 'open' and 'synchronize', skip 'close'
action = payload['action']
print 'action: ' + action
pr = payload['pull_request']
url = pr['html_url']
print "url:" + url
#get statuses url
statuses_url = pr['statuses_url']
#get pr target branch
branch = pr['base']['ref']
#set commit status to pending
target_url = os.environ['BUILD_URL']
if(action == 'closed'):
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered'
return(0)
r = requests.get(pr['url']+"/commits")
commits = r.json()
last_commit = commits[len(commits)-1]
message = last_commit['commit']['message']
pattern = re.compile("\[ci(\s+)skip\]", re.I)
result = pattern.search(message)
if result is not None:
print 'skip build for pull request #' + str(pr_num)
return(0)
data = {"state":"pending", "target_url":target_url}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}
try:
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
except:
traceback.print_exc()
job_trigger_url = os.environ['JOB_TRIGGER_URL']+access_token
#send trigger and payload
post_data = {'payload':""}
post_data['payload']= payload_str
requests.post(job_trigger_url, data=post_data)
return(0)
# -------------- main --------------
if __name__ == '__main__':
sys_ret = 0
try:
sys_ret = main()
except:
traceback.print_exc()
sys_ret = 1
finally:
sys.exit(sys_ret)

View File

@ -57,7 +57,7 @@ def main():
set_description(pr_desc, target_url)
if((action != 'opened') and (action != 'synchronize')):
if(action == 'closed'):
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered'
return(0)