Merge branch 'v3' into v3_dll

This commit is contained in:
Huabing.Xu 2014-07-11 11:10:26 +08:00
commit 60dd7a4514
549 changed files with 49326 additions and 10796 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.2 ???
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()
@ -32,6 +50,7 @@ cocos2d-x-3.2 ???
[FIX] UIListView: element position is changed a little when you click and up a list view without move
[FIX] UIListView: element will respond to item_end event when end of scrolling a list view
[FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android
[FIX] WP8: crash of utils::captureScreen()
cocos2d-x-3.2-alpha0 Jun.17 2014
[NEW] Console: add a command to show engine version

View File

@ -53,23 +53,7 @@ def check_environment_variables_sdk():
return SDK_ROOT
def select_toolchain_version():
'''Because ndk-r8e uses gcc4.6 as default. gcc4.6 doesn't support c++11. So we should select gcc4.7 when
using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
Conclution:
ndk-r8e -> use gcc4.7
ndk-r9 -> use gcc4.8
'''
ndk_root = check_environment_variables()
if os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.8")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8'
print "The Selected NDK toolchain version was 4.8 !"
elif os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.7")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.7'
print "The Selected NDK toolchain version was 4.7 !"
else:
print "Couldn't find the gcc toolchain."
exit(1)
pass
def caculate_built_samples(args):
''' Compute the sampels to be built

View File

@ -1025,29 +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 */; };
3E6176831960F9C400DE83F5 /* CCNSLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61767C1960F9C400DE83F5 /* CCNSLog.h */; };
3E6176841960F9C400DE83F5 /* CCNSLog.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E61767E1960F9C400DE83F5 /* CCNSLog.mm */; };
3E6176851960F9C400DE83F5 /* LoggerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61767F1960F9C400DE83F5 /* LoggerClient.h */; };
3E6176861960F9C400DE83F5 /* LoggerClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176801960F9C400DE83F5 /* LoggerClient.m */; };
3E6176871960F9C400DE83F5 /* LoggerCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176811960F9C400DE83F5 /* LoggerCommon.h */; };
3E6176881960F9C400DE83F5 /* NSLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176821960F9C400DE83F5 /* NSLogger.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 */; };
@ -2376,29 +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>"; };
3E61767C1960F9C400DE83F5 /* CCNSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNSLog.h; sourceTree = "<group>"; };
3E61767E1960F9C400DE83F5 /* CCNSLog.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCNSLog.mm; sourceTree = "<group>"; };
3E61767F1960F9C400DE83F5 /* LoggerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggerClient.h; sourceTree = "<group>"; };
3E6176801960F9C400DE83F5 /* LoggerClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoggerClient.m; sourceTree = "<group>"; };
3E6176811960F9C400DE83F5 /* LoggerCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggerCommon.h; sourceTree = "<group>"; };
3E6176821960F9C400DE83F5 /* NSLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSLogger.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>"; };
@ -3199,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 */,
@ -3505,7 +3460,6 @@
1A57033E180BD0490088DEC7 /* external */ = {
isa = PBXGroup;
children = (
3E61767B1960F9C400DE83F5 /* nslog */,
1AC026971914068200FA920D /* ConvertUTF */,
46C02E0418E91123004B7456 /* xxhash */,
46A168B21807AF9C005B8026 /* Box2D */,
@ -4189,28 +4143,6 @@
path = internal;
sourceTree = "<group>";
};
3E61767B1960F9C400DE83F5 /* nslog */ = {
isa = PBXGroup;
children = (
3E61767C1960F9C400DE83F5 /* CCNSLog.h */,
3E61767D1960F9C400DE83F5 /* ios */,
);
name = nslog;
path = ../external/nslog;
sourceTree = "<group>";
};
3E61767D1960F9C400DE83F5 /* ios */ = {
isa = PBXGroup;
children = (
3E61767E1960F9C400DE83F5 /* CCNSLog.mm */,
3E61767F1960F9C400DE83F5 /* LoggerClient.h */,
3E6176801960F9C400DE83F5 /* LoggerClient.m */,
3E6176811960F9C400DE83F5 /* LoggerCommon.h */,
3E6176821960F9C400DE83F5 /* NSLogger.h */,
);
path = ios;
sourceTree = "<group>";
};
46A15FD01807A56F005B8026 /* audio */ = {
isa = PBXGroup;
children = (
@ -5606,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 */,
@ -5643,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 */,
@ -5663,7 +5593,6 @@
50ABBD411925AB0000A911A9 /* CCMath.h in Headers */,
1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */,
50ABBD9A1925AB4100A911A9 /* CCGLProgramStateCache.h in Headers */,
3E6176881960F9C400DE83F5 /* NSLogger.h in Headers */,
50ABBD3F1925AB0000A911A9 /* CCGeometry.h in Headers */,
50ABBFFE1926664800A911A9 /* CCFileUtilsApple.h in Headers */,
1A5701A4180BCB590088DEC7 /* CCFontAtlas.h in Headers */,
@ -5712,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 */,
@ -5731,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 */,
@ -5744,8 +5671,6 @@
1A570303180BCE890088DEC7 /* CCParallaxNode.h in Headers */,
50ABBE2A1925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */,
1A57030F180BCF190088DEC7 /* CCComponent.h in Headers */,
3E6176851960F9C400DE83F5 /* LoggerClient.h in Headers */,
3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */,
1A570313180BCF190088DEC7 /* CCComponentContainer.h in Headers */,
0634A4DF194B19E400E608AF /* CCNodeReader.h in Headers */,
1A087AEB1860400400196EF5 /* edtaa3func.h in Headers */,
@ -5759,7 +5684,6 @@
50ABBD4B1925AB0000A911A9 /* Mat4.h in Headers */,
1A01C69B18F57BE800EFE3A6 /* CCSet.h in Headers */,
50ABBED61925AB6F00A911A9 /* utlist.h in Headers */,
3E6176871960F9C400DE83F5 /* LoggerCommon.h in Headers */,
1A57035B180BD0B00088DEC7 /* unzip.h in Headers */,
5034CA48191D591100CE6051 /* ccShader_Label_normal.frag in Headers */,
50ABBD531925AB0000A911A9 /* Quaternion.h in Headers */,
@ -5789,7 +5713,6 @@
50E6D33B18E174130051CA34 /* UIRelativeBox.h in Headers */,
503DD8EB1926736A00CD74DD /* CCGL.h in Headers */,
50ABBE3C1925AB6F00A911A9 /* CCData.h in Headers */,
3E6176831960F9C400DE83F5 /* CCNSLog.h in Headers */,
1AD71DD8180E26E600808F54 /* CCLabelTTFLoader.h in Headers */,
503DD8FA1926B0DB00CD74DD /* CCIMEDispatcher.h in Headers */,
1AD71DDC180E26E600808F54 /* CCLayerColorLoader.h in Headers */,
@ -5854,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 */,
@ -6757,7 +6679,6 @@
2AC795E318628746005EC8E1 /* SkeletonBounds.cpp in Sources */,
2AC795E418628746005EC8E1 /* Event.cpp in Sources */,
2AC795E518628746005EC8E1 /* EventData.cpp in Sources */,
3E6176861960F9C400DE83F5 /* LoggerClient.m in Sources */,
2AC795E618628746005EC8E1 /* BoundingBoxAttachment.cpp in Sources */,
46A171001807CECB005B8026 /* CCPhysicsJoint.cpp in Sources */,
46A171051807CECB005B8026 /* CCPhysicsWorld.cpp in Sources */,
@ -6792,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 */,
@ -6832,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 */,
@ -6842,7 +6763,6 @@
2905FA4B18CF08D100240AA3 /* UICheckBox.cpp in Sources */,
1A5701BE180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */,
1A5701C2180BCB5A0088DEC7 /* CCLabelBMFont.cpp in Sources */,
3E6176841960F9C400DE83F5 /* CCNSLog.mm in Sources */,
1A087AE91860400400196EF5 /* edtaa3func.cpp in Sources */,
B375107E1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */,
1A5701C8180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */,
@ -6872,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 */,
@ -6894,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 */,
@ -7007,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 */,
@ -7046,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 */,

View File

@ -58,6 +58,13 @@
1503FAC418DA8B6C00F6518C /* tp.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB118DA8B6C00F6518C /* tp.lua */; };
1503FAC518DA8B6C00F6518C /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB218DA8B6C00F6518C /* url.lua */; };
1503FAC618DA8B6C00F6518C /* url.lua in Resources */ = {isa = PBXBuildFile; fileRef = 1503FAB218DA8B6C00F6518C /* url.lua */; };
15AECE0B195C0F8A00907DB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA0FB65191B933000B170C8 /* MediaPlayer.framework */; };
15AECE0F195C1FDD00907DB0 /* cocosvideo.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 3EA0FB5D191B92F100B170C8 /* cocosvideo.mp4 */; };
15AECE1F195D0EC500907DB0 /* experimentalConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = 15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */; };
15AECE22195D122400907DB0 /* experimentalConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = 15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */; };
15AECE23195D122600907DB0 /* experimentalConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = 15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */; };
15AECE24195D122700907DB0 /* experimentalConstants.lua in Resources */ = {isa = PBXBuildFile; fileRef = 15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */; };
15AECE25195D467D00907DB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA0FB65191B933000B170C8 /* MediaPlayer.framework */; };
15B0870D195AD52000D6F62B /* ActionTimeline in Resources */ = {isa = PBXBuildFile; fileRef = 38FA2E75194AECF800FF2BE4 /* ActionTimeline */; };
15C64825165F3934007D4F18 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64824165F3934007D4F18 /* OpenGL.framework */; };
15C64827165F394E007D4F18 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64826165F394E007D4F18 /* QuartzCore.framework */; };
@ -827,8 +834,6 @@
3E6177351960FB4000DE83F5 /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176DE1960FA6300DE83F5 /* AppController.mm */; };
3E6177361960FB5A00DE83F5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176EE1960FA6300DE83F5 /* main.m */; };
3E6177371960FB5E00DE83F5 /* RootViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176F01960FA6300DE83F5 /* RootViewController.mm */; };
3E6177391960FBB800DE83F5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E6177381960FBB800DE83F5 /* SystemConfiguration.framework */; };
3E61773B1960FBC300DE83F5 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E61773A1960FBC300DE83F5 /* CFNetwork.framework */; };
3E61773D1960FBD200DE83F5 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E61773C1960FBD100DE83F5 /* GameController.framework */; };
3E6177F41960FEFE00DE83F5 /* fonts in Resources */ = {isa = PBXBuildFile; fileRef = 3E6177F01960FEFE00DE83F5 /* fonts */; };
3E6177F51960FEFE00DE83F5 /* ipad in Resources */ = {isa = PBXBuildFile; fileRef = 3E6177F11960FEFE00DE83F5 /* ipad */; };
@ -1313,6 +1318,7 @@
1503FAB018DA8B6C00F6518C /* socket.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = socket.lua; path = ../external/lua/luasocket/socket.lua; sourceTree = "<group>"; };
1503FAB118DA8B6C00F6518C /* tp.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tp.lua; path = ../external/lua/luasocket/tp.lua; sourceTree = "<group>"; };
1503FAB218DA8B6C00F6518C /* url.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = url.lua; path = ../external/lua/luasocket/url.lua; sourceTree = "<group>"; };
15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = experimentalConstants.lua; path = "../cocos/scripting/lua-bindings/script/experimentalConstants.lua"; sourceTree = "<group>"; };
15C64822165F391E007D4F18 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
15C64824165F3934007D4F18 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; };
15C64826165F394E007D4F18 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; };
@ -2043,6 +2049,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
15AECE25195D467D00907DB0 /* MediaPlayer.framework in Frameworks */,
1A0EE42C18CDF799004CD58F /* libz.dylib in Frameworks */,
1A0EE42D18CDF799004CD58F /* CoreMotion.framework in Frameworks */,
1A0EE42E18CDF799004CD58F /* AudioToolbox.framework in Frameworks */,
@ -2087,6 +2094,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
15AECE0B195C0F8A00907DB0 /* MediaPlayer.framework in Frameworks */,
1ABCA3B018CDA06D0087CE3A /* libz.dylib in Frameworks */,
1ABCA3AA18CD9F1A0087CE3A /* CoreMotion.framework in Frameworks */,
1ABCA3A918CD9F130087CE3A /* AudioToolbox.framework in Frameworks */,
@ -2132,8 +2140,6 @@
buildActionMask = 2147483647;
files = (
3E61773D1960FBD200DE83F5 /* GameController.framework in Frameworks */,
3E61773B1960FBC300DE83F5 /* CFNetwork.framework in Frameworks */,
3E6177391960FBB800DE83F5 /* SystemConfiguration.framework in Frameworks */,
3E6177211960FAED00DE83F5 /* libchipmunk iOS.a in Frameworks */,
3E6177221960FAED00DE83F5 /* libcocos2dx iOS.a in Frameworks */,
3E6177231960FAED00DE83F5 /* libCocosDenshion iOS.a in Frameworks */,
@ -2214,6 +2220,7 @@
1ABCA36418CD9E060087CE3A /* Lua Common */ = {
isa = PBXGroup;
children = (
15AECE1E195D0EC500907DB0 /* experimentalConstants.lua */,
1503FAA918DA8B6C00F6518C /* ftp.lua */,
1503FAAA18DA8B6C00F6518C /* headers.lua */,
1503FAAB18DA8B6C00F6518C /* http.lua */,
@ -4364,6 +4371,7 @@
1AC35D5D18CEDE9E00F37B72 /* MainMenu.xib in Resources */,
1503FABD18DA8B6C00F6518C /* mime.lua in Resources */,
1A0EE56F18CDFBBE004CD58F /* CCBReaderLoad.lua in Resources */,
15AECE23195D122600907DB0 /* experimentalConstants.lua in Resources */,
1A0EE57018CDFBBE004CD58F /* Cocos2d.lua in Resources */,
1A0EE57B18CDFBBE004CD58F /* luaj.lua in Resources */,
1A0EE57918CDFBBE004CD58F /* GuiConstants.lua in Resources */,
@ -4433,6 +4441,7 @@
1A0EE56018CDFBBD004CD58F /* CocoStudio.lua in Resources */,
1A0EE56318CDFBBD004CD58F /* DeprecatedEnum.lua in Resources */,
1503FAB818DA8B6C00F6518C /* http.lua in Resources */,
15AECE22195D122400907DB0 /* experimentalConstants.lua in Resources */,
1AC35D4B18CEDE9400F37B72 /* Icon-144.png in Resources */,
1503FAC618DA8B6C00F6518C /* url.lua in Resources */,
1AC35D4618CEDE9400F37B72 /* Default-568h@2x.png in Resources */,
@ -4477,6 +4486,7 @@
1AC35DBB18CEE65100F37B72 /* components in Resources */,
1AC35DE218CEE65900F37B72 /* effect2.ogg in Resources */,
1ABCA39A18CD9E180087CE3A /* StudioConstants.lua in Resources */,
15AECE24195D122700907DB0 /* experimentalConstants.lua in Resources */,
15C90B4318E66C1700D69802 /* mime.lua in Resources */,
1AC35DB118CEE5DA00F37B72 /* InfoPlist.strings in Resources */,
1AC35DDD18CEE65900F37B72 /* CocosBuilderExample.ccbproj in Resources */,
@ -4539,6 +4549,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
15AECE0F195C1FDD00907DB0 /* cocosvideo.mp4 in Resources */,
15B0870D195AD52000D6F62B /* ActionTimeline in Resources */,
15E66FC8192D957100C20A52 /* Sprite3DTest in Resources */,
15C90B4418E66C1800D69802 /* mime.lua in Resources */,
@ -4555,6 +4566,7 @@
1AC35DD718CEE65200F37B72 /* Particles in Resources */,
1AC35D9D18CEE5D100F37B72 /* Icon-120.png in Resources */,
15C90B3E18E66BF200D69802 /* http.lua in Resources */,
15AECE1F195D0EC500907DB0 /* experimentalConstants.lua in Resources */,
1AC35DA018CEE5D100F37B72 /* Icon-57.png in Resources */,
1ABCA37F18CD9E180087CE3A /* Cocos2dConstants.lua in Resources */,
1AC35DF118CEE65B00F37B72 /* fileLookup.plist in Resources */,
@ -5728,6 +5740,7 @@
"$(inherited)",
CC_TARGET_OS_IPHONE,
);
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
INFOPLIST_FILE = "$(SRCROOT)/../tests/game-controller-test/proj.ios/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
PRODUCT_NAME = "game-controller-test IOS";
@ -5745,6 +5758,7 @@
"$(inherited)",
CC_TARGET_OS_IPHONE,
);
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
INFOPLIST_FILE = "$(SRCROOT)/../tests/game-controller-test/proj.ios/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
PRODUCT_NAME = "game-controller-test IOS";

View File

@ -594,7 +594,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);
@ -759,7 +759,7 @@ public:
virtual ScaleBy* clone() const override;
virtual ScaleBy* reverse(void) const override;
protected:
CC_CONSTRUCTOR_ACCESS:
ScaleBy() {}
virtual ~ScaleBy() {}
@ -851,7 +851,7 @@ public:
void setReverseAction(FadeTo* ac);
protected:
CC_CONSTRUCTOR_ACCESS:
FadeIn():_reverseAction(nullptr) {}
virtual ~FadeIn() {}
@ -878,7 +878,7 @@ public:
void setReverseAction(FadeTo* ac);
protected:
CC_CONSTRUCTOR_ACCESS:
FadeOut():_reverseAction(nullptr) {}
virtual ~FadeOut() {}
private:
@ -970,7 +970,7 @@ public:
virtual DelayTime* reverse() const override;
virtual DelayTime* clone() const override;
protected:
CC_CONSTRUCTOR_ACCESS:
DelayTime() {}
virtual ~DelayTime() {}

View File

@ -180,7 +180,7 @@ void FastTMXLayer::onDraw(int offset, int count)
GL::bindTexture2D(_texture->getName());
getGLProgramState()->apply(_modelViewTransform);
glBindVertexArray(0);
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
@ -237,7 +237,7 @@ void FastTMXLayer::updateTiles(const Rect& culledRect)
else
{
//do nothing, do not support
CCASSERT(0, "TMX invalid value");
//CCASSERT(0, "TMX invalid value");
}
_indicesVertexZNumber.clear();
@ -264,9 +264,8 @@ void FastTMXLayer::updateTiles(const Rect& culledRect)
int offset = iter->second;
iter->second++;
//CC_ASSERT(_tileToQuadIndex.find(tileIndex) != _tileToQuadIndex.end() && _tileToQuadIndex[tileIndex] <= _totalQuads.size()-1);
int quadIndex = (int)_tileToQuadIndex[tileIndex];
int quadIndex = _tileToQuadIndex[tileIndex];
CC_ASSERT(-1 != quadIndex);
_indices[6 * offset + 0] = quadIndex * 4 + 0;
_indices[6 * offset + 1] = quadIndex * 4 + 1;
_indices[6 * offset + 2] = quadIndex * 4 + 2;
@ -387,7 +386,13 @@ Mat4 FastTMXLayer::tileToNodeTransform()
}
case FAST_TMX_ORIENTATION_HEX:
{
_tileToNodeTransform = Mat4::IDENTITY;
_tileToNodeTransform = Mat4
(
h * sqrtf(0.75), 0, 0, 0,
-h/2, -h, 0, offY,
0, 0, 1, 0,
0, 0, 0, 1
);
return _tileToNodeTransform;
}
default:
@ -408,6 +413,7 @@ void FastTMXLayer::updateTotalQuads()
_tileToQuadIndex.clear();
_totalQuads.resize(int(_layerSize.width * _layerSize.height));
_indices.resize(6 * int(_layerSize.width * _layerSize.height));
_tileToQuadIndex.resize(int(_layerSize.width * _layerSize.height),-1);
_indicesVertexZOffsets.clear();
int quadIndex = 0;
@ -617,7 +623,7 @@ int FastTMXLayer::getVertexZForPos(const Vec2& pos)
ret = static_cast<int>(-(_layerSize.height-pos.y));
break;
case FAST_TMX_ORIENTATION_HEX:
CCASSERT(0, "TMX Hexa zOrder not supported");
CCASSERT(0, "TMX Hexa vertexZ not supported");
break;
default:
CCASSERT(0, "TMX invalid value");

View File

@ -239,7 +239,7 @@ protected:
Mat4 _tileToNodeTransform;
/** data for rendering */
bool _quadsDirty;
std::unordered_map<ssize_t, ssize_t> _tileToQuadIndex;
std::vector<int> _tileToQuadIndex;
std::vector<V3F_C4B_T2F_Quad> _totalQuads;
std::vector<int> _indices;
std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets;

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

@ -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,31 +862,19 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
subStrlength -= 3;
}
// Remove '/', '//' and '/..' if exist
// Remove '//', '/..' if exist
std::string newName = name.substr(subStrStartPos, subStrlength);
// If search from parent, then add * at first to make it match its children, which will do make
if (searchFromParent)
{
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
{
@ -946,7 +924,7 @@ bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback)
bool ret = false;
for (const auto& child : _children)
{
if(std::regex_match(child->_name, std::regex(searchName)))
if (std::regex_match(child->_name, std::regex(searchName)))
{
if (!needRecursive)
{
@ -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, support 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

@ -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();
}

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();

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 \
@ -227,10 +222,10 @@ LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static
# define the macro to compile through support/zip_support/ioapi.c
LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_CPPFLAGS := -Wno-literal-suffix -Wno-deprecated-declarations
LOCAL_EXPORT_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_EXPORT_CPPFLAGS := -Wno-literal-suffix -Wno-deprecated-declarations
LOCAL_CFLAGS := -DUSE_FILE32API
LOCAL_CPPFLAGS := -Wno-deprecated-declarations
LOCAL_EXPORT_CFLAGS := -DUSE_FILE32API
LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations
include $(BUILD_STATIC_LIBRARY)

View File

@ -15,7 +15,4 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../.. \
$(LOCAL_PATH)/../../platform/android
LOCAL_CFLAGS += -Wno-psabi
LOCAL_EXPORT_CFLAGS += -Wno-psabi
include $(BUILD_STATIC_LIBRARY)

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,259 +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"
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);
if (!isAnalog)
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
@ -289,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
@ -302,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,22 +27,15 @@
#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>
#include "CCNSLog.h"
@interface GCControllerConnectionEventHandler : NSObject
typedef void (^GCControllerConnectionBlock)(GCController* controller);
@ -107,95 +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()
{
CCNSLOG("startDiscoveryController...: %s", "hello");
[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){
CCNSLOG("Controller(%p)'s paused handler was invoked.", 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);
CCNSLOG("controller %p was connnected!", gcController);
_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) {
CCNSLOG("controller %p was disconnected!", 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);
}];
}
@ -205,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
@ -232,153 +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){
CCNSLOG("dpad up %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.extendedGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad down %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.extendedGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad left %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.extendedGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad right %d, %f", button.pressed, button.value);
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){
CCNSLOG("dpad up %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.gamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad down %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.gamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad left %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.gamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad right %d, %f", button.pressed, button.value);
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,121 @@
#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();
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;}
static Controller* getControllerByTag(int tag);
static void startDiscoveryController();
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);
void setTag(int tag) { _controllerTag = tag;}
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,55 +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__CCControllerAxisInput__
#define __cocos2d_libs__CCControllerAxisInput__
#include "CCPlatformMacros.h"
#include "CCControllerElement.h"
NS_CC_BEGIN
class ControllerAxisInput : public ControllerElement
{
public:
float getValue() const;
protected:
ControllerAxisInput();
virtual ~ControllerAxisInput();
void setValue(float value);
float _value;
friend class Controller;
friend class ControllerImpl;
friend class ControllerDirectionPad;
friend class ControllerThumbstick;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCControllerAxisInput__) */

View File

@ -1,69 +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 "CCControllerButtonInput.h"
NS_CC_BEGIN
ControllerButtonInput::ControllerButtonInput()
: _value(0.0f)
, _isPressed(false)
, _isPrevStatusPressed(false)
{
}
ControllerButtonInput::~ControllerButtonInput()
{
}
float ControllerButtonInput::getValue() const
{
return _value;
}
bool ControllerButtonInput::isPressed() const
{
return _isPressed;
}
bool ControllerButtonInput::isPrevStatusPressed() const
{
return _isPrevStatusPressed;
}
void ControllerButtonInput::setValue(float value)
{
_value = value;
}
void ControllerButtonInput::setPressed(bool isPressed)
{
_isPrevStatusPressed = _isPressed;
_isPressed = isPressed;
}
NS_CC_END

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,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.
****************************************************************************/
#include "CCControllerElement.h"
NS_CC_BEGIN
ControllerElement::ControllerElement()
: _isAnalog(false)
, _collection(nullptr)
{
}
ControllerElement::~ControllerElement()
{
}
bool ControllerElement::isAnalog() const
{
return _isAnalog;
}
void ControllerElement::setAnalog(bool isAnalog)
{
_isAnalog = isAnalog;
}
ControllerElement* ControllerElement::getCollection()
{
return _collection;
}
void ControllerElement::setCollection(ControllerElement* collection)
{
_collection = collection;
}
NS_CC_END

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

@ -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__CCControllerThumbStick__
#define __cocos2d_libs__CCControllerThumbStick__
#include "CCPlatformMacros.h"
#include "CCControllerElement.h"
NS_CC_BEGIN
class ControllerAxisInput;
class ControllerButtonInput;
class ControllerThumbstick : public ControllerElement
{
public:
ControllerAxisInput* getAxisX() const;
ControllerAxisInput* getAxisY() const;
ControllerButtonInput* getButton() const;
protected:
friend class Controller;
friend class Gamepad;
ControllerThumbstick();
virtual ~ControllerThumbstick();
ControllerAxisInput* _axisX;
ControllerAxisInput* _axisY;
ControllerButtonInput* _button;
};
NS_CC_END
#endif /* defined(__cocos2d_libs__CCControllerThumbStick__) */

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

@ -613,7 +613,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 +1276,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,10 +25,8 @@
#include "CCEventListenerController.h"
#include "CCEventController.h"
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "ccMacros.h"
#include "CCNSLog.h"
#include "base/CCController.h"
NS_CC_BEGIN
@ -52,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)
@ -64,46 +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];
CCNSLOG("button event: %d, %d, %f", button->isPressed(), button->isPrevStatusPressed(), button->getValue());
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

@ -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

@ -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

@ -72,19 +72,50 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
// The frame buffer is always created with portrait orientation on WP8.
// So if the current device orientation is landscape, we need to rotate the frame buffer.
auto renderTargetSize = glView->getRenerTargetSize();
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#else
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#endif
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
if (!flippedBuffer)
{
break;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
if (width == static_cast<int>(renderTargetSize.width))
{
// The current device orientation is portrait.
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
}
else
{
// The current device orientation is landscape.
for (int row = 0; row < width; ++row)
{
for (int col = 0; col < height; ++col)
{
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
}
}
}
#else
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
#endif
std::shared_ptr<Image> image(new Image);
if (image)
{

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

@ -261,6 +261,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

@ -35,8 +35,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../2d \
$(LOCAL_PATH) \
$(LOCAL_PATH)/../../..
LOCAL_CFLAGS += -Wno-psabi
LOCAL_EXPORT_CFLAGS += -Wno-psabi
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_extension_static

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

@ -45,6 +45,8 @@ static const char* ClassName_Button = "Button";
static const char* ClassName_CheckBox = "CheckBox";
static const char* ClassName_ImageView = "ImageView";
static const char* ClassName_TextAtlas = "TextAtlas";
static const char* ClassName_LabelAtlas = "LabelAtlas";
static const char* ClassName_LabelBMFont= "LabelBMFont";
static const char* ClassName_TextBMFont = "TextBMFont";
static const char* ClassName_Text = "Text";
static const char* ClassName_LoadingBar = "LoadingBar";
@ -132,7 +134,8 @@ void NodeReader::init()
_funcs.insert(Pair(ClassName_SubGraph, std::bind(&NodeReader::loadSubGraph, this, _1)));
_funcs.insert(Pair(ClassName_Sprite, std::bind(&NodeReader::loadSprite, this, _1)));
_funcs.insert(Pair(ClassName_Particle, std::bind(&NodeReader::loadParticle, this, _1)));
_funcs.insert(Pair(ClassName_LabelAtlas,std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_LabelBMFont,std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_Panel, std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_Button, std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_CheckBox, std::bind(&NodeReader::loadWidget, this, _1)));
@ -281,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)
@ -293,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

@ -68,8 +68,8 @@ $(LOCAL_PATH)/../../../external \
$(LOCAL_PATH)/.. \
$(LOCAL_PATH)/../..
LOCAL_CFLAGS += -Wno-psabi -fexceptions
LOCAL_EXPORT_CFLAGS += -Wno-psabi
LOCAL_CFLAGS += -fexceptions
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static

View File

@ -83,7 +83,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
CCLOG("filename == %s",fileName.c_str());
cocos2d::Vector<ActionObject*> actionList;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
stExpCocoNode *stChildArray = pCocoNode->GetChildArray(cocoLoader);
stExpCocoNode *actionNode = nullptr;
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
@ -99,7 +99,7 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
ActionObject* action = new ActionObject();
action->autorelease();
action->initWithBinary(cocoLoader, actionNode->GetChildArray(), root);
action->initWithBinary(cocoLoader, actionNode->GetChildArray(cocoLoader), root);
actionList.pushBack(action);
}

View File

@ -195,11 +195,11 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
stExpCocoNode *stChildNode = cocoNode;
int actionNodeCount = stChildNode->GetChildNum();
stChildNode = stChildNode[0].GetChildArray();
stChildNode = stChildNode[0].GetChildArray(cocoLoader);
stExpCocoNode *frameListNode = nullptr;
for (int i = 0; i < actionNodeCount; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();
std::string value = stChildNode[i].GetValue(cocoLoader);
if (key == "ActionTag") {
setActionTag(valueToInt(value));
}else if (key == "actionframelist"){
@ -208,7 +208,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
}
int actionFrameCount = frameListNode->GetChildNum();
stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray();
stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray(cocoLoader);
for (int i=0; i<actionFrameCount; i++) {
int frameIndex;
@ -225,10 +225,10 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
std::vector<float> frameTweenParameter;
int framesCount = stFrameChildNode[i].GetChildNum();
stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray();
stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray(cocoLoader);
for (int j = 0; j < framesCount; j++) {
std::string key = innerFrameNode[j].GetName(cocoLoader);
std::string value = innerFrameNode[j].GetValue();
std::string value = innerFrameNode[j].GetValue(cocoLoader);
if (key == "frameid") {
frameIndex = valueToInt(value);
@ -237,10 +237,10 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
}else if (key == "tweenParameter"){
// There are no tweenParameter args in the json file
int tweenParameterCount = innerFrameNode[j].GetChildNum();
stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray();
stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray(cocoLoader);
for (int k = 0; k < tweenParameterCount; ++k) {
std::string t_key = tweenParameterArray[j].GetName(cocoLoader);
std::string t_value = tweenParameterArray[j].GetValue();
std::string t_value = tweenParameterArray[j].GetValue(cocoLoader);
frameTweenParameter.push_back(valueToFloat(t_value));
}
}else if (key == "positionx"){

View File

@ -132,12 +132,12 @@ void ActionObject::initWithBinary(CocoLoader *cocoLoader,
stExpCocoNode *cocoNode,
cocos2d::Ref *root)
{
stExpCocoNode *stChildNode = cocoNode->GetChildArray();
stExpCocoNode *stChildNode = cocoNode->GetChildArray(cocoLoader);
stExpCocoNode *actionNodeList = nullptr;
int count = cocoNode->GetChildNum();
for (int i = 0; i < count; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();
std::string value = stChildNode[i].GetValue(cocoLoader);
if (key == "name") {
setName(value.c_str());
}else if (key == "loop"){
@ -152,7 +152,7 @@ void ActionObject::initWithBinary(CocoLoader *cocoLoader,
if(nullptr != actionNodeList)
{
int actionNodeCount = actionNodeList->GetChildNum();
stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray();
stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray(cocoLoader);
int maxLength = 0;
for (int i=0; i<actionNodeCount; i++) {
ActionNode* actionNode = new ActionNode();

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

@ -144,14 +144,43 @@ ComAttribute* ComAttribute::create(void)
bool ComAttribute::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
CocoLoader *cocoLoader = serData->_cocoLoader;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue(cocoLoader);
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue(cocoLoader);
stExpCocoNode *fileData = cocoNode[3].GetChildArray(cocoLoader);
CC_BREAK_IF(!fileData);
file = fileData[0].GetValue(cocoLoader);
CC_BREAK_IF(file == nullptr);
resType = atoi(fileData[2].GetValue(cocoLoader));
CC_BREAK_IF(resType != 0);
}
if (comName != nullptr)
{
setName(comName);
@ -160,22 +189,17 @@ bool ComAttribute::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
parse(filePath.c_str());
bRet = true;
} while (0);
return bRet;
if (parse(filePath.c_str()))
{
ret = true;
}
}while (0);
return ret;
}
bool ComAttribute::parse(const std::string &jsonFile)

View File

@ -69,14 +69,47 @@ void ComAudio::setEnabled(bool b)
bool ComAudio::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
CocoLoader *cocoLoader = serData->_cocoLoader;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
bool loop = false;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue(cocoLoader);
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue(cocoLoader);
stExpCocoNode *pfileData = cocoNode[4].GetChildArray(cocoLoader);
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue(cocoLoader);
CC_BREAK_IF(file == nullptr);
resType = atoi(pfileData[2].GetValue(cocoLoader));
CC_BREAK_IF(resType != 0);
loop = atoi(cocoNode[5].GetValue(cocoLoader)) != 0? true:false;
ret = true;
}
if (comName != nullptr)
{
setName(comName);
@ -85,17 +118,14 @@ bool ComAudio::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
if (strcmp(file, "") == 0)
{
continue;
}
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
if (strcmp(className, "CCBackgroundAudio") == 0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
@ -108,9 +138,8 @@ bool ComAudio::serialize(void* r)
filePath.replace(pos, filePath.length(), ".wav");
#endif
preloadBackgroundMusic(filePath.c_str());
bool loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
setLoop(loop);
playBackgroundMusic(filePath.c_str(), loop);
playBackgroundMusic(filePath.c_str(), loop);
}
else if(strcmp(className, "CCComAudio") == 0)
{
@ -120,10 +149,9 @@ bool ComAudio::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
ret = true;
}while (0);
return ret;
}
ComAudio* ComAudio::create(void)

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string>
#include "DictionaryHelper.h"
#include "base/ObjectFactory.h"
#include "CocoLoader.h"
#define DECLARE_CLASS_COMPONENT_INFO \
@ -45,5 +46,18 @@ THE SOFTWARE.
#define CREATE_CLASS_COMPONENT_INFO(className) \
cocos2d::ObjectFactory::TInfo(#className, &className::createInstance)
struct SerData
{
const rapidjson::Value *_rData;
cocostudio::stExpCocoNode *_cocoNode;
cocostudio::CocoLoader *_cocoLoader;
SerData()
{
_rData = NULL;
_cocoNode = NULL;
_cocoLoader = NULL;
}
};
#endif

View File

@ -90,14 +90,45 @@ void ComRender::setNode(cocos2d::Node *node)
bool ComRender::serialize(void* r)
{
bool bRet = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
CocoLoader *cocoLoader = serData->_cocoLoader;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
const char *plist = nullptr;
std::string filePath;
std::string plistPath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
}
else if(cocoNode != nullptr)
{
className = cocoNode[1].GetValue(cocoLoader);
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue(cocoLoader);
stExpCocoNode *pfileData = cocoNode[4].GetChildArray(cocoLoader);
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue(cocoLoader);
plist = pfileData[1].GetValue(cocoLoader);
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = atoi(pfileData[2].GetValue(cocoLoader));
}
if (comName != nullptr)
{
setName(comName);
@ -106,72 +137,175 @@ bool ComRender::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
const char *plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
std::string filePath;
std::string plistPath;
if (file != nullptr)
{
filePath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(file));
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
if (plist != nullptr)
{
plistPath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(plist));
plistPath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(plist));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
if (resType == 0)
{
if (strcmp(className, "CCSprite") == 0 && filePath.find(".png") != std::string::npos)
if (strcmp(className, "CCSprite") == 0 && (filePath.find(".png") != filePath.npos || filePath.find(".pvr.ccz") != filePath.npos))
{
_render = Sprite::create(filePath.c_str());
_render->retain();
_render = CCSprite::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != std::string::npos)
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != filePath.npos)
{
_render = TMXTiledMap::create(filePath.c_str());
_render->retain();
_render = CCTMXTiledMap::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != std::string::npos)
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != filePath.npos)
{
_render = ParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Vec2(0.0f, 0.0f));
_render->retain();
_render = CCParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Point(0.0f, 0.0f));
_render->retain();
ret = true;
}
else if(strcmp(className, "CCArmature") == 0)
{
std::string reDir = filePath;
std::string file_path = "";
size_t pos = reDir.find_last_of('/');
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_path = reDir.substr(0, pos+1);
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue(cocoLoader);//DICTOOL->getStringValue_json(*v, "selectedactionname");
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
if (actionName != nullptr && pAr->getAnimation() != nullptr)
else if (file_extension == ".CSB")
{
pAr->getAnimation()->play(actionName);
ssize_t size = 0;
unsigned char *pBytes = nullptr;
std::string binaryFilePath = FileUtils::getInstance()->fullPathForFilename(filePath.c_str());
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
int count = tpRootCocoNode->GetChildNum();
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
for (int i = 0; i < count; ++i)
{
std::string key = tpChildArray[i].GetName(&tCocoLoader);
if (key.compare("armature_data") == 0)
{
int length = tpChildArray[i].GetChildNum();
stExpCocoNode *armature_dataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
if (length < 1)
{
continue;
}
length = armature_dataArray[0].GetChildNum();
stExpCocoNode *armature_data = armature_dataArray[0].GetChildArray(&tCocoLoader);
for (int j = 0; j < length; ++j)
{
std::string key1 = armature_data[j].GetName(&tCocoLoader);
const char *str1 = armature_data[j].GetValue(&tCocoLoader);
if (key.compare("name") == 0)
{
if (str1 != nullptr)
{
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = CCArmature::create(str1);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue(&tCocoLoader);
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
}
}
}
}
}
}
else
{
continue;
}
}
else
{
continue;
}
}
else if(strcmp(className, "GUIComponent") == 0)
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
else if (file_extension == ".CSB")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromBinaryFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
}
else
{
@ -190,8 +324,10 @@ bool ComRender::serialize(void* r)
}
strPngFile.replace(pos, strPngFile.length(), ".png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str());
_render = Sprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
_render = CCSprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
ret = true;
}
else
{
@ -202,10 +338,9 @@ bool ComRender::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
} while (0);
return ret;
}
ComRender* ComRender::create(void)

View File

@ -301,9 +301,9 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
// Read content from file
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
bool isbinarysrc = str==".csb";
bool isbinaryfilesrc = str==".csb";
std::string filemode("r");
if(isbinarysrc)
if(isbinaryfilesrc)
filemode += "b";
ssize_t filesize;
@ -324,7 +324,7 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
{
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
}
else if(str == ".csb")
else if(isbinaryfilesrc)
{
DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo);
}
@ -438,7 +438,7 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const
{
data->configType = CocoStudio_JSON;
}
else if(str == ".csb")
else if(isbinaryfilesrc)
{
data->configType = CocoStudio_Binary;
}
@ -474,7 +474,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt)
if (pAsyncStruct->imagePath != "" && pAsyncStruct->plistPath != "")
{
_getFileMutex.lock();
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(pAsyncStruct->plistPath.c_str(), pAsyncStruct->imagePath.c_str());
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(pAsyncStruct->plistPath.c_str(), pAsyncStruct->imagePath.c_str(), pDataInfo->filename.c_str());
_getFileMutex.unlock();
}
@ -482,7 +482,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt)
{
std::string configPath = pDataInfo->configFileQueue.front();
_getFileMutex.lock();
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str());
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str(),pDataInfo->filename.c_str());
_getFileMutex.unlock();
pDataInfo->configFileQueue.pop();
}
@ -1258,7 +1258,7 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData);
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str());
armatureData->release();
if (dataInfo->asyncStruct)
{
@ -1277,7 +1277,7 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData);
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str());
animationData->release();
if (dataInfo->asyncStruct)
{
@ -1296,7 +1296,7 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
{
_dataReaderHelper->_addDataMutex.lock();
}
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData);
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str());
textureData->release();
if (dataInfo->asyncStruct)
{
@ -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.");
@ -1330,7 +1330,7 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
std::string plistPath = filePath + ".plist";
std::string pngPath = filePath + ".png";
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str());
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str());
}
}
}
@ -1750,7 +1750,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
int nCount = tpRootCocoNode->GetChildNum();
dataInfo->contentScale = 1.0f;
@ -1762,12 +1762,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
key = tpChildArray[i].GetName(&tCocoLoader);
if (key.compare(CONTENT_SCALE) == 0)
{
std::string value = tpChildArray[i].GetValue();
std::string value = tpChildArray[i].GetValue(&tCocoLoader);
dataInfo->contentScale = atof(value.c_str());
}
else if ( 0 == key.compare(ARMATURE_DATA))
{
pDataArray = tpChildArray[i].GetChildArray();
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
length = tpChildArray[i].GetChildNum();
ArmatureData * armatureData;
for (int ii = 0; ii < length; ++ii)
@ -1787,7 +1787,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
else if ( 0 == key.compare(ANIMATION_DATA))
{
pDataArray = tpChildArray[i].GetChildArray();
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
length = tpChildArray[i].GetChildNum();
AnimationData *animationData;
for (int ii = 0; ii < length; ++ii)
@ -1807,7 +1807,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
else if (key.compare(TEXTURE_DATA) == 0)
{
pDataArray = tpChildArray[i].GetChildArray();
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
length = tpChildArray[i].GetChildNum();
for (int ii = 0; ii < length; ++ii)
{
@ -1837,10 +1837,10 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
continue;
}
length = tpChildArray[i].GetChildNum();
stExpCocoNode *pConfigFilePath = tpChildArray[i].GetChildArray();
stExpCocoNode *pConfigFilePath = tpChildArray[i].GetChildArray(&tCocoLoader);
for (int ii = 0; ii < length; ii++)
{
const char *path = pConfigFilePath[ii].GetValue();
const char *path = pConfigFilePath[ii].GetValue(&tCocoLoader);
if (path == nullptr)
{
CCLOG("load CONFIG_FILE_PATH error.");
@ -1872,18 +1872,18 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
ArmatureData *armatureData = new ArmatureData();
armatureData->init();
stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray();
const char *name = pAramtureDataArray[2].GetValue(); //DICTOOL->getStringValue_json(json, A_NAME);
stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray(cocoLoader);
const char *name = pAramtureDataArray[2].GetValue(cocoLoader); //DICTOOL->getStringValue_json(json, A_NAME);
if(name != nullptr)
{
armatureData->name = name;
}
float version = atof(pAramtureDataArray[1].GetValue());
float version = atof(pAramtureDataArray[1].GetValue(cocoLoader));
dataInfo->cocoStudioVersion = armatureData->dataVersion = version; //DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
int length = pAramtureDataArray[3].GetChildNum(); //DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
stExpCocoNode *pBoneChildren = pAramtureDataArray[3].GetChildArray();
stExpCocoNode *pBoneChildren = pAramtureDataArray[3].GetChildArray(cocoLoader);
stExpCocoNode* child;
for (int i = 0; i < length; i++)
{
@ -1905,7 +1905,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
decodeNode(boneData, cocoLoader, cocoNode, dataInfo);
int length = cocoNode->GetChildNum();
stExpCocoNode *pBoneChildren = cocoNode->GetChildArray();
stExpCocoNode *pBoneChildren = cocoNode->GetChildArray(cocoLoader);
stExpCocoNode* child;
const char *str = nullptr;
std::string key;
@ -1913,7 +1913,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
child = &pBoneChildren[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
str = child->GetValue(cocoLoader);
if (key.compare(A_NAME) == 0)
{
//DICTOOL->getStringValue_json(json, A_NAME);
@ -1933,7 +1933,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(DISPLAY_DATA) == 0)
{
int count = child->GetChildNum();
stExpCocoNode *pDisplayData = child->GetChildArray();
stExpCocoNode *pDisplayData = child->GetChildArray(cocoLoader);
for (int ii = 0; ii < count; ++ii)
{
DisplayData *displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo);
@ -1950,16 +1950,16 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
DisplayData* DataReaderHelper::decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
{
stExpCocoNode* children = cocoNode->GetChildArray();
stExpCocoNode* children = cocoNode->GetChildArray(cocoLoader);
stExpCocoNode* child = &children[1];
const char *str = nullptr;
std::string key = child->GetName(cocoLoader);
str = child->GetValue();
str = child->GetValue(cocoLoader);
DisplayData *displayData = nullptr;
if (key.compare(A_DISPLAY_TYPE) == 0)
{
str = child->GetValue();
str = child->GetValue(cocoLoader);
DisplayType displayType = (DisplayType)(atoi(str));
int length = 0;
@ -1969,12 +1969,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
displayData = new SpriteDisplayData();
const char *name = children[0].GetValue();
const char *name = children[0].GetValue(cocoLoader);
if(name != nullptr)
{
((SpriteDisplayData *)displayData)->displayName = name;
}
stExpCocoNode *pSkinDataArray = children[2].GetChildArray();
stExpCocoNode *pSkinDataArray = children[2].GetChildArray(cocoLoader);
if (pSkinDataArray != nullptr)
{
stExpCocoNode *pSkinData = &pSkinDataArray[0];
@ -1982,11 +1982,11 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
SpriteDisplayData *sdd = (SpriteDisplayData *)displayData;
length = pSkinData->GetChildNum();
stExpCocoNode *SkinDataValue = pSkinData->GetChildArray();
stExpCocoNode *SkinDataValue = pSkinData->GetChildArray(cocoLoader);
for (int i = 0; i < length; ++i)
{
key = SkinDataValue[i].GetName(cocoLoader);
str = SkinDataValue[i].GetValue();
str = SkinDataValue[i].GetValue(cocoLoader);
if (key.compare(A_X) == 0)
{
sdd->skinData.x = atof(str) * s_PositionReadScale;
@ -2024,7 +2024,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
displayData = new ArmatureDisplayData();
const char *name = cocoNode[0].GetValue();
const char *name = cocoNode[0].GetValue(cocoLoader);
if(name != nullptr)
{
((ArmatureDisplayData *)displayData)->displayName = name;
@ -2035,11 +2035,11 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
displayData = new ParticleDisplayData();
length = cocoNode->GetChildNum();
stExpCocoNode *pDisplayData = cocoNode->GetChildArray();
stExpCocoNode *pDisplayData = cocoNode->GetChildArray(cocoLoader);
for (int i = 0; i < length; ++i)
{
key = pDisplayData[i].GetName(cocoLoader);
str = pDisplayData[i].GetValue();
str = pDisplayData[i].GetValue(cocoLoader);
if (key.compare(A_PLIST) == 0)
{
const char *plist = str;
@ -2073,7 +2073,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
AnimationData *aniData = new AnimationData();
int length = cocoNode->GetChildNum();
stExpCocoNode *pAnimationData = cocoNode->GetChildArray();
stExpCocoNode *pAnimationData = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
std::string key;
stExpCocoNode* child;
@ -2082,7 +2082,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
child = &pAnimationData[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
str = child->GetValue(cocoLoader);
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
@ -2093,7 +2093,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(MOVEMENT_DATA) == 0)
{
int movcount = child->GetChildNum();
stExpCocoNode* movArray = child->GetChildArray();
stExpCocoNode* movArray = child->GetChildArray(cocoLoader);
for( int movnum =0; movnum <movcount; movnum++)
{
movementData = decodeMovement(cocoLoader, &movArray[movnum], dataInfo);
@ -2111,7 +2111,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
movementData->scale = 1.0f;
int length = cocoNode->GetChildNum();
stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray();
stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
std::string key;
@ -2120,7 +2120,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
child = &pMoveDataArray[i];
key = child->GetName(cocoLoader);
str = child->GetValue();
str = child->GetValue(cocoLoader);
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
@ -2182,7 +2182,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(MOVEMENT_BONE_DATA) == 0)
{
int count = child->GetChildNum();
stExpCocoNode *pMoveBoneData = child->GetChildArray();
stExpCocoNode *pMoveBoneData = child->GetChildArray(cocoLoader);
MovementBoneData *movementBoneData;
for (int ii = 0; ii < count; ++ii)
{
@ -2201,14 +2201,14 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
movementBoneData->init();
int length = cocoNode->GetChildNum();
stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray();
stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray(cocoLoader);
stExpCocoNode* movebonechild;
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
movebonechild = &pMovementBoneDataArray[i];
std::string key = movebonechild->GetName(cocoLoader);
str = movebonechild->GetValue();
str = movebonechild->GetValue(cocoLoader);
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
@ -2226,7 +2226,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(FRAME_DATA) == 0)
{
int count =movebonechild->GetChildNum();
stExpCocoNode *pFrameDataArray = movebonechild->GetChildArray();
stExpCocoNode *pFrameDataArray = movebonechild->GetChildArray(cocoLoader);
for (int ii = 0; ii < count; ++ii)
{
FrameData *frameData = decodeFrame(cocoLoader, &pFrameDataArray[ii], dataInfo);
@ -2296,12 +2296,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
decodeNode(frameData, cocoLoader, cocoNode, dataInfo);
int length = cocoNode->GetChildNum();
stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray();
stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = pFrameDataArray[i].GetName(cocoLoader);
str = pFrameDataArray[i].GetValue();
str = pFrameDataArray[i].GetValue(cocoLoader);
if (key.compare(A_TWEEN_EASING) == 0)
{
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
@ -2376,10 +2376,10 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
if (count != 0 )
{
frameData->easingParams = new float[count];
stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray();
stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray(cocoLoader);
for (int ii = 0; ii < count; ++ii)
{
str = pFrameData[ii].GetValue();
str = pFrameData[ii].GetValue(cocoLoader);
if (str != nullptr)
{
frameData->easingParams[ii] = atof(str);
@ -2404,12 +2404,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
}
int length = cocoNode->GetChildNum();
stExpCocoNode *pTextureDataArray = cocoNode->GetChildArray();
stExpCocoNode *pTextureDataArray = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = pTextureDataArray[i].GetName(cocoLoader);
str = pTextureDataArray[i].GetValue();
str = pTextureDataArray[i].GetValue(cocoLoader);
if (key.compare(A_NAME) == 0)
{
if(str != nullptr)
@ -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);
}
@ -2448,7 +2448,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
else if (key.compare(CONTOUR_DATA) == 0)
{
int count = pTextureDataArray[i].GetChildNum();
stExpCocoNode *pContourArray = pTextureDataArray[i].GetChildArray();
stExpCocoNode *pContourArray = pTextureDataArray[i].GetChildArray(cocoLoader);
for (int ii = 0; ii < count; ++ii)
{
ContourData *contourData = decodeContour(cocoLoader, &pContourArray[ii]);
@ -2466,23 +2466,23 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
contourData->init();
int length = cocoNode->GetChildNum();
stExpCocoNode *verTexPointArray = cocoNode->GetChildArray();
stExpCocoNode *verTexPointArray = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
for (int i = 0; i < length; ++i)
{
std::string key = verTexPointArray[i].GetName(cocoLoader);
str = verTexPointArray[i].GetValue();
str = verTexPointArray[i].GetValue(cocoLoader);
if (key.compare(VERTEX_POINT) == 0)
{
int count = verTexPointArray[i].GetChildNum();
stExpCocoNode *pVerTexPointArray = verTexPointArray[i].GetChildArray();
stExpCocoNode *pVerTexPointArray = verTexPointArray[i].GetChildArray(cocoLoader);
stExpCocoNode *pVerTexPoint;
for (int ii = count - 1; ii >= 0; --ii)
{
pVerTexPoint = pVerTexPointArray[ii].GetChildArray();
pVerTexPoint = pVerTexPointArray[ii].GetChildArray(cocoLoader);
Vec2 vertex;
vertex.x = atof(pVerTexPoint[0].GetValue());
vertex.y = atof(pVerTexPoint[1].GetValue());
vertex.x = atof(pVerTexPoint[0].GetValue(cocoLoader));
vertex.y = atof(pVerTexPoint[1].GetValue(cocoLoader));
contourData->vertexList.push_back(vertex); }
break;
}
@ -2493,7 +2493,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
void DataReaderHelper::decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode* cocoNode, DataInfo *dataInfo)
{
int length = cocoNode->GetChildNum();
stExpCocoNode *NodeArray = cocoNode->GetChildArray();
stExpCocoNode *NodeArray = cocoNode->GetChildArray(cocoLoader);
const char *str = nullptr;
bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING;
@ -2502,7 +2502,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
child = &NodeArray[i];
std::string key = child->GetName(cocoLoader);
str = child->GetValue();
str = child->GetValue(cocoLoader);
if (key.compare(A_X) == 0)
{
node->x = atof(str) * dataInfo->contentScale;
@ -2539,12 +2539,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
if(child->GetChildNum() == 4)
{
stExpCocoNode *ChildArray = child->GetChildArray();
stExpCocoNode *ChildArray = child->GetChildArray(cocoLoader);
node->a = atoi(ChildArray[0].GetValue());
node->r = atoi(ChildArray[1].GetValue());
node->g = atoi(ChildArray[2].GetValue());
node->b = atoi(ChildArray[3].GetValue());
node->a = atoi(ChildArray[0].GetValue(cocoLoader));
node->r = atoi(ChildArray[1].GetValue(cocoLoader));
node->g = atoi(ChildArray[2].GetValue(cocoLoader));
node->b = atoi(ChildArray[3].GetValue(cocoLoader));
}
}
@ -2566,12 +2566,12 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json,
{
if(NodeArray[0].GetChildNum() == 4)
{
stExpCocoNode *ChildArray = NodeArray[0].GetChildArray();
stExpCocoNode *ChildArray = NodeArray[0].GetChildArray(cocoLoader);
node->a = atoi(ChildArray[0].GetValue());
node->r = atoi(ChildArray[1].GetValue());
node->g = atoi(ChildArray[2].GetValue());
node->b = atoi(ChildArray[3].GetValue());
node->a = atoi(ChildArray[0].GetValue(cocoLoader));
node->r = atoi(ChildArray[1].GetValue(cocoLoader));
node->g = atoi(ChildArray[2].GetValue(cocoLoader));
node->b = atoi(ChildArray[3].GetValue(cocoLoader));
}
}

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))
@ -361,13 +361,13 @@ Widget* GUIReader::widgetFromBinaryFile(const char *fileName)
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType || rapidjson::kArrayType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
for (int i = 0; i < tpRootCocoNode->GetChildNum(); ++i) {
std::string key = tpChildArray[i].GetName(&tCocoLoader);
if (key == "version") {
fileVersion = tpChildArray[i].GetValue();
fileVersion = tpChildArray[i].GetValue(&tCocoLoader);
break;
}
}
@ -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));
}
/* ********************** */
@ -1222,7 +1222,7 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
cocos2d::ui::Widget* WidgetPropertiesReader0300::createWidgetFromBinary(CocoLoader* cocoLoader,stExpCocoNode* cocoNode, const char* fileName)
{
stExpCocoNode *tpChildArray = cocoNode->GetChildArray();
stExpCocoNode *tpChildArray = cocoNode->GetChildArray(cocoLoader);
float fileDesignWidth;
float fileDesignHeight;
@ -1236,14 +1236,14 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
for (int j=0; j<texturesCount; j++)
{
std::string file;
stExpCocoNode *textureCountsArray = tpChildArray[i].GetChildArray();
file = textureCountsArray[j].GetValue();
stExpCocoNode *textureCountsArray = tpChildArray[i].GetChildArray(cocoLoader);
file = textureCountsArray[j].GetValue(cocoLoader);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
}
}else if (key == "designWidth"){
fileDesignWidth = atof(tpChildArray[i].GetValue());
fileDesignWidth = atof(tpChildArray[i].GetValue(cocoLoader));
}else if (key == "designHeight"){
fileDesignHeight = atof(tpChildArray[i].GetValue());
fileDesignHeight = atof(tpChildArray[i].GetValue(cocoLoader));
}else if (key == "widgetTree"){
if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
@ -1268,14 +1268,14 @@ 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));
}
}
}
/* ********************** */
/* ********************** */
stExpCocoNode *optionChildNode = cocoNode->GetChildArray();
stExpCocoNode *optionChildNode = cocoNode->GetChildArray(cocoLoader);
for (int k = 0; k < cocoNode->GetChildNum(); ++k) {
std::string key = optionChildNode[k].GetName(cocoLoader);
if (key == "animation") {
@ -1291,7 +1291,7 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNode)
{
Widget* widget = nullptr;
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
stExpCocoNode *optionsNode = nullptr;
stExpCocoNode *childrenNode = nullptr;
int elementCount = cocoNode->GetChildNum();
@ -1299,7 +1299,7 @@ Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* cocoLoader, st
for (int i = 0; i < elementCount; ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
std::string value = stChildArray[i].GetValue(cocoLoader);
if (key == "classname" )
{
@ -1340,12 +1340,12 @@ 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;
stExpCocoNode *optionChildNode = optionsNode->GetChildArray();
const char* customProperty = nullptr;
stExpCocoNode *optionChildNode = optionsNode->GetChildArray(cocoLoader);
for (int k = 0; k < optionsNode->GetChildNum(); ++k) {
std::string key = optionChildNode[k].GetName(cocoLoader);
if (key == "customProperty") {
customProperty = optionChildNode[k].GetValue();
customProperty = optionChildNode[k].GetValue(cocoLoader);
break;
}
}
@ -1369,7 +1369,7 @@ Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* cocoLoader, st
if (tType22 == rapidjson::kArrayType) {
int childrenCount = childrenNode->GetChildNum();
stExpCocoNode* innerChildArray = childrenNode->GetChildArray();
stExpCocoNode* innerChildArray = childrenNode->GetChildArray(cocoLoader);
for (int i=0; i < childrenCount; ++i) {
rapidjson::Type tType = innerChildArray[i].GetType(cocoLoader);

View File

@ -56,28 +56,134 @@ const char* SceneReader::sceneReaderVersion()
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/)
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
std::string reDir = fileName;
std::string file_extension = "";
size_t pos = reDir.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = reDir.substr(pos, reDir.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON")
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
}
else if(file_extension == ".CSB")
{
ssize_t size = 0;
unsigned char *pBytes = nullptr;
do {
std::string binaryFilePath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
CC_BREAK_IF(tpRootCocoNode->GetChildNum() == 0);
_node = Node::create();
int nCount = 0;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
std::string key = tpChildArray[15].GetName(&tCocoLoader);
if (key == "components")
{
nCount = tpChildArray[15].GetChildNum();
}
stExpCocoNode *pComponents = tpChildArray[15].GetChildArray(&tCocoLoader);
SerData *data = new SerData();
for (int i = 0; i < nCount; i++)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray(&tCocoLoader);
if (subDict == nullptr)
{
continue;
}
std::string key1 = subDict[1].GetName(&tCocoLoader);
const char *comName = subDict[1].GetValue(&tCocoLoader);
Component *pCom = nullptr;
if (key1 == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
data->_cocoLoader = &tCocoLoader;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
setPropertyFromJsonDict(&tCocoLoader, tpRootCocoNode, _node);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
_node->addComponent(*iter);
}
stExpCocoNode *pGameObjects = tpChildArray[11].GetChildArray(&tCocoLoader);
int length = tpChildArray[11].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(&tCocoLoader, &pGameObjects[i], _node, attachComponent);
}
TriggerMng::getInstance()->parse(&tCocoLoader, tpChildArray);
}
}
}while (0);
return _node;
}
else
{
log("read file [%s] error!\n", fileName.c_str());
}
return nullptr;
}
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool bRet = false;
bool ret = false;
do {
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
bRet = true;
ret = true;
} while (0);
return bRet;
return ret;
}
Node* SceneReader::nodeByTag(Node *parent, int tag)
@ -172,9 +278,14 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = this->createComponent(comName);
CCLOG("classname = %s", comName);
SerData *data = new SerData();
if (com != nullptr)
{
if (com->serialize((void*)(&subDict)))
data->_rData = &subDict;
data->_cocoNode = nullptr;
data->_cocoLoader = nullptr;
if (com->serialize(data))
{
ComRender *tRender = dynamic_cast<ComRender*>(com);
if (tRender == nullptr)
@ -187,9 +298,10 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
}
}
CC_SAFE_DELETE(data);
if(_fnSelector != nullptr)
{
_fnSelector(com, (void*)(&subDict));
_fnSelector(com, data);
}
}
@ -234,6 +346,112 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
return nullptr;
}
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = nullptr;
stExpCocoNode *pNodeArray = cocoNode->GetChildArray(cocoLoader);
std::string Key = pNodeArray[1].GetName(cocoLoader);
if (Key == "classname")
{
className = pNodeArray[1].GetValue(cocoLoader);
}
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
int count = 0;
std::string key = pNodeArray[13].GetName(cocoLoader);
if (key == "components")
{
count = pNodeArray[13].GetChildNum();
}
stExpCocoNode *pComponents = pNodeArray[13].GetChildArray(cocoLoader);
SerData *data = new SerData();
for (int i = 0; i < count; ++i)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray(cocoLoader);
if (subDict == nullptr)
{
continue;
}
std::string key1 = subDict[1].GetName(cocoLoader);
const char *comName = subDict[1].GetValue(cocoLoader);
Component *pCom = nullptr;
if (key1 == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
data->_cocoLoader = cocoLoader;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
CC_SAFE_DELETE(data);
if (parent != nullptr)
{
if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = CCNode::create();
if (pRender != nullptr)
{
_vecComs.push_back(pRender);
}
}
else
{
gb = pRender->getNode();
gb->retain();
pRender->setNode(nullptr);
CC_SAFE_RELEASE_NULL(pRender);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(cocoLoader, cocoNode, gb);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray(cocoLoader);
if (pGameObjects != nullptr)
{
int length = pNodeArray[12].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(cocoLoader, &pGameObjects[i], gb, attachComponent);
}
}
return gb;
}
return nullptr;
}
void SceneReader::setTarget(const std::function<void(cocos2d::Ref* obj, void* doc)>& selector)
{
@ -276,6 +494,62 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d:
float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation");
node->setRotation(fRotationZ);
}
void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node)
{
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
float x = 0.0f, y = 0.0f, fScaleX = 1.0f, fScaleY = 1.0f, fRotationZ = 1.0f;
bool bVisible = false;
int nTag = 0, nZorder = -1;
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
{
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue(cocoLoader);
if (key == "x")
{
x = atof(value.c_str());
node->setPositionX(x);
}
else if (key == "y")
{
y = atof(value.c_str());
node->setPositionY(y);
}
else if (key == "visible")
{
bVisible = (bool)atoi(value.c_str());
node->setVisible(bVisible);
}
else if (key == "objecttag")
{
nTag = atoi(value.c_str());
node->setTag(nTag);
}
else if (key == "zorder")
{
nZorder = atoi(value.c_str());
node->setLocalZOrder(nZorder);
}
else if(key == "scalex")
{
fScaleX = atof(value.c_str());
node->setScaleX(fScaleX);
}
else if(key == "scaley")
{
fScaleY = atof(value.c_str());
node->setScaleY(fScaleY);
}
else if(key == "rotation")
{
fRotationZ = atof(value.c_str());
node->setRotation(fRotationZ);
}
}
}
SceneReader* SceneReader::getInstance()
{

View File

@ -76,6 +76,10 @@ private:
cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node);
bool readJson(const std::string &fileName, rapidjson::Document& doc);
cocos2d::Node* createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node);
cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag);
private:
static SceneReader* s_sharedReader;

View File

@ -1,5 +1,5 @@
#include "CocoLoader.h"
#include "zlib.h"
using namespace std;
using namespace rapidjson;
@ -7,190 +7,231 @@ using namespace rapidjson;
namespace cocostudio{
char cTypeName[] = {'N','F','T','O','A','S','V'};
const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };
const char* kObjKeyName[] = { "__type" , "classname" };
char g_Buff[2048];
Type stExpCocoNode::GetType(CocoLoader* pCoco)
char* stExpCocoAttribDesc::GetName(CocoLoader* pCoco)
{
Type tType = kObjectType;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
tType = tpAttribDescArray[m_AttribIndex].m_Type;
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)m_szValue;
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
return ( pCoco->GetMemoryAddr_String() + m_szName );
}
}
else
{
tType = kObjectType;
}
}
else
{
if(m_AttribIndex >= 0)
{
tType = (Type)m_ChildNum;
char* stExpCocoObjectDesc::GetName(CocoLoader* pCoco)
{
return ( pCoco->GetMemoryAddr_String() + m_szName );
}
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)m_szValue;
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
}
else
{
tType = kArrayType;
}
}
return tType;
int stExpCocoObjectDesc::GetAttribNum()
{
return m_cAttribNum;
}
stExpCocoAttribDesc* stExpCocoObjectDesc::GetAttribDescArray(CocoLoader* pCoco)
{
return (stExpCocoAttribDesc*)( pCoco->GetMemoryAddr_AttribDesc() + m_pAttribDescArray );
}
Type stExpCocoNode::GetType(CocoLoader* pCoco)
{
Type tType = kObjectType;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray() ;
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].GetAttribDescArray(pCoco);
tType = Type(tpAttribDescArray[m_AttribIndex].m_cTypeName - 'N' + kNullType);
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)GetValue(pCoco);
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
}
else
{
tType = kObjectType;
}
}
else
{
if(m_AttribIndex >= 0)
{
tType = (Type)m_ChildNum;
if(kFalseType == tType || kTrueType == tType)
{
char* szValue = (char*)GetValue(pCoco);
if(szValue[0] == '0')
{
return kFalseType;
}
else
{
return kTrueType;
}
}
}
else
{
tType = kArrayType;
}
}
return tType;
}
char* stExpCocoNode::GetName(CocoLoader* pCoco)
{
char* szName = NULL ;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
szName = (char*)tpAttribDescArray[m_AttribIndex].m_szName;
}
else
{
char* szValue = (char*)m_szValue;
if(szValue[0])
{
szName = (char*)m_szValue;
}
else
{
szName = (char*)tpCocoObjectDesc[m_ObjIndex].m_szName;
}
}
}
else
{
if(m_AttribIndex >= 0)
{
char* pStringAddr = (char*)pCoco->GetCocoObjectDescArray() + pCoco->GetFileHeader()->m_lStringMemAddr ;
szName = m_ChildArray + pStringAddr;
}
else
{
szName = (char*)m_szValue;
}
}
return szName ;
char* szName = nullptr ;
if(m_ObjIndex >= 0)
{
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray();
if( m_AttribIndex >= 0 )
{
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].GetAttribDescArray(pCoco);
szName = tpAttribDescArray[m_AttribIndex].GetName(pCoco);
}
else
{
char* szValue = GetValue(pCoco);
if(szValue[0])
{
szName = GetValue(pCoco);
}
else
{
szName = tpCocoObjectDesc[m_ObjIndex].GetName(pCoco);
}
}
}
else
{
if(m_AttribIndex >= 0)
{
char* pStringAddr = (char*)pCoco->GetCocoObjectDescArray() + pCoco->GetFileHeader()->m_lStringMemAddr ;
szName = m_ChildArray + pStringAddr;
}
else
{
szName = (char*)GetValue(pCoco);
}
}
return szName ;
}
char* stExpCocoNode::GetValue()
{
return (char*)m_szValue;
}
char* stExpCocoNode::GetValue(CocoLoader* pCoco)
{
char* szValue = ( pCoco->GetMemoryAddr_String() + m_szValue );
if(GetType(pCoco) == kStringType )
{
if(szValue && 0==strcmp(szValue,"null"))
{
strcpy(szValue,"");
}
}
return szValue;
}
int stExpCocoNode::GetChildNum()
{
return m_ChildNum;
return m_ChildNum;
}
stExpCocoNode* stExpCocoNode::GetChildArray()
stExpCocoNode* stExpCocoNode::GetChildArray(CocoLoader* pCoco)
{
return (stExpCocoNode*)m_ChildArray;
}
void stExpCocoNode::ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr)
{
m_szValue = m_szValue + (uint64_t)pStringMemoryAddr;
if( -1 == m_AttribIndex )
{
if(m_ChildNum > 0)
{
m_ChildArray = m_ChildArray + (uint64_t)cocoNodeAddr;
stExpCocoNode* tpChildArray = (stExpCocoNode*)m_ChildArray;
for(int i = 0 ; i < m_ChildNum ; i++)
{
tpChildArray[i].ReBuild(cocoNodeAddr,pStringMemoryAddr);
}
}
}
return (stExpCocoNode*)( pCoco->GetMemoryAddr_CocoNode() + m_ChildArray );
}
CocoLoader::CocoLoader()
{
m_pRootNode = NULL;
m_pObjectDescArray = NULL;
m_pRootNode = nullptr;
m_pObjectDescArray = nullptr;
m_pMemoryBuff = nullptr;
}
CocoLoader::~CocoLoader()
{
if(m_pMemoryBuff)
{
delete[] m_pMemoryBuff;
m_pMemoryBuff = nullptr;
}
}
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
{
if(m_pMemoryBuff)return true;
char* pTempBuff = pBinBuff;
m_pFileHeader = (stCocoFileHeader*)pTempBuff;
pTempBuff += sizeof(stCocoFileHeader);
char* pStartAddr = pTempBuff;
m_pObjectDescArray = (stExpCocoObjectDesc*)pStartAddr;
char* pAttrAddr = pStartAddr + m_pFileHeader->m_lAttribMemAddr ;
char* pCocoMemAddr = pStartAddr + m_pFileHeader->m_CocoNodeMemAddr;
char* pStringAddr = pStartAddr + m_pFileHeader->m_lStringMemAddr ;
m_pRootNode = (stExpCocoNode*)pCocoMemAddr;
if(1 == m_pFileHeader->m_nFirstUsed)
{
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
{
m_pObjectDescArray[i].ReBuild(pAttrAddr,pStringAddr) ;
}
m_pRootNode->ReBuild(pCocoMemAddr,pStringAddr);
m_pFileHeader->m_nFirstUsed = 0;
char* pStartAddr = m_pMemoryBuff = pTempBuff;
if( m_pFileHeader->m_nCompressSize > 0 )
{
char* pDestBuff = new char[m_pFileHeader->m_nDataSize];
uLongf dwSrcSize = m_pFileHeader->m_nCompressSize;
uLongf dwDestSize = m_pFileHeader->m_nDataSize;
uncompress((Bytef*)pDestBuff,&dwDestSize,(Bytef*)m_pMemoryBuff,dwSrcSize);
pStartAddr = m_pMemoryBuff = pDestBuff;
}
m_pObjectDescArray = (stExpCocoObjectDesc*)pStartAddr;
char* pCocoMemAddr = pStartAddr + m_pFileHeader->m_CocoNodeMemAddr;
m_pRootNode = (stExpCocoNode*)pCocoMemAddr;
return true;
}
stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(const char* szObjDesc)
{
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
{
if(0 == strcmp((char*)m_pObjectDescArray[i].m_szName,szObjDesc))
{
return &m_pObjectDescArray[i];
}
}
return NULL;
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
{
if(0 == strcmp((char*)m_pObjectDescArray[i].m_szName,szObjDesc))
{
return &m_pObjectDescArray[i];
}
}
return nullptr;
}
stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(int vIndex)
{
if(vIndex >= 0 && vIndex < m_pFileHeader->m_ObjectCount)
{
return &m_pObjectDescArray[vIndex];
}
return nullptr;
}
char* CocoLoader::GetMemoryAddr_AttribDesc()
{
return m_pMemoryBuff + m_pFileHeader->m_lAttribMemAddr ;
}
char* CocoLoader::GetMemoryAddr_CocoNode()
{
return m_pMemoryBuff + m_pFileHeader->m_CocoNodeMemAddr;
}
char* CocoLoader::GetMemoryAddr_String()
{
return m_pMemoryBuff + m_pFileHeader->m_lStringMemAddr ;
}
}

View File

@ -36,101 +36,80 @@
namespace cocostudio{
class CocoLoader;
struct stExpCocoAttribDesc
{
rapidjson::Type m_Type;
uint64_t m_szName;
uint64_t m_szDefaultValue;
char m_cTypeName;
uint32_t m_szName;
public:
void ReBuild(char* pStringMemoryAddr)
{
m_szName = m_szName + (uint64_t)pStringMemoryAddr;
m_szDefaultValue = m_szDefaultValue + (uint64_t)pStringMemoryAddr;
}
char* GetName(CocoLoader* pCoco);
};
struct stExpCocoObjectDesc
{
uint32_t m_nAttribNum;
uint64_t m_szName;
uint64_t m_pAttribDescArray;
unsigned char m_cAttribNum;
uint32_t m_szName;
uint32_t m_pAttribDescArray;
public:
stExpCocoObjectDesc()
{
m_nAttribNum = 0;
m_szName = 0;
m_pAttribDescArray = 0;
}
void ReBuild(char* pAttribMemoryAddr,char* pStringMemoryAddr)
{
m_szName = m_szName + (uint64_t)pStringMemoryAddr;
m_pAttribDescArray = m_pAttribDescArray + (uint64_t)pAttribMemoryAddr;
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*)m_pAttribDescArray;
for(uint32_t i = 0 ; i < m_nAttribNum ; i++)
{
tpAttribDescArray[i].ReBuild(pStringMemoryAddr);
}
}
char* GetName(CocoLoader* pCoco);
int GetAttribNum();
stExpCocoAttribDesc* GetAttribDescArray(CocoLoader* pCoco);
};
class CocoLoader;
struct stExpCocoNode
struct stExpCocoNode
{
protected:
int32_t m_ObjIndex;
int32_t m_AttribIndex;
uint32_t m_ChildNum;
uint64_t m_szValue;
uint64_t m_ChildArray;
public:
rapidjson::Type GetType(CocoLoader* pCoco);
char* GetName(CocoLoader* pCoco);
char* GetValue();
int GetChildNum();
stExpCocoNode* GetChildArray();
int16_t m_ObjIndex;
int16_t m_AttribIndex;
unsigned char m_ChildNum;
uint32_t m_szValue;
uint32_t m_ChildArray;
public:
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
rapidjson::Type GetType(CocoLoader* pCoco);
char* GetName(CocoLoader* pCoco);
char* GetValue(CocoLoader* pCoco);
int GetChildNum();
stExpCocoNode* GetChildArray(CocoLoader* pCoco);
public:
void WriteJson(CocoLoader* pCoco,void* pFileName = nullptr, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
};
struct stCocoFileHeader
{
char m_FileDesc[32];
char m_Version[32];
uint32_t m_nFirstUsed;
uint32_t m_ObjectCount;
uint64_t m_lAttribMemAddr;
uint64_t m_CocoNodeMemAddr;
uint64_t m_lStringMemAddr;
char m_FileDesc[32];
char m_Version[32];
uint32_t m_nDataSize;
uint32_t m_nCompressSize;
uint32_t m_ObjectCount;
uint32_t m_lAttribMemAddr;
uint32_t m_CocoNodeMemAddr;
uint32_t m_lStringMemAddr;
};
class CocoLoader
{
private:
stCocoFileHeader* m_pFileHeader;
stExpCocoNode* m_pRootNode;
stExpCocoObjectDesc* m_pObjectDescArray;
stCocoFileHeader* m_pFileHeader;
stExpCocoNode* m_pRootNode;
stExpCocoObjectDesc* m_pObjectDescArray;
char* m_pMemoryBuff;
public:
CocoLoader();
~CocoLoader();
CocoLoader();
~CocoLoader();
public:
bool ReadCocoBinBuff(char* pBinBuff);
stCocoFileHeader* GetFileHeader(){return m_pFileHeader;}
stExpCocoNode* GetRootCocoNode(){return m_pRootNode;}
stExpCocoObjectDesc* GetCocoObjectDescArray(){return m_pObjectDescArray;}
stExpCocoObjectDesc* GetCocoObjectDesc(const char* szObjDesc);
bool ReadCocoBinBuff(char* pBinBuff);
stCocoFileHeader* GetFileHeader(){return m_pFileHeader;}
stExpCocoNode* GetRootCocoNode(){return m_pRootNode;}
stExpCocoObjectDesc* GetCocoObjectDescArray(){return m_pObjectDescArray;}
stExpCocoObjectDesc* GetCocoObjectDesc(const char* szObjDesc);
stExpCocoObjectDesc* GetCocoObjectDesc(int vIndex);
char* GetMemoryAddr_AttribDesc();
char* GetMemoryAddr_CocoNode();
char* GetMemoryAddr_String();
};
}

View File

@ -104,6 +104,44 @@ void TriggerMng::parse(const rapidjson::Value &root)
}
}
}
void TriggerMng::parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
CCLOG("%s", triggerMngVersion());
int count = pCocoNode[13].GetChildNum();
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray(pCocoLoader);
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
bool useBindings = engine != nullptr;
if (useBindings)
{
if (count > 0 )
{
rapidjson::Document document;
buildJson(document, pCocoLoader, pCocoNode);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
engine->parseConfig(ScriptEngineProtocol::ConfigType::COCOSTUDIO, buffer.GetString());
}
}
else
#endif // #if CC_ENABLE_SCRIPT_BINDING
{
for (int i = 0; i < count; ++i)
{
TriggerObj *obj = TriggerObj::create();
obj->serialize(pCocoLoader, &pTriggersArray[i]);
_triggerObjs.insert(std::pair<unsigned int, TriggerObj*>(obj->getId(), obj));
obj->retain();
}
}
}
TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
{
@ -152,6 +190,216 @@ bool TriggerMng::isEmpty(void) const
return _triggerObjs.empty();
}
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int count = pCocoNode[13].GetChildNum();
int length = 0;
int num = 0;
int size = 0;
int extent = 0;
int border = 0;
std::string key0;
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray(pCocoLoader);
document.SetArray();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
for (int i0 = 0; i0 < count; ++i0)
{
rapidjson::Value vElemItem(rapidjson::kObjectType);
border = pTriggersArray[i0].GetChildNum();
stExpCocoNode *pTriggerArray = pTriggersArray[i0].GetChildArray(pCocoLoader);
for (int i1 = 0; i1 < border; ++i1)
{
std::string key1 = pTriggerArray[i1].GetName(pCocoLoader);
const char *str1 = pTriggerArray[i1].GetValue(pCocoLoader);
if (key1.compare("actions") == 0)
{
rapidjson::Value actionsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerArray[i1].GetChildArray(pCocoLoader);
for (int i2 = 0; i2 < length; ++i2)
{
rapidjson::Value action(rapidjson::kObjectType);
num = pActionsArray[i2].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader);
for (int i3 = 0; i3 < num; ++i3)
{
std::string key2 = pActionArray[i3].GetName(pCocoLoader);
const char *str2 = pActionArray[i3].GetValue(pCocoLoader);
if (key2.compare("classname") == 0)
{
if (str2 != nullptr)
{
action.AddMember("classname", str2, allocator);
}
}
else if (key2.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pActionArray[i3].GetChildNum();
stExpCocoNode *pDataItemsArray = pActionArray[i3].GetChildArray(pCocoLoader);
for (int i4 = 0; i4 < size; ++i4)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i4].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i4].GetChildArray(pCocoLoader);
for (int i5 = 0; i5 < extent; ++i5)
{
std::string key3 = pDataItemArray[i5].GetName(pCocoLoader);
const char *str3 = pDataItemArray[i5].GetValue(pCocoLoader);
if (key3.compare("key") == 0)
{
if (str3 != nullptr)
{
dataitem.AddMember("key", str3, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i4].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str3, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str3);
float fV = atof(str3);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
action.AddMember("dataitems", dataitems, allocator);
}
}
actionsItem.PushBack(action, allocator);
}
vElemItem.AddMember("actions", actionsItem, allocator);
}
else if (key1.compare("conditions") == 0)
{
rapidjson::Value condsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerArray[i1].GetChildArray(pCocoLoader);
for (int i6 = 0; i6 < length; ++i6)
{
rapidjson::Value cond(rapidjson::kObjectType);
num = pConditionsArray[i6].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i6].GetChildArray(pCocoLoader);
for (int i7 = 0; i7 < num; ++i7)
{
std::string key4 = pConditionArray[i7].GetName(pCocoLoader);
const char *str4 = pConditionArray[i7].GetValue(pCocoLoader);
if (key4.compare("classname") == 0)
{
if (str4 != nullptr)
{
cond.AddMember("classname", str4, allocator);
}
}
else if (key4.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pConditionArray[i7].GetChildNum();
stExpCocoNode *pDataItemsArray = pConditionArray[i7].GetChildArray(pCocoLoader);
for (int i8 = 0; i8 < size; ++i8)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i8].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i8].GetChildArray(pCocoLoader);
for (int i9 = 0; i9 < extent; ++i9)
{
std::string key5 = pDataItemArray[i9].GetName(pCocoLoader);
const char *str5 = pDataItemArray[i9].GetValue(pCocoLoader);
if (key5.compare("key") == 0)
{
if (str5 != nullptr)
{
dataitem.AddMember("key", str5, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i9].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str5, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str5);
float fV = atof(str5);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
cond.AddMember("dataitems", dataitems, allocator);
}
}
condsItem.PushBack(cond, allocator);
}
vElemItem.AddMember("conditions", condsItem, allocator);
}
else if (key1.compare("events") == 0)
{
rapidjson::Value eventsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerArray[i1].GetChildArray(pCocoLoader);
for (int i10 = 0; i10 < length; ++i10)
{
rapidjson::Value event(rapidjson::kObjectType);
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 != nullptr)
{
event.AddMember("id", atoi(str6), allocator);
eventsItem.PushBack(event, allocator);
}
}
vElemItem.AddMember("events", eventsItem, allocator);
}
else if (key1.compare("id") == 0)
{
if (str1 != nullptr)
{
vElemItem.AddMember("id", atoi(str1), allocator);
}
}
}
document.PushBack(vElemItem, allocator);
}
}
void TriggerMng::addArmatureMovementCallBack(Armature *pAr, Ref *pTarget, SEL_MovementEventCallFunc mecf)
{
if (pAr == nullptr || _movementDispatches == nullptr || pTarget == nullptr || mecf == nullptr)

View File

@ -64,6 +64,7 @@ public:
public:
void parse(const rapidjson::Value &root);
void parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
void removeAll(void);
cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
TriggerObj* getTriggerObj(unsigned int id) const;
@ -78,6 +79,8 @@ public:
void dispatchEvent(cocos2d::EventCustom* tEvent);
void removeEventListener(cocos2d::EventListener* listener);
void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority);
private:
void buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
private:
static TriggerMng *_sharedTriggerMng;

View File

@ -48,6 +48,11 @@ bool BaseTriggerCondition::detect()
void BaseTriggerCondition::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerCondition::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerCondition::removeAll()
{
@ -75,6 +80,10 @@ void BaseTriggerAction::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerAction::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerAction::removeAll()
{
}
@ -231,6 +240,102 @@ void TriggerObj::serialize(const rapidjson::Value &val)
}
}
void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
int num = 0;
stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray(pCocoLoader);
for (int i0 = 0; i0 < length; ++i0)
{
std::string key = pTriggerObjArray[i0].GetName(pCocoLoader);
const char* str0 = pTriggerObjArray[i0].GetValue(pCocoLoader);
if (key.compare("id") == 0)
{
if (str0 != nullptr)
{
_id = atoi(str0); //(unsigned int)(DICTOOL->getIntValue_json(val, "id"));
}
}
else if (key.compare("conditions") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader);
for (int i1 = 0; i1 < count; ++i1)
{
num = pConditionsArray[i1].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i1].GetChildArray(pCocoLoader);
const char *classname = pConditionArray[0].GetValue(pCocoLoader);
if (classname == nullptr)
{
continue;
}
BaseTriggerCondition *con = dynamic_cast<BaseTriggerCondition*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(con != nullptr, "class named classname can not implement!");
con->serialize(pCocoLoader, &pConditionArray[1]);
con->init();
_cons.pushBack(con);
}
}
else if (key.compare("actions") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader);
for (int i2 = 0; i2 < count; ++i2)
{
num = pActionsArray[i2].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader);
const char *classname = pActionArray[0].GetValue(pCocoLoader);
if (classname == nullptr)
{
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(act != nullptr, "class named classname can not implement!");
act->serialize(pCocoLoader, &pActionArray[1]);
act->init();
_acts.pushBack(act);
}
}
else if (key.compare("events") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader);
for (int i3 = 0; i3 < count; ++i3)
{
num = pEventsArray[i3].GetChildNum();
stExpCocoNode *pEventArray = pEventsArray[i3].GetChildArray(pCocoLoader);
const char *str1 = pEventArray[0].GetValue(pCocoLoader);
if (str1 == nullptr)
{
continue;
}
int event = atoi(str1);
if (event < 0)
{
continue;
}
char* buf = new char[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
CC_SAFE_DELETE_ARRAY(buf);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
}
}
unsigned int TriggerObj::getId()
{
return _id;

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