From 2ca5c01902138d659c678af8a3134ceffbb66de4 Mon Sep 17 00:00:00 2001 From: LinWenhai Date: Fri, 4 Jul 2014 21:24:32 +0800 Subject: [PATCH] issue #4689: Refactoring game controller API[ios] --- build/cocos2d_libs.xcodeproj/project.pbxproj | 52 +-- build/cocos2d_tests.xcodeproj/project.pbxproj | 6 +- cocos/base/CCController-iOS.mm | 375 ++++++++---------- cocos/base/CCController.cpp | 2 +- cocos/base/CCController.h | 1 + .../Classes/GameControllerTest.cpp | 30 +- .../Classes/GameControllerTest.h | 4 +- 7 files changed, 176 insertions(+), 294 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index ecf07d8ded..afffa6f339 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1025,23 +1025,12 @@ 373B912A187891FB00198F86 /* CCComBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 373B910718787C0B00198F86 /* CCComBase.h */; }; 3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */; }; 3E6176691960F89B00DE83F5 /* CCController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176561960F89B00DE83F5 /* CCController.h */; }; - 3E61766A1960F89B00DE83F5 /* CCControllerAxisInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */; }; - 3E61766B1960F89B00DE83F5 /* CCControllerAxisInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */; }; - 3E61766C1960F89B00DE83F5 /* CCControllerButtonInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */; }; - 3E61766D1960F89B00DE83F5 /* CCControllerButtonInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */; }; - 3E61766E1960F89B00DE83F5 /* CCControllerDirectionPad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */; }; - 3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */; }; - 3E6176701960F89B00DE83F5 /* CCControllerElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */; }; - 3E6176711960F89B00DE83F5 /* CCControllerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61765E1960F89B00DE83F5 /* CCControllerElement.h */; }; - 3E6176721960F89B00DE83F5 /* CCControllerThumbstick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */; }; - 3E6176731960F89B00DE83F5 /* CCControllerThumbstick.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */; }; 3E6176741960F89B00DE83F5 /* CCEventController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176611960F89B00DE83F5 /* CCEventController.cpp */; }; 3E6176751960F89B00DE83F5 /* CCEventController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176621960F89B00DE83F5 /* CCEventController.h */; }; 3E6176761960F89B00DE83F5 /* CCEventListenerController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */; }; 3E6176771960F89B00DE83F5 /* CCEventListenerController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176641960F89B00DE83F5 /* CCEventListenerController.h */; }; 3E6176781960F89B00DE83F5 /* CCGameController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176651960F89B00DE83F5 /* CCGameController.h */; }; - 3E6176791960F89B00DE83F5 /* CCGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176661960F89B00DE83F5 /* CCGamepad.cpp */; }; - 3E61767A1960F89B00DE83F5 /* CCGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176671960F89B00DE83F5 /* CCGamepad.h */; }; + 3E61781D1966A5A300DE83F5 /* CCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E61781C1966A5A300DE83F5 /* CCController.cpp */; }; 3EA0FB6B191C841D00B170C8 /* UIVideoPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */; }; 3EA0FB6C191C841D00B170C8 /* UIVideoPlayerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */; }; 3EA47870195478E00068D9D1 /* CCBundleReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */; }; @@ -2370,23 +2359,12 @@ 37936A3E1869B76800E974DD /* writer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = writer.h; sourceTree = ""; }; 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = "CCController-iOS.mm"; path = "../base/CCController-iOS.mm"; sourceTree = ""; }; 3E6176561960F89B00DE83F5 /* CCController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCController.h; path = ../base/CCController.h; sourceTree = ""; }; - 3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerAxisInput.cpp; path = ../base/CCControllerAxisInput.cpp; sourceTree = ""; }; - 3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerAxisInput.h; path = ../base/CCControllerAxisInput.h; sourceTree = ""; }; - 3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerButtonInput.cpp; path = ../base/CCControllerButtonInput.cpp; sourceTree = ""; }; - 3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerButtonInput.h; path = ../base/CCControllerButtonInput.h; sourceTree = ""; }; - 3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerDirectionPad.cpp; path = ../base/CCControllerDirectionPad.cpp; sourceTree = ""; }; - 3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerDirectionPad.h; path = ../base/CCControllerDirectionPad.h; sourceTree = ""; }; - 3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerElement.cpp; path = ../base/CCControllerElement.cpp; sourceTree = ""; }; - 3E61765E1960F89B00DE83F5 /* CCControllerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerElement.h; path = ../base/CCControllerElement.h; sourceTree = ""; }; - 3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCControllerThumbstick.cpp; path = ../base/CCControllerThumbstick.cpp; sourceTree = ""; }; - 3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCControllerThumbstick.h; path = ../base/CCControllerThumbstick.h; sourceTree = ""; }; 3E6176611960F89B00DE83F5 /* CCEventController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventController.cpp; path = ../base/CCEventController.cpp; sourceTree = ""; }; 3E6176621960F89B00DE83F5 /* CCEventController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventController.h; path = ../base/CCEventController.h; sourceTree = ""; }; 3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventListenerController.cpp; path = ../base/CCEventListenerController.cpp; sourceTree = ""; }; 3E6176641960F89B00DE83F5 /* CCEventListenerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventListenerController.h; path = ../base/CCEventListenerController.h; sourceTree = ""; }; 3E6176651960F89B00DE83F5 /* CCGameController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGameController.h; path = ../base/CCGameController.h; sourceTree = ""; }; - 3E6176661960F89B00DE83F5 /* CCGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCGamepad.cpp; path = ../base/CCGamepad.cpp; sourceTree = ""; }; - 3E6176671960F89B00DE83F5 /* CCGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGamepad.h; path = ../base/CCGamepad.h; sourceTree = ""; }; + 3E61781C1966A5A300DE83F5 /* CCController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCController.cpp; path = ../base/CCController.cpp; sourceTree = ""; }; 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoPlayer.h; sourceTree = ""; }; 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIVideoPlayerIOS.mm; sourceTree = ""; }; 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBundleReader.cpp; sourceTree = ""; }; @@ -3187,25 +3165,14 @@ 1A5700A2180BC5E60088DEC7 /* base */ = { isa = PBXGroup; children = ( + 3E61781C1966A5A300DE83F5 /* CCController.cpp */, 3E6176551960F89B00DE83F5 /* CCController-iOS.mm */, 3E6176561960F89B00DE83F5 /* CCController.h */, - 3E6176571960F89B00DE83F5 /* CCControllerAxisInput.cpp */, - 3E6176581960F89B00DE83F5 /* CCControllerAxisInput.h */, - 3E6176591960F89B00DE83F5 /* CCControllerButtonInput.cpp */, - 3E61765A1960F89B00DE83F5 /* CCControllerButtonInput.h */, - 3E61765B1960F89B00DE83F5 /* CCControllerDirectionPad.cpp */, - 3E61765C1960F89B00DE83F5 /* CCControllerDirectionPad.h */, - 3E61765D1960F89B00DE83F5 /* CCControllerElement.cpp */, - 3E61765E1960F89B00DE83F5 /* CCControllerElement.h */, - 3E61765F1960F89B00DE83F5 /* CCControllerThumbstick.cpp */, - 3E6176601960F89B00DE83F5 /* CCControllerThumbstick.h */, 3E6176611960F89B00DE83F5 /* CCEventController.cpp */, 3E6176621960F89B00DE83F5 /* CCEventController.h */, 3E6176631960F89B00DE83F5 /* CCEventListenerController.cpp */, 3E6176641960F89B00DE83F5 /* CCEventListenerController.h */, 3E6176651960F89B00DE83F5 /* CCGameController.h */, - 3E6176661960F89B00DE83F5 /* CCGamepad.cpp */, - 3E6176671960F89B00DE83F5 /* CCGamepad.h */, 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */, 299754F3193EC95400A54AC3 /* ObjectFactory.h */, 50ABBDC11925AB6E00A911A9 /* atitc.cpp */, @@ -5571,7 +5538,6 @@ 1A570068180BC5A10088DEC7 /* CCActionCamera.h in Headers */, 1A57006C180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */, 5034CA3A191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */, - 3E61766B1960F89B00DE83F5 /* CCControllerAxisInput.h in Headers */, 50ABBEC41925AB6F00A911A9 /* CCVector.h in Headers */, 50ABBE501925AB6F00A911A9 /* CCEventCustom.h in Headers */, 1A570070180BC5A10088DEC7 /* CCActionEase.h in Headers */, @@ -5608,7 +5574,6 @@ 50ABC0101926664800A911A9 /* CCFileUtils.h in Headers */, 2905FA4318CF08D100240AA3 /* CocosGUI.h in Headers */, 5034CA30191D591100CE6051 /* ccShader_PositionTexture.vert in Headers */, - 3E6176711960F89B00DE83F5 /* CCControllerElement.h in Headers */, 50E6D33718E174130051CA34 /* UIHBox.h in Headers */, 1A570111180BC8EE0088DEC7 /* CCDrawingPrimitives.h in Headers */, 50E6D33F18E174130051CA34 /* UIVBox.h in Headers */, @@ -5676,7 +5641,6 @@ 5034CA2C191D591100CE6051 /* ccShader_PositionTextureA8Color.vert in Headers */, 50ABBE981925AB6F00A911A9 /* CCProtocols.h in Headers */, 2905FA8B18CF08D100240AA3 /* UITextField.h in Headers */, - 3E6176731960F89B00DE83F5 /* CCControllerThumbstick.h in Headers */, 50FCEBA618C72017004AD434 /* ListViewReader.h in Headers */, 50ABBD431925AB0000A911A9 /* CCMathBase.h in Headers */, 50ABBE441925AB6F00A911A9 /* CCDirector.h in Headers */, @@ -5695,7 +5659,6 @@ 50ABBE741925AB6F00A911A9 /* CCEventListenerMouse.h in Headers */, 2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */, 50FCEB9A18C72017004AD434 /* CheckBoxReader.h in Headers */, - 3E61766D1960F89B00DE83F5 /* CCControllerButtonInput.h in Headers */, 1A5702CB180BCE370088DEC7 /* CCTextFieldTTF.h in Headers */, 2905FA7F18CF08D100240AA3 /* UIText.h in Headers */, 1A5702ED180BCE750088DEC7 /* CCTileMapAtlas.h in Headers */, @@ -5708,7 +5671,6 @@ 1A570303180BCE890088DEC7 /* CCParallaxNode.h in Headers */, 50ABBE2A1925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */, 1A57030F180BCF190088DEC7 /* CCComponent.h in Headers */, - 3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */, 1A570313180BCF190088DEC7 /* CCComponentContainer.h in Headers */, 0634A4DF194B19E400E608AF /* CCNodeReader.h in Headers */, 1A087AEB1860400400196EF5 /* edtaa3func.h in Headers */, @@ -5815,7 +5777,6 @@ 1AD71ED0180E26E600808F54 /* Skeleton.h in Headers */, 50ABBE541925AB6F00A911A9 /* CCEventDispatcher.h in Headers */, 1AD71ED4180E26E600808F54 /* SkeletonData.h in Headers */, - 3E61767A1960F89B00DE83F5 /* CCGamepad.h in Headers */, 1AD71ED8180E26E600808F54 /* SkeletonJson.h in Headers */, 1A12775A18DFCC4F0005F345 /* CCTweenFunction.h in Headers */, 1AD71EDC180E26E600808F54 /* Skin.h in Headers */, @@ -6752,7 +6713,6 @@ 3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */, 2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */, 29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */, - 3E61766C1960F89B00DE83F5 /* CCControllerButtonInput.cpp in Sources */, B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */, 0634A4D5194B19E400E608AF /* CCActionTimelineCache.cpp in Sources */, 50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */, @@ -6792,6 +6752,7 @@ 1A57019E180BCB590088DEC7 /* CCFont.cpp in Sources */, 503DD8E21926736A00CD74DD /* CCCommon.mm in Sources */, 1A5701A2180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */, + 3E61781D1966A5A300DE83F5 /* CCController.cpp in Sources */, 50ABC00E1926664800A911A9 /* CCFileUtils.cpp in Sources */, 50ABBE241925AB6F00A911A9 /* base64.cpp in Sources */, 1A5701A6180BCB590088DEC7 /* CCFontAtlasCache.cpp in Sources */, @@ -6831,13 +6792,11 @@ 1A570215180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */, 1A570222180BCC1A0088DEC7 /* CCParticleBatchNode.cpp in Sources */, 1A570226180BCC1A0088DEC7 /* CCParticleExamples.cpp in Sources */, - 3E6176791960F89B00DE83F5 /* CCGamepad.cpp in Sources */, 1A57022A180BCC1A0088DEC7 /* CCParticleSystem.cpp in Sources */, B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */, B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */, 1A57022E180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */, 50ABBD901925AB4100A911A9 /* CCGLProgramCache.cpp in Sources */, - 3E6176701960F89B00DE83F5 /* CCControllerElement.cpp in Sources */, 2905FA5718CF08D100240AA3 /* UILayout.cpp in Sources */, 2905FA7D18CF08D100240AA3 /* UIText.cpp in Sources */, 50E6D33D18E174130051CA34 /* UIVBox.cpp in Sources */, @@ -6853,7 +6812,6 @@ 1A5702C9180BCE370088DEC7 /* CCTextFieldTTF.cpp in Sources */, 1A5702EB180BCE750088DEC7 /* CCTileMapAtlas.cpp in Sources */, 1A5702EF180BCE750088DEC7 /* CCTMXLayer.cpp in Sources */, - 3E61766A1960F89B00DE83F5 /* CCControllerAxisInput.cpp in Sources */, 1A5702F3180BCE750088DEC7 /* CCTMXObjectGroup.cpp in Sources */, 50ABBD3D1925AB0000A911A9 /* CCGeometry.cpp in Sources */, 50ABBECC1925AB6F00A911A9 /* s3tc.cpp in Sources */, @@ -6966,7 +6924,6 @@ 50ABBE9A1925AB6F00A911A9 /* CCRef.cpp in Sources */, 3E6176741960F89B00DE83F5 /* CCEventController.cpp in Sources */, 50ABBE361925AB6F00A911A9 /* CCConsole.cpp in Sources */, - 3E61766E1960F89B00DE83F5 /* CCControllerDirectionPad.cpp in Sources */, 503DD8E51926736A00CD74DD /* CCDirectorCaller.mm in Sources */, 50ABBD5D1925AB0000A911A9 /* Vec3.cpp in Sources */, 50ABC0121926664800A911A9 /* CCGLViewProtocol.cpp in Sources */, @@ -7005,7 +6962,6 @@ 1A8C59D4180E930E00EF57C3 /* CCDecorativeDisplay.cpp in Sources */, 1A8C59D8180E930E00EF57C3 /* CCDisplayFactory.cpp in Sources */, 46C02E0818E91123004B7456 /* xxhash.c in Sources */, - 3E6176721960F89B00DE83F5 /* CCControllerThumbstick.cpp in Sources */, 50ABBED01925AB6F00A911A9 /* TGAlib.cpp in Sources */, 2905FA4118CF08D100240AA3 /* CocosGUI.cpp in Sources */, 1A01C68518F57BE800EFE3A6 /* CCArray.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 2c889dbc87..003fb4fd48 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -827,8 +827,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 */; }; @@ -2132,8 +2130,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 */, @@ -5728,6 +5724,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 +5742,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"; diff --git a/cocos/base/CCController-iOS.mm b/cocos/base/CCController-iOS.mm index 69ecbf88ad..8daa45e47e 100644 --- a/cocos/base/CCController-iOS.mm +++ b/cocos/base/CCController-iOS.mm @@ -27,17 +27,12 @@ #include "base/CCPlatformConfig.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "CCGamepad.h" -#include "CCControllerDirectionPad.h" -#include "CCControllerButtonInput.h" -#include "CCControllerAxisInput.h" -#include "CCControllerThumbstick.h" - #include "ccMacros.h" #include "CCEventDispatcher.h" #include "CCEventController.h" #include "CCEventListenerController.h" #include "CCDirector.h" +#include "CCLabel.h" #import @@ -105,90 +100,50 @@ 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::_controllers; - -const std::vector& Controller::getControllers() -{ - return _controllers; -} +std::vector Controller::s_allController; void Controller::startDiscoveryController() { [GCController startWirelessControllerDiscoveryWithCompletionHandler: nil]; [[GCControllerConnectionEventHandler getInstance] observerConnection: ^(GCController* gcController) { + auto controller = new Controller(); controller->_impl->_gcController = gcController; - gcController.controllerPausedHandler = ^(GCController* gcCon){ - - auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcCon](Controller* c){ return c->_impl->_gcController == gcCon; }); - - CCASSERT(iter != _controllers.end(), "Could not find the controller"); - - auto button = (*iter)->getGamepad()->getButtonPause(); - button->setPressed(true); - EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, (*iter), button); - Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt); - - // Reset the pause button status to unpressed. - button->setPressed(false); - }; + s_allController.push_back(controller); - _controllers.push_back(controller); + controller->registerListeners(); + controller->getDeviceName(); - - EventController evt(EventController::ControllerEventType::CONNECTION, controller, true); - Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt); + controller->onConnected(); } disconnection: ^(GCController* gcController) { + auto iter = std::find_if(s_allController.begin(), s_allController.end(), [gcController](Controller* c){ return c->_impl->_gcController == gcController; }); - auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcController](Controller* c){ return c->_impl->_gcController == gcController; }); + if(iter == s_allController.end()) + { + log("disconnect:Could not find the controller"); + return; + } - CCASSERT(iter != _controllers.end(), "Could not find the controller"); + (*iter)->onDisconnected(); + s_allController.erase(iter); - EventController evt(EventController::ControllerEventType::CONNECTION, *iter, false); - Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt); - - delete (*iter); - _controllers.erase(iter); }]; } @@ -198,26 +153,165 @@ 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); + }; +} + +const std::string& Controller::getDeviceName() +{ + if (_deviceName.empty()) + { + _deviceName = [_impl->_gcController.vendorName UTF8String]; + } + return _deviceName; } bool Controller::isConnected() const @@ -225,147 +319,6 @@ bool Controller::isConnected() const return _impl->_gcController.isAttachedToDevice == YES; } -int Controller::getPlayerIndex() const -{ - return _playerIndex; -} - -void Controller::setPlayerIndex(int playerIndex) -{ - _playerIndex = playerIndex; -} - -Gamepad* Controller::getGamepad() const -{ - if (_impl->_gcController == nil) - return nullptr; - if(_impl->_gcController.gamepad == nil && _impl->_gcController.extendedGamepad == nil) - { - CCASSERT(false, "No gamepad was found!"); - } - else if (_impl->_lazyRegisterListener) - { - _impl->_lazyRegisterListener = false; - if (_impl->_gcController.extendedGamepad != nil) - { - _impl->_gcController.extendedGamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getUp(), button); - }; - - _impl->_gcController.extendedGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getDown(), button); - }; - - _impl->_gcController.extendedGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getLeft(), button); - }; - - _impl->_gcController.extendedGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getRight(), button); - }; - - _impl->_gcController.extendedGamepad.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){ - sendEventAxis(_gamepad->getLeftThumbstick()->getAxisX(), axis); - }; - - _impl->_gcController.extendedGamepad.leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){ - sendEventAxis(_gamepad->getLeftThumbstick()->getAxisY(), axis); - }; - - _impl->_gcController.extendedGamepad.rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){ - sendEventAxis(_gamepad->getRightThumbstick()->getAxisX(), axis); - }; - - _impl->_gcController.extendedGamepad.rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value){ - sendEventAxis(_gamepad->getRightThumbstick()->getAxisY(), axis); - }; - - _impl->_gcController.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element){ - if (element == gamepad.buttonA) - { - sendEventButton(_gamepad->getButtonA(), gamepad.buttonA); - } - else if (element == gamepad.buttonB) - { - sendEventButton(_gamepad->getButtonB(), gamepad.buttonB); - } - else if (element == gamepad.buttonX) - { - sendEventButton(_gamepad->getButtonX(), gamepad.buttonX); - } - else if (element == gamepad.buttonY) - { - sendEventButton(_gamepad->getButtonY(), gamepad.buttonY); - } - else if (element == gamepad.leftShoulder) - { - sendEventButton(_gamepad->getLeftShoulder(), gamepad.leftShoulder); - } - else if (element == gamepad.rightShoulder) - { - sendEventButton(_gamepad->getRightShoulder(), gamepad.rightShoulder); - } - else if (element == gamepad.leftTrigger) - { - sendEventButton(_gamepad->getLeftTrigger(), gamepad.leftTrigger); - } - else if (element == gamepad.rightTrigger) - { - sendEventButton(_gamepad->getRightTrigger(), gamepad.rightTrigger); - } - }; - } - else - { - _impl->_gcController.gamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getUp(), button); - }; - - _impl->_gcController.gamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getDown(), button); - }; - - _impl->_gcController.gamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getLeft(), button); - }; - - _impl->_gcController.gamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){ - sendEventButton(_gamepad->getDirectionPad()->getRight(), button); - }; - - _impl->_gcController.gamepad.valueChangedHandler = ^(GCGamepad *gamepad, GCControllerElement *element){ - - if (element == gamepad.buttonA) - { - sendEventButton(_gamepad->getButtonA(), gamepad.buttonA); - } - else if (element == gamepad.buttonB) - { - sendEventButton(_gamepad->getButtonB(), gamepad.buttonB); - } - else if (element == gamepad.buttonX) - { - sendEventButton(_gamepad->getButtonX(), gamepad.buttonX); - } - else if (element == gamepad.buttonY) - { - sendEventButton(_gamepad->getButtonY(), gamepad.buttonY); - } - else if (element == gamepad.leftShoulder) - { - sendEventButton(_gamepad->getLeftShoulder(), gamepad.leftShoulder); - } - else if (element == gamepad.rightShoulder) - { - sendEventButton(_gamepad->getRightShoulder(), gamepad.rightShoulder); - } - }; - } - } - - return _gamepad; -} - NS_CC_END #endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) diff --git a/cocos/base/CCController.cpp b/cocos/base/CCController.cpp index 58f6522b1a..566b80ad52 100644 --- a/cocos/base/CCController.cpp +++ b/cocos/base/CCController.cpp @@ -25,7 +25,7 @@ #include "CCController.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "ccMacros.h" #include "CCEventDispatcher.h" diff --git a/cocos/base/CCController.h b/cocos/base/CCController.h index 52feac5481..61013b8953 100644 --- a/cocos/base/CCController.h +++ b/cocos/base/CCController.h @@ -114,6 +114,7 @@ private: 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 _allKeyStatus; std::unordered_map _allKeyPrevStatus; diff --git a/tests/game-controller-test/Classes/GameControllerTest.cpp b/tests/game-controller-test/Classes/GameControllerTest.cpp index 0f9f860a4d..9e535b6d64 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.cpp +++ b/tests/game-controller-test/Classes/GameControllerTest.cpp @@ -283,32 +283,6 @@ void GameControllerTest::onAxisEvent(cocos2d::Controller* controller, int keyCod } } -void GameControllerTest::update(float dt) -{ - /*if (_player1 && _player1->isConnected()) - { - auto gamePad = _player1->getGamepad(); - - Vec2 newPos = _leftActor->getPosition(); - newPos.x += gamePad->getLeftThumbstick()->getAxisX()->getValue(); - newPos.y -= gamePad->getLeftThumbstick()->getAxisY()->getValue(); - adjustActorPos(newPos); - _leftActor->setPosition(newPos); - - newPos = _rightActor->getPosition(); - newPos.x += gamePad->getRightThumbstick()->getAxisX()->getValue(); - newPos.y -= gamePad->getRightThumbstick()->getAxisY()->getValue(); - adjustActorPos(newPos); - _rightActor->setPosition(newPos); - - char triggerStatus[50]; - sprintf(triggerStatus,"left trigger:%f",gamePad->getLeftTrigger()->getValue()); - _leftTriggerLabel->setString(triggerStatus); - sprintf(triggerStatus,"right trigger:%f",gamePad->getRightTrigger()->getValue()); - _rightTriggerLabel->setString(triggerStatus); - }*/ -} - bool GameControllerTest::init() { if ( !Layer::init() ) @@ -341,7 +315,7 @@ bool GameControllerTest::init() auto menu = Menu::create(closeItem,nullptr); menu->setPosition(Vec2::ZERO); this->addChild(menu); - + registerControllerListener(); return true; @@ -376,7 +350,7 @@ void GameControllerTest::createControllerSprite(ControllerHolder& holder) holder._holderNode->addChild(holder._deviceIdLabel); //----------------------------------------------------------------- //371,294 64 - auto dPadTexture = Director::sharedDirector()->getTextureCache()->addImage("dPad.png"); + auto dPadTexture = Director::getInstance()->getTextureCache()->addImage("dPad.png"); auto dPadCenter = Sprite::createWithTexture(dPadTexture,Rect(60,60,68,68)); dPadCenter->setPosition(Vec2(371,294)); diff --git a/tests/game-controller-test/Classes/GameControllerTest.h b/tests/game-controller-test/Classes/GameControllerTest.h index f2a2e6fd3e..26b843e534 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.h +++ b/tests/game-controller-test/Classes/GameControllerTest.h @@ -18,9 +18,9 @@ public: void onKeyDown(cocos2d::Controller* controller, int keyCode, cocos2d::Event* event); void onKeyUp(cocos2d::Controller* controller, int keyCode, cocos2d::Event* event); void onAxisEvent(cocos2d::Controller* controller, int keyCode, cocos2d::Event* event); - - void update(float dt); + void menuCloseCallback(Ref* sender); + private: float _visibleCentreX; float _visibleCentreY;