From 545798600ea0daa118b6e94b516582e807d5ca8f Mon Sep 17 00:00:00 2001 From: elasota Date: Fri, 22 Oct 2021 22:01:33 -0400 Subject: [PATCH] Fix gamepads not working, enable on Android --- .../app/jni/main/GpMain_SDL_Android.cpp | 18 ++++++++++-------- AerofoilSDL/Android.mk | 1 + AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp | 2 -- GpShell/GpAppEnvironment.cpp | 7 ------- GpShell/GpAppEnvironment.h | 1 - PortabilityLayer/HostSuspendHook.cpp | 5 +++++ PortabilityLayer/PortabilityLayer_Combined.cpp | 1 + 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp b/AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp index 5e1a193..2039496 100644 --- a/AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp +++ b/AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp @@ -26,6 +26,7 @@ GpAndroidGlobals g_gpAndroidGlobals; IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties); IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties); +IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties); class GpLogDriver_Android final : public IGpLogDriver { @@ -75,7 +76,7 @@ int main(int argc, char* argv[]) SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO); - if (SDL_Init(SDL_INIT_VIDEO) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) return -1; SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight"); @@ -94,8 +95,13 @@ int main(int argc, char* argv[]) g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None; - g_gpGlobalConfig.m_inputDriverTypes = nullptr; - g_gpGlobalConfig.m_numInputDrivers = 0; + EGpInputDriverType inputDrivers[] = + { + EGpInputDriverType_SDL2_Gamepad + }; + + g_gpGlobalConfig.m_inputDriverTypes = inputDrivers; + g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]); g_gpGlobalConfig.m_osGlobals = &g_gpAndroidGlobals; g_gpGlobalConfig.m_logger = GpLogDriver_Android::GetInstance(); @@ -104,6 +110,7 @@ int main(int argc, char* argv[]) GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2); GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL); + GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad); int returnCode = GpMain::Run(); @@ -118,8 +125,3 @@ int main(int argc, char* argv[]) return returnCode; } - -IGpInputDriverSDLGamepad *IGpInputDriverSDLGamepad::GetInstance() -{ - return nullptr; -} diff --git a/AerofoilSDL/Android.mk b/AerofoilSDL/Android.mk index 6f6d341..6acae03 100644 --- a/AerofoilSDL/Android.mk +++ b/AerofoilSDL/Android.mk @@ -20,6 +20,7 @@ LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0 LOCAL_SRC_FILES := \ GpAudioDriver_SDL2.cpp \ GpDisplayDriver_SDL_GL2.cpp \ + GpInputDriver_SDL_Gamepad.cpp \ ShaderCode/CopyQuadP.cpp \ ShaderCode/DrawQuadPaletteP.cpp \ ShaderCode/DrawQuad32P.cpp \ diff --git a/AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp b/AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp index f9d18ae..9ed3a81 100644 --- a/AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp +++ b/AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp @@ -177,8 +177,6 @@ void GpInputDriverSDLGamepad::HandleDeviceRemoved(SDL_JoystickID joystickID) { m_playerButtonDown[playerNum][button] = false; - - GpVOSEvent evt; evt.m_eventType = GpVOSEventTypes::kKeyboardInput; evt.m_event.m_keyboardInputEvent.m_eventType = GpKeyboardInputEventTypes::kUp; diff --git a/GpShell/GpAppEnvironment.cpp b/GpShell/GpAppEnvironment.cpp index 14d2f18..5e4866b 100644 --- a/GpShell/GpAppEnvironment.cpp +++ b/GpShell/GpAppEnvironment.cpp @@ -88,10 +88,3 @@ void GpAppEnvironment::InitializeApplicationState() drivers->SetDriver(m_fontHandler); drivers->SetDriver(m_vosEventQueue); } - -void GpAppEnvironment::SynchronizeState() -{ - const size_t numInputDrivers = m_numInputDrivers; - for (size_t i = 0; i < numInputDrivers; i++) - m_inputDrivers[i]->ProcessInput(); -} diff --git a/GpShell/GpAppEnvironment.h b/GpShell/GpAppEnvironment.h index aa0820a..9dac62f 100644 --- a/GpShell/GpAppEnvironment.h +++ b/GpShell/GpAppEnvironment.h @@ -41,7 +41,6 @@ public: private: static void StaticAppThreadFunc(void *context); void InitializeApplicationState(); - void SynchronizeState(); IGpDisplayDriver *m_displayDriver; IGpAudioDriver *m_audioDriver; diff --git a/PortabilityLayer/HostSuspendHook.cpp b/PortabilityLayer/HostSuspendHook.cpp index 39af223..43d67fd 100644 --- a/PortabilityLayer/HostSuspendHook.cpp +++ b/PortabilityLayer/HostSuspendHook.cpp @@ -5,6 +5,7 @@ #include "PLDrivers.h" #include "IGpDisplayDriver.h" +#include "IGpInputDriver.h" namespace PortabilityLayer @@ -13,5 +14,9 @@ namespace PortabilityLayer { PLDrivers::GetDisplayDriver()->ServeTicks(ticks); DisplayDeviceManager::GetInstance()->IncrementTickCount(ticks); + + const size_t numInputDrivers = PLDrivers::GetNumInputDrivers(); + for (size_t i = 0; i < numInputDrivers; i++) + PLDrivers::GetInputDriver(i)->ProcessInput(); } } diff --git a/PortabilityLayer/PortabilityLayer_Combined.cpp b/PortabilityLayer/PortabilityLayer_Combined.cpp index ae49bf3..6bb4350 100644 --- a/PortabilityLayer/PortabilityLayer_Combined.cpp +++ b/PortabilityLayer/PortabilityLayer_Combined.cpp @@ -4,6 +4,7 @@ #include "BitmapImage.cpp" #include "ByteSwap.cpp" #include "CFileStream.cpp" +#include "CompositeRenderedFont.cpp" #include "DeflateCodec.cpp" #include "DialogManager.cpp" #include "DisplayDeviceManager.cpp"