forked from Mirrors/openclonk
send perioic gamepad axis change callbacks even if direction didn't change
parent
c733884bf9
commit
dda34d3897
|
@ -159,7 +159,7 @@ bool C4Application::DoInit()
|
|||
return true;
|
||||
#endif
|
||||
|
||||
DDrawCfg.Shader = Config.Graphics.EnableShaders;
|
||||
DDrawCfg.Shader = !!Config.Graphics.EnableShaders;
|
||||
|
||||
// Fixup resolution
|
||||
ApplyResolutionConstraints();
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <C4Log.h>
|
||||
#include <C4Network2Stats.h>
|
||||
#include <C4MouseControl.h>
|
||||
#include <C4GamePadCon.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4355)
|
||||
|
@ -530,6 +531,7 @@ void C4GameControl::PrepareInput()
|
|||
{
|
||||
// add per-controlframe input
|
||||
::MouseControl.DoMoveInput();
|
||||
if (Application.pGamePadControl) Application.pGamePadControl->DoAxisInput();
|
||||
}
|
||||
|
||||
C4GameControl Control;
|
||||
|
|
|
@ -60,20 +60,24 @@ void C4GamePadControl::Clear()
|
|||
}
|
||||
|
||||
void C4GamePadControl::OpenGamepad(int id)
|
||||
{
|
||||
{
|
||||
if (!Inside(id, 0, CStdGamepad_MaxGamePad-1)) return;
|
||||
// add gamepad ref
|
||||
if (!(Gamepads[id].iRefCount++))
|
||||
{
|
||||
{
|
||||
// this is the first gamepad opening: Init it
|
||||
Pad &rPad = Gamepads[id];
|
||||
rPad.pGamepad = new CStdGamePad(id);
|
||||
rPad.Buttons= 0;
|
||||
for (int i=0; i< CStdGamepad_MaxAxis; ++i) rPad.AxisPosis[i] = CStdGamePad::Mid;
|
||||
for (int i=0; i< CStdGamepad_MaxAxis; ++i)
|
||||
{
|
||||
rPad.AxisPosis[i] = CStdGamePad::Mid;
|
||||
rPad.AxisStrengths[i] = 0;
|
||||
}
|
||||
rPad.pGamepad->SetCalibration(&(Config.Gamepads[id].AxisMin[0]), &(Config.Gamepads[id].AxisMax[0]), &(Config.Gamepads[id].AxisCalibrated[0]));
|
||||
++iNumGamepads;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void C4GamePadControl::CloseGamepad(int id)
|
||||
{
|
||||
|
@ -98,7 +102,7 @@ int C4GamePadControl::GetGamePadCount()
|
|||
|
||||
const int MaxGamePadButton=10;
|
||||
|
||||
void C4GamePadControl::Execute()
|
||||
void C4GamePadControl::Execute(bool send_axis_strength_changes)
|
||||
{
|
||||
// Get gamepad inputs
|
||||
int iNum = iNumGamepads;
|
||||
|
@ -113,11 +117,13 @@ void C4GamePadControl::Execute()
|
|||
{
|
||||
int32_t iStrength = 100;
|
||||
CStdGamePad::AxisPos eAxisPos = rPad.pGamepad->GetAxisPos(iAxis, &iStrength), ePrevAxisPos = rPad.AxisPosis[iAxis];
|
||||
int32_t iPrevStrength = rPad.AxisStrengths[iAxis];
|
||||
// Evaluate changes and pass single controls
|
||||
// this is a generic Gamepad-control: Create events
|
||||
if (eAxisPos != ePrevAxisPos)
|
||||
if (eAxisPos != ePrevAxisPos || (send_axis_strength_changes && Abs(iPrevStrength-iStrength) > AxisStrengthChangeThreshold))
|
||||
{
|
||||
rPad.AxisPosis[iAxis] = eAxisPos;
|
||||
rPad.AxisStrengths[iAxis] = iStrength;
|
||||
if (ePrevAxisPos != CStdGamePad::Mid)
|
||||
Game.DoKeyboardInput(KEY_Gamepad(idGamepad, KEY_JOY_Axis(iAxis, (ePrevAxisPos==CStdGamePad::High))), KEYEV_Up, false, false, false, false);
|
||||
if (eAxisPos != CStdGamePad::Mid)
|
||||
|
@ -139,6 +145,13 @@ void C4GamePadControl::Execute()
|
|||
}
|
||||
}
|
||||
|
||||
void C4GamePadControl::DoAxisInput()
|
||||
{
|
||||
// Send axis strength changes
|
||||
Execute(true);
|
||||
}
|
||||
|
||||
|
||||
bool C4GamePadControl::AnyButtonDown()
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -48,10 +48,13 @@ class C4GamePadControl {
|
|||
int iRefCount;
|
||||
uint32_t Buttons;
|
||||
CStdGamePad::AxisPos AxisPosis[CStdGamepad_MaxAxis];
|
||||
int32_t AxisStrengths[CStdGamepad_MaxAxis];
|
||||
};
|
||||
Pad Gamepads[CStdGamepad_MaxGamePad];
|
||||
int iNumGamepads;
|
||||
|
||||
enum { AxisStrengthChangeThreshold = 2 }; // if axis strength change > this value, a new control is issued
|
||||
|
||||
public:
|
||||
void OpenGamepad(int id); // add gamepad ref
|
||||
void CloseGamepad(int id); // del gamepad ref
|
||||
|
@ -67,7 +70,8 @@ class C4GamePadControl {
|
|||
~C4GamePadControl();
|
||||
void Clear();
|
||||
int GetGamePadCount();
|
||||
void Execute();
|
||||
void Execute(bool send_axis_strength_changes=false);
|
||||
void DoAxisInput(); // period axis strength update controls sent on each control frame creation
|
||||
static bool AnyButtonDown();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue