Merge pull request #7444 from samuele3hu/v3_hot_fix

Add bit extend module and fix some bugs found in test
This commit is contained in:
minggo 2014-07-15 13:45:19 +08:00
commit 642321d5a7
12 changed files with 407 additions and 461 deletions

View File

@ -58,6 +58,8 @@
1503FAC418DA8B6C00F6518C /* tp.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB118DA8B6C00F6518C /* tp.lua */; };
1503FAC518DA8B6C00F6518C /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB218DA8B6C00F6518C /* url.lua */; };
1503FAC618DA8B6C00F6518C /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB218DA8B6C00F6518C /* url.lua */; };
156229331973D400009C9067 /* bitExtend.lua in Resources */ = {isa = PBXBuildFile; fileRef = 156229321973D400009C9067 /* bitExtend.lua */; };
156229341973D400009C9067 /* bitExtend.lua in Resources */ = {isa = PBXBuildFile; fileRef = 156229321973D400009C9067 /* bitExtend.lua */; };
15AECE0B195C0F8A00907DB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA0FB65191B933000B170C8 /* MediaPlayer.framework */; };
15AECE0F195C1FDD00907DB0 /* cocosvideo.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 3EA0FB5D191B92F100B170C8 /* cocosvideo.mp4 */; };
15AECE1F195D0EC500907DB0 /* experimentalConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = 15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */; };
@ -1393,6 +1395,7 @@
1503FAB018DA8B6C00F6518C /* socket.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = socket.lua; path = ../external/lua/luasocket/socket.lua; sourceTree = "<group>"; };
1503FAB118DA8B6C00F6518C /* tp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tp.lua; path = ../external/lua/luasocket/tp.lua; sourceTree = "<group>"; };
1503FAB218DA8B6C00F6518C /* url.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = url.lua; path = ../external/lua/luasocket/url.lua; sourceTree = "<group>"; };
156229321973D400009C9067 /* bitExtend.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = bitExtend.lua; path = "../cocos/scripting/lua-bindings/script/bitExtend.lua"; sourceTree = "<group>"; };
15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = experimentalConstants.lua; path = "../cocos/scripting/lua-bindings/script/experimentalConstants.lua"; sourceTree = "<group>"; };
15C64822165F391E007D4F18 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
15C64824165F3934007D4F18 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; };
@ -5531,6 +5534,7 @@
1ABCA36418CD9E060087CE3A /* Lua Common */ = {
isa = PBXGroup;
children = (
156229321973D400009C9067 /* bitExtend.lua */,
15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */,
1503FAA918DA8B6C00F6518C /* ftp.lua */,
1503FAAA18DA8B6C00F6518C /* headers.lua */,
@ -7897,6 +7901,7 @@
15C90B4918E66C2A00D69802 /* tp.lua in Resources */,
1AC35DE918CEE65900F37B72 /* effect1.wav in Resources */,
1ABCA38E18CD9E180087CE3A /* GuiConstants.lua in Resources */,
156229331973D400009C9067 /* bitExtend.lua in Resources */,
15C90B3F18E66C0C00D69802 /* ltn12.lua in Resources */,
15C90B4718E66C2400D69802 /* socket.lua in Resources */,
15C90B3A18E66BE200D69802 /* ftp.lua in Resources */,
@ -7939,6 +7944,7 @@
15B0870D195AD52000D6F62B /* ActionTimeline in Resources */,
15E66FC8192D957100C20A52 /* Sprite3DTest in Resources */,
15C90B4418E66C1800D69802 /* mime.lua in Resources */,
156229341973D400009C9067 /* bitExtend.lua in Resources */,
15C90B4C18E66C3100D69802 /* url.lua in Resources */,
1AC35DD618CEE65200F37B72 /* Misc in Resources */,
1ABCA37B18CD9E180087CE3A /* CCBReaderLoad.lua in Resources */,

View File

@ -6090,7 +6090,8 @@ int lua_cocos2dx_TMXLayer_getTileGIDAt(lua_State* tolua_S)
return 0;
unsigned int ret = cobj->getTileGIDAt(arg0);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
tolua_pushnumber(tolua_S,(lua_Number)0);
return 2;
}
if (argc == 2)
{
@ -6105,7 +6106,8 @@ int lua_cocos2dx_TMXLayer_getTileGIDAt(lua_State* tolua_S)
unsigned int ret = cobj->getTileGIDAt(arg0, (cocos2d::TMXTileFlags*)&arg1);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
tolua_pushnumber(tolua_S,(lua_Number)arg1);
return 2;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getTileGIDAt",argc, 1);
return 0;
@ -6471,7 +6473,8 @@ static int lua_cocos2dx_FastTMXLayer_getTileGIDAt(lua_State* tolua_S)
return 0;
int ret = cobj->getTileGIDAt(arg0);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
tolua_pushnumber(tolua_S,(lua_Number)0);
return 2;
}
if (argc == 2)
{
@ -6486,7 +6489,8 @@ static int lua_cocos2dx_FastTMXLayer_getTileGIDAt(lua_State* tolua_S)
unsigned int ret = cobj->getTileGIDAt(arg0, (cocos2d::TMXTileFlags*)&arg1);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
tolua_pushnumber(tolua_S,(lua_Number)arg1);
return 2;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getTileGIDAt",argc, 1);
return 0;

View File

@ -0,0 +1,95 @@
-- bit operation
bit = bit or {}
bit.data32 = {}
for i=1,32 do
bit.data32[i]=2^(32-i)
end
function bit._b2d(arg)
local nr=0
for i=1,32 do
if arg[i] ==1 then
nr=nr+bit.data32[i]
end
end
return nr
end
function bit._d2b(arg)
arg = arg >= 0 and arg or (0xFFFFFFFF + arg + 1)
local tr={}
for i=1,32 do
if arg >= bit.data32[i] then
tr[i]=1
arg=arg-bit.data32[i]
else
tr[i]=0
end
end
return tr
end
function bit._and(a,b)
local op1=bit._d2b(a)
local op2=bit._d2b(b)
local r={}
for i=1,32 do
if op1[i]==1 and op2[i]==1 then
r[i]=1
else
r[i]=0
end
end
return bit._b2d(r)
end
function bit._rshift(a,n)
local op1=bit._d2b(a)
n = n <= 32 and n or 32
n = n >= 0 and n or 0
for i=32, n+1, -1 do
op1[i] = op1[i-n]
end
for i=1, n do
op1[i] = 0
end
return bit._b2d(op1)
end
function bit._not(a)
local op1=bit._d2b(a)
local r={}
for i=1,32 do
if op1[i]==1 then
r[i]=0
else
r[i]=1
end
end
return bit._b2d(r)
end
function bit._or(a,b)
local op1=bit._d2b(a)
local op2=bit._d2b(b)
local r={}
for i=1,32 do
if op1[i]==1 or op2[i]==1 then
r[i]=1
else
r[i]=0
end
end
return bit._b2d(r)
end
bit.band = bit.band or bit._and
bit.rshift = bit.rshift or bit._rshift
bit.bnot = bit.bnot or bit._not

View File

@ -25,6 +25,15 @@ SceneEditorTestLayer.title =
"Trigger Test",
}
SceneEditorTestLayer.loadtypeStr=
{
"change to load \nwith binary file",
"change to load \nwith json file"
}
SceneEditorTestLayer.fileName = ""
SceneEditorTestLayer.rootNode = nil
function SceneEditorTestLayer.extend(target)
local t = tolua.getpeer(target)
if not t then
@ -70,9 +79,44 @@ function SceneEditorTestLayer:createTitle()
title:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 30))
end
function SceneEditorTestLayer:loadFileChangeHelper(filePathName)
local indexTable = {}
local index = 0
while true do
index = string.find(filePathName, "%.", index + 1)
if nil == index then
break
end
indexTable[#indexTable + 1] = index
end
if #indexTable == 0 then
return filePathName
end
local lastIndex = indexTable[#indexTable]
if lastIndex == 1 then
return filePathName
end
local renamePathName= string.sub(filePathName, 1, lastIndex - 1)
if self.isCsbLoad then
renamePathName = renamePathName .. ".csb"
else
renamePathName = renamePathName .. ".json"
end
print("renamePath is", renamePathName)
return renamePathName
end
function SceneEditorTestLayer:defaultPlay()
end
function SceneEditorTestLayer:createMenu()
local menu = cc.Menu:create()
local function pre()
local scene = cc.Scene:create()
scene:addChild(backSceneEditorTest())
@ -118,6 +162,41 @@ function SceneEditorTestLayer:createMenu()
end
end
self.isCsbLoad = false
self.loadtypeLabel = cc.Label:createWithSystemFont(self.loadtypeStr[1], "Arial", 12)
local function changeLoadTypeCallback(tag,sender)
self.isCsbLoad = not self.isCsbLoad
if self.isCsbLoad then
self.loadtypeLabel:setString(self.loadtypeStr[2])
else
self.loadtypeLabel:setString(self.loadtypeStr[1])
end
if sceneEditorTestIdx == #SceneEditorTestLayer.title then
self:unscheduleUpdate()
end
SceneEditorTestLayer.fileName = self:loadFileChangeHelper(SceneEditorTestLayer.fileName)
if SceneEditorTestLayer.rootNode ~= nil then
self:removeChild(SceneEditorTestLayer.rootNode, true)
SceneEditorTestLayer.rootNode = ccs.SceneReader:getInstance():createNodeWithSceneFile(SceneEditorTestLayer.fileName)
if SceneEditorTestLayer.rootNode == nil then
return
end
self:defaultPlay()
self:addChild(SceneEditorTestLayer.rootNode, 0, 1)
end
end
local loadTypeItem = cc.MenuItemLabel:create(self.loadtypeLabel)
loadTypeItem:registerScriptTapHandler(changeLoadTypeCallback)
local loadtypeMenu = cc.Menu:create()
loadtypeMenu:addChild(loadTypeItem)
loadtypeMenu:setPosition(cc.p(0,0))
loadTypeItem:setPosition(cc.p(VisibleRect:rightTop().x -80,VisibleRect:rightTop().y -30))
self:addChild(loadtypeMenu, 100)
local backMenu = cc.Menu:create()
cc.MenuItemFont:setFontName("Arial")
cc.MenuItemFont:setFontSize(24)
@ -145,9 +224,16 @@ end
function LoadSceneEdtiorFileTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/LoadSceneEdtiorFileTest/FishJoy2.json")
SceneEditorTestLayer.fileName = "scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
return node
end
function LoadSceneEdtiorFileTest:defaultPlay()
end
function LoadSceneEdtiorFileTest:onEnter()
self:createMenu()
self:createTitle()
@ -191,13 +277,9 @@ end
function SpriteComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/SpriteComponentTest/SpriteComponentTest.json")
if nil ~= node then
local action1 = cc.Blink:create(2, 10)
local action2 = cc.Blink:create(2, 5)
local sister1 = node:getChildByTag(10003):getComponent("CCSprite")
sister1:getNode():runAction(action1)
local sister2 = node:getChildByTag(10004):getComponent("CCSprite")
sister2:getNode():runAction(action2)
SceneEditorTestLayer.fileName = "scenetest/SpriteComponentTest/SpriteComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
@ -209,8 +291,19 @@ function SpriteComponentTest:onEnter()
local root = self:createGameScene()
if nil ~= root then
self:addChild(root, 0, 1)
end
end
function SpriteComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local action1 = cc.Blink:create(2, 10)
local action2 = cc.Blink:create(2, 5)
local sister1 = SceneEditorTestLayer.rootNode:getChildByTag(10003):getComponent("CCSprite")
sister1:getNode():runAction(action1)
local sister2 = SceneEditorTestLayer.rootNode:getChildByTag(10004):getComponent("CCSprite")
sister2:getNode():runAction(action2)
end
end
function SpriteComponentTest.create()
@ -246,14 +339,23 @@ end
function ArmatureComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json")
if nil ~= node then
SceneEditorTestLayer.fileName = "scenetest/ArmatureComponentTest/ArmatureComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function ArmatureComponentTest:defaultPlay()
if SceneEditorTestLayer.rootName ~= nil then
local blowFish = node:getChildByTag(10007):getComponent("CCArmature")
blowFish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
local butterflyfish = node:getChildByTag(10008):getComponent("CCArmature")
butterflyfish:getNode():runAction(CCMoveBy:create(10.0, cc.p(-1000.0, 0)))
butterflyfish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
end
return node
end
function ArmatureComponentTest:onEnter()
@ -299,23 +401,31 @@ end
function UIComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json")
if nil ~= node then
local render = node:getChildByTag(10025):getComponent("GUIComponent")
SceneEditorTestLayer.fileName = "scenetest/UIComponentTest/UIComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function UIComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local render = SceneEditorTestLayer.rootNode:getChildByTag(10025):getComponent("GUIComponent")
local widget = render:getNode()
local button = widget:getChildByName("Button_156")
local function onTouch(sender, eventType)
if eventType == ccui.TouchEventType.began then
local blowFish = node:getChildByTag(10010):getComponent("CCArmature")
local blowFish = SceneEditorTestLayer.rootNode:getChildByTag(10010):getComponent("CCArmature")
blowFish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
local butterflyfish = node:getChildByTag(10011):getComponent("CCArmature")
local butterflyfish = SceneEditorTestLayer.rootNode:getChildByTag(10011):getComponent("CCArmature")
butterflyfish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
end
end
button:addTouchEventListener(onTouch)
end
return node
end
function UIComponentTest:onEnter()
@ -361,7 +471,18 @@ end
function TmxMapComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json")
if nil ~= node then
local tmxMap = node:getChildByTag(10015):getComponent("CCTMXTiledMap")
SceneEditorTestLayer.fileName = "scenetest/TmxMapComponentTest/TmxMapComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function TmxMapComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local tmxMap = SceneEditorTestLayer.rootNode:getChildByTag(10015):getComponent("CCTMXTiledMap")
local actionTo = cc.SkewTo:create(2, 0.0, 2.0)
local rotateTo = cc.RotateTo:create(2, 61.0)
local actionScaleTo = cc.ScaleTo:create(2, -0.44, 0.47)
@ -374,8 +495,6 @@ function TmxMapComponentTest:createGameScene()
tmxMap:getNode():runAction(cc.Sequence:create(rotateTo, rotateToBack))
tmxMap:getNode():runAction(cc.Sequence:create(actionScaleTo, actionScaleToBack))
end
return node
end
function TmxMapComponentTest:onEnter()
@ -421,13 +540,22 @@ end
function ParticleComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json")
if nil ~= node then
local particle = node:getChildByTag(10020):getComponent("CCParticleSystemQuad")
SceneEditorTestLayer.fileName = "scenetest/ParticleComponentTest/ParticleComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function ParticleComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local particle = SceneEditorTestLayer.rootNode:getChildByTag(10020):getComponent("CCParticleSystemQuad")
local jump = cc.JumpBy:create(5, cc.p(-500,0), 50, 4)
local action = cc.Sequence:create( jump, jump:reverse())
particle:getNode():runAction(action)
end
return node
end
function ParticleComponentTest:onEnter()
@ -473,13 +601,24 @@ end
function EffectComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json")
if nil ~= node then
local render = node:getChildByTag(10015):getComponent("CCArmature")
SceneEditorTestLayer.fileName = "scenetest/EffectComponentTest/EffectComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function EffectComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local render = SceneEditorTestLayer.rootNode:getChildByTag(10015):getComponent("CCArmature")
local armature = render:getNode()
local function animationEvent(armatureBack,movementType,movementID)
local id = movementID
if movementType == ccs.MovementEventType.loopComplete then
if id == "Fire" then
local audio = node:getChildByTag(10015):getComponent("CCComAudio")
local audio = SceneEditorTestLayer.rootNode:getChildByTag(10015):getComponent("CCComAudio")
audio:playEffect()
end
end
@ -487,8 +626,6 @@ function EffectComponentTest:createGameScene()
armature:getAnimation():setMovementEventCallFunc(animationEvent)
end
return node
end
function EffectComponentTest:onEnter()
@ -534,13 +671,22 @@ end
function BackgroundComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.json")
if nil ~= node then
local audio = node:getComponent("CCBackgroundAudio")
audio:playBackgroundMusic()
SceneEditorTestLayer.fileName = "scenetest/BackgroundComponentTest/BackgroundComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function BackgroundComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local audio = SceneEditorTestLayer.rootNode:getComponent("CCBackgroundAudio")
audio:playBackgroundMusic()
end
end
function BackgroundComponentTest:onEnter()
self:createMenu()
self:createTitle()
@ -583,11 +729,21 @@ end
function AttributeComponentTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.json")
local attribute = node:getChildByTag(10015):getComponent("CCComAttribute")
print(string.format("Name: %s, HP: %f, MP: %f", attribute:getString("name"), attribute:getFloat("maxHP"), attribute:getFloat("maxMP")))
if nil ~= node then
SceneEditorTestLayer.fileName = "scenetest/AttributeComponentTest/AttributeComponentTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
function AttributeComponentTest:defaultPlay()
if SceneEditorTestLayer.rootNode ~= nil then
local attribute = SceneEditorTestLayer.rootNode:getChildByTag(10015):getComponent("CCComAttribute")
print(string.format("Name: %s, HP: %f, MP: %f", attribute:getString("name"), attribute:getFloat("maxHP"), attribute:getFloat("maxMP")))
end
end
function AttributeComponentTest:onEnter()
self:createMenu()
self:createTitle()
@ -631,7 +787,12 @@ end
function TriggerTest:createGameScene()
local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/TriggerTest/TriggerTest.json")
if nil ~= node then
SceneEditorTestLayer.fileName = "scenetest/TriggerTest/TriggerTest.json"
SceneEditorTestLayer.rootNode = node
self:defaultPlay()
end
return node
end
@ -658,6 +819,17 @@ function TriggerTest:onEnter()
local root = self:createGameScene()
if nil ~= root then
self:addChild(root, 0, 1)
local function onTouchEvent(touch, event)
if eventType == "began" then
return self:onTouchBegan(touch, event)
elseif eventType == "moved" then
self:onTouchMoved(touch, event)
elseif eventType == "ended" then
self:onTouchEnded(touch, event)
elseif eventType == "cancelled" then
self:onTouchCancelled(touch, event)
end
end
self._touchListener = nil
local listener = cc.EventListenerTouchOneByOne:create()
listener:setSwallowTouches(true)
@ -668,20 +840,27 @@ function TriggerTest:onEnter()
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
self._touchListener = listener
self:unscheduleUpdate()
local function update(dt)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_UPDATESCENE)
end
self:scheduleUpdateWithPriorityLua(update,0)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_ENTERSCENE)
end
end
end
function TriggerTest:defaultPlay()
end
function TriggerTest:onExit()
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_LEAVESCENE)
self:unscheduleUpdate()
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_LEAVESCENE)
local dispatcher = self:getEventDispatcher()
dispatcher:removeEventListener(self._touchListener)
self._touchListener = nil
ccs.TriggerMng.destroyInstance()
ccs.ArmatureDataManager:destroyInstance()
ccs.SceneReader:destroyInstance()

View File

@ -1,6 +1,5 @@
require "src/ExtensionTest/CocosBuilderTest"
require "src/ExtensionTest/WebProxyTest"
require "src/ExtensionTest/SceneEditorTest"
local LINE_SPACE = 40
local kItemTagBasic = 1000
@ -14,8 +13,7 @@ local ExtensionTestEnum =
TEST_EDITBOX = 4,
TEST_TABLEVIEW = 5,
TEST_SCROLLVIEW = 6,
TEST_STUDIOSCENE = 7,
TEST_MAX_COUNT = 8,
TEST_MAX_COUNT = 7,
}
local testsName =
@ -27,7 +25,6 @@ local testsName =
"EditBoxTest",
"TableViewTest",
"ScrollViewTest",
"CocoStudioSceneTest",
}
@ -1190,7 +1187,6 @@ local CreateExtensionsTestTable =
runEditBoxTest,
runTableViewTest,
runScrollViewTest,
runStudioSceneTest,
}

View File

@ -1,270 +0,0 @@
require "CCBReaderLoad"
function SceneEditorTestLayer(filename)
local layer = cc.Layer:create()
local isCsbLoad = false;
local loadtypeStr = {"change to load \nwith binary file","change to load \nwith json file"}
local loadtypelb = cc.Label:createWithSystemFont(loadtypeStr[1], "Arial", 12);
local filePath = filename
layer.rootNode = nil
function layer:defaultPlay()end
local loadFileChangeHelper = function(filename)
if filename ~= nil then
if isCsbLoad then
return filename .. ".csb"
else
return filename .. ".json"
end
end
return filename
end
local changeLoadTypeCallback = function(sender)
isCsbLoad = not isCsbLoad
loadtypelb:setString(loadtypeStr[isCsbLoad == false and 1 or 2])
local file = loadFileChangeHelper(filePath)
if layer.rootNode ~= nil then
layer:removeChild(layer.rootNode)
layer.rootNode = SceneReader:getInstance():createNodeWithSceneFile(file)
layer:addChild(layer.rootNode, 0, 1)
layer:defaultPlay()
end
end
function layer:enter()
layer.rootNode = SceneReader:getInstance():createNodeWithSceneFile(loadFileChangeHelper(filePath))
layer:addChild(layer.rootNode, 0, 1)
layer:defaultPlay()
end
function layer:exit()
ccs.ArmatureDataManager:destroyInstance()
ccs.SceneReader:destroyInstance()
ccs.ActionManagerEx:destroyInstance()
ccs.GUIReader:destroyInstance()
end
local function onNodeEvent(event)
if "enter" == event then
layer:enter()
elseif "exit" == event then
layer:exit()
end
end
layer:registerScriptHandler(onNodeEvent)
local itemlb = cc.MenuItemLabel:create(loadtypelb)
itemlb:registerScriptTapHandler(changeLoadTypeCallback)
local loadtypemenu = cc.Menu:create(itemlb)
loadtypemenu:setPosition(cc.p(VisibleRect:rightTop().x -50,VisibleRect:rightTop().y -20));
layer:addChild(loadtypemenu,100);
Helper.initWithLayer(layer)
Helper.titleLabel:setString("SceneReader Test LoadSceneEditorFile")
return layer
end
function LoadSceneEdtiorFileTest()
local layer = SceneEditorTestLayer("scenetest/LoadSceneEdtiorFileTest/FishJoy2")
Helper.titleLabel:setString("loadSceneEdtiorFile Test")
return layer
end
function SpriteComponentTest()
local layer = SceneEditorTestLayer("scenetest/SpriteComponentTest/SpriteComponentTest")
Helper.titleLabel:setString("Sprite Component Test")
function layer:defaultPlay()
layer.rootNode:getChildByTag(10003):getComponent("CCSprite"):getNode():runAction(cc.Blink:create(2, 10));
layer.rootNode:getChildByTag(10004):getComponent("CCSprite"):getNode():runAction(cc.Blink:create(2, 5));
end
return layer
end
function ArmatureComponentTest()
local layer = SceneEditorTestLayer("scenetest/ArmatureComponentTest/ArmatureComponentTest")
Helper.titleLabel:setString("Armature Component Test")
function layer:defaultPlay()
layer.rootNode:getChildByTag(10007):getComponent("CCArmature"):getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
layer.rootNode:getChildByTag(10008):getComponent("CCArmature"):getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
end
return layer
end
function UIComponentTest()
local layer = SceneEditorTestLayer("scenetest/UIComponentTest/UIComponentTest")
Helper.titleLabel:setString("UI Component Test")
local function touchEvent(sender,eventType)
if eventType == ccui.TouchEventType.began then
layer.rootNode:getChildByTag(10010):getComponent("CCArmature"):getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
layer.rootNode:getChildByTag(10011):getComponent("CCArmature"):getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0)))
end
end
function layer:defaultPlay()
local render = layer.rootNode:getChildByTag(10025):getComponent("GUIComponent")
local widget = render:getNode()
local button = widget:getChildByName("Button_156")
button:addTouchEventListener(touchEvent)
end
return layer
end
function TmxMapComponentTest()
local layer = SceneEditorTestLayer("scenetest/TmxMapComponentTest/TmxMapComponentTest")
Helper.titleLabel:setString("TmxMap Component Test")
function layer:defaultPlay()
local render = layer.rootNode:getChildByTag(10015):getComponent("CCTMXTiledMap")
local skewTo = cc.SkewTo:create(2, 0, 2);
local rotateTo = cc.RotateTo:create(2, 61);
local scaleTo = cc.ScaleTo:create(2, -0.44, 0.47);
local scaleBack = cc.ScaleTo:create(2, 1, 1);
local rotateBack = cc.RotateTo:create(2, 0);
local skewBack = cc.SkewTo:create(2, 0, 0);
render:getNode():runAction(cc.Sequence:create(skewTo, skewBack));
render:getNode():runAction(cc.Sequence:create(rotateTo, rotateBack));
render:getNode():runAction(cc.Sequence:create(scaleTo, scaleBack));
end
return layer
end
function ParticleComponentTest()
local layer = SceneEditorTestLayer("scenetest/ParticleComponentTest/ParticleComponentTest")
Helper.titleLabel:setString("Particle Component Test")
function layer:defaultPlay()
local render = layer.rootNode:getChildByTag(10020):getComponent("CCParticleSystemQuad")
local action = cc.JumpBy:create(5, cc.p(-500,0), 50, 4);
render:getNode():runAction(cc.Sequence:create(action, action:reverse()))
end
return layer
end
function EffectComponentTest()
local layer = SceneEditorTestLayer("scenetest/EffectComponentTest/EffectComponentTest")
Helper.titleLabel:setString("Effect Component Test")
local animationEvent = function(armature,movementType,movementID)
if movementType == ccs.MovementEventType.loopComplete then
if movementID == "Fire" then
layer.rootNode:getChildByTag(10015):getComponent("CCComAudio"):playEffect()
end
end
end
function layer:defaultPlay()
local render = layer.rootNode:getChildByTag(10015):getComponent("CCArmature")
render:getNode():getAnimation():setMovementEventCallFunc(animationEvent);
end
return layer
end
function BackgroundComponentTest()
local layer = SceneEditorTestLayer("scenetest/BackgroundComponentTest/BackgroundComponentTest")
Helper.titleLabel:setString("Background Component Test")
function layer:defaultPlay()
layer.rootNode:getComponent("CCBackgroundAudio"):playBackgroundMusic();
end
return layer
end
function AttributeComponentTest()
local layer = SceneEditorTestLayer("scenetest/AttributeComponentTest/AttributeComponentTest")
Helper.titleLabel:setString("Attribute Component Test")
function layer:defaultPlay()
local attribute = layer.rootNode:getChildByTag(10015):getComponent("CCComAttribute")
cclog("Name: " .. attribute:getString("name") .. ", HP: " .. attribute:getFloat("maxHP") .. ", MP: " .. attribute:getFloat("maxMP"))
end
return layer
end
function TriggerTest()
local layer = SceneEditorTestLayer("scenetest/TriggerTest/TriggerTest")
Helper.titleLabel:setString("Trigger Test")
local function onTouchBegan(touch, event)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_TOUCHBEGAN)
end
local function onTouchMoved(touch, event)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_TOUCHMOVED)
end
local function onTouchEnded(touch, event)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_TOUCHENDED)
end
local function onTouchCancelled(touch, event)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_TOUCHCANCELLED)
end
local touchListener = cc.EventListenerTouchOneByOne:create()
touchListener:setSwallowTouches(true)
touchListener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
touchListener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED)
touchListener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED)
touchListener:registerScriptHandler(onTouchCancelled, cc.Handler.EVENT_TOUCH_CANCELLED)
local eventDispatcher = layer:getEventDispatcher()
eventDispatcher:addEventListenerWithFixedPriority(touchListener, 1)
local function gameLogic(dt)
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_UPDATESCENE)
end
local layerExit = layer.exit
function layer:exit()
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_LEAVESCENE)
layer:unschedule(gameLogic)
eventDispatcher:removeEventListener(touchListener)
layerExit(layer)
end
schedule(layer,gameLogic)
function layer:defaultPlay()
ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_ENTERSCENE);
end
return layer
end
function runStudioSceneTest()
local scene = cc.Scene:create()
Helper.createFunctionTable = {
LoadSceneEdtiorFileTest,
SpriteComponentTest,
ArmatureComponentTest,
UIComponentTest,
TmxMapComponentTest,
ParticleComponentTest,
EffectComponentTest,
BackgroundComponentTest,
AttributeComponentTest,
TriggerTest,
}
scene:addChild(Helper.createFunctionTable[1]())
scene:addChild(CreateBackMenuItem())
return scene
end

View File

@ -1012,39 +1012,37 @@ local function TMXOrthoFlipRunTimeTest()
map:runAction(action)
local function flipIt(dt)
-- local map = tolua.cast(ret:getChildByTag(kTagTileMap), "TMXTiledMap")
-- local layer = map:getLayer("Layer 0")
local map = ret:getChildByTag(kTagTileMap)
local layer = map:getLayer("Layer 0")
local tileCoord = cc.p(1, 10)
local flags = 0
local GID, flags = layer:getTileGIDAt(tileCoord, flags)
if 0 ~= bit._and(flags, cc.TMX_TILE_VERTICAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_VERTICAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_VERTICAL_FLAG)
end
layer:setTileGID(GID, tileCoord, flags)
-- --blue diamond
-- local tileCoord = cc.p(1,10)
-- local flags = 0
-- local GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Vertical
-- if( flags & kcc.TMXTileVerticalFlag )
-- flags &= ~kcc.TMXTileVerticalFlag
-- else
-- flags |= kcc.TMXTileVerticalFlag
-- layer:setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags)
tileCoord = cc.p(1,8)
GID, flags = layer:getTileGIDAt(tileCoord, flags)
if 0 ~= bit._and(flags, cc.TMX_TILE_VERTICAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_VERTICAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_VERTICAL_FLAG)
end
layer:setTileGID(GID ,tileCoord, flags)
-- tileCoord = cc.p(1,8)
-- GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Vertical
-- if( flags & kcc.TMXTileVerticalFlag )
-- flags &= ~kcc.TMXTileVerticalFlag
-- else
-- flags |= kcc.TMXTileVerticalFlag
-- layer:setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags)
-- tileCoord = cc.p(2,8)
-- GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Horizontal
-- if( flags & kcc.TMXTileHorizontalFlag )
-- flags &= ~kcc.TMXTileHorizontalFlag
-- else
-- flags |= kcc.TMXTileHorizontalFlag
-- layer:setTileGID(GID, tileCoord, (ccTMXTileFlags)flags)
tileCoord = cc.p(2,8)
GID, flags = layer:getTileGIDAt(tileCoord, flags)
-- Horizontal
if 0~= bit._and(flags, cc.TMX_TILE_HORIZONTAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_HORIZONTAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_HORIZONTAL_FLAG)
end
layer:setTileGID(GID, tileCoord, flags)
end
local schedulerEntry = nil
local function onNodeEvent(event)
@ -1054,6 +1052,9 @@ local function TMXOrthoFlipRunTimeTest()
scheduler:unscheduleScriptEntry(schedulerEntry)
end
end
ret:registerScriptHandler(onNodeEvent)
return ret
end

View File

@ -20,6 +20,8 @@ local vertDefaultSource = "\n".."\n" ..
" v_texCoord = a_texCoord;\n" ..
"} \n"
local scaleFactor = cc.Director:getInstance():getContentScaleFactor()
local function OpenGLTestMainLayer()
local kItemTagBasic = 1000
local testCount = 16
@ -231,6 +233,8 @@ local function OpenGLTestMainLayer()
time = 0
majorLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return majorLayer
end
@ -272,6 +276,8 @@ local function OpenGLTestMainLayer()
time = 0
mandelbrotLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return mandelbrotLayer
end
@ -314,6 +320,8 @@ local function OpenGLTestMainLayer()
time = 0
heartLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return heartLayer
end
@ -357,6 +365,8 @@ local function OpenGLTestMainLayer()
time = 0
plasmaLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return plasmaLayer
end
@ -399,6 +409,8 @@ local function OpenGLTestMainLayer()
time = 0
flowerLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return flowerLayer
end
@ -441,6 +453,8 @@ local function OpenGLTestMainLayer()
time = 0
juliaLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return juliaLayer
end
@ -545,7 +559,7 @@ local function OpenGLTestMainLayer()
shader:setUniformsForBuiltins(transform)
gl.bindTexture(gl.TEXTURE_2D, texture.texture_id)
gl.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_TEX_COORDS or cc.VERTEX_ATTRIB_FLAG_POSITION)
gl.glEnableVertexAttribs(bit._or(cc.VERTEX_ATTRIB_FLAG_TEX_COORDS, cc.VERTEX_ATTRIB_FLAG_POSITION))
gl.bindBuffer(gl.ARRAY_BUFFER, squareVertexPositionBuffer.buffer_id)
gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION,2,gl.FLOAT,false,0,0)

View File

@ -16,89 +16,6 @@ local function range(from, to, step)
end, nil, from - step
end
-- bit operation
bit = bit or {}
bit.data32 = {}
for i=1,32 do
bit.data32[i]=2^(32-i)
end
function bit._b2d(arg)
local nr=0
for i=1,32 do
if arg[i] ==1 then
nr=nr+bit.data32[i]
end
end
return nr
end
function bit._d2b(arg)
arg = arg >= 0 and arg or (0xFFFFFFFF + arg + 1)
local tr={}
for i=1,32 do
if arg >= bit.data32[i] then
tr[i]=1
arg=arg-bit.data32[i]
else
tr[i]=0
end
end
return tr
end
function bit._and(a,b)
local op1=bit._d2b(a)
local op2=bit._d2b(b)
local r={}
for i=1,32 do
if op1[i]==1 and op2[i]==1 then
r[i]=1
else
r[i]=0
end
end
return bit._b2d(r)
end
function bit._rshift(a,n)
local op1=bit._d2b(a)
n = n <= 32 and n or 32
n = n >= 0 and n or 0
for i=32, n+1, -1 do
op1[i] = op1[i-n]
end
for i=1, n do
op1[i] = 0
end
return bit._b2d(op1)
end
function bit._not(a)
local op1=bit._d2b(a)
local r={}
for i=1,32 do
if op1[i]==1 then
r[i]=0
else
r[i]=1
end
end
return bit._b2d(r)
end
bit.band = bit.band or bit._and
bit.rshift = bit.rshift or bit._rshift
bit.bnot = bit.bnot or bit._not
-- bit operation end
local function initWithLayer(layer, callback)
curLayer = layer
layer.spriteTexture = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100):getTexture()

View File

@ -1001,14 +1001,15 @@ local function TextureAsync()
cc.Director:getInstance():getTextureCache():addImageAsync("Images/background.png", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/atlastest.png", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/grossini_dance_atlas.png",imageLoaded)
ret:unscheduleUpdate()
end
local schedulerEntry = nil
local function onNodeEvent(event)
if event == "enter" then
schedulerEntry = scheduler:scheduleScriptFunc(loadImages, 1.0, false)
ret:scheduleUpdateWithPriorityLua(loadImages,0)
elseif event == "exit" then
scheduler:unscheduleScriptEntry(schedulerEntry)
ret:unscheduleUpdate()
cc.Director:getInstance():getTextureCache():removeAllTextures()
end
end

View File

@ -1106,41 +1106,40 @@ local function TMXOrthoFlipRunTimeTest()
local action = cc.ScaleBy:create(2, 0.5)
map:runAction(action)
local function flipIt(dt)
local map = ret:getChildByTag(kTagTileMap)
local layer = map:getLayer("Layer 0")
-- local map = tolua.cast(ret:getChildByTag(kTagTileMap), "TMXTiledMap")
-- local layer = map:getLayer("Layer 0")
local tileCoord = cc.p(1, 10)
local flags = 0
local GID, flags = layer:getTileGIDAt(tileCoord, flags)
-- --blue diamond
-- local tileCoord = cc.p(1,10)
-- local flags = 0
-- local GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Vertical
-- if( flags & kcc.TMXTileVerticalFlag )
-- flags &= ~kcc.TMXTileVerticalFlag
-- else
-- flags |= kcc.TMXTileVerticalFlag
-- layer:setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags)
if 0 ~= bit._and(flags, cc.TMX_TILE_VERTICAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_VERTICAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_VERTICAL_FLAG)
end
layer:setTileGID(GID, tileCoord, flags)
tileCoord = cc.p(1,8)
GID, flags = layer:getTileGIDAt(tileCoord, flags)
if 0 ~= bit._and(flags, cc.TMX_TILE_VERTICAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_VERTICAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_VERTICAL_FLAG)
end
layer:setTileGID(GID ,tileCoord, flags)
-- tileCoord = cc.p(1,8)
-- GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Vertical
-- if( flags & kcc.TMXTileVerticalFlag )
-- flags &= ~kcc.TMXTileVerticalFlag
-- else
-- flags |= kcc.TMXTileVerticalFlag
-- layer:setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags)
-- tileCoord = cc.p(2,8)
-- GID = layer:getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags)
-- -- Horizontal
-- if( flags & kcc.TMXTileHorizontalFlag )
-- flags &= ~kcc.TMXTileHorizontalFlag
-- else
-- flags |= kcc.TMXTileHorizontalFlag
-- layer:setTileGID(GID, tileCoord, (ccTMXTileFlags)flags)
tileCoord = cc.p(2,8)
GID, flags = layer:getTileGIDAt(tileCoord, flags)
-- Horizontal
if 0~= bit._and(flags, cc.TMX_TILE_HORIZONTAL_FLAG) then
flags = bit._and(flags, bit._not(cc.TMX_TILE_HORIZONTAL_FLAG))
else
flags = bit._or(flags, cc.TMX_TILE_HORIZONTAL_FLAG)
end
layer:setTileGID(GID, tileCoord, flags)
end
local schedulerEntry = nil
local function onNodeEvent(event)
if event == "enter" then
@ -1149,6 +1148,9 @@ local function TMXOrthoFlipRunTimeTest()
scheduler:unscheduleScriptEntry(schedulerEntry)
end
end
ret:registerScriptHandler(onNodeEvent)
return ret
end

View File

@ -4,6 +4,7 @@ require "Opengl"
require "OpenglConstants"
require "StudioConstants"
require "GuiConstants"
require "bitExtend"
require "src/helper"
require "src/testResource"
require "src/VisibleRect"