-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrockets_nodes.h
111 lines (86 loc) · 2.08 KB
/
rockets_nodes.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
108
109
110
111
#ifndef _rockets_nodes_h
#define _rockets_nodes_h
typedef enum { SENSOR=0, CONSTANT=1, PREDICATE=2, GATE=3, THRUSTER=4 } NodeType;
char* nodetype_names[] = {
"SENSOR",
"CONSTANT",
"PREDICATE",
"GATE",
"THRUSTER",
};
struct node;
typedef struct {
Direction sensor_direction;
// I think sensor nodes are going to be entity specific.
int entity_id;
} SensorNode;
typedef struct {
int value;
} ConstantNode;
typedef enum { EQ=0, NEQ=1, LT=2, GT=3, LEQ=4, GEQ=5 } Predicate;
char* predicate_names[] = {
"==",
"<>",
"<",
">",
"<=",
">="
};
typedef struct {
Predicate predicate;
struct node* lhs;
struct node* rhs;
} PredicateNode;
typedef enum { AND=0, OR=1, NOT=2 } Gate;
char* gate_names[] = {
"AND",
"OR",
"NOT"
};
typedef struct {
Gate gate;
struct node* lhs;
struct node* rhs;
} GateNode;
typedef enum {
BP = (1 << 0), // 1
BS = (1 << 1), // 2
SP = (1 << 2), // 4
SS = (1 << 3), // 8
BOOST = (1 << 4), // 16
} Thruster;
typedef struct {
Thruster thruster;
struct node* input;
} ThrusterNode;
#define NAH -1
typedef struct node {
int id;
NodeType type;
V2 position;
// @NOTE: Using a union for this makes the memory management really easy with 1 freelist.
union {
SensorNode sensor;
ConstantNode constant;
PredicateNode predicate;
GateNode gate;
ThrusterNode thruster;
};
int current_value; // yo if this is -1 then NAHHHHH
struct node* next_in_hash;
// Keep track of number of nodes that depend on this to make topological iteration easier.
int num_dependencies;
struct node* next_in_q;
} Node;
// @NOTE: I'm not sure I really need the id or the hash.
typedef struct {
int last_used_id;
int node_buffer_size;
Node* node_buffer_base;
int node_buffer_used;
Node* first_free_node;
// @NOTE: Must be power of 2 for bad hash function.
Node* id_hash[128];
// @TODO: Add another index for the topological sort. Makes evaluation faster.
} NodeStore;
#endif