mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
* Broadphase refactor * Stuff * Working * TODO * Changes * Which fucking madman came up with this shit * Known gud state * Kinda shitcodey but it works so fuck it doin it live * Shuttle jankiness * Refactor entitylookups to be 30% more based * Refactor gucci * Done? * Fix most tests * nothing suss * Vera single-handedly saving shuttles * fex * Fix renderingtreecomp for relativity * Fix IEntityLookup * Fixes * Testing jank please revert some of it before merging * Fix the remaining bugs * Fix crash * Fix grid physics initialization * Shuttle collisions working * Fixes * Fixes * Velocity on transfers * Velocity on parent change * Fixes * world angular velocity too * Slightly faster map velocities * showbb revert * Sketch grids kinda workin * Fix PVS contact crash * Cleanup gridfixture updates 0.1% * Grid fixtures * AAAAAAAAAAAAAAA * a * termp * Fixes * Test reversion reversion? * Tests * Fix Equals * Slight box2i cleanup * Better initializer * Fix merge issues * Shuttles go BRRT * Remove MoveProxy from DynamicTreeBroadphase * Optimise a shit tonne * Approx * fix showbb * clean * Slightly more optimised * My almonds are activating * Contact transform caching * Avoid duplicates * Typo * Logger * Jitter 1% better * Okay shit maybe that's not it. * Contact fixes * Move check thingy up front * Revert some jank caching * Contact filtering * Fix master merge * Test fixes * Re-fix MapLoaderTest * Use proxies instead * uhh wtf? * Woops * Fix collisions * Fix grid fixture generation * Fix deserializing * Tile window fix * Cleanup broadphase * Bit more cleanup Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
/// <summary>
|
|
/// Handles moving entities between grids as they move around.
|
|
/// </summary>
|
|
internal sealed class SharedGridTraversalSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
private Queue<MoveEvent> _queuedEvents = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<MoveEvent>(ev => _queuedEvents.Enqueue(ev));
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
// Need to queue because otherwise calling HandleMove during FrameUpdate will lead to prediction isues.
|
|
while (_queuedEvents.TryDequeue(out var moveEvent))
|
|
{
|
|
HandleMove(moveEvent);
|
|
}
|
|
}
|
|
|
|
private void HandleMove(MoveEvent moveEvent)
|
|
{
|
|
var entity = moveEvent.Sender;
|
|
|
|
if (entity.Deleted ||
|
|
entity.HasComponent<IMapComponent>() ||
|
|
entity.HasComponent<IMapGridComponent>() ||
|
|
entity.IsInContainer())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var transform = entity.Transform;
|
|
|
|
if (float.IsNaN(moveEvent.NewPosition.X) || float.IsNaN(moveEvent.NewPosition.Y))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var mapPos = moveEvent.NewPosition.ToMapPos(EntityManager);
|
|
|
|
// Change parent if necessary
|
|
if (_mapManager.TryFindGridAt(transform.MapID, mapPos, out var grid) &&
|
|
EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt) &&
|
|
grid.GridEntityId != entity.Uid)
|
|
{
|
|
// Some minor duplication here with AttachParent but only happens when going on/off grid so not a big deal ATM.
|
|
if (grid.Index != transform.GridID)
|
|
{
|
|
transform.AttachParent(EntityManager.GetEntity(grid.GridEntityId));
|
|
RaiseLocalEvent(entity.Uid, new ChangedGridMessage(entity, transform.GridID, grid.Index));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var oldGridId = transform.GridID;
|
|
|
|
// Attach them to map / they are on an invalid grid
|
|
if (oldGridId != GridId.Invalid)
|
|
{
|
|
transform.AttachParent(_mapManager.GetMapEntity(transform.MapID));
|
|
RaiseLocalEvent(entity.Uid, new ChangedGridMessage(entity, oldGridId, GridId.Invalid));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public sealed class ChangedGridMessage : EntityEventArgs
|
|
{
|
|
public IEntity Entity;
|
|
public GridId OldGrid;
|
|
public GridId NewGrid;
|
|
|
|
public ChangedGridMessage(IEntity entity, GridId oldGrid, GridId newGrid)
|
|
{
|
|
Entity = entity;
|
|
OldGrid = oldGrid;
|
|
NewGrid = newGrid;
|
|
}
|
|
}
|
|
}
|