mirror of
https://github.com/bdnugget/rs-sdk.git
synced 2026-11-07 09:07:30 +00:00
perf(lite): skip BFS scratch-map fills when target is already in reach
route() cleared two BuildArea-sized dir/dist maps before discovering, on the first queue element, that the actor already stands in reach of the target. Run the same wall/decor/loc reach checks up front and return "already reachable" without any fill or MOVE_OPCLICK packet, matching the existing length<=0 no-packet behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2fa65b8342
commit
ca88d2142d
2 files changed
+43
No files matched your search
@@ -27,6 +27,7 @@ import WordPack from '#/wordfilter/WordPack.js';
|
||||
|
||||
import { loadCache } from './cache.js';
|
||||
import { LiteClient } from './LiteClient.js';
|
||||
import { tryMoveTo } from './movement.js';
|
||||
import { dispatch } from './protocol/incoming.js';
|
||||
|
||||
const ORIGIN = process.env.LITE_TEST_ORIGIN ?? 'https://rs-sdk-demo.fly.dev';
|
||||
@@ -276,4 +277,20 @@ describe('outgoing action encoding', () => {
|
||||
expect(r.g2()).toBe(3250);
|
||||
expect(r.at).toBe(c.out.pos);
|
||||
});
|
||||
|
||||
test('an actor already inside an NPC footprint needs no movement packet', () => {
|
||||
if (!available) {
|
||||
return;
|
||||
}
|
||||
|
||||
const c = makeClient('bota');
|
||||
c.collision[0] = new CollisionMap();
|
||||
c.localPlayer!.routeX[0] = 50;
|
||||
c.localPlayer!.routeZ[0] = 50;
|
||||
|
||||
const start = c.out.pos;
|
||||
// A size-five NPC rooted at 48,48 contains the actor at 50,50.
|
||||
expect(tryMoveTo(c, 48, 48, 5, 5, 0, 0, 0)).toBe(true);
|
||||
expect(c.out.pos).toBe(start);
|
||||
});
|
||||
});
|
||||
@@ -66,6 +66,32 @@ function route(
|
||||
const srcX = c.localPlayer.routeX[0];
|
||||
const srcZ = c.localPlayer.routeZ[0];
|
||||
|
||||
// The normal BFS performs these exact reach checks on its first queue
|
||||
// element, after clearing two full BuildArea-sized scratch maps. Hot
|
||||
// interactions such as the KBD spawn attack are deliberately staged
|
||||
// inside the target footprint, so return the identical "already in
|
||||
// reach" result before those O(scene) fills. As in the existing
|
||||
// length<=0 branch below, no MOVE_OPCLICK packet is required here; the
|
||||
// caller immediately emits the interaction op.
|
||||
if (srcX === dx && srcZ === dz) {
|
||||
return true;
|
||||
}
|
||||
if (locShape !== LocShape.WALL_STRAIGHT) {
|
||||
if ((locShape < LocShape.WALLDECOR_STRAIGHT_OFFSET
|
||||
|| locShape === LocShape.CENTREPIECE_STRAIGHT)
|
||||
&& collisionMap.testWall(srcX, srcZ, dx, dz, locShape - 1, locAngle)) {
|
||||
return true;
|
||||
}
|
||||
if (locShape < LocShape.CENTREPIECE_STRAIGHT
|
||||
&& collisionMap.testWDecor(srcX, srcZ, dx, dz, locShape - 1, locAngle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (locWidth !== 0 && locLength !== 0
|
||||
&& collisionMap.testLoc(srcX, srcZ, dx, dz, locWidth, locLength, forceapproach)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
dirMap.fill(0);
|
||||
distMap.fill(99999999);
|
||||
|
||||
|
||||
Reference in new issue
Block a user