Force pathfinding graph for empty chunks (#12856)
* Force pathfinding graph for empty chunks * im merging
This commit is contained in:
@@ -49,9 +49,18 @@ public sealed partial class PathfindingSystem
|
|||||||
SubscribeLocalEvent<GridPathfindingComponent, ComponentShutdown>(OnGridPathShutdown);
|
SubscribeLocalEvent<GridPathfindingComponent, ComponentShutdown>(OnGridPathShutdown);
|
||||||
SubscribeLocalEvent<CollisionChangeEvent>(OnCollisionChange);
|
SubscribeLocalEvent<CollisionChangeEvent>(OnCollisionChange);
|
||||||
SubscribeLocalEvent<PhysicsBodyTypeChangedEvent>(OnBodyTypeChange);
|
SubscribeLocalEvent<PhysicsBodyTypeChangedEvent>(OnBodyTypeChange);
|
||||||
|
SubscribeLocalEvent<TileChangedEvent>(OnTileChange);
|
||||||
SubscribeLocalEvent<MoveEvent>(OnMoveEvent);
|
SubscribeLocalEvent<MoveEvent>(OnMoveEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTileChange(TileChangedEvent ev)
|
||||||
|
{
|
||||||
|
if (ev.OldTile.IsEmpty == ev.NewTile.Tile.IsEmpty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DirtyChunk(ev.Entity, Comp<MapGridComponent>(ev.Entity).GridTileToLocal(ev.NewTile.GridIndices));
|
||||||
|
}
|
||||||
|
|
||||||
private void OnGridPathPause(EntityUid uid, GridPathfindingComponent component, ref EntityUnpausedEvent args)
|
private void OnGridPathPause(EntityUid uid, GridPathfindingComponent component, ref EntityUnpausedEvent args)
|
||||||
{
|
{
|
||||||
component.NextUpdate += args.PausedTime;
|
component.NextUpdate += args.PausedTime;
|
||||||
@@ -88,8 +97,10 @@ public sealed partial class PathfindingSystem
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We defer chunk updates because rebuilding a navmesh is hella costly
|
// We defer chunk updates because rebuilding a navmesh is hella costly
|
||||||
// If we're paused then NPCs can't run anyway.
|
// Still run even when paused.
|
||||||
foreach (var comp in EntityQuery<GridPathfindingComponent>())
|
var query = AllEntityQuery<GridPathfindingComponent>();
|
||||||
|
|
||||||
|
while (query.MoveNext(out var comp))
|
||||||
{
|
{
|
||||||
if (comp.DirtyChunks.Count == 0 ||
|
if (comp.DirtyChunks.Count == 0 ||
|
||||||
comp.NextUpdate < curTime ||
|
comp.NextUpdate < curTime ||
|
||||||
@@ -318,6 +329,17 @@ public sealed partial class PathfindingSystem
|
|||||||
private void OnGridInit(GridInitializeEvent ev)
|
private void OnGridInit(GridInitializeEvent ev)
|
||||||
{
|
{
|
||||||
EnsureComp<GridPathfindingComponent>(ev.EntityUid);
|
EnsureComp<GridPathfindingComponent>(ev.EntityUid);
|
||||||
|
|
||||||
|
// Pathfinder refactor
|
||||||
|
var mapGrid = Comp<MapGridComponent>(ev.EntityUid);
|
||||||
|
|
||||||
|
for (var x = Math.Floor(mapGrid.LocalAABB.Left); x <= Math.Ceiling(mapGrid.LocalAABB.Right + ChunkSize); x += ChunkSize)
|
||||||
|
{
|
||||||
|
for (var y = Math.Floor(mapGrid.LocalAABB.Bottom); y <= Math.Ceiling(mapGrid.LocalAABB.Top + ChunkSize); y += ChunkSize)
|
||||||
|
{
|
||||||
|
DirtyChunk(ev.EntityUid, mapGrid.GridTileToLocal(new Vector2i((int) x, (int) y)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGridRemoved(GridRemovalEvent ev)
|
private void OnGridRemoved(GridRemovalEvent ev)
|
||||||
|
|||||||
Reference in New Issue
Block a user