mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Fixed performance issue where entities could have multiple movement operations running at a time
This commit is contained in:
parent
a0435fb890
commit
8116cae7df
4 changed files with 17 additions and 24 deletions
|
|
@ -97,30 +97,22 @@ class CombatState(val bot: PestControlTestBot) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Functions
|
|
||||||
|
|
||||||
fun randomWalkTo(loc: Location, radius: Int) {
|
fun randomWalkTo(loc: Location, radius: Int) {
|
||||||
|
var newloc = loc.transform(RandomFunction.random(radius, -radius),
|
||||||
|
RandomFunction.random(radius, -radius), 0)
|
||||||
if(!bot.walkingQueue.isMoving) {
|
if(!bot.walkingQueue.isMoving) {
|
||||||
GlobalScope.launch {
|
walkToIterator(newloc)
|
||||||
var newloc = loc.transform(RandomFunction.random(radius, -radius),
|
|
||||||
RandomFunction.random(radius, -radius), 0)
|
|
||||||
walkToIterator(newloc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun walkToIterator(loc: Location){
|
private fun walkToIterator(loc: Location){
|
||||||
var diffX = loc.x - bot.location.x
|
var diffX = loc.x - bot.location.x
|
||||||
var diffY = loc.y - bot.location.y
|
var diffY = loc.y - bot.location.y
|
||||||
while(!bot.location.transform(diffX, diffY, 0).withinDistance(bot.location)) {
|
|
||||||
diffX /= 2
|
|
||||||
diffY /= 2
|
|
||||||
}
|
|
||||||
GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) {
|
GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) {
|
||||||
override fun pulse(): Boolean {
|
override fun pulse(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,30 +97,22 @@ class CombatStateIntermediate(val bot: PestControlTestBot2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
|
|
||||||
fun randomWalkTo(loc: Location, radius: Int) {
|
fun randomWalkTo(loc: Location, radius: Int) {
|
||||||
|
var newloc = loc.transform(RandomFunction.random(radius, -radius),
|
||||||
|
RandomFunction.random(radius, -radius), 0)
|
||||||
if(!bot.walkingQueue.isMoving) {
|
if(!bot.walkingQueue.isMoving) {
|
||||||
GlobalScope.launch {
|
walkToIterator(newloc)
|
||||||
Thread.currentThread().name = "RandomWalkToIteratorBot"
|
|
||||||
var newloc = loc.transform(RandomFunction.random(radius, -radius),
|
|
||||||
RandomFunction.random(radius, -radius), 0)
|
|
||||||
walkToIterator(newloc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun walkToIterator(loc: Location){
|
private fun walkToIterator(loc: Location){
|
||||||
var diffX = loc.x - bot.location.x
|
var diffX = loc.x - bot.location.x
|
||||||
var diffY = loc.y - bot.location.y
|
var diffY = loc.y - bot.location.y
|
||||||
while(!bot.location.transform(diffX, diffY, 0).withinDistance(bot.location)) {
|
|
||||||
diffX /= 2
|
|
||||||
diffY /= 2
|
|
||||||
}
|
|
||||||
GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) {
|
GameWorld.Pulser.submit(object : MovementPulse(bot, bot.location.transform(diffX, diffY, 0), Pathfinder.SMART) {
|
||||||
override fun pulse(): Boolean {
|
override fun pulse(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import core.game.node.entity.npc.NPC;
|
||||||
import core.game.node.entity.npc.NPCBehavior;
|
import core.game.node.entity.npc.NPCBehavior;
|
||||||
import core.game.node.entity.player.Player;
|
import core.game.node.entity.player.Player;
|
||||||
import core.game.system.task.Pulse;
|
import core.game.system.task.Pulse;
|
||||||
|
import core.game.world.GameWorld;
|
||||||
import core.game.world.map.Direction;
|
import core.game.world.map.Direction;
|
||||||
import core.game.world.map.Location;
|
import core.game.world.map.Location;
|
||||||
import core.game.world.map.Point;
|
import core.game.world.map.Point;
|
||||||
|
|
@ -191,6 +192,12 @@ public abstract class MovementPulse extends Pulse {
|
||||||
|
|
||||||
if (destination instanceof NPC || destination instanceof Player)
|
if (destination instanceof NPC || destination instanceof Player)
|
||||||
destinationFlag = DestinationFlag.ENTITY;
|
destinationFlag = DestinationFlag.ENTITY;
|
||||||
|
|
||||||
|
if (mover.currentMovement != null) {
|
||||||
|
mover.currentMovement.stop();
|
||||||
|
mover.getWalkingQueue().reset();
|
||||||
|
}
|
||||||
|
mover.currentMovement = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,8 @@ public abstract class Entity extends Node {
|
||||||
public ScriptProcessor scripts = new ScriptProcessor(this);
|
public ScriptProcessor scripts = new ScriptProcessor(this);
|
||||||
public final int[] clocks = new int[10];
|
public final int[] clocks = new int[10];
|
||||||
|
|
||||||
|
public MovementPulse currentMovement;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mapping of event types to event hooks
|
* The mapping of event types to event hooks
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue