/* 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 */ #ifndef __ActionInput_H__ #define __ActionInput_H__ #include #include typedef uint32_t ActionInputState; typedef unsigned int ActionInput_action; #define ActionInputState_allNeutral 0 #define ACTION_INPUT_BITS_PER_ACTION 2 #define ACTION_INPUT_COUNT_MAX (sizeof(ActionInput) * 8 / ACTION_INPUT_BITS_PER_ACTION) // 16 // Starts the specified action, setting the dirty bit for that action and returning true if it wasn't already active bool ActionInput_start(ActionInputState * ioState, ActionInput_action action); // Stops the specified action, setting the dirty bit for that action and returning true if it was active bool ActionInput_stop(ActionInputState * ioState, ActionInput_action action); // Marks that the specified action has been acknowledged and clears its dirty bit void ActionInput_processed(ActionInputState * ioState, ActionInput_action action); // Resets the specified action to inactive and not dirty void ActionInput_clear(ActionInputState * ioState, ActionInput_action action); // Returns true if the specified action is currently active bool ActionInput_isActive(ActionInputState state, ActionInput_action action); // Returns true if the state of the specified action has changed since the last call to ActionInput_processed() bool ActionInput_isDirty(ActionInputState state, ActionInput_action action); // Returns true if the specified action is currently both active and dirty bool ActionInput_isNewlyActive(ActionInputState state, ActionInput_action action); // Returns true if the specified action is currently both inactive and dirty bool ActionInput_isNewlyInactive(ActionInputState state, ActionInput_action action); #endif