|
1 | 1 | package com.github.elebras1.flecs; |
2 | 2 |
|
| 3 | +import com.github.elebras1.flecs.util.FlecsConstants; |
| 4 | + |
3 | 5 | import java.lang.foreign.Arena; |
4 | 6 | import java.lang.foreign.MemorySegment; |
5 | 7 | import java.lang.foreign.ValueLayout; |
@@ -101,47 +103,98 @@ public ObserverBuilder with(long relationId, long objectId) { |
101 | 103 | return this; |
102 | 104 | } |
103 | 105 |
|
104 | | - public ObserverBuilder without(long componentId) { |
105 | | - this.with(componentId); |
106 | | - |
| 106 | + public ObserverBuilder in() { |
107 | 107 | if (this.termCount == 0) { |
108 | | - throw new IllegalStateException("No term to apply 'without' modifier to"); |
| 108 | + throw new IllegalStateException("No term to apply 'in' modifier to"); |
109 | 109 | } |
110 | 110 |
|
111 | | - MemorySegment queryDesc = ecs_observer_desc_t.query(this.desc); |
| 111 | + MemorySegment queryDesc = ecs_system_desc_t.query(this.desc); |
112 | 112 | long termsOffset = ecs_query_desc_t.terms$offset(); |
113 | 113 | long termOffset = termsOffset + ((this.termCount - 1) * TERM_SIZE); |
114 | 114 |
|
115 | 115 | MemorySegment term = queryDesc.asSlice(termOffset, TERM_SIZE); |
116 | | - long operOffset = ecs_term_t.oper$offset(); |
| 116 | + long inoutOffset = ecs_term_t.inout$offset(); |
117 | 117 |
|
118 | | - term.set(ValueLayout.JAVA_SHORT, operOffset, (short) EcsNot); |
| 118 | + term.set(ValueLayout.JAVA_INT, inoutOffset, EcsIn); |
119 | 119 |
|
120 | 120 | return this; |
121 | 121 | } |
122 | 122 |
|
123 | | - public <T> ObserverBuilder without(Class<T> componentClass) { |
124 | | - long componentId = this.world.componentRegistry().getComponentId(componentClass); |
125 | | - return this.without(componentId); |
| 123 | + public ObserverBuilder out() { |
| 124 | + if (this.termCount == 0) { |
| 125 | + throw new IllegalStateException("No term to apply 'out' modifier to"); |
| 126 | + } |
| 127 | + |
| 128 | + MemorySegment queryDesc = ecs_system_desc_t.query(this.desc); |
| 129 | + long termsOffset = ecs_query_desc_t.terms$offset(); |
| 130 | + long termOffset = termsOffset + ((this.termCount - 1) * TERM_SIZE); |
| 131 | + |
| 132 | + MemorySegment term = queryDesc.asSlice(termOffset, TERM_SIZE); |
| 133 | + long inoutOffset = ecs_term_t.inout$offset(); |
| 134 | + |
| 135 | + term.set(ValueLayout.JAVA_INT, inoutOffset, EcsOut); |
| 136 | + |
| 137 | + return this; |
126 | 138 | } |
127 | 139 |
|
128 | | - public ObserverBuilder filter() { |
| 140 | + public ObserverBuilder inOut() { |
129 | 141 | if (this.termCount == 0) { |
130 | | - throw new IllegalStateException("No term to apply 'filter' modifier to"); |
| 142 | + throw new IllegalStateException("No term to apply 'inout' modifier to"); |
131 | 143 | } |
132 | 144 |
|
133 | | - MemorySegment queryDesc = ecs_observer_desc_t.query(this.desc); |
| 145 | + MemorySegment queryDesc = ecs_system_desc_t.query(this.desc); |
134 | 146 | long termsOffset = ecs_query_desc_t.terms$offset(); |
135 | 147 | long termOffset = termsOffset + ((this.termCount - 1) * TERM_SIZE); |
136 | 148 |
|
137 | 149 | MemorySegment term = queryDesc.asSlice(termOffset, TERM_SIZE); |
138 | 150 | long inoutOffset = ecs_term_t.inout$offset(); |
139 | 151 |
|
140 | | - term.set(ValueLayout.JAVA_SHORT, inoutOffset, (short) EcsIn); |
| 152 | + term.set(ValueLayout.JAVA_INT, inoutOffset, EcsInOut); |
| 153 | + |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + public ObserverBuilder operator(int operator) { |
| 158 | + if (this.termCount == 0) { |
| 159 | + throw new IllegalStateException("No term to apply 'operator' modifier to"); |
| 160 | + } |
| 161 | + |
| 162 | + long termsOffset = ecs_query_desc_t.terms$offset(); |
| 163 | + long termOffset = termsOffset + ((this.termCount - 1) * TERM_SIZE); |
141 | 164 |
|
| 165 | + MemorySegment term = this.desc.asSlice(termOffset, TERM_SIZE); |
| 166 | + ecs_term_t.oper(term, (short) operator); |
142 | 167 | return this; |
143 | 168 | } |
144 | 169 |
|
| 170 | + public ObserverBuilder and() { |
| 171 | + return this.operator(FlecsConstants.EcsAnd); |
| 172 | + } |
| 173 | + |
| 174 | + public ObserverBuilder or() { |
| 175 | + return this.operator(FlecsConstants.EcsOr); |
| 176 | + } |
| 177 | + |
| 178 | + public ObserverBuilder not() { |
| 179 | + return this.operator(FlecsConstants.EcsNot); |
| 180 | + } |
| 181 | + |
| 182 | + public ObserverBuilder optional() { |
| 183 | + return this.operator(FlecsConstants.EcsOptional); |
| 184 | + } |
| 185 | + |
| 186 | + public ObserverBuilder andFrom() { |
| 187 | + return this.operator(FlecsConstants.EcsAndFrom); |
| 188 | + } |
| 189 | + |
| 190 | + public ObserverBuilder orFrom() { |
| 191 | + return this.operator(FlecsConstants.EcsOrFrom); |
| 192 | + } |
| 193 | + |
| 194 | + public ObserverBuilder notFrom() { |
| 195 | + return this.operator(FlecsConstants.EcsNotFrom); |
| 196 | + } |
| 197 | + |
145 | 198 | public ObserverBuilder yieldExisting() { |
146 | 199 | ecs_observer_desc_t.yield_existing(this.desc, true); |
147 | 200 | return this; |
|
0 commit comments