Refactor asynchronous actions to avoid thread usage

Adds custom coroutines specifically for use within Actions.  This
implements all features of the previous system, however, does not rely
on a separate executor to wake up continuations.

Note: since Actions are still ran by an executor and a small chance of
overlap exists the ActionCoroutine implementation uses atomic counters
and references.
This commit is contained in:
Gary Tierney
2017-09-19 01:52:10 +01:00
parent 169d89ffc0
commit 76dd8ba192
9 changed files with 220 additions and 122 deletions
+3 -4
View File
@@ -1,6 +1,7 @@
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.selects.select
import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncDistancedAction
import org.apollo.game.action.DistancedAction
import org.apollo.game.message.impl.ObjectActionMessage
@@ -53,9 +54,9 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction
}
override suspend fun executeActionAsync() {
override fun action(): ActionBlock = {
mob.sendMessage("You hit the dummy.")
mob.turnTo(this.position)
mob.turnTo(position)
mob.playAnimation(PUNCH_ANIMATION)
wait()
@@ -66,8 +67,6 @@ class DummyAction(val player: Player, position: Position) : AsyncDistancedAction
} else {
skills.addExperience(Skill.ATTACK, EXP_PER_HIT)
}
stop()
}
}