/* Copyright (c) 2023 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #include "gamemath/ActionInput.h" bool ActionInput_start(ActionInputState * ioState, ActionInput_action action) { ActionInputState state = *ioState; bool wasActive = ActionInput_isActive(state, action); state |= 1 << (action * 2); if (!wasActive) { state |= 2 << (action * 2); } *ioState = state; return !wasActive; } bool ActionInput_stop(ActionInputState * ioState, ActionInput_action action) { ActionInputState state = *ioState; bool wasActive = ActionInput_isActive(state, action); state &= ~(1 << (action * 2)); if (wasActive) { state |= 2 << (action * 2); } *ioState = state; return wasActive; } void ActionInput_processed(ActionInputState * ioState, ActionInput_action action) { *ioState &= ~(2 << (action * 2)); } void ActionInput_clear(ActionInputState * ioState, ActionInput_action action) { *ioState &= ~(3 << (action * 2)); } bool ActionInput_isActive(ActionInputState state, ActionInput_action action) { return state & (1 << (action * 2)); } bool ActionInput_isDirty(ActionInputState state, ActionInput_action action) { return state & (2 << (action * 2)); } bool ActionInput_isNewlyActive(ActionInputState state, ActionInput_action action) { return (state & (3 << (action * 2))) == (3u << action * 2); } bool ActionInput_isNewlyInactive(ActionInputState state, ActionInput_action action) { return (state & (3 << (action * 2))) == (2u << action * 2); }