Looks like it's going in a good direction -- good luck!
On Sat, Oct 8, 2016 at 6:24 PM, Steve Winfield <[email protected]
> wrote:
>
>
> Am Samstag, 8. Oktober 2016 22:09:46 UTC+2 schrieb Justin du coeur:
>>
>> (Although my first impression is that I'd probably use a repeated
>> schedule, and on each call decide whether to stop, rather than a lot of
>> scheduleOnce's.)
>>
> Players are not always moving and I guess (!!) that a repeated schedule
> uses something like an internal "scheduleOnce" as well. I tested it with
> 50k actors running concurrently and there weren't any latencies, so I
> suppose that it will be okay.
>
> I extended it btw (there is a "Space actor" now - It handles pathfinder
> stuff as well in order to avoid a racing condition..)
>
> class RoomCoordinator extends Actor {
> val mapState = Array.ofDim[TileState](0, 0)
>
> def getTileTowardsDestination(from: Vector2, to: Vector2): Option[Vector2]
> = None // Pathfinder.getNextStep(from, to, mapState)...
>
> def receive = {
> case GetTileTowardsDestination(from, to) =>
> sender ! getTileTowardsDestination(from, to)
> case BlockTileTowardsDestination(from, to) =>
> val tile = getTileTowardsDestination(from, to)
> // Block tile and send it back to the sender
> // mapState(tile.x)(tile.y) = TileState.Blocked
> sender ! tile
> case ClearTile(at) =>
> // Clear tile
> // mapState(at.x)(at.y) = TileState.Cleared
> }
> }
>
> object RoomCoordinator {
> case class GetTileTowardsDestination(from: Vector2, to: Vector2)
> case class BlockTileTowardsDestination(from: Vector2, to: Vector2)
> case class ClearTile(at: Vector2)
> }
>
> trait Walking { this: RoomEntity =>
> import context.dispatcher
>
> var walkDestination: Option[Vector2] = None
> var walking: Boolean = false
>
> def handleWalking: Receive = {
> case WalkTo(destination) if destination != position =>
> walkDestination = Some(destination)
>
> if (!walking) {
> implicit val timeout = Timeout(1 second)
> val nextStep = (coordinator ? BlockTileTowardsDestination(position,
> destination)).mapTo[Option[Vector2]]
>
> walking = true
>
> nextStep onComplete {
> case Success(result) if result.isDefined => self !
> WalkOver(result.get)
> case _ => self ! FinishWalk
> }
> }
>
> case WalkOver(pos) =>
> context.system.scheduler.scheduleOnce(RoomEntity.WalkingSpeed, self,
> WalkOn(pos))
>
> case WalkOn(newPos) =>
> coordinator ! ClearTile(position)
>
> position = newPos
> walking = false
>
> walkDestination match {
> case Some(destination) if destination != position => self !
> WalkTo(destination)
> case _ => self ! FinishWalk
> }
>
> case FinishWalk =>
> // Stop animation
> walkDestination = None
> walking = false
> }
> }
>
> object Walking {
> case class WalkTo(destination: Vector2)
> case class WalkOver(pos: Vector2)
> case class WalkOn(newPos: Vector2)
> case object FinishWalk
> }
>
>
> Cheers!
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.