diff --git a/src/Makefile.am b/src/Makefile.am index 044d1990..0e6b9a04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,7 @@ liblol_a_SOURCES = \ $(xbox_sources) \ $(nacl_sources) \ $(sdl_sources) \ + $(d3d9_sources) \ $(android_sources) \ \ thread/threadbase.h thread/thread.h \ @@ -51,6 +52,9 @@ sdl_sources = \ platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ platform/sdl/sdlinput.cpp platform/sdl/sdlinput.h +d3d9_sources = \ + platform/xbox/xboxinput.cpp platform/xbox/xboxinput.h + if USE_NACL nacl_sources = \ platform/nacl/naclapp.cpp platform/nacl/naclapp.h \ diff --git a/src/platform/d3d9/d3d9input.cpp b/src/platform/d3d9/d3d9input.cpp new file mode 100644 index 00000000..b13e616e --- /dev/null +++ b/src/platform/d3d9/d3d9input.cpp @@ -0,0 +1,102 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// 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 +# include +#endif + +#include "core.h" +#include "d3d9input.h" + +namespace lol +{ + +/* + * D3d9 Input implementation class + */ + +class D3d9InputData +{ + friend class D3d9Input; + +private: +#if defined USE_D3D9 + Array 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 */ + diff --git a/src/platform/d3d9/d3d9input.h b/src/platform/d3d9/d3d9input.h new file mode 100644 index 00000000..bfb5a13b --- /dev/null +++ b/src/platform/d3d9/d3d9input.h @@ -0,0 +1,43 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// 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__ + diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 4624fc80..02b36078 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -24,6 +24,9 @@ #include "lolgl.h" #include "platform/sdl/sdlapp.h" #include "platform/sdl/sdlinput.h" +#if defined USE_D3D9 +# include "platform/d3d9/d3d9input.h" +#endif #if defined USE_SDL && defined USE_D3D9 HWND g_hwnd = NULL; @@ -86,6 +89,11 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : Audio::Setup(2); /* 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(); #endif } diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index ceab290c..a4978fcb 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -58,7 +58,11 @@ SdlInput::SdlInput() /* Blacklist HDAPS, it's not a real joystick */ 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); continue; @@ -69,11 +73,8 @@ SdlInput::SdlInput() stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick)); /* 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); } diff --git a/win32/Lol.Vars.props b/win32/Lol.Vars.props index 5f99894d..c7841966 100644 --- a/win32/Lol.Vars.props +++ b/win32/Lol.Vars.props @@ -35,8 +35,8 @@ $(DXSDK_DIR)\Include $(DXSDK_DIR)\Lib\x86 $(DXSDK_DIR)\Lib\x64 - d3d9.lib;d3dx9.lib - d3d9.lib;d3dx9d.lib + d3d9.lib;d3dx9.lib;xinput.lib + d3d9.lib;d3dx9d.lib;xinput.lib HAVE_SDL_H;USE_SDL;USE_GDIPLUS;USE_D3D9 diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index 3395c3f8..40a27550 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -108,6 +108,7 @@ + @@ -167,6 +168,7 @@ + @@ -191,4 +193,4 @@ - + \ No newline at end of file diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index 02aa9dfd..47288ee8 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -44,6 +44,9 @@ {94992c0e-ebc5-4185-b766-323b06547dcf} + + {a914e15d-3201-467a-a9c9-d7c5244b13ee} + @@ -205,6 +208,9 @@ src\input + + src\platform\d3d9 + @@ -387,5 +393,8 @@ src\input + + src\platform\d3d9 + - + \ No newline at end of file