properly detected using the generic SDL driver.legacy
| @@ -22,6 +22,7 @@ liblol_a_SOURCES = \ | |||||
| $(xbox_sources) \ | $(xbox_sources) \ | ||||
| $(nacl_sources) \ | $(nacl_sources) \ | ||||
| $(sdl_sources) \ | $(sdl_sources) \ | ||||
| $(d3d9_sources) \ | |||||
| $(android_sources) \ | $(android_sources) \ | ||||
| \ | \ | ||||
| thread/threadbase.h thread/thread.h \ | thread/threadbase.h thread/thread.h \ | ||||
| @@ -51,6 +52,9 @@ sdl_sources = \ | |||||
| platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ | platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ | ||||
| platform/sdl/sdlinput.cpp platform/sdl/sdlinput.h | platform/sdl/sdlinput.cpp platform/sdl/sdlinput.h | ||||
| d3d9_sources = \ | |||||
| platform/xbox/xboxinput.cpp platform/xbox/xboxinput.h | |||||
| if USE_NACL | if USE_NACL | ||||
| nacl_sources = \ | nacl_sources = \ | ||||
| platform/nacl/naclapp.cpp platform/nacl/naclapp.h \ | platform/nacl/naclapp.cpp platform/nacl/naclapp.h \ | ||||
| @@ -0,0 +1,102 @@ | |||||
| // | |||||
| // Lol Engine | |||||
| // | |||||
| // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||||
| // This program is free software; you can redistribute it and/or | |||||
| // modify it under the terms of the Do What The Fuck You Want To | |||||
| // Public License, Version 2, as published by Sam Hocevar. See | |||||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||||
| // | |||||
| #if defined HAVE_CONFIG_H | |||||
| # include "config.h" | |||||
| #endif | |||||
| #if defined USE_D3D9 | |||||
| # include <d3d9.h> | |||||
| # include <xinput.h> | |||||
| #endif | |||||
| #include "core.h" | |||||
| #include "d3d9input.h" | |||||
| namespace lol | |||||
| { | |||||
| /* | |||||
| * D3d9 Input implementation class | |||||
| */ | |||||
| class D3d9InputData | |||||
| { | |||||
| friend class D3d9Input; | |||||
| private: | |||||
| #if defined USE_D3D9 | |||||
| Array<int, Stick *> m_joysticks; | |||||
| #endif | |||||
| }; | |||||
| /* | |||||
| * Public D3d9Input class | |||||
| */ | |||||
| D3d9Input::D3d9Input() | |||||
| : m_data(new D3d9InputData()) | |||||
| { | |||||
| #if defined USE_D3D9 | |||||
| for (int i = 0; i < XUSER_MAX_COUNT; i++) | |||||
| { | |||||
| XINPUT_STATE state; | |||||
| if (XInputGetState(i, &state) != ERROR_SUCCESS) | |||||
| continue; | |||||
| Stick *stick = Input::CreateStick(); | |||||
| stick->SetAxisCount(4); | |||||
| stick->SetButtonCount(0); | |||||
| m_data->m_joysticks.Push(i, stick); | |||||
| } | |||||
| #endif | |||||
| m_gamegroup = GAMEGROUP_BEFORE; | |||||
| } | |||||
| D3d9Input::~D3d9Input() | |||||
| { | |||||
| #if defined USE_D3D9 | |||||
| /* Unregister all the joysticks we added */ | |||||
| while (m_data->m_joysticks.Count()) | |||||
| { | |||||
| Input::DestroyStick(m_data->m_joysticks[0].m2); | |||||
| m_data->m_joysticks.Remove(0); | |||||
| } | |||||
| #endif | |||||
| delete m_data; | |||||
| } | |||||
| void D3d9Input::TickGame(float seconds) | |||||
| { | |||||
| Entity::TickGame(seconds); | |||||
| } | |||||
| void D3d9Input::TickDraw(float seconds) | |||||
| { | |||||
| Entity::TickDraw(seconds); | |||||
| #if defined USE_D3D9 | |||||
| for (int i = 0; i < m_data->m_joysticks.Count(); i++) | |||||
| { | |||||
| XINPUT_STATE state; | |||||
| if (XInputGetState(m_data->m_joysticks[i].m1, &state) != ERROR_SUCCESS) | |||||
| continue; | |||||
| m_data->m_joysticks[i].m2->SetAxis(0, (float)state.Gamepad.sThumbLX / 32768.f); | |||||
| m_data->m_joysticks[i].m2->SetAxis(1, -(float)state.Gamepad.sThumbLY / 32768.f); | |||||
| m_data->m_joysticks[i].m2->SetAxis(2, (float)state.Gamepad.sThumbRX / 32768.f); | |||||
| m_data->m_joysticks[i].m2->SetAxis(3, -(float)state.Gamepad.sThumbRY / 32768.f); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| } /* namespace lol */ | |||||
| @@ -0,0 +1,43 @@ | |||||
| // | |||||
| // Lol Engine | |||||
| // | |||||
| // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||||
| // This program is free software; you can redistribute it and/or | |||||
| // modify it under the terms of the Do What The Fuck You Want To | |||||
| // Public License, Version 2, as published by Sam Hocevar. See | |||||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||||
| // | |||||
| // | |||||
| // The D3d9Input class | |||||
| // ------------------- | |||||
| // | |||||
| #if !defined __LOL_D3D9INPUT_H__ | |||||
| #define __LOL_D3D9INPUT_H__ | |||||
| #include "entity.h" | |||||
| namespace lol | |||||
| { | |||||
| class D3d9InputData; | |||||
| class D3d9Input : public Entity | |||||
| { | |||||
| public: | |||||
| D3d9Input(); | |||||
| virtual ~D3d9Input(); | |||||
| protected: | |||||
| virtual void TickGame(float seconds); | |||||
| virtual void TickDraw(float seconds); | |||||
| private: | |||||
| D3d9InputData *m_data; | |||||
| }; | |||||
| } /* namespace lol */ | |||||
| #endif // __LOL_D3D9INPUT_H__ | |||||
| @@ -24,6 +24,9 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| #include "platform/sdl/sdlapp.h" | #include "platform/sdl/sdlapp.h" | ||||
| #include "platform/sdl/sdlinput.h" | #include "platform/sdl/sdlinput.h" | ||||
| #if defined USE_D3D9 | |||||
| # include "platform/d3d9/d3d9input.h" | |||||
| #endif | |||||
| #if defined USE_SDL && defined USE_D3D9 | #if defined USE_SDL && defined USE_D3D9 | ||||
| HWND g_hwnd = NULL; | HWND g_hwnd = NULL; | ||||
| @@ -86,6 +89,11 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||||
| Audio::Setup(2); | Audio::Setup(2); | ||||
| /* Autoreleased objects */ | /* Autoreleased objects */ | ||||
| # if defined USE_D3D9 | |||||
| /* Prefer D3d9 for joysticks on Windows, because the X360 pads are not | |||||
| * advertised with the proper number of axes. */ | |||||
| new D3d9Input(); | |||||
| # endif | |||||
| new SdlInput(); | new SdlInput(); | ||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -58,7 +58,11 @@ SdlInput::SdlInput() | |||||
| /* Blacklist HDAPS, it's not a real joystick */ | /* Blacklist HDAPS, it's not a real joystick */ | ||||
| char const *name = SDL_JoystickName(i); | char const *name = SDL_JoystickName(i); | ||||
| if (strstr(name, "HDAPS")) | |||||
| if (strstr(name, "HDAPS") | |||||
| # if !defined USE_D3D9 | |||||
| || strstr(name, "XBOX 360 For Windows") | |||||
| # endif | |||||
| || true) | |||||
| { | { | ||||
| SDL_JoystickClose(sdlstick); | SDL_JoystickClose(sdlstick); | ||||
| continue; | continue; | ||||
| @@ -69,11 +73,8 @@ SdlInput::SdlInput() | |||||
| stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick)); | stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick)); | ||||
| /* It's possible to remap axes */ | /* It's possible to remap axes */ | ||||
| if (strstr(name, "XBOX 360 For Windows")) | |||||
| { | |||||
| //stick->RemapAxis(4, 2); | |||||
| //stick->RemapAxis(2, 4); | |||||
| } | |||||
| //stick->RemapAxis(4, 2); | |||||
| //stick->RemapAxis(2, 4); | |||||
| m_data->m_joysticks.Push(sdlstick, stick); | m_data->m_joysticks.Push(sdlstick, stick); | ||||
| } | } | ||||
| @@ -35,8 +35,8 @@ | |||||
| <D3d9Includes>$(DXSDK_DIR)\Include</D3d9Includes> | <D3d9Includes>$(DXSDK_DIR)\Include</D3d9Includes> | ||||
| <D3d9Libs Condition="'$(Platform)'=='Win32'">$(DXSDK_DIR)\Lib\x86</D3d9Libs> | <D3d9Libs Condition="'$(Platform)'=='Win32'">$(DXSDK_DIR)\Lib\x86</D3d9Libs> | ||||
| <D3d9Libs Condition="'$(Platform)'=='x64'">$(DXSDK_DIR)\Lib\x64</D3d9Libs> | <D3d9Libs Condition="'$(Platform)'=='x64'">$(DXSDK_DIR)\Lib\x64</D3d9Libs> | ||||
| <D3d9Deps Condition="'$(Configuration)'=='Release'">d3d9.lib;d3dx9.lib</D3d9Deps> | |||||
| <D3d9Deps Condition="'$(Configuration)'=='Debug'">d3d9.lib;d3dx9d.lib</D3d9Deps> | |||||
| <D3d9Deps Condition="'$(Configuration)'=='Release'">d3d9.lib;d3dx9.lib;xinput.lib</D3d9Deps> | |||||
| <D3d9Deps Condition="'$(Configuration)'=='Debug'">d3d9.lib;d3dx9d.lib;xinput.lib</D3d9Deps> | |||||
| <Win32Defines>HAVE_SDL_H;USE_SDL;USE_GDIPLUS;USE_D3D9</Win32Defines> | <Win32Defines>HAVE_SDL_H;USE_SDL;USE_GDIPLUS;USE_D3D9</Win32Defines> | ||||
| <XboxDefines></XboxDefines> | <XboxDefines></XboxDefines> | ||||
| @@ -108,6 +108,7 @@ | |||||
| <ClCompile Include="..\src\math\trig.cpp" /> | <ClCompile Include="..\src\math\trig.cpp" /> | ||||
| <ClCompile Include="..\src\math\vector.cpp" /> | <ClCompile Include="..\src\math\vector.cpp" /> | ||||
| <ClCompile Include="..\src\platform.cpp" /> | <ClCompile Include="..\src\platform.cpp" /> | ||||
| <ClCompile Include="..\src\platform\d3d9\d3d9input.cpp" /> | |||||
| <ClCompile Include="..\src\platform\sdl\sdlapp.cpp" /> | <ClCompile Include="..\src\platform\sdl\sdlapp.cpp" /> | ||||
| <ClCompile Include="..\src\platform\sdl\sdlinput.cpp" /> | <ClCompile Include="..\src\platform\sdl\sdlinput.cpp" /> | ||||
| <ClCompile Include="..\src\platform\xbox\xboxapp.cpp" /> | <ClCompile Include="..\src\platform\xbox\xboxapp.cpp" /> | ||||
| @@ -167,6 +168,7 @@ | |||||
| <ClInclude Include="..\src\math\trig.h" /> | <ClInclude Include="..\src\math\trig.h" /> | ||||
| <ClInclude Include="..\src\numeric.h" /> | <ClInclude Include="..\src\numeric.h" /> | ||||
| <ClInclude Include="..\src\platform.h" /> | <ClInclude Include="..\src\platform.h" /> | ||||
| <ClInclude Include="..\src\platform\d3d9\d3d9input.h" /> | |||||
| <ClInclude Include="..\src\platform\sdl\sdlapp.h" /> | <ClInclude Include="..\src\platform\sdl\sdlapp.h" /> | ||||
| <ClInclude Include="..\src\platform\sdl\sdlinput.h" /> | <ClInclude Include="..\src\platform\sdl\sdlinput.h" /> | ||||
| <ClInclude Include="..\src\platform\xbox\xboxapp.h" /> | <ClInclude Include="..\src\platform\xbox\xboxapp.h" /> | ||||
| @@ -191,4 +193,4 @@ | |||||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||
| <ImportGroup Label="ExtensionTargets"> | <ImportGroup Label="ExtensionTargets"> | ||||
| </ImportGroup> | </ImportGroup> | ||||
| </Project> | |||||
| </Project> | |||||
| @@ -44,6 +44,9 @@ | |||||
| <Filter Include="src\input"> | <Filter Include="src\input"> | ||||
| <UniqueIdentifier>{94992c0e-ebc5-4185-b766-323b06547dcf}</UniqueIdentifier> | <UniqueIdentifier>{94992c0e-ebc5-4185-b766-323b06547dcf}</UniqueIdentifier> | ||||
| </Filter> | </Filter> | ||||
| <Filter Include="src\platform\d3d9"> | |||||
| <UniqueIdentifier>{a914e15d-3201-467a-a9c9-d7c5244b13ee}</UniqueIdentifier> | |||||
| </Filter> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ClCompile Include="..\src\image\image.cpp"> | <ClCompile Include="..\src\image\image.cpp"> | ||||
| @@ -205,6 +208,9 @@ | |||||
| <ClCompile Include="..\src\input\stick.cpp"> | <ClCompile Include="..\src\input\stick.cpp"> | ||||
| <Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
| </ClCompile> | </ClCompile> | ||||
| <ClCompile Include="..\src\platform\d3d9\d3d9input.cpp"> | |||||
| <Filter>src\platform\d3d9</Filter> | |||||
| </ClCompile> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ClInclude Include="..\src\image\image.h"> | <ClInclude Include="..\src\image\image.h"> | ||||
| @@ -387,5 +393,8 @@ | |||||
| <ClInclude Include="..\src\input\stick.h"> | <ClInclude Include="..\src\input\stick.h"> | ||||
| <Filter>src\input</Filter> | <Filter>src\input</Filter> | ||||
| </ClInclude> | </ClInclude> | ||||
| <ClInclude Include="..\src\platform\d3d9\d3d9input.h"> | |||||
| <Filter>src\platform\d3d9</Filter> | |||||
| </ClInclude> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | |||||
| </Project> | |||||