mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 00:38:14 +00:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user