mirror of https://github.com/axmolengine/axmol.git
Merge pull request #13776 from natural-law/v3
Remove performance tests from lua-tests & js-tests.
This commit is contained in:
commit
04d3119871
tests
|
@ -56,17 +56,7 @@
|
||||||
"src/ActionManagerTest/ActionManagerTest.js",
|
"src/ActionManagerTest/ActionManagerTest.js",
|
||||||
"src/EaseActionsTest/EaseActionsTest.js",
|
"src/EaseActionsTest/EaseActionsTest.js",
|
||||||
"src/ParallaxTest/ParallaxTest.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/FontTest/FontTest.js",
|
||||||
"src/PerformanceTest/PerformanceTouchesTest.js",
|
|
||||||
"src/LabelTest/LabelTest.js",
|
"src/LabelTest/LabelTest.js",
|
||||||
"src/CurrentLanguageTest/CurrentLanguageTest.js",
|
"src/CurrentLanguageTest/CurrentLanguageTest.js",
|
||||||
"src/TextInputTest/TextInputTest.js",
|
"src/TextInputTest/TextInputTest.js",
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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<num; i++) {
|
|
||||||
var sprite = new cc.Sprite('Images/grossini.png');
|
|
||||||
parent.addChild( sprite );
|
|
||||||
|
|
||||||
var x = Math.random() * winSize.width;
|
|
||||||
var y = Math.random() * winSize.height;
|
|
||||||
sprite.x = x;
|
|
||||||
sprite.y = y;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
endA:function() {
|
|
||||||
this.removeChildByTag( 10, true );
|
|
||||||
},
|
|
||||||
|
|
||||||
testB:function(num) {
|
|
||||||
// Draws all sprites on the screen
|
|
||||||
// Batched drawing
|
|
||||||
|
|
||||||
this.profiling = new Profiling("Test B - Total Sprites: " + num);
|
|
||||||
|
|
||||||
// use the same seed for the tests
|
|
||||||
Math.seedrandom('perftest');
|
|
||||||
var parent = new cc.SpriteBatchNode('Images/grossini.png',num);
|
|
||||||
this.addChild(parent,0,10);
|
|
||||||
for( var i=0; i<num; i++) {
|
|
||||||
var sprite = new cc.Sprite('Images/grossini.png');
|
|
||||||
parent.addChild( sprite );
|
|
||||||
|
|
||||||
var x = Math.random() * winSize.width;
|
|
||||||
var y = Math.random() * winSize.height;
|
|
||||||
sprite.x = x;
|
|
||||||
sprite.y = y;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
endB:function() {
|
|
||||||
this.removeChildByTag( 10, true );
|
|
||||||
},
|
|
||||||
|
|
||||||
update:function(dt) {
|
|
||||||
if( ! this.firstTick ) {
|
|
||||||
var ms = director.getSecondsPerFrame();
|
|
||||||
this.profiling.beginEndBlock(ms*1000);
|
|
||||||
} else
|
|
||||||
this.firstTick = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
endProfiling:function(dt) {
|
|
||||||
this.profiling.dump();
|
|
||||||
this.firstTick = true;
|
|
||||||
if( ! this.runNextTest() )
|
|
||||||
this.unschedule( this.endProfiling );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Scenes
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
var arrayOfPerformanceSpriteTest = [
|
|
||||||
|
|
||||||
PerformanceSpriteTest1
|
|
||||||
|
|
||||||
];
|
|
||||||
var PerformanceSpriteTestScene = TestScene.extend({
|
|
||||||
runThisTest:function (num) {
|
|
||||||
performanceSpriteTestSceneIdx = (num || num == 0) ? (num - 1) : -1;
|
|
||||||
var layer = nextPerformanceSpriteTest();
|
|
||||||
this.addChild(layer);
|
|
||||||
|
|
||||||
director.runScene(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var nextPerformanceSpriteTest = function () {
|
|
||||||
performanceSpriteTestSceneIdx++;
|
|
||||||
performanceSpriteTestSceneIdx = performanceSpriteTestSceneIdx % arrayOfPerformanceSpriteTest.length;
|
|
||||||
|
|
||||||
return new arrayOfPerformanceSpriteTest[performanceSpriteTestSceneIdx]();
|
|
||||||
};
|
|
||||||
var previousPerformanceSpriteTest = function () {
|
|
||||||
performanceSpriteTestSceneIdx--;
|
|
||||||
if (performanceSpriteTestSceneIdx < 0)
|
|
||||||
performanceSpriteTestSceneIdx += arrayOfPerformanceSpriteTest.length;
|
|
||||||
|
|
||||||
return new arrayOfPerformanceSpriteTest[performanceSpriteTestSceneIdx]();
|
|
||||||
};
|
|
||||||
var restartPerformanceSpriteTest = function () {
|
|
||||||
return new arrayOfPerformanceSpriteTest[performanceSpriteTestSceneIdx]();
|
|
||||||
};
|
|
||||||
|
|
||||||
function runPerformanceSpriteTest2() {
|
|
||||||
var scene = new PerformanceSpriteTestScene();
|
|
||||||
scene.runThisTest();
|
|
||||||
}
|
|
|
@ -1,199 +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 ITEM_TAG_BASIC = 1000;
|
|
||||||
var nCurCase = 0;
|
|
||||||
|
|
||||||
var PerformanceTests = [
|
|
||||||
"PerformanceNodeChildrenTest",
|
|
||||||
"PerformanceParticleTest",
|
|
||||||
"PerformanceSpriteTest",
|
|
||||||
"PerformanceTextureTest",
|
|
||||||
"PerformanceTouchesTest",
|
|
||||||
"PerformanceAnimationTest",
|
|
||||||
"Automated Sprite Performarnce Test"
|
|
||||||
];
|
|
||||||
|
|
||||||
// PerformanceVirtualMachineTest is about JS optimizations on cocos2d-html5.
|
|
||||||
// It is pretty irrelevant in JSB so we don't include it in JSB.
|
|
||||||
// "PerformanceVirtualMachineTest" is inserted before
|
|
||||||
// "Automated Sprite Performarnce Test".
|
|
||||||
if (!cc.sys.isNative)
|
|
||||||
PerformanceTests.splice(6, 0, "PerformanceVirtualMachineTest");
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PerformanceMainLayer
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
var PerformanceMainLayer = cc.LayerGradient.extend({
|
|
||||||
ctor:function() {
|
|
||||||
this._super(cc.color(0,0,0,255), cc.color(98,99,117,255));
|
|
||||||
},
|
|
||||||
|
|
||||||
onEnter:function () {
|
|
||||||
this._super();
|
|
||||||
|
|
||||||
var s = cc.director.getWinSize();
|
|
||||||
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
menu.x = 0;
|
|
||||||
menu.y = 0;
|
|
||||||
cc.MenuItemFont.setFontName("Arial");
|
|
||||||
cc.MenuItemFont.setFontSize(24);
|
|
||||||
|
|
||||||
for (var i = 0; i < PerformanceTests.length; i++) {
|
|
||||||
var pItem = new cc.MenuItemFont(PerformanceTests[i], this.menuCallback, this);
|
|
||||||
pItem.x = s.width / 2;
|
|
||||||
pItem.y = s.height - (i + 1) * LINE_SPACE;
|
|
||||||
menu.addChild(pItem, ITEM_TAG_BASIC + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addChild(menu);
|
|
||||||
},
|
|
||||||
menuCallback:function (sender) {
|
|
||||||
var index = sender.zIndex - ITEM_TAG_BASIC;
|
|
||||||
// create the test scene and run it
|
|
||||||
switch (index) {
|
|
||||||
case 0:
|
|
||||||
runNodeChildrenTest();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
runParticleTest();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
runSpriteTest();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
runTextureTest();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
runTouchesTest();
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
runAnimationTest();
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
if (!cc.sys.isNative) {
|
|
||||||
runVirtualMachineTest();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Else, fall through (JSB).
|
|
||||||
// TODO: For now I think it's ugly to have "Automated Sprite
|
|
||||||
// Perforance Test" come before "PerformanceVirtualMachineTest",
|
|
||||||
// that's why there's ugly code like this. Let's think about
|
|
||||||
// this later.
|
|
||||||
case 7:
|
|
||||||
runPerformanceSpriteTest2();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PerformBasicLayer
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
var PerformBasicLayer = cc.Layer.extend({
|
|
||||||
_controlMenuVisible:true,
|
|
||||||
_maxCases:1,
|
|
||||||
_curCase:0,
|
|
||||||
ctor:function () {
|
|
||||||
this._super();
|
|
||||||
this.init();
|
|
||||||
this._curCase = nCurCase;
|
|
||||||
},
|
|
||||||
onEnter:function () {
|
|
||||||
this._super();
|
|
||||||
|
|
||||||
var s = cc.director.getWinSize();
|
|
||||||
|
|
||||||
cc.MenuItemFont.setFontName("Arial");
|
|
||||||
cc.MenuItemFont.setFontSize(24);
|
|
||||||
var mainItem = new cc.MenuItemFont("Back", this.toMainLayer, this);
|
|
||||||
mainItem.x = s.width - 50;
|
|
||||||
mainItem.y = 25;
|
|
||||||
var menu = new cc.Menu(mainItem);
|
|
||||||
menu.x = 0;
|
|
||||||
menu.y = 0;
|
|
||||||
|
|
||||||
if (this._controlMenuVisible) {
|
|
||||||
var item1 = new cc.MenuItemImage(s_pathB1, s_pathB2, this.backCallback, this);
|
|
||||||
var item2 = new cc.MenuItemImage(s_pathR1, s_pathR2, this.restartCallback, this);
|
|
||||||
var item3 = new cc.MenuItemImage(s_pathF1, s_pathF2, this.nextCallback, this);
|
|
||||||
item1.x = s.width / 2 - 100;
|
|
||||||
item1.y = 30;
|
|
||||||
item2.x = s.width / 2;
|
|
||||||
item2.y = 30;
|
|
||||||
item3.x = s.width / 2 + 100;
|
|
||||||
item3.y = 30;
|
|
||||||
|
|
||||||
menu.addChild(item1, ITEM_TAG_BASIC);
|
|
||||||
menu.addChild(item2, ITEM_TAG_BASIC);
|
|
||||||
menu.addChild(item3, ITEM_TAG_BASIC);
|
|
||||||
}
|
|
||||||
this.addChild(menu);
|
|
||||||
},
|
|
||||||
restartCallback:function (sender) {
|
|
||||||
this.showCurrentTest();
|
|
||||||
},
|
|
||||||
nextCallback:function (sender) {
|
|
||||||
this._curCase++;
|
|
||||||
this._curCase = this._curCase % this._maxCases;
|
|
||||||
nCurCase = this._curCase;
|
|
||||||
this.showCurrentTest();
|
|
||||||
},
|
|
||||||
backCallback:function (sender) {
|
|
||||||
this._curCase--;
|
|
||||||
if (this._curCase < 0) {
|
|
||||||
this._curCase += this._maxCases;
|
|
||||||
}
|
|
||||||
nCurCase = this._curCase;
|
|
||||||
this.showCurrentTest();
|
|
||||||
},
|
|
||||||
showCurrentTest:function (sender) {
|
|
||||||
},
|
|
||||||
toMainLayer:function (sender) {
|
|
||||||
var scene = new PerformanceTestScene();
|
|
||||||
scene.runThisTest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PerformanceTestScene
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
var PerformanceTestScene = TestScene.extend({
|
|
||||||
runThisTest:function () {
|
|
||||||
var layer = new PerformanceMainLayer();
|
|
||||||
this.addChild(layer);
|
|
||||||
cc.director.runScene(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,184 +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_nTexCurCase = 0;
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// TextureMenuLayer
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
var TextureMenuLayer = PerformBasicLayer.extend({
|
|
||||||
showCurrentTest:function () {
|
|
||||||
var scene = null;
|
|
||||||
switch (this._curCase) {
|
|
||||||
case 0:
|
|
||||||
scene = TextureTest.scene();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s_nTexCurCase = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.performTests();
|
|
||||||
},
|
|
||||||
title:function () {
|
|
||||||
return "no title";
|
|
||||||
},
|
|
||||||
subtitle:function () {
|
|
||||||
return "no subtitle";
|
|
||||||
},
|
|
||||||
performTests:function () {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// TextureTest
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
var TextureTest = TextureMenuLayer.extend({
|
|
||||||
performTests:function () {
|
|
||||||
cc.log("--------");
|
|
||||||
cc.log("--- PNG 128x128 ---");
|
|
||||||
this.performTestsPNG("Images/test_image.png");
|
|
||||||
|
|
||||||
cc.log("--- PNG 512x512 ---");
|
|
||||||
this.performTestsPNG("Images/texture512x512.png");
|
|
||||||
|
|
||||||
cc.log("EMPTY IMAGE");
|
|
||||||
cc.log("--- PNG 1024x1024 ---");
|
|
||||||
this.performTestsPNG("Images/texture1024x1024.png");
|
|
||||||
|
|
||||||
cc.log("LANDSCAPE IMAGE");
|
|
||||||
cc.log("--- PNG 1024x1024 ---");
|
|
||||||
this.performTestsPNG("Images/landscape-1024x1024.png");
|
|
||||||
},
|
|
||||||
title:function () {
|
|
||||||
return "Texture Performance Test";
|
|
||||||
},
|
|
||||||
subtitle:function () {
|
|
||||||
return "See console for results";
|
|
||||||
},
|
|
||||||
performTestsPNG:function (filename) {
|
|
||||||
var now = Date.now();
|
|
||||||
var texture;
|
|
||||||
var cache = cc.textureCache;
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
var defaultFormat = cc.Texture2D.defaultPixelFormat;
|
|
||||||
cc.log("RGBA 8888");
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888;
|
|
||||||
|
|
||||||
var now = Date.now();
|
|
||||||
texture = cache.addImage(filename);
|
|
||||||
if (texture)
|
|
||||||
cc.log(" seconds:" + calculateDeltaTime(now));
|
|
||||||
else
|
|
||||||
cc.log(" ERROR");
|
|
||||||
cache.removeTexture(texture);
|
|
||||||
|
|
||||||
cc.log("RGBA 4444");
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA4444;
|
|
||||||
|
|
||||||
var now = Date.now();
|
|
||||||
texture = cache.addImage(filename);
|
|
||||||
if (texture)
|
|
||||||
cc.log(" seconds:" + calculateDeltaTime(now));
|
|
||||||
else
|
|
||||||
cc.log(" ERROR");
|
|
||||||
cache.removeTexture(texture);
|
|
||||||
|
|
||||||
cc.log("RGBA 5551");
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGB5A1;
|
|
||||||
|
|
||||||
var now = Date.now();
|
|
||||||
texture = cache.addImage(filename);
|
|
||||||
if (texture)
|
|
||||||
cc.log(" seconds:" + calculateDeltaTime(now));
|
|
||||||
else
|
|
||||||
cc.log(" ERROR");
|
|
||||||
cache.removeTexture(texture);
|
|
||||||
|
|
||||||
cc.log("RGB 565");
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
cc.Texture2D.defaultPixelFormat = cc.Texture2D.PIXEL_FORMAT_RGB565;
|
|
||||||
|
|
||||||
var now = Date.now();
|
|
||||||
texture = cache.addImage(filename);
|
|
||||||
if (texture)
|
|
||||||
cc.log(" seconds:" + calculateDeltaTime(now));
|
|
||||||
else
|
|
||||||
cc.log(" ERROR");
|
|
||||||
cache.removeTexture(texture);
|
|
||||||
if ("opengl" in cc.sys.capabilities)
|
|
||||||
cc.Texture2D.defaultPixelFormat = defaultFormat;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
TextureTest.scene = function () {
|
|
||||||
var scene = new cc.Scene();
|
|
||||||
var layer = new TextureTest(false, 1, s_nTexCurCase);
|
|
||||||
scene.addChild(layer);
|
|
||||||
return scene;
|
|
||||||
};
|
|
||||||
function runTextureTest() {
|
|
||||||
s_nTexCurCase = 0;
|
|
||||||
var scene = TextureTest.scene();
|
|
||||||
cc.director.runScene(scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateDeltaTime(lastUpdate) {
|
|
||||||
var now = Date.now();
|
|
||||||
var dt = (now - lastUpdate) / 1000;
|
|
||||||
return dt;
|
|
||||||
}
|
|
|
@ -1,165 +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_nTouchCurCase = 0;
|
|
||||||
|
|
||||||
var TouchesMainScene = PerformBasicLayer.extend({
|
|
||||||
_maxCases:2,
|
|
||||||
_plabel:null,
|
|
||||||
_numberOfTouchesB:0,
|
|
||||||
_numberOfTouchesM:0,
|
|
||||||
_numberOfTouchesE:0,
|
|
||||||
_numberOfTouchesC:0,
|
|
||||||
_elapsedTime:null,
|
|
||||||
showCurrentTest:function () {
|
|
||||||
var layer = null;
|
|
||||||
switch (this._curCase) {
|
|
||||||
case 0:
|
|
||||||
layer = new TouchesPerformTest1(true, 2, this._curCase);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
layer = new TouchesPerformTest2(true, 2, this._curCase);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s_nTouchCurCase = this._curCase;
|
|
||||||
|
|
||||||
if (layer) {
|
|
||||||
var scene = new cc.Scene();
|
|
||||||
scene.addChild(layer);
|
|
||||||
|
|
||||||
cc.director.runScene(scene);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onEnter:function () {
|
|
||||||
this._super();
|
|
||||||
|
|
||||||
var s = cc.director.getWinSize();
|
|
||||||
|
|
||||||
// add title
|
|
||||||
var label = new cc.LabelTTF(this.title(), "Arial", 32);
|
|
||||||
this.addChild(label, 1);
|
|
||||||
label.x = s.width / 2;
|
|
||||||
label.y = s.height - 50;
|
|
||||||
|
|
||||||
this.scheduleUpdate();
|
|
||||||
|
|
||||||
this._plabel = new cc.LabelTTF("00.0", "Arial", 16);
|
|
||||||
this._plabel.x = s.width / 2;
|
|
||||||
this._plabel.y = s.height / 2;
|
|
||||||
this.addChild(this._plabel);
|
|
||||||
|
|
||||||
this._elapsedTime = 0;
|
|
||||||
this._numberOfTouchesB = this._numberOfTouchesM = this._numberOfTouchesE = this._numberOfTouchesC = 0;
|
|
||||||
},
|
|
||||||
title:function () {
|
|
||||||
return "No title";
|
|
||||||
},
|
|
||||||
update:function (dt) {
|
|
||||||
this._elapsedTime += dt;
|
|
||||||
|
|
||||||
if (this._elapsedTime > 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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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:
|
|
||||||
//
|
|
||||||
// <script src=http://davidbau.com/encode/seedrandom-min.js></script>
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
// <script src="http://bit.ly/srandom-512"></script>
|
|
||||||
// Seeds using physical random bits downloaded
|
|
||||||
// from random.org.
|
|
||||||
//
|
|
||||||
// <script src="https://jsonlib.appspot.com/urandom?callback=Math.seedrandom">
|
|
||||||
// </script> 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
|
|
||||||
);
|
|
|
@ -535,15 +535,6 @@ var testNames = [
|
||||||
return new PathTestScene();
|
return new PathTestScene();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title:"Performance Test",
|
|
||||||
platforms: PLATFORM_ALL,
|
|
||||||
linksrc:"",
|
|
||||||
resource:g_performace,
|
|
||||||
testScene:function () {
|
|
||||||
return new PerformanceTestScene();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title:"Physics3D Test",
|
title:"Physics3D Test",
|
||||||
platforms: PLATFORM_JSB,
|
platforms: PLATFORM_JSB,
|
||||||
|
|
|
@ -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
|
|
File diff suppressed because it is too large
Load Diff
|
@ -36,7 +36,6 @@ require "OpenGLTest/OpenGLTest"
|
||||||
require "ParallaxTest/ParallaxTest"
|
require "ParallaxTest/ParallaxTest"
|
||||||
require "ParticleTest/ParticleTest"
|
require "ParticleTest/ParticleTest"
|
||||||
require "Particle3DTest/Particle3DTest"
|
require "Particle3DTest/Particle3DTest"
|
||||||
require "PerformanceTest/PerformanceTest"
|
|
||||||
require "RenderTextureTest/RenderTextureTest"
|
require "RenderTextureTest/RenderTextureTest"
|
||||||
require "RotateWorldTest/RotateWorldTest"
|
require "RotateWorldTest/RotateWorldTest"
|
||||||
require "Sprite3DTest/Sprite3DTest"
|
require "Sprite3DTest/Sprite3DTest"
|
||||||
|
@ -124,7 +123,6 @@ local _allTests = {
|
||||||
{ isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain },
|
{ isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain },
|
||||||
{ isSupported = true, name = "ParticleTest" , create_func = ParticleTest },
|
{ isSupported = true, name = "ParticleTest" , create_func = ParticleTest },
|
||||||
{ isSupported = true, name = "Particle3D (PU)" , create_func = Particle3DTest },
|
{ 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 = "PhysicsTest" , create_func = PhysicsTest },
|
||||||
{ isSupported = true, name = "Physics3DTest" , create_func = Physics3DTest },
|
{ isSupported = true, name = "Physics3DTest" , create_func = Physics3DTest },
|
||||||
{ isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
|
{ isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
|
||||||
|
|
Loading…
Reference in New Issue