From 4e858f743052c9fde909e09f7e569bf9a441419b Mon Sep 17 00:00:00 2001 From: ceikry Date: Fri, 30 Jul 2021 11:06:30 -0500 Subject: [PATCH] More stability improvements --- .../game/ai/minigamebots/pestcontrol/CombatState.kt | 4 +++- .../pestcontrol/CombatStateIntermediate.kt | 4 +++- .../kotlin/rs09/game/world/update/UpdateSequence.kt | 11 +++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatState.kt b/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatState.kt index 0adf3c315..a56fc69f0 100644 --- a/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatState.kt +++ b/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatState.kt @@ -7,6 +7,8 @@ import core.game.world.map.Location import core.game.world.map.RegionManager import core.game.world.map.path.Pathfinder import core.tools.RandomFunction +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import rs09.game.content.activity.pestcontrol.PestControlHelper.GATE_ENTRIES import rs09.game.content.activity.pestcontrol.PestControlHelper.getMyPestControlSession1 import rs09.game.world.GameWorld @@ -100,7 +102,7 @@ class CombatState(val bot: PestControlTestBot) { fun randomWalkTo(loc: Location, radius: Int) { if(!bot.walkingQueue.isMoving) { - Executors.newSingleThreadExecutor().execute { + GlobalScope.launch { var newloc = loc.transform(RandomFunction.random(radius, -radius), RandomFunction.random(radius, -radius), 0) walkToIterator(newloc) diff --git a/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatStateIntermediate.kt b/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatStateIntermediate.kt index 509090075..70243a700 100644 --- a/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatStateIntermediate.kt +++ b/Server/src/main/kotlin/rs09/game/ai/minigamebots/pestcontrol/CombatStateIntermediate.kt @@ -7,6 +7,8 @@ import core.game.world.map.Location import core.game.world.map.RegionManager import core.game.world.map.path.Pathfinder import core.tools.RandomFunction +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import rs09.game.content.activity.pestcontrol.PestControlHelper.GATE_ENTRIES import rs09.game.content.activity.pestcontrol.PestControlHelper.getMyPestControlSession2 import rs09.game.world.GameWorld @@ -99,7 +101,7 @@ class CombatStateIntermediate(val bot: PestControlTestBot2) { fun randomWalkTo(loc: Location, radius: Int) { if(!bot.walkingQueue.isMoving) { - Executors.newSingleThreadExecutor().execute { + GlobalScope.launch { Thread.currentThread().name = "RandomWalkToIteratorBot" var newloc = loc.transform(RandomFunction.random(radius, -radius), RandomFunction.random(radius, -radius), 0) diff --git a/Server/src/main/kotlin/rs09/game/world/update/UpdateSequence.kt b/Server/src/main/kotlin/rs09/game/world/update/UpdateSequence.kt index 5d13af290..4a16fef80 100644 --- a/Server/src/main/kotlin/rs09/game/world/update/UpdateSequence.kt +++ b/Server/src/main/kotlin/rs09/game/world/update/UpdateSequence.kt @@ -8,6 +8,8 @@ import core.game.world.repository.InitializingNodeList import core.net.packet.PacketRepository import core.net.packet.context.PlayerContext import core.net.packet.out.ClearMinimapFlag +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import rs09.game.world.repository.Repository import java.util.concurrent.CountDownLatch import java.util.concurrent.Executors @@ -58,7 +60,7 @@ class UpdateSequence fun run() { val latch = CountDownLatch(renderablePlayers.size) playersList!!.forEach(Consumer { player: Player -> - EXECUTOR.execute { + GlobalScope.launch { try { player.update() } catch (t: Throwable) { @@ -89,7 +91,6 @@ class UpdateSequence * Terminates the update sequence. */ fun terminate() { - EXECUTOR.shutdown() } companion object { @@ -103,11 +104,5 @@ class UpdateSequence @JvmStatic val renderablePlayers = InitializingNodeList() - /** - * The executor used. - */ - @JvmStatic - private val EXECUTOR = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) - } } \ No newline at end of file