Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.4 KiB

package wow.doge.mygame.utils.wrappers.jme
import cats.effect.Sync
import com.jme3.{bullet => jmeb}
import com.jme3.{scene => jmes}
import wow.doge.mygame.implicits._
final class PhysicsSpace[F[_]: Sync](space: jmeb.PhysicsSpace) {
def add(anyObject: Any) = Sync[F].delay(space.add(anyObject))
def remove(anyObject: Any) =
Sync[F].delay {
space.remove(anyObject)
space
}
def addAll(spatial: jmes.Spatial) = Sync[F].delay(space.addAll(spatial))
def removeAll(spatial: jmes.Spatial) =
Sync[F].delay {
space.removeAll(spatial)
space
}
def collisionObservable = space.collisionObservable()
def physicsTickObservable = space.physicsTickObservable()
}
object PhysicsSpace {
implicit final class PhysicsSpaceOps[F[_]](private val space: PhysicsSpace[F])
extends AnyVal {
def +=(anyObject: Any) = space.add(anyObject)
def :+(anyObject: Any) = {
space.add(anyObject)
space
}
def -(anyObject: Any) = {
space.remove(anyObject)
space
}
def -=(anyObject: Any) = space.remove(anyObject)
def +=(spatial: jmes.Spatial) = space.addAll(spatial)
def :+(spatial: jmes.Spatial) = {
space.addAll(spatial)
space
}
def -(spatial: jmes.Spatial) = {
space.removeAll(spatial)
space
}
def -=(spatial: jmes.Spatial) = space.removeAll(spatial)
}
}