mirror of https://github.com/axmolengine/axmol.git
Add controller support for Linux and Win32 (#17990)
* Add controller support for Linux and Win32 * Fix iOS and Mac linker issue * Fixed documentation. Removed unnecessary whitespace.
This commit is contained in:
parent
1c55ad104d
commit
5dd81e758a
|
@ -1277,6 +1277,8 @@
|
|||
C5384A7E1C85314A00EC986E /* UITabControlTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C5384A7C1C8530E200EC986E /* UITabControlTest.cpp */; };
|
||||
C5384A7F1C8531A700EC986E /* UITabControlTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C5384A7C1C8530E200EC986E /* UITabControlTest.cpp */; };
|
||||
C5384A801C85339200EC986E /* UITabControlTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C5384A7C1C8530E200EC986E /* UITabControlTest.cpp */; };
|
||||
C8DE9E471F0EACE400B48C6B /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50FC3FA01D74C15B001C936A /* GameController.framework */; };
|
||||
C8DE9E491F0EAECD00B48C6B /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8DE9E481F0EAECD00B48C6B /* GameController.framework */; };
|
||||
D0FD03641A3B546400825BB5 /* AllocatorTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0FD03621A3B546400825BB5 /* AllocatorTest.cpp */; };
|
||||
D0FD03651A3B546400825BB5 /* AllocatorTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0FD03621A3B546400825BB5 /* AllocatorTest.cpp */; };
|
||||
D60AE43417F7FFE100757E4B /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D60AE43317F7FFE100757E4B /* CoreMotion.framework */; };
|
||||
|
@ -2486,6 +2488,7 @@
|
|||
C08689C018D370C90093E810 /* background.caf */ = {isa = PBXFileReference; lastKnownFileType = file; name = background.caf; path = "../tests/cpp-tests/Resources/background.caf"; sourceTree = "<group>"; };
|
||||
C5384A7C1C8530E200EC986E /* UITabControlTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UITabControlTest.cpp; path = UITabControlTest/UITabControlTest.cpp; sourceTree = "<group>"; };
|
||||
C5384A7D1C8530E200EC986E /* UITabControlTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UITabControlTest.h; path = UITabControlTest/UITabControlTest.h; sourceTree = "<group>"; };
|
||||
C8DE9E481F0EAECD00B48C6B /* GameController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameController.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/GameController.framework; sourceTree = DEVELOPER_DIR; };
|
||||
D0FD03621A3B546400825BB5 /* AllocatorTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AllocatorTest.cpp; path = AllocatorTest/AllocatorTest.cpp; sourceTree = "<group>"; };
|
||||
D0FD03631A3B546400825BB5 /* AllocatorTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AllocatorTest.h; path = AllocatorTest/AllocatorTest.h; sourceTree = "<group>"; };
|
||||
D60AE43317F7FFE100757E4B /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreMotion.framework; sourceTree = DEVELOPER_DIR; };
|
||||
|
@ -2599,6 +2602,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C8DE9E471F0EACE400B48C6B /* GameController.framework in Frameworks */,
|
||||
185663581B4155D3009EF2AE /* Security.framework in Frameworks */,
|
||||
185664951B4246C9009EF2AE /* libsqlite3.dylib in Frameworks */,
|
||||
185664941B4246BA009EF2AE /* AppKit.framework in Frameworks */,
|
||||
|
@ -2622,6 +2626,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C8DE9E491F0EAECD00B48C6B /* GameController.framework in Frameworks */,
|
||||
294D7D8F1D0E50B2002CE7B7 /* CoreText.framework in Frameworks */,
|
||||
4B5C5BB11CA114C700D55A14 /* Security.framework in Frameworks */,
|
||||
18FC4D5F1B4257CD00B76F95 /* libsqlite3.dylib in Frameworks */,
|
||||
|
@ -4541,6 +4546,7 @@
|
|||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C8DE9E481F0EAECD00B48C6B /* GameController.framework */,
|
||||
50FC3FA01D74C15B001C936A /* GameController.framework */,
|
||||
29DC5A1E1CFFE5E700CF2930 /* CoreText.framework */,
|
||||
4B5C5BB41CA114DB00D55A14 /* Security.framework */,
|
||||
|
|
|
@ -423,17 +423,21 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\openssl\prebuilt\win32\*.*" "$(OutDir)"
|
|||
<ClCompile Include="..\base\ccCArray.cpp" />
|
||||
<ClCompile Include="..\base\CCConfiguration.cpp" />
|
||||
<ClCompile Include="..\base\CCConsole.cpp" />
|
||||
<ClCompile Include="..\base\CCController.cpp" />
|
||||
<ClCompile Include="..\base\CCController-linux-win32.cpp" />
|
||||
<ClCompile Include="..\base\CCData.cpp" />
|
||||
<ClCompile Include="..\base\CCDataVisitor.cpp" />
|
||||
<ClCompile Include="..\base\CCDirector.cpp" />
|
||||
<ClCompile Include="..\base\CCEvent.cpp" />
|
||||
<ClCompile Include="..\base\CCEventAcceleration.cpp" />
|
||||
<ClCompile Include="..\base\CCEventController.cpp" />
|
||||
<ClCompile Include="..\base\CCEventCustom.cpp" />
|
||||
<ClCompile Include="..\base\CCEventDispatcher.cpp" />
|
||||
<ClCompile Include="..\base\CCEventFocus.cpp" />
|
||||
<ClCompile Include="..\base\CCEventKeyboard.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListener.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListenerAcceleration.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListenerController.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListenerCustom.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListenerFocus.cpp" />
|
||||
<ClCompile Include="..\base\CCEventListenerKeyboard.cpp" />
|
||||
|
@ -1019,17 +1023,20 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\openssl\prebuilt\win32\*.*" "$(OutDir)"
|
|||
<ClInclude Include="..\base\ccConfig.h" />
|
||||
<ClInclude Include="..\base\CCConfiguration.h" />
|
||||
<ClInclude Include="..\base\CCConsole.h" />
|
||||
<ClInclude Include="..\base\CCController.h" />
|
||||
<ClInclude Include="..\base\CCData.h" />
|
||||
<ClInclude Include="..\base\CCDataVisitor.h" />
|
||||
<ClInclude Include="..\base\CCDirector.h" />
|
||||
<ClInclude Include="..\base\CCEvent.h" />
|
||||
<ClInclude Include="..\base\CCEventAcceleration.h" />
|
||||
<ClInclude Include="..\base\CCEventController.h" />
|
||||
<ClInclude Include="..\base\CCEventCustom.h" />
|
||||
<ClInclude Include="..\base\CCEventDispatcher.h" />
|
||||
<ClInclude Include="..\base\CCEventFocus.h" />
|
||||
<ClInclude Include="..\base\CCEventKeyboard.h" />
|
||||
<ClInclude Include="..\base\CCEventListener.h" />
|
||||
<ClInclude Include="..\base\CCEventListenerAcceleration.h" />
|
||||
<ClInclude Include="..\base\CCEventListenerController.h" />
|
||||
<ClInclude Include="..\base\CCEventListenerCustom.h" />
|
||||
<ClInclude Include="..\base\CCEventListenerFocus.h" />
|
||||
<ClInclude Include="..\base\CCEventListenerKeyboard.h" />
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "base/CCController.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#include "base/CCEventDispatcher.h"
|
||||
#include "base/CCEventController.h"
|
||||
|
@ -47,6 +47,19 @@ Controller* Controller::getControllerByTag(int tag)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Controller* Controller::getControllerByDeviceId(int deviceId)
|
||||
{
|
||||
for (auto controller : Controller::s_allController)
|
||||
{
|
||||
if (controller->_deviceId == deviceId)
|
||||
{
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
for (int key = Key::JOYSTICK_LEFT_X; key < Key::KEY_MAX; ++key)
|
||||
|
@ -112,4 +125,4 @@ void Controller::onAxisEvent(int axisCode, float value, bool isAnalog)
|
|||
|
||||
NS_CC_END
|
||||
|
||||
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
|
|
@ -47,7 +47,7 @@ class EventDispatcher;
|
|||
* @brief A Controller object represents a connected physical game controller.
|
||||
* @js NA
|
||||
*/
|
||||
class Controller
|
||||
class CC_DLL Controller
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -124,17 +124,25 @@ public:
|
|||
*/
|
||||
static Controller* getControllerByTag(int tag);
|
||||
|
||||
/**
|
||||
* Gets a Controller object with device ID.
|
||||
*
|
||||
* @param deviceId A unique identifier to find the controller.
|
||||
* @return A Controller object.
|
||||
*/
|
||||
static Controller* getControllerByDeviceId(int deviceId);
|
||||
|
||||
/**
|
||||
* Start discovering new controllers.
|
||||
*
|
||||
* @warning The API only work on the IOS platform. Empty implementation on other platform.
|
||||
* @warning The API has an empty implementation on Android.
|
||||
*/
|
||||
static void startDiscoveryController();
|
||||
|
||||
/**
|
||||
* Stop the discovery process.
|
||||
*
|
||||
* @warning The API only work on the IOS platform.Empty implementation on other platform.
|
||||
* @warning The API has an empty implementation on Android.
|
||||
*/
|
||||
static void stopDiscoveryController();
|
||||
|
||||
|
@ -211,6 +219,20 @@ private:
|
|||
EventController *_keyEvent;
|
||||
EventController *_axisEvent;
|
||||
|
||||
#if ( CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 )
|
||||
// Attach the controller profiles from CCController-linux-win32.cpp to each
|
||||
// of the Controller variables in order to minimize profile lookup time.
|
||||
|
||||
// Note: this increases memory usage unecessarily since the same maps are
|
||||
// already stored on ControllerImpl within the static member variable
|
||||
// "s_controllerProfiles", but on these platforms the increase in memory
|
||||
// usage is negligible. Peformance over memory optimization was
|
||||
// consciously chosen.
|
||||
|
||||
std::unordered_map<int,int> _buttonInputMap;
|
||||
std::unordered_map<int,int> _axisInputMap;
|
||||
#endif
|
||||
|
||||
friend class ControllerImpl;
|
||||
friend class EventListenerController;
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ class EventListenerController;
|
|||
/** @class EventController
|
||||
* @brief Controller event.
|
||||
*/
|
||||
class EventController : public Event
|
||||
class CC_DLL EventController : public Event
|
||||
{
|
||||
public:
|
||||
/** ControllerEventType Controller event type.*/
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "base/CCEventListenerKeyboard.h"
|
||||
#include "base/CCEventListenerCustom.h"
|
||||
#include "base/CCEventListenerFocus.h"
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "base/CCEventListenerController.h"
|
||||
#endif
|
||||
#include "2d/CCScene.h"
|
||||
|
@ -94,7 +94,7 @@ static EventListener::ListenerID __getListenerID(Event* event)
|
|||
// return UNKNOWN instead.
|
||||
CCASSERT(false, "Don't call this method if the event is for touch.");
|
||||
break;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
case Event::Type::GAME_CONTROLLER:
|
||||
ret = EventListenerController::LISTENER_ID;
|
||||
break;
|
||||
|
|
|
@ -43,7 +43,7 @@ class Controller;
|
|||
* @param Controller event listener.
|
||||
* @js NA
|
||||
*/
|
||||
class EventListenerController : public EventListener
|
||||
class CC_DLL EventListenerController : public EventListener
|
||||
{
|
||||
public:
|
||||
static const std::string LISTENER_ID;
|
||||
|
|
|
@ -9,6 +9,10 @@ elseif(ANDROID)
|
|||
base/CCUserDefault-android.cpp
|
||||
base/CCController-android.cpp
|
||||
)
|
||||
elseif(LINUX)
|
||||
set(COCOS_BASE_SPECIFIC_SRC
|
||||
base/CCController-linux-win32.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(COCOS_BASE_SRC
|
||||
|
|
|
@ -75,8 +75,11 @@ THE SOFTWARE.
|
|||
#include "base/CCEventListenerFocus.h"
|
||||
#include "base/CCEventListenerKeyboard.h"
|
||||
#include "base/CCEventListenerMouse.h"
|
||||
#include "base/CCEventListenerController.h"
|
||||
#include "base/CCEventListenerTouch.h"
|
||||
#include "base/CCEventMouse.h"
|
||||
#include "base/CCEventController.h"
|
||||
#include "base/CCController.h"
|
||||
#include "base/CCEventTouch.h"
|
||||
#include "base/CCEventType.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue