Merge pull request #47 from cocos2d/v3

update cocos2d-x
This commit is contained in:
cocoscodeide 2014-07-12 10:49:44 +08:00
commit be5da3d74d
457 changed files with 17491 additions and 5017 deletions

View File

@ -886,6 +886,7 @@ Developers:
zhouxiaoxiaoxujian
Added TextField::getStringLength()
Add shadow, outline, glow filter support for UIText
Fix UITextField IME can't auto detach
QiuleiWang
Fix the bug that calculated height of multi-line string was incorrect on iOS
@ -906,6 +907,9 @@ Developers:
Teivaz
Custom uniform search optimization
chareice
Make `setup.py` work on zsh
Retired Core Developers:
WenSheng Yang

View File

@ -1,4 +1,22 @@
cocos2d-x-3.2rc0 ??
cocos2d-x-3.2 ??
[FIX] Animation3D: getOrCreate is deprecated and replaced with Animation3D::create
[FIX] Animate3D: setSpeed() accept negtive value, which means play reverse, getPlayback and setPlayBack are deprecated
[FIX] GLView: cursor position is not correct if design resolution is different from device resolution
[FIX] Label: color can not be set correctly if using system font
[FIX] Lua-binding: support UIVideoPlayer
[FIX] Node: setRotation3D not work based on anchor point
[FIX] Node: modify regular of enumerateChildren, now it just searchs its children
[FIX] Setup.py: not work if using zsh
[FIX] SpriteBatchNode: opacity can not work
[FIX] Sprite3D: may crash on Android if playing animation and replace Scene after come from background
[FIX] UIdget: opacity is wrong when replace texture
[FIX] UITextField: keyboard can not hide if touching space outside of keyboard
[FIX] Others: don't release singleton objects correctly that are needed in the whole game, which will be treated
as memory leak when using VLD.
cocos2d-x-3.2rc0 Jul.7 2014
[NEW] FastTMXTiledMap: added fast tmx, which is much more faster for static tiled map
[NEW] GLProgramState: can use uniform location to get/set uniform values
[NEW] HttpClient: added sendImmediate()

View File

@ -8,7 +8,7 @@ import shutil
from optparse import OptionParser
CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests', 'game-controller-test']
LUA_SAMPLES = ['lua-empty-test', 'lua-tests']
LUA_SAMPLES = ['lua-empty-test', 'lua-tests', 'lua-game-controller-test']
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES
def get_num_of_cpu():
@ -172,6 +172,10 @@ def copy_resources(target, app_android_root):
resources_dir = os.path.join(app_android_root, "../../../cpp-tests/Resources")
copy_files(resources_dir, assets_res_dir)
if target == "lua-game-controller-test":
print("coming generator game controller")
resources_dir = os.path.join(app_android_root, "../../../game-controller-test/Resources")
copy_files(resources_dir, assets_res_dir)
def build_samples(target,ndk_build_param,android_platform,build_mode):
@ -203,7 +207,8 @@ def build_samples(target,ndk_build_param,android_platform,build_mode):
"game-controller-test": "tests/game-controller-test/proj.android",
"cpp-tests": "tests/cpp-tests/proj.android",
"lua-empty-test": "tests/lua-empty-test/project/proj.android",
"lua-tests": "tests/lua-tests/project/proj.android"
"lua-tests": "tests/lua-tests/project/proj.android",
"lua-game-controller-test": "tests/lua-game-controller-test/project/proj.android"
}
for target in build_targets:

View File

@ -1025,23 +1025,12 @@
373B912A187891FB00198F86 /* CCComBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 373B910718787C0B00198F86 /* CCComBase.h */; };
3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */; };
3E6176691960F89B00DE83F5 /* CCController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176561960F89B00DE83F5 /* CCController.h */; };
3E61766A1960F89B00DE83F5 /* CCControllerAxisInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */; };
3E61766B1960F89B00DE83F5 /* CCControllerAxisInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */; };
3E61766C1960F89B00DE83F5 /* CCControllerButtonInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */; };
3E61766D1960F89B00DE83F5 /* CCControllerButtonInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */; };
3E61766E1960F89B00DE83F5 /* CCControllerDirectionPad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */; };
3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */; };
3E6176701960F89B00DE83F5 /* CCControllerElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */; };
3E6176711960F89B00DE83F5 /* CCControllerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765E1960F89B00DE83F5 /* CCControllerElement.h */; };
3E6176721960F89B00DE83F5 /* CCControllerThumbstick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */; };
3E6176731960F89B00DE83F5 /* CCControllerThumbstick.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */; };
3E6176741960F89B00DE83F5 /* CCEventController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176611960F89B00DE83F5 /* CCEventController.cpp */; };
3E6176751960F89B00DE83F5 /* CCEventController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176621960F89B00DE83F5 /* CCEventController.h */; };
3E6176761960F89B00DE83F5 /* CCEventListenerController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */; };
3E6176771960F89B00DE83F5 /* CCEventListenerController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176641960F89B00DE83F5 /* CCEventListenerController.h */; };
3E6176781960F89B00DE83F5 /* CCGameController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176651960F89B00DE83F5 /* CCGameController.h */; };
3E6176791960F89B00DE83F5 /* CCGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176661960F89B00DE83F5 /* CCGamepad.cpp */; };
3E61767A1960F89B00DE83F5 /* CCGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176671960F89B00DE83F5 /* CCGamepad.h */; };
3E61781D1966A5A300DE83F5 /* CCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61781C1966A5A300DE83F5 /* CCController.cpp */; };
3EA0FB6B191C841D00B170C8 /* UIVideoPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */; };
3EA0FB6C191C841D00B170C8 /* UIVideoPlayerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */; };
3EA47870195478E00068D9D1 /* CCBundleReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */; };
@ -2370,23 +2359,12 @@
37936A3E1869B76800E974DD /* writer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = writer.h; sourceTree = "<group>"; };
3E6176551960F89B00DE83F5 /* CCController-iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "CCController-iOS.mm"; path = "../base/CCController-iOS.mm"; sourceTree = "<group>"; };
3E6176561960F89B00DE83F5 /* CCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCController.h; path = ../base/CCController.h; sourceTree = "<group>"; };
3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerAxisInput.cpp; path = ../base/CCControllerAxisInput.cpp; sourceTree = "<group>"; };
3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerAxisInput.h; path = ../base/CCControllerAxisInput.h; sourceTree = "<group>"; };
3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerButtonInput.cpp; path = ../base/CCControllerButtonInput.cpp; sourceTree = "<group>"; };
3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerButtonInput.h; path = ../base/CCControllerButtonInput.h; sourceTree = "<group>"; };
3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerDirectionPad.cpp; path = ../base/CCControllerDirectionPad.cpp; sourceTree = "<group>"; };
3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerDirectionPad.h; path = ../base/CCControllerDirectionPad.h; sourceTree = "<group>"; };
3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerElement.cpp; path = ../base/CCControllerElement.cpp; sourceTree = "<group>"; };
3E61765E1960F89B00DE83F5 /* CCControllerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerElement.h; path = ../base/CCControllerElement.h; sourceTree = "<group>"; };
3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerThumbstick.cpp; path = ../base/CCControllerThumbstick.cpp; sourceTree = "<group>"; };
3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerThumbstick.h; path = ../base/CCControllerThumbstick.h; sourceTree = "<group>"; };
3E6176611960F89B00DE83F5 /* CCEventController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventController.cpp; path = ../base/CCEventController.cpp; sourceTree = "<group>"; };
3E6176621960F89B00DE83F5 /* CCEventController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventController.h; path = ../base/CCEventController.h; sourceTree = "<group>"; };
3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventListenerController.cpp; path = ../base/CCEventListenerController.cpp; sourceTree = "<group>"; };
3E6176641960F89B00DE83F5 /* CCEventListenerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventListenerController.h; path = ../base/CCEventListenerController.h; sourceTree = "<group>"; };
3E6176651960F89B00DE83F5 /* CCGameController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGameController.h; path = ../base/CCGameController.h; sourceTree = "<group>"; };
3E6176661960F89B00DE83F5 /* CCGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCGamepad.cpp; path = ../base/CCGamepad.cpp; sourceTree = "<group>"; };
3E6176671960F89B00DE83F5 /* CCGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGamepad.h; path = ../base/CCGamepad.h; sourceTree = "<group>"; };
3E61781C1966A5A300DE83F5 /* CCController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCController.cpp; path = ../base/CCController.cpp; sourceTree = "<group>"; };
3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoPlayer.h; sourceTree = "<group>"; };
3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIVideoPlayerIOS.mm; sourceTree = "<group>"; };
3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBundleReader.cpp; sourceTree = "<group>"; };
@ -3187,25 +3165,14 @@
1A5700A2180BC5E60088DEC7 /* base */ = {
isa = PBXGroup;
children = (
3E61781C1966A5A300DE83F5 /* CCController.cpp */,
3E6176551960F89B00DE83F5 /* CCController-iOS.mm */,
3E6176561960F89B00DE83F5 /* CCController.h */,
3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */,
3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */,
3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */,
3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */,
3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */,
3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */,
3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */,
3E61765E1960F89B00DE83F5 /* CCControllerElement.h */,
3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */,
3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */,
3E6176611960F89B00DE83F5 /* CCEventController.cpp */,
3E6176621960F89B00DE83F5 /* CCEventController.h */,
3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */,
3E6176641960F89B00DE83F5 /* CCEventListenerController.h */,
3E6176651960F89B00DE83F5 /* CCGameController.h */,
3E6176661960F89B00DE83F5 /* CCGamepad.cpp */,
3E6176671960F89B00DE83F5 /* CCGamepad.h */,
299754F2193EC95400A54AC3 /* ObjectFactory.cpp */,
299754F3193EC95400A54AC3 /* ObjectFactory.h */,
50ABBDC11925AB6E00A911A9 /* atitc.cpp */,
@ -5571,7 +5538,6 @@
1A570068180BC5A10088DEC7 /* CCActionCamera.h in Headers */,
1A57006C180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */,
5034CA3A191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */,
3E61766B1960F89B00DE83F5 /* CCControllerAxisInput.h in Headers */,
50ABBEC41925AB6F00A911A9 /* CCVector.h in Headers */,
50ABBE501925AB6F00A911A9 /* CCEventCustom.h in Headers */,
1A570070180BC5A10088DEC7 /* CCActionEase.h in Headers */,
@ -5608,7 +5574,6 @@
50ABC0101926664800A911A9 /* CCFileUtils.h in Headers */,
2905FA4318CF08D100240AA3 /* CocosGUI.h in Headers */,
5034CA30191D591100CE6051 /* ccShader_PositionTexture.vert in Headers */,
3E6176711960F89B00DE83F5 /* CCControllerElement.h in Headers */,
50E6D33718E174130051CA34 /* UIHBox.h in Headers */,
1A570111180BC8EE0088DEC7 /* CCDrawingPrimitives.h in Headers */,
50E6D33F18E174130051CA34 /* UIVBox.h in Headers */,
@ -5676,7 +5641,6 @@
5034CA2C191D591100CE6051 /* ccShader_PositionTextureA8Color.vert in Headers */,
50ABBE981925AB6F00A911A9 /* CCProtocols.h in Headers */,
2905FA8B18CF08D100240AA3 /* UITextField.h in Headers */,
3E6176731960F89B00DE83F5 /* CCControllerThumbstick.h in Headers */,
50FCEBA618C72017004AD434 /* ListViewReader.h in Headers */,
50ABBD431925AB0000A911A9 /* CCMathBase.h in Headers */,
50ABBE441925AB6F00A911A9 /* CCDirector.h in Headers */,
@ -5695,7 +5659,6 @@
50ABBE741925AB6F00A911A9 /* CCEventListenerMouse.h in Headers */,
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */,
50FCEB9A18C72017004AD434 /* CheckBoxReader.h in Headers */,
3E61766D1960F89B00DE83F5 /* CCControllerButtonInput.h in Headers */,
1A5702CB180BCE370088DEC7 /* CCTextFieldTTF.h in Headers */,
2905FA7F18CF08D100240AA3 /* UIText.h in Headers */,
1A5702ED180BCE750088DEC7 /* CCTileMapAtlas.h in Headers */,
@ -5708,7 +5671,6 @@
1A570303180BCE890088DEC7 /* CCParallaxNode.h in Headers */,
50ABBE2A1925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */,
1A57030F180BCF190088DEC7 /* CCComponent.h in Headers */,
3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */,
1A570313180BCF190088DEC7 /* CCComponentContainer.h in Headers */,
0634A4DF194B19E400E608AF /* CCNodeReader.h in Headers */,
1A087AEB1860400400196EF5 /* edtaa3func.h in Headers */,
@ -5815,7 +5777,6 @@
1AD71ED0180E26E600808F54 /* Skeleton.h in Headers */,
50ABBE541925AB6F00A911A9 /* CCEventDispatcher.h in Headers */,
1AD71ED4180E26E600808F54 /* SkeletonData.h in Headers */,
3E61767A1960F89B00DE83F5 /* CCGamepad.h in Headers */,
1AD71ED8180E26E600808F54 /* SkeletonJson.h in Headers */,
1A12775A18DFCC4F0005F345 /* CCTweenFunction.h in Headers */,
1AD71EDC180E26E600808F54 /* Skin.h in Headers */,
@ -6752,7 +6713,6 @@
3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */,
2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */,
29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */,
3E61766C1960F89B00DE83F5 /* CCControllerButtonInput.cpp in Sources */,
B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */,
0634A4D5194B19E400E608AF /* CCActionTimelineCache.cpp in Sources */,
50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */,
@ -6792,6 +6752,7 @@
1A57019E180BCB590088DEC7 /* CCFont.cpp in Sources */,
503DD8E21926736A00CD74DD /* CCCommon.mm in Sources */,
1A5701A2180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */,
3E61781D1966A5A300DE83F5 /* CCController.cpp in Sources */,
50ABC00E1926664800A911A9 /* CCFileUtils.cpp in Sources */,
50ABBE241925AB6F00A911A9 /* base64.cpp in Sources */,
1A5701A6180BCB590088DEC7 /* CCFontAtlasCache.cpp in Sources */,
@ -6831,13 +6792,11 @@
1A570215180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */,
1A570222180BCC1A0088DEC7 /* CCParticleBatchNode.cpp in Sources */,
1A570226180BCC1A0088DEC7 /* CCParticleExamples.cpp in Sources */,
3E6176791960F89B00DE83F5 /* CCGamepad.cpp in Sources */,
1A57022A180BCC1A0088DEC7 /* CCParticleSystem.cpp in Sources */,
B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */,
B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */,
1A57022E180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */,
50ABBD901925AB4100A911A9 /* CCGLProgramCache.cpp in Sources */,
3E6176701960F89B00DE83F5 /* CCControllerElement.cpp in Sources */,
2905FA5718CF08D100240AA3 /* UILayout.cpp in Sources */,
2905FA7D18CF08D100240AA3 /* UIText.cpp in Sources */,
50E6D33D18E174130051CA34 /* UIVBox.cpp in Sources */,
@ -6853,7 +6812,6 @@
1A5702C9180BCE370088DEC7 /* CCTextFieldTTF.cpp in Sources */,
1A5702EB180BCE750088DEC7 /* CCTileMapAtlas.cpp in Sources */,
1A5702EF180BCE750088DEC7 /* CCTMXLayer.cpp in Sources */,
3E61766A1960F89B00DE83F5 /* CCControllerAxisInput.cpp in Sources */,
1A5702F3180BCE750088DEC7 /* CCTMXObjectGroup.cpp in Sources */,
50ABBD3D1925AB0000A911A9 /* CCGeometry.cpp in Sources */,
50ABBECC1925AB6F00A911A9 /* s3tc.cpp in Sources */,
@ -6966,7 +6924,6 @@
50ABBE9A1925AB6F00A911A9 /* CCRef.cpp in Sources */,
3E6176741960F89B00DE83F5 /* CCEventController.cpp in Sources */,
50ABBE361925AB6F00A911A9 /* CCConsole.cpp in Sources */,
3E61766E1960F89B00DE83F5 /* CCControllerDirectionPad.cpp in Sources */,
503DD8E51926736A00CD74DD /* CCDirectorCaller.mm in Sources */,
50ABBD5D1925AB0000A911A9 /* Vec3.cpp in Sources */,
50ABC0121926664800A911A9 /* CCGLViewProtocol.cpp in Sources */,
@ -7005,7 +6962,6 @@
1A8C59D4180E930E00EF57C3 /* CCDecorativeDisplay.cpp in Sources */,
1A8C59D8180E930E00EF57C3 /* CCDisplayFactory.cpp in Sources */,
46C02E0818E91123004B7456 /* xxhash.c in Sources */,
3E6176721960F89B00DE83F5 /* CCControllerThumbstick.cpp in Sources */,
50ABBED01925AB6F00A911A9 /* TGAlib.cpp in Sources */,
2905FA4118CF08D100240AA3 /* CocosGUI.cpp in Sources */,
1A01C68518F57BE800EFE3A6 /* CCArray.cpp in Sources */,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "15CBA015196EE56C005877BB"
BuildableName = "lua-game-controller-test iOS.app"
BlueprintName = "lua-game-controller-test iOS"
ReferencedContainer = "container:cocos2d_tests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "15CBA015196EE56C005877BB"
BuildableName = "lua-game-controller-test iOS.app"
BlueprintName = "lua-game-controller-test iOS"
ReferencedContainer = "container:cocos2d_tests.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "15CBA015196EE56C005877BB"
BuildableName = "lua-game-controller-test iOS.app"
BlueprintName = "lua-game-controller-test iOS"
ReferencedContainer = "container:cocos2d_tests.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "15CBA015196EE56C005877BB"
BuildableName = "lua-game-controller-test iOS.app"
BlueprintName = "lua-game-controller-test iOS"
ReferencedContainer = "container:cocos2d_tests.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -585,7 +585,7 @@ public:
virtual JumpTo* clone() const override;
virtual JumpTo* reverse(void) const override;
private:
CC_CONSTRUCTOR_ACCESS:
JumpTo() {}
virtual ~JumpTo() {}
CC_DISALLOW_COPY_AND_ASSIGN(JumpTo);
@ -750,7 +750,7 @@ public:
virtual ScaleBy* clone() const override;
virtual ScaleBy* reverse(void) const override;
protected:
CC_CONSTRUCTOR_ACCESS:
ScaleBy() {}
virtual ~ScaleBy() {}
@ -842,7 +842,7 @@ public:
void setReverseAction(FadeTo* ac);
protected:
CC_CONSTRUCTOR_ACCESS:
FadeIn():_reverseAction(nullptr) {}
virtual ~FadeIn() {}
@ -869,7 +869,7 @@ public:
void setReverseAction(FadeTo* ac);
protected:
CC_CONSTRUCTOR_ACCESS:
FadeOut():_reverseAction(nullptr) {}
virtual ~FadeOut() {}
private:
@ -961,7 +961,7 @@ public:
virtual DelayTime* reverse() const override;
virtual DelayTime* clone() const override;
protected:
CC_CONSTRUCTOR_ACCESS:
DelayTime() {}
virtual ~DelayTime() {}

View File

@ -194,8 +194,8 @@ bool DrawNode::init()
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
/** listen the event that coming to foreground on Android */
auto listener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event){
/** listen the event that renderer was recreated on Android/WP8 */
this->init();
});

View File

@ -31,6 +31,7 @@
#include "base/CCEventDispatcher.h"
#include "base/CCEventType.h"
NS_CC_BEGIN
const int FontAtlas::CacheTextureWidth = 512;
@ -41,9 +42,9 @@ FontAtlas::FontAtlas(Font &theFont)
: _font(&theFont)
, _currentPageData(nullptr)
, _fontAscender(0)
, _toForegroundListener(nullptr)
, _toBackgroundListener(nullptr)
, _rendererRecreatedListener(nullptr)
, _antialiasEnabled(true)
, _rendererRecreate(false)
{
_font->retain();
@ -77,12 +78,12 @@ FontAtlas::FontAtlas(Font &theFont)
addTexture(texture,0);
texture->release();
#if CC_ENABLE_CACHE_TEXTURE_DATA
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
_toBackgroundListener = EventListenerCustom::create(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(FontAtlas::listenToBackground, this));
eventDispatcher->addEventListenerWithFixedPriority(_toBackgroundListener, 1);
_toForegroundListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(FontAtlas::listenToForeground, this));
eventDispatcher->addEventListenerWithFixedPriority(_toForegroundListener, 1);
_rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(FontAtlas::listenRendererRecreated, this));
eventDispatcher->addEventListenerWithFixedPriority(_rendererRecreatedListener, 1);
#endif
}
}
@ -91,19 +92,11 @@ FontAtlas::~FontAtlas()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
if (fontTTf)
if (fontTTf && _rendererRecreatedListener)
{
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
if (_toForegroundListener)
{
eventDispatcher->removeEventListener(_toForegroundListener);
_toForegroundListener = nullptr;
}
if (_toBackgroundListener)
{
eventDispatcher->removeEventListener(_toBackgroundListener);
_toBackgroundListener = nullptr;
}
eventDispatcher->removeEventListener(_rendererRecreatedListener);
_rendererRecreatedListener = nullptr;
}
#endif
@ -149,11 +142,10 @@ void FontAtlas::purgeTexturesAtlas()
}
}
void FontAtlas::listenToBackground(EventCustom *event)
void FontAtlas::listenRendererRecreated(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
if (fontTTf && _atlasTextures.size() > 1)
if (fontTTf)
{
for( auto &item: _atlasTextures)
{
@ -171,30 +163,12 @@ void FontAtlas::listenToBackground(EventCustom *event)
_currentPage = 0;
_currentPageOrigX = 0;
_currentPageOrigY = 0;
}
#endif
}
void FontAtlas::listenToForeground(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
if (fontTTf)
{
if (_currentPageOrigX == 0 && _currentPageOrigY == 0)
{
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
eventDispatcher->dispatchCustomEvent(EVENT_PURGE_TEXTURES,this);
}
else
{
auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
}
_rendererRecreate = true;
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
eventDispatcher->dispatchCustomEvent(EVENT_PURGE_TEXTURES,this);
_rendererRecreate = false;
}
#endif
}
void FontAtlas::addLetterDefinition(const FontLetterDefinition &letterDefinition)
@ -223,7 +197,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16String)
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
if(fontTTf == nullptr)
return false;
size_t length = utf16String.length();
float offsetAdjust = _letterPadding / 2;
@ -333,17 +307,25 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16String)
if(existNewLetter)
{
unsigned char *data = nullptr;
if(pixelFormat == Texture2D::PixelFormat::AI88)
if (_rendererRecreate)
{
data = _currentPageData + CacheTextureWidth * (int)startY * 2;
}
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
}
else
{
data = _currentPageData + CacheTextureWidth * (int)startY;
unsigned char *data = nullptr;
if(pixelFormat == Texture2D::PixelFormat::AI88)
{
data = _currentPageData + CacheTextureWidth * (int)startY * 2;
}
else
{
data = _currentPageData + CacheTextureWidth * (int)startY;
}
_atlasTextures[_currentPage]->updateWithData(data, 0, startY,
CacheTextureWidth, _currentPageOrigY - startY + _commonLineHeight);
}
_atlasTextures[_currentPage]->updateWithData(data, 0, startY,
CacheTextureWidth, _currentPageOrigY - startY + _commonLineHeight);
}
return true;
}

View File

@ -84,15 +84,10 @@ public:
Texture2D* getTexture(int slot);
const Font* getFont() const;
/** Listen "come to background" message, and clear the texture atlas.
It only has effect on Android.
/** listen the event that renderer was recreated on Android/WP8
It only has effect on Android and WP8.
*/
void listenToBackground(EventCustom *event);
/** Listen "come to foreground" message and restore the texture atlas.
It only has effect on Android.
*/
void listenToForeground(EventCustom *event);
void listenRendererRecreated(EventCustom *event);
/** Removes textures atlas.
It will purge the textures atlas and if multiple texture exist in the FontAtlas.
@ -129,9 +124,9 @@ private:
bool _makeDistanceMap;
int _fontAscender;
EventListenerCustom* _toBackgroundListener;
EventListenerCustom* _toForegroundListener;
EventListenerCustom* _rendererRecreatedListener;
bool _antialiasEnabled;
bool _rendererRecreate;
};

View File

@ -266,20 +266,13 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
setAnchorPoint(Vec2::ANCHOR_MIDDLE);
reset();
#if CC_ENABLE_CACHE_TEXTURE_DATA
auto toBackgroundListener = EventListenerCustom::create(EVENT_COME_TO_BACKGROUND, [this](EventCustom* event){
if (_fontAtlas && _currentLabelType == LabelType::TTF)
{
_batchNodes.clear();
_batchNodes.push_back(this);
Node::removeAllChildrenWithCleanup(true);
}
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(toBackgroundListener, this);
#endif
auto purgeTextureListener = EventListenerCustom::create(FontAtlas::EVENT_PURGE_TEXTURES, [this](EventCustom* event){
if (_fontAtlas && _currentLabelType == LabelType::TTF && event->getUserData() == _fontAtlas)
{
Node::removeAllChildrenWithCleanup(true);
_batchNodes.clear();
_batchNodes.push_back(this);
alignText();
}
});

View File

@ -133,6 +133,11 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
//CCLabelAtlas - Atlas generation
void LabelAtlas::updateAtlasValues()
{
if(_itemsPerRow == 0)
{
return;
}
ssize_t n = _string.length();
const unsigned char *s = (unsigned char*)_string.c_str();

View File

@ -884,7 +884,7 @@ LayerMultiplex * LayerMultiplex::create(Layer * layer, ...)
LayerMultiplex * LayerMultiplex::createWithLayer(Layer* layer)
{
return LayerMultiplex::create(layer, NULL);
return LayerMultiplex::create(layer, nullptr);
}
LayerMultiplex* LayerMultiplex::create()

View File

@ -25,7 +25,6 @@ THE SOFTWARE.
****************************************************************************/
#include "2d/CCMenu.h"
#include "base/CCDirector.h"
#include "CCApplication.h"
#include "base/CCTouch.h"
#include "CCStdC.h"
#include "base/CCEventListenerTouch.h"

View File

@ -839,6 +839,18 @@ MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler s
return ret;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MenuItemToggle * MenuItemToggle::createWithCallbackVA(const ccMenuCallback &callback, MenuItem* item, ...)
{
va_list args;
va_start(args, item);
MenuItemToggle *ret = new MenuItemToggle();
ret->initWithCallback(callback, item, args);
ret->autorelease();
va_end(args);
return ret;
}
#else
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, MenuItem* item, ...)
{
va_list args;
@ -849,6 +861,7 @@ MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callba
va_end(args);
return ret;
}
#endif
MenuItemToggle * MenuItemToggle::create()
{

View File

@ -478,7 +478,25 @@ public:
/** creates a menu item from a Array with a callable object */
static MenuItemToggle * createWithCallback(const ccMenuCallback& callback, const Vector<MenuItem*>& menuItems);
/** creates a menu item from a list of items with a callable object */
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported
typedef MenuItem* M;
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, m6, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, m6, m7, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, m6, m7, m8, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return createWithCallbackVA(callback, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }
// On WP8 for lists longer than 10 items, use createWithArray or variadicCreate with NULL as the last argument
static MenuItemToggle* createWithCallbackVA(const ccMenuCallback& callback, M item, ...);
#else
static MenuItemToggle* createWithCallback(const ccMenuCallback& callback, MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
#endif
/** creates a menu item with no target/selector and no items */
static MenuItemToggle* create();
/** creates a menu item with a item */

View File

@ -842,23 +842,13 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
size_t subStrStartPos = 0; // sub string start index
size_t subStrlength = length; // sub string length
// Starts with '/' or '//'?
bool searchFromRoot = false;
bool searchFromRootRecursive = false;
if (name[0] == '/')
// Starts with '//'?
bool searchRecursively = false;
if (length > 2 && name[0] == '/' && name[1] == '/')
{
if (length > 2 && name[1] == '/')
{
searchFromRootRecursive = true;
subStrStartPos = 2;
subStrlength -= 2;
}
else
{
searchFromRoot = true;
subStrStartPos = 1;
subStrlength -= 1;
}
searchRecursively = true;
subStrStartPos = 2;
subStrlength -= 2;
}
// End with '/..'?
@ -872,7 +862,7 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
subStrlength -= 3;
}
// Remove '/', '//', '/..' if exist
// Remove '//', '/..' if exist
std::string newName = name.substr(subStrStartPos, subStrlength);
if (searchFromParent)
@ -880,23 +870,11 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
newName.insert(0, "[[:alnum:]]+/");
}
if (searchFromRoot)
{
// name is '/xxx'
auto root = getScene();
if (root)
{
root->doEnumerate(newName, callback);
}
}
else if (searchFromRootRecursive)
if (searchRecursively)
{
// name is '//xxx'
auto root = getScene();
if (root)
{
doEnumerateRecursive(root, newName, callback);
}
doEnumerateRecursive(this, newName, callback);
}
else
{
@ -1305,6 +1283,9 @@ Mat4 Node::transform(const Mat4& parentTransform)
void Node::onEnter()
{
if (_onEnterCallback)
_onEnterCallback();
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
@ -1332,6 +1313,9 @@ void Node::onEnter()
void Node::onEnterTransitionDidFinish()
{
if (_onEnterTransitionDidFinishCallback)
_onEnterTransitionDidFinishCallback();
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
@ -1354,6 +1338,9 @@ void Node::onEnterTransitionDidFinish()
void Node::onExitTransitionDidStart()
{
if (_onExitTransitionDidStartCallback)
_onExitTransitionDidStartCallback();
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
@ -1375,6 +1362,9 @@ void Node::onExitTransitionDidStart()
void Node::onExit()
{
if (_onExitCallback)
_onExitCallback();
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
@ -1623,17 +1613,19 @@ const Mat4& Node::getNodeToParentTransform() const
bool needsSkewMatrix = ( _skewX || _skewY );
Vec2 anchorPoint;
anchorPoint.x = _anchorPointInPoints.x * _scaleX;
anchorPoint.y = _anchorPointInPoints.y * _scaleY;
// optimization:
// inline anchor point calculation if skew is not needed
// Adjusted transform calculation for rotational skew
if (! needsSkewMatrix && !_anchorPointInPoints.equals(Vec2::ZERO))
{
x += cy * -_anchorPointInPoints.x * _scaleX + -sx * -_anchorPointInPoints.y * _scaleY;
y += sy * -_anchorPointInPoints.x * _scaleX + cx * -_anchorPointInPoints.y * _scaleY;
x += cy * -anchorPoint.x + -sx * -anchorPoint.y;
y += sy * -anchorPoint.x + cx * -anchorPoint.y;
}
// Build Transform Matrix
// Adjusted transform calculation for rotational skew
float mat[] = {
@ -1644,6 +1636,11 @@ const Mat4& Node::getNodeToParentTransform() const
_transform.set(mat);
if(!_ignoreAnchorPointForPosition)
{
_transform.translate(anchorPoint.x, anchorPoint.y, 0);
}
// XXX
// FIX ME: Expensive operation.
// FIX ME: It should be done together with the rotationZ
@ -1658,6 +1655,11 @@ const Mat4& Node::getNodeToParentTransform() const
_transform = _transform * rotX;
}
if(!_ignoreAnchorPointForPosition)
{
_transform.translate(-anchorPoint.x, -anchorPoint.y, 0);
}
// XXX: Try to inline skew
// If skew is needed, apply skew and then anchor point
if (needsSkewMatrix)

View File

@ -714,23 +714,19 @@ public:
virtual Node* getChildByName(const std::string& name) const;
/** Search the children of the receiving node to perform processing for nodes which share a name.
*
* @param name The name to search for, supports c++11 regular expression
* @param name The name to search for, supports c++11 regular expression.
* Search syntax options:
* `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node.
* `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node
* and be performed recursively across the entire node tree.
* `//`: Can only be placed at the begin of the search string. This indicates that it will search recursively.
* `..`: The search should move up to the node's parent. Can only be placed at the end of string
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children.
*
* @code
* enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`.
* enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`.
* enumerateChildren("//MyName", ...): This searches the children recursively and matches any node with the name `MyName`.
* enumerateChildren("[[:alnum:]]+", ...): This search string matches every node of its children.
* enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`.
* enumerateChildren("A[[:digit:]]", ...): This searches the node's children and returns any child named `A0`, `A1`, ..., `A9`
* enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal`
* and whose parent is named `Abby`.
* enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose
* enumerateChildren("//Abby/Normal", ...): This searches recursively and returns any node whose name is `Normal` and whose
* parent is named `Abby`.
* @endcode
*
@ -1466,7 +1462,16 @@ public:
virtual void setOpacityModifyRGB(bool value) {CC_UNUSED_PARAM(value);}
virtual bool isOpacityModifyRGB() const { return false; };
void setOnEnterCallback(const std::function<void()>& callback) { _onEnterCallback = callback; }
const std::function<void()>& getOnEnterCallback() const { return _onEnterCallback; }
void setOnExitCallback(const std::function<void()>& callback) { _onExitCallback = callback; }
const std::function<void()>& getOnExitCallback() const { return _onExitCallback; }
void setonEnterTransitionDidFinishCallback(const std::function<void()>& callback) { _onEnterTransitionDidFinishCallback = callback; }
const std::function<void()>& getonEnterTransitionDidFinishCallback() const { return _onEnterTransitionDidFinishCallback; }
void setonExitTransitionDidStartCallback(const std::function<void()>& callback) { _onExitTransitionDidStartCallback = callback; }
const std::function<void()>& getonExitTransitionDidStartCallback() const { return _onExitTransitionDidStartCallback; }
CC_CONSTRUCTOR_ACCESS:
// Nodes should be created using create();
Node();
@ -1605,6 +1610,11 @@ protected:
static int s_globalOrderOfArrival;
std::function<void()> _onEnterCallback;
std::function<void()> _onExitCallback;
std::function<void()> _onEnterTransitionDidFinishCallback;
std::function<void()> _onExitTransitionDidStartCallback;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Node);

View File

@ -135,7 +135,7 @@ bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles)
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(ParticleSystemQuad::listenBackToForeground, this));
auto listener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(ParticleSystemQuad::listenRendererRecreated, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
@ -509,7 +509,7 @@ void ParticleSystemQuad::setupVBO()
CHECK_GL_ERROR_DEBUG();
}
void ParticleSystemQuad::listenBackToForeground(EventCustom* event)
void ParticleSystemQuad::listenRendererRecreated(EventCustom* event)
{
if (Configuration::getInstance()->supportsShareableVAO())
{

View File

@ -81,11 +81,11 @@ public:
*/
void setTextureWithRect(Texture2D *texture, const Rect& rect);
/** listen the event that coming to foreground on Android
/** listen the event that renderer was recreated on Android/WP8
* @js NA
* @lua NA
*/
void listenBackToForeground(EventCustom* event);
void listenRendererRecreated(EventCustom* event);
/**
* @js NA

View File

@ -85,6 +85,10 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity)
CCASSERT(capacity>=0, "Capacity must be >= 0");
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
if(tex->hasPremultipliedAlpha())
{
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
}
_textureAtlas = new TextureAtlas();
if (capacity == 0)

View File

@ -222,7 +222,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
<ClCompile Include="..\base\CCTouch.cpp" />
<ClCompile Include="..\base\ccTypes.cpp" />
<ClCompile Include="..\base\CCUserDefault.cpp" />
<ClCompile Include="..\base\CCUserDefaultAndroid.cpp" />
<ClCompile Include="..\base\ccUTF8.cpp" />
<ClCompile Include="..\base\ccUtils.cpp" />
<ClCompile Include="..\base\CCValue.cpp" />

View File

@ -353,7 +353,6 @@
<ClCompile Include="..\base\CCTouch.cpp" />
<ClCompile Include="..\base\ccTypes.cpp" />
<ClCompile Include="..\base\CCUserDefault.cpp" />
<ClCompile Include="..\base\CCUserDefaultAndroid.cpp" />
<ClCompile Include="..\base\ccUTF8.cpp" />
<ClCompile Include="..\base\ccUtils.cpp" />
<ClCompile Include="..\base\CCValue.cpp" />

View File

@ -280,7 +280,6 @@
<ClCompile Include="..\base\CCTouch.cpp" />
<ClCompile Include="..\base\ccTypes.cpp" />
<ClCompile Include="..\base\CCUserDefault.cpp" />
<ClCompile Include="..\base\CCUserDefaultAndroid.cpp" />
<ClCompile Include="..\base\ccUTF8.cpp" />
<ClCompile Include="..\base\ccUtils.cpp" />
<ClCompile Include="..\base\CCValue.cpp" />

View File

@ -7,7 +7,7 @@
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(EngineRoot)cocos\platform\wp8;$(EngineRoot)cocos\platform\winrt;$(EngineRoot)\external\winrt-specific\angle\include;$(EngineRoot)\external\curl\include\wp8;$(EngineRoot)\external\winrt-specific;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external;$(EngineRoot)cocos\editor-support;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(GeneratedFilesDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(EngineRoot)cocos\platform\wp8;$(EngineRoot)cocos\platform\winrt;$(EngineRoot)\external\winrt-specific\angle\include;$(EngineRoot)\external\curl\include\wp8;$(EngineRoot)\external\winrt-specific;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external;$(EngineRoot)cocos\editor-support;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\wp8-specific\zlib\include;$(GeneratedFilesDir)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_VARIADIC_MAX=10;NOMINMAX;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsWinRT>true</CompileAsWinRT>
<MultiProcessorCompilation>true</MultiProcessorCompilation>

View File

@ -66,12 +66,12 @@ Animate3D* Animate3D::clone() const
auto animate = const_cast<Animate3D*>(this);
auto copy = Animate3D::create(animate->_animation);
copy->_speed = _speed;
copy->_absSpeed = _absSpeed;
copy->_weight = _weight;
copy->_elapsed = _elapsed;
copy->_start = _start;
copy->_last = _last;
copy->_playBack = _playBack;
copy->_playReverse = _playReverse;
copy->setDuration(animate->getDuration());
return copy;
@ -81,7 +81,7 @@ Animate3D* Animate3D::clone() const
Animate3D* Animate3D::reverse() const
{
auto animate = clone();
animate->_playBack = !animate->_playBack;
animate->_playReverse = !animate->_playReverse;
return animate;
}
@ -112,16 +112,16 @@ void Animate3D::startWithTarget(Node *target)
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
void Animate3D::step(float dt)
{
ActionInterval::step(dt * _speed);
ActionInterval::step(dt * _absSpeed);
}
void Animate3D::update(float t)
{
if (_target)
if (_target && _weight > 0.f)
{
float transDst[3], rotDst[4], scaleDst[3];
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
if (_playBack)
if (_playReverse)
t = 1 - t;
t = _start + t * _last;
@ -149,13 +149,29 @@ void Animate3D::update(float t)
}
float Animate3D::getSpeed() const
{
return _playReverse ? -_absSpeed : _absSpeed;
}
void Animate3D::setSpeed(float speed)
{
_absSpeed = fabsf(speed);
_playReverse = speed < 0;
}
void Animate3D::setWeight(float weight)
{
CCASSERT(weight >= 0.0f, "invalid weight");
_weight = fabsf(weight);
}
Animate3D::Animate3D()
: _speed(1)
: _absSpeed(1.f)
, _weight(1.f)
, _start(0.f)
, _last(1.f)
, _animation(nullptr)
, _playBack(false)
, _playReverse(false)
{
}

View File

@ -32,12 +32,13 @@
#include "base/ccMacros.h"
#include "base/CCRef.h"
#include "base/ccTypes.h"
#include "base/CCPlatformMacros.h"
#include "2d/CCActionInterval.h"
NS_CC_BEGIN
class Animation3D;
class Bone;
class Bone3D;
/**
* Animate3D, Animates a Sprite3D given with an Animation3D
*/
@ -66,17 +67,17 @@ public:
virtual void update(float t) override;
/**get & set speed */
float getSpeed() const { return _speed; }
void setSpeed(float speed) { _speed = speed; }
/**get & set speed, negative speed means playing reverse */
float getSpeed() const;
void setSpeed(float speed);
/**get & set blend weight*/
/**get & set blend weight, weight must positive*/
float getWeight() const { return _weight; }
void setWeight(float weight) { _weight = weight; }
void setWeight(float weight);
/**get & set play back*/
bool getPlayBack() const { return _playBack; }
void setPlayBack(bool playBack) { _playBack = playBack; }
/**get & set play reverse, these are deprecated, use set negative speed instead*/
CC_DEPRECATED_ATTRIBUTE bool getPlayBack() const { return _playReverse; }
CC_DEPRECATED_ATTRIBUTE void setPlayBack(bool reverse) { _playReverse = reverse; }
CC_CONSTRUCTOR_ACCESS:
@ -86,12 +87,12 @@ CC_CONSTRUCTOR_ACCESS:
protected:
Animation3D* _animation; //animation data
float _speed; //playing speed
float _absSpeed; //playing speed
float _weight; //blend weight
float _start; //start time 0 - 1, used to generate sub Animate3D
float _last; //last time 0 - 1, used to generate sub Animate3D
bool _playBack; // is playing back
std::map<Bone*, Animation3D::Curve*> _boneCurves; //weak ref
bool _playReverse; // is playing reverse
std::map<Bone3D*, Animation3D::Curve*> _boneCurves; //weak ref
};
NS_CC_END

View File

@ -30,7 +30,7 @@
NS_CC_BEGIN
Animation3D* Animation3D::getOrCreate(const std::string& fileName, const std::string& animationName)
Animation3D* Animation3D::create(const std::string& fileName, const std::string& animationName)
{
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string key = fullPath + "#" + animationName;

View File

@ -59,8 +59,10 @@ public:
~Curve();
};
/**read all animation or only the animation with given animationName? animationName == "" read all.*/
static Animation3D* getOrCreate(const std::string& filename, const std::string& animationName = "");
/**read all animation or only the animation with given animationName? animationName == "" read the first.*/
static Animation3D* create(const std::string& filename, const std::string& animationName = "");
CC_DEPRECATED_ATTRIBUTE static Animation3D* getOrCreate(const std::string& filename, const std::string& animationName = ""){ return create(filename, animationName); }
/**get duration*/
float getDuration() const { return _duration; }

View File

@ -447,8 +447,7 @@ bool Bundle3D::loadBinary(const std::string& path)
return false;
}
// Create bundle reader
//CC_SAFE_DELETE(_bundleReader);
// Initialise bundle reader
_binaryReader.init( (char*)_binaryBuffer->getBytes(), _binaryBuffer->getSize() );
// Read identifier info
@ -463,20 +462,23 @@ bool Bundle3D::loadBinary(const std::string& path)
// Read version
unsigned char ver[2];
if (_binaryReader.read(ver, 1, 2) == 2)
{
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (_binaryReader.read(ver, 1, 2)!= 2){
CCLOG("Failed to read version:");
return false;
}
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
// Read ref table size
if (_binaryReader.read(&_referenceCount, 4, 1) != 1)
@ -766,17 +768,37 @@ bool Bundle3D::loadAnimationDataBinary(Animation3DData* animationdata)
GLenum Bundle3D::parseGLType(const std::string& str)
{
if (str == "GL_FLOAT")
if (str == "GL_BYTE")
{
return GL_FLOAT;
return GL_BYTE;
}
else if(str == "GL_UNSIGNED_BYTE")
{
return GL_UNSIGNED_BYTE;
}
else if(str == "GL_SHORT")
{
return GL_SHORT;
}
else if(str == "GL_UNSIGNED_SHORT")
{
return GL_UNSIGNED_SHORT;
}
else if(str == "GL_INT")
{
return GL_INT;
}
else if (str == "GL_UNSIGNED_INT")
{
return GL_UNSIGNED_INT;
}
else if (str == "GL_FLOAT")
{
return GL_FLOAT;
}
else
{
assert(0);
CCASSERT(false, "Wrong GL type");
return 0;
}
}

View File

@ -5,7 +5,7 @@ NS_CC_BEGIN
BundleReader::BundleReader()
{
m_buffer = NULL;
m_buffer = nullptr;
m_position = 0;
m_length = 0;
};
@ -65,7 +65,7 @@ char* BundleReader::readLine(int num,char* line)
char* p = line;
char c;
ssize_t readNum = 0;
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position<(long int)m_length)
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position < m_length)
{
*p = c;
p++;
@ -91,7 +91,7 @@ ssize_t BundleReader::length()
return m_length;
}
long int BundleReader::tell()
ssize_t BundleReader::tell()
{
if (!m_buffer)
return -1;
@ -123,7 +123,7 @@ bool BundleReader::seek(long int offset, int origin)
bool BundleReader::rewind()
{
if (m_buffer != NULL)
if (m_buffer != nullptr)
{
m_position = 0;
return true;

View File

@ -112,7 +112,7 @@ public:
bool readMatrix(float* m);
private:
long int m_position;
ssize_t m_position;
ssize_t m_length;
char* m_buffer;
};
@ -136,6 +136,7 @@ inline bool BundleReader::readArray(unsigned int *length, std::vector<T> *values
{
return false;
}
if (*length > 0 && values)
{
values->resize(*length);

View File

@ -125,7 +125,7 @@ bool RenderMeshData::init(const std::vector<float>& positions,
return true;
}
bool RenderMeshData::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
bool RenderMeshData::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, const std::vector<MeshVertexAttrib>& attribs)
{
_vertexs = vertices;
_indices = indices;
@ -174,10 +174,10 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
return nullptr;
}
Mesh* Mesh::create(const std::vector<float> &vertices, int vertexSizeInFloat, const std::vector<unsigned short> &indices, int numIndex, const std::vector<MeshVertexAttrib> &attribs, int attribCount)
Mesh* Mesh::create(const std::vector<float> &vertices, int vertexSizeInFloat, const std::vector<unsigned short> &indices, const std::vector<MeshVertexAttrib> &attribs)
{
auto mesh = new Mesh();
if (mesh && mesh->init(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount))
if (mesh && mesh->init(vertices, vertexSizeInFloat, indices, attribs))
{
mesh->autorelease();
return mesh;
@ -192,17 +192,17 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
if (!bRet)
return false;
restore();
buildBuffer();
return true;
}
bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, const std::vector<MeshVertexAttrib>& attribs)
{
bool bRet = _renderdata.init(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount);
bool bRet = _renderdata.init(vertices, vertexSizeInFloat, indices, attribs);
if (!bRet)
return false;
restore();
buildBuffer();
return true;
}
@ -242,20 +242,20 @@ void Mesh::buildBuffer()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
unsigned int indexSize = 2;
IndexFormat indexformat = IndexFormat::INDEX16;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * _renderdata._indices.size(), &_renderdata._indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
_primitiveType = PrimitiveType::TRIANGLES;
_indexFormat = indexformat;
_indexFormat = IndexFormat::INDEX16;
_indexCount = _renderdata._indices.size();
}
void Mesh::restore()
{
cleanAndFreeBuffers();
_vertexBuffer = 0;
_indexBuffer = 0;
buildBuffer();
}
@ -322,22 +322,22 @@ void MeshCache::removeUnusedMesh()
MeshCache::MeshCache()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// listen the event when app go to foreground
_backToForegroundlistener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(MeshCache::listenBackToForeground, this));
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
// listen the event that renderer was recreated on Android/WP8
_rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(MeshCache::listenRendererRecreated, this));
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_rendererRecreatedListener, -1);
#endif
}
MeshCache::~MeshCache()
{
removeAllMeshes();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundlistener);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
Director::getInstance()->getEventDispatcher()->removeEventListener(_rendererRecreatedListener);
#endif
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void MeshCache::listenBackToForeground(EventCustom* event)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
void MeshCache::listenRendererRecreated(EventCustom* event)
{
for (auto iter = _meshes.begin(); iter != _meshes.end(); ++iter)
{

View File

@ -49,7 +49,7 @@ public:
}
bool hasVertexAttrib(int attrib);
bool init(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, const std::vector<MeshVertexAttrib>& attribs);
protected:
@ -90,7 +90,10 @@ public:
static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
/**create mesh with vertex attributes*/
static Mesh* create(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
CC_DEPRECATED_ATTRIBUTE static Mesh* create(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount) { return create(vertices, vertexSizeInFloat, indices, attribs); }
/**create mesh with vertex attributes*/
static Mesh* create(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, const std::vector<MeshVertexAttrib>& attribs);
/**get vertex buffer*/
inline GLuint getVertexBuffer() const { return _vertexBuffer; }
@ -124,7 +127,7 @@ CC_CONSTRUCTOR_ACCESS:
bool init(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
/**init mesh*/
bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, const std::vector<MeshVertexAttrib>& attribs);
/**build buffer*/
void buildBuffer();
@ -163,8 +166,8 @@ public:
/**remove unused meshes*/
void removeUnusedMesh();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void listenBackToForeground(EventCustom* event);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
void listenRendererRecreated(EventCustom* event);
#endif
CC_CONSTRUCTOR_ACCESS:
@ -178,8 +181,8 @@ protected:
std::unordered_map<std::string, Mesh*> _meshes; //cached meshes
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
EventListenerCustom* _backToForegroundlistener;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
EventListenerCustom* _rendererRecreatedListener;
#endif
};

View File

@ -36,22 +36,22 @@ NS_CC_BEGIN
*
* @param m C3DMatrix representing the inverse bind pose for this Bone.
*/
void Bone::setInverseBindPose(const Mat4& m)
void Bone3D::setInverseBindPose(const Mat4& m)
{
_invBindPose = m;
}
const Mat4& Bone::getInverseBindPose()
const Mat4& Bone3D::getInverseBindPose()
{
return _invBindPose;
}
void Bone::setOriPose(const Mat4& m)
void Bone3D::setOriPose(const Mat4& m)
{
_oriPose = m;
}
void Bone::resetPose()
void Bone3D::resetPose()
{
_local =_oriPose;
@ -60,7 +60,7 @@ void Bone::resetPose()
}
}
void Bone::setWorldMatDirty(bool dirty)
void Bone3D::setWorldMatDirty(bool dirty)
{
_worldDirty = dirty;
for (auto it : _children) {
@ -69,7 +69,7 @@ void Bone::setWorldMatDirty(bool dirty)
}
//update own world matrix and children's
void Bone::updateWorldMat()
void Bone3D::updateWorldMat()
{
getWorldMat();
for (auto itor : _children) {
@ -77,7 +77,7 @@ void Bone::updateWorldMat()
}
}
const Mat4& Bone::getWorldMat()
const Mat4& Bone3D::getWorldMat()
{
if (_worldDirty)
{
@ -95,7 +95,7 @@ const Mat4& Bone::getWorldMat()
return _world;
}
void Bone::setAnimationValue(float* trans, float* rot, float* scale, void* tag, float weight)
void Bone3D::setAnimationValue(float* trans, float* rot, float* scale, void* tag, float weight)
{
for (auto& it : _blendStates) {
if (it.tag == tag)
@ -124,7 +124,7 @@ void Bone::setAnimationValue(float* trans, float* rot, float* scale, void* tag,
_blendStates.push_back(state);
}
void Bone::clearBoneBlendState()
void Bone3D::clearBoneBlendState()
{
_blendStates.clear();
for (auto it : _children) {
@ -135,14 +135,14 @@ void Bone::clearBoneBlendState()
/**
* Creates C3DBone.
*/
Bone* Bone::create(const std::string& id)
Bone3D* Bone3D::create(const std::string& id)
{
auto bone = new Bone(id);
auto bone = new Bone3D(id);
bone->autorelease();
return bone;
}
void Bone::updateJointMatrix(Vec4* matrixPalette)
void Bone3D::updateJointMatrix(Vec4* matrixPalette)
{
{
static Mat4 t;
@ -154,37 +154,37 @@ void Bone::updateJointMatrix(Vec4* matrixPalette)
}
}
Bone* Bone::getParentBone()
Bone3D* Bone3D::getParentBone()
{
return _parent;
}
ssize_t Bone::getChildBoneCount() const
ssize_t Bone3D::getChildBoneCount() const
{
return _children.size();
}
Bone* Bone::getChildBoneByIndex(int index)
Bone3D* Bone3D::getChildBoneByIndex(int index)
{
return _children.at(index);
}
void Bone::addChildBone(Bone* bone)
void Bone3D::addChildBone(Bone3D* bone)
{
if (_children.find(bone) == _children.end())
_children.pushBack(bone);
}
void Bone::removeChildBoneByIndex(int index)
void Bone3D::removeChildBoneByIndex(int index)
{
_children.erase(index);
}
void Bone::removeChildBone(Bone* bone)
void Bone3D::removeChildBone(Bone3D* bone)
{
_children.eraseObject(bone);
}
void Bone::removeAllChildBone()
void Bone3D::removeAllChildBone()
{
_children.clear();
}
Bone::Bone(const std::string& id)
Bone3D::Bone3D(const std::string& id)
: _name(id)
, _parent(nullptr)
, _worldDirty(true)
@ -192,12 +192,12 @@ Bone::Bone(const std::string& id)
}
Bone::~Bone()
Bone3D::~Bone3D()
{
removeAllChildBone();
}
void Bone::updateLocalMat()
void Bone3D::updateLocalMat()
{
if (_blendStates.size())
{
@ -299,13 +299,13 @@ bool MeshSkin::initFromSkinData(const SkinData& skindata)
{
ssize_t i = 0;
for (; i < skindata.skinBoneNames.size(); i++) {
auto bone = Bone::create(skindata.skinBoneNames[i]);
auto bone = Bone3D::create(skindata.skinBoneNames[i]);
bone->_invBindPose = skindata.inverseBindPoseMatrices[i];
bone->setOriPose(skindata.skinBoneOriginMatrices[i]);
addSkinBone(bone);
}
for (i = 0; i < skindata.nodeBoneNames.size(); i++) {
auto bone = Bone::create(skindata.nodeBoneNames[i]);
auto bone = Bone3D::create(skindata.nodeBoneNames[i]);
bone->setOriPose(skindata.nodeBoneOriginMatrices[i]);
addNodeBone(bone);
}
@ -330,7 +330,7 @@ ssize_t MeshSkin::getBoneCount() const
}
//get bone
Bone* MeshSkin::getBoneByIndex(unsigned int index) const
Bone3D* MeshSkin::getBoneByIndex(unsigned int index) const
{
if (index < _skinBones.size())
return _skinBones.at(index);
@ -340,7 +340,7 @@ Bone* MeshSkin::getBoneByIndex(unsigned int index) const
return nullptr;
}
Bone* MeshSkin::getBoneByName(const std::string& id) const
Bone3D* MeshSkin::getBoneByName(const std::string& id) const
{
//search from skin bones
for (auto it : _skinBones) {
@ -355,18 +355,18 @@ Bone* MeshSkin::getBoneByName(const std::string& id) const
return nullptr;
}
Bone* MeshSkin::getRootBone() const
Bone3D* MeshSkin::getRootBone() const
{
return _rootBone;
}
void MeshSkin::setRootBone(Bone* joint)
void MeshSkin::setRootBone(Bone3D* joint)
{
CC_SAFE_RETAIN(joint);
CC_SAFE_RELEASE(_rootBone);
_rootBone = joint;
}
int MeshSkin::getBoneIndex(Bone* bone) const
int MeshSkin::getBoneIndex(Bone3D* bone) const
{
int i = 0;
for (; i < _skinBones.size(); i++) {
@ -419,12 +419,12 @@ void MeshSkin::removeAllBones()
CC_SAFE_RELEASE(_rootBone);
}
void MeshSkin::addSkinBone(Bone* bone)
void MeshSkin::addSkinBone(Bone3D* bone)
{
_skinBones.pushBack(bone);
}
void MeshSkin::addNodeBone(Bone* bone)
void MeshSkin::addNodeBone(Bone3D* bone)
{
_nodeBones.pushBack(bone);
}

View File

@ -40,7 +40,7 @@ NS_CC_BEGIN
/**
* Defines a basic hierachial structure of transformation spaces.
*/
class Bone : public Ref
class Bone3D : public Ref
{
friend class MeshSkin;
public:
@ -76,7 +76,7 @@ public:
/**
* Creates C3DBone.
*/
static Bone* create(const std::string& id);
static Bone3D* create(const std::string& id);
/**
* Sets the inverse bind pose matrix.
@ -105,17 +105,17 @@ public:
void updateJointMatrix(Vec4* matrixPalette);
/**bone tree, we do not inherit from Node, Node has too many properties that we do not need. A clean Node is needed.*/
Bone* getParentBone();
Bone3D* getParentBone();
/**get child bone count*/
ssize_t getChildBoneCount() const;
/**get child bone by index*/
Bone* getChildBoneByIndex(int index);
Bone3D* getChildBoneByIndex(int index);
/**add child bone*/
void addChildBone(Bone* bone);
void addChildBone(Bone3D* bone);
/**remove child bone by index*/
void removeChildBoneByIndex(int index);
/**remove child bone*/
void removeChildBone(Bone* bone);
void removeChildBone(Bone3D* bone);
/**remove all child bone*/
void removeAllChildBone();
@ -143,12 +143,12 @@ protected:
/**
* Constructor.
*/
Bone(const std::string& id);
Bone3D(const std::string& id);
/**
* Destructor.
*/
virtual ~Bone();
virtual ~Bone3D();
/**
* Update local matrix
@ -166,9 +166,9 @@ protected:
Mat4 _oriPose; //original bone pose
Bone* _parent; //parent bone
Bone3D* _parent; //parent bone
Vector<Bone*> _children;
Vector<Bone3D*> _children;
bool _worldDirty;
Mat4 _world;
@ -193,15 +193,15 @@ public:
ssize_t getBoneCount() const;
/**get bone*/
Bone* getBoneByIndex(unsigned int index) const;
Bone* getBoneByName(const std::string& id) const;
Bone3D* getBoneByIndex(unsigned int index) const;
Bone3D* getBoneByName(const std::string& id) const;
/**get & set root bone*/
Bone* getRootBone() const;
void setRootBone(Bone* bone);
Bone3D* getRootBone() const;
void setRootBone(Bone3D* bone);
/**get bone index*/
int getBoneIndex(Bone* bone) const;
int getBoneIndex(Bone3D* bone) const;
/**compute matrix palette used by gpu skin*/
Vec4* getMatrixPalette();
@ -225,17 +225,17 @@ CC_CONSTRUCTOR_ACCESS:
void removeAllBones();
/**add skin bone*/
void addSkinBone(Bone* bone);
void addSkinBone(Bone3D* bone);
/**add Node bone*/
void addNodeBone(Bone* bone);
void addNodeBone(Bone3D* bone);
protected:
Vector<Bone*> _skinBones; // bones with skin
Vector<Bone*> _nodeBones; //bones without skin, only used to compute transform of children
Vector<Bone3D*> _skinBones; // bones with skin
Vector<Bone3D*> _nodeBones; //bones without skin, only used to compute transform of children
Bone* _rootBone;
Bone3D* _rootBone;
// Pointer to the array of palette matrices.
// This array is passed to the vertex shader as a uniform.

View File

@ -193,7 +193,7 @@ bool Sprite3D::loadFromC3x(const std::string& path)
return false;
}
_mesh = Mesh::create(meshdata.vertex, meshdata.vertexSizeInFloat, meshdata.indices, meshdata.numIndex, meshdata.attribs, meshdata.attribCount);
_mesh = Mesh::create(meshdata.vertex, meshdata.vertexSizeInFloat, meshdata.indices, meshdata.attribs);
CC_SAFE_RETAIN(_mesh);
_skin = MeshSkin::create(fullPath, "");
@ -342,7 +342,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
_meshCommand.setDepthTestEnabled(true);
if (_skin)
{
_meshCommand.setMatrixPaletteSize(_skin->getMatrixPaletteSize());
_meshCommand.setMatrixPaletteSize((int)_skin->getMatrixPaletteSize());
_meshCommand.setMatrixPalette(_skin->getMatrixPalette());
}
//support tint and fade

View File

@ -141,13 +141,8 @@ base/ccUTF8.cpp \
base/ccUtils.cpp \
base/etc1.cpp \
base/s3tc.cpp \
base/CCController.cpp \
base/CCController-android.cpp \
base/CCControllerAxisInput.cpp \
base/CCControllerButtonInput.cpp \
base/CCControllerDirectionPad.cpp \
base/CCControllerElement.cpp \
base/CCControllerThumbstick.cpp \
base/CCGamepad.cpp \
base/ObjectFactory.cpp \
renderer/CCBatchCommand.cpp \
renderer/CCCustomCommand.cpp \

View File

@ -222,7 +222,7 @@ static void _log(const char *format, va_list args)
WCHAR wszBuf[MAX_LOG_LENGTH] = {0};
MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf));
OutputDebugStringW(wszBuf);
WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, buf, sizeof(buf), NULL, FALSE);
WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, buf, sizeof(buf), nullptr, FALSE);
printf("%s", buf);
fflush(stdout);
#else
@ -337,7 +337,7 @@ bool Console::listenOnTCP(int port)
#endif
#endif
if ( (n = getaddrinfo(NULL, serv, &hints, &res)) != 0) {
if ( (n = getaddrinfo(nullptr, serv, &hints, &res)) != 0) {
fprintf(stderr,"net_listen error for %s: %s", serv, gai_strerror(n));
return false;
}
@ -359,9 +359,9 @@ bool Console::listenOnTCP(int port)
#else
close(listenfd);
#endif
} while ( (res = res->ai_next) != NULL);
} while ( (res = res->ai_next) != nullptr);
if (res == NULL) {
if (res == nullptr) {
perror("net_listen:");
freeaddrinfo(ressave);
return false;
@ -372,14 +372,14 @@ bool Console::listenOnTCP(int port)
if (res->ai_family == AF_INET) {
char buf[INET_ADDRSTRLEN] = "";
struct sockaddr_in *sin = (struct sockaddr_in*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != NULL )
if( inet_ntop(res->ai_family, &sin->sin_addr, buf, sizeof(buf)) != nullptr )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin_port));
else
perror("inet_ntop");
} else if (res->ai_family == AF_INET6) {
char buf[INET6_ADDRSTRLEN] = "";
struct sockaddr_in6 *sin = (struct sockaddr_in6*) res->ai_addr;
if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != NULL )
if( inet_ntop(res->ai_family, &sin->sin6_addr, buf, sizeof(buf)) != nullptr )
cocos2d::log("Console: listening on %s : %d", buf, ntohs(sin->sin6_port));
else
perror("inet_ntop");
@ -1042,7 +1042,7 @@ void Console::loop()
copy_set = _read_set;
timeout_copy = timeout;
int nready = select(_maxfd+1, &copy_set, NULL, NULL, &timeout_copy);
int nready = select(_maxfd+1, &copy_set, nullptr, nullptr, &timeout_copy);
if( nready == -1 )
{

View File

@ -47,6 +47,7 @@ typedef SSIZE_T ssize_t;
#include <mutex>
#include <stdarg.h>
#include "base/CCRef.h"
#include "base/ccMacros.h"
#include "base/CCPlatformMacros.h"
@ -73,6 +74,7 @@ void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2);
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
class CC_DLL Console
: public Ref
{
public:
struct Command {

View File

@ -26,258 +26,94 @@
#include "CCController.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "CCGamepad.h"
#include "CCControllerDirectionPad.h"
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "CCControllerThumbstick.h"
#include <functional>
#include "ccMacros.h"
#include "CCEventDispatcher.h"
#include "CCEventController.h"
#include "CCEventListenerController.h"
#include "CCDirector.h"
#include "jni/JniHelper.h"
#include "base/CCEventController.h"
NS_CC_BEGIN
enum class AndroidControllerCode
{
THUMBSTICK_LEFT_X = 100,
THUMBSTICK_LEFT_Y = 101,
THUMBSTICK_RIGHT_X = 102,
THUMBSTICK_RIGHT_Y = 103,
BUTTON_A = 110,
BUTTON_B = 111,
BUTTON_C = 112,
BUTTON_X = 113,
BUTTON_Y = 114,
BUTTON_Z = 115,
BUTTON_LEFT_SHOULDER = 120,
BUTTON_RIGHT_SHOULDER = 121,
BUTTON_LEFT_TRIGGER = 122,
BUTTON_RIGHT_TRIGGER = 123,
BUTTON_DPAD_UP = 130,
BUTTON_DPAD_DOWN = 131,
BUTTON_DPAD_LEFT = 132,
BUTTON_DPAD_RIGHT = 133,
BUTTON_DPAD_CENTER = 134,
BUTTON_LEFT_THUMBSTICK = 140,
BUTTON_RIGHT_THUMBSTICK = 141,
BUTTON_START = 150,
BUTTON_SELECT = 151,
};
class ControllerImpl
{
public:
ControllerImpl(Controller* controller)
: _controller(controller)
, _controllerID(-1)
{
}
static std::vector<Controller*>::iterator findController(const std::string& vendorName, int controllerID)
static std::vector<Controller*>::iterator findController(const std::string& deviceName, int deviceId)
{
auto iter = std::find_if(Controller::_controllers.begin(), Controller::_controllers.end(), [&](Controller* controller){
return (vendorName == controller->getVendorName()) && (controllerID == controller->_impl->_controllerID);
auto iter = std::find_if(Controller::s_allController.begin(), Controller::s_allController.end(), [&](Controller* controller){
return (deviceName == controller->_deviceName) && (deviceId == controller->_deviceId);
});
return iter;
}
static void onConnected(const std::string& vendorName, int controllerID)
static void onConnected(const std::string& deviceName, int deviceId)
{
// Check whether the controller is already connected.
auto iter = findController(vendorName, controllerID);
if (iter != Controller::_controllers.end())
CCLOG("onConnected %s,%d", deviceName.c_str(),deviceId);
auto iter = findController(deviceName, deviceId);
if (iter != Controller::s_allController.end())
return;
// It's a new controller being connected.
auto controller = new cocos2d::Controller();
controller->_vendorName = vendorName;
Controller::_controllers.push_back(controller);
controller->_impl->_controllerID = controllerID;
EventController evt(EventController::ControllerEventType::CONNECTION, controller, true);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
controller->_deviceId = deviceId;
controller->_deviceName = deviceName;
Controller::s_allController.push_back(controller);
controller->onConnected();
}
static void onDisconnected(const std::string& vendorName, int controllerID)
static void onDisconnected(const std::string& deviceName, int deviceId)
{
auto iter = findController(vendorName, controllerID);
if (iter == Controller::_controllers.end())
CCLOG("onDisconnected %s,%d", deviceName.c_str(),deviceId);
auto iter = findController(deviceName, deviceId);
if (iter == Controller::s_allController.end())
{
CCLOGERROR("Could not find the controller!");
return;
}
EventController evt(EventController::ControllerEventType::CONNECTION, *iter, false);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
Controller::_controllers.erase(iter);
(*iter)->onDisconnected();
Controller::s_allController.erase(iter);
}
void sendEventButton(ControllerButtonInput* button, bool isPressed, float value, bool isAnalog)
static void onButtonEvent(const std::string& deviceName, int deviceId, int keyCode, bool isPressed, float value, bool isAnalog)
{
button->setPressed(isPressed);
button->setValue(value);
button->setAnalog(isAnalog);
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, _controller, button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
auto iter = findController(deviceName, deviceId);
if (iter == Controller::s_allController.end())
{
CCLOG("onButtonEvent:connect new controller.");
onConnected(deviceName, deviceId);
iter = findController(deviceName, deviceId);
}
(*iter)->onButtonEvent(keyCode, isPressed, value, isAnalog);
}
void sendEventAxis(ControllerAxisInput* axis, float value, bool isAnalog)
static void onAxisEvent(const std::string& deviceName, int deviceId, int axisCode, float value, bool isAnalog)
{
axis->setValue(value);
axis->setAnalog(isAnalog);
EventController evt(EventController::ControllerEventType::AXIS_STATUS_CHANGED, _controller, axis);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
}
static void onButtonEvent(const std::string& vendorName, int controllerID, AndroidControllerCode btnCode, bool isPressed, float value, bool isAnalog)
{
auto iter = findController(vendorName, controllerID);
if (iter == Controller::_controllers.end())
auto iter = findController(deviceName, deviceId);
if (iter == Controller::s_allController.end())
{
onConnected(vendorName, controllerID);
iter = findController(vendorName, controllerID);
}
auto gamepad = (*iter)->getGamepad();
auto thiz = (*iter)->getImpl();
switch(btnCode)
{
case AndroidControllerCode::BUTTON_A:
{
thiz->sendEventButton(gamepad->getButtonA(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_B:
{
thiz->sendEventButton(gamepad->getButtonB(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_X:
{
thiz->sendEventButton(gamepad->getButtonX(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_Y:
{
thiz->sendEventButton(gamepad->getButtonY(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_LEFT_SHOULDER:
{
thiz->sendEventButton(gamepad->getLeftShoulder(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_RIGHT_SHOULDER:
{
thiz->sendEventButton(gamepad->getRightShoulder(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_LEFT_TRIGGER:
{
thiz->sendEventButton(gamepad->getLeftTrigger(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_RIGHT_TRIGGER:
{
thiz->sendEventButton(gamepad->getRightTrigger(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_DPAD_UP:
{
thiz->sendEventButton(gamepad->getDirectionPad()->getUp(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_DPAD_DOWN:
{
thiz->sendEventButton(gamepad->getDirectionPad()->getDown(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_DPAD_LEFT:
{
thiz->sendEventButton(gamepad->getDirectionPad()->getLeft(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_DPAD_RIGHT:
{
thiz->sendEventButton(gamepad->getDirectionPad()->getRight(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_START:
{
thiz->sendEventButton(gamepad->getButtonStart(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_SELECT:
{
thiz->sendEventButton(gamepad->getButtonSelect(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_LEFT_THUMBSTICK:
{
thiz->sendEventButton(gamepad->getLeftThumbstick()->getButton(), isPressed, value, isAnalog);
}
break;
case AndroidControllerCode::BUTTON_RIGHT_THUMBSTICK:
{
thiz->sendEventButton(gamepad->getRightThumbstick()->getButton(), isPressed, value, isAnalog);
}
break;
default:
// CCASSERT(false, "Invalid controller button code!");
break;
}
}
static void onAxisEvent(const std::string& vendorName, int controllerID, AndroidControllerCode axisCode, float value, bool isAnalog)
{
// log("vendorName: %s, controller id: %d, axis: %d, value: %f", vendorName.c_str(), controllerID, axisCode, value);
auto iter = findController(vendorName, controllerID);
if (iter == Controller::_controllers.end())
{
onConnected(vendorName, controllerID);
iter = findController(vendorName, controllerID);
}
auto gamepad = (*iter)->getGamepad();
auto thiz = (*iter)->getImpl();
switch (axisCode)
{
case AndroidControllerCode::THUMBSTICK_LEFT_X:
thiz->sendEventAxis(gamepad->getLeftThumbstick()->getAxisX(), value, isAnalog);
break;
case AndroidControllerCode::THUMBSTICK_LEFT_Y:
thiz->sendEventAxis(gamepad->getLeftThumbstick()->getAxisY(), value, isAnalog);
break;
case AndroidControllerCode::THUMBSTICK_RIGHT_X:
thiz->sendEventAxis(gamepad->getRightThumbstick()->getAxisX(), value, isAnalog);
break;
case AndroidControllerCode::THUMBSTICK_RIGHT_Y:
thiz->sendEventAxis(gamepad->getRightThumbstick()->getAxisY(), value, isAnalog);
break;
default:
CCASSERT(false, "Invalid controller axis code!");
break;
CCLOG("onAxisEvent:connect new controller.");
onConnected(deviceName, deviceId);
iter = findController(deviceName, deviceId);
}
(*iter)->onAxisEvent(axisCode, value, isAnalog);
}
private:
Controller* _controller;
int _controllerID;
};
std::vector<Controller*> Controller::_controllers;
const std::vector<Controller*>& Controller::getControllers()
{
return _controllers;
}
void Controller::startDiscoveryController()
{
// Empty implementation on Android
@ -288,9 +124,17 @@ void Controller::stopDiscoveryController()
// Empty implementation on Android
}
const std::string& Controller::getVendorName()
Controller::~Controller()
{
delete _impl;
delete _connectEvent;
delete _keyEvent;
delete _axisEvent;
}
void Controller::registerListeners()
{
return _vendorName;
}
bool Controller::isConnected() const
@ -301,61 +145,50 @@ bool Controller::isConnected() const
return true;
}
int Controller::getPlayerIndex() const
{
return _playerIndex;
}
void Controller::setPlayerIndex(int playerIndex)
{
_playerIndex = playerIndex;
}
Gamepad* Controller::getGamepad() const
{
return _gamepad;
}
Controller::Controller()
: _playerIndex(PLAYER_INDEX_UNSET)
, _gamepad(new Gamepad)
: _controllerTag(TAG_UNSET)
, _impl(new ControllerImpl(this))
, _connectEvent(nullptr)
, _keyEvent(nullptr)
, _axisEvent(nullptr)
{
_gamepad->_controller = this;
init();
}
Controller::~Controller()
void Controller::receiveExternalKeyEvent(int externalKeyCode,bool receive)
{
CC_SAFE_DELETE(_impl);
CC_SAFE_DELETE(_gamepad);
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/GameControllerHelper", "receiveExternalKeyEvent", "(IIZ)V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID, _deviceId, externalKeyCode, receive);
t.env->DeleteLocalRef(t.classID);
}
}
NS_CC_END
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected(JNIEnv* env, jobject thiz, jstring vendorName, jint controllerID)
void Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected(JNIEnv* env, jobject thiz, jstring deviceName, jint controllerID)
{
CCLOG("controller id: %d connected!", controllerID);
cocos2d::ControllerImpl::onConnected(cocos2d::JniHelper::jstring2string(vendorName), controllerID);
cocos2d::ControllerImpl::onConnected(cocos2d::JniHelper::jstring2string(deviceName), controllerID);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerDisconnected(JNIEnv* env, jobject thiz, jstring vendorName, jint controllerID)
void Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerDisconnected(JNIEnv* env, jobject thiz, jstring deviceName, jint controllerID)
{
CCLOG("controller id: %d disconnected!", controllerID);
cocos2d::ControllerImpl::onDisconnected(cocos2d::JniHelper::jstring2string(vendorName), controllerID);
cocos2d::ControllerImpl::onDisconnected(cocos2d::JniHelper::jstring2string(deviceName), controllerID);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerButtonEvent(JNIEnv* env, jobject thiz, jstring vendorName, jint controllerID, jint button, jboolean isPressed, jfloat value, jboolean isAnalog)
void Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerButtonEvent(JNIEnv* env, jobject thiz, jstring deviceName, jint controllerID, jint button, jboolean isPressed, jfloat value, jboolean isAnalog)
{
CCLOG("controller id: %d, btn code: %d, isPressed: %d, value: %f, isAnalog:%d", controllerID, button, (int)isPressed, value, (int)isAnalog);
cocos2d::ControllerImpl::onButtonEvent(cocos2d::JniHelper::jstring2string(vendorName), controllerID, static_cast<cocos2d::AndroidControllerCode>(button), isPressed, value, isAnalog);
cocos2d::ControllerImpl::onButtonEvent(cocos2d::JniHelper::jstring2string(deviceName), controllerID, button, isPressed, value, isAnalog);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerAxisEvent(JNIEnv* env, jobject thiz, jstring vendorName, jint controllerID, jint axis, jfloat value, jboolean isAnalog)
void Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerAxisEvent(JNIEnv* env, jobject thiz, jstring deviceName, jint controllerID, jint axis, jfloat value, jboolean isAnalog)
{
// CCLOG("controller id: %d, axis code: %d, value: %f, isAnalog:%d", controllerID, axis, value, (int)isAnalog);
cocos2d::ControllerImpl::onAxisEvent(cocos2d::JniHelper::jstring2string(vendorName), controllerID, static_cast<cocos2d::AndroidControllerCode>(axis), value, isAnalog);
cocos2d::ControllerImpl::onAxisEvent(cocos2d::JniHelper::jstring2string(deviceName), controllerID, axis, value, isAnalog);
}
} // extern "C" {

View File

@ -27,17 +27,12 @@
#include "base/CCPlatformConfig.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "CCGamepad.h"
#include "CCControllerDirectionPad.h"
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "CCControllerThumbstick.h"
#include "ccMacros.h"
#include "CCEventDispatcher.h"
#include "CCEventController.h"
#include "CCEventListenerController.h"
#include "CCDirector.h"
#include "CCLabel.h"
#import <GameController/GameController.h>
@ -105,90 +100,49 @@ static GCControllerConnectionEventHandler* __instance = nil;
NS_CC_BEGIN
#define sendEventButton(dstID, srcID) \
dstID->setPressed(srcID.isPressed); \
dstID->setValue(srcID.value); \
dstID->setAnalog(srcID.isAnalog); \
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, _gamepad->_controller, dstID); \
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
#define sendEventAxis(dstID, srcID) \
\
dstID->setValue(srcID.value); \
dstID->setAnalog(srcID.isAnalog); \
\
EventController evt(EventController::ControllerEventType::AXIS_STATUS_CHANGED, _gamepad->_controller, dstID); \
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
class ControllerImpl
{
public:
ControllerImpl(Controller* controller)
: _controller(controller)
, _gcController(nil)
, _lazyRegisterListener(true)
{
}
~ControllerImpl()
{
}
Controller* _controller;
GCController* _gcController;
bool _lazyRegisterListener;
};
std::vector<Controller*> Controller::_controllers;
const std::vector<Controller*>& Controller::getControllers()
{
return _controllers;
}
void Controller::startDiscoveryController()
{
[GCController startWirelessControllerDiscoveryWithCompletionHandler: nil];
[[GCControllerConnectionEventHandler getInstance] observerConnection: ^(GCController* gcController) {
auto controller = new Controller();
controller->_impl->_gcController = gcController;
controller->_deviceName = [gcController.vendorName UTF8String];
gcController.controllerPausedHandler = ^(GCController* gcCon){
auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcCon](Controller* c){ return c->_impl->_gcController == gcCon; });
CCASSERT(iter != _controllers.end(), "Could not find the controller");
auto button = (*iter)->getGamepad()->getButtonPause();
button->setPressed(true);
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, (*iter), button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
// Reset the pause button status to unpressed.
button->setPressed(false);
};
s_allController.push_back(controller);
_controllers.push_back(controller);
controller->registerListeners();
controller->getDeviceName();
EventController evt(EventController::ControllerEventType::CONNECTION, controller, true);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
controller->onConnected();
} disconnection: ^(GCController* gcController) {
auto iter = std::find_if(s_allController.begin(), s_allController.end(), [gcController](Controller* c){ return c->_impl->_gcController == gcController; });
auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcController](Controller* c){ return c->_impl->_gcController == gcController; });
if(iter == s_allController.end())
{
log("disconnect:Could not find the controller");
return;
}
CCASSERT(iter != _controllers.end(), "Could not find the controller");
(*iter)->onDisconnected();
s_allController.erase(iter);
EventController evt(EventController::ControllerEventType::CONNECTION, *iter, false);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
delete (*iter);
_controllers.erase(iter);
}];
}
@ -198,26 +152,156 @@ void Controller::stopDiscoveryController()
}
Controller::Controller()
: _controllerTag(TAG_UNSET)
, _impl(new ControllerImpl(this))
, _connectEvent(nullptr)
, _keyEvent(nullptr)
, _axisEvent(nullptr)
, _deviceId(0)
{
_playerIndex = PLAYER_INDEX_UNSET;
_gamepad = new Gamepad();
_gamepad->_controller = this;
_impl = new ControllerImpl(this);
init();
}
Controller::~Controller()
{
CC_SAFE_DELETE(_impl);
CC_SAFE_DELETE(_gamepad);
delete _impl;
delete _connectEvent;
delete _keyEvent;
delete _axisEvent;
}
const std::string& Controller::getVendorName()
void Controller::registerListeners()
{
if (_vendorName.empty())
if (_impl->_gcController.extendedGamepad != nil)
{
_vendorName = [_impl->_gcController.vendorName UTF8String];
_impl->_gcController.extendedGamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_UP, pressed, value, button.isAnalog);
};
_impl->_gcController.extendedGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_DOWN, pressed, value, button.isAnalog);
};
_impl->_gcController.extendedGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_LEFT, pressed, value, button.isAnalog);
};
_impl->_gcController.extendedGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_RIGHT, pressed, value, button.isAnalog);
};
_impl->_gcController.extendedGamepad.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
onAxisEvent(Key::JOYSTICK_LEFT_X, value, axis.isAnalog);
};
_impl->_gcController.extendedGamepad.leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
onAxisEvent(Key::JOYSTICK_LEFT_Y, value, axis.isAnalog);
};
_impl->_gcController.extendedGamepad.rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
onAxisEvent(Key::JOYSTICK_RIGHT_X, value, axis.isAnalog);
};
_impl->_gcController.extendedGamepad.rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
onAxisEvent(Key::JOYSTICK_RIGHT_Y, value, axis.isAnalog);
};
_impl->_gcController.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element){
if (element == gamepad.buttonA)
{
onButtonEvent(Key::BUTTON_A, gamepad.buttonA.isPressed, gamepad.buttonA.value, gamepad.buttonA.isAnalog);
}
else if (element == gamepad.buttonB)
{
onButtonEvent(Key::BUTTON_B, gamepad.buttonB.isPressed, gamepad.buttonB.value, gamepad.buttonB.isAnalog);
}
else if (element == gamepad.buttonX)
{
onButtonEvent(Key::BUTTON_X, gamepad.buttonX.isPressed, gamepad.buttonX.value, gamepad.buttonX.isAnalog);
}
else if (element == gamepad.buttonY)
{
onButtonEvent(Key::BUTTON_Y, gamepad.buttonY.isPressed, gamepad.buttonY.value, gamepad.buttonY.isAnalog);
}
else if (element == gamepad.leftShoulder)
{
onButtonEvent(Key::BUTTON_LEFT_SHOULDER, gamepad.leftShoulder.isPressed, gamepad.leftShoulder.value, gamepad.leftShoulder.isAnalog);
}
else if (element == gamepad.rightShoulder)
{
onButtonEvent(Key::BUTTON_RIGHT_SHOULDER, gamepad.rightShoulder.isPressed, gamepad.rightShoulder.value, gamepad.rightShoulder.isAnalog);
}
else if (element == gamepad.leftTrigger)
{
onAxisEvent(Key::AXIS_LEFT_TRIGGER, gamepad.leftTrigger.value, gamepad.leftTrigger.isAnalog);
}
else if (element == gamepad.rightTrigger)
{
onAxisEvent(Key::AXIS_RIGHT_TRIGGER, gamepad.rightTrigger.value, gamepad.rightTrigger.isAnalog);
}
};
}
return _vendorName;
else
{
_impl->_gcController.gamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_UP, pressed, value, button.isAnalog);
};
_impl->_gcController.gamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_DOWN, pressed, value, button.isAnalog);
};
_impl->_gcController.gamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_LEFT, pressed, value, button.isAnalog);
};
_impl->_gcController.gamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
onButtonEvent(Key::BUTTON_DPAD_RIGHT, pressed, value, button.isAnalog);
};
_impl->_gcController.gamepad.valueChangedHandler = ^(GCGamepad *gamepad, GCControllerElement *element){
if (element == gamepad.buttonA)
{
onButtonEvent(Key::BUTTON_A, gamepad.buttonA.isPressed, gamepad.buttonA.value, gamepad.buttonA.isAnalog);
}
else if (element == gamepad.buttonB)
{
onButtonEvent(Key::BUTTON_B, gamepad.buttonB.isPressed, gamepad.buttonB.value, gamepad.buttonB.isAnalog);
}
else if (element == gamepad.buttonX)
{
onButtonEvent(Key::BUTTON_X, gamepad.buttonX.isPressed, gamepad.buttonX.value, gamepad.buttonX.isAnalog);
}
else if (element == gamepad.buttonY)
{
onButtonEvent(Key::BUTTON_Y, gamepad.buttonY.isPressed, gamepad.buttonY.value, gamepad.buttonY.isAnalog);
}
else if (element == gamepad.leftShoulder)
{
onButtonEvent(Key::BUTTON_LEFT_SHOULDER, gamepad.leftShoulder.isPressed, gamepad.leftShoulder.value, gamepad.leftShoulder.isAnalog);
}
else if (element == gamepad.rightShoulder)
{
onButtonEvent(Key::BUTTON_RIGHT_SHOULDER, gamepad.rightShoulder.isPressed, gamepad.rightShoulder.value, gamepad.rightShoulder.isAnalog);
}
};
}
_impl->_gcController.controllerPausedHandler = ^(GCController* gcCon){
auto iter = std::find_if(s_allController.begin(), s_allController.end(), [gcCon](Controller* c){ return c->_impl->_gcController == gcCon; });
if(iter == s_allController.end())
{
log("Could not find the controller");
return;
}
onButtonEvent(Key::BUTTON_PAUSE, true, 1.0f, false);
onButtonEvent(Key::BUTTON_PAUSE, false, 0.0f, false);
};
}
bool Controller::isConnected() const
@ -225,145 +309,8 @@ bool Controller::isConnected() const
return _impl->_gcController.isAttachedToDevice == YES;
}
int Controller::getPlayerIndex() const
void Controller::receiveExternalKeyEvent(int externalKeyCode,bool receive)
{
return _playerIndex;
}
void Controller::setPlayerIndex(int playerIndex)
{
_playerIndex = playerIndex;
}
Gamepad* Controller::getGamepad() const
{
if (_impl->_gcController == nil)
return nullptr;
if(_impl->_gcController.gamepad == nil && _impl->_gcController.extendedGamepad == nil)
{
CCASSERT(false, "No gamepad was found!");
}
else if (_impl->_lazyRegisterListener)
{
_impl->_lazyRegisterListener = false;
if (_impl->_gcController.extendedGamepad != nil)
{
_impl->_gcController.extendedGamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.extendedGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.extendedGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.extendedGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getRight(), button);
};
_impl->_gcController.extendedGamepad.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
sendEventAxis(_gamepad->getLeftThumbstick()->getAxisX(), axis);
};
_impl->_gcController.extendedGamepad.leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
sendEventAxis(_gamepad->getLeftThumbstick()->getAxisY(), axis);
};
_impl->_gcController.extendedGamepad.rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
sendEventAxis(_gamepad->getRightThumbstick()->getAxisX(), axis);
};
_impl->_gcController.extendedGamepad.rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){
sendEventAxis(_gamepad->getRightThumbstick()->getAxisY(), axis);
};
_impl->_gcController.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element){
if (element == gamepad.buttonA)
{
sendEventButton(_gamepad->getButtonA(), gamepad.buttonA);
}
else if (element == gamepad.buttonB)
{
sendEventButton(_gamepad->getButtonB(), gamepad.buttonB);
}
else if (element == gamepad.buttonX)
{
sendEventButton(_gamepad->getButtonX(), gamepad.buttonX);
}
else if (element == gamepad.buttonY)
{
sendEventButton(_gamepad->getButtonY(), gamepad.buttonY);
}
else if (element == gamepad.leftShoulder)
{
sendEventButton(_gamepad->getLeftShoulder(), gamepad.leftShoulder);
}
else if (element == gamepad.rightShoulder)
{
sendEventButton(_gamepad->getRightShoulder(), gamepad.rightShoulder);
}
else if (element == gamepad.leftTrigger)
{
sendEventButton(_gamepad->getLeftTrigger(), gamepad.leftTrigger);
}
else if (element == gamepad.rightTrigger)
{
sendEventButton(_gamepad->getRightTrigger(), gamepad.rightTrigger);
}
};
}
else
{
_impl->_gcController.gamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.gamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.gamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.gamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
sendEventButton(_gamepad->getDirectionPad()->getRight(), button);
};
_impl->_gcController.gamepad.valueChangedHandler = ^(GCGamepad *gamepad, GCControllerElement *element){
if (element == gamepad.buttonA)
{
sendEventButton(_gamepad->getButtonA(), gamepad.buttonA);
}
else if (element == gamepad.buttonB)
{
sendEventButton(_gamepad->getButtonB(), gamepad.buttonB);
}
else if (element == gamepad.buttonX)
{
sendEventButton(_gamepad->getButtonX(), gamepad.buttonX);
}
else if (element == gamepad.buttonY)
{
sendEventButton(_gamepad->getButtonY(), gamepad.buttonY);
}
else if (element == gamepad.leftShoulder)
{
sendEventButton(_gamepad->getLeftShoulder(), gamepad.leftShoulder);
}
else if (element == gamepad.rightShoulder)
{
sendEventButton(_gamepad->getRightShoulder(), gamepad.rightShoulder);
}
};
}
}
return _gamepad;
}
NS_CC_END

117
cocos/base/CCController.cpp Normal file
View File

@ -0,0 +1,117 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#include "CCController.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "ccMacros.h"
#include "CCEventDispatcher.h"
#include "CCEventController.h"
#include "CCEventListenerController.h"
#include "CCDirector.h"
NS_CC_BEGIN
std::vector<Controller*> Controller::s_allController;
Controller* Controller::getControllerByTag(int tag)
{
for (auto controller:Controller::s_allController)
{
if (controller->_controllerTag == tag)
{
return controller;
}
}
return nullptr;
}
void Controller::init()
{
for (int key = Key::JOYSTICK_LEFT_X; key < Key::KEY_MAX; ++key)
{
_allKeyStatus[key].isPressed = false;
_allKeyStatus[key].value = 0.0f;
_allKeyPrevStatus[key].isPressed = false;
_allKeyPrevStatus[key].value = 0.0f;
}
_eventDispatcher = Director::getInstance()->getEventDispatcher();
_connectEvent = new EventController(EventController::ControllerEventType::CONNECTION, this, false);
_keyEvent = new EventController(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, this, 0);
_axisEvent = new EventController(EventController::ControllerEventType::AXIS_STATUS_CHANGED, this, 0);
}
const Controller::KeyStatus& Controller::getKeyStatus(int keyCode)
{
if (_allKeyStatus.find(keyCode) == _allKeyStatus.end())
{
_allKeyStatus[keyCode].isPressed = false;
_allKeyStatus[keyCode].value = 0.0f;
}
return _allKeyStatus[keyCode];
}
void Controller::onConnected()
{
_connectEvent->setConnectStatus(true);
_eventDispatcher->dispatchEvent(_connectEvent);
}
void Controller::onDisconnected()
{
_connectEvent->setConnectStatus(false);
_eventDispatcher->dispatchEvent(_connectEvent);
delete this;
}
void Controller::onButtonEvent(int keyCode, bool isPressed, float value, bool isAnalog)
{
_allKeyPrevStatus[keyCode] = _allKeyStatus[keyCode];
_allKeyStatus[keyCode].isPressed = isPressed;
_allKeyStatus[keyCode].value = value;
_allKeyStatus[keyCode].isAnalog = isAnalog;
_keyEvent->setKeyCode(keyCode);
_eventDispatcher->dispatchEvent(_keyEvent);
}
void Controller::onAxisEvent(int axisCode, float value, bool isAnalog)
{
_allKeyPrevStatus[axisCode] = _allKeyStatus[axisCode];
_allKeyStatus[axisCode].value = value;
_allKeyStatus[axisCode].isAnalog = isAnalog;
_axisEvent->setKeyCode(axisCode);
_eventDispatcher->dispatchEvent(_axisEvent);
}
NS_CC_END
#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

View File

@ -27,50 +27,140 @@
#define __cocos2d_libs__CCController__
#include "CCPlatformMacros.h"
#include <string>
#include <vector>
#include <functional>
#include <unordered_map>
NS_CC_BEGIN
class Gamepad;
class ControllerImpl;
class EventListenerController;
class EventController;
class EventDispatcher;
class Controller
{
public:
static const std::vector<Controller*>& getControllers();
/** Controllers' standard key
* Controller receives only standard key which contained within enum Key by default.
*/
enum Key
{
JOYSTICK_LEFT_X = 1000,
JOYSTICK_LEFT_Y,
JOYSTICK_RIGHT_X,
JOYSTICK_RIGHT_Y,
BUTTON_A,
BUTTON_B,
BUTTON_C,
BUTTON_X,
BUTTON_Y,
BUTTON_Z,
BUTTON_DPAD_UP,
BUTTON_DPAD_DOWN,
BUTTON_DPAD_LEFT,
BUTTON_DPAD_RIGHT,
BUTTON_DPAD_CENTER,
BUTTON_LEFT_SHOULDER,
BUTTON_RIGHT_SHOULDER,
AXIS_LEFT_TRIGGER,
AXIS_RIGHT_TRIGGER,
BUTTON_LEFT_THUMBSTICK,
BUTTON_RIGHT_THUMBSTICK,
BUTTON_START,
BUTTON_SELECT,
BUTTON_PAUSE,
KEY_MAX
};
typedef struct _keyStatus
{
bool isPressed;
float value;
bool isAnalog;
}KeyStatus;
static const int TAG_UNSET = -1;
static const std::vector<Controller*>& getAllController(){ return s_allController;}
/** Gets a controller with its tag
* @param tag An identifier to find the controller.
*/
static Controller* getControllerByTag(int tag);
/** To start discovering new controllers
* @warning The API only work on the IOS platform.Empty implementation on Android
*/
static void startDiscoveryController();
/** End the discovery process
* @warning The API only work on the IOS platform.Empty implementation on Android
*/
static void stopDiscoveryController();
const std::string& getVendorName();
const std::string& getDeviceName() const { return _deviceName;}
int getDeviceId() const { return _deviceId;}
bool isConnected() const;
static const int PLAYER_INDEX_UNSET = -1;
const KeyStatus& getKeyStatus(int keyCode);
/** Activate receives key event from external key. e.g. back,menu.
* Controller receives only standard key which contained within enum Key by default.
* @warning The API only work on the android platform for support diversified game controller.
*
* @param externalKeyCode external key code
* @param receive true if external key event on this controller should be receive, false otherwise.
*/
void receiveExternalKeyEvent(int externalKeyCode,bool receive);
int getPlayerIndex() const;
void setPlayerIndex(int playerIndex);
/** Changes the tag that is used to identify the controller easily.
* @param tag A integer that identifies the controller.
*/
void setTag(int tag) { _controllerTag = tag;}
/**
* Returns a tag that is used to identify the controller easily.
*
* @return An integer that identifies the controller.
*/
int getTag() const { return _controllerTag;}
Gamepad* getGamepad() const;
// For internal use only
inline ControllerImpl* getImpl() const { return _impl; };
private:
static std::vector<Controller*> s_allController;
Controller();
virtual ~Controller();
private:
static std::vector<Controller*> _controllers;
void init();
std::string _vendorName;
int _playerIndex;
Gamepad* _gamepad;
void onConnected();
void onDisconnected();
void onButtonEvent(int keyCode, bool isPressed, float value, bool isAnalog);
void onAxisEvent(int axisCode, float value, bool isAnalog);
void registerListeners();
std::unordered_map<int, KeyStatus> _allKeyStatus;
std::unordered_map<int, KeyStatus> _allKeyPrevStatus;
std::string _deviceName;
int _deviceId;
int _controllerTag;
ControllerImpl* _impl;
EventDispatcher* _eventDispatcher;
EventController *_connectEvent;
EventController *_keyEvent;
EventController *_axisEvent;
friend class ControllerImpl;
ControllerImpl* _impl;
friend class EventListenerController;
};

View File

@ -1,63 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#ifndef __cocos2d_libs__CCControllerButtonInput__
#define __cocos2d_libs__CCControllerButtonInput__
#include "CCPlatformMacros.h"
#include "CCControllerElement.h"
NS_CC_BEGIN
class ControllerButtonInput : public ControllerElement
{
public:
float getValue() const;
bool isPressed() const;
bool isPrevStatusPressed() const;
protected:
ControllerButtonInput();
virtual ~ControllerButtonInput();
void setValue(float value);
void setPressed(bool isPressed);
float _value;
bool _isPressed;
bool _isPrevStatusPressed; // Whether previous status is pressed
friend class Controller;
friend class ControllerImpl;
friend class ControllerDirectionPad;
friend class ControllerThumbstick;
friend class Gamepad;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCControllerButtonInput__) */

View File

@ -1,74 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#include "CCControllerDirectionPad.h"
#include "CCControllerAxisInput.h"
#include "CCControllerButtonInput.h"
NS_CC_BEGIN
ControllerDirectionPad::ControllerDirectionPad()
: _up(new ControllerButtonInput())
, _down(new ControllerButtonInput())
, _left(new ControllerButtonInput())
, _right(new ControllerButtonInput())
{
_up->setCollection(this);
_down->setCollection(this);
_left->setCollection(this);
_right->setCollection(this);
}
ControllerDirectionPad::~ControllerDirectionPad()
{
CC_SAFE_DELETE(_up);
CC_SAFE_DELETE(_down);
CC_SAFE_DELETE(_left);
CC_SAFE_DELETE(_right);
}
ControllerButtonInput* ControllerDirectionPad::getUp() const
{
return _up;
}
ControllerButtonInput* ControllerDirectionPad::getDown() const
{
return _down;
}
ControllerButtonInput* ControllerDirectionPad::getLeft() const
{
return _left;
}
ControllerButtonInput* ControllerDirectionPad::getRight() const
{
return _right;
}
NS_CC_END

View File

@ -1,61 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#ifndef __cocos2d_libs__CCControllerDirectionPad__
#define __cocos2d_libs__CCControllerDirectionPad__
#include "CCPlatformMacros.h"
#include "CCControllerElement.h"
NS_CC_BEGIN
class ControllerAxisInput;
class ControllerButtonInput;
class ControllerDirectionPad : public ControllerElement
{
public:
ControllerButtonInput* getUp() const;
ControllerButtonInput* getDown() const;
ControllerButtonInput* getLeft() const;
ControllerButtonInput* getRight() const;
protected:
friend class Controller;
friend class Gamepad;
ControllerDirectionPad();
virtual ~ControllerDirectionPad();
ControllerButtonInput* _up;
ControllerButtonInput* _down;
ControllerButtonInput* _left;
ControllerButtonInput* _right;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCControllerDirectionPad__) */

View File

@ -1,64 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#ifndef __cocos2d_libs__CCControllerElement__
#define __cocos2d_libs__CCControllerElement__
#include "CCPlatformMacros.h"
NS_CC_BEGIN
/**
Every controller element knows which collection it belongs to and whether its input value is analog or digital.
*/
class ControllerElement
{
public:
/**
Each element can be part of a wider collection of inputs that map to a single logical element. A directional pad (dpad)
is a logical collection of two axis inputs and thus each axis belongs to the same collection element - the dpad.
*/
ControllerElement * getCollection();
/**
Check if the element can support more than just digital values, such as decimal ranges between 0 and 1.
*/
bool isAnalog() const;
protected:
ControllerElement();
virtual ~ControllerElement();
void setAnalog(bool isAnalog);
void setCollection(ControllerElement* collection);
bool _isAnalog;
ControllerElement* _collection;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCControllerElement__) */

View File

@ -1,66 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#include "CCControllerThumbstick.h"
#include "CCControllerAxisInput.h"
#include "CCControllerButtonInput.h"
NS_CC_BEGIN
ControllerThumbstick::ControllerThumbstick()
: _axisX(new ControllerAxisInput())
, _axisY(new ControllerAxisInput())
, _button(new ControllerButtonInput())
{
_axisX->setCollection(this);
_axisY->setCollection(this);
_button->setCollection(this);
}
ControllerThumbstick::~ControllerThumbstick()
{
CC_SAFE_DELETE(_axisX);
CC_SAFE_DELETE(_axisY);
CC_SAFE_DELETE(_button);
}
ControllerAxisInput* ControllerThumbstick::getAxisX() const
{
return _axisX;
}
ControllerAxisInput* ControllerThumbstick::getAxisY() const
{
return _axisY;
}
ControllerButtonInput* ControllerThumbstick::getButton() const
{
return _button;
}
NS_CC_END

View File

@ -177,7 +177,6 @@ Director::~Director(void)
CC_SAFE_RELEASE(_scheduler);
CC_SAFE_RELEASE(_actionManager);
delete _eventAfterUpdate;
delete _eventAfterDraw;
delete _eventAfterVisit;
@ -191,12 +190,11 @@ Director::~Director(void)
CC_SAFE_RELEASE(_eventDispatcher);
// clean auto release pool
PoolManager::destroyInstance();
// delete _lastUpdate
CC_SAFE_DELETE(_lastUpdate);
Configuration::destroyInstance();
s_SharedDirector = nullptr;
}
@ -976,7 +974,6 @@ void Director::purgeDirector()
GLProgramCache::destroyInstance();
GLProgramStateCache::destroyInstance();
FileUtils::destroyInstance();
Configuration::destroyInstance();
// cocos2d-x specific data structures
UserDefault::destroyInstance();

View File

@ -27,10 +27,10 @@
NS_CC_BEGIN
EventController::EventController(ControllerEventType type, Controller* controller, ControllerElement* element)
EventController::EventController(ControllerEventType type, Controller* controller, int keyCode)
: Event(Type::GAME_CONTROLLER)
, _controllerEventType(type)
, _element(element)
, _keyCode(keyCode)
, _controller(controller)
, _isConnected(true)
{
@ -40,31 +40,11 @@ EventController::EventController(ControllerEventType type, Controller* controlle
EventController::EventController(ControllerEventType type, Controller* controller, bool isConnected)
: Event(Type::GAME_CONTROLLER)
, _controllerEventType(type)
, _element(nullptr)
, _controller(controller)
, _isConnected(isConnected)
, _keyCode(0)
{
}
EventController::ControllerEventType EventController::getControllerEventType() const
{
return _controllerEventType;
}
Controller* EventController::getController() const
{
return _controller;
}
ControllerElement* EventController::getControllerElement() const
{
return _element;
}
bool EventController::isConnected() const
{
return _isConnected;
}
NS_CC_END

View File

@ -31,10 +31,8 @@
NS_CC_BEGIN
class ControllerButtonInput;
class ControllerAxisInput;
class ControllerElement;
class Controller;
class EventListenerController;
class EventController : public Event
{
@ -46,19 +44,25 @@ public:
AXIS_STATUS_CHANGED,
};
EventController(ControllerEventType type, Controller* controller, ControllerElement* element);
EventController(ControllerEventType type, Controller* controller, int keyCode);
EventController(ControllerEventType type, Controller* controller, bool isConnected);
ControllerEventType getControllerEventType() const;
Controller* getController() const;
ControllerElement* getControllerElement() const;
bool isConnected() const;
ControllerEventType getControllerEventType() const { return _controllerEventType; }
Controller* getController() const { return _controller; }
int getKeyCode() const{ return _keyCode; }
void setKeyCode(int keyCode) { _keyCode = keyCode;}
void setConnectStatus(bool isConnected) {_isConnected = isConnected;}
bool isConnected() const { return _isConnected; }
protected:
ControllerEventType _controllerEventType;
ControllerElement* _element;
Controller* _controller;
int _keyCode;
bool _isConnected;
friend class EventListenerController;
};
NS_CC_END

View File

@ -211,6 +211,7 @@ EventDispatcher::EventDispatcher()
// Therefore, internal listeners would not be cleaned when removeAllEventListeners is invoked.
_internalCustomListenerIDs.insert(EVENT_COME_TO_FOREGROUND);
_internalCustomListenerIDs.insert(EVENT_COME_TO_BACKGROUND);
_internalCustomListenerIDs.insert(EVENT_RENDERER_RECREATED);
}
EventDispatcher::~EventDispatcher()
@ -613,7 +614,7 @@ void EventDispatcher::removeEventListener(EventListener* listener)
if (l->getAssociatedNode() != nullptr)
{
dissociateNodeAndEventListener(l->getAssociatedNode(), l);
l->setAssociatedNode(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
l->setAssociatedNode(nullptr); // nullptr out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)
@ -1276,7 +1277,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis
if (l->getAssociatedNode() != nullptr)
{
dissociateNodeAndEventListener(l->getAssociatedNode(), l);
l->setAssociatedNode(nullptr); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes.
l->setAssociatedNode(nullptr); // nullptr out the node pointer so we don't have any dangling pointers to destroyed nodes.
}
if (_inDispatch == 0)

View File

@ -25,9 +25,8 @@
#include "CCEventListenerController.h"
#include "CCEventController.h"
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "ccMacros.h"
#include "base/CCController.h"
NS_CC_BEGIN
@ -51,8 +50,9 @@ bool EventListenerController::init()
{
auto listener = [this](Event* event){
auto evtController = static_cast<EventController*>(event);
if (evtController->getControllerEventType() == EventController::ControllerEventType::CONNECTION)
switch (evtController->getControllerEventType())
{
case EventController::ControllerEventType::CONNECTION:
if (evtController->isConnected())
{
if (this->onConnected)
@ -63,45 +63,40 @@ bool EventListenerController::init()
if (this->onDisconnected)
this->onDisconnected(evtController->getController(), event);
}
}
else
{
switch (evtController->getControllerEventType()) {
case EventController::ControllerEventType::BUTTON_STATUS_CHANGED:
{
auto button = static_cast<ControllerButtonInput*>(evtController->getControllerElement());
break;
case EventController::ControllerEventType::BUTTON_STATUS_CHANGED:
{
const auto& keyStatus = evtController->_controller->_allKeyStatus[evtController->_keyCode];
const auto& keyPrevStatus = evtController->_controller->_allKeyPrevStatus[evtController->_keyCode];
if (this->onButtonPressed && button->isPressed() && !button->isPrevStatusPressed())
{
this->onButtonPressed(evtController->getController(), button, event);
}
else if (this->onButtonReleased && !button->isPressed() && button->isPrevStatusPressed())
{
this->onButtonReleased(evtController->getController(), button, event);
}
if (this->onButtonValueChanged)
{
this->onButtonValueChanged(evtController->getController(), button, event);
}
}
break;
case EventController::ControllerEventType::AXIS_STATUS_CHANGED:
{
if (this->onAxisValueChanged)
{
auto axis = static_cast<ControllerAxisInput*>(evtController->getControllerElement());
this->onAxisValueChanged(evtController->getController(), axis, event);
}
}
break;
default:
CCASSERT(false, "Invalid EventController type");
break;
if (this->onKeyDown && keyStatus.isPressed && !keyPrevStatus.isPressed)
{
this->onKeyDown(evtController->_controller, evtController->_keyCode, event);
}
else if (this->onKeyUp && !keyStatus.isPressed && keyPrevStatus.isPressed)
{
this->onKeyUp(evtController->_controller, evtController->_keyCode, event);
}
else if (this->onKeyRepeat && keyStatus.isPressed && keyPrevStatus.isPressed)
{
this->onKeyRepeat(evtController->_controller, evtController->_keyCode, event);
}
}
break;
case EventController::ControllerEventType::AXIS_STATUS_CHANGED:
{
if (this->onAxisEvent)
{
this->onAxisEvent(evtController->_controller, evtController->_keyCode, event);
}
}
break;
default:
CCASSERT(false, "Invalid EventController type");
break;
}
};
if (EventListener::init(EventListener::Type::GAME_CONTROLLER, LISTENER_ID, listener))
{
return true;

View File

@ -33,8 +33,6 @@ NS_CC_BEGIN
class Event;
class Controller;
class ControllerButtonInput;
class ControllerAxisInput;
class EventListenerController : public EventListener
{
@ -50,11 +48,11 @@ public:
std::function<void(Controller*, Event*)> onConnected;
std::function<void(Controller*, Event*)> onDisconnected;
std::function<void(Controller*, ControllerButtonInput*, Event*)> onButtonPressed;
std::function<void(Controller*, ControllerButtonInput*, Event*)> onButtonReleased;
std::function<void(Controller*, ControllerButtonInput*, Event*)> onButtonValueChanged;
std::function<void(Controller*, int, Event*)> onKeyDown;
std::function<void(Controller*, int, Event*)> onKeyUp;
std::function<void(Controller*, int, Event*)> onKeyRepeat;
std::function<void(Controller*, ControllerAxisInput*, Event*)> onAxisValueChanged;
std::function<void(Controller*, int, Event*)> onAxisEvent;
protected:
bool init();

View File

@ -30,7 +30,7 @@ NS_CC_BEGIN
EventMouse::EventMouse(MouseEventType mouseEventCode)
: Event(Type::MOUSE)
, _mouseEventType(mouseEventCode)
, _mouseButton(0)
, _mouseButton(-1)
, _x(0.0f)
, _y(0.0f)
, _scrollX(0.0f)

View File

@ -30,13 +30,17 @@
*/
// The application will come to foreground.
// This message is used for reloading resources before come to foreground on Android.
// This message is posted in main.cpp.
// This message is posted in cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp.
#define EVENT_COME_TO_FOREGROUND "event_come_to_foreground"
// The renderer[android:GLSurfaceView.Renderer WP8:Cocos2dRenderer] was recreated.
// This message is used for reloading resources before renderer is recreated on Android/WP8.
// This message is posted in cocos/platform/android/javaactivity.cpp and cocos\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp.
#define EVENT_RENDERER_RECREATED "event_renderer_recreated"
// The application will come to background.
// This message is used for doing something before coming to background, such as save RenderTexture.
// This message is posted in cocos2dx/platform/android/jni/MessageJni.cpp.
// This message is posted in cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp and cocos\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp.
#define EVENT_COME_TO_BACKGROUND "event_come_to_background"
#endif // __CCEVENT_TYPE_H__

View File

@ -26,12 +26,6 @@
#ifndef __cocos2d_libs__CCGameController__
#define __cocos2d_libs__CCGameController__
#include "CCControllerElement.h"
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "CCControllerDirectionPad.h"
#include "CCControllerThumbstick.h"
#include "CCGamepad.h"
#include "CCController.h"
#include "CCEventController.h"
#include "CCEventListenerController.h"

View File

@ -1,146 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#include "CCGamepad.h"
#include "CCControllerDirectionPad.h"
#include "CCControllerButtonInput.h"
#include "CCControllerThumbstick.h"
NS_CC_BEGIN
Gamepad::Gamepad()
: _controller(nullptr)
, _directionPad(new ControllerDirectionPad())
, _buttonA(new ControllerButtonInput())
, _buttonB(new ControllerButtonInput())
, _buttonX(new ControllerButtonInput())
, _buttonY(new ControllerButtonInput())
, _buttonSelect(new ControllerButtonInput())
, _buttonStart(new ControllerButtonInput())
, _buttonPause(new ControllerButtonInput())
, _leftShoulder(new ControllerButtonInput())
, _rightShoulder(new ControllerButtonInput())
, _leftThumbstick(new ControllerThumbstick())
, _rightThumbstick(new ControllerThumbstick())
, _leftTrigger(new ControllerButtonInput())
, _rightTrigger(new ControllerButtonInput())
{
}
Gamepad::~Gamepad()
{
CC_SAFE_DELETE(_directionPad);
CC_SAFE_DELETE(_buttonA);
CC_SAFE_DELETE(_buttonB);
CC_SAFE_DELETE(_buttonX);
CC_SAFE_DELETE(_buttonY);
CC_SAFE_DELETE(_buttonSelect);
CC_SAFE_DELETE(_buttonStart);
CC_SAFE_DELETE(_buttonPause);
CC_SAFE_DELETE(_leftShoulder);
CC_SAFE_DELETE(_rightShoulder);
CC_SAFE_DELETE(_leftThumbstick);
CC_SAFE_DELETE(_rightThumbstick);
CC_SAFE_DELETE(_leftTrigger);
CC_SAFE_DELETE(_rightTrigger);
}
Controller* Gamepad::getController()
{
return _controller;
}
ControllerDirectionPad* Gamepad::getDirectionPad() const
{
return _directionPad;
}
ControllerButtonInput* Gamepad::getButtonA() const
{
return _buttonA;
}
ControllerButtonInput* Gamepad::getButtonB() const
{
return _buttonB;
}
ControllerButtonInput* Gamepad::getButtonX() const
{
return _buttonX;
}
ControllerButtonInput* Gamepad::getButtonY() const
{
return _buttonY;
}
ControllerButtonInput* Gamepad::getButtonPause() const
{
return _buttonPause;
}
ControllerButtonInput* Gamepad::getButtonSelect() const
{
return _buttonSelect;
}
ControllerButtonInput* Gamepad::getButtonStart() const
{
return _buttonStart;
}
ControllerButtonInput* Gamepad::getLeftShoulder() const
{
return _leftShoulder;
}
ControllerButtonInput* Gamepad::getRightShoulder() const
{
return _rightShoulder;
}
ControllerThumbstick* Gamepad::getLeftThumbstick() const
{
return _leftThumbstick;
}
ControllerThumbstick* Gamepad::getRightThumbstick() const
{
return _rightThumbstick;
}
ControllerButtonInput* Gamepad::getLeftTrigger() const
{
return _leftTrigger;
}
ControllerButtonInput* Gamepad::getRightTrigger() const
{
return _rightTrigger;
}
NS_CC_END

View File

@ -1,122 +0,0 @@
/****************************************************************************
Copyright (c) 2014 cocos2d-x.org
Copyright (c) 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.
****************************************************************************/
#ifndef __cocos2d_libs__CCGamepad__
#define __cocos2d_libs__CCGamepad__
#include "CCPlatformMacros.h"
NS_CC_BEGIN
class ControllerButtonInput;
class ControllerDirectionPad;
class ControllerThumbstick;
class Controller;
class Gamepad
{
public:
/**
A profile keeps a reference to the controller that this profile is mapping input from.
*/
Controller* getController();
// API for Standard / Extended Gamepad
ControllerDirectionPad* getDirectionPad() const;
/**
All face buttons are required to be analog in the Extended profile. These must be arranged
in the diamond pattern given below:
Y
/ \
X B
\ /
A
*/
ControllerButtonInput* getButtonA() const;
ControllerButtonInput* getButtonB() const;
ControllerButtonInput* getButtonX() const;
ControllerButtonInput* getButtonY() const;
// Select button
ControllerButtonInput* getButtonSelect() const;
// Start button
ControllerButtonInput* getButtonStart() const;
// Pause button
ControllerButtonInput* getButtonPause() const;
// Shoulder buttons
ControllerButtonInput* getLeftShoulder() const;
ControllerButtonInput* getRightShoulder() const;
// API for Extended Gamepad only
/**
A thumbstick is a 2-axis control that is physically required to be analog. All the elements of this directional input are thus analog.
*/
ControllerThumbstick* getLeftThumbstick() const;
ControllerThumbstick* getRightThumbstick() const;
/**
If Trigger button supports analog inputs, it could be used as acceleration and decelleration in a driving game for example.
*/
ControllerButtonInput* getLeftTrigger() const;
ControllerButtonInput* getRightTrigger() const;
protected:
Gamepad();
virtual ~Gamepad();
friend class Controller;
Controller* _controller;
ControllerDirectionPad* _directionPad;
ControllerButtonInput* _buttonA;
ControllerButtonInput* _buttonB;
ControllerButtonInput* _buttonX;
ControllerButtonInput* _buttonY;
ControllerButtonInput* _buttonSelect;
ControllerButtonInput* _buttonStart;
ControllerButtonInput* _buttonPause;
ControllerButtonInput* _leftShoulder;
ControllerButtonInput* _rightShoulder;
ControllerThumbstick* _leftThumbstick;
ControllerThumbstick* _rightThumbstick;
ControllerButtonInput* _leftTrigger;
ControllerButtonInput* _rightTrigger;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCGamepad__) */

View File

@ -46,6 +46,7 @@ Ref::Ref()
static unsigned int uObjectCount = 0;
_luaID = 0;
_ID = ++uObjectCount;
_scriptObject = nullptr;
#endif
#if CC_USE_MEM_LEAK_DETECTION
@ -64,7 +65,7 @@ Ref::~Ref()
else
{
ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine();
if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript)
if (pEngine != nullptr && pEngine->getScriptType() == kScriptTypeJavascript)
{
pEngine->removeScriptObjectByObject(this);
}

View File

@ -142,6 +142,8 @@ public:
unsigned int _ID;
/// Lua reference id
int _luaID;
/// scriptObject, support for swift
void* _scriptObject;
#endif
// Memory leak diagnostic data (only included when CC_USE_MEM_LEAK_DETECTION is defined and its value isn't zero)

View File

@ -173,7 +173,7 @@ public:
/**
* @js NA
*/
const static std::string& getXMLFilePath();
static const std::string& getXMLFilePath();
/**
* @js NA
*/

View File

@ -455,7 +455,7 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value)
deleteNodeByKey(pKey);
#endif
CCLOG("SET DATA FOR KEY: --%s--%d", value.getBytes(), value.getSize());
CCLOG("SET DATA FOR KEY: --%s--%d", value.getBytes(), (int)(value.getSize()));
char * encodedData = nullptr;
unsigned int encodedDataLen = base64Encode(value.getBytes(), value.getSize(), &encodedData);

View File

@ -181,7 +181,7 @@ void tgaFlipImage( tImageTGA *info )
unsigned char *row = (unsigned char *)malloc(rowbytes);
int y;
if (row == NULL) return;
if (row == nullptr) return;
for( y = 0; y < (info->height/2); y++ )
{
@ -233,7 +233,7 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size)
info->imageData = (unsigned char *)malloc(sizeof(unsigned char) * total);
// check to make sure we have the memory required
if (info->imageData == NULL)
if (info->imageData == nullptr)
{
info->status = TGA_ERROR_MEMORY;
break;

View File

@ -202,9 +202,6 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios.
0 -- disabled
1 -- draw bounding box
2 -- draw texture box
0 -- disabled
1 -- draw bounding box
2 -- draw texture box
*/
#ifndef CC_SPRITE_DEBUG_DRAW
#define CC_SPRITE_DEBUG_DRAW 0

View File

@ -33,6 +33,7 @@ THE SOFTWARE.
#include "math/CCGeometry.h"
#include "math/CCMath.h"
#include "CCGL.h"
#include "CCRef.h"
NS_CC_BEGIN
@ -65,15 +66,15 @@ struct Color3B
GLubyte g;
GLubyte b;
const static Color3B WHITE;
const static Color3B YELLOW;
const static Color3B BLUE;
const static Color3B GREEN;
const static Color3B RED;
const static Color3B MAGENTA;
const static Color3B BLACK;
const static Color3B ORANGE;
const static Color3B GRAY;
static const Color3B WHITE;
static const Color3B YELLOW;
static const Color3B BLUE;
static const Color3B GREEN;
static const Color3B RED;
static const Color3B MAGENTA;
static const Color3B BLACK;
static const Color3B ORANGE;
static const Color3B GRAY;
};
/** RGBA color composed of 4 bytes
@ -98,15 +99,15 @@ struct Color4B
GLubyte b;
GLubyte a;
const static Color4B WHITE;
const static Color4B YELLOW;
const static Color4B BLUE;
const static Color4B GREEN;
const static Color4B RED;
const static Color4B MAGENTA;
const static Color4B BLACK;
const static Color4B ORANGE;
const static Color4B GRAY;
static const Color4B WHITE;
static const Color4B YELLOW;
static const Color4B BLUE;
static const Color4B GREEN;
static const Color4B RED;
static const Color4B MAGENTA;
static const Color4B BLACK;
static const Color4B ORANGE;
static const Color4B GRAY;
};
@ -137,15 +138,15 @@ struct Color4F
GLfloat b;
GLfloat a;
const static Color4F WHITE;
const static Color4F YELLOW;
const static Color4F BLUE;
const static Color4F GREEN;
const static Color4F RED;
const static Color4F MAGENTA;
const static Color4F BLACK;
const static Color4F ORANGE;
const static Color4F GRAY;
static const Color4F WHITE;
static const Color4F YELLOW;
static const Color4F BLUE;
static const Color4F GREEN;
static const Color4F RED;
static const Color4F MAGENTA;
static const Color4F BLACK;
static const Color4F ORANGE;
static const Color4F GRAY;
};
/** A vertex composed of 2 floats: x, y
@ -334,13 +335,13 @@ struct BlendFunc
GLenum dst;
//! Blending disabled. Uses {GL_ONE, GL_ZERO}
const static BlendFunc DISABLE;
static const BlendFunc DISABLE;
//! Blending enabled for textures with Alpha premultiplied. Uses {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}
const static BlendFunc ALPHA_PREMULTIPLIED;
static const BlendFunc ALPHA_PREMULTIPLIED;
//! Blending enabled for textures with Alpha NON premultiplied. Uses {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
const static BlendFunc ALPHA_NON_PREMULTIPLIED;
static const BlendFunc ALPHA_NON_PREMULTIPLIED;
//! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
const static BlendFunc ADDITIVE;
static const BlendFunc ADDITIVE;
bool operator==(const BlendFunc &a) const
{
@ -484,6 +485,7 @@ public:
@brief The device accelerometer reports values for each axis in units of g-force
*/
class Acceleration
: public Ref
{
public:
double x;

View File

@ -31,7 +31,7 @@ NS_CC_BEGIN
const char* cocos2dVersion()
{
return "cocos2d-x 3.2alpha0";
return "cocos2d-x 3.2beta0";
}
NS_CC_END

View File

@ -253,6 +253,8 @@ THE SOFTWARE.
#include "2d/CCTMXTiledMap.h"
#include "2d/CCTMXXMLParser.h"
#include "2d/CCTileMapAtlas.h"
#include "2d/CCFastTMXTiledMap.h"
#include "2d/CCFastTMXLayer.h"
// component
#include "2d/CCComponent.h"
@ -261,6 +263,10 @@ THE SOFTWARE.
//3d
#include "3d/CCSprite3D.h"
#include "3d/CCMesh.h"
#include "3d/CCMeshSkin.h"
#include "3d/CCAnimate3D.h"
#include "3d/CCAnimation3D.h"
#include "3d/CCSprite3DMaterial.h"
// Audio
#include "audio/include/SimpleAudioEngine.h"

View File

@ -1020,7 +1020,7 @@ CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLEnableVertexAttribs(unsigned int
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLBindTexture2D(GLuint textureId) { GL::bindTexture2D(textureId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLBindTexture2DN(GLuint textureUnit, GLuint textureId) { GL::bindTexture2DN(textureUnit, textureId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLDeleteTexture(GLuint textureId) { GL::deleteTexture(textureId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLDeleteTextureN(GLuint textureUnit, GLuint textureId) { GL::deleteTextureN(textureUnit, textureId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLDeleteTextureN(GLuint textureUnit, GLuint textureId) { GL::deleteTexture(textureId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLBindVAO(GLuint vaoId) { GL::bindVAO(vaoId); }
CC_DEPRECATED_ATTRIBUTE inline void CC_DLL ccGLEnable( int flags ) { /* ignore */ };
CC_DEPRECATED_ATTRIBUTE typedef int ccGLServerState;

View File

@ -97,7 +97,7 @@ unsigned int __Dictionary::count()
__Array* __Dictionary::allKeys()
{
int iKeyCount = this->count();
if (iKeyCount <= 0) return NULL;
if (iKeyCount <= 0) return nullptr;
__Array* array = __Array::createWithCapacity(iKeyCount);
@ -127,7 +127,7 @@ __Array* __Dictionary::allKeys()
__Array* __Dictionary::allKeysForObject(Ref* object)
{
int iKeyCount = this->count();
if (iKeyCount <= 0) return NULL;
if (iKeyCount <= 0) return nullptr;
__Array* array = __Array::create();
DictElement *pElement, *tmp;
@ -161,16 +161,16 @@ __Array* __Dictionary::allKeysForObject(Ref* object)
Ref* __Dictionary::objectForKey(const std::string& key)
{
// if dictionary wasn't initialized, return NULL directly.
if (_dictType == kDictUnknown) return NULL;
// if dictionary wasn't initialized, return nullptr directly.
if (_dictType == kDictUnknown) return nullptr;
// __Dictionary only supports one kind of key, string or integer.
// This method uses string as key, therefore we should make sure that the key type of this __Dictionary is string.
CCASSERT(_dictType == kDictStr, "this dictionary does not use string as key.");
Ref* pRetObject = NULL;
DictElement *pElement = NULL;
Ref* pRetObject = nullptr;
DictElement *pElement = nullptr;
HASH_FIND_STR(_elements, key.c_str(), pElement);
if (pElement != NULL)
if (pElement != nullptr)
{
pRetObject = pElement->_object;
}
@ -179,16 +179,16 @@ Ref* __Dictionary::objectForKey(const std::string& key)
Ref* __Dictionary::objectForKey(intptr_t key)
{
// if dictionary wasn't initialized, return NULL directly.
if (_dictType == kDictUnknown) return NULL;
// if dictionary wasn't initialized, return nullptr directly.
if (_dictType == kDictUnknown) return nullptr;
// __Dictionary only supports one kind of key, string or integer.
// This method uses integer as key, therefore we should make sure that the key type of this __Dictionary is integer.
CCASSERT(_dictType == kDictInt, "this dictionary does not use integer as key.");
Ref* pRetObject = NULL;
DictElement *pElement = NULL;
Ref* pRetObject = nullptr;
DictElement *pElement = nullptr;
HASH_FIND_PTR(_elements, &key, pElement);
if (pElement != NULL)
if (pElement != nullptr)
{
pRetObject = pElement->_object;
}
@ -198,7 +198,7 @@ Ref* __Dictionary::objectForKey(intptr_t key)
const __String* __Dictionary::valueForKey(const std::string& key)
{
__String* pStr = dynamic_cast<__String*>(objectForKey(key));
if (pStr == NULL)
if (pStr == nullptr)
{
pStr = __String::create("");
}
@ -208,7 +208,7 @@ const __String* __Dictionary::valueForKey(const std::string& key)
const __String* __Dictionary::valueForKey(intptr_t key)
{
__String* pStr = dynamic_cast<__String*>(objectForKey(key));
if (pStr == NULL)
if (pStr == nullptr)
{
pStr = __String::create("");
}
@ -217,7 +217,7 @@ const __String* __Dictionary::valueForKey(intptr_t key)
void __Dictionary::setObject(Ref* pObject, const std::string& key)
{
CCASSERT(key.length() > 0 && pObject != NULL, "Invalid Argument!");
CCASSERT(key.length() > 0 && pObject != nullptr, "Invalid Argument!");
if (_dictType == kDictUnknown)
{
_dictType = kDictStr;
@ -225,9 +225,9 @@ void __Dictionary::setObject(Ref* pObject, const std::string& key)
CCASSERT(_dictType == kDictStr, "this dictionary doesn't use string as key.");
DictElement *pElement = NULL;
DictElement *pElement = nullptr;
HASH_FIND_STR(_elements, key.c_str(), pElement);
if (pElement == NULL)
if (pElement == nullptr)
{
setObjectUnSafe(pObject, key);
}
@ -243,7 +243,7 @@ void __Dictionary::setObject(Ref* pObject, const std::string& key)
void __Dictionary::setObject(Ref* pObject, intptr_t key)
{
CCASSERT(pObject != NULL, "Invalid Argument!");
CCASSERT(pObject != nullptr, "Invalid Argument!");
if (_dictType == kDictUnknown)
{
_dictType = kDictInt;
@ -251,9 +251,9 @@ void __Dictionary::setObject(Ref* pObject, intptr_t key)
CCASSERT(_dictType == kDictInt, "this dictionary doesn't use integer as key.");
DictElement *pElement = NULL;
DictElement *pElement = nullptr;
HASH_FIND_PTR(_elements, &key, pElement);
if (pElement == NULL)
if (pElement == nullptr)
{
setObjectUnSafe(pObject, key);
}
@ -277,7 +277,7 @@ void __Dictionary::removeObjectForKey(const std::string& key)
CCASSERT(_dictType == kDictStr, "this dictionary doesn't use string as its key");
CCASSERT(key.length() > 0, "Invalid Argument!");
DictElement *pElement = NULL;
DictElement *pElement = nullptr;
HASH_FIND_STR(_elements, key.c_str(), pElement);
removeObjectForElememt(pElement);
}
@ -290,7 +290,7 @@ void __Dictionary::removeObjectForKey(intptr_t key)
}
CCASSERT(_dictType == kDictInt, "this dictionary doesn't use integer as its key");
DictElement *pElement = NULL;
DictElement *pElement = nullptr;
HASH_FIND_PTR(_elements, &key, pElement);
removeObjectForElememt(pElement);
}
@ -311,7 +311,7 @@ void __Dictionary::setObjectUnSafe(Ref* pObject, const intptr_t key)
void __Dictionary::removeObjectsForKeys(__Array* pKey__Array)
{
Ref* pObj = NULL;
Ref* pObj = nullptr;
CCARRAY_FOREACH(pKey__Array, pObj)
{
__String* pStr = static_cast<__String*>(pObj);
@ -321,7 +321,7 @@ void __Dictionary::removeObjectsForKeys(__Array* pKey__Array)
void __Dictionary::removeObjectForElememt(DictElement* pElement)
{
if (pElement != NULL)
if (pElement != nullptr)
{
HASH_DEL(_elements, pElement);
pElement->_object->release();
@ -345,7 +345,7 @@ Ref* __Dictionary::randomObject()
{
if (_dictType == kDictUnknown)
{
return NULL;
return nullptr;
}
Ref* key = allKeys()->getRandomObject();
@ -360,7 +360,7 @@ Ref* __Dictionary::randomObject()
}
else
{
return NULL;
return nullptr;
}
}
@ -566,9 +566,9 @@ __Dictionary* __Dictionary::clone() const
{
__Dictionary* newDict = __Dictionary::create();
DictElement* element = NULL;
Ref* tmpObj = NULL;
Clonable* obj = NULL;
DictElement* element = nullptr;
Ref* tmpObj = nullptr;
Clonable* obj = nullptr;
if (_dictType == kDictInt)
{
CCDICT_FOREACH(this, element)

View File

@ -66,7 +66,7 @@ __Set * __Set::create()
{
__Set * pRet = new __Set();
if (pRet != NULL)
if (pRet != nullptr)
{
pRet->autorelease();
}

View File

@ -69,7 +69,7 @@ bool __String::initWithFormatAndValist(const char* format, va_list ap)
{
bool bRet = false;
char* pBuf = (char*)malloc(kMaxStringLen);
if (pBuf != NULL)
if (pBuf != nullptr)
{
vsnprintf(pBuf, kMaxStringLen, format, ap);
_string = pBuf;
@ -170,7 +170,7 @@ void __String::appendWithFormat(const char* format, ...)
va_start(ap, format);
char* pBuf = (char*)malloc(kMaxStringLen);
if (pBuf != NULL)
if (pBuf != nullptr)
{
vsnprintf(pBuf, kMaxStringLen, format, ap);
_string.append(pBuf);
@ -207,7 +207,7 @@ bool __String::isEqual(const Ref* pObject)
{
bool bRet = false;
const __String* pStr = dynamic_cast<const __String*>(pObject);
if (pStr != NULL)
if (pStr != nullptr)
{
if (0 == _string.compare(pStr->_string))
{
@ -226,11 +226,11 @@ __String* __String::create(const std::string& str)
__String* __String::createWithData(const unsigned char* data, size_t nLen)
{
__String* ret = NULL;
if (data != NULL)
__String* ret = nullptr;
if (data != nullptr)
{
char* pStr = (char*)malloc(nLen+1);
if (pStr != NULL)
if (pStr != nullptr)
{
pStr[nLen] = '\0';
if (nLen > 0)

View File

@ -86,15 +86,15 @@ void ControlButtonLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, con
void ControlButtonLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::NORMAL);
}
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::HIGH_LIGHTED);
}
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::DISABLED);
}
} else {

View File

@ -10,15 +10,15 @@ namespace cocosbuilder {
void MenuItemImageLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_NORMALDISPLAYFRAME) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((MenuItemImage *)pNode)->setNormalSpriteFrame(pSpriteFrame);
}
} else if(strcmp(pPropertyName, PROPERTY_SELECTEDDISPLAYFRAME) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((MenuItemImage *)pNode)->setSelectedSpriteFrame(pSpriteFrame);
}
} else if(strcmp(pPropertyName, PROPERTY_DISABLEDDISPLAYFRAME) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((MenuItemImage *)pNode)->setDisabledSpriteFrame(pSpriteFrame);
}
} else {

View File

@ -9,7 +9,7 @@ namespace cocosbuilder {
void MenuItemLoader::onHandlePropTypeBlock(Node * pNode, Node * pParent, const char * pPropertyName, BlockData * pBlockData, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_BLOCK) == 0) {
if (NULL != pBlockData) // Add this condition to allow MenuItemImage without target/selector predefined
if (nullptr != pBlockData) // Add this condition to allow MenuItemImage without target/selector predefined
{
((MenuItem *)pNode)->setCallback( std::bind( pBlockData->mSELMenuHandler, pBlockData->_target, std::placeholders::_1) );
// ((MenuItem *)pNode)->setTarget(pBlockData->_target, pBlockData->mSELMenuHandler);

View File

@ -71,7 +71,7 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe
// #endif
// Forward properties for sub ccb files
if (dynamic_cast<CCBFile*>(pNode) != NULL)
if (dynamic_cast<CCBFile*>(pNode) != nullptr)
{
CCBFile *ccbNode = (CCBFile*)pNode;
if (ccbNode->getCCBFileNode() && isExtraProp)
@ -80,7 +80,7 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe
// Skip properties that doesn't have a value to override
__Array *extraPropsNames = (__Array*)pNode->getUserObject();
Ref* pObj = NULL;
Ref* pObj = nullptr;
bool bFound = false;
CCARRAY_FOREACH(extraPropsNames, pObj)
{
@ -346,7 +346,7 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe
case CCBReader::PropertyType::BLOCK_CONTROL:
{
BlockControlData * blockControlData = this->parsePropTypeBlockControl(pNode, pParent, ccbReader);
if(setProp && blockControlData != NULL) {
if(setProp && blockControlData != nullptr) {
this->onHandlePropTypeBlockControl(pNode, pParent, propertyName.c_str(), blockControlData, ccbReader);
}
CC_SAFE_DELETE(blockControlData);
@ -574,14 +574,14 @@ SpriteFrame * NodeLoader::parsePropTypeSpriteFrame(Node * pNode, Node * pParent,
std::string spriteSheet = ccbReader->readCachedString();
std::string spriteFile = ccbReader->readCachedString();
SpriteFrame *spriteFrame = NULL;
SpriteFrame *spriteFrame = nullptr;
if (spriteFile.length() != 0)
{
if (spriteSheet.length() == 0)
{
spriteFile = ccbReader->getCCBRootPath() + spriteFile;
Texture2D * texture = Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
if(texture != NULL) {
if(texture != nullptr) {
Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
}
@ -613,7 +613,7 @@ Animation * NodeLoader::parsePropTypeAnimation(Node * pNode, Node * pParent, CCB
std::string animationFile = ccbReader->getCCBRootPath() + ccbReader->readCachedString();
std::string animation = ccbReader->readCachedString();
Animation * ccAnimation = NULL;
Animation * ccAnimation = nullptr;
// Support for stripping relative file paths, since ios doesn't currently
// know what to do with them, since its pulling from bundle.
@ -642,7 +642,7 @@ Texture2D * NodeLoader::parsePropTypeTexture(Node * pNode, Node * pParent, CCBRe
}
else
{
return NULL;
return nullptr;
}
}
@ -761,7 +761,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
if(selectorTarget != CCBReader::TargetType::NONE)
{
Ref* target = NULL;
Ref* target = nullptr;
if(!ccbReader->isJSControlled())
{
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
@ -773,7 +773,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
target = ccbReader->getOwner();
}
if(target != NULL)
if(target != nullptr)
{
if(selectorName.length() > 0)
{
@ -781,7 +781,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
if(targetAsCCBSelectorResolver != NULL)
if(targetAsCCBSelectorResolver != nullptr)
{
selMenuHandler = targetAsCCBSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
}
@ -789,7 +789,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
if(selMenuHandler == 0)
{
CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
if(ccbSelectorResolver != NULL)
if(ccbSelectorResolver != nullptr)
{
selMenuHandler = ccbSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
}
@ -809,7 +809,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
CCLOG("Unexpected empty selector.");
}
} else {
CCLOG("Unexpected NULL target for selector.");
CCLOG("Unexpected nullptr target for selector.");
}
}
else
@ -831,7 +831,7 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
}
}
return NULL;
return nullptr;
}
BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pParent, CCBReader * ccbReader)
@ -844,7 +844,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
{
if(!ccbReader->isJSControlled())
{
Ref* target = NULL;
Ref* target = nullptr;
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
{
target = ccbReader->getAnimationManager()->getRootNode();
@ -854,7 +854,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
target = ccbReader->getOwner();
}
if(target != NULL)
if(target != nullptr)
{
if(selectorName.length() > 0)
{
@ -862,7 +862,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
if(targetAsCCBSelectorResolver != NULL)
if(targetAsCCBSelectorResolver != nullptr)
{
selControlHandler = targetAsCCBSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
}
@ -870,7 +870,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
if(selControlHandler == 0)
{
CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
if(ccbSelectorResolver != NULL)
if(ccbSelectorResolver != nullptr)
{
selControlHandler = ccbSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
}
@ -894,7 +894,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
CCLOG("Unexpected empty selector.");
}
} else {
CCLOG("Unexpected NULL target for selector.");
CCLOG("Unexpected nullptr target for selector.");
}
}
else
@ -914,7 +914,7 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
}
}
return NULL;
return nullptr;
}
Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader * pCCBReader) {
@ -960,7 +960,7 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
reader->getAnimationManager()->runAnimationsForSequenceIdTweenDuration(reader->getAnimationManager()->getAutoPlaySequenceId(), 0);
}
if (reader->isJSControlled() && pCCBReader->isJSControlled() && NULL == reader->_owner)
if (reader->isJSControlled() && pCCBReader->isJSControlled() && nullptr == reader->_owner)
{
//set variables and callback to owner
//set callback

View File

@ -79,10 +79,10 @@ void NodeLoaderLibrary::purge(bool pReleaseNodeLoaders) {
static NodeLoaderLibrary * sSharedNodeLoaderLibrary = NULL;
static NodeLoaderLibrary * sSharedNodeLoaderLibrary = nullptr;
NodeLoaderLibrary * NodeLoaderLibrary::getInstance() {
if(sSharedNodeLoaderLibrary == NULL) {
if(sSharedNodeLoaderLibrary == nullptr) {
sSharedNodeLoaderLibrary = new NodeLoaderLibrary();
sSharedNodeLoaderLibrary->registerDefaultNodeLoaders();

View File

@ -12,10 +12,10 @@ namespace cocosbuilder {
void SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_DISPLAYFRAME) == 0) {
if(pSpriteFrame != NULL) {
if(pSpriteFrame != nullptr) {
((Sprite *)pNode)->setSpriteFrame(pSpriteFrame);
} else {
CCLOG("ERROR: SpriteFrame NULL");
CCLOG("ERROR: SpriteFrame nullptr");
}
} else {
NodeLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);

View File

@ -278,8 +278,8 @@ void ActionTimeline::emitFrameEvent(Frame* frame)
void ActionTimeline::gotoFrame(int frameIndex)
{
int size = _timelineList.size();
for(int i = 0; i<size; i++)
ssize_t size = _timelineList.size();
for(ssize_t i = 0; i < size; i++)
{
_timelineList.at(i)->gotoFrame(frameIndex);
}
@ -287,8 +287,8 @@ void ActionTimeline::gotoFrame(int frameIndex)
void ActionTimeline::stepToFrame(int frameIndex)
{
int size = _timelineList.size();
for(int i = 0; i<size; i++)
ssize_t size = _timelineList.size();
for(ssize_t i = 0; i < size; i++)
{
_timelineList.at(i)->stepToFrame(frameIndex);
}

View File

@ -68,7 +68,7 @@ VisibleFrame* VisibleFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
VisibleFrame::VisibleFrame()
@ -104,7 +104,7 @@ TextureFrame* TextureFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
TextureFrame::TextureFrame()
@ -155,7 +155,7 @@ RotationFrame* RotationFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
RotationFrame::RotationFrame()
@ -204,7 +204,7 @@ SkewFrame* SkewFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
SkewFrame::SkewFrame()
@ -261,7 +261,7 @@ RotationSkewFrame* RotationSkewFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
RotationSkewFrame::RotationSkewFrame()
@ -314,7 +314,7 @@ PositionFrame* PositionFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
PositionFrame::PositionFrame()
@ -366,7 +366,7 @@ ScaleFrame* ScaleFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
ScaleFrame::ScaleFrame()
@ -421,7 +421,7 @@ AnchorPointFrame* AnchorPointFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
AnchorPointFrame::AnchorPointFrame()
@ -457,7 +457,7 @@ InnerActionFrame* InnerActionFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
InnerActionFrame::InnerActionFrame()
@ -493,7 +493,7 @@ ColorFrame* ColorFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
ColorFrame::ColorFrame()
@ -559,7 +559,7 @@ EventFrame* EventFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
EventFrame::EventFrame()
@ -594,7 +594,7 @@ ZOrderFrame* ZOrderFrame::create()
return frame;
}
CC_SAFE_DELETE(frame);
return NULL;
return nullptr;
}
ZOrderFrame::ZOrderFrame()
@ -605,7 +605,7 @@ ZOrderFrame::ZOrderFrame()
void ZOrderFrame::onEnter(Frame *nextFrame)
{
if(_node)
_node->setZOrder(_zorder);
_node->setLocalZOrder(_zorder);
}

View File

@ -284,9 +284,9 @@ void NodeReader::initNode(Node* node, const rapidjson::Value& json)
if (rotation != 0)
node->setRotation(rotation);
if(rotationSkewX != 0)
node->setRotationX(rotationSkewX);
node->setRotationSkewX(rotationSkewX);
if(rotationSkewY != 0)
node->setRotationY(rotationSkewY);
node->setRotationSkewY(rotationSkewY);
if(skewx != 0)
node->setSkewX(skewx);
if(skewy != 0)
@ -296,19 +296,17 @@ void NodeReader::initNode(Node* node, const rapidjson::Value& json)
if(width != 0 || height != 0)
node->setContentSize(Size(width, height));
if(zorder != 0)
node->setZOrder(zorder);
node->setLocalZOrder(zorder);
if(visible != true)
node->setVisible(visible);
if(alpha != 255)
{
node->setOpacity(alpha);
node->setCascadeOpacityEnabled(true);
}
if(red != 255 || green != 255 || blue != 255)
{
node->setColor(Color3B(red, green, blue));
node->setCascadeColorEnabled(true);
}

View File

@ -104,7 +104,7 @@ void Timeline::insertFrame(Frame* frame, int index)
void Timeline::removeFrame(Frame* frame)
{
_frames.eraseObject(frame);
frame->setTimeline(NULL);
frame->setTimeline(nullptr);
}
void Timeline::setNode(Node* node)
@ -131,8 +131,8 @@ void Timeline::apply(int frameIndex)
void Timeline::binarySearchKeyFrame(int frameIndex)
{
Frame *from = NULL;
Frame *to = NULL;
Frame *from = nullptr;
Frame *to = nullptr;
long length = _frames.size();
bool needEnterFrame = false;

View File

@ -402,9 +402,9 @@ void Armature::draw(cocos2d::Renderer *renderer, const Mat4 &transform, uint32_t
Skin *skin = static_cast<Skin *>(node);
skin->updateTransform();
bool blendDirty = bone->isBlendDirty();
BlendFunc func = bone->getBlendFunc();
if (blendDirty)
if (func.src != _blendFunc.src || func.dst != _blendFunc.dst)
{
skin->setBlendFunc(bone->getBlendFunc());
}

View File

@ -201,8 +201,8 @@ void Bone::update(float delta)
_worldInfo->y = _tweenData->y + _position.y;
_worldInfo->scaleX = _tweenData->scaleX * _scaleX;
_worldInfo->scaleY = _tweenData->scaleY * _scaleY;
_worldInfo->skewX = _tweenData->skewX + _skewX + _rotationX;
_worldInfo->skewY = _tweenData->skewY + _skewY - _rotationY;
_worldInfo->skewX = _tweenData->skewX + _skewX + _rotationZ_X;
_worldInfo->skewY = _tweenData->skewY + _skewY - _rotationZ_Y;
if(_parentBone)
{

View File

@ -1311,7 +1311,7 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
length = DICTOOL->getArrayCount_json(json, CONFIG_FILE_PATH); // json[CONFIG_FILE_PATH].IsNull() ? 0 : json[CONFIG_FILE_PATH].Size();
for (int i = 0; i < length; i++)
{
const char *path = DICTOOL->getStringValueFromArray_json(json, CONFIG_FILE_PATH, i); // json[CONFIG_FILE_PATH][i].IsNull() ? NULL : json[CONFIG_FILE_PATH][i].GetString();
const char *path = DICTOOL->getStringValueFromArray_json(json, CONFIG_FILE_PATH, i); // json[CONFIG_FILE_PATH][i].IsNull() ? nullptr : json[CONFIG_FILE_PATH][i].GetString();
if (path == nullptr)
{
CCLOG("load CONFIG_FILE_PATH error.");
@ -2426,21 +2426,21 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
else if (key.compare(A_HEIGHT) == 0)
{
if(str != NULL)
if(str != nullptr)
{
textureData->height = atof(str);
}
}
else if (key.compare(A_PIVOT_X) == 0)
{
if(str != NULL)
if(str != nullptr)
{
textureData->pivotX = atof(str);
}
}
else if (key.compare(A_PIVOT_Y) == 0)
{
if(str != NULL)
if(str != nullptr)
{
textureData->pivotY = atof(str);
}

View File

@ -351,7 +351,7 @@ Widget* GUIReader::widgetFromBinaryFile(const char *fileName)
const char* fileVersion = "";
ui::Widget* widget = nullptr;
if (pBuffer != NULL && nSize > 0)
if (pBuffer != nullptr && nSize > 0)
{
CocoLoader tCocoLoader;
if(true == tCocoLoader.ReadCocoBinBuff((char*)pBuffer))
@ -494,7 +494,7 @@ Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, c
if (widget->getContentSize().equals(Size::ZERO))
{
Layout* rootWidget = dynamic_cast<Layout*>(widget);
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
rootWidget->setContentSize(Size(fileDesignWidth, fileDesignHeight));
}
/* ********************** */
@ -608,7 +608,7 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget*widg
float w = DICTOOL->getFloatValue_json(options, "width");
float h = DICTOOL->getFloatValue_json(options, "height");
widget->setSize(Size(w, h));
widget->setContentSize(Size(w, h));
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
@ -707,7 +707,7 @@ void WidgetPropertiesReader0250::setPropsForButtonFromJsonDictionary(Widget*widg
{
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
button->setSize(Size(swf, shf));
button->setContentSize(Size(swf, shf));
}
}
else
@ -823,7 +823,7 @@ void WidgetPropertiesReader0250::setPropsForImageViewFromJsonDictionary(Widget*w
{
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
imageView->setSize(Size(swf, shf));
imageView->setContentSize(Size(swf, shf));
}
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
@ -1016,7 +1016,7 @@ void WidgetPropertiesReader0250::setPropsForSliderFromJsonDictionary(Widget*widg
{
slider->loadBarTexture(imageFileName_tp);
}
slider->setSize(Size(barLength, slider->getContentSize().height));
slider->setContentSize(Size(barLength, slider->getContentSize().height));
}
else
{
@ -1204,7 +1204,7 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
if (widget->getContentSize().equals(Size::ZERO))
{
Layout* rootWidget = dynamic_cast<Layout*>(widget);
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
rootWidget->setContentSize(Size(fileDesignWidth, fileDesignHeight));
}
/* ********************** */
@ -1268,7 +1268,7 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
if (widget->getContentSize().equals(Size::ZERO))
{
Layout* rootWidget = dynamic_cast<Layout*>(widget);
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
rootWidget->setContentSize(Size(fileDesignWidth, fileDesignHeight));
}
}
}
@ -1340,7 +1340,7 @@ Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* cocoLoader, st
setPropsForAllWidgetFromBinary(reader, widget, cocoLoader, optionsNode);
// 2nd., custom widget parse with custom reader
//2nd. parse custom property
const char* customProperty = NULL;
const char* customProperty = nullptr;
stExpCocoNode *optionChildNode = optionsNode->GetChildArray(cocoLoader);
for (int k = 0; k < optionsNode->GetChildNum(); ++k) {
std::string key = optionChildNode[k].GetName(cocoLoader);
@ -1459,7 +1459,7 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va
}
setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict);
}else{
CCLOG("Widget or WidgetReader doesn't exists!!! Please check your csb file.");
CCLOG("Widget or WidgetReader doesn't exists!!! Please check your json file.");
}
}

View File

@ -531,7 +531,7 @@ void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode
else if (key == "zorder")
{
nZorder = atoi(value.c_str());
node->setZOrder(nZorder);
node->setLocalZOrder(nZorder);
}
else if(key == "scalex")
{

View File

@ -92,7 +92,7 @@ Type stExpCocoNode::GetType(CocoLoader* pCoco)
char* stExpCocoNode::GetName(CocoLoader* pCoco)
{
char* szName = NULL ;
char* szName = nullptr ;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
@ -132,9 +132,15 @@ char* stExpCocoNode::GetName(CocoLoader* pCoco)
char* stExpCocoNode::GetValue(CocoLoader* pCoco)
{
return ( pCoco->GetMemoryAddr_String() + m_szValue );
char* szValue = ( pCoco->GetMemoryAddr_String() + m_szValue );
if( 0==strcmp(szValue,"null") && GetType(pCoco) == kStringType )
{
strcpy(szValue,"");
}
return szValue;
}
int stExpCocoNode::GetChildNum()
{
return m_ChildNum;
@ -147,9 +153,9 @@ stExpCocoNode* stExpCocoNode::GetChildArray(CocoLoader* pCoco)
CocoLoader::CocoLoader()
{
m_pRootNode = NULL;
m_pObjectDescArray = NULL;
m_pMemoryBuff = NULL;
m_pRootNode = nullptr;
m_pObjectDescArray = nullptr;
m_pMemoryBuff = nullptr;
}
CocoLoader::~CocoLoader()
@ -157,7 +163,7 @@ CocoLoader::~CocoLoader()
if(m_pMemoryBuff)
{
delete[] m_pMemoryBuff;
m_pMemoryBuff = NULL;
m_pMemoryBuff = nullptr;
}
}
@ -176,7 +182,7 @@ bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
char* pDestBuff = new char[m_pFileHeader->m_nDataSize];
uLongf dwSrcSize = m_pFileHeader->m_nCompressSize;
uLongf dwDestSize = m_pFileHeader->m_nDataSize;
int nRes = uncompress((Bytef*)pDestBuff,&dwDestSize,(Bytef*)m_pMemoryBuff,dwSrcSize);
uncompress((Bytef*)pDestBuff,&dwDestSize,(Bytef*)m_pMemoryBuff,dwSrcSize);
pStartAddr = m_pMemoryBuff = pDestBuff;
}
@ -198,7 +204,7 @@ stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(const char* szObjDesc)
return &m_pObjectDescArray[i];
}
}
return NULL;
return nullptr;
}
stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(int vIndex)
@ -207,7 +213,7 @@ stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(int vIndex)
{
return &m_pObjectDescArray[vIndex];
}
return NULL;
return nullptr;
}
char* CocoLoader::GetMemoryAddr_AttribDesc()

View File

@ -115,7 +115,7 @@ void TriggerMng::parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCoc
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
bool useBindings = engine != NULL;
bool useBindings = engine != nullptr;
if (useBindings)
{
@ -234,7 +234,7 @@ bool TriggerMng::isEmpty(void) const
const char *str2 = pActionArray[i3].GetValue(pCocoLoader);
if (key2.compare("classname") == 0)
{
if (str2 != NULL)
if (str2 != nullptr)
{
action.AddMember("classname", str2, allocator);
}
@ -255,7 +255,7 @@ bool TriggerMng::isEmpty(void) const
const char *str3 = pDataItemArray[i5].GetValue(pCocoLoader);
if (key3.compare("key") == 0)
{
if (str3 != NULL)
if (str3 != nullptr)
{
dataitem.AddMember("key", str3, allocator);
}
@ -310,7 +310,7 @@ bool TriggerMng::isEmpty(void) const
const char *str4 = pConditionArray[i7].GetValue(pCocoLoader);
if (key4.compare("classname") == 0)
{
if (str4 != NULL)
if (str4 != nullptr)
{
cond.AddMember("classname", str4, allocator);
}
@ -331,7 +331,7 @@ bool TriggerMng::isEmpty(void) const
const char *str5 = pDataItemArray[i9].GetValue(pCocoLoader);
if (key5.compare("key") == 0)
{
if (str5 != NULL)
if (str5 != nullptr)
{
dataitem.AddMember("key", str5, allocator);
}
@ -380,7 +380,7 @@ bool TriggerMng::isEmpty(void) const
stExpCocoNode *pEventArray = pEventsArray->GetChildArray(pCocoLoader);
std::string key6 = pEventArray[0].GetName(pCocoLoader);
const char *str6 = pEventArray[0].GetValue(pCocoLoader);
if (key6.compare("id") == 0 && str6 != NULL)
if (key6.compare("id") == 0 && str6 != nullptr)
{
event.AddMember("id", atoi(str6), allocator);
eventsItem.PushBack(event, allocator);
@ -390,7 +390,7 @@ bool TriggerMng::isEmpty(void) const
}
else if (key1.compare("id") == 0)
{
if (str1 != NULL)
if (str1 != nullptr)
{
vElemItem.AddMember("id", atoi(str1), allocator);
}

View File

@ -253,7 +253,7 @@ void TriggerObj::serialize(const rapidjson::Value &val)
const char* str0 = pTriggerObjArray[i0].GetValue(pCocoLoader);
if (key.compare("id") == 0)
{
if (str0 != NULL)
if (str0 != nullptr)
{
_id = atoi(str0); //(unsigned int)(DICTOOL->getIntValue_json(val, "id"));
}
@ -292,7 +292,7 @@ void TriggerObj::serialize(const rapidjson::Value &val)
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(act != NULL, "class named classname can not implement!");
CCAssert(act != nullptr, "class named classname can not implement!");
act->serialize(pCocoLoader, &pActionArray[1]);
act->init();
_acts.pushBack(act);

View File

@ -152,7 +152,7 @@ namespace cocostudio
if (button->isScale9Enabled()) {
button->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
button->setSize(Size(scale9Width, scale9Height));
button->setContentSize(Size(scale9Width, scale9Height));
}
button->setTitleColor(Color3B(cri, cgi, cbi));
@ -203,7 +203,7 @@ namespace cocostudio
{
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width);
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height);
button->setSize(Size(swf, shf));
button->setContentSize(Size(swf, shf));
}
}
bool tt = DICTOOL->checkObjectExist_json(options, P_Text);

View File

@ -15,7 +15,7 @@ namespace cocostudio
static const char* P_BackGroundBoxDisabledData = "backGroundBoxDisabledData";
static const char* P_FrontCrossDisabledData = "frontCrossDisabledData";
static CheckBoxReader* instanceCheckBoxReader = NULL;
static CheckBoxReader* instanceCheckBoxReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader)

View File

@ -19,7 +19,7 @@ namespace cocostudio
static const char* P_Scale9Height = "scale9Height";
static ImageViewReader* instanceImageViewReader = NULL;
static ImageViewReader* instanceImageViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader)
@ -128,7 +128,7 @@ namespace cocostudio
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width,80.0f);
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height,80.0f);
imageView->setSize(Size(swf, shf));
imageView->setContentSize(Size(swf, shf));
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);

View File

@ -34,7 +34,7 @@ namespace cocostudio
static const char* P_BackGroundImageData = "backGroundImageData";
static const char* P_LayoutType = "layoutType";
static LayoutReader* instanceLayoutReader = NULL;
static LayoutReader* instanceLayoutReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader)
@ -72,7 +72,7 @@ namespace cocostudio
int ecr=0, ecg=0, ecb= 0;
float bgcv1 = 0.0f, bgcv2= 0.0f;
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
Layout::Type layoutType;
Layout::Type layoutType = Layout::Type::ABSOLUTE;
int bgColorOpacity = panel->getBackGroundColorOpacity();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {

View File

@ -12,7 +12,7 @@ namespace cocostudio
static const char* P_Direction = "direction";
static const char* P_ItemMargin = "itemMargin";
static ListViewReader* instanceListViewReader = NULL;
static ListViewReader* instanceListViewReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader)

View File

@ -19,7 +19,7 @@ namespace cocostudio
static const char* P_Direction = "direction";
static const char* P_Percent = "percent";
static LoadingBarReader* instanceLoadingBar = NULL;
static LoadingBarReader* instanceLoadingBar = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
@ -130,7 +130,7 @@ namespace cocostudio
float width = DICTOOL->getFloatValue_json(options, P_Width);
float height = DICTOOL->getFloatValue_json(options, P_Height);
loadingBar->setSize(Size(width, height));
loadingBar->setContentSize(Size(width, height));
/**/

View File

@ -18,9 +18,7 @@ namespace cocostudio
static const char* P_BallDisabledData = "ballDisabledData";
static const char* P_ProgressBarData = "progressBarData";
static const char* P_BarFileName = "barFileName";
static SliderReader* instanceSliderReader = NULL;
static SliderReader* instanceSliderReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
@ -125,7 +123,7 @@ namespace cocostudio
} //end of for loop
if (slider->isScale9Enabled()) {
slider->setSize(Size(barLength, slider->getContentSize().height));
slider->setContentSize(Size(barLength, slider->getContentSize().height));
}
slider->setPercent(percent);

View File

@ -15,10 +15,7 @@ namespace cocostudio
static const char* P_ItemHeight = "itemHeight";
static const char* P_StartCharMap = "startCharMap";
static const char* P_CharMapFile = "charMapFile";
static TextAtlasReader* instanceTextAtalsReader = NULL;
static TextAtlasReader* instanceTextAtalsReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader)

View File

@ -12,7 +12,7 @@ namespace cocostudio
static const char* P_FileNameData = "fileNameData";
static const char* P_Text = "text";
static TextBMFontReader* instanceTextBMFontReader = NULL;
static TextBMFontReader* instanceTextBMFontReader = nullptr;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)

Some files were not shown because too many files have changed in this diff Show More