コード例 #1
0
    public override void Update(float frameTime)
    {
        _accumulator += frameTime;

        if (_accumulator < Frequency)
        {
            return;
        }

        _accumulator -= Frequency;

        foreach (var(component, xform) in EntityManager.EntityQuery <RadarConsoleComponent, TransformComponent>())
        {
            var s = component.Owner.GetUIOrNull(RadarConsoleUiKey.Key);

            if (s is null)
            {
                continue;
            }

            var(radarPos, _, radarInvMatrix) = xform.GetWorldPositionRotationInvMatrix();

            var mapId   = xform.MapID;
            var objects = new List <RadarObjectData>();

            _mapManager.FindGridsIntersectingEnumerator(mapId, new Box2(radarPos - component.Range, radarPos + component.Range), out var enumerator, true);

            while (enumerator.MoveNext(out var grid))
            {
                var phy       = Comp <PhysicsComponent>(grid.GridEntityId);
                var transform = Transform(grid.GridEntityId);

                if (phy.Mass < 50)
                {
                    continue;
                }

                var rad        = Math.Log2(phy.Mass);
                var gridCenter = transform.WorldMatrix.Transform(phy.LocalCenter);

                var pos = radarInvMatrix.Transform(gridCenter);
                pos.Y = -pos.Y; // Robust has an inverted Y, like BYOND. This undoes that.

                if (pos.Length > component.Range)
                {
                    continue;
                }

                objects.Add(new RadarObjectData {
                    Color = Color.Aqua, Position = pos, Radius = (float)rad
                });
            }

            s.SetState(new RadarConsoleBoundInterfaceState(component.Range, objects.ToArray()));
        }
    }
コード例 #2
0
        private DockingComponent?GetDockable(PhysicsComponent body, TransformComponent dockingXform)
        {
            // Did you know Saltern is the most dockable station?

            // Assume the docking port itself (and its body) is valid

            if (!_mapManager.TryGetGrid(dockingXform.GridUid, out var grid) ||
                !HasComp <ShuttleComponent>(grid.GridEntityId))
            {
                return(null);
            }

            var transform      = body.GetTransform();
            var dockingFixture = _fixtureSystem.GetFixtureOrNull(body, DockingFixture);

            if (dockingFixture == null)
            {
                return(null);
            }

            Box2?aabb = null;

            for (var i = 0; i < dockingFixture.Shape.ChildCount; i++)
            {
                aabb = aabb?.Union(dockingFixture.Shape.ComputeAABB(transform, i)) ?? dockingFixture.Shape.ComputeAABB(transform, i);
            }

            if (aabb == null)
            {
                return(null);
            }

            var enlargedAABB = aabb.Value.Enlarged(DockingRadius * 1.5f);

            // Get any docking ports in range on other grids.
            _mapManager.FindGridsIntersectingEnumerator(dockingXform.MapID, enlargedAABB, out var enumerator);

            while (enumerator.MoveNext(out var otherGrid))
            {
                if (otherGrid.GridEntityId == dockingXform.GridUid)
                {
                    continue;
                }

                foreach (var ent in otherGrid.GetAnchoredEntities(enlargedAABB))
                {
                    if (!TryComp(ent, out DockingComponent? otherDocking) ||
                        !otherDocking.Enabled ||
                        !TryComp(ent, out PhysicsComponent? otherBody))
                    {
                        continue;
                    }

                    var otherTransform      = otherBody.GetTransform();
                    var otherDockingFixture = _fixtureSystem.GetFixtureOrNull(otherBody, DockingFixture);

                    if (otherDockingFixture == null)
                    {
                        DebugTools.Assert(false);
                        _sawmill.Error($"Found null docking fixture on {ent}");
                        continue;
                    }

                    for (var i = 0; i < otherDockingFixture.Shape.ChildCount; i++)
                    {
                        var otherAABB = otherDockingFixture.Shape.ComputeAABB(otherTransform, i);

                        if (!aabb.Value.Intersects(otherAABB))
                        {
                            continue;
                        }

                        // TODO: Need CollisionManager's GJK for accurate bounds
                        // Realistically I want 2 fixtures anyway but I'll deal with that later.
                        return(otherDocking);
                    }
                }
            }

            return(null);
        }