Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: ecs_event.c |
3 |
|
|
* Path: source/utils |
4 |
|
|
* Created Date: Thursday, November 30th 2023, 5:39 pm |
5 |
|
|
* Author: osvegn |
6 |
|
|
* |
7 |
|
|
* Copyright (c) 2023 ECS |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include "utils/ecs_event.h" |
11 |
|
|
#include "world_logger.h" |
12 |
|
|
|
13 |
|
|
static event_queue queue = {0}; |
14 |
|
|
|
15 |
|
12 |
void event_queue_constructor(void) |
16 |
|
|
{ |
17 |
|
12 |
log_info("Constructing event queue"); |
18 |
|
12 |
vector_constructor(&queue, sizeof(ecs_event_t), 10); |
19 |
|
12 |
} |
20 |
|
|
|
21 |
|
12 |
void event_queue_destructor() |
22 |
|
|
{ |
23 |
|
12 |
log_info("Destructing event queue"); |
24 |
|
12 |
queue.destructor(&queue); |
25 |
|
12 |
} |
26 |
|
|
|
27 |
|
11 |
void add_mouse_event(ecs_mouse_t mouse, float value, int device_id) |
28 |
|
|
{ |
29 |
|
11 |
ecs_event_t e = { |
30 |
|
|
.device_id=device_id, |
31 |
|
|
.input.mouse=mouse, |
32 |
|
|
.value=value, |
33 |
|
|
.type=EVENT_MOUSE |
34 |
|
|
}; |
35 |
|
11 |
log_info("Adding mouse event to queue with value %f", value); |
36 |
|
11 |
queue.emplace_back(&queue, &e); |
37 |
|
11 |
} |
38 |
|
|
|
39 |
|
8 |
void add_key_event(ecs_keyboard_t key, float value, int device_id) |
40 |
|
|
{ |
41 |
|
8 |
ecs_event_t e = { |
42 |
|
|
.device_id=device_id, |
43 |
|
|
.input.key=key, |
44 |
|
|
.value=value, |
45 |
|
|
.type=EVENT_KEYBOARD |
46 |
|
|
}; |
47 |
|
8 |
log_info("Adding key event to queue with value %f", value); |
48 |
|
8 |
queue.emplace_back(&queue, &e); |
49 |
|
8 |
} |
50 |
|
|
|
51 |
|
✗ |
void add_controller_event(ecs_controller_t controller, float value, int device_id) |
52 |
|
|
{ |
53 |
|
✗ |
ecs_event_t e = { |
54 |
|
|
.input.controller=controller, |
55 |
|
|
.device_id=device_id, |
56 |
|
|
.value=value, |
57 |
|
|
.type=EVENT_CONTROLLER |
58 |
|
|
}; |
59 |
|
✗ |
log_info("Adding controller event to queue with value %f", value); |
60 |
|
✗ |
queue.emplace_back(&queue, &e); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
2 |
void get_event(ecs_event_t *event) |
64 |
|
|
{ |
65 |
|
2 |
(*event) = *(ecs_event_t *)queue.at(&queue, 0); |
66 |
|
2 |
log_info("Event type: %d", event->type); |
67 |
|
2 |
queue.erase(&queue, 0); |
68 |
|
2 |
log_info("Event queue size: %d", queue.size(&queue)); |
69 |
|
2 |
} |
70 |
|
|
|
71 |
|
2 |
void event_queue_clear(void) |
72 |
|
|
{ |
73 |
|
2 |
log_info("Clearing event queue"); |
74 |
|
2 |
queue.clear(&queue); |
75 |
|
2 |
} |
76 |
|
|
|
77 |
|
16 |
unsigned int event_queue_size(void) |
78 |
|
|
{ |
79 |
|
16 |
log_info("Event queue size: %d", queue.size(&queue)); |
80 |
|
16 |
return queue.size(&queue); |
81 |
|
|
} |
82 |
|
|
|