package wow.doge.mygame.game import com.jme3.app.SimpleApplication import com.jme3.app.state.AppState import com.jme3.bullet.BulletAppState import com.jme3.bullet.collision.shapes.CapsuleCollisionShape import com.jme3.bullet.control.CharacterControl import com.jme3.bullet.control.RigidBodyControl import com.jme3.bullet.util.CollisionShapeFactory import com.jme3.scene.Spatial import com.jme3.syntax._ import com.jme3.asset.plugins.ZipLocator import com.jme3.math.ColorRGBA import wow.doge.mygame.implicits._ class GameApp( // actorSystem: ActorSystem[SpawnProtocol.Command], appStates: AppState* ) extends SimpleApplication(appStates: _*) { // implicit val timeout = Timeout(10.seconds) // implicit val scheduler = actorSystem.scheduler private lazy val sceneModel: Spatial = assetManager.loadModel("main.scene") private lazy val bulletAppState: BulletAppState = new BulletAppState() // bulletAppState.setThreadingType(ThreadingType.SEQUENTIAL) // We set up collision detection for the scene by creating a // compound collision shape and a static RigidBodyControl with mass zero. private lazy val sceneShape = CollisionShapeFactory.createMeshShape( sceneModel.toNode match { case util.Right(node) => node case util.Left(ex) => throw new NotImplementedError("No fallback sceneshape") } ) private lazy val landscape: RigidBodyControl = new RigidBodyControl(sceneShape, 0) // We set up collision detection for the player by creating // a capsule collision shape and a CharacterControl. // The CharacterControl offers extra settings for // size, stepheight, jumping, falling, and gravity. // We also put the player in its starting position. protected lazy val capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1) private lazy val player: CharacterControl = new CharacterControl(capsuleShape, 0.05f) override def simpleInitApp(): Unit = { discard { stateManager.attach(bulletAppState) } assetManager.registerLocator( // "src/main/resources/assets/town.zip", (os.rel / "src" / "main" / "resources" / "assets" / "town.zip"), classOf[ZipLocator] ) viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f)) sceneModel.setLocalScale(2f) sceneModel.addControl(landscape) discard { rootNode.attachChild(sceneModel) } bulletAppState.getPhysicsSpace.add(landscape) bulletAppState.getPhysicsSpace.add(player) println("gameapp" + Thread.currentThread().getName()) // val ship = ed.createEntity() // val mbState = stateManager().state[EntityDataState]().map(_.getEntityData()) // val mbState = Try( // stateManager() // .state[TestAppState]() // .entity // ).toOption.flatten.toRight(println("empty")) // // .flatMap(_.entity) // val x = mbState.flatMap( // _.query // .filter[TestComponent]("name", new Object()) // // .filterOr[TestEntity]( // // Filters // // .fieldEquals(classOf[TestEntity], "", null) // // ) // .component[Tag]() // .component[TestComponent]() // .result // .toRight(println("failed")) // ) // rootNode // .child(geom) // .child(geom) // .child(geom) // .child(geom) // .child(geom) // .child(geom) // .child(geom) // .child(geom) // Future(println("hello"))(jmeEC(this)) // val wbActor: Future[ActorRef[Greeter.Greet]] = actorSystem.ask( // SpawnProtocol.Spawn( // behavior = Greeter(), // name = "listener", // DispatcherSelector.fromConfig("jme-dispatcher"), // _ // ) // ) // wbActor.map(a => a.ask(Greeter.Greet("hello", _)).map(println)) } override def simpleUpdate(tpf: Float): Unit = { // val rot2 = rot.fromAngleAxis(FastMath.PI, new Vector3f(0, 0, 1)) // val rotation = geom.getLocalRotation() // rotation.add(rot2) // geom.rotate(rot2) // geom.updateModelBound() // geom.updateGeometricState() } // override def stop(): Unit = { // actorSystem.terminate() // super.stop() // } // override def start(): Unit = { // monix.eval.Task(super.start()).runToFuture(Scheduler(JMEExecutorService)) // } // def start(system: ActorRef[RootActor.Command]) = { // // system ! RootActor.Start // super.start() // } // override def stop(): Unit = { // println("stopping") // } def stop[T](cb: () => T): Unit = { println("destroy") cb() super.stop() } // override def stop(): Unit = {} }