@@ -147,6 +147,8 @@ private struct MainThreadFlags: RuleThreadFlags {
147
147
static var value : OGAttributeTypeFlags { . mainThread }
148
148
}
149
149
150
+ #if canImport(Darwin)
151
+
150
152
// MARK: - StaticBody
151
153
152
154
private struct StaticBody < Accessor: BodyAccessor , ThreadFlags: RuleThreadFlags > {
@@ -165,55 +167,43 @@ extension StaticBody: StatefulRule {
165
167
func updateValue( ) {
166
168
accessor. updateBody ( of: container, changed: true )
167
169
}
170
+
171
+ static var flags : OGAttributeTypeFlags { ThreadFlags . value }
168
172
}
169
173
170
- extension StaticBody : _AttributeBody {
171
- static var flags : OGAttributeTypeFlags {
172
- ThreadFlags . value
173
- }
174
- }
175
-
176
- #if canImport(Darwin)
177
-
178
174
extension StaticBody : BodyAccessorRule {
179
175
static var container : Any . Type {
180
176
Accessor . Container. self
181
177
}
182
178
183
- static func buffer< Value> ( as type: Value . Type , attribute: OGAttribute ) -> _DynamicPropertyBuffer ? {
184
- nil
185
- }
186
-
187
- static func value< Value> ( as type: Value . Type , attribute: OGAttribute ) -> Value ? {
188
- guard container == type else {
179
+ static func value< Value> ( as _: Value . Type , attribute: OGAttribute ) -> Value ? {
180
+ guard container == Value . self else {
189
181
return nil
190
182
}
191
- return ( attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. container as! Value )
183
+ return unsafeBitCast ( attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. container, to: Value . self)
184
+ }
185
+
186
+ static func buffer< Value> ( as _: Value . Type , attribute _: OGAttribute ) -> _DynamicPropertyBuffer ? {
187
+ nil
192
188
}
193
189
194
- static func metaProperties< Value> ( as type : Value . Type , attribute: OGAttribute ) -> [ ( String , OGAttribute ) ] {
195
- guard container == type else {
190
+ static func metaProperties< Value> ( as _ : Value . Type , attribute: OGAttribute ) -> [ ( String , OGAttribute ) ] {
191
+ guard container == Value . self else {
196
192
return [ ]
197
193
}
198
194
return [ ( " @self " , attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. _container. identifier) ]
199
195
}
200
196
}
201
-
202
- #endif
203
-
204
197
extension StaticBody : CustomStringConvertible {
205
198
var description : String { " \( Accessor . Body. self) " }
206
199
}
207
200
208
201
// MARK: - DynamicBody
209
202
210
- // TODO
211
203
private struct DynamicBody < Accessor: BodyAccessor , ThreadFlags: RuleThreadFlags > {
212
204
let accessor : Accessor
213
- @Attribute
214
- var container : Accessor . Container
215
- @Attribute
216
- var phase : _GraphInputs . Phase
205
+ @Attribute var container : Accessor . Container
206
+ @Attribute var phase : _GraphInputs . Phase
217
207
var links : _DynamicPropertyBuffer
218
208
var resetSeed : UInt32
219
209
@@ -224,19 +214,69 @@ private struct DynamicBody<Accessor: BodyAccessor, ThreadFlags: RuleThreadFlags>
224
214
links: _DynamicPropertyBuffer ,
225
215
resetSeed: UInt32
226
216
) {
227
- fatalError ( " TODO " )
228
- // self.accessor = accessor
229
- // self._container = container
230
- // self._phase = phase
231
- // self.links = links
232
- // self.resetSeed = resetSeed
217
+ self . accessor = accessor
218
+ self . _container = container
219
+ self . _phase = phase
220
+ self . links = links
221
+ self . resetSeed = resetSeed
233
222
}
234
223
}
235
224
236
225
extension DynamicBody : StatefulRule {
237
226
typealias Value = Accessor . Body
238
227
239
- func updateValue( ) {
240
- // TODO
228
+ mutating func updateValue( ) {
229
+ if resetSeed != phase. seed {
230
+ links. reset ( )
231
+ resetSeed = phase. seed
232
+ }
233
+ var ( container, containerChanged) = $container. changedValue ( )
234
+ let linkChanged = withUnsafeMutablePointer ( to: & container) {
235
+ links. update ( container: $0, phase: phase)
236
+ }
237
+ let changed = linkChanged || containerChanged || !hasValue
238
+ accessor. updateBody ( of: container, changed: changed)
239
+ }
240
+
241
+ static var flags : OGAttributeTypeFlags { ThreadFlags . value }
242
+ }
243
+
244
+ extension DynamicBody : ObservedAttribute {
245
+ func destroy( ) { links. destroy ( ) }
246
+ }
247
+
248
+ extension DynamicBody : BodyAccessorRule {
249
+ static var container : Any . Type {
250
+ Accessor . Container. self
251
+ }
252
+
253
+ static func value< Value> ( as _: Value . Type , attribute: OGAttribute ) -> Value ? {
254
+ guard container == Value . self else {
255
+ return nil
256
+ }
257
+ return unsafeBitCast ( attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. container, to: Value . self)
258
+ }
259
+
260
+ static func buffer< Value> ( as _: Value . Type , attribute: OGAttribute ) -> _DynamicPropertyBuffer ? {
261
+ guard container == Value . self else {
262
+ return nil
263
+ }
264
+ return attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. links
265
+ }
266
+
267
+ static func metaProperties< Value> ( as _: Value . Type , attribute: OGAttribute ) -> [ ( String , OGAttribute ) ] {
268
+ guard container == Value . self else {
269
+ return [ ]
270
+ }
271
+ return [
272
+ ( " @self " , attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. _container. identifier) ,
273
+ ( " @identity " , attribute. info. body. assumingMemoryBound ( to: Self . self) . pointee. _phase. identifier)
274
+ ]
241
275
}
242
276
}
277
+
278
+ extension DynamicBody : CustomStringConvertible {
279
+ var description : String { " \( Accessor . Body. self) " }
280
+ }
281
+
282
+ #endif
0 commit comments