diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/entry')
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_ios.mm | 10 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_p.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_sdl.cpp | 157 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_windows.cpp | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/entry/entry_x11.cpp | 35 |
5 files changed, 185 insertions, 21 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_ios.mm b/3rdparty/bgfx/examples/common/entry/entry_ios.mm index e12c224e623..052c161abd4 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_ios.mm +++ b/3rdparty/bgfx/examples/common/entry/entry_ios.mm @@ -185,7 +185,7 @@ static void* m_device = NULL; } } #endif - + return [CAEAGLLayer class]; } @@ -197,15 +197,15 @@ static void* m_device = NULL; { return nil; } - + bgfx::PlatformData pd; pd.ndt = NULL; pd.nwh = self.layer; - pd.context = m_device; + pd.context = m_device; pd.backBuffer = NULL; pd.backBufferDS = NULL; bgfx::setPlatformData(pd); - + return self; } @@ -309,7 +309,7 @@ static void* m_device = NULL; [m_window setRootViewController:viewController]; [m_window makeKeyAndVisible]; - + [m_window makeKeyAndVisible]; //float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but ui is too small on ipad retina diff --git a/3rdparty/bgfx/examples/common/entry/entry_p.h b/3rdparty/bgfx/examples/common/entry/entry_p.h index 880f44123e4..502eed673ad 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_p.h +++ b/3rdparty/bgfx/examples/common/entry/entry_p.h @@ -14,7 +14,7 @@ #include <string.h> // memcpy #ifndef ENTRY_CONFIG_USE_SDL -# define ENTRY_CONFIG_USE_SDL 0 +# define ENTRY_CONFIG_USE_SDL BX_PLATFORM_STEAMLINK #endif // ENTRY_CONFIG_USE_SDL #ifndef ENTRY_CONFIG_USE_GLFW diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp index c5ab2c7d57a..989d0ae0667 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp @@ -11,13 +11,24 @@ # define SDL_MAIN_HANDLED #endif // BX_PLATFORM_WINDOWS +#include <bx/bx.h> + #include <SDL2/SDL.h> + +BX_PRAGMA_DIAGNOSTIC_PUSH_CLANG() +BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wextern-c-compat") #include <SDL2/SDL_syswm.h> +BX_PRAGMA_DIAGNOSTIC_POP_CLANG() + #include <bgfx/bgfxplatform.h> +#if defined(None) // X11 defines this... +# undef None +#endif // defined(None) #include <stdio.h> #include <bx/thread.h> #include <bx/handlealloc.h> +#include <bx/readerwriter.h> #include <tinystl/allocator.h> #include <tinystl/string.h> @@ -74,6 +85,22 @@ namespace entry return GamepadAxis::Enum(s_translateGamepadAxis[_sdl]); } + struct AxisDpadRemap + { + Key::Enum first; + Key::Enum second; + }; + + static AxisDpadRemap s_axisDpad[] = + { + { Key::GamepadLeft, Key::GamepadRight }, + { Key::GamepadUp, Key::GamepadDown }, + { Key::None, Key::None }, + { Key::GamepadLeft, Key::GamepadRight }, + { Key::GamepadUp, Key::GamepadDown }, + { Key::None, Key::None }, + }; + struct GamepadSDL { GamepadSDL() @@ -91,17 +118,59 @@ namespace entry m_deadzone[GamepadAxis::RightZ] = 30; } - void create(int32_t _jid) + void create(const SDL_JoyDeviceEvent& _jev) { - m_controller = SDL_GameControllerOpen(_jid); + m_joystick = SDL_JoystickOpen(_jev.which); + SDL_Joystick* joystick = m_joystick; + m_jid = SDL_JoystickInstanceID(joystick); + } + + void create(const SDL_ControllerDeviceEvent& _cev) + { + m_controller = SDL_GameControllerOpen(_cev.which); SDL_Joystick* joystick = SDL_GameControllerGetJoystick(m_controller); m_jid = SDL_JoystickInstanceID(joystick); } + void update(EventQueue& _eventQueue, WindowHandle _handle, GamepadHandle _gamepad, GamepadAxis::Enum _axis, int32_t _value) + { + if (filter(_axis, &_value) ) + { + _eventQueue.postAxisEvent(_handle, _gamepad, _axis, _value); + + if (Key::None != s_axisDpad[_axis].first) + { + if (_value == 0) + { + _eventQueue.postKeyEvent(_handle, s_axisDpad[_axis].first, 0, false); + _eventQueue.postKeyEvent(_handle, s_axisDpad[_axis].second, 0, false); + } + else + { + _eventQueue.postKeyEvent(_handle + , 0 > _value ? s_axisDpad[_axis].first : s_axisDpad[_axis].second + , 0 + , true + ); + } + } + } + } + void destroy() { - SDL_GameControllerClose(m_controller); - m_controller = NULL; + if (NULL != m_controller) + { + SDL_GameControllerClose(m_controller); + m_controller = NULL; + } + + if (NULL != m_joystick) + { + SDL_JoystickClose(m_joystick); + m_joystick = NULL; + } + m_jid = INT32_MAX; } @@ -119,6 +188,7 @@ namespace entry int32_t m_value[GamepadAxis::Count]; int32_t m_deadzone[GamepadAxis::Count]; + SDL_Joystick* m_joystick; SDL_GameController* m_controller; // SDL_Haptic* m_haptic; SDL_JoystickID m_jid; @@ -148,6 +218,8 @@ namespace entry return wmi.info.cocoa.window; # elif BX_PLATFORM_WINDOWS return wmi.info.win.window; +# elif BX_PLATFORM_STEAMLINK + return wmi.info.vivante.window; # endif // BX_PLATFORM_ } @@ -326,7 +398,6 @@ namespace entry m_mte.m_argv = _argv; SDL_Init(0 - | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER ); @@ -356,10 +427,18 @@ namespace entry WindowHandle defaultWindow = { 0 }; setWindowSize(defaultWindow, m_width, m_height, true); - SDL_RWops* rw = SDL_RWFromFile("gamecontrollerdb.txt", "rb"); - if (NULL != rw) + bx::CrtFileReader reader; + if (bx::open(&reader, "gamecontrollerdb.txt") ) { - SDL_GameControllerAddMappingsFromRW(rw, 1); + bx::AllocatorI* allocator = getAllocator(); + uint32_t size = (uint32_t)bx::getSize(&reader); + void* data = BX_ALLOC(allocator, size); + bx::read(&reader, data, size); + bx::close(&reader); + + SDL_GameControllerAddMapping( (char*)data); + + BX_FREE(allocator, data); } bool exit = false; @@ -477,6 +556,7 @@ namespace entry } } break; + case SDL_KEYUP: { const SDL_KeyboardEvent& kev = event.key; @@ -530,6 +610,18 @@ namespace entry } break; + case SDL_JOYAXISMOTION: + { + const SDL_JoyAxisEvent& jev = event.jaxis; + GamepadHandle handle = findGamepad(jev.which); + if (isValid(handle) ) + { + GamepadAxis::Enum axis = translateGamepadAxis(jev.axis); + m_gamepad[handle.idx].update(m_eventQueue, defaultWindow, handle, axis, jev.value); + } + } + break; + case SDL_CONTROLLERAXISMOTION: { const SDL_ControllerAxisEvent& aev = event.caxis; @@ -537,10 +629,23 @@ namespace entry if (isValid(handle) ) { GamepadAxis::Enum axis = translateGamepadAxis(aev.axis); - int32_t value = aev.value; - if (m_gamepad[handle.idx].filter(axis, &value) ) + m_gamepad[handle.idx].update(m_eventQueue, defaultWindow, handle, axis, aev.value); + } + } + break; + + case SDL_JOYBUTTONDOWN: + case SDL_JOYBUTTONUP: + { + const SDL_JoyButtonEvent& bev = event.jbutton; + GamepadHandle handle = findGamepad(bev.which); + + if (isValid(handle) ) + { + Key::Enum key = translateGamepad(bev.button); + if (Key::Count != key) { - m_eventQueue.postAxisEvent(defaultWindow, handle, axis, value); + m_eventQueue.postKeyEvent(defaultWindow, key, 0, event.type == SDL_JOYBUTTONDOWN); } } } @@ -562,14 +667,38 @@ namespace entry } break; - case SDL_CONTROLLERDEVICEADDED: + case SDL_JOYDEVICEADDED: { - const SDL_ControllerDeviceEvent& cev = event.cdevice; + GamepadHandle handle = { m_gamepadAlloc.alloc() }; + if (isValid(handle) ) + { + const SDL_JoyDeviceEvent& jev = event.jdevice; + m_gamepad[handle.idx].create(jev); + m_eventQueue.postGamepadEvent(defaultWindow, handle, true); + } + } + break; + + case SDL_JOYDEVICEREMOVED: + { + const SDL_JoyDeviceEvent& jev = event.jdevice; + GamepadHandle handle = findGamepad(jev.which); + if (isValid(handle) ) + { + m_gamepad[handle.idx].destroy(); + m_gamepadAlloc.free(handle.idx); + m_eventQueue.postGamepadEvent(defaultWindow, handle, false); + } + } + break; + case SDL_CONTROLLERDEVICEADDED: + { GamepadHandle handle = { m_gamepadAlloc.alloc() }; if (isValid(handle) ) { - m_gamepad[handle.idx].create(cev.which); + const SDL_ControllerDeviceEvent& cev = event.cdevice; + m_gamepad[handle.idx].create(cev); m_eventQueue.postGamepadEvent(defaultWindow, handle, true); } } diff --git a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp index 247bed44385..37f403ee480 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_windows.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_windows.cpp @@ -358,7 +358,7 @@ namespace entry s_translateKey[VK_HOME] = Key::Home; s_translateKey[VK_END] = Key::End; s_translateKey[VK_PRIOR] = Key::PageUp; - s_translateKey[VK_NEXT] = Key::PageUp; + s_translateKey[VK_NEXT] = Key::PageDown; s_translateKey[VK_SNAPSHOT] = Key::Print; s_translateKey[VK_OEM_PLUS] = Key::Plus; s_translateKey[VK_OEM_MINUS] = Key::Minus; diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp index a058479fabb..8ced748dcbe 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp @@ -61,6 +61,23 @@ namespace entry GamepadAxis::RightZ, }; + struct AxisDpadRemap + { + Key::Enum first; + Key::Enum second; + }; + + static AxisDpadRemap s_axisDpad[] = + { + { Key::GamepadLeft, Key::GamepadRight }, + { Key::GamepadUp, Key::GamepadDown }, + { Key::None, Key::None }, + { Key::GamepadLeft, Key::GamepadRight }, + { Key::GamepadUp, Key::GamepadDown }, + { Key::None, Key::None }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_translateAxis) == BX_COUNTOF(s_axisDpad) ); + struct Joystick { Joystick() @@ -135,6 +152,24 @@ namespace entry if (filter(axis, &value) ) { _eventQueue.postAxisEvent(defaultWindow, handle, axis, value); + + if (Key::None != s_axisDpad[axis].first) + { + if (m_value[axis] == 0) + { + _eventQueue.postKeyEvent(defaultWindow, s_axisDpad[axis].first, 0, false); + _eventQueue.postKeyEvent(defaultWindow, s_axisDpad[axis].second, 0, false); + } + else + { + _eventQueue.postKeyEvent(defaultWindow + , 0 > m_value[axis] ? s_axisDpad[axis].first : s_axisDpad[axis].second + , 0 + , true + ); + } + } + } } } |