82 lines
2.3 KiB
C
82 lines
2.3 KiB
C
#include "control.h"
|
|
|
|
void
|
|
control_tick(Control* self, Input* input)
|
|
{
|
|
memcpy(&self->previous, &self->current, sizeof(bool) * CONTROL_COUNT);
|
|
memset(&self->current, '\0', sizeof(bool) * CONTROL_COUNT);
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_UP] || input->keyboard.current[KEYBOARD_KEY_W])
|
|
self->current[CONTROL_UP] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_LEFT] || input->keyboard.current[KEYBOARD_KEY_A])
|
|
self->current[CONTROL_LEFT] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_RIGHT] || input->keyboard.current[KEYBOARD_KEY_D])
|
|
self->current[CONTROL_RIGHT] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_DOWN] || input->keyboard.current[KEYBOARD_KEY_S])
|
|
self->current[CONTROL_DOWN] = true;
|
|
|
|
if (input->mouse.current[MOUSE_BUTTON_LEFT])
|
|
self->current[CONTROL_ACTION_PRIMARY] = true;
|
|
|
|
if (input->mouse.current[MOUSE_BUTTON_RIGHT])
|
|
self->current[CONTROL_ACTION_SECONDARY] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_SPACE] || input->mouse.current[MOUSE_BUTTON_MIDDLE])
|
|
self->current[CONTROL_ACTION_TERTIARY] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_1])
|
|
self->current[CONTROL_INVIGORATE] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_2])
|
|
self->current[CONTROL_EXTEND] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_3])
|
|
self->current[CONTROL_FORESIGHT] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_4])
|
|
self->current[CONTROL_CANCEL] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_5])
|
|
self->current[CONTROL_MAGNET] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_P])
|
|
self->current[CONTROL_PAUSE] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_R])
|
|
self->current[CONTROL_RETRY] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_ESCAPE])
|
|
self->current[CONTROL_ESCAPE] = true;
|
|
|
|
if (input->keyboard.current[KEYBOARD_KEY_M])
|
|
self->current[CONTROL_MUTE] = true;
|
|
}
|
|
|
|
bool
|
|
control_held(Control* self, ControlType type)
|
|
{
|
|
return self->current[type] && self->previous[type];
|
|
}
|
|
|
|
bool
|
|
control_pressed(Control* self, ControlType type)
|
|
{
|
|
return self->current[type] && !self->previous[type];
|
|
}
|
|
|
|
bool
|
|
control_released(Control* self, ControlType type)
|
|
{
|
|
return !self->current[type] && self->previous[type];
|
|
}
|
|
|
|
void
|
|
control_clear(Control* self)
|
|
{
|
|
memset(&self->previous, '\0', sizeof(bool) * CONTROL_COUNT);
|
|
memset(&self->current, '\0', sizeof(bool) * CONTROL_COUNT);
|
|
}
|