-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_component.sh
More file actions
74 lines (56 loc) · 1.87 KB
/
Copy pathgen_component.sh
File metadata and controls
74 lines (56 loc) · 1.87 KB
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
#!/bin/sh
# Usage: ./gen_component.sh <component_name>
# Example: ./gen_component.sh collider
if [ $# -ne 1 ]; then
echo "Usage: $0 <component_name>"
exit 1
fi
COMPONENT_NAME="$1"
COMPONENT_NAME_UPPER=$(echo "$COMPONENT_NAME" | tr '[:lower:]' '[:upper:]')
COMPONENT_NAME_LOWER=$(echo "$COMPONENT_NAME" | tr '[:upper:]' '[:lower:]')
# Generate header file
cat > "include/${COMPONENT_NAME_LOWER}.h" << EOF
#ifndef ${COMPONENT_NAME_UPPER}_H
#define ${COMPONENT_NAME_UPPER}_H
#include <component.h>
#include <stdbool.h>
#define ${COMPONENT_NAME_UPPER}_PUBLIC_FIELDS(field) \\
field(${COMPONENT_NAME_LOWER}, bool, enabled)
decl_component(${COMPONENT_NAME_LOWER}, ${COMPONENT_NAME_UPPER}_PUBLIC_FIELDS);
#endif /* ${COMPONENT_NAME_UPPER}_H */
EOF
# Generate source file
cat > "${COMPONENT_NAME_LOWER}.c" << EOF
#include <${COMPONENT_NAME_LOWER}.h>
#include <entity.h>
#include <component.h>
#define ${COMPONENT_NAME_UPPER}_FIELDS(field) \\
${COMPONENT_NAME_UPPER}_PUBLIC_FIELDS(field)
static decl_component_storage(${COMPONENT_NAME_LOWER},
${COMPONENT_NAME_UPPER}_PUBLIC_FIELDS,
${COMPONENT_NAME_UPPER}_FIELDS)
static inline void ${COMPONENT_NAME_LOWER}_init_private(void) {}
static inline void ${COMPONENT_NAME_LOWER}_shutdown_private(void) {}
void ${COMPONENT_NAME_LOWER}_start(void) {}
static inline void ${COMPONENT_NAME_LOWER}_add_private(Entity ent, EntityIndex index)
{
(void)ent;
(void)index;
}
static inline void ${COMPONENT_NAME_LOWER}_rem_private(Entity ent, EntityIndex index)
{
(void)ent;
(void)index;
}
static inline bool
${COMPONENT_NAME_LOWER}_enabled_impl(EntityIndex id)
{
return ${COMPONENT_NAME_LOWER}_data.enabled[id];
}
static inline void
${COMPONENT_NAME_LOWER}_set_enabled_impl(EntityIndex id, bool enabled)
{
${COMPONENT_NAME_LOWER}_data.enabled[id] = enabled;
}
EOF
echo "Generated ${COMPONENT_NAME_LOWER}.h and ${COMPONENT_NAME_LOWER}.c"