-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs.test.h
107 lines (87 loc) · 3.89 KB
/
ecs.test.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by bear on 2021-04-02.
//
#ifndef ECS_TEST
#define ECS_TEST
#include "ecs.h"
void print_map(world *w) {
HASHMAP_FOR_EACH(w->map, kv) {
printf("[%s,%d]\n\n", (char *) kv->key, kv->value);
}
printf("====\n");
}
void length_height_position_function(archetype_column ** columns){
printf("------length_height_position_function------\n");
for(int count = (* columns)->element_length,i=0;i<count;i++){
int * length = (int *)VECTOR_AT((*(columns+0)),i);
int * height = (int *)VECTOR_AT((*(columns+1)),i);
A * position = (A *)VECTOR_AT((*(columns+1)),i);
printf("[%d] length=%d, height=%d, position.x=%d ,position.y=%d\n",
i, *length,*height,position->x,position->y);
}
printf("------------\n");
}
void length_function(archetype_column ** columns){
printf("------length_function------\n");
for(int count = (* columns)->element_length,i=0;i<count;i++){
int * length = (int *)VECTOR_AT((*(columns+0)),i);
printf("[%d] length=%d, height=%d, position.x=%d ,position.y=%d\n",
i, *length);
}
printf("------------\n");
}
void length_height_function(archetype_column ** columns){
printf("------length_height_function------\n");
for(int count = (* columns)->element_length,i=0;i<count;i++){
int * length = (int *)VECTOR_AT((*(columns+0)),i);
int * height = (int *)VECTOR_AT((*(columns+1)),i);
printf("[%d] length=%d, height=%d, position.x=%d ,position.y=%d\n",
i, *length,*height);
}
printf("------------\n");
}
void ecs_test() {
world *w = ecs_world_new();
ecs_component_register(w, "length", sizeof(int));
print_map(w);
ecs_component_register(w, "length", sizeof(int));
print_map(w);
ecs_component_register(w, "height", sizeof(int));
print_map(w);
ecs_component_register(w, "position", sizeof(A));
print_map(w);
assert(w->component_types->element_length == 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "height", "position"}, 3);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "position"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"length", "height"}, 2);
ecs_entity_new(w, (char *[]) {"position"}, 1);
ecs_entity_new(w, (char *[]) {"position"}, 1);
ecs_entity_new(w, (char *[]) {"position"}, 1);
ecs_entity_new(w, (char *[]) {"position"}, 1);
ecs_entity_new(w, (char *[]) {"position"}, 1);
ecs_entity_new(w, (char *[]) {"position"}, 1);
assert(w->archetypes->element_length == 4);
ecs_system_register(w, 0, length_function, (char *[]){"length"}, 1);
ecs_system_register(w, 1, length_height_function, (char *[]){"length", "height"}, 2);
ecs_system_register(w, 2, length_height_position_function, (char *[]) {"length", "height", "position"}, 3);
assert(w->system_types->element_length == 3);
ecs_run(w);
}
#endif