| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2015 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #include "inputhandler.hpp" |
| 17 | #include <cassert> |
| 18 | #include <iostream> |
| 19 | |
| 20 | bool InputHandler::m_enabled = true; |
| 21 | |
| 22 | InputHandler::InputHandler(size_t maxPlayers) |
| 23 | : m_playerActions(maxPlayers, std::bitset<static_cast<int>(Action::EndOfEnum)>()) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | bool InputHandler::getActionState(size_t playerIndex, Action action) const |
| 28 | { |
| 29 | return InputHandler::m_enabled && m_playerActions[playerIndex][static_cast<size_t>(action)]; |
| 30 | } |
| 31 | |
| 32 | void InputHandler::setActionState(size_t playerIndex, Action action, bool state) |
| 33 | { |
| 34 | m_playerActions[playerIndex][static_cast<size_t>(action)] = state; |
| 35 | } |
| 36 | |
| 37 | void InputHandler::setEnabled(bool state) |
| 38 | { |
| 39 | m_enabled = state; |
| 40 | } |
| 41 | |
| 42 | bool InputHandler::enabled() |
| 43 | { |
| 44 | return m_enabled; |
| 45 | } |
| 46 | |
| 47 | void InputHandler::reset() |
| 48 | { |
| 49 | for (auto && i : m_playerActions) |
| 50 | { |
| 51 | i.reset(); |
| 52 | } |
| 53 | } |