first commit

This commit is contained in:
2024-08-24 00:47:58 -04:00
commit f6ef842a28
400 changed files with 43479 additions and 0 deletions
CMakeLists.txtLICENSE
include/cglm
src
COMMON.h
engine
game
GAME_COMMON.h
ecs
ECS_COMMON.h
component
COMPONENT_COMMON.h
animation
game
physics
ui
utility
visual
ecs.cecs.hecs_component.cecs_component.hecs_component_list.cecs_component_list.hecs_entity.cecs_entity.h
entity
game.cgame.h
input
render
resource
state
main.cmain.h

78
src/game/input/control.c Normal file

@ -0,0 +1,78 @@
#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;
}
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);
}