Imagine in your
class NattyScene: SKScene {
you have perhaps a custom Field for the nodes, or something else that happens every frame. Now imagine you have some calculation, a nice example might be center of gravity ...
var globalCOG: CGPoint
func updateCOG() {
.. say, get all the .position of all Spaceship ..
globalCOG = .. some point
}
It would make great sense to put that on another thread, assuming issues like
- it's threadsafe / fast to read the .positions
- this other putative thread on another core, knows about SpriteKit frames (so that you can calculate until giveup time in the usual manner, etc, perhaps you may prefer to skip frame or whatever - the usual panoply of threaded game programming)
- you can threadsafe/blahblah write the COG global back to the rest of SpriteKit
What's the deal on this?
- What really is the modern idiom for this in Swift4 / SpriteKit
- How do you force it to go on another whole physical core?
Any ideas?
override func update(_ currentTime: TimeInterval) {
let x = safely get info from a thread on another physical core on the device
print("now that's cool")
}
on the other core ...
func loopy() {
let x = safely look at info on NattyScene
let globalCOG = calculation
}
Note, KOD has pointed to DispatchQueue
, which is great - but is there any way to ensure it's really on another core?