From 8e9928ad9934ed16ab0bfa10e54c63e590f3bb71 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 11 Sep 2015 10:53:17 +0800 Subject: [PATCH 1/2] Remove performance tests from lua-tests & js-tests. --- .../PerformanceAnimationTest.js | 240 -- .../PerformanceNodeChildrenTest.js | 524 ----- .../PerformanceParticleTest.js | 526 ----- .../PerformanceTest/PerformanceSpriteTest.js | 606 ----- .../PerformanceTest/PerformanceSpriteTest2.js | 305 --- .../src/PerformanceTest/PerformanceTest.js | 199 -- .../PerformanceTest/PerformanceTextureTest.js | 184 -- .../PerformanceTest/PerformanceTouchesTest.js | 165 -- .../PerformanceVirtualMachineTest.js | 550 ----- .../src/PerformanceTest/seedrandom.js | 272 --- tests/js-tests/src/tests-main.js | 9 - .../PerformanceTest/PerformanceSpriteTest.lua | 552 ----- .../src/PerformanceTest/PerformanceTest.lua | 1950 ----------------- tests/lua-tests/src/mainMenu.lua | 2 - 14 files changed, 6084 deletions(-) delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceAnimationTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceNodeChildrenTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceParticleTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceSpriteTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceSpriteTest2.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceTextureTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceTouchesTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/PerformanceVirtualMachineTest.js delete mode 100644 tests/js-tests/src/PerformanceTest/seedrandom.js delete mode 100644 tests/lua-tests/src/PerformanceTest/PerformanceSpriteTest.lua delete mode 100644 tests/lua-tests/src/PerformanceTest/PerformanceTest.lua diff --git a/tests/js-tests/src/PerformanceTest/PerformanceAnimationTest.js b/tests/js-tests/src/PerformanceTest/PerformanceAnimationTest.js deleted file mode 100644 index a8e5939a5f..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceAnimationTest.js +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var s_nAnimationCurCase = 0; -//////////////////////////////////////////////////////// -// -// AnimationLayer -// -//////////////////////////////////////////////////////// -var AnimationMenuLayer = PerformBasicLayer.extend({ - showCurrentTest:function () { - var scene = null; - switch (this._curCase) { - case 0: - scene = AnimationTest.scene(); - break; - } - s_nAnimationCurCase = this._curCase; - - if (scene) { - cc.director.runScene(scene); - } - }, - - onEnter:function () { - this._super(); - - var s = cc.director.getWinSize(); - - // Title - var label = new cc.LabelTTF(this.title(), "Arial", 40); - this.addChild(label, 1); - label.x = s.width / 2; - label.y = s.height - 32; - label.color = cc.color(255, 255, 40); - - // Subtitle - var strSubTitle = this.subtitle(); - if (strSubTitle.length) { - var l = new cc.LabelTTF(strSubTitle, "Thonburi", 16); - this.addChild(l, 1); - l.x = s.width / 2; - l.y = s.height - 80; - } - - }, - title:function () { - return "no title"; - }, - subtitle:function () { - return "no subtitle"; - }, - performTests:function () { - - } -}); - -//////////////////////////////////////////////////////// -// -// AnimationTest -// -//////////////////////////////////////////////////////// -var AnimationTest = AnimationMenuLayer.extend({ - numNodes:null, - lastRenderedCount:null, - moveLayerList:null, - init:function () { - this._super(); - - var size = cc.director.getWinSize(); - - cc.MenuItemFont.setFontSize(65); - var decrease = new cc.MenuItemFont(" - ", this.onDecrease, this); - decrease.color = cc.color(0, 200, 20); - var increase = new cc.MenuItemFont(" + ", this.onIncrease, this); - increase.color = cc.color(0, 200, 20); - - var menu = new cc.Menu(decrease, increase); - menu.alignItemsHorizontally(); - menu.x = size.width / 2; - menu.y = size.height / 2 + 100; - this.addChild(menu, 1); - - var infoLabel = new cc.LabelTTF("0 nodes", "Marker Felt", 24); - infoLabel.color = cc.color(0, 200, 20); - infoLabel.x = size.width / 2; - infoLabel.y = size.height - 90; - this.addChild(infoLabel, 1, TAG_INFO_LAYER); - this.numNodes = 0; - this.moveLayerList = []; - this.createMovieClip(); - //this.scheduleUpdate(); - }, - performTests:function () { - this.init(); - }, - title:function () { - return "Animation Performance Test"; - }, - subtitle:function () { - return ""; - }, - createMovieClip:function () { - var moveLayer = new cc.Node(); - this.addChild(moveLayer); - this.moveLayerList.push(moveLayer); - var size = cc.director.getWinSize(); - for(var i=0; i<10; i++) { - var character = new CharacterView(); - character.init(); - character.x = size.width /2 - i*15 - 200; - character.y = size.height /2 - i*15; - this.numNodes++; - cc.log("create"+this.numNodes); - moveLayer.addChild(character, 0, this.numNodes); - } - var action = cc.moveBy(1, cc.p(20,0)); - moveLayer.runAction(action.repeatForever()); - this.updateNodes(); - }, - onIncrease:function () { - this.createMovieClip(); - }, - onDecrease:function () { - if(this.numNodes > 0) { - var moveLayer = this.moveLayerList[this.moveLayerList.length-1]; - for(var i=0;i<10;i++) { - cc.log("remove"+this.numNodes); - moveLayer.removeChildByTag(this.numNodes, true); - this.numNodes--; - } - moveLayer.removeFromParent(true); - this.moveLayerList.pop(); - } - this.updateNodes(); - }, - updateNodes:function () { - if (this.numNodes != this.lastRenderedCount) { - var infoLabel = this.getChildByTag(TAG_INFO_LAYER); - var str = this.numNodes + " nodes"; - infoLabel.setString(str); - - this.lastRenderedCount = this.numNodes; - } - } -}); - -var CharacterView = cc.Node.extend({ - leftData:null, - leftItem:null, - rightData:null, - rightItem:null, - leftX:null, - - init: function() { - this._super(); - cc.spriteFrameCache.addSpriteFrames("animations/crystals.plist"); - var i = 0; - rightData = new Array(10); - for (i = 0; i < 10; i++) { - var right = new cc.Sprite("#crystals/4.png"); - right.x = 50; - right.y = i * 10 - 40; - right.rotation = -90; - right.scale = 1; - this.addChild(right); - - rightData[i] = right; - if (i == 0) { - rightItem = right; - } - } - - for(i=0; i<10; i++){ - var head = new cc.Sprite("#crystals/1.png"); - head.x = i * 5; - head.y = 50; - this.addChild(head); - head.scale = 1.5; - head.rotation = 350; - var rotateToA = cc.rotateBy(0.01, 5); - head.runAction(rotateToA.repeatForever()); - } - - leftData = new Array(10); - for(i=0; i<10; i++){ - var left = new cc.Sprite("#crystals/2.png"); - left.x = 10; - left.y = i * 5 - 20; - left.rotation = 90; - this.addChild(left); - //var moveStep = cc.moveBy(0.01, cc.p(-5,0)); - // left.runAction(moveStep); - leftData[i] = left; - if(i==0){ - leftItem = left; - } - } - - }, - - setDistance: function(){ - leftX = leftItem.x; - } -}); - -AnimationTest.scene = function () { - var scene = new cc.Scene(); - var layer = new AnimationTest(false, 1, s_nAnimationCurCase); - scene.addChild(layer); - return scene; -}; -function runAnimationTest() { - s_nAnimationCurCase = 0; - var scene = AnimationTest.scene(); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/PerformanceNodeChildrenTest.js b/tests/js-tests/src/PerformanceTest/PerformanceNodeChildrenTest.js deleted file mode 100644 index c0a7528f14..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceNodeChildrenTest.js +++ /dev/null @@ -1,524 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var TAG_BASE = 2000; -var MAX_NODES = 1500; -var NODES_INCREASE = 50; -var s_nCurCase = 0; - -//////////////////////////////////////////////////////// -// -// NodeChildrenMenuLayer -// -//////////////////////////////////////////////////////// -var NodeChildrenMenuLayer = PerformBasicLayer.extend({ - _maxCases:4, - showCurrentTest:function () { - var nodes = (this.parent).getQuantityOfNodes(); - var scene = null; - switch (this._curCase) { - case 0: - scene = new IterateSpriteSheetCArray(); - break; - case 1: - scene = new AddSpriteSheet(); - break; - case 2: - scene = new RemoveSpriteSheet(); - break; - case 3: - scene = new ReorderSpriteSheet(); - break; - } - s_nCurCase = this._curCase; - - if (scene) { - scene.initWithQuantityOfNodes(nodes); - cc.director.runScene(scene); - } - } -}); - -//////////////////////////////////////////////////////// -// -// NodeChildrenMainScene -// -//////////////////////////////////////////////////////// -var NodeChildrenMainScene = cc.Scene.extend({ - _lastRenderedCount:null, - _quantityOfNodes:null, - _currentQuantityOfNodes:null, - - ctor:function() { - this._super(); - this.init(); - }, - - initWithQuantityOfNodes:function (nodes) { - //srand(time()); - var s = cc.director.getWinSize(); - - // Title - var label = new cc.LabelTTF(this.title(), "Arial", 40); - this.addChild(label, 1); - label.x = s.width / 2; - label.y = s.height - 32; - label.color = cc.color(255, 255, 40); - - // Subtitle - var strSubTitle = this.subtitle(); - if (strSubTitle.length) { - var l = new cc.LabelTTF(strSubTitle, "Thonburi", 16); - this.addChild(l, 1); - l.x = s.width / 2; - l.y = s.height - 80; - } - - this._lastRenderedCount = 0; - this._currentQuantityOfNodes = 0; - this._quantityOfNodes = nodes; - - cc.MenuItemFont.setFontSize(65); - var that = this; - var decrease = new cc.MenuItemFont(" - ", this.onDecrease, this); - decrease.color = cc.color(0, 200, 20); - var increase = new cc.MenuItemFont(" + ", this.onIncrease, this); - increase.color = cc.color(0, 200, 20); - - var menu = new cc.Menu(decrease, increase); - menu.alignItemsHorizontally(); - menu.x = s.width / 2; - menu.y = s.height / 2 + 15; - this.addChild(menu, 1); - - var infoLabel = new cc.LabelTTF("0 nodes", "Marker Felt", 30); - infoLabel.color = cc.color(0, 200, 20); - infoLabel.x = s.width / 2; - infoLabel.y = s.height / 2 - 15; - this.addChild(infoLabel, 1, TAG_INFO_LAYER); - - var menu = new NodeChildrenMenuLayer(true, 4, s_nCurCase); - this.addChild(menu); - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - }, - title:function () { - return "No title"; - }, - subtitle:function () { - return ""; - }, - updateQuantityOfNodes:function () { - - }, - onDecrease:function (sender) { - this._quantityOfNodes -= NODES_INCREASE; - if (this._quantityOfNodes < 0) { - this._quantityOfNodes = 0; - } - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - }, - onIncrease:function (sender) { - this._quantityOfNodes += NODES_INCREASE; - if (this._quantityOfNodes > MAX_NODES) { - this._quantityOfNodes = MAX_NODES - } - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - }, - updateQuantityLabel:function () { - if (this._quantityOfNodes != this._lastRenderedCount) { - var infoLabel = this.getChildByTag(TAG_INFO_LAYER); - var str = this._quantityOfNodes + " nodes"; - infoLabel.setString(str); - - this._lastRenderedCount = this._quantityOfNodes; - } - }, - getQuantityOfNodes:function () { - return this._quantityOfNodes; - } -}); - -//////////////////////////////////////////////////////// -// -// IterateSpriteSheet -// -//////////////////////////////////////////////////////// -var IterateSpriteSheet = NodeChildrenMainScene.extend({ - _batchNode:null, - _profilingTimer:null, - ctor:function () { - this._super(); - if (cc.ENABLE_PROFILERS) { - this._profilingTimer = new cc.ProfilingTimer(); - } - }, - updateQuantityOfNodes:function () { - var s = cc.director.getWinSize(); - - // increase nodes - if (this._currentQuantityOfNodes < this._quantityOfNodes) { - for (var i = 0; i < (this._quantityOfNodes - this._currentQuantityOfNodes); i++) { - var sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 32, 32)); - this._batchNode.addChild(sprite); - sprite.x = Math.random() * s.width; - sprite.y = Math.random() * s.height; - } - } - - // decrease nodes - else if (this._currentQuantityOfNodes > this._quantityOfNodes) { - for (var i = 0; i < (this._currentQuantityOfNodes - this._quantityOfNodes); i++) { - var index = this._currentQuantityOfNodes - i - 1; - this._batchNode.removeChildAtIndex(index, true); - } - } - - this._currentQuantityOfNodes = this._quantityOfNodes; - }, - initWithQuantityOfNodes:function (nodes) { - this._batchNode = new cc.SpriteBatchNode("Images/spritesheet1.png"); - this.addChild(this._batchNode); - - this._super(nodes); - - if (cc.ENABLE_PROFILERS) { - this._profilingTimer = cc.Profiler.timerWithName(this.profilerName(), this); - } - this.scheduleUpdate(); - }, - update:function (dt) { - }, - profilerName:function () { - return "none"; - } -}); - -//////////////////////////////////////////////////////// -// -// IterateSpriteSheetFastEnum -// -//////////////////////////////////////////////////////// -var IterateSpriteSheetFastEnum = IterateSpriteSheet.extend({ - update:function (dt) { - // iterate using fast enumeration protocol - var children = this._batchNode.children; - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingBeginTimingBlock(this._profilingTimer); - } - - for (var i = 0; i < children.length; i++) { - var sprite = children[i]; - sprite.visible = false; - } - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingEndTimingBlock(this._profilingTimer); - } - }, - - title:function () { - return "A - Iterate SpriteSheet"; - }, - subtitle:function () { - return "Iterate children using Fast Enum API. See console"; - }, - profilerName:function () { - return "iter fast enum"; - } -}); - -//////////////////////////////////////////////////////// -// -// IterateSpriteSheetCArray -// -//////////////////////////////////////////////////////// -var IterateSpriteSheetCArray = IterateSpriteSheet.extend({ - update:function (dt) { - // iterate using fast enumeration protocol - var children = this._batchNode.children; - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingBeginTimingBlock(this._profilingTimer); - } - for (var i = 0; i < children.length; i++) { - var sprite = children[i]; - sprite.visible = false; - } - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingEndTimingBlock(this._profilingTimer); - } - }, - - title:function () { - return "B - Iterate SpriteSheet"; - }, - subtitle:function () { - return "Iterate children using Array API. See console"; - }, - profilerName:function () { - return "iter c-array"; - } -}); - -//////////////////////////////////////////////////////// -// -// AddRemoveSpriteSheet -// -//////////////////////////////////////////////////////// -var AddRemoveSpriteSheet = NodeChildrenMainScene.extend({ - _batchNode:null, - ctor:function () { - this._super(); - if (cc.ENABLE_PROFILERS) { - this._profilingTimer = new cc.ProfilingTimer(); - } - }, - updateQuantityOfNodes:function () { - var s = cc.director.getWinSize(); - - // increase nodes - if (this._currentQuantityOfNodes < this._quantityOfNodes) { - for (var i = 0; i < (this._quantityOfNodes - this._currentQuantityOfNodes); i++) { - var sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 32, 32)); - this._batchNode.addChild(sprite); - sprite.x = Math.random() * s.width; - sprite.y = Math.random() * s.height; - sprite.visible = false; - } - } - // decrease nodes - else if (this._currentQuantityOfNodes > this._quantityOfNodes) { - for (var i = 0; i < (this._currentQuantityOfNodes - this._quantityOfNodes); i++) { - var index = this._currentQuantityOfNodes - i - 1; - this._batchNode.removeChildAtIndex(index, true); - } - } - - this._currentQuantityOfNodes = this._quantityOfNodes; - }, - initWithQuantityOfNodes:function (nodes) { - this._batchNode = new cc.SpriteBatchNode("Images/spritesheet1.png"); - this.addChild(this._batchNode); - - this._super(nodes); - - if (cc.ENABLE_PROFILERS) { - this._profilingTimer = cc.Profiler.timerWithName(this.profilerName(), this); - } - - this.scheduleUpdate(); - }, - update:function (dt) { - }, - profilerName:function () { - return "none"; - } -}); - -//////////////////////////////////////////////////////// -// -// AddSpriteSheet -// -//////////////////////////////////////////////////////// -var AddSpriteSheet = AddRemoveSpriteSheet.extend({ - update:function (dt) { - // reset seed - //srandom(0); - - // 15 percent - var totalToAdd = this._currentQuantityOfNodes * 0.15; - - if (totalToAdd > 0) { - var sprites = []; - var zs = []; - - // Don't include the sprite creation time and random as part of the profiling - for (var i = 0; i < totalToAdd; i++) { - var sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 32, 32)); - sprites.push(sprite); - zs[i] = (Math.random()*2-1) * 50; - } - - // add them with random Z (very important!) - if (cc.ENABLE_PROFILERS) - cc.ProfilingBeginTimingBlock(this._profilingTimer); - } - - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.addChild(sprites[i], zs[i], TAG_BASE + i); - } - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingEndTimingBlock(this._profilingTimer); - } - - // remove them - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.removeChildByTag(TAG_BASE + i, true); - } - - delete zs; - - }, - title:function () { - return "C - Add to spritesheet"; - }, - subtitle:function () { - return "Adds %10 of total sprites with random z. See console"; - }, - profilerName:function () { - return "add sprites"; - } - }) - ; - -//////////////////////////////////////////////////////// -// -// RemoveSpriteSheet -// -//////////////////////////////////////////////////////// -var RemoveSpriteSheet = AddRemoveSpriteSheet.extend({ - update:function (dt) { - //srandom(0); - - // 15 percent - var totalToAdd = this._currentQuantityOfNodes * 0.15; - - if (totalToAdd > 0) { - var sprites = []; - - // Don't include the sprite creation time as part of the profiling - for (var i = 0; i < totalToAdd; i++) { - var sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 32, 32)); - sprites.push(sprite); - } - - // add them with random Z (very important!) - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.addChild(sprites[i], (Math.random()*2-1) * 50, TAG_BASE + i); - } - - // remove them - if (cc.ENABLE_PROFILERS) { - cc.ProfilingBeginTimingBlock(this._profilingTimer); - } - - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.removeChildByTag(TAG_BASE + i, true); - } - - if (cc.ENABLE_PROFILERS) { - cc.ProfilingEndTimingBlock(this._profilingTimer); - } - } - }, - title:function () { - return "D - Del from spritesheet"; - }, - subtitle:function () { - return "Remove %10 of total sprites placed randomly. See console"; - }, - profilerName:function () { - return "remove sprites"; - } -}); - -//////////////////////////////////////////////////////// -// -// ReorderSpriteSheet -// -//////////////////////////////////////////////////////// -var ReorderSpriteSheet = AddRemoveSpriteSheet.extend({ - - update:function (dt) { - //srandom(0); - - // 15 percent - var totalToAdd = this._currentQuantityOfNodes * 0.15; - - if (totalToAdd > 0) { - var sprites = []; - - // Don't include the sprite creation time as part of the profiling - for (var i = 0; i < totalToAdd; i++) { - var sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 32, 32)); - sprites.push(sprite); - } - - // add them with random Z (very important!) - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.addChild(sprites[i], (Math.random()*2-1) * 50, TAG_BASE + i); - } - - // [this._batchNode sortAllChildren]; - - // reorder them - if (cc.ENABLE_PROFILERS) { - cc.ProfilingBeginTimingBlock(this._profilingTimer); - } - - for (var i = 0; i < totalToAdd; i++) { - var node = this._batchNode.children[i]; - ; - this._batchNode.reorderChild(node, (Math.random()*2-1) * 50); - } - if (cc.ENABLE_PROFILERS) { - cc.ProfilingEndTimingBlock(this._profilingTimer); - } - } - - - // remove them - for (var i = 0; i < totalToAdd; i++) { - this._batchNode.removeChildByTag(TAG_BASE + i, true); - } - - }, - - title:function () { - return "E - Reorder from spritesheet"; - }, - subtitle:function () { - return "Reorder %10 of total sprites placed randomly. See console"; - }, - profilerName:function () { - return "reorder sprites"; - } -}); - -function runNodeChildrenTest() { - var scene = new IterateSpriteSheetCArray(); - scene.initWithQuantityOfNodes(NODES_INCREASE); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/PerformanceParticleTest.js b/tests/js-tests/src/PerformanceTest/PerformanceParticleTest.js deleted file mode 100644 index b844b20101..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceParticleTest.js +++ /dev/null @@ -1,526 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -var TAG_PARTICLE_SYSTEM = 3; -var TAG_LABEL_ATLAS = 4; -var MAX_PARTICLES = 3000; -var PARTICLE_NODES_INCREASE = 200; -var s_nParCurIdx = 0; -var TAG_PARTICLE_MENU_LAYER = 1000; - -//////////////////////////////////////////////////////// -// -// ParticleMenuLayer -// -//////////////////////////////////////////////////////// -var ParticleMenuLayer = PerformBasicLayer.extend({ - _maxCases:4, - showCurrentTest:function () { - var scene = this.parent; - var subTest = scene.getSubTestNum(); - var parNum = scene.getParticlesNum(); - - var newScene = null; - - switch (this._curCase) { - case 0: - newScene = new ParticlePerformTest1; - break; - case 1: - newScene = new ParticlePerformTest2; - break; - case 2: - newScene = new ParticlePerformTest3; - break; - case 3: - newScene = new ParticlePerformTest4; - break; - } - - s_nParCurIdx = this._curCase; - if (newScene) { - newScene.initWithSubTest(subTest, parNum); - cc.director.runScene(newScene); - } - } -}); - -//////////////////////////////////////////////////////// -// -// ParticleMainScene -// -//////////////////////////////////////////////////////// -var ParticleMainScene = cc.Scene.extend({ - _lastRenderedCount:null, - _quantityParticles:null, - _subtestNumber:null, - ctor:function () { - this._super(); - this.init(); - }, - initWithSubTest:function (asubtest, particles) { - //srandom(0); - - this._subtestNumber = asubtest; - var s = cc.director.getWinSize(); - - this._lastRenderedCount = 0; - this._quantityParticles = particles; - - cc.MenuItemFont.setFontSize(65); - var decrease = new cc.MenuItemFont(" - ", this.onDecrease, this); - decrease.color = cc.color(0, 200, 20); - var increase = new cc.MenuItemFont(" + ", this.onIncrease, this); - increase.color = cc.color(0, 200, 20); - - var menu = new cc.Menu(decrease, increase); - menu.alignItemsHorizontally(); - menu.x = s.width / 2; - menu.y = s.height / 2 + 15; - this.addChild(menu, 1); - - var infoLabel = new cc.LabelTTF("0 nodes", "Marker Felt", 30); - infoLabel.color = cc.color(0, 200, 20); - infoLabel.x = s.width / 2; - infoLabel.y = s.height - 90; - this.addChild(infoLabel, 1, TAG_INFO_LAYER); - - // particles on stage - var labelAtlas = new cc.LabelAtlas("0000", "Images/fps_images.png", 16, 24, '.'); - // var labelAtlas = cc.LabelTTF.create("0000", "Marker Felt", 30); - this.addChild(labelAtlas, 0, TAG_LABEL_ATLAS); - labelAtlas.x = s.width - 66; - labelAtlas.y = 50; - - // Next Prev Test - var menu = new ParticleMenuLayer(true, 4, s_nParCurIdx); - this.addChild(menu, 1, TAG_PARTICLE_MENU_LAYER); - - // Sub Tests - cc.MenuItemFont.setFontSize(40); - var subMenu = new cc.Menu(); - for (var i = 1; i <= 3; ++i) { - var str = i.toString(); - var itemFont = new cc.MenuItemFont(str, this.testNCallback, this); - itemFont.tag = i; - subMenu.addChild(itemFont, 10); - - if (i <= 1) { - itemFont.color = cc.color(200, 20, 20); - } - else { - itemFont.color = cc.color(0, 200, 20); - } - } - subMenu.alignItemsHorizontally(); - subMenu.x = s.width / 2; - subMenu.y = 80; - this.addChild(subMenu, 2); - - var label = new cc.LabelTTF(this.title(), "Arial", 40); - this.addChild(label, 1); - label.x = s.width / 2; - label.y = s.height - 32; - label.color = cc.color(255, 255, 40); - - this.updateQuantityLabel(); - this.createParticleSystem(); - - this.schedule(this.step); - }, - title:function () { - return "No title"; - }, - - step:function (dt) { - var atlas = this.getChildByTag(TAG_LABEL_ATLAS); - var emitter = this.getChildByTag(TAG_PARTICLE_SYSTEM); - - var str = emitter.getParticleCount().toString(); - atlas.setString(str); - }, - createParticleSystem:function () { - /* - * Tests: - * 1 Quad Particle System using 32-bit textures (PNG) - * 2: Quad Particle System using 16-bit textures (PNG) - * 3: Quad Particle System using 8-bit textures (PNG) - * 4: Quad Particle System using 4-bit textures (PVRTC) - */ - - this.removeChildByTag(TAG_PARTICLE_SYSTEM, true); - - // remove the "fire.png" from the TextureCache cache. - //var texture = cc.textureCache.addImage("Images/fire.png"); - //cc.textureCache.removeTexture(texture); - - var particleSystem = new cc.ParticleSystem(this._quantityParticles); - - switch (this._subtestNumber) { - case 1: - if ("opengl" in cc.sys.capabilities) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - particleSystem.texture = cc.textureCache.addImage("Images/fire.png"); - break; - case 2: - if ("opengl" in cc.sys.capabilities) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA4444; - particleSystem.texture = cc.textureCache.addImage("Images/fire.png"); - break; - case 3: - if ("opengl" in cc.sys.capabilities) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_A8; - particleSystem.texture = cc.textureCache.addImage("Images/fire.png"); - break; - default: - particleSystem = null; - cc.log("Shall not happen!"); - break; - } - this.addChild(particleSystem, 0, TAG_PARTICLE_SYSTEM); - - this.doTest(); - - // restore the default pixel format - if ("opengl" in cc.sys.capabilities) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - }, - onDecrease:function (sender) { - this._quantityParticles -= PARTICLE_NODES_INCREASE; - if (this._quantityParticles < 0) - this._quantityParticles = 0; - - this.updateQuantityLabel(); - this.createParticleSystem(); - }, - onIncrease:function (sender) { - this._quantityParticles += PARTICLE_NODES_INCREASE; - if (this._quantityParticles > MAX_PARTICLES) { - this._quantityParticles = MAX_PARTICLES; - } - this.updateQuantityLabel(); - this.createParticleSystem(); - }, - testNCallback:function (sender) { - this._subtestNumber = sender.tag; - var menu = this.getChildByTag(TAG_PARTICLE_MENU_LAYER); - menu.restartCallback(sender); - }, - updateQuantityLabel:function () { - if (this._quantityParticles != this._lastRenderedCount) { - var infoLabel = this.getChildByTag(TAG_INFO_LAYER); - var str = this._quantityParticles + " particles"; - infoLabel.setString(str); - - this._lastRenderedCount = this._quantityParticles; - } - }, - getSubTestNum:function () { - return this._subtestNumber; - }, - getParticlesNum:function () { - return this._quantityParticles; - }, - doTest:function () { - } -}); - -//////////////////////////////////////////////////////// -// -// ParticlePerformTest1 -// -//////////////////////////////////////////////////////// -var ParticlePerformTest1 = ParticleMainScene.extend({ - - title:function () { - return "A " + this._subtestNumber + " size=4"; - }, - doTest:function () { - var s = cc.director.getWinSize(); - var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM); - - // duration - particleSystem.setDuration(-1); - - // gravity - particleSystem.setGravity(cc.p(0, -90)); - - // angle - particleSystem.setAngle(90); - particleSystem.setAngleVar(0); - - // radial - particleSystem.setRadialAccel(0); - particleSystem.setRadialAccelVar(0); - - // speed of particles - particleSystem.setSpeed(180); - particleSystem.setSpeedVar(50); - - // emitter position - particleSystem.x = s.width / 2; - particleSystem.y = 100; - particleSystem.setPosVar(cc.p(s.width / 2, 0)); - - // life of particles - particleSystem.setLife(2.0); - particleSystem.setLifeVar(1); - - // emits per frame - particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife()); - - // color of particles - var startColor = cc.color(128, 128, 128, 255); - particleSystem.setStartColor(startColor); - - var startColorVar = cc.color(128, 128, 128, 255); - particleSystem.setStartColorVar(startColorVar); - - var endColor = cc.color(26, 26, 26, 51); - particleSystem.setEndColor(endColor); - - var endColorVar = cc.color(26, 26, 26, 51); - particleSystem.setEndColorVar(endColorVar); - - // size, in pixels - particleSystem.setEndSize(4.0); - particleSystem.setStartSize(4.0); - particleSystem.setEndSizeVar(0); - particleSystem.setStartSizeVar(0); - - // additive - particleSystem.setBlendAdditive(false); - } -}); - -//////////////////////////////////////////////////////// -// -// ParticlePerformTest2 -// -//////////////////////////////////////////////////////// -var ParticlePerformTest2 = ParticleMainScene.extend({ - - title:function () { - return "B " + this._subtestNumber + " size=8"; - }, - doTest:function () { - var s = cc.director.getWinSize(); - var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM); - - // duration - particleSystem.setDuration(-1); - - // gravity - particleSystem.setGravity(cc.p(0, -90)); - - // angle - particleSystem.setAngle(90); - particleSystem.setAngleVar(0); - - // radial - particleSystem.setRadialAccel(0); - particleSystem.setRadialAccelVar(0); - - // speed of particles - particleSystem.setSpeed(180); - particleSystem.setSpeedVar(50); - - // emitter position - particleSystem.x = s.width / 2; - particleSystem.y = 100; - particleSystem.setPosVar(cc.p(s.width / 2, 0)); - - // life of particles - particleSystem.setLife(2.0); - particleSystem.setLifeVar(1); - - // emits per frame - particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife()); - - // color of particles - var startColor = cc.color(128, 128, 128, 255); - particleSystem.setStartColor(startColor); - - var startColorVar = cc.color(128, 128, 128, 255); - particleSystem.setStartColorVar(startColorVar); - - var endColor = cc.color(26, 26, 26, 51); - particleSystem.setEndColor(endColor); - - var endColorVar = cc.color(26, 26, 26, 51); - particleSystem.setEndColorVar(endColorVar); - - // size, in pixels - particleSystem.setEndSize(8.0); - particleSystem.setStartSize(8.0); - particleSystem.setEndSizeVar(0); - particleSystem.setStartSizeVar(0); - - // additive - particleSystem.setBlendAdditive(false); - } -}); - -//////////////////////////////////////////////////////// -// -// ParticlePerformTest3 -// -//////////////////////////////////////////////////////// -var ParticlePerformTest3 = ParticleMainScene.extend({ - - title:function () { - return "C " + this._subtestNumber + " size=32"; - }, - doTest:function () { - var s = cc.director.getWinSize(); - var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM); - - // duration - particleSystem.setDuration(-1); - - // gravity - particleSystem.setGravity(cc.p(0, -90)); - - // angle - particleSystem.setAngle(90); - particleSystem.setAngleVar(0); - - // radial - particleSystem.setRadialAccel(0); - particleSystem.setRadialAccelVar(0); - - // speed of particles - particleSystem.setSpeed(180); - particleSystem.setSpeedVar(50); - - // emitter position - particleSystem.x = s.width / 2; - particleSystem.y = 100; - particleSystem.setPosVar(cc.p(s.width / 2, 0)); - - // life of particles - particleSystem.setLife(2.0); - particleSystem.setLifeVar(1); - - // emits per frame - particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife()); - - // color of particles - var startColor = cc.color(128, 128, 128, 255); - particleSystem.setStartColor(startColor); - - var startColorVar = cc.color(128, 128, 128, 255); - particleSystem.setStartColorVar(startColorVar); - - var endColor = cc.color(26, 26, 26, 51); - particleSystem.setEndColor(endColor); - - var endColorVar = cc.color(26, 26, 26, 51); - particleSystem.setEndColorVar(endColorVar); - - // size, in pixels - particleSystem.setEndSize(32.0); - particleSystem.setStartSize(32.0); - particleSystem.setEndSizeVar(0); - particleSystem.setStartSizeVar(0); - - // additive - particleSystem.setBlendAdditive(false); - } -}); - -//////////////////////////////////////////////////////// -// -// ParticlePerformTest4 -// -//////////////////////////////////////////////////////// -var ParticlePerformTest4 = ParticleMainScene.extend({ - - title:function () { - return "D " + this._subtestNumber + " size=64"; - }, - doTest:function () { - var s = cc.director.getWinSize(); - var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM); - - // duration - particleSystem.setDuration(-1); - - // gravity - particleSystem.setGravity(cc.p(0, -90)); - - // angle - particleSystem.setAngle(90); - particleSystem.setAngleVar(0); - - // radial - particleSystem.setRadialAccel(0); - particleSystem.setRadialAccelVar(0); - - // speed of particles - particleSystem.setSpeed(180); - particleSystem.setSpeedVar(50); - - // emitter position - particleSystem.x = s.width / 2; - particleSystem.y = 100; - particleSystem.setPosVar(cc.p(s.width / 2, 0)); - - // life of particles - particleSystem.setLife(2.0); - particleSystem.setLifeVar(1); - - // emits per frame - particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife()); - - // color of particles - var startColor = cc.color(128, 128, 128, 255); - particleSystem.setStartColor(startColor); - - var startColorVar = cc.color(128, 128, 128, 255); - particleSystem.setStartColorVar(startColorVar); - - var endColor = cc.color(26, 26, 26, 51); - particleSystem.setEndColor(endColor); - - var endColorVar = cc.color(26, 26, 26, 51); - particleSystem.setEndColorVar(endColorVar); - - // size, in pixels - particleSystem.setEndSize(64.0); - particleSystem.setStartSize(64.0); - particleSystem.setEndSizeVar(0); - particleSystem.setStartSizeVar(0); - - // additive - particleSystem.setBlendAdditive(false); - } -}); - -function runParticleTest() { - var scene = new ParticlePerformTest1; - scene.initWithSubTest(1, PARTICLE_NODES_INCREASE); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest.js b/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest.js deleted file mode 100644 index 004a94b8cc..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest.js +++ /dev/null @@ -1,606 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -var MAX_SPRITES = 10000; -var SPRITES_INCREASE = 500; - -if ( !cc.sys.isNative) { - if(cc.sys.isMobile){ - MAX_SPRITES = 3000; - SPRITES_INCREASE = 50; - } -} - -var TAG_INFO_LAYER = 1; -var TAG_MAIN_LAYER = 2; -var TAG_SPRITE_MENU_LAYER = (MAX_SPRITES + 1000); - -var s_nSpriteCurCase = 0; - -//////////////////////////////////////////////////////// -// -// SubTest -// -//////////////////////////////////////////////////////// -var SubTest = cc.Class.extend({ - _subtestNumber:null, - _batchNode:null, - _parent:null, - removeByTag:function (tag) { - switch (this._subtestNumber) { - case 1: - case 4: - case 7: - this._parent.removeChildByTag(tag + 100, true); - break; - case 2: - case 3: - case 5: - case 6: - case 8: - case 9: - this._batchNode.removeChildAtIndex(tag, true); - break; - default: - break; - } - }, - createSpriteWithTag:function (tag) { -// create - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - - var sprite = null; - switch (this._subtestNumber) { - case 1: - { - sprite = new cc.Sprite("Images/grossinis_sister1.png"); - this._parent.addChild(sprite, 0, tag + 100); - break; - } - case 2: - case 3: - { - sprite = new cc.Sprite(this._batchNode.texture, cc.rect(0, 0, 52, 139)); - this._batchNode.addChild(sprite, 0, tag + 100); - break; - } - case 4: - { - var idx = parseInt(Math.random() * 14) + 1; - idx = idx < 10 ? "0" + idx : idx.toString(); - var str = "Images/grossini_dance_" + idx + ".png"; - sprite = new cc.Sprite(str); - this._parent.addChild(sprite, 0, tag + 100); - break; - } - case 5: - case 6: - { - var idx = 0 | (Math.random() * 14); - var x = (idx % 5) * 85; - var y = (0 | (idx / 5)) * 121; - sprite = new cc.Sprite(this._batchNode.texture, cc.rect(x, y, 85, 121)); - this._batchNode.addChild(sprite, 0, tag + 100); - break; - } - - case 7: - { - var y, x; - var r = 0 | (Math.random() * 64); - - y = parseInt(r / 8); - x = parseInt(r % 8); - - var str = "Images/sprites_test/sprite-" + x + "-" + y + ".png"; - sprite = new cc.Sprite(str); - this._parent.addChild(sprite, 0, tag + 100); - break; - } - - case 8: - case 9: - { - var y, x; - var r = 0 | (Math.random() * 64); - - y = (0 | (r / 8)) * 32; - x = (r % 8) * 32; - sprite = new cc.Sprite(this._batchNode.texture, cc.rect(x, y, 32, 32)); - this._batchNode.addChild(sprite, 0, tag + 100); - break; - } - - default: - break; - } - - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_DEFAULT; - - return sprite; - }, - initWithSubTest:function (subTest, p) { - this._subtestNumber = subTest; - this._parent = p; - this._batchNode = null; - /* - * Tests: - * 1: 1 (32-bit) PNG sprite of 52 x 139 - * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139 - - * 5: 14 (32-bit) PNG sprites of 85 x 121 each - * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each - * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each - * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each - - * 9: 64 (32-bit) sprites of 32 x 32 each - *10: 64 (32-bit) PNG Batch Node of 32 x 32 each - *11: 64 (16-bit) PNG Batch Node of 32 x 32 each - *12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each - */ - - // purge textures - // - // [mgr removeAllTextures]; - if ( cc.sys.isNative) { - var mgr = cc.textureCache; - mgr.removeTexture(mgr.addImage("Images/grossinis_sister1.png")); - mgr.removeTexture(mgr.addImage("Images/grossini_dance_atlas.png")); - mgr.removeTexture(mgr.addImage("Images/spritesheet1.png")); - } - - switch (this._subtestNumber) { - case 1: - case 4: - case 7: - break; - /// - case 2: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - this._batchNode = new cc.SpriteBatchNode("Images/grossinis_sister1.png", 500); - p.addChild(this._batchNode, 0); - break; - case 3: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA4444; - this._batchNode = new cc.SpriteBatchNode("Images/grossinis_sister1.png", 500); - p.addChild(this._batchNode, 0); - break; - - /// - case 5: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - this._batchNode = new cc.SpriteBatchNode("Images/grossini_dance_atlas.png", 500); - p.addChild(this._batchNode, 0); - break; - case 6: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA4444; - this._batchNode = new cc.SpriteBatchNode("Images/grossini_dance_atlas.png", 500); - p.addChild(this._batchNode, 0); - break; - - /// - case 8: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - this._batchNode = new cc.SpriteBatchNode("Images/spritesheet1.png", 500); - p.addChild(this._batchNode, 0); - break; - case 9: - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA4444; - this._batchNode = new cc.SpriteBatchNode("Images/spritesheet1.png", 500); - p.addChild(this._batchNode, 0); - break; - - default: - break; - } - - if( "opengl" in cc.sys.capabilities ) - cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_DEFAULT; - } -}); - -//////////////////////////////////////////////////////// -// -// SpriteMenuLayer -// -//////////////////////////////////////////////////////// -var SpriteMenuLayer = PerformBasicLayer.extend({ - _maxCases:7, - showCurrentTest:function () { - var scene = null; - var preScene = this.parent; - var subTest = preScene.getSubTestNum(); - var nodes = preScene.getNodesNum(); - - Math.seedrandom('perftest'); - - switch (this._curCase) { - case 0: - scene = new SpritePerformTest1(); - break; - case 1: - scene = new SpritePerformTest2(); - break; - case 2: - scene = new SpritePerformTest3(); - break; - case 3: - scene = new SpritePerformTest4(); - break; - case 4: - scene = new SpritePerformTest5(); - break; - case 5: - scene = new SpritePerformTest6(); - break; - case 6: - scene = new SpritePerformTest7(); - break; - } - s_nSpriteCurCase = this._curCase; - - if (scene) { - scene.initWithSubTest(subTest, nodes); - cc.director.runScene(scene); - } - } -}); - -//////////////////////////////////////////////////////// -// -// SpriteMainScene -// -//////////////////////////////////////////////////////// -var SpriteMainScene = cc.Scene.extend({ - _lastRenderedCount:null, - _quantityNodes:null, - _subTest:null, - _subtestNumber:1, - ctor:function() { - this._super(); - this.init(); - }, - - title:function () { - return "No title"; - }, - initWithSubTest:function (asubtest, nodes) { - this._subtestNumber = asubtest; - this._subTest = new SubTest(); - this._subTest.initWithSubTest(asubtest, this); - - var s = cc.director.getWinSize(); - - this._lastRenderedCount = 0; - this._quantityNodes = 0; - - // add title label - var label = new cc.LabelTTF(this.title(), "Arial", 40); - this.addChild(label, 1); - label.x = s.width / 2; - label.y = s.height - 32; - label.color = cc.color(255, 255, 40); - - cc.MenuItemFont.setFontSize(65); - var decrease = new cc.MenuItemFont(" - ", this.onDecrease, this); - decrease.color = cc.color(0, 200, 20); - var increase = new cc.MenuItemFont(" + ", this.onIncrease, this); - increase.color = cc.color(0, 200, 20); - - var menu = new cc.Menu(decrease, increase); - menu.alignItemsHorizontally(); - - menu.x = s.width / 2; - - menu.y = s.height - 65; - this.addChild(menu, 1); - - var infoLabel = new cc.LabelTTF("0 nodes", "Marker Felt", 30); - infoLabel.color = cc.color(0, 200, 20); - infoLabel.x = s.width / 2; - infoLabel.y = s.height - 90; - this.addChild(infoLabel, 1, TAG_INFO_LAYER); - - // add menu - var menu = new SpriteMenuLayer(true, 7, s_nSpriteCurCase); - this.addChild(menu, 1, TAG_SPRITE_MENU_LAYER); - - // Sub Tests - cc.MenuItemFont.setFontSize(32); - var subMenu = new cc.Menu(); - for (var i = 1; i <= 9; ++i) { - var text = i.toString(); - var itemFont = new cc.MenuItemFont(text, this.testNCallback, this); - itemFont.tag = i; - subMenu.addChild(itemFont, 10); - - if (i <= 3) - itemFont.color = cc.color(200, 20, 20); - else if (i <= 6) - itemFont.color = cc.color(0, 200, 20); - else - itemFont.color = cc.color(0, 20, 200); - } - - subMenu.alignItemsHorizontally(); - subMenu.x = s.width / 2; - subMenu.y = 80; - this.addChild(subMenu, 2); - - while (this._quantityNodes < nodes) { - this.onIncrease(this); - } - }, - updateNodes:function () { - if (this._quantityNodes != this._lastRenderedCount) { - var infoLabel = this.getChildByTag(TAG_INFO_LAYER); - var str = this._quantityNodes + " nodes"; - infoLabel.setString(str); - - this._lastRenderedCount = this._quantityNodes; - } - }, - testNCallback:function (sender) { - this._subtestNumber = sender.tag; - var menu = this.getChildByTag(TAG_SPRITE_MENU_LAYER); - menu.restartCallback(sender); - }, - onIncrease:function (sender) { - if (this._quantityNodes >= MAX_SPRITES) - return; - - for (var i = 0; i < SPRITES_INCREASE; i++) { - var sprite = this._subTest.createSpriteWithTag(this._quantityNodes); - this.doTest(sprite); - this._quantityNodes++; - } - - this.updateNodes(); - }, - onDecrease:function (sender) { - if (this._quantityNodes <= 0) - return; - - for (var i = 0; i < SPRITES_INCREASE; i++) { - this._quantityNodes--; - this._subTest.removeByTag(this._quantityNodes); - } - - this.updateNodes(); - }, - - doTest:function (sprite) { - - }, - - getSubTestNum:function () { - return this._subtestNumber - }, - getNodesNum:function () { - return this._quantityNodes - } -}); - - -//////////////////////////////////////////////////////// -// -// For test functions -// -//////////////////////////////////////////////////////// -function performanceActions(sprite) { - var size = cc.director.getWinSize(); - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); - - var period = 0.5 + (Math.random() * 1000) / 500.0; - var rot = cc.rotateBy(period, 360.0 * Math.random()); - var rot_back = rot.reverse(); - var permanentRotation = cc.sequence(rot, rot_back).repeatForever(); - sprite.runAction(permanentRotation); - - var growDuration = 0.5 + (Math.random() * 1000) / 500.0; - var grow = cc.scaleBy(growDuration, 0.5, 0.5); - var permanentScaleLoop = cc.sequence(grow, grow.reverse()).repeatForever(); - sprite.runAction(permanentScaleLoop); -} - -function performanceActions20(sprite) { - var size = cc.director.getWinSize(); - if (Math.random() < 0.2) { - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); - } - else { - sprite.x = -1000; - sprite.y = -1000; - } - - var period = 0.5 + (Math.random() * 1000) / 500.0; - var rot = cc.rotateBy(period, 360.0 * Math.random()); - var rot_back = rot.reverse(); - var permanentRotation = cc.sequence(rot, rot_back).repeatForever(); - sprite.runAction(permanentRotation); - - var growDuration = 0.5 + (Math.random() * 1000) / 500.0; - var grow = cc.scaleBy(growDuration, 0.5, 0.5); - var permanentScaleLoop = cc.sequence(grow, grow.reverse()).repeatForever(); - sprite.runAction(permanentScaleLoop); -} - -function performanceRotationScale(sprite) { - var size = cc.director.getWinSize(); - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); - sprite.rotation = Math.random() * 360; - sprite.scale = Math.random() * 2; -} - -function performancePosition(sprite) { - var size = cc.director.getWinSize(); - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); -} - -function performanceout20(sprite) { - var size = cc.director.getWinSize(); - - if (Math.random() < 0.2) { - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); - } - else { - sprite.x = -1000; - sprite.y = -1000; - } -} - -function performanceOut100(sprite) { - sprite.x = -1000; - sprite.y = -1000; -} - -function performanceScale(sprite) { - var size = cc.director.getWinSize(); - sprite.x = parseInt(Math.random() * size.width); - sprite.y = parseInt(Math.random() * size.height); - sprite.scale = Math.random() * 100 / 50; -} - - -//////////////////////////////////////////////////////// -// -// SpritePerformTest1 -// -//////////////////////////////////////////////////////// -var SpritePerformTest1 = SpriteMainScene.extend({ - doTest:function (sprite) { - performancePosition(sprite); - }, - title:function () { - return "A (" + this._subtestNumber + ") position"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest2 -// -//////////////////////////////////////////////////////// -var SpritePerformTest2 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceScale(sprite); - }, - title:function () { - return "B (" + this._subtestNumber + ") scale"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest3 -// -//////////////////////////////////////////////////////// -var SpritePerformTest3 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceRotationScale(sprite); - }, - title:function () { - return "C (" + this._subtestNumber + ") scale + rot"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest4 -// -//////////////////////////////////////////////////////// -var SpritePerformTest4 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceOut100(sprite); - }, - title:function () { - return "D (" + this._subtestNumber + ") 100% out"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest5 -// -//////////////////////////////////////////////////////// -var SpritePerformTest5 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceout20(sprite); - }, - title:function () { - return "E (" + this._subtestNumber + ") 80% out"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest6 -// -//////////////////////////////////////////////////////// -var SpritePerformTest6 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceActions(sprite); - }, - title:function () { - return "F (" + this._subtestNumber + ") actions"; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritePerformTest7 -// -//////////////////////////////////////////////////////// -var SpritePerformTest7 = SpriteMainScene.extend({ - doTest:function (sprite) { - performanceActions20(sprite); - }, - title:function () { - return "G (" + this._subtestNumber + ") actions 80% out"; - } -}); - -function runSpriteTest() { - Math.seedrandom('perftest'); - - var scene = new SpritePerformTest1; - scene.initWithSubTest(1, 50); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest2.js b/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest2.js deleted file mode 100644 index 840f2977c5..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceSpriteTest2.js +++ /dev/null @@ -1,305 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var SECONDS_PER_TEST = 5; -//------------------------------------------------------------------ -// -// Profiler -// -//------------------------------------------------------------------ - -function Profiling(name) { - this.name = name; - this.numberOfCalls = 0; - this.totalTime = 0; - this.minTime = 10000; - this.maxTime = 0; - this.lastUpdate = 0; - - this.beginBlock = function() { - this.lastUpdate = Date.now(); - }; - - this.endBlock = function() { - var now = Date.now(); - var diff = now-this.lastUpdate; - this.totalTime += diff; - this.numberOfCalls++; - this.minTime = Math.min(this.minTime, diff); - this.maxTime = Math.max(this.maxTime, diff); - }; - - this.beginEndBlock = function(diff) { - this.totalTime += diff; - this.numberOfCalls++; - this.minTime = Math.min(this.minTime, diff); - this.maxTime = Math.max(this.maxTime, diff); - }; - - this.reset = function() { - this.totalTime = 0; - this.minTime = 100000; - this.maxTime = 0; - this.lastUpdate = 0; - this.numberOfCalls = 0; - }; - - this.dump = function() { - cc.log('Profiling info for: ' + this.name + '\n' + - 'Number of calls: ' + this.numberOfCalls + '\n' + - 'Average Time: ' + (this.totalTime/this.numberOfCalls)/1000 + '\n' + - 'Min Time: ' + this.minTime/1000 + '\n' + - 'Max Time: ' + this.maxTime/1000 + '\n' + - 'Total Time: ' + this.totalTime/1000 + '\n' - ); - }; -} - - - -var performanceSpriteTestSceneIdx = -1; -//------------------------------------------------------------------ -// -// PerformanceSpriteTestDemo -// -//------------------------------------------------------------------ -var PerformanceTestBase = cc.Layer.extend({ - _title:"", - _subtitle:"", - - ctor:function() { - this._super(); - this.init(); - }, - onEnter:function () { - this._super(); - - var label = new cc.LabelTTF(this._title, "Arial", 28); - this.addChild(label, 1); - label.x = winSize.width / 2; - label.y = winSize.height - 50; - - if (this._subtitle !== "") { - var l = new cc.LabelTTF(this._subtitle, "Thonburi", 16); - this.addChild(l, 1); - l.x = winSize.width / 2; - l.y = winSize.height - 80; - } - - var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.onBackCallback, this); - var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.onRestartCallback, this); - var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.onNextCallback, this); - - var menu = new cc.Menu(item1, item2, item3); - - menu.x = 0; - - menu.y = 0; - var csw = item2.width, csh = item2.height; - item1.x = winSize.width/2 - csw*2; - item1.y = csh/2; - item2.x = winSize.width/2; - item2.y = csh/2; - item3.x = winSize.width/2 + csw*2; - item3.y = csh/2; - - this.addChild(menu, 1); - }, - - onRestartCallback:function (sender) { - var s = new PerformanceSpriteTestScene(); - s.addChild(restartPerformanceSpriteTest()); - director.runScene(s); - }, - onNextCallback:function (sender) { - var s = new PerformanceSpriteTestScene(); - s.addChild(nextPerformanceSpriteTest()); - director.runScene(s); - }, - onBackCallback:function (sender) { - var s = new PerformanceSpriteTestScene(); - s.addChild(previousPerformanceSpriteTest()); - director.runScene(s); - } -}); - -//------------------------------------------------------------------ -// -// PerformanceSpriteTest1 -// -//------------------------------------------------------------------ -var PerformanceSpriteTest1 = PerformanceTestBase.extend({ - _title:"Performance Test 1", - _subtitle:"Let it run until you see the 'done' message. See console for results.", - - ctor:function () { - this._super(); - - this.testFunctions = [this.testA, this.testB]; - this.endFunctions = [this.endA, this.endB]; - this.testSpriteTotals = [100,500,1000,2000,5000,10000]; - this.functionsIdx = 0; - this.spritesTotalsIdx = -1; - - this.runNextTest(); - - this.scheduleUpdate(); - this.schedule( this.endProfiling, SECONDS_PER_TEST); - this.firstTick = true; - }, - - runNextTest:function() { - - // cleanup current function - if( this.spritesTotalsIdx != -1) { - var cleanup = this.endFunctions[ this.functionsIdx ]; - cleanup.bind(this)(); - } - - this.spritesTotalsIdx++; - - // get next function - if( this.spritesTotalsIdx >= this.testSpriteTotals.length ) { - this.spritesTotalsIdx = 0; - this.functionsIdx++; - if( this.functionsIdx >= this.testFunctions.length ) { - cc.log("No more tests"); - return false; - } - } - var func = this.testFunctions[ this.functionsIdx ]; - var t = this.testSpriteTotals[ this.spritesTotalsIdx ]; - func.bind(this)(t); - return true; - }, - - testA:function(num) { - // Draws all sprites on the screen - // Non-batched drawing - - this.profiling = new Profiling("Test A - Total Sprites: " + num); - - // use the same seed for the tests - Math.seedrandom('perftest'); - var parent = new cc.Node(); - this.addChild(parent,0,10); - - for( var i=0; i 1.0) { - var frameRateB = (this._numberOfTouchesB / this._elapsedTime).toFixed(1); - var frameRateM = (this._numberOfTouchesM / this._elapsedTime).toFixed(1); - var frameRateE = (this._numberOfTouchesE / this._elapsedTime).toFixed(1); - var frameRateC = (this._numberOfTouchesC / this._elapsedTime).toFixed(1); - this._elapsedTime = 0; - this._numberOfTouchesB = this._numberOfTouchesM = this._numberOfTouchesE = this._numberOfTouchesC = 0; - - var str = frameRateB + " " + frameRateM + " " + frameRateE + " " + frameRateC; - this._plabel.setString(str); - } - } -}); - -//////////////////////////////////////////////////////// -// -// TouchesPerformTest1 -// -//////////////////////////////////////////////////////// -var TouchesPerformTest1 = TouchesMainScene.extend({ - onEnter:function () { - this._super(); - - var _this = this; - cc.eventManager.addListener({ - event: cc.EventListener.TOUCH_ONE_BY_ONE, - swallowTouches: true, - onTouchBegan:function (touch, event) { - _this._numberOfTouchesB++; - return true; - }, - onTouchMoved:function (touch, event) { - _this._numberOfTouchesM++; - }, - onTouchEnded:function (touch, event) { - _this._numberOfTouchesE++; - }, - onTouchCancelled:function (touch, event) { - _this._numberOfTouchesC++; - } - }, this); - }, - title:function () { - return "Targeted touches"; - } -}); - -//////////////////////////////////////////////////////// -// -// TouchesPerformTest2 -// -//////////////////////////////////////////////////////// -var TouchesPerformTest2 = TouchesMainScene.extend({ - onEnter:function () { - this._super(); - var _this = this; - cc.eventManager.addListener({ - event: cc.EventListener.TOUCH_ALL_AT_ONCE, - onTouchesBegan:function (touches, event) { - _this._numberOfTouchesB += touches.length; - }, - onTouchesMoved:function (touches, event) { - _this._numberOfTouchesM += touches.length; - }, - onTouchesEnded:function (touches, event) { - _this._numberOfTouchesE += touches.length; - }, - onTouchesCancelled:function (touches, event) { - _this._numberOfTouchesC += touches.length; - } - }, this); - }, - title:function () { - return "Standard touches"; - } -}); - -function runTouchesTest() { - s_nTouchCurCase = 0; - var scene = new cc.Scene(); - var layer = new TouchesPerformTest1(true, 2, s_nTouchCurCase); - scene.addChild(layer); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/PerformanceVirtualMachineTest.js b/tests/js-tests/src/PerformanceTest/PerformanceVirtualMachineTest.js deleted file mode 100644 index 605fa17d4b..0000000000 --- a/tests/js-tests/src/PerformanceTest/PerformanceVirtualMachineTest.js +++ /dev/null @@ -1,550 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var VM_TAG_BASE = 2000; -var VM_MAX_NODES = 1500; -var VM_NODES_INCREASE = 100; -var s_nVMCurCase = 0; - -//////////////////////////////////////////////////////// -// -// VirtualMachineTestMenuLayer -// -// These are some demo test cases about low level JS engine behavior, so in -// some sense this is simliar to PerformanceNodeChildrenTest. This file is -// derived from PerformanceNodeChildrenTest.js actually. -// -// See https://github.com/oupengsoftware/v8/wiki for some of the details (V8) -// under the hood. -// Keyword: hidden class, inline cache, dictionary mode. -// -//////////////////////////////////////////////////////// -var VirtualMachineTestMenuLayer = PerformBasicLayer.extend({ - _maxCases:6, - ctor:function(){ - this._super(); - this._maxCases = (cc._renderType === cc._RENDER_TYPE_CANVAS) ? 6 : 4; - }, - showCurrentTest:function () { - var nodes = (this.parent).getQuantityOfNodes(); - var scene = null; - switch (this._curCase) { - case 0: - scene = new SpritesWithManyPropertiesTestScene1(); - break; - case 1: - scene = new SpritesWithManyPropertiesTestScene2(); - break; - case 2: - scene = new SpritesUndergoneDifferentOperationsTestScene1(); - break; - case 3: - scene = new SpritesUndergoneDifferentOperationsTestScene2(); - break; - case 4: - scene = new ClonedSpritesTestScene1(); - break; - case 5: - scene = new ClonedSpritesTestScene2(); - break; - } - s_nVMCurCase = this._curCase; - - if (scene) { - scene.initWithQuantityOfNodes(nodes); - cc.director.runScene(scene); - } - } -}); - -//////////////////////////////////////////////////////// -// -// VirtualMachineTestMainScene -// -//////////////////////////////////////////////////////// -var VirtualMachineTestMainScene = cc.Scene.extend({ - _lastRenderedCount:null, - _quantityOfNodes:null, - _currentQuantityOfNodes:null, - _batchNode:null, - - ctor:function() { - this._super(); - this.init(); - }, - - initWithQuantityOfNodes:function (nodes) { - this._batchNode = new cc.SpriteBatchNode("Images/grossinis_sister1.png"); - this.addChild(this._batchNode); - - //srand(time()); - var s = cc.director.getWinSize(); - - // Title - var label = new cc.LabelTTF(this.title(), "Arial", 40); - this.addChild(label, 1); - label.x = s.width / 2; - label.y = s.height - 32; - label.color = cc.color(255, 255, 40); - - // Subtitle - var strSubTitle = this.subtitle(); - if (strSubTitle.length) { - var l = new cc.LabelTTF(strSubTitle, "Thonburi", 16); - this.addChild(l, 1); - l.x = s.width / 2; - l.y = s.height - 80; - } - - this._lastRenderedCount = 0; - this._currentQuantityOfNodes = 0; - this._quantityOfNodes = nodes; - - cc.MenuItemFont.setFontSize(65); - var that = this; - var decrease = new cc.MenuItemFont(" - ", this.onDecrease, this); - decrease.color = cc.color(0, 200, 20); - var increase = new cc.MenuItemFont(" + ", this.onIncrease, this); - increase.color = cc.color(0, 200, 20); - - var menu = new cc.Menu(decrease, increase); - menu.alignItemsHorizontally(); - menu.x = s.width / 2; - menu.y = s.height / 2 + 15; - this.addChild(menu, 1); - - var infoLabel = new cc.LabelTTF("0 nodes", "Marker Felt", 30); - infoLabel.color = cc.color(0, 200, 20); - infoLabel.x = s.width / 2; - infoLabel.y = s.height / 2 - 15; - this.addChild(infoLabel, 1, TAG_INFO_LAYER); - - var menu = new VirtualMachineTestMenuLayer(true, 3, s_nVMCurCase); - this.addChild(menu); - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - this.scheduleUpdate(); - }, - title:function () { - cc.Assert(0); - // override me - }, - subtitle:function () { - cc.Assert(0); - // override me - }, - updateQuantityOfNodes:function () { - cc.Assert(0); - // override me - }, - onDecrease:function (sender) { - this._quantityOfNodes -= VM_NODES_INCREASE; - if (this._quantityOfNodes < 0) { - this._quantityOfNodes = 0; - } - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - }, - onIncrease:function (sender) { - this._quantityOfNodes += VM_NODES_INCREASE; - if (this._quantityOfNodes > VM_MAX_NODES) { - this._quantityOfNodes = VM_MAX_NODES - } - - this.updateQuantityLabel(); - this.updateQuantityOfNodes(); - }, - updateQuantityLabel:function () { - if (this._quantityOfNodes != this._lastRenderedCount) { - var infoLabel = this.getChildByTag(TAG_INFO_LAYER); - var str = this._quantityOfNodes + " nodes"; - infoLabel.setString(str); - - this._lastRenderedCount = this._quantityOfNodes; - } - }, - getQuantityOfNodes:function () { - return this._quantityOfNodes; - }, - arrayToUpdate:null, - update:function (dt) { - if (!this.arrayToUpdate) return; - for (var i = 0, imax = this.arrayToUpdate.length; i < imax; ++i) { - var child = this.arrayToUpdate[i]; - if (!(child instanceof SimpleNewtonianSprite) && - child instanceof cc.Class) continue; // old cc.clone-ed - // sprite is not a cc.Class - for (var j = 0; j < 1000; ++j ) { - child._velocityX = child._velocityX + dt * child._accelerationX; - child._velocityY = child._velocityY + dt * child._accelerationY; - child._positionX = child._positionX + dt * child._velocityX; - child._positionY = child._positionY + dt * child._velocityY; - } - } - } -}); - -// Simple sprite extension used for testing the performance of property access. -var SimpleNewtonianSprite = cc.Sprite.extend({ - ctor:function(texture, rect) { - cc.Sprite.prototype.ctor.call(this); - // Since jsb doesn't have ._position, in order not to make these - // showcase more complicated by introducing fuction calls (because - // different JS engines have different inlining strategy), we simply - // introduce ._postionX ._positionY here. These (and update()) really - // just represent *heavy property access operation* anyway (they're - // otherwise dummy). - this._positionX = 0.0; - this._positionY = 0.0; - this._velocityX = 0.0; - this._velocityY = 0.0; - this._accelerationX = 0.0; - this._accelerationY = 0.0; - - if(texture && rect) - this.initWithTexture(texture, rect); - } -}); - -//////////////////////////////////////////////////////// -// -// SpritesWithManyPropertiesTestScene -// -// Some JS engines (notably, V8) assume that objects with many properties are -// dictionary (c.f CCClass.js) and that makes bad performance. Here we -// simulate a character class with many properties of a character, but -// otherwise these properties are dummy (and probably doesn't make much -// sense) in the test of course. -// (TODO: Find a open source real world example, which shouldn't be that hard. -// :) ) -// -//////////////////////////////////////////////////////// -var SpriteWithManyProperties = SimpleNewtonianSprite.extend({ - ctor:function(texture, rect) { - SimpleNewtonianSprite.prototype.ctor.call(this, texture, rect); - this._name = ""; - this._species = ""; - this._id = -1; - this._hp = 100; - this._mp = 100; - this._exp = 100; - this._lv = 1; - this._str = 100; - this._dex = 100; - this._int = 100; - this._luk = 100; - this._gold = 10000000; // I'm rich. - this._weight = 100.0; - this._height = 100.0; - this._items = []; - this._spells = []; - this._dressing = null; - this._weapon = null; - this._mission = null; - this._friends = []; - this._groups = []; - - this._idleTime = 0.0; - this._loginTime = 0.0; - this._isAutoMove = false; - this._autoMoveTarget = false; - this._attackMode = 0; - this._active = true; - this._canBeAttack = true; - this._isLocalPlayer = false; - this._moveType = null; - this._I_AM_TIRED_OF_COMING_UP_WITH_NEW_PROPERTIES = true; - } -}); - -var SpritesWithManyPropertiesTestScene1 = VirtualMachineTestMainScene.extend({ - updateQuantityOfNodes:function () { - var s = cc.director.getWinSize(); - - // increase nodes - if (this._currentQuantityOfNodes < this._quantityOfNodes) { - for (var i = 0; - i < (this._quantityOfNodes - this._currentQuantityOfNodes); - i++) { - var sprite = - new SpriteWithManyProperties(this._batchNode.texture, - cc.rect(0, 0, 52, 139)); - this._batchNode.addChild(sprite); - sprite.x = Math.random() * s.width; - sprite.y = Math.random() * s.height; - } - } - - // decrease nodes - else if (this._currentQuantityOfNodes > this._quantityOfNodes) { - for (var i = 0; - i < (this._currentQuantityOfNodes - this._quantityOfNodes); - i++) { - var index = this._currentQuantityOfNodes - i - 1; - this._batchNode.removeChildAtIndex(index, true); - } - } - - this._currentQuantityOfNodes = this._quantityOfNodes; - }, - title:function () { - return "A1 - Sprites Have Many Properties"; - }, - subtitle:function () { - return "See fps (and source code of this test)."; - } -}); - -var SpritesWithManyPropertiesTestScene2 = - SpritesWithManyPropertiesTestScene1.extend({ - updateQuantityOfNodes:function () { - this._super(); - var arrayToUpdate = this._batchNode.children; - for (var i = 0, imax = arrayToUpdate.length; i < imax; ++i) - arrayToUpdate[i].visible = false; - this.arrayToUpdate = arrayToUpdate; - }, - title:function () { - return "A2 - Sprites Have Many Properties"; - }, - subtitle:function () { - return "No draw(). update() does heavy calculations."; - } -}); - -//////////////////////////////////////////////////////// -// -// SpritesUndergoneDifferentOperationsTestScene -// -// If properties in use are not initilized on each instance, a combinarial -// explosion of hidden classes have to be created for each possible -// permutation of operations. This increases inline cache size and -// constitutes significant performance penalty. -// -//////////////////////////////////////////////////////// - -var SpritesUndergoneDifferentOperationsTestScene1 = VirtualMachineTestMainScene.extend({ - // Adpated from http://codereview.stackexchange.com/a/7025 - possibleOperationSeries:(function permutations(array){ - var fn = function(active, rest, a) { - if (!active.length && !rest.length) { - a.push([]); - return; - } - if (!rest.length) { - if (active.length === 1) { - a.push(active); - return; - } - - var fac = 1; - for (var i = active.length; i > 0; --i) fac = fac * i; - for (var i = 0; i < fac; ++i) { - var choice_num = i; - var choice = []; - for (var j = 1; j < active.length + 1; ++j) { - choice.unshift(choice_num % j); - choice_num = (choice_num - choice_num % j) / j; - } - - var to_choose_from = active.slice(0); - var new_permutation = []; - for (var k = 0; k < active.length; ++k) - new_permutation.push(to_choose_from. - splice(choice[k], 1)[0]); - a.push(new_permutation); - } - } else { - fn(active.concat([rest[0]]), rest.slice(1), a); - fn(active, rest.slice(1), a); - } - return a; - }; - return fn([], array, []); - })([ - function() { this.children; }, // appends ._children - function() { this.tag = cc.NODE_TAG_INVALID; }, // appends .tag - function() { this.setParent(null); }, // appends ._parent - function() { this.zIndex = 0; }, // appends ._zOrder - function() { this.rotation = 0; }, // appends ._rotationX/Y - function() { this.visible = true; }, // appends ._visible - function() { this.onEnter(); } // appends ._running - ]), - updateQuantityOfNodes:function () { - var s = cc.director.getWinSize(); - - // increase nodes - if (this._currentQuantityOfNodes < this._quantityOfNodes) { - for (var i = 0; - i < (this._quantityOfNodes - this._currentQuantityOfNodes); - i++) { - var sprite = - new SimpleNewtonianSprite(this._batchNode.texture, - cc.rect(0, 0, 52, 139)); - var series = this.possibleOperationSeries[i]; - for (var op = 0, opmax = series.length; op < opmax; ++op) - series[op].call(sprite); - - this._batchNode.addChild(sprite); - sprite.x = Math.random() * s.width; - sprite.y = Math.random() * s.height; - } - } - - // decrease nodes - else if (this._currentQuantityOfNodes > this._quantityOfNodes) { - for (var i = 0; - i < (this._currentQuantityOfNodes - this._quantityOfNodes); - i++) { - var index = this._currentQuantityOfNodes - i - 1; - this._batchNode.removeChildAtIndex(index, true); - } - } - - this._currentQuantityOfNodes = this._quantityOfNodes; - }, - title:function () { - return "B1 - Sprites Undergone Different Op. Order"; - }, - subtitle:function () { - return "See fps (and source code of this test)."; - } -}); - -var SpritesUndergoneDifferentOperationsTestScene2 = - SpritesUndergoneDifferentOperationsTestScene1.extend({ - // This looks exactly like the one on ManyPropertiesTestScene2, but - // we can't just do - // 'updateQuantityOfNodes: SpritesWithManyPropertiesTestScene2.prototype.updateQuantityOfNodes' - // here becasue this._super() is different! - updateQuantityOfNodes:function () { - this._super(); - var arrayToUpdate = this._batchNode.children; - for (var i = 0, imax = arrayToUpdate.length; i < imax; ++i) - arrayToUpdate[i].visible = false; - this.arrayToUpdate = arrayToUpdate; - }, - title:function () { - return "B2 - Sprites Undergone Different Op. Order"; - }, - subtitle:function () { - return "No draw(). update() does heavy calculations."; - } -}); - -//////////////////////////////////////////////////////// -// -// ClonedSpritesTestScene -// -// cc.clone has to be written carefully or cloned objects all go to dictionary -// mode. -// -//////////////////////////////////////////////////////// -var ClonedSpritesTestScene1 = VirtualMachineTestMainScene.extend({ - template:null, - updateQuantityOfNodes:function () { - if (!this.template) - this.template = - new SimpleNewtonianSprite(this._batchNode.texture, - cc.rect(0, 0, 52, 139)); - var s = cc.director.getWinSize(); - - // increase nodes - if (this._currentQuantityOfNodes < this._quantityOfNodes) { - for (var i = 0; - i < (this._quantityOfNodes - this._currentQuantityOfNodes); - i++) { - var sprite = cc.clone(this.template); - sprite.setParent(null); // old cc.clone copies null as {}... - - // cc.SpriteBatchNode doesn't support adding non-cc.Sprite child - // and hence incompatible with old cc.clone. We add the sprite - // to the scene directly. - this.addChild(sprite, -1); // zOrder has to be less than 0 or it - // overlaps the menu. - sprite.x = Math.random() * s.width; - sprite.y = Math.random() * s.height; - } - } - - // decrease nodes - else if (this._currentQuantityOfNodes > this._quantityOfNodes) { - var children = this.children; - var lastChildToRemove = children.length; - for (var i = children.length - 1; i >= 0; --i) { - var child = children[i]; - if (child instanceof SimpleNewtonianSprite || - !(child instanceof cc.Class)) { // old cc.clone-ed - // sprite is not a cc.Class - lastChildToRemove = i; - break; - } - } - - for (var i = 0; - i < (this._currentQuantityOfNodes - this._quantityOfNodes); - i++) { - var index = lastChildToRemove - i; - this.removeChild(children[index], true); - } - } - - this._currentQuantityOfNodes = this._quantityOfNodes; - }, - title:function () { - return "C1 - Cloned Sprites"; - }, - subtitle:function () { - return "See fps (and source code of this test)."; - } -}); - -var ClonedSpritesTestScene2 = ClonedSpritesTestScene1.extend({ - updateQuantityOfNodes:function () { - if (!this.template) { - this.template = - new SimpleNewtonianSprite(this._batchNode.texture, - cc.rect(0, 0, 52, 139)); - this.template.visible = false; - } - this._super(); - this.arrayToUpdate = this.children; - }, - title:function () { - return "C2 - Cloned Sprites"; - }, - subtitle:function () { - return "No draw(). update() does heavy calculations."; - } -}); - -function runVirtualMachineTest() { - var scene = new SpritesWithManyPropertiesTestScene1(); - scene.initWithQuantityOfNodes(VM_NODES_INCREASE); - cc.director.runScene(scene); -} diff --git a/tests/js-tests/src/PerformanceTest/seedrandom.js b/tests/js-tests/src/PerformanceTest/seedrandom.js deleted file mode 100644 index 58b4a96158..0000000000 --- a/tests/js-tests/src/PerformanceTest/seedrandom.js +++ /dev/null @@ -1,272 +0,0 @@ -// seedrandom.js version 2.0. -// Author: David Bau 4/2/2011 -// -// Defines a method Math.seedrandom() that, when called, substitutes -// an explicitly seeded RC4-based algorithm for Math.random(). Also -// supports automatic seeding from local or network sources of entropy. -// -// Usage: -// -// -// -// Math.seedrandom('yipee'); Sets Math.random to a function that is -// initialized using the given explicit seed. -// -// Math.seedrandom(); Sets Math.random to a function that is -// seeded using the current time, dom state, -// and other accumulated local entropy. -// The generated seed string is returned. -// -// Math.seedrandom('yowza', true); -// Seeds using the given explicit seed mixed -// together with accumulated entropy. -// -// -// Seeds using physical random bits downloaded -// from random.org. -// -// Seeds using urandom bits from call.jsonlib.com, -// which is faster than random.org. -// -// Examples: -// -// Math.seedrandom("hello"); // Use "hello" as the seed. -// document.write(Math.random()); // Always 0.5463663768140734 -// document.write(Math.random()); // Always 0.43973793770592234 -// var rng1 = Math.random; // Remember the current prng. -// -// var autoseed = Math.seedrandom(); // New prng with an automatic seed. -// document.write(Math.random()); // Pretty much unpredictable. -// -// Math.random = rng1; // Continue "hello" prng sequence. -// document.write(Math.random()); // Always 0.554769432473455 -// -// Math.seedrandom(autoseed); // Restart at the previous seed. -// document.write(Math.random()); // Repeat the 'unpredictable' value. -// -// Notes: -// -// Each time seedrandom('arg') is called, entropy from the passed seed -// is accumulated in a pool to help generate future seeds for the -// zero-argument form of Math.seedrandom, so entropy can be injected over -// time by calling seedrandom with explicit data repeatedly. -// -// On speed - This javascript implementation of Math.random() is about -// 3-10x slower than the built-in Math.random() because it is not native -// code, but this is typically fast enough anyway. Seeding is more expensive, -// especially if you use auto-seeding. Some details (timings on Chrome 4): -// -// Our Math.random() - avg less than 0.002 milliseconds per call -// seedrandom('explicit') - avg less than 0.5 milliseconds per call -// seedrandom('explicit', true) - avg less than 2 milliseconds per call -// seedrandom() - avg about 38 milliseconds per call -// -// LICENSE (BSD): -// -// Copyright 2010 David Bau, all rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of this module nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/** - * All code is in an anonymous closure to keep the global namespace clean. - * - * @param {number=} overflow - * @param {number=} startdenom - */ -(function (pool, math, width, chunks, significance, overflow, startdenom) { - - -// -// seedrandom() -// This is the seedrandom function described above. -// -math.seedrandom = function seedrandom(seed, use_entropy) { - var key = []; - var arc4; - - // Flatten the seed string or build one from local entropy if needed. - seed = mixkey(flatten( - use_entropy ? [seed, pool] : - arguments.length ? seed : - [Date.now(), pool, window], 3), key); - - // Use the seed to initialize an ARC4 generator. - arc4 = new ARC4(key); - - // Mix the randomness into accumulated entropy. - mixkey(arc4.S, pool); - - // Override Math.random - - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - - math.random = function random() { // Closure to return a random double: - var n = arc4.g(chunks); // Start with a numerator n < 2 ^ 48 - var d = startdenom; // and denominator d = 2 ^ 48. - var x = 0; // and no 'extra last byte'. - while (n < significance) { // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - // Return the seed that was used - return seed; -}; - -// -// ARC4 -// -// An ARC4 implementation. The constructor takes a key in the form of -// an array of at most (width) integers that should be 0 <= x < (width). -// -// The g(count) method returns a pseudorandom integer that concatenates -// the next (count) outputs from ARC4. Its return value is a number x -// that is in the range 0 <= x < (width ^ count). -// -/** @constructor */ -function ARC4(key) { - var t, u, me = this, keylen = key.length; - var i = 0, j = me.i = me.j = me.m = 0; - me.S = []; - me.c = []; - - // The empty key [] is treated as [0]. - if (!keylen) { key = [keylen++]; } - - // Set up S using the standard key scheduling algorithm. - while (i < width) { me.S[i] = i++; } - for (i = 0; i < width; i++) { - t = me.S[i]; - j = lowbits(j + t + key[i % keylen]); - u = me.S[j]; - me.S[i] = u; - me.S[j] = t; - } - - // The "g" method returns the next (count) outputs as one number. - me.g = function getnext(count) { - var s = me.S; - var i = lowbits(me.i + 1); var t = s[i]; - var j = lowbits(me.j + t); var u = s[j]; - s[i] = u; - s[j] = t; - var r = s[lowbits(t + u)]; - while (--count) { - i = lowbits(i + 1); t = s[i]; - j = lowbits(j + t); u = s[j]; - s[i] = u; - s[j] = t; - r = r * width + s[lowbits(t + u)]; - } - me.i = i; - me.j = j; - return r; - }; - // For robust unpredictability discard an initial batch of values. - // See http://www.rsa.com/rsalabs/node.asp?id=2009 - me.g(width); -} - -// -// flatten() -// Converts an object tree to nested arrays of strings. -// -/** @param {Object=} result - * @param {string=} prop - * @param {string=} typ */ -function flatten(obj, depth, result, prop, typ) { - result = []; - typ = typeof(obj); - if (depth && typ == 'object') { - for (prop in obj) { - if (prop.indexOf('S') < 5) { // Avoid FF3 bug (local/sessionStorage) - try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} - } - } - } - return (result.length ? result : obj + (typ != 'string' ? '\0' : '')); -} - -// -// mixkey() -// Mixes a string seed into a key that is an array of integers, and -// returns a shortened string seed that is equivalent to the result key. -// -/** @param {number=} smear - * @param {number=} j */ -function mixkey(seed, key, smear, j) { - seed += ''; // Ensure the seed is a string - smear = 0; - for (j = 0; j < seed.length; j++) { - key[lowbits(j)] = - lowbits((smear ^= key[lowbits(j)] * 19) + seed.charCodeAt(j)); - } - seed = ''; - for (j in key) { seed += String.fromCharCode(key[j]); } - return seed; -} - -// -// lowbits() -// A quick "n mod width" for width a power of 2. -// -function lowbits(n) { return n & (width - 1); } - -// -// The following constants are related to IEEE 754 limits. -// -startdenom = math.pow(width, chunks); -significance = math.pow(2, significance); -overflow = significance * 2; - -// -// When seedrandom.js is loaded, we immediately mix a few bits -// from the built-in RNG into the entropy pool. Because we do -// not want to intefere with determinstic PRNG state later, -// seedrandom will not call math.random on its own again after -// initialization. -// -mixkey(math.random(), pool); - -// End anonymous scope, and pass initial values. -})( - [], // pool: entropy pool starts empty - Math, // math: package containing random, pow, and seedrandom - 256, // width: each RC4 output is 0 <= x < 256 - 6, // chunks: at least six RC4 outputs for each double - 52 // significance: there are 52 significant digits in a double -); diff --git a/tests/js-tests/src/tests-main.js b/tests/js-tests/src/tests-main.js index 7e311a6cad..358da7221d 100644 --- a/tests/js-tests/src/tests-main.js +++ b/tests/js-tests/src/tests-main.js @@ -535,15 +535,6 @@ var testNames = [ return new PathTestScene(); } }, - { - title:"Performance Test", - platforms: PLATFORM_ALL, - linksrc:"", - resource:g_performace, - testScene:function () { - return new PerformanceTestScene(); - } - }, { title:"Physics3D Test", platforms: PLATFORM_JSB, diff --git a/tests/lua-tests/src/PerformanceTest/PerformanceSpriteTest.lua b/tests/lua-tests/src/PerformanceTest/PerformanceSpriteTest.lua deleted file mode 100644 index 78050ac48e..0000000000 --- a/tests/lua-tests/src/PerformanceTest/PerformanceSpriteTest.lua +++ /dev/null @@ -1,552 +0,0 @@ -local kMaxNodes = 50000 -local kBasicZOrder = 10 -local kNodesIncrease = 250 -local TEST_COUNT = 7 - -local s = cc.Director:getInstance():getWinSize() - ------------------------------------ --- For test functions ------------------------------------ -local function performanceActions(sprite) - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) - - local period = 0.5 + math.mod(math.random(1, 99999999), 1000) / 500.0 - local rot = cc.RotateBy:create(period, 360.0 * math.random()) - local rot = cc.RotateBy:create(period, 360.0 * math.random()) - local permanentRotation = cc.RepeatForever:create(cc.Sequence:createWithTwoActions(rot, rot:reverse())) - sprite:runAction(permanentRotation) - - local growDuration = 0.5 + math.mod(math.random(1, 99999999), 1000) / 500.0 - local grow = cc.ScaleBy:create(growDuration, 0.5, 0.5) - local permanentScaleLoop = cc.RepeatForever:create(cc.Sequence:createWithTwoActions(grow, grow:reverse())) - sprite:runAction(permanentScaleLoop) -end - -local function performanceActions20(sprite) - if math.random() < 0.2 then - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) - else - sprite:setPosition(cc.p(-1000, -1000)) - end - - local period = 0.5 + math.mod(math.random(1, 99999999), 1000) / 500.0 - local rot = cc.RotateBy:create(period, 360.0 * math.random()) - local permanentRotation = cc.RepeatForever:create(cc.Sequence:createWithTwoActions(rot, rot:reverse())) - sprite:runAction(permanentRotation) - - local growDuration = 0.5 + math.mod(math.random(1, 99999999), 1000) / 500.0 - local grow = cc.ScaleBy:create(growDuration, 0.5, 0.5) - local permanentScaleLoop = cc.RepeatForever:create(cc.Sequence:createWithTwoActions(grow, grow:reverse())) - sprite:runAction(permanentScaleLoop) -end - -local function performanceRotationScale(sprite) - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) - sprite:setRotation(math.random() * 360) - sprite:setScale(math.random() * 2) -end - -local function performancePosition(sprite) - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) -end - -local function performanceout20(sprite) - if math.random() < 0.2 then - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) - else - sprite:setPosition(cc.p(-1000, -1000)) - end -end - -local function performanceOut100(sprite) - sprite:setPosition(cc.p( -1000, -1000)) -end - -local function performanceScale(sprite) - sprite:setPosition(cc.p(math.mod(math.random(1, 99999999), s.width), math.mod(math.random(1, 99999999), s.height))) - sprite:setScale(math.random() * 100 / 50) -end - ------------------------------------ --- Subtest ------------------------------------ -local subtestNumber = 1 -local batchNode = nil -- cc.SpriteBatchNode -local parent = nil -- cc.Node - -local function initWithSubTest(nSubTest, p) - subtestNumber = nSubTest - parent = p - batchNode = nil - - local mgr = cc.Director:getInstance():getTextureCache() - -- remove all texture - mgr:removeTexture(mgr:addImage("Images/grossinis_sister1.png")) - mgr:removeTexture(mgr:addImage("Images/grossini_dance_atlas.png")) - mgr:removeTexture(mgr:addImage("Images/spritesheet1.png")) - - if subtestNumber == 2 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - batchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) - p:addChild(batchNode, 0) - elseif subtestNumber == 3 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - batchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) - p:addChild(batchNode, 0) - elseif subtestNumber == 5 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - batchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) - p:addChild(batchNode, 0) - elseif subtestNumber == 6 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - batchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) - p:addChild(batchNode, 0) - elseif subtestNumber == 8 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - batchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) - p:addChild(batchNode, 0) - elseif subtestNumber == 9 then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - batchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) - p:addChild(batchNode, 0) - end - - -- todo - if batchNode ~= nil then - batchNode:retain() - end - - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT) -end - -local function createSpriteWithTag(tag) - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - - local sprite = nil - if subtestNumber == 1 then - sprite = cc.Sprite:create("Images/grossinis_sister1.png") - parent:addChild(sprite, -1, tag + 100) - elseif subtestNumber == 2 then - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(0, 0, 52, 139)) - batchNode:addChild(sprite, 0, tag + 100) - elseif subtestNumber == 3 then - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(0, 0, 52, 139)) - batchNode:addChild(sprite, 0, tag + 100) - elseif subtestNumber == 4 then - local idx = math.floor((math.random() * 1400 / 100)) + 1 - local num - if idx < 10 then - num = "0" .. idx - else - num = idx - end - local str = "Images/grossini_dance_" .. num .. ".png" - sprite = cc.Sprite:create(str) - parent:addChild(sprite, -1, tag + 100) - elseif subtestNumber == 5 then - local y, x - local r = math.floor(math.random() * 1400 / 100) - y = math.floor(r / 5) - x = math.mod(r, 5) - x = x * 85 - y = y * 121 - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(x, y, 85, 121)) - batchNode:addChild(sprite, 0, tag + 100) - elseif subtestNumber == 6 then - local y, x - local r = math.floor(math.random() * 1400 / 100) - y = math.floor(r / 5) - x = math.mod(r, 5) - x = x * 85 - y = y * 121 - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(x, y, 85, 121)) - batchNode:addChild(sprite, 0, tag + 100) - elseif subtestNumber == 7 then - local y, x - local r = math.floor(math.random() * 6400 / 100) - y = math.floor(r / 8) - x = math.mod(r, 8) - local str = "Images/sprites_test/sprite-"..x.."-"..y..".png" - sprite = cc.Sprite:create(str) - parent:addChild(sprite, -1, tag + 100) - elseif subtestNumber == 8 then - local y, x - local r = math.floor(math.random() * 6400 / 100) - y = math.floor(r / 8) - x = math.mod(r, 8) - x = x * 32 - y = y * 32 - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(x, y, 32, 32)) - batchNode:addChild(sprite, 0, tag + 100) - elseif subtestNumber == 9 then - local y, x - local r = math.floor(math.random() * 6400 / 100) - y = math.floor(r / 8) - x = math.mod(r, 8) - x = x * 32 - y = y * 32 - sprite = cc.Sprite:createWithTexture(batchNode:getTexture(), cc.rect(x, y, 32, 32)) - batchNode:addChild(sprite, 0, tag + 100) - end - - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT) - - return sprite -end - -local function removeByTag(tag) - if subtestNumber == 1 then - parent:removeChildByTag(tag + 100, true) - elseif subtestNumber == 4 then - parent:removeChildByTag(tag + 100, true) - elseif subtestNumber == 7 then - parent:removeChildByTag(tag + 100, true) - else - batchNode:removeChildAtIndex(tag, true) - end -end - ------------------------------------ --- PerformBasicLayer ------------------------------------ -local curCase = 0 -local maxCases = 7 - -local function showThisTest() - local scene = CreateSpriteTestScene() - cc.Director:getInstance():replaceScene(scene) -end - -local function backCallback(sender) - subtestNumber = 1 - curCase = curCase - 1 - if curCase < 0 then - curCase = curCase + maxCases - end - showThisTest() -end - -local function restartCallback(sender) - subtestNumber = 1 - showThisTest() -end - -local function nextCallback(sender) - subtestNumber = 1 - curCase = curCase + 1 - curCase = math.mod(curCase, maxCases) - showThisTest() -end - -local function toPerformanceMainLayer(sender) - cc.Director:getInstance():replaceScene(PerformanceTest()) -end - -local function initWithLayer(layer, controlMenuVisible) - cc.MenuItemFont:setFontName("Arial") - cc.MenuItemFont:setFontSize(24) - local mainItem = cc.MenuItemFont:create("Back") - mainItem:registerScriptTapHandler(toPerformanceMainLayer) - mainItem:setPosition(s.width - 50, 25) - local menu = cc.Menu:create() - menu:addChild(mainItem) - menu:setPosition(cc.p(0, 0)) - - if controlMenuVisible == true then - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - item1:setPosition(s.width / 2 - 100, 30) - item2:setPosition(s.width / 2, 30) - item3:setPosition(s.width / 2 + 100, 30) - - menu:addChild(item1, kItemTagBasic) - menu:addChild(item2, kItemTagBasic) - menu:addChild(item3, kItemTagBasic) - end - layer:addChild(menu) -end - ------------------------------------ --- SpriteMainScene ------------------------------------ -local lastRenderedCount = nil -local quantityNodes = nil - -local infoLabel = nil -local titleLabel = nil - -local function testNCallback(tag) - subtestNumber = tag - kBasicZOrder - showThisTest() -end - -local function updateNodes() - if quantityNodes ~= lastRenderedCount then - local str = quantityNodes .. " nodes" - infoLabel:setString(str) - lastRenderedCount = quantityNodes - end -end - -local function onDecrease(sender) - if quantityNodes <= 0 then - return - end - - for i = 0, kNodesIncrease - 1 do - quantityNodes = quantityNodes - 1 - removeByTag(quantityNodes) - end - updateNodes() -end - -local function onIncrease(sender) - if quantityNodes >= kMaxNodes then - return - end - - for i = 0, kNodesIncrease - 1 do - local sprite = createSpriteWithTag(quantityNodes) - - if curCase == 0 then - doPerformSpriteTest1(sprite) - elseif curCase == 1 then - doPerformSpriteTest2(sprite) - elseif curCase == 2 then - doPerformSpriteTest3(sprite) - elseif curCase == 3 then - doPerformSpriteTest4(sprite) - elseif curCase == 4 then - doPerformSpriteTest5(sprite) - elseif curCase == 5 then - doPerformSpriteTest6(sprite) - elseif curCase == 6 then - doPerformSpriteTest7(sprite) - end - - quantityNodes = quantityNodes + 1 - end - - updateNodes() -end - -local function initWithMainTest(scene, asubtest, nNodes) - subtestNumber = asubtest - initWithSubTest(asubtest, scene) - - lastRenderedCount = 0 - quantityNodes = 0 - - cc.MenuItemFont:setFontSize(65) - local decrease = cc.MenuItemFont:create(" - ") - decrease:registerScriptTapHandler(onDecrease) - decrease:setColor(cc.c3b(0, 200, 20)) - local increase = cc.MenuItemFont:create(" + ") - increase:registerScriptTapHandler(onIncrease) - increase:setColor(cc.c3b(0, 200, 20)) - - local menu = cc.Menu:create() - menu:addChild(decrease) - menu:addChild(increase) - menu:alignItemsHorizontally() - menu:setPosition(s.width / 2, s.height - 65) - scene:addChild(menu, 1) - - infoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30) - infoLabel:setColor(cc.c3b(0, 200, 20)) - infoLabel:setAnchorPoint(cc.p(0.5, 0.5)) - infoLabel:setPosition(s.width / 2, s.height - 90) - scene:addChild(infoLabel, 1) - - maxCases = TEST_COUNT - - -- Sub Tests - cc.MenuItemFont:setFontSize(32) - subMenu = cc.Menu:create() - for i = 1, 9 do - local str = i .. " " - local itemFont = cc.MenuItemFont:create(str) - itemFont:registerScriptTapHandler(testNCallback) - --itemFont:setTag(i) - subMenu:addChild(itemFont, kBasicZOrder + i, kBasicZOrder + i) - - if i <= 3 then - itemFont:setColor(cc.c3b(200, 20, 20)) - elseif i <= 6 then - itemFont:setColor(cc.c3b(0, 200, 20)) - else - itemFont:setColor(cc.c3b(0, 20, 200)) - end - end - - subMenu:alignItemsHorizontally() - subMenu:setPosition(cc.p(s.width / 2, 80)) - scene:addChild(subMenu, 1) - - -- add title label - titleLabel = cc.Label:createWithTTF("No title", s_arialPath, 40) - scene:addChild(titleLabel, 1) - titleLabel:setAnchorPoint(cc.p(0.5, 0.5)) - titleLabel:setPosition(s.width / 2, s.height - 32) - titleLabel:setColor(cc.c3b(255, 255, 40)) - - while quantityNodes < nNodes do - onIncrease() - end -end - ------------------------------------ --- SpritePerformTest1 ------------------------------------ -function doPerformSpriteTest1(sprite) - performancePosition(sprite) -end - -local function SpriteTestLayer1() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "A (" .. subtestNumber .. ") position" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest2 ------------------------------------ -function doPerformSpriteTest2(sprite) - performanceScale(sprite) -end - -local function SpriteTestLayer2() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "B (" .. subtestNumber .. ") scale" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest3 ------------------------------------ -function doPerformSpriteTest3(sprite) - performanceRotationScale(sprite) -end - -local function SpriteTestLayer3() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "C (" .. subtestNumber .. ") scale + rot" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest4 ------------------------------------ -function doPerformSpriteTest4(sprite) - performanceOut100(sprite) -end - -local function SpriteTestLayer4() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "D (" .. subtestNumber .. ") 100% out" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest5 ------------------------------------ -function doPerformSpriteTest5(sprite) - performanceout20(sprite) -end - -local function SpriteTestLayer5() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "E (" .. subtestNumber .. ") 80% out" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest6 ------------------------------------ -function doPerformSpriteTest6(sprite) - performanceActions(sprite) -end - -local function SpriteTestLayer6() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "F (" .. subtestNumber .. ") actions" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- SpritePerformTest7 ------------------------------------ -function doPerformSpriteTest7(sprite) - performanceActions20(sprite) -end - -local function SpriteTestLayer7() - local layer = cc.Layer:create() - initWithLayer(layer, true) - - local str = "G (" .. subtestNumber .. ") actions 80% out" - titleLabel:setString(str) - - return layer -end - ------------------------------------ --- PerformanceSpriteTest ------------------------------------ -function CreateSpriteTestScene() - local scene = cc.Scene:create() - initWithMainTest(scene, subtestNumber, kNodesIncrease) - - if curCase == 0 then - scene:addChild(SpriteTestLayer1()) - elseif curCase == 1 then - scene:addChild(SpriteTestLayer2()) - elseif curCase == 2 then - scene:addChild(SpriteTestLayer3()) - elseif curCase == 3 then - scene:addChild(SpriteTestLayer4()) - elseif curCase == 4 then - scene:addChild(SpriteTestLayer5()) - elseif curCase == 5 then - scene:addChild(SpriteTestLayer6()) - elseif curCase == 6 then - scene:addChild(SpriteTestLayer7()) - end - - return scene -end - -function PerformanceSpriteTest() - curCase = 0 - - return CreateSpriteTestScene() -end diff --git a/tests/lua-tests/src/PerformanceTest/PerformanceTest.lua b/tests/lua-tests/src/PerformanceTest/PerformanceTest.lua deleted file mode 100644 index 3963d03e34..0000000000 --- a/tests/lua-tests/src/PerformanceTest/PerformanceTest.lua +++ /dev/null @@ -1,1950 +0,0 @@ -require "PerformanceTest/PerformanceSpriteTest" - -local MAX_COUNT = 6 -local LINE_SPACE = 40 -local kItemTagBasic = 1000 - -local testsName = -{ - "PerformanceNodeChildrenTest", - "PerformanceParticleTest", - "PerformanceSpriteTest", - "PerformanceTextureTest", - "PerformanceTouchesTest", - "PerformanceFuncRelateWithTable", -} - -local s = cc.Director:getInstance():getWinSize() - ---Create toMainLayr MenuItem -function CreatePerfomBasicLayerMenu(pMenu) - if nil == pMenu then - return - end - local function toMainLayer() - local pScene = PerformanceTestMain() - if pScene ~= nil then - cc.Director:getInstance():replaceScene(pScene) - end - end - --Create BackMneu - cc.MenuItemFont:setFontName("Arial") - cc.MenuItemFont:setFontSize(24) - local pMenuItemFont = cc.MenuItemFont:create("Back") - pMenuItemFont:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25)) - pMenuItemFont:registerScriptTapHandler(toMainLayer) - pMenu:addChild(pMenuItemFont) -end - ----------------------------------- ---PerformanceNodeChildrenTest ----------------------------------- -local NodeChildrenTestParam = -{ - kTagInfoLayer = 1, - kTagMainLayer = 2, - kTagLabelAtlas = 3, - kTagBase = 20000, - TEST_COUNT = 4, - kMaxNodes = 15000, - kNodesIncrease = 500, -} - -local function runNodeChildrenTest() - --NodeChildrenMainScene - local nLastRenderedCount = 0 - local nQuantityOfNodes = 0 - local nCurrentQuantityOfNodes = 0 - --IterateSpriteSheet - local pBatchNode = nil - - --BasiceLayer param - local bControlMenuVisible = false - local nMaxCases = 0 - local nCurCase = 0 - - local pNewscene = cc.Scene:create() - - local function GetTitle() - if 0 == nCurCase then - return "B - Iterate SpriteSheet" - elseif 1 == nCurCase then - return "C - Add to spritesheet" - elseif 2 == nCurCase then - return "D - Del from spritesheet" - elseif 3 == nCurCase then - return "E - Reorder from spritesheet" - end - end - - local function GetSubTitle() - if 0 == nCurCase then - return "Iterate children using C Array API. See console" - elseif 1 == nCurCase then - return "Adds %10 of total sprites with random z. See console" - elseif 2 == nCurCase then - return "Remove %10 of total sprites placed randomly. See console" - elseif 3 == nCurCase then - return "Reorder %10 of total sprites placed randomly. See console" - end - end - - local function GetProfilerName() - if 0 == nCurCase then - return "iter c-array" - elseif 1 == nCurCase then - return "add sprites" - elseif 2 == nCurCase then - return "remove sprites" - elseif 3 == nCurCase then - return "reorder sprites" - end - end - - local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end - - local function restartCallback() - ShowCurrentTest() - end - - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end - end - - local function updateQuantityLabel() - if nQuantityOfNodes ~= nLastRenderedCount then - -- local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local strNode = nQuantityOfNodes.." nodes" - pInfoLabel:setString(strNode) - nLastRenderedCount = nQuantityOfNodes - end - end - - local function IterateSpriteSheetCArrayUpdate(t) - if nil == pBatchNode then - return - end - local pChildren = pBatchNode:getChildren() - local pObject = nil - if nil == pChildren then - return - end - local i = 0 - local len = table.getn(pChildren) - for i = 0, len - 1, 1 do - local child = pChildren[i + 1] - child:setVisible(false) - end - end - - local function AddSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end - - --15 percent - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - local zs = {} - if nTotalToAdd > 0 then - local pSprites = {} - local i = 0 - for i = 0 , nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) - pSprites[i + 1] = pSprite - zs[i] = math.random(-1,1) * 50 - end - - for i = 0 , nTotalToAdd - 1 do - local pChild = pSprites[i + 1] - pBatchNode:addChild(pChild, zs[i], NodeChildrenTestParam.kTagBase + i) - end - - pBatchNode:sortAllChildren() - - for i = 0 , nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) - end - end - end - - local function RemoveSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - if nTotalToAdd > 0 then - local pSprites = {} - -- Don't include the sprite creation time as part of the profiling - local i = 0 - for i = 0, nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) - pSprites[i + 1] = pSprite - end - -- add them with random Z (very important!) - for i=0, nTotalToAdd - 1 do - local pChild = pSprites[i + 1] - pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) - end - - for i = 0, nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) - end - end - end - - local function ReorderSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end - -- 15 percent - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - - if nTotalToAdd > 0 then - local pSprites = {} - -- Don't include the sprite creation time as part of the profiling - local i = 0 - for i = 0,nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) - pSprites[i + 1] = pSprite - end - - --dd them with random Z (very important!) - for i = 0, nTotalToAdd - 1 do - local pChild = pSprites[i + 1] - pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) - end - - pBatchNode:sortAllChildren() - - -- reorder them - for i = 0, nTotalToAdd - 1 do - local pNode = pSprites[i + 1] - pBatchNode:reorderChild(pNode, math.random(-1,1) * 50) - end - pBatchNode:sortAllChildren() - --remove them - for i = 0, nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase+i, true) - end - end - end - - local function NodeChildrenScheduleUpdate() - if 0 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(IterateSpriteSheetCArrayUpdate,0) - elseif 1 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(AddSpriteSheetUpdate,0) - elseif 2 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(RemoveSpriteSheetUpdate,0) - elseif 3 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(ReorderSpriteSheetUpdate,0) - end - end - - local function updateQuantityOfNodes() - local s = cc.Director:getInstance():getWinSize() - --increase nodes - if( nCurrentQuantityOfNodes < nQuantityOfNodes ) then - local i = 0 - for i = 0,nQuantityOfNodes - nCurrentQuantityOfNodes - 1 do - local sprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 32, 32)) - pBatchNode:addChild(sprite) - sprite:setPosition(cc.p( math.random() * s.width, math.random() * s.height)) - if 0 ~= nCurCase then - sprite:setVisible(false) - end - end - elseif (nCurrentQuantityOfNodes > nQuantityOfNodes ) then - i = 0 - for i = 0, nCurrentQuantityOfNodes - nQuantityOfNodes - 1 do - local index = nCurrentQuantityOfNodes - i - 1 - pBatchNode:removeChildAtIndex(index, true) - end - end - - - nCurrentQuantityOfNodes = nQuantityOfNodes - end - - local function onDecrease() - nQuantityOfNodes = nQuantityOfNodes - NodeChildrenTestParam.kNodesIncrease - if nQuantityOfNodes < 0 then - nQuantityOfNodes = 0 - end - - updateQuantityLabel() - updateQuantityOfNodes() - end - - local function onIncrease() - nQuantityOfNodes = nQuantityOfNodes + NodeChildrenTestParam.kNodesIncrease - if nQuantityOfNodes > NodeChildrenTestParam.kMaxNodes then - nQuantityOfNodes = NodeChildrenTestParam.kMaxNodes - end - - updateQuantityLabel() - updateQuantityOfNodes() - end - - - local function SpecialInitWithQuantityOfNodes() - -- if 0 == nCurCase then - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") - pNewscene:addChild(pBatchNode) - --[[ - else - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") - pNewscene:addChild(pBatchNode) - end - ]]-- - end - - local function MainSceneInitWithQuantityOfNodes(nNodes) - local s = cc.Director:getInstance():getWinSize() - - --Title - local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40) - pNewscene:addChild(pLabel, 1) - pLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then - local pSubLabel = cc.Label:createWithTTF(GetSubTitle(), s_thonburiPath, 16) - pNewscene:addChild(pSubLabel, 1) - pSubLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pSubLabel:setPosition(cc.p(s.width/2, s.height-80)) - end - - nLastRenderedCount = 0 - nCurrentQuantityOfNodes = 0 - nQuantityOfNodes = nNodes - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewscene:addChild(pMenuAddOrSub,1) - - --InfoLayer - local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30) - pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height/2-15)) - pNewscene:addChild(pInfoLabel, 1, NodeChildrenTestParam.kTagInfoLayer) - - --NodeChildrenMenuLayer - local pNodeChildrenMenuLayer = cc.Layer:create() - local pNodeChildrenMenuMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pNodeChildrenMenuMenu) - CreateBasicLayerMenuItem(pNodeChildrenMenuMenu,true,NodeChildrenTestParam.TEST_COUNT,nCurCase) - pNodeChildrenMenuMenu:setPosition(cc.p(0, 0)) - pNodeChildrenMenuLayer:addChild(pNodeChildrenMenuMenu) - pNewscene:addChild(pNodeChildrenMenuLayer) - - updateQuantityLabel() - updateQuantityOfNodes() - - end - - function ShowCurrentTest() - if nil ~= pNewscene then - pNewscene:unscheduleUpdate() - end - - pNewscene = cc.Scene:create() - if nil ~= pNewscene then - SpecialInitWithQuantityOfNodes() - MainSceneInitWithQuantityOfNodes(nQuantityOfNodes) --- pNewscene:registerScriptHandler(onNodeEvent) - NodeChildrenScheduleUpdate() - cc.Director:getInstance():replaceScene(pNewscene) - end - end - - SpecialInitWithQuantityOfNodes() - MainSceneInitWithQuantityOfNodes(NodeChildrenTestParam.kNodesIncrease) --- pNewscene:registerScriptHandler(onNodeEvent) - NodeChildrenScheduleUpdate() - - return pNewscene -end ----------------------------------- ---PerformanceParticleTest ----------------------------------- -local ParticleTestParam = -{ - kTagInfoLayer = 1, - kTagMainLayer = 2, - kTagParticleSystem = 3, - kTagLabelAtlas = 4, - kTagMenuLayer = 1000, - - TEST_COUNT = 4, - kMaxParticles = 14000, - kNodesIncrease = 500, - - kSubMenuBasicZOrder = 10 -} - -local function runParticleTest() - --PerformanceParticle param - local nLastRenderedCount = 0 - local nQuantityParticles = 0 - local nSubtestNumber = 0 - --BasiceLayer param - local bControlMenuVisible = false - local nMaxCases = 0 - local nCurCase = 0 - - local ScheduleSelector = nil - - local pNewScene = cc.Scene:create() - - local function GetTitle() - local strTitle = nil - if 0 == nCurCase then - strTitle = string.format("A (%d) size=4",nSubtestNumber) - elseif 1 == nCurCase then - strTitle = string.format("B (%d) size=8",nSubtestNumber) - elseif 2 == nCurCase then - strTitle = string.format("C (%d) size=32",nSubtestNumber) - elseif 3 == nCurCase then - strTitle = string.format("D (%d) size=64",nSubtestNumber) - end - return strTitle - end - - local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end - - local function restartCallback() - ShowCurrentTest() - end - - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end - end - - local function TestNCallback(tag,pMenuItem) - local nIndex = pMenuItem:getLocalZOrder() - ParticleTestParam.kSubMenuBasicZOrder - nSubtestNumber = nIndex - ShowCurrentTest() - end - - local function UpdateQuantityLabel() - if nQuantityParticles ~= nLastRenderedCount then - local pInfoLabel = pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer) - local strInfo = string.format("%u particles", nQuantityParticles) - pInfoLabel:setString(strInfo) - - nLastRenderedCount = nQuantityParticles - end - end - - local function doTest() - local s = cc.Director:getInstance():getWinSize() - local pParticleSystem = pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem) - if nil == pParticleSystem then - return - end - if 0 == nCurCase then - --duration - pParticleSystem:setDuration(-1) - - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) - - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) - - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles - pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) - - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) - - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - -- size, in pixels - pParticleSystem:setEndSize(4.0) - pParticleSystem:setStartSize(4.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - - elseif 1 == nCurCase then - --duration - pParticleSystem:setDuration(-1) - - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) - - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) - - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles - pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) - - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) - - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - -- size, in pixels - pParticleSystem:setEndSize(8.0) - pParticleSystem:setStartSize(8.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - elseif 2 == nCurCase then - --duration - pParticleSystem:setDuration(-1) - - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) - - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) - - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles - pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) - - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) - - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - -- size, in pixels - pParticleSystem:setEndSize(32.0) - pParticleSystem:setStartSize(32.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - elseif 3 == nCurCase then - --duration - pParticleSystem:setDuration(-1) - - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) - - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) - - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles - pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) - - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) - - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - - -- size, in pixels - pParticleSystem:setEndSize(64.0) - pParticleSystem:setStartSize(64.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - end - end - - local function CreateParticleSystem() - local pParticleSystem = nil - --[[ - * Tests: - * 1: Point Particle System using 32-bit textures (PNG) - * 2: Point Particle System using 16-bit textures (PNG) - * 3: Point Particle System using 8-bit textures (PNG) - * 4: Point Particle System using 4-bit textures (PVRTC) - - * 5: Quad Particle System using 32-bit textures (PNG) - * 6: Quad Particle System using 16-bit textures (PNG) - * 7: Quad Particle System using 8-bit textures (PNG) - * 8: Quad Particle System using 4-bit textures (PVRTC) - ]]-- - pNewScene:removeChildByTag(ParticleTestParam.kTagParticleSystem, true) - - --remove the "fire.png" from the TextureCache cache. - local pTexture = cc.Director:getInstance():getTextureCache():addImage("Images/fire.png") - cc.Director:getInstance():getTextureCache():removeTexture(pTexture) - local pParticleSystem = cc.ParticleSystemQuad:createWithTotalParticles(nQuantityParticles) - if 1 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - elseif 2 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - elseif 3 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) - elseif 4 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - elseif 5 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - elseif 6 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) - else - pParticleSystem = nil - print("Shall not happen!") - end - - if nil ~= pParticleSystem then - pParticleSystem:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png")) - end - - pNewScene:addChild(pParticleSystem, 0, ParticleTestParam.kTagParticleSystem) - - doTest() - --restore the default pixel format - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - end - - local function step(t) - local pAtlas = pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas) - local pEmitter = pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem) - local strInfo = string.format("%4d",pEmitter:getParticleCount()) - pAtlas:setString(strInfo) - end - - local function ScheduleFuncion() - local function OnEnterOrExit(tag) - local scheduler = cc.Director:getInstance():getScheduler() - if tag == "enter" then - ScheduleSelector = scheduler:scheduleScriptFunc(step,0,false) - elseif tag == "exit" then - scheduler:unscheduleScriptEntry(ScheduleSelector) - end - end - pNewScene:registerScriptHandler(OnEnterOrExit) - end - - local function onDecrease() - nQuantityParticles = nQuantityParticles - ParticleTestParam.kNodesIncrease - if nQuantityParticles < 0 then - nQuantityParticles = 0 - end - - UpdateQuantityLabel() - CreateParticleSystem() - end - - local function onIncrease() - nQuantityParticles = nQuantityParticles + ParticleTestParam.kNodesIncrease - if nQuantityParticles > ParticleTestParam.kMaxParticles then - nQuantityParticles = ParticleTestParam.kMaxParticles - end - - UpdateQuantityLabel() - CreateParticleSystem() - end - - local function InitWithSubTest(nSubtest,nParticles) - nSubtestNumber = nSubtest - local s = cc.Director:getInstance():getWinSize() - - nLastRenderedCount = 0 - nQuantityParticles = nParticles - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewScene:addChild(pMenuAddOrSub,1) - - local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30) - pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) - pNewScene:addChild(pInfoLabel, 1, ParticleTestParam.kTagInfoLayer) - - --particles on stage - local pLabelAtlas = cc.LabelAtlas:_create("0000", "fps_images.png", 12, 32, string.byte('.')) - pNewScene:addChild(pLabelAtlas, 0, ParticleTestParam.kTagLabelAtlas) - pLabelAtlas:setPosition(cc.p(s.width-66,50)) - - --ParticleTestMenuLayer - local pParticleMenuLayer = cc.Layer:create() - local pParticleMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pParticleMenu) - CreateBasicLayerMenuItem(pParticleMenu,true,ParticleTestParam.TEST_COUNT,nCurCase) - pParticleMenu:setPosition(cc.p(0, 0)) - pParticleMenuLayer:addChild(pParticleMenu) - pNewScene:addChild(pParticleMenuLayer) - - --Sub Tests - cc.MenuItemFont:setFontSize(40) - local pSubMenu = cc.Menu:create() - local i = 1 - for i = 1, 6 do - local strNum = string.format("%d ",i) - local pItemFont = cc.MenuItemFont:create(strNum) - pItemFont:registerScriptTapHandler(TestNCallback) - pSubMenu:addChild(pItemFont, i + ParticleTestParam.kSubMenuBasicZOrder) - if i <= 3 then - pItemFont:setColor(cc.c3b(200,20,20)) - else - pItemFont:setColor(cc.c3b(0,200,20)) - end - end - pSubMenu:alignItemsHorizontally() - pSubMenu:setPosition(cc.p(s.width/2, 80)) - pNewScene:addChild(pSubMenu, 2) - - local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40) - pNewScene:addChild(pLabel, 1) - pLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - UpdateQuantityLabel() - CreateParticleSystem() - ScheduleFuncion() - end - - function ShowCurrentTest() - if nil ~= pNewScene then - cc.Director:getInstance():getScheduler():unscheduleScriptEntry(ScheduleSelector) - end - pNewScene = cc.Scene:create() - InitWithSubTest(nSubtestNumber,nQuantityParticles) - cc.Director:getInstance():replaceScene(pNewScene) - end - - - InitWithSubTest(1,ParticleTestParam.kNodesIncrease) - return pNewScene -end - ----------------------------------- ---PerformanceSpriteTest ----------------------------------- -local SpriteTestParam = -{ - kMaxNodes = 50000, - kNodesIncrease = 250, - TEST_COUNT = 7, - - kTagInfoLayer = 1, - kTagMainLayer = 2, - -- 50000 -- kMaxNodes - kTagMenuLayer = 50000 + 1000, - kInitNodes = 50, - kSubMenuBasicZOrder = 20, - - kRandMax = 32767 -} - -local function runSpriteTest() - --PerformanceParticle param - local nLastRenderedCount = 0 - local nQuantityNodes = 0 - local nSubtestNumber = 0 - --BasiceLayer param - local bControlMenuVisible = false - local nMaxCases = 0 - local nCurCase = 0 - - local ScheduleSelector = nil - - --SubTest - local pBatchNode = nil - - local function GetTitle() - local strTitle = nil - if 0 == nCurCase then - strTitle = string.format("A (%d) position",nSubtestNumber) - elseif 1 == nCurCase then - strTitle = string.format("B (%d) scale",nSubtestNumber) - elseif 2 == nCurCase then - strTitle = string.format("C (%d) scale + rot",nSubtestNumber) - elseif 3 == nCurCase then - strTitle = string.format("D (%d) 100%% out",nSubtestNumber) - elseif 4 == nCurCase then - strTitle = string.format("E (%d) 80%% out",nSubtestNumber) - elseif 5 == nCurCase then - strTitle = string.format("F (%d) actions",nSubtestNumber) - elseif 6 == nCurCase then - strTitle = string.format("G (%d) actions 80%% out",nSubtestNumber) - end - - return strTitle - end - - local pNewScene = cc.Scene:create() - - local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end - - local function restartCallback() - ShowCurrentTest() - end - - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end - end - - local function UpdateNodes() - if nQuantityNodes ~= nLastRenderedCount then - local pInfoLabel = pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer) - local strInfo = string.format("%u nodes", nQuantityNodes) - pInfoLabel:setString(strInfo) - nLastRenderedCount = nQuantityNodes - end - end - - local function PerformancePosition(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - end - - local function PerformanceScale(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - pSprite:setScale(math.random() * 100 / 50) - end - - local function PerformanceRotationScale(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - pSprite:setRotation(math.random() * 360) - pSprite:setScale(math.random() * 2) - end - - local function PerformanceOut100(pSprite) - pSprite:setPosition(cc.p( -1000, -1000)) - end - - local function Performanceout20(pSprite) - local size = cc.Director:getInstance():getWinSize() - print("come in") - if math.random() < 0.2 then - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - else - pSprite:setPosition(cc.p( -1000, -1000)) - end - end - - local function PerformanceActions(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - - local fPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pRot = cc.RotateBy:create(fPeriod, 360.0 * math.random() ) - local pRot_back = pRot:reverse() - local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) - pSprite:runAction(pPermanentRotation) - - local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) - local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse())) - pSprite:runAction(pPermanentScaleLoop) - end - - local function PerformanceActions20(pSprite) - local size = cc.Director:getInstance():getWinSize() - - if math.random() < 0.2 then - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - else - pSprite:setPosition(cc.p( -1000, -1000)) - end - - local pPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pRot = cc.RotateBy:create(pPeriod, 360.0 * math.random()) - local pRot_back = pRot:reverse() - local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) - pSprite:runAction(pPermanentRotation) - - - local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) - local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse())) - pSprite:runAction(pPermanentScaleLoop) - - end - - local function CreateSpriteWithTag(nTag) - --create - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - local pSprite = nil - if 1 == nSubtestNumber then - pSprite = cc.Sprite:create("Images/grossinis_sister1.png") - pNewScene:addChild(pSprite, 0, nTag+100) - elseif 2 == nSubtestNumber or 3 == nSubtestNumber then - pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 52, 139)) - pBatchNode:addChild(pSprite, 0, nTag+100) - elseif 4 == nSubtestNumber then - local nIndex = math.floor((math.random() * 1400 / 100)) + 1 - local strPath = string.format("Images/grossini_dance_%02d.png", nIndex) - pSprite = cc.Sprite:create(strPath) - pNewScene:addChild(pSprite, 0, nTag+100) - elseif 5 == nSubtestNumber or 6 == nSubtestNumber then - local nY = 0 - local nX = 0 - local nR = math.floor(math.random() * 1400 / 100) - - nX = nR % 5 - nY = math.floor(nR / 5) - - nX = nX * 85 - nY = nY * 121 - pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,85,121)) - pBatchNode:addChild(pSprite, 0, nTag+100) - elseif 7 == nSubtestNumber then - local nX = 0 - local nY = 0 - local nR = math.floor(math.random() * 6400 / 100) - - nX = nR % 8 - nY = math.floor(nR / 8) - - local strPath = string.format("Images/sprites_test/sprite-%d-%d.png", nX, nY) - pSprite = cc.Sprite:create(strPath) - pNewScene:addChild(pSprite, 0, nTag+100) - elseif 8 == nSubtestNumber or 9 == nSubtestNumber then - local nX = 0 - local nY = 0 - local nR = math.floor(math.random() * 6400 / 100) - - nX = nR % 8 - nY = math.floor(nR / 8) - - nX = nX * 32 - nY = nY * 32 - pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,32,32)) - pBatchNode:addChild(pSprite, 0, nTag+100) - end - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_DEFAULT) - - return pSprite - end - - local function RemoveByTag(nTag) - if 1 == nSubtestNumber or 4 == nSubtestNumber or 7 == nSubtestNumber then - pNewScene:removeChildByTag(nTag + 100, true) - elseif 2 == nSubtestNumber or 3 == nSubtestNumber or 5 == nSubtestNumber or 6 == nSubtestNumber or 8 == nSubtestNumber or 9 == nSubtestNumber then - pBatchNode:removeChildAtIndex(nTag,true) - end - - end - - local function DoTest(pSprite) - if 0 == nCurCase then - PerformancePosition(pSprite) - elseif 1 == nCurCase then - PerformanceScale(pSprite) - elseif 2 == nCurCase then - PerformanceRotationScale(pSprite) - elseif 3 == nCurCase then - PerformanceOut100(pSprite) - elseif 4 == nCurCase then - Performanceout20(pSprite) - elseif 5 == nCurCase then - PerformanceActions(pSprite) - elseif 6 == nCurCase then - PerformanceActions20(pSprite) - end - end - - local function onDecrease() - if nQuantityNodes <= 0 then - return - end - - local i = 0 - for i = 0 , SpriteTestParam.kNodesIncrease - 1 do - nQuantityNodes = nQuantityNodes - 1 - RemoveByTag(nQuantityNodes) - end - UpdateNodes() - end - - local function onIncrease() - if nQuantityNodes >= SpriteTestParam.kMaxNodes then - return - end - - local i = 0 - for i = 0,SpriteTestParam.kNodesIncrease - 1 do - local pSprite = CreateSpriteWithTag(nQuantityNodes) - DoTest(pSprite) - nQuantityNodes = nQuantityNodes + 1 - end - UpdateNodes() - end - - local function TestNCallback(tag,pMenuItem) - local nIndex = pMenuItem:getLocalZOrder() - SpriteTestParam.kSubMenuBasicZOrder - nSubtestNumber = nIndex - ShowCurrentTest() - end - - local function InitWithSubTest(nSubTest) - pBatchNode = nil - --[[ - * Tests: - * 1: 1 (32-bit) PNG sprite of 52 x 139 - * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139 - - * 5: 14 (32-bit) PNG sprites of 85 x 121 each - * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each - * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each - * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each - - * 9: 64 (32-bit) sprites of 32 x 32 each - *10: 64 (32-bit) PNG Batch Node of 32 x 32 each - *11: 64 (16-bit) PNG Batch Node of 32 x 32 each - *12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each - ]]-- - --purge textures - local pMgr = cc.Director:getInstance():getTextureCache() - --[mgr removeAllTextures] - pMgr:removeTexture(pMgr:addImage("Images/grossinis_sister1.png")) - pMgr:removeTexture(pMgr:addImage("Images/grossini_dance_atlas.png")) - pMgr:removeTexture(pMgr:addImage("Images/spritesheet1.png")) - - if 1 == nSubTest or 4 == nSubTest or 7 == nSubTest then - elseif 2 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) - pNewScene:addChild(pBatchNode, 0) - elseif 3 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) - pNewScene:addChild(pBatchNode, 0) - elseif 5 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) - pNewScene:addChild(pBatchNode, 0) - elseif 6 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) - pNewScene:addChild(pBatchNode, 0) - elseif 8 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) - pNewScene:addChild(pBatchNode, 0) - elseif 9 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) - pNewScene:addChild(pBatchNode, 0) - end - - if nil ~= pBatchNode then - pBatchNode:retain() - end - - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_DEFAULT) - end - - local function InitWithSpriteTest(nSubtest,nNodes) - nSubtestNumber = nSubtest - --about create subset - InitWithSubTest(nSubtest) - local s = cc.Director:getInstance():getWinSize() - - nLastRenderedCount = 0 - nQuantityNodes = 0 - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewScene:addChild(pMenuAddOrSub,1) - - local pInfoLabel = cc.Label:createWithTTF("0 nodes", s_markerFeltFontPath, 30) - pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) - pNewScene:addChild(pInfoLabel, 1, SpriteTestParam.kTagInfoLayer) - - --SpriteTestMenuLayer - local pSpriteMenuLayer = cc.Layer:create() - local pSpriteMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pSpriteMenu) - CreateBasicLayerMenuItem(pSpriteMenu,true,SpriteTestParam.TEST_COUNT,nCurCase) - pSpriteMenu:setPosition(cc.p(0, 0)) - pSpriteMenuLayer:addChild(pSpriteMenu) - pNewScene:addChild(pSpriteMenuLayer,1,SpriteTestParam.kTagMenuLayer) - - - --Sub Tests - cc.MenuItemFont:setFontSize(40) - local pSubMenu = cc.Menu:create() - local i = 1 - for i = 1, 9 do - local strNum = string.format("%d ",i) - local pItemFont = cc.MenuItemFont:create(strNum) - pItemFont:registerScriptTapHandler(TestNCallback) - pSubMenu:addChild(pItemFont, i + SpriteTestParam.kSubMenuBasicZOrder) - if i <= 3 then - pItemFont:setColor(cc.c3b(200,20,20)) - elseif i <= 6 then - pItemFont:setColor(cc.c3b(0,200,20)) - else - pItemFont:setColor(cc.c3b(0,20,200)) - end - end - - - pSubMenu:alignItemsHorizontally() - pSubMenu:setPosition(cc.p(s.width/2, 80)) - pNewScene:addChild(pSubMenu, 2) - - local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40) - pNewScene:addChild(pLabel, 1) - pLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - while nQuantityNodes < nNodes do - onIncrease() - end - end - - function ShowCurrentTest() - pNewScene = cc.Scene:create() - InitWithSpriteTest(nSubtestNumber,nQuantityNodes) - cc.Director:getInstance():replaceScene(pNewScene) - end - - InitWithSpriteTest(1,SpriteTestParam.kInitNodes) - - return pNewScene -end - ----------------------------------- ---PerformanceTextureTest ----------------------------------- -local TextureTestParam = -{ - TEST_COUNT = 1, -} - -local function runTextureTest() - - local function GetTitle() - return "Texture Performance Test" - end - - local function GetSubtitle() - return "See console for results" - end - - local nTexCurCase = 0 - local pNewscene = cc.Scene:create() - local pLayer = cc.Layer:create() - local s = cc.Director:getInstance():getWinSize() - - local function PerformTestsPNG(strFileName) - local time - local pTexture = nil - local pCache = cc.Director:getInstance():getTextureCache() - - local pDefaultFormat = cc.Texture2D:getDefaultAlphaPixelFormat(); - - print("RGBA 8888") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - --os.time()--get secs,not micr sec - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) - - print("RGBA 4444") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - --gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) - - print("RGBA 5551") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1) - --gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) - - print("RGB 565") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565) - -- gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - --log(" ms:%f", calculateDeltaTime(&now) ) - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) - - cc.Texture2D:setDefaultAlphaPixelFormat(pDefaultFormat) - end - local function PerformTests() - print("--------") - print("--- PNG 128x128 ---") - PerformTestsPNG("Images/test_image.png") - - print("--- PNG 512x512 ---") - PerformTestsPNG("Images/texture512x512.png") - - print("EMPTY IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/texture1024x1024.png") - - print("SPRITESHEET IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/PlanetCute-1024x1024.png") - - print("LANDSCAPE IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/landscape-1024x1024.png") - end - - local function InitTextureMenuLayer() - if nil == pLayer then - return - end - - --Title - local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40) - pLayer:addChild(pLabel, 1) - pLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - --Subtitle - local pSubLabel = cc.Label:createWithTTF(GetSubtitle(), s_thonburiPath, 16) - pLayer:addChild(pSubLabel, 1) - pSubLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pSubLabel:setPosition(cc.p(s.width/2, s.height-80)) - - --menu - local pMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pMenu) - pMenu:setPosition(cc.p(0, 0)) - pLayer:addChild(pMenu) - - PerformTests() - end - - InitTextureMenuLayer() - pNewscene:addChild(pLayer) - return pNewscene -end ----------------------------------- ---PerformanceTouchesTest ----------------------------------- -local TouchesTestParam = -{ - TEST_COUNT = 2, -} -local function runTouchesTest() - local nTouchCurCase = 0 - --PerformBasicLayer param - local bControlMenuVisible = false - local nMaxCases = 0 - local nCurCase = 0 - --TouchesMainScene param - local pClassLabel = nil - local nNumberOfTouchesB = 0 - local nNumberOfTouchesM = 0 - local nNumberOfTouchesE = 0 - local nNumberOfTouchesC = 0 - local fElapsedTime = 0.0 - - local s = cc.Director:getInstance():getWinSize() - local pNewscene = cc.Scene:create() - local pLayer = cc.Layer:create() - - local function GetTitle() - if 0 == nCurCase then - return "Targeted touches" - elseif 1 == nCurCase then - return "Standard touches" - end - end - - local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end - - local function restartCallback() - ShowCurrentTest() - end - - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end - end - - local function update(fTime) - fElapsedTime = fElapsedTime + fTime - - if fElapsedTime > 1.0 then - local fFrameRateB = nNumberOfTouchesB / fElapsedTime - local fFrameRateM = nNumberOfTouchesM / fElapsedTime - local fFrameRateE = nNumberOfTouchesE / fElapsedTime - local fFrameRateC = nNumberOfTouchesC / fElapsedTime - fElapsedTime = 0 - nNumberOfTouchesB = 0 - nNumberOfTouchesM = 0 - nNumberOfTouchesE = 0 - nNumberOfTouchesC = 0 - - local strInfo = string.format("%.1f %.1f %.1f %.1f",fFrameRateB, fFrameRateM, fFrameRateE, fFrameRateC) - if nil ~= pClassLabel then - pClassLabel:setString(strInfo) - end - end - - end - - -- handling touch events - local function onTouchEnded(touch, event) - nNumberOfTouchesE = nNumberOfTouchesE + 1 - end - - local function onTouchBegan(touch, event) - nNumberOfTouchesB = nNumberOfTouchesB + 1 - end - - local function onTouchMoved(touch, event) - nNumberOfTouchesM = nNumberOfTouchesM + 1 - end - - local function onTouchCancelled(touch, event) - nNumberOfTouchesC = nNumberOfTouchesC + 1 - end - - - local function onTouchesEnded(touches, event) - nNumberOfTouchesE = nNumberOfTouchesE + table.getn(touches) - end - - local function onTouchesBegan(touches, event) - nNumberOfTouchesB = nNumberOfTouchesB + table.getn(touches) - end - - local function onTouchesMoved(touches, event) - nNumberOfTouchesM = nNumberOfTouchesM + table.getn(touches) - end - - local function onTouchesCancelled(touches, event) - nNumberOfTouchesC= nNumberOfTouchesC + table.getn(touches) - end - - local function InitLayer() - --menu - local pTouchesTestMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pTouchesTestMenu) - CreateBasicLayerMenuItem(pTouchesTestMenu,true,TouchesTestParam.TEST_COUNT,nCurCase) - pTouchesTestMenu:setPosition(cc.p(0, 0)) - pLayer:addChild(pTouchesTestMenu) - - --Title - local pLabel = cc.Label:createWithTTF(GetTitle(), s_arialPath, 40) - pLayer:addChild(pLabel, 1) - pLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - pLayer:scheduleUpdateWithPriorityLua(update,0) - - pClassLabel = cc.Label:createWithBMFont("fonts/arial16.fnt", "00.0") - pClassLabel:setAnchorPoint(cc.p(0.5, 0.5)) - pClassLabel:setPosition(cc.p(s.width/2, s.height/2)) - pLayer:addChild(pClassLabel) - - fElapsedTime = 0.0 - nNumberOfTouchesB = 0 - nNumberOfTouchesM = 0 - nNumberOfTouchesE = 0 - nNumberOfTouchesC = 0 - - if 0 == nCurCase then - local listener = cc.EventListenerTouchOneByOne:create() - listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) - listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) - listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) - listener:registerScriptHandler(onTouchCancelled,cc.Handler.EVENT_TOUCH_CANCELLED ) - local eventDispatcher = pLayer:getEventDispatcher() - eventDispatcher:addEventListenerWithSceneGraphPriority(listener, pLayer) - elseif 1 == nCurCase then - local listener = cc.EventListenerTouchAllAtOnce:create() - listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN ) - listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED ) - listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED ) - listener:registerScriptHandler(onTouchesCancelled,cc.Handler.EVENT_TOUCHES_CANCELLED ) - local eventDispatcher = pLayer:getEventDispatcher() - eventDispatcher:addEventListenerWithSceneGraphPriority(listener, pLayer) - end - end - - function ShowCurrentTest() - if nil ~= pLayer then - pLayer:unscheduleUpdate() - end - - pNewscene = cc.Scene:create() - - if nil ~= pNewscene then - pLayer = cc.Layer:create() - InitLayer() - pNewscene:addChild(pLayer) - cc.Director:getInstance():replaceScene(pNewscene) - end - end - - InitLayer() - pNewscene:addChild(pLayer) - return pNewscene -end - -local function runFuncRelateWithTable() - -- body - local newscene = cc.Scene:create() - local layer = cc.Layer:create() - local s = cc.Director:getInstance():getWinSize() - local scheduler = cc.Director:getInstance():getScheduler() - local scheduleEntryID = 0 - local quantityOfNodes = 10000 - local socket = require("socket") - local maxTime = 0.0 - local minTime = 99999 - local averageTime1 = 0.0 - local averageTime2 = 0.0 - local totalTime = 0.0 - local numberOfCalls = 0 - - local function GetTitle() - return "Func Releated Table Performance Test" - end - - local function GetSubtitle() - return "See console for results" - end - - local function initVar() - maxTime = 0.0 - minTime = 99999 - averageTime1 = 0.0 - averageTime2 = 0.0 - totalTime = 0.0 - numberOfCalls = 0 - end - - --Title - local title = cc.Label:createWithTTF(GetTitle(), s_arialPath, 28) - layer:addChild(title, 1) - title:setAnchorPoint(cc.p(0.5, 0.5)) - title:setPosition(cc.p(s.width/2, s.height-32)) - title:setColor(cc.c3b(255,255,40)) - --Subtitle - local subTitle = cc.Label:createWithTTF(GetSubtitle(), s_thonburiPath, 16) - layer:addChild(subTitle, 1) - subTitle:setAnchorPoint(cc.p(0.5, 0.5)) - subTitle:setPosition(cc.p(s.width/2, s.height-80)) - - --"+","-" Menu - local function onDecrease() - quantityOfNodes = quantityOfNodes - 100 - if quantityOfNodes == 0 then - quantityOfNodes = 100 - end - local numLabel = layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local strNum = string.format("%d", quantityOfNodes) - numLabel:setString(strNum) - end - - local function onIncrease() - quantityOfNodes = quantityOfNodes + 100 - local numLabel = layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local strNum = string.format("%d", quantityOfNodes) - numLabel:setString(strNum) - end - - cc.MenuItemFont:setFontSize(65) - local decrease = cc.MenuItemFont:create(" - ") - decrease:registerScriptTapHandler(onDecrease) - decrease:setColor(cc.c3b(0,200,20)) - local increase = cc.MenuItemFont:create(" + ") - increase:registerScriptTapHandler(onIncrease) - increase:setColor(cc.c3b(0,200,20)) - - local menuAddOrSub = cc.Menu:create() - menuAddOrSub:addChild(decrease) - menuAddOrSub:addChild(increase) - menuAddOrSub:alignItemsHorizontally() - menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - layer:addChild(menuAddOrSub,1) - - --num - local numLabel = cc.Label:createWithTTF("10000", s_markerFeltFontPath, 30) - numLabel:setColor(cc.c3b(0,200,20)) - numLabel:setAnchorPoint(cc.p(0.5, 0.5)) - numLabel:setPosition(cc.p(s.width/2, s.height/2-15)) - layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer) - - --setPosition,getPosition,Point - cc.MenuItemFont:setFontSize(18) - local setPositionItem = cc.MenuItemFont:create("setPosition") - local getPositionItem = cc.MenuItemFont:create("getPosition") - local getAnchorPointItem = cc.MenuItemFont:create("getAnchorPoint") - local pointItem = cc.MenuItemFont:create("object") - local funcToggleItem = cc.MenuItemToggle:create(setPositionItem) - funcToggleItem:addSubItem(getPositionItem) - funcToggleItem:addSubItem(getAnchorPointItem) - funcToggleItem:addSubItem(pointItem) - funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5)) - funcToggleItem:setPosition(cc.p(VisibleRect:left())) - local funcMenu = cc.Menu:create(funcToggleItem) - funcMenu:setPosition(cc.p(0, 0)) - layer:addChild(funcMenu) - - local testNode = cc.Node:create() - layer:addChild(testNode) - - local function step(dt) - print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",quantityOfNodes, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) - end - - local function profileEnd(startTime) - local duration = socket.gettime() - startTime - totalTime = totalTime + duration - averageTime1 = (averageTime1 + duration) / 2 - averageTime2 = totalTime / numberOfCalls - - if maxTime < duration then - maxTime = duration - end - - if minTime > duration then - minTime = duration - end - end - - local function callSetPosition() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,quantityOfNodes do - testNode:setPosition(cc.p(1,2)) - end - profileEnd(startTime) - end - - local function callGetPosition() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,quantityOfNodes do - local x,y = testNode:getPosition() - end - profileEnd(startTime) - end - - local function callGetAnchorPoint() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,quantityOfNodes do - local anchorPoint = testNode:getAnchorPoint() - end - profileEnd(startTime) - end - - local function callTableObject() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,quantityOfNodes do - local pt = cc.p(1,2) - end - profileEnd(startTime) - end - - local function update(dt) - - local funcSelected = funcToggleItem:getSelectedIndex() - if 0 == funcSelected then - callSetPosition() - elseif 1 == funcSelected then - callGetPosition() - elseif 2 == funcSelected then - callGetAnchorPoint() - elseif 3 == funcSelected then - callTableObject() - end - end - - local function onNodeEvent(tag) - if tag == "exit" then - layer:unscheduleUpdate() - scheduler:unscheduleScriptEntry(scheduleEntryID) - end - end - - layer:registerScriptHandler(onNodeEvent) - - - local function startCallback() - initVar() - decrease:setEnabled(false) - increase:setEnabled(false) - funcToggleItem:setEnabled(false) - layer:unscheduleUpdate() - layer:scheduleUpdateWithPriorityLua(update, 0) - scheduler:unscheduleScriptEntry(scheduleEntryID) - scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false) - end - - local function stopCallback() - decrease:setEnabled(true) - increase:setEnabled(true) - funcToggleItem:setEnabled(true) - layer:unscheduleUpdate() - scheduler:unscheduleScriptEntry(scheduleEntryID) - end - local startItem = cc.MenuItemFont:create("start") - startItem:registerScriptTapHandler(startCallback) - local stopItem = cc.MenuItemFont:create("stop") - stopItem:registerScriptTapHandler(stopCallback) - local startAndStop = cc.Menu:create(startItem,stopItem) - startAndStop:alignItemsVertically() - startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y) - layer:addChild(startAndStop) - - --back menu - local menu = cc.Menu:create() - CreatePerfomBasicLayerMenu(menu) - menu:setPosition(cc.p(0, 0)) - layer:addChild(menu) - - newscene:addChild(layer) - return newscene -end - - ------------------------- --- ------------------------- -local CreatePerformancesTestTable = -{ - runNodeChildrenTest, - runParticleTest, - runSpriteTest, - runTextureTest, - runTouchesTest, - runFuncRelateWithTable, -} - -local function CreatePerformancesTestScene(nPerformanceNo) - local pNewscene = CreatePerformancesTestTable[nPerformanceNo]() - return pNewscene -end -local function menuCallback(tag, pMenuItem) - local scene = nil - local nIdx = pMenuItem:getLocalZOrder() - kItemTagBasic - local PerformanceTestScene = CreatePerformancesTestScene(nIdx) - if nil ~= PerformanceTestScene then - cc.Director:getInstance():replaceScene(PerformanceTestScene) - end -end - -local function PerformanceMainLayer() - local layer = cc.Layer:create() - - local menu = cc.Menu:create() - menu:setPosition(cc.p(0, 0)) - cc.MenuItemFont:setFontName("Arial") - cc.MenuItemFont:setFontSize(24) - for i = 1, MAX_COUNT do - local item = cc.MenuItemFont:create(testsName[i]) - item:registerScriptTapHandler(menuCallback) - item:setPosition(s.width / 2, s.height - i * LINE_SPACE) - menu:addChild(item, kItemTagBasic + i) - if i == MAX_COUNT then - local targetPlatform = cc.Application:getInstance():getTargetPlatform() - if (cc.PLATFORM_OS_IPHONE ~= targetPlatform) and (cc.PLATFORM_OS_IPAD ~= targetPlatform) and - (cc.PLATFORM_OS_ANDROID ~= targetPlatform) and (cc.PLATFORM_OS_WINDOWS ~= targetPlatform) and - (cc.PLATFORM_OS_MAC ~= targetPlatform) then - item:setEnabled(false) - end - end - end - - layer:addChild(menu) - - return layer -end - -------------------------------------- --- Performance Test -------------------------------------- -function PerformanceTestMain() - local scene = cc.Scene:create() - - scene:addChild(PerformanceMainLayer()) - scene:addChild(CreateBackMenuItem()) - - return scene -end diff --git a/tests/lua-tests/src/mainMenu.lua b/tests/lua-tests/src/mainMenu.lua index 20e116e246..1af3f93081 100644 --- a/tests/lua-tests/src/mainMenu.lua +++ b/tests/lua-tests/src/mainMenu.lua @@ -36,7 +36,6 @@ require "OpenGLTest/OpenGLTest" require "ParallaxTest/ParallaxTest" require "ParticleTest/ParticleTest" require "Particle3DTest/Particle3DTest" -require "PerformanceTest/PerformanceTest" require "RenderTextureTest/RenderTextureTest" require "RotateWorldTest/RotateWorldTest" require "Sprite3DTest/Sprite3DTest" @@ -124,7 +123,6 @@ local _allTests = { { isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain }, { isSupported = true, name = "ParticleTest" , create_func = ParticleTest }, { isSupported = true, name = "Particle3D (PU)" , create_func = Particle3DTest }, - { isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain }, { isSupported = true, name = "PhysicsTest" , create_func = PhysicsTest }, { isSupported = true, name = "Physics3DTest" , create_func = Physics3DTest }, { isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain }, From edb964a6731a9b74cbc0bb0ec01833dff9bb6279 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 11 Sep 2015 16:03:07 +0800 Subject: [PATCH 2/2] Remove the performance related config in project.json. --- tests/js-tests/project.json | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/js-tests/project.json b/tests/js-tests/project.json index 17b933b141..c42e93adf5 100644 --- a/tests/js-tests/project.json +++ b/tests/js-tests/project.json @@ -56,17 +56,7 @@ "src/ActionManagerTest/ActionManagerTest.js", "src/EaseActionsTest/EaseActionsTest.js", "src/ParallaxTest/ParallaxTest.js", - "src/PerformanceTest/PerformanceTest.js", - "src/PerformanceTest/PerformanceSpriteTest.js", - "src/PerformanceTest/PerformanceSpriteTest2.js", - "src/PerformanceTest/PerformanceParticleTest.js", - "src/PerformanceTest/PerformanceNodeChildrenTest.js", - "src/PerformanceTest/PerformanceTextureTest.js", - "src/PerformanceTest/PerformanceAnimationTest.js", - "src/PerformanceTest/PerformanceVirtualMachineTest.js", - "src/PerformanceTest/seedrandom.js", "src/FontTest/FontTest.js", - "src/PerformanceTest/PerformanceTouchesTest.js", "src/LabelTest/LabelTest.js", "src/CurrentLanguageTest/CurrentLanguageTest.js", "src/TextInputTest/TextInputTest.js",