Add cleanup of input handlers when shutting down; Remove C++11ism.

This commit is contained in:
Levi Pearson 2017-01-25 22:58:45 -07:00
parent 91e2918f50
commit 6e06a9ac52
3 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,7 @@
class InputHandler
{
public:
virtual ~InputHandler() {};
virtual bool update(SDL_Event &e) = 0;
virtual bool pressed() = 0;
virtual void reset() = 0;

View File

@ -36,6 +36,14 @@ UserInput::UserInput(Configuration &c)
UserInput::~UserInput()
{
for (unsigned int i = 0; i < keyHandlers_.size(); ++i)
{
if (keyHandlers_[i].first)
{
delete keyHandlers_[i].first;
}
}
// This code causes an exception when a controller is attached; it's disabled to prevent crashes on exit.
// for(std::vector<SDL_Joystick *>::iterator it = joysticks_.begin(); it != joysticks_.end(); it++)
// {

View File

@ -64,7 +64,7 @@ private:
bool MapKey(std::string keyDescription, KeyCode_E key, bool required);
Configuration &config_;
std::vector<SDL_Joystick *> joysticks_;
std::vector<std::pair<InputHandler *, KeyCode_E>> keyHandlers_;
std::vector<std::pair<InputHandler *, KeyCode_E> > keyHandlers_;
bool lastKeyState_[KeyCodeMax];
bool currentKeyState_[KeyCodeMax];
};