浏览代码

input: support Xbox input system for gamepads.

legacy
Sam Hocevar sam 12 年前
父节点
当前提交
54fe8937ad
共有 7 个文件被更改,包括 161 次插入4 次删除
  1. +2
    -1
      src/Makefile.am
  2. +4
    -1
      src/platform/xbox/xboxapp.cpp
  3. +102
    -0
      src/platform/xbox/xboxinput.cpp
  4. +43
    -0
      src/platform/xbox/xboxinput.h
  5. +2
    -0
      win32/lolcore.vcxproj
  6. +7
    -1
      win32/lolcore.vcxproj.filters
  7. +1
    -1
      win32/lolengine.sln

+ 2
- 1
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 = \


+ 4
- 1
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
}



+ 102
- 0
src/platform/xbox/xboxinput.cpp 查看文件

@@ -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 _XBOX
# include <xtl.h>
# include <xbdm.h>
#endif

#include "core.h"
#include "xboxinput.h"

namespace lol
{

/*
* Xbox Input implementation class
*/

class XboxInputData
{
friend class XboxInput;

private:
#if defined _XBOX
Array<int, Stick *> 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 */


+ 43
- 0
src/platform/xbox/xboxinput.h 查看文件

@@ -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 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__


+ 2
- 0
win32/lolcore.vcxproj 查看文件

@@ -111,6 +111,7 @@
<ClCompile Include="..\src\platform\sdl\sdlapp.cpp" />
<ClCompile Include="..\src\platform\sdl\sdlinput.cpp" />
<ClCompile Include="..\src\platform\xbox\xboxapp.cpp" />
<ClCompile Include="..\src\platform\xbox\xboxinput.cpp" />
<ClCompile Include="..\src\profiler.cpp" />
<ClCompile Include="..\src\sample.cpp" />
<ClCompile Include="..\src\sampler.cpp" />
@@ -169,6 +170,7 @@
<ClInclude Include="..\src\platform\sdl\sdlapp.h" />
<ClInclude Include="..\src\platform\sdl\sdlinput.h" />
<ClInclude Include="..\src\platform\xbox\xboxapp.h" />
<ClInclude Include="..\src\platform\xbox\xboxinput.h" />
<ClInclude Include="..\src\profiler.h" />
<ClInclude Include="..\src\sample.h" />
<ClInclude Include="..\src\sampler.h" />


+ 7
- 1
win32/lolcore.vcxproj.filters 查看文件

@@ -193,6 +193,9 @@
<ClCompile Include="..\src\platform\xbox\xboxapp.cpp">
<Filter>src\platform\xbox</Filter>
</ClCompile>
<ClCompile Include="..\src\platform\xbox\xboxinput.cpp">
<Filter>src\platform\xbox</Filter>
</ClCompile>
<ClCompile Include="..\src\gpu\indexbuffer.cpp">
<Filter>src\gpu</Filter>
</ClCompile>
@@ -366,6 +369,9 @@
<ClInclude Include="..\src\platform\xbox\xboxapp.h">
<Filter>src\platform\xbox</Filter>
</ClInclude>
<ClInclude Include="..\src\platform\xbox\xboxinput.h">
<Filter>src\platform\xbox</Filter>
</ClInclude>
<ClInclude Include="..\src\gpu\indexbuffer.h">
<Filter>src\gpu</Filter>
</ClInclude>
@@ -382,4 +388,4 @@
<Filter>src\input</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>

+ 1
- 1
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


正在加载...
取消
保存