mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop
# By samuele3hu (3) and others # Via James Chen (3) and others * 'develop' of https://github.com/cocos2d/cocos2d-x: Update CHANGELOG [ci skip] issue #3708:Remove some comments issue #3708:Remove the useless test case #3947 Simulate 'setTimeout' and 'setInterval' in JSB. issue #3708:Performance Test: data structure conversion in lua binding
This commit is contained in:
commit
7b4f15dae9
|
@ -6,6 +6,7 @@ cocos2d-x-3.0rc0 Feb.?? 2014
|
|||
[NEW] Using python to automatically generate script bindings codes.
|
||||
[NEW] Linux javascript bindings support.
|
||||
|
||||
[FIX] Supports 'setTimeout' and 'setInterval' in JSB.
|
||||
[FIX] Exposes the missing data structures of Spine to JS.
|
||||
[FIX] Node::setRotation() moves opposite when node has a physics body.
|
||||
[FIX] A string which only contains CJK characters can't make a line-break when it's needed.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
var cc = cc || {};
|
||||
var window = window || this;
|
||||
|
||||
cc.TARGET_PLATFORM = {
|
||||
WINDOWS:0,
|
||||
|
@ -821,3 +822,62 @@ cc.VisibleRect = {
|
|||
}
|
||||
};
|
||||
|
||||
var _windowTimeIntervalId = 0;
|
||||
var _windowTimeFunHash = {};
|
||||
var WindowTimeFun = cc.Class.extend({
|
||||
_code: null,
|
||||
_intervalId: 0,
|
||||
ctor: function (code) {
|
||||
this._intervalId = _windowTimeIntervalId++;
|
||||
this._code = code;
|
||||
},
|
||||
fun: function () {
|
||||
if (!this._code) return;
|
||||
var code = this._code;
|
||||
if (typeof code == "string") {
|
||||
Function(code)();
|
||||
}
|
||||
else if (typeof code == "function") {
|
||||
code();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* overwrite window's setTimeout
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
var setTimeout = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, 0, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's setInterval
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
var setInterval = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, cc.REPEAT_FOREVER, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's clearInterval
|
||||
@param {number} intervalId
|
||||
*/
|
||||
var clearInterval = function (intervalId) {
|
||||
var target = _windowTimeFunHash[intervalId];
|
||||
if (target) {
|
||||
cc.Director.getInstance().getScheduler().unscheduleCallbackForTarget(target, target.fun);
|
||||
delete _windowTimeFunHash[intervalId];
|
||||
}
|
||||
};
|
||||
var clearTimeout = clearInterval;
|
|
@ -1,6 +1,6 @@
|
|||
require "luaScript/PerformanceTest/PerformanceSpriteTest"
|
||||
|
||||
local MAX_COUNT = 5
|
||||
local MAX_COUNT = 6
|
||||
local LINE_SPACE = 40
|
||||
local kItemTagBasic = 1000
|
||||
|
||||
|
@ -10,7 +10,8 @@ local testsName =
|
|||
"PerformanceParticleTest",
|
||||
"PerformanceSpriteTest",
|
||||
"PerformanceTextureTest",
|
||||
"PerformanceTouchesTest"
|
||||
"PerformanceTouchesTest",
|
||||
"PerformanceFuncRelateWithTable",
|
||||
}
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
|
@ -1020,7 +1021,7 @@ local function runSpriteTest()
|
|||
|
||||
local function Performanceout20(pSprite)
|
||||
local size = cc.Director:getInstance():getWinSize()
|
||||
|
||||
print("come in")
|
||||
if math.random() < 0.2 then
|
||||
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
||||
else
|
||||
|
@ -1651,6 +1652,223 @@ local function runTouchesTest()
|
|||
return pNewscene
|
||||
end
|
||||
|
||||
local function runFuncRelateWithTable()
|
||||
-- body
|
||||
local newscene = cc.Scene:create()
|
||||
local layer = cc.Layer:create()
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local scheduler = cc.Director:getInstance():getScheduler()
|
||||
local scheduleEntryID = 0
|
||||
local quantityOfNodes = 10000
|
||||
local socket = require("socket")
|
||||
local maxTime = 0.0
|
||||
local minTime = 99999
|
||||
local averageTime1 = 0.0
|
||||
local averageTime2 = 0.0
|
||||
local totalTime = 0.0
|
||||
local numberOfCalls = 0
|
||||
|
||||
local function GetTitle()
|
||||
return "Func Releated Table Performance Test"
|
||||
end
|
||||
|
||||
local function GetSubtitle()
|
||||
return "See console for results"
|
||||
end
|
||||
|
||||
local function initVar()
|
||||
maxTime = 0.0
|
||||
minTime = 99999
|
||||
averageTime1 = 0.0
|
||||
averageTime2 = 0.0
|
||||
totalTime = 0.0
|
||||
numberOfCalls = 0
|
||||
end
|
||||
|
||||
--Title
|
||||
local title = cc.LabelTTF:create(GetTitle(), "Arial", 28)
|
||||
layer:addChild(title, 1)
|
||||
title:setPosition(cc.p(s.width/2, s.height-32))
|
||||
title:setColor(cc.c3b(255,255,40))
|
||||
--Subtitle
|
||||
local subTitle = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16)
|
||||
layer:addChild(subTitle, 1)
|
||||
subTitle:setPosition(cc.p(s.width/2, s.height-80))
|
||||
|
||||
--"+","-" Menu
|
||||
local function onDecrease()
|
||||
quantityOfNodes = quantityOfNodes - 100
|
||||
if quantityOfNodes == 0 then
|
||||
quantityOfNodes = 100
|
||||
end
|
||||
local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF")
|
||||
local strNum = string.format("%d", quantityOfNodes)
|
||||
numLabel:setString(strNum)
|
||||
end
|
||||
|
||||
local function onIncrease()
|
||||
quantityOfNodes = quantityOfNodes + 100
|
||||
local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF")
|
||||
local strNum = string.format("%d", quantityOfNodes)
|
||||
numLabel:setString(strNum)
|
||||
end
|
||||
|
||||
cc.MenuItemFont:setFontSize(65)
|
||||
local decrease = cc.MenuItemFont:create(" - ")
|
||||
decrease:registerScriptTapHandler(onDecrease)
|
||||
decrease:setColor(cc.c3b(0,200,20))
|
||||
local increase = cc.MenuItemFont:create(" + ")
|
||||
increase:registerScriptTapHandler(onIncrease)
|
||||
increase:setColor(cc.c3b(0,200,20))
|
||||
|
||||
local menuAddOrSub = cc.Menu:create()
|
||||
menuAddOrSub:addChild(decrease)
|
||||
menuAddOrSub:addChild(increase)
|
||||
menuAddOrSub:alignItemsHorizontally()
|
||||
menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
|
||||
layer:addChild(menuAddOrSub,1)
|
||||
|
||||
--num
|
||||
local numLabel = cc.LabelTTF:create("10000", "Marker Felt", 30)
|
||||
numLabel:setColor(cc.c3b(0,200,20))
|
||||
numLabel:setPosition(cc.p(s.width/2, s.height/2-15))
|
||||
layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer)
|
||||
|
||||
--setPosition,getPosition,Point
|
||||
cc.MenuItemFont:setFontSize(18)
|
||||
local setPositionItem = cc.MenuItemFont:create("setPosition")
|
||||
local getPositionItem = cc.MenuItemFont:create("getPosition")
|
||||
local getAnchorPointItem = cc.MenuItemFont:create("getAnchorPoint")
|
||||
local pointItem = cc.MenuItemFont:create("object")
|
||||
local funcToggleItem = cc.MenuItemToggle:create(setPositionItem)
|
||||
funcToggleItem:addSubItem(getPositionItem)
|
||||
funcToggleItem:addSubItem(getAnchorPointItem)
|
||||
funcToggleItem:addSubItem(pointItem)
|
||||
funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5))
|
||||
funcToggleItem:setPosition(cc.p(VisibleRect:left()))
|
||||
local funcMenu = cc.Menu:create(funcToggleItem)
|
||||
funcMenu:setPosition(cc.p(0, 0))
|
||||
layer:addChild(funcMenu)
|
||||
|
||||
local testNode = cc.Node:create()
|
||||
layer:addChild(testNode)
|
||||
|
||||
local function step(dt)
|
||||
print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",quantityOfNodes, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls))
|
||||
end
|
||||
|
||||
local function profileEnd(startTime)
|
||||
local duration = socket.gettime() - startTime
|
||||
totalTime = totalTime + duration
|
||||
averageTime1 = (averageTime1 + duration) / 2
|
||||
averageTime2 = totalTime / numberOfCalls
|
||||
|
||||
if maxTime < duration then
|
||||
maxTime = duration
|
||||
end
|
||||
|
||||
if minTime > duration then
|
||||
minTime = duration
|
||||
end
|
||||
end
|
||||
|
||||
local function callSetPosition()
|
||||
numberOfCalls = numberOfCalls + 1
|
||||
local startTime = socket.gettime()
|
||||
for i=1,quantityOfNodes do
|
||||
testNode:setPosition(cc.p(1,2))
|
||||
end
|
||||
profileEnd(startTime)
|
||||
end
|
||||
|
||||
local function callGetPosition()
|
||||
numberOfCalls = numberOfCalls + 1
|
||||
local startTime = socket.gettime()
|
||||
for i=1,quantityOfNodes do
|
||||
local x,y = testNode:getPosition()
|
||||
end
|
||||
profileEnd(startTime)
|
||||
end
|
||||
|
||||
local function callGetAnchorPoint()
|
||||
numberOfCalls = numberOfCalls + 1
|
||||
local startTime = socket.gettime()
|
||||
for i=1,quantityOfNodes do
|
||||
local anchorPoint = testNode:getAnchorPoint()
|
||||
end
|
||||
profileEnd(startTime)
|
||||
end
|
||||
|
||||
local function callTableObject()
|
||||
numberOfCalls = numberOfCalls + 1
|
||||
local startTime = socket.gettime()
|
||||
for i=1,quantityOfNodes do
|
||||
local pt = cc.p(1,2)
|
||||
end
|
||||
profileEnd(startTime)
|
||||
end
|
||||
|
||||
local function update(dt)
|
||||
|
||||
local funcSelected = funcToggleItem:getSelectedIndex()
|
||||
if 0 == funcSelected then
|
||||
callSetPosition()
|
||||
elseif 1 == funcSelected then
|
||||
callGetPosition()
|
||||
elseif 2 == funcSelected then
|
||||
callGetAnchorPoint()
|
||||
elseif 3 == funcSelected then
|
||||
callTableObject()
|
||||
end
|
||||
end
|
||||
|
||||
local function onNodeEvent(tag)
|
||||
if tag == "exit" then
|
||||
layer:unscheduleUpdate()
|
||||
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||
end
|
||||
end
|
||||
|
||||
layer:registerScriptHandler(onNodeEvent)
|
||||
|
||||
|
||||
local function startCallback()
|
||||
initVar()
|
||||
decrease:setEnabled(false)
|
||||
increase:setEnabled(false)
|
||||
funcToggleItem:setEnabled(false)
|
||||
layer:unscheduleUpdate()
|
||||
layer:scheduleUpdateWithPriorityLua(update, 0)
|
||||
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||
scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false)
|
||||
end
|
||||
|
||||
local function stopCallback()
|
||||
decrease:setEnabled(true)
|
||||
increase:setEnabled(true)
|
||||
funcToggleItem:setEnabled(true)
|
||||
layer:unscheduleUpdate()
|
||||
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||
end
|
||||
local startItem = cc.MenuItemFont:create("start")
|
||||
startItem:registerScriptTapHandler(startCallback)
|
||||
local stopItem = cc.MenuItemFont:create("stop")
|
||||
stopItem:registerScriptTapHandler(stopCallback)
|
||||
local startAndStop = cc.Menu:create(startItem,stopItem)
|
||||
startAndStop:alignItemsVertically()
|
||||
startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y)
|
||||
layer:addChild(startAndStop)
|
||||
|
||||
--back menu
|
||||
local menu = cc.Menu:create()
|
||||
CreatePerfomBasicLayerMenu(menu)
|
||||
menu:setPosition(cc.p(0, 0))
|
||||
layer:addChild(menu)
|
||||
|
||||
newscene:addChild(layer)
|
||||
return newscene
|
||||
end
|
||||
|
||||
|
||||
------------------------
|
||||
--
|
||||
|
@ -1661,7 +1879,8 @@ local CreatePerformancesTestTable =
|
|||
runParticleTest,
|
||||
runSpriteTest,
|
||||
runTextureTest,
|
||||
runTouchesTest
|
||||
runTouchesTest,
|
||||
runFuncRelateWithTable,
|
||||
}
|
||||
|
||||
local function CreatePerformancesTestScene(nPerformanceNo)
|
||||
|
@ -1687,7 +1906,7 @@ local function PerformanceMainLayer()
|
|||
for i = 1, MAX_COUNT do
|
||||
local item = cc.MenuItemFont:create(testsName[i])
|
||||
item:registerScriptTapHandler(menuCallback)
|
||||
item:setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE)
|
||||
item:setPosition(s.width / 2, s.height - i * LINE_SPACE)
|
||||
menu:addChild(item, kItemTagBasic + i)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue