Paddle: make raw interface to return values in [-1,1] to ease transformations.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
e8972aa824
commit
d314546b11
8 changed files with 24 additions and 16 deletions
|
@ -90,14 +90,14 @@ bool EvDevPaddle::getButton(int i) const
|
||||||
return value != 0;
|
return value != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EvDevPaddle::getAxis(int i) const
|
double EvDevPaddle::getAxis(int i) const
|
||||||
{
|
{
|
||||||
if (myDev)
|
if (myDev)
|
||||||
{
|
{
|
||||||
int value = 0;
|
int value = 0;
|
||||||
int rc = libevdev_fetch_event_value(myDev.get(), EV_ABS, myAxisCodes[i], &value);
|
int rc = libevdev_fetch_event_value(myDev.get(), EV_ABS, myAxisCodes[i], &value);
|
||||||
int pdl = 255 * (value - myAxisMins[i]) / (myAxisMaxs[i] - myAxisMins[i]);
|
const double axis = 2.0 * (value - myAxisMins[i]) / (myAxisMaxs[i] - myAxisMins[i]) - 1.0;
|
||||||
return pdl;
|
return axis;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
const std::string & getName() const;
|
const std::string & getName() const;
|
||||||
virtual bool getButton(int i) const;
|
virtual bool getButton(int i) const;
|
||||||
virtual int getAxis(int i) const;
|
virtual double getAxis(int i) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int myFD;
|
int myFD;
|
||||||
|
|
|
@ -43,7 +43,7 @@ bool GamepadPaddle::getButton(int i) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GamepadPaddle::getAxis(int i) const
|
double GamepadPaddle::getAxis(int i) const
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
switch (i)
|
switch (i)
|
||||||
|
@ -58,6 +58,5 @@ int GamepadPaddle::getAxis(int i) const
|
||||||
value = 0.0;
|
value = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int pdl = int((value + 1.0) / 2.0 * 255.0);
|
return value;
|
||||||
return pdl;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
static std::shared_ptr<Paddle> fromName(const QString & name);
|
static std::shared_ptr<Paddle> fromName(const QString & name);
|
||||||
|
|
||||||
virtual bool getButton(int i) const;
|
virtual bool getButton(int i) const;
|
||||||
virtual int getAxis(int i) const;
|
virtual double getAxis(int i) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GamepadPaddle(const std::shared_ptr<QGamepad> & gamepad);
|
GamepadPaddle(const std::shared_ptr<QGamepad> & gamepad);
|
||||||
|
|
|
@ -27,16 +27,16 @@ bool Gamepad::getButton(int i) const
|
||||||
return value != 0;
|
return value != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gamepad::getAxis(int i) const
|
double Gamepad::getAxis(int i) const
|
||||||
{
|
{
|
||||||
if (myController)
|
if (myController)
|
||||||
{
|
{
|
||||||
const int value = SDL_GameControllerGetAxis(myController.get(), myAxisCodes[i]);
|
const int value = SDL_GameControllerGetAxis(myController.get(), myAxisCodes[i]);
|
||||||
int pdl = 255 * (value - AXIS_MIN) / (AXIS_MAX - AXIS_MIN);
|
const double axis = 2.0 * double(value - AXIS_MIN) / double(AXIS_MAX - AXIS_MIN) - 1.0;
|
||||||
return pdl;
|
return axis;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
Gamepad(const int index);
|
Gamepad(const int index);
|
||||||
|
|
||||||
virtual bool getButton(int i) const;
|
virtual bool getButton(int i) const;
|
||||||
virtual int getAxis(int i) const;
|
virtual double getAxis(int i) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<SDL_GameController> myController;
|
std::shared_ptr<SDL_GameController> myController;
|
||||||
|
|
|
@ -45,11 +45,18 @@ bool Paddle::getButton(int i) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Paddle::getAxis(int i) const
|
double Paddle::getAxis(int i) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Paddle::getAxisValue(int i) const
|
||||||
|
{
|
||||||
|
const double axis = getAxis(i);
|
||||||
|
const int value = static_cast<int>((axis + 1.0) * 0.5 * 255);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
Paddle::~Paddle()
|
Paddle::~Paddle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -100,7 +107,7 @@ BYTE __stdcall JoyReadPosition(WORD pc, WORD address, BYTE bWrite, BYTE d, ULONG
|
||||||
if (nJoyNum == 0)
|
if (nJoyNum == 0)
|
||||||
{
|
{
|
||||||
int axis = address & 1;
|
int axis = address & 1;
|
||||||
int pdl = paddle->getAxis(axis);
|
int pdl = paddle->getAxisValue(axis);
|
||||||
// This is from KEGS. It helps games like Championship Lode Runner & Boulderdash
|
// This is from KEGS. It helps games like Championship Lode Runner & Boulderdash
|
||||||
if (pdl >= 255)
|
if (pdl >= 255)
|
||||||
pdl = 280;
|
pdl = 280;
|
||||||
|
|
|
@ -11,7 +11,9 @@ public:
|
||||||
virtual ~Paddle();
|
virtual ~Paddle();
|
||||||
|
|
||||||
virtual bool getButton(int i) const;
|
virtual bool getButton(int i) const;
|
||||||
virtual int getAxis(int i) const;
|
virtual double getAxis(int i) const;
|
||||||
|
|
||||||
|
int getAxisValue(int i) const;
|
||||||
|
|
||||||
static constexpr int ourOpenApple = 0x61;
|
static constexpr int ourOpenApple = 0x61;
|
||||||
static constexpr int ourSolidApple = 0x62;
|
static constexpr int ourSolidApple = 0x62;
|
||||||
|
|
Loading…
Add table
Reference in a new issue