summaryrefslogtreecommitdiff
path: root/prge_input.c
blob: 74de9e56172ac09fed40d8068a1565eca0ee3623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Input init_input()
{
	Input	in;

	MEM0STRUCT(&in);

	in.first_mouse = 1;

	return in;
}

/* NOTE(pryazha): Updates the last states of keys, mouse position and offset.
 * Should be called every frame */
void update_input(Input *in)
{
	in->last_mouse_pos = in->mouse_pos;
	in->mouse_offset = V2_ZERO;
	in->mouse_left.last = in->mouse_left.state;
	in->mouse_right.last = in->mouse_right.state;

	in->move_right.last = in->move_right.state;
	in->move_forward.last = in->move_forward.state;
	in->move_left.last = in->move_left.state;
	in->move_backward.last = in->move_backward.state;
	in->move_up.last = in->move_up.state;
	in->move_down.last = in->move_down.state;
	in->jump.last = in->jump.state;
	in->action_right.last = in->action_right.state;
	in->action_up.last = in->action_up.state;
	in->action_left.last = in->action_left.state;
	in->action_down.last = in->action_down.state;
	in->exit.last = in->exit.state;
}

B32 is_key_down(Key key)
{
	B32 r = (key.state == KeyState_PRESS);
	return r;
}

B32 is_key_pressed(Key key)
{
	B32 r = ((key.last == KeyState_RELEASE) && (key.state == KeyState_PRESS));
	return r;
}

B32 was_key_pressed(Key key)
{
	B32 r = ((key.last == KeyState_PRESS) && (key.state == KeyState_RELEASE));
	return r;
}