-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
70 lines (56 loc) · 1.59 KB
/
test.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "evs.h"
#include "../ecs.h/ecs.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define NUM_ENT 512
#define NUM_EVT_PER_ENT 1000
#define TEST_SEC 10
#define EVT_TYPES 3
// Event handlers
void on_frame(void *ctx, void *data) {
// Frame update logic here
}
void on_position(void *ctx, void *data) {
// Position update logic here
}
void on_collision(void *ctx, void *data) {
// Collision detection logic here
}
int main() {
evs_t evs;
ecs_t ecs = {0};
evs_init(&evs);
// Subscribe <event_id> to <func>
evs_subscribe(&evs, 1, on_frame);
evs_subscribe(&evs, 1, on_position);
evs_subscribe(&evs, 2, on_position);
evs_subscribe(&evs, 3, on_collision);
// Create entities
for (int i = 0; i < NUM_ENT; ++i) {
create_ent(&ecs);
}
// Start time for the test
time_t start = time(NULL);
size_t evt_count = 0;
// Main loop
while (difftime(time(NULL), start) < TEST_SEC) {
for (int i = 0; i < NUM_EVT_PER_ENT; ++i) {
for (int j = 0; j < EVT_TYPES; ++j) {
for (int k = 0; k < NUM_ENT; ++k) {
// Emit different events
ev_trigger(&evs, j + 1, &ecs, &ecs.data[0][k]);
evt_count++;
}
}
}
}
// End time for the test
time_t end = time(NULL);
// Performance metrics
double duration = difftime(end, start);
printf("Processed %zu events in %.2f seconds\n", evt_count, duration);
printf("Events per second: %.2f\n", evt_count / duration);
evs_destroy(&evs);
return 0;
}