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
@@ -1,3 +1,4 @@
import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncAction
import org.apollo.game.message.impl.ItemOptionMessage
import org.apollo.game.model.Animation
@@ -27,7 +28,7 @@ class ConsumeAction(val consumable: Consumable, player: Player, val slot: Int) :
}
}
suspend override fun executeActionAsync() {
override fun action(): ActionBlock = {
consumable.consume(mob, slot)
mob.playAnimation(Animation(CONSUME_ANIMATION_ID))
wait(consumable.delay)