diff --git a/src/Makefile.am b/src/Makefile.am index 87b7a4c2..044d1990 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -70,7 +70,8 @@ endif if HAVE_XBOX xbox_sources = \ - platform/xbox/xboxapp.cpp platform/xbox/xboxapp.h + platform/xbox/xboxapp.cpp platform/xbox/xboxapp.h \ + platform/xbox/xboxinput.cpp platform/xbox/xboxinput.h endif android_sources = \ diff --git a/src/platform/xbox/xboxapp.cpp b/src/platform/xbox/xboxapp.cpp index 8460f51b..2d492e9e 100644 --- a/src/platform/xbox/xboxapp.cpp +++ b/src/platform/xbox/xboxapp.cpp @@ -17,8 +17,8 @@ #endif #include "core.h" -#include "lolgl.h" #include "xboxapp.h" +#include "xboxinput.h" #if defined _XBOX extern D3DDevice *g_d3ddevice; @@ -50,6 +50,9 @@ XboxApp::XboxApp(char const *title, ivec2 res, float fps) : #if defined _XBOX Ticker::Setup(fps); Video::Setup(res); + + /* Autoreleased objects */ + new XboxInput(); #endif } diff --git a/src/platform/xbox/xboxinput.cpp b/src/platform/xbox/xboxinput.cpp new file mode 100644 index 00000000..da6f21b2 --- /dev/null +++ b/src/platform/xbox/xboxinput.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 _XBOX +# include +# include +#endif + +#include "core.h" +#include "xboxinput.h" + +namespace lol +{ + +/* + * Xbox Input implementation class + */ + +class XboxInputData +{ + friend class XboxInput; + +private: +#if defined _XBOX + Array m_joysticks; +#endif +}; + +/* + * Public XboxInput class + */ + +XboxInput::XboxInput() + : m_data(new XboxInputData()) +{ +#if defined _XBOX + 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; +} + +XboxInput::~XboxInput() +{ +#if defined _XBOX + /* 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 XboxInput::TickGame(float seconds) +{ + Entity::TickGame(seconds); +} + +void XboxInput::TickDraw(float seconds) +{ + Entity::TickDraw(seconds); + +#if defined _XBOX + 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/xbox/xboxinput.h b/src/platform/xbox/xboxinput.h new file mode 100644 index 00000000..b26156a7 --- /dev/null +++ b/src/platform/xbox/xboxinput.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 XboxInput class +// ------------------- +// + +#if !defined __LOL_XBOXINPUT_H__ +#define __LOL_XBOXINPUT_H__ + +#include "entity.h" + +namespace lol +{ + +class XboxInputData; + +class XboxInput : public Entity +{ +public: + XboxInput(); + virtual ~XboxInput(); + +protected: + virtual void TickGame(float seconds); + virtual void TickDraw(float seconds); + +private: + XboxInputData *m_data; +}; + +} /* namespace lol */ + +#endif // __LOL_XBOXINPUT_H__ + diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index bb7feee1..3395c3f8 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -111,6 +111,7 @@ + @@ -169,6 +170,7 @@ + diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index 5d18e43a..02aa9dfd 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -193,6 +193,9 @@ src\platform\xbox + + src\platform\xbox + src\gpu @@ -366,6 +369,9 @@ src\platform\xbox + + src\platform\xbox + src\gpu @@ -382,4 +388,4 @@ src\input - \ No newline at end of file + diff --git a/win32/lolengine.sln b/win32/lolengine.sln index 5711db12..d4b34b06 100644 --- a/win32/lolengine.sln +++ b/win32/lolengine.sln @@ -259,8 +259,8 @@ Global {B1E10086-A1DA-401A-834D-969C9DBB5CC1} = {E0491194-35E3-4513-9D31-608EA3165ECF} {80F81C11-8DA2-4990-91CB-9807783BA46E} = {E0491194-35E3-4513-9D31-608EA3165ECF} {B92ABADC-45BE-4CC5-B724-9426053123A1} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} - {6BF81B39-EDC2-4227-9992-C2D8ABEA95AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {7B083DA2-FE08-4F6D-BFDD-195D5C2783EB} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} + {6BF81B39-EDC2-4227-9992-C2D8ABEA95AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} {32F3F8CF-D22E-45E4-BEB8-AD909E8C5515} = {33704AA4-F2B5-4138-A40D-E3E77F89ED46} {EE203B88-44CF-4859-9D42-7A5F40FECB52} = {8C77EAA8-1077-4EF7-AE53-97C6C60A3601} EndGlobalSection