Convert joystick handler to use vectors and eliminate raw new/delete.

This commit is contained in:
Stephen Anthony 2019-12-22 21:43:50 -03:30
parent 2ec91dbe6b
commit 2944ee7564
2 changed files with 11 additions and 25 deletions

View File

@ -30,19 +30,10 @@ PhysicalJoystick::PhysicalJoystick()
name("None"),
numAxes(0),
numButtons(0),
numHats(0),
axisLastValue(nullptr),
buttonLast(nullptr)
numHats(0)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystick::~PhysicalJoystick()
{
delete[] axisLastValue;
delete[] buttonLast;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalJoystick::initialize(int index, const string& desc,
int axes, int buttons, int hats, int /*balls*/)
@ -50,21 +41,11 @@ void PhysicalJoystick::initialize(int index, const string& desc,
ID = index;
name = desc;
// Dynamically create the various mapping arrays for this joystick,
// based on its specific attributes
numAxes = axes;
numButtons = buttons;
numHats = hats;
axisLastValue = new int[numAxes];
buttonLast = new int[numButtons];
// 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;
axisLastValue.resize(numAxes, 0);
buttonLast.resize(numButtons, JOY_CTRL_NONE);
// Erase the mappings
eraseMap(EventMode::kMenuMode);

View File

@ -43,7 +43,6 @@ class PhysicalJoystick
public:
PhysicalJoystick();
virtual ~PhysicalJoystick();
string getMap() const;
bool setMap(const string& map);
@ -70,8 +69,8 @@ class PhysicalJoystick
int ID;
string name;
int numAxes, numButtons, numHats;
int* axisLastValue;
int* buttonLast;
IntArray axisLastValue;
IntArray buttonLast;
// Hashmaps of controller events
JoyMap joyMap;
@ -84,6 +83,12 @@ class PhysicalJoystick
<< ", numbtns: " << s.numButtons << ", numhats: " << s.numHats;
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