mirror of https://github.com/stella-emu/stella.git
Convert joystick handler to use vectors and eliminate raw new/delete.
This commit is contained in:
parent
2ec91dbe6b
commit
2944ee7564
|
@ -30,19 +30,10 @@ PhysicalJoystick::PhysicalJoystick()
|
||||||
name("None"),
|
name("None"),
|
||||||
numAxes(0),
|
numAxes(0),
|
||||||
numButtons(0),
|
numButtons(0),
|
||||||
numHats(0),
|
numHats(0)
|
||||||
axisLastValue(nullptr),
|
|
||||||
buttonLast(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
PhysicalJoystick::~PhysicalJoystick()
|
|
||||||
{
|
|
||||||
delete[] axisLastValue;
|
|
||||||
delete[] buttonLast;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PhysicalJoystick::initialize(int index, const string& desc,
|
void PhysicalJoystick::initialize(int index, const string& desc,
|
||||||
int axes, int buttons, int hats, int /*balls*/)
|
int axes, int buttons, int hats, int /*balls*/)
|
||||||
|
@ -50,21 +41,11 @@ void PhysicalJoystick::initialize(int index, const string& desc,
|
||||||
ID = index;
|
ID = index;
|
||||||
name = desc;
|
name = desc;
|
||||||
|
|
||||||
// Dynamically create the various mapping arrays for this joystick,
|
|
||||||
// based on its specific attributes
|
|
||||||
numAxes = axes;
|
numAxes = axes;
|
||||||
numButtons = buttons;
|
numButtons = buttons;
|
||||||
numHats = hats;
|
numHats = hats;
|
||||||
axisLastValue = new int[numAxes];
|
axisLastValue.resize(numAxes, 0);
|
||||||
buttonLast = new int[numButtons];
|
buttonLast.resize(numButtons, JOY_CTRL_NONE);
|
||||||
|
|
||||||
// Erase the last button
|
|
||||||
for (int b = 0; b < numButtons; ++b)
|
|
||||||
buttonLast[b] = JOY_CTRL_NONE;
|
|
||||||
|
|
||||||
// Erase the last axis value
|
|
||||||
for(int a = 0; a < numAxes; ++a)
|
|
||||||
axisLastValue[a] = 0;
|
|
||||||
|
|
||||||
// Erase the mappings
|
// Erase the mappings
|
||||||
eraseMap(EventMode::kMenuMode);
|
eraseMap(EventMode::kMenuMode);
|
||||||
|
|
|
@ -43,7 +43,6 @@ class PhysicalJoystick
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PhysicalJoystick();
|
PhysicalJoystick();
|
||||||
virtual ~PhysicalJoystick();
|
|
||||||
|
|
||||||
string getMap() const;
|
string getMap() const;
|
||||||
bool setMap(const string& map);
|
bool setMap(const string& map);
|
||||||
|
@ -70,8 +69,8 @@ class PhysicalJoystick
|
||||||
int ID;
|
int ID;
|
||||||
string name;
|
string name;
|
||||||
int numAxes, numButtons, numHats;
|
int numAxes, numButtons, numHats;
|
||||||
int* axisLastValue;
|
IntArray axisLastValue;
|
||||||
int* buttonLast;
|
IntArray buttonLast;
|
||||||
|
|
||||||
// Hashmaps of controller events
|
// Hashmaps of controller events
|
||||||
JoyMap joyMap;
|
JoyMap joyMap;
|
||||||
|
@ -84,6 +83,12 @@ class PhysicalJoystick
|
||||||
<< ", numbtns: " << s.numButtons << ", numhats: " << s.numHats;
|
<< ", numbtns: " << s.numButtons << ", numhats: " << s.numHats;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Following constructors and assignment operators not supported
|
||||||
|
PhysicalJoystick(const PhysicalJoystick&) = delete;
|
||||||
|
PhysicalJoystick(PhysicalJoystick&&) = delete;
|
||||||
|
PhysicalJoystick& operator=(const PhysicalJoystick&) = delete;
|
||||||
|
PhysicalJoystick& operator=(PhysicalJoystick&&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue