mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add grid tile to Vector2 methods (#4851)
* Add grid tile to Vector2 methods Avoids me having to do it on content. * Release note * Engine * Collapsible * Add entitylookup methods for parent / map Content's done it a bunch so make it reusable. * Add MaxDimension property to Box2 Sometimes I want to pretend it's a circle radius. * Add GetLocalPosition to controls In my case I want the mouse's position inside of the control to show something under it unless there's a better way. * Add global rectangles for controls Like my other PR used to check if mouse is inbounds on the control without doing some skrunkly caching with mousemove. * Add dotted line drawing to screen handle Probably needs anti-aliasing but idk an easy way to do it. * weh * weh * a * weh * weh * Optimise ChunkEnumerator It never unioned the AABB passed in with the grid's AABB so it might inadvertantly iterate a lot more dummy chunks than it needs to. This helps speedup FindGridsIntersecting. * weh * Add DrawPrimitives overload for List<Vector2> Storing ValueList in a field seems sussy so this is the next best thing. * weh * Bump pool size * oop wrong method * Add drawing methods for lists Content may be using it over a valuelist for whatever reason. * Add more ValueList conveniences * Add more CollectionExtension methods Maybe array.resize is bad for sandbox coin, in which case I'd also settle for changing it to a list instead. * Add ToMapCoordinates method for NetCoordinates * fr * mraow * Release notes
This commit is contained in:
@@ -35,11 +35,13 @@ END TEMPLATE-->
|
||||
|
||||
### Breaking changes
|
||||
|
||||
*None yet*
|
||||
* Change Collapsible controls default orientations to Vertical.
|
||||
|
||||
### New features
|
||||
|
||||
* Add an overload to DrawingHandleBase.DrawPrimitives that allows a `List<Vector2>` to be passed in.
|
||||
* Expose the Label control for Collapsible controls.
|
||||
* Add GetGridPosition that considers physics center-of-mass.
|
||||
* Add TileToVector methods to get the LocalPosition of tile-coords (taking into account tile size).
|
||||
|
||||
### Bugfixes
|
||||
|
||||
@@ -51,7 +53,7 @@ END TEMPLATE-->
|
||||
|
||||
### Internal
|
||||
|
||||
*None yet*
|
||||
* Bump max pool size for robust jobs.
|
||||
|
||||
|
||||
## 211.0.2
|
||||
|
||||
@@ -29,9 +29,11 @@ namespace Robust.Client.UserInterface.Controls
|
||||
}
|
||||
|
||||
public Collapsible()
|
||||
{}
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical;
|
||||
}
|
||||
|
||||
public Collapsible(CollapsibleHeading header, CollapsibleBody body)
|
||||
public Collapsible(CollapsibleHeading header, CollapsibleBody body) : this()
|
||||
{
|
||||
AddChild(header);
|
||||
AddChild(body);
|
||||
@@ -39,12 +41,9 @@ namespace Robust.Client.UserInterface.Controls
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public Collapsible(string title, CollapsibleBody body)
|
||||
public Collapsible(string title, CollapsibleBody body) : this(new CollapsibleHeading(title), body)
|
||||
{
|
||||
AddChild(new CollapsibleHeading(title));
|
||||
AddChild(body);
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected internal override void Draw(DrawingHandleScreen handle)
|
||||
@@ -105,11 +104,15 @@ namespace Robust.Client.UserInterface.Controls
|
||||
set => _chevron.Margin = value;
|
||||
}
|
||||
|
||||
private Label _title = new();
|
||||
/// <summary>
|
||||
/// Exposes the label for this heading.
|
||||
/// </summary>
|
||||
public Label Label { get; }
|
||||
|
||||
public string? Title
|
||||
{
|
||||
get => _title.Text;
|
||||
set => _title.Text = value;
|
||||
get => Label.Text;
|
||||
set => Label.Text = value;
|
||||
}
|
||||
|
||||
public CollapsibleHeading()
|
||||
@@ -118,8 +121,8 @@ namespace Robust.Client.UserInterface.Controls
|
||||
var box = new BoxContainer();
|
||||
AddChild(box);
|
||||
box.AddChild(_chevron);
|
||||
_title = new Label();
|
||||
box.AddChild(_title);
|
||||
Label = new Label();
|
||||
box.AddChild(Label);
|
||||
}
|
||||
|
||||
public CollapsibleHeading(string title) : this()
|
||||
|
||||
@@ -127,7 +127,31 @@ public abstract partial class SharedMapSystem
|
||||
SubscribeLocalEvent<MapGridComponent, MoveEvent>(OnGridMove);
|
||||
}
|
||||
|
||||
public void OnGridBoundsChange(EntityUid uid, MapGridComponent component)
|
||||
/// <summary>
|
||||
/// <see cref="GetGridPosition(Robust.Shared.GameObjects.Entity{Robust.Shared.Physics.Components.PhysicsComponent?},System.Numerics.Vector2,Robust.Shared.Maths.Angle)"/>
|
||||
/// </summary>
|
||||
public Vector2 GetGridPosition(Entity<PhysicsComponent?> grid, Vector2 worldPos, Angle worldRot)
|
||||
{
|
||||
if (!Resolve(grid.Owner, ref grid.Comp))
|
||||
return Vector2.Zero;
|
||||
|
||||
return worldPos + worldRot.RotateVec(grid.Comp.LocalCenter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapgrid's position considering its local physics center.
|
||||
/// </summary>
|
||||
public Vector2 GetGridPosition(Entity<PhysicsComponent?, TransformComponent?> grid)
|
||||
{
|
||||
if (!Resolve(grid.Owner, ref grid.Comp1, ref grid.Comp2))
|
||||
return Vector2.Zero;
|
||||
|
||||
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(grid.Comp2);
|
||||
|
||||
return GetGridPosition((grid.Owner, grid.Comp1), worldPos, worldRot);
|
||||
}
|
||||
|
||||
private void OnGridBoundsChange(EntityUid uid, MapGridComponent component)
|
||||
{
|
||||
// Just MapLoader things.
|
||||
if (component.MapProxy == DynamicTree.Proxy.Free) return;
|
||||
@@ -193,7 +217,7 @@ public abstract partial class SharedMapSystem
|
||||
|
||||
if (xform.ParentUid != xform.MapUid && meta.EntityLifeStage < EntityLifeStage.Terminating && _netManager.IsServer)
|
||||
{
|
||||
Log.Error($"Grid {ToPrettyString(uid, meta)} it not parented to a map. y'all need jesus. {Environment.StackTrace}");
|
||||
Log.Error($"Grid {ToPrettyString(uid, meta)} is not parented to {ToPrettyString(xform._parent)} which is not a map. y'all need jesus. {Environment.StackTrace}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1363,8 +1387,36 @@ public abstract partial class SharedMapSystem
|
||||
|
||||
public EntityCoordinates GridTileToLocal(EntityUid uid, MapGridComponent grid, Vector2i gridTile)
|
||||
{
|
||||
return new(uid,
|
||||
new Vector2(gridTile.X * grid.TileSize + (grid.TileSize / 2f), gridTile.Y * grid.TileSize + (grid.TileSize / 2f)));
|
||||
var position = TileCenterToVector(uid, grid, gridTile);
|
||||
|
||||
return new(uid, position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns a gridtile origin into a Vector2, accounting for tile size.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector2 TileToVector(Entity<MapGridComponent> grid, Vector2i gridTile)
|
||||
{
|
||||
return new Vector2(gridTile.X * grid.Comp.TileSize, gridTile.Y * grid.Comp.TileSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns a gridtile center into a Vector2, accounting for tile size.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector2 TileCenterToVector(EntityUid uid, MapGridComponent grid, Vector2i gridTile)
|
||||
{
|
||||
return TileCenterToVector((uid, grid), gridTile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns a gridtile center into a Vector2, accounting for tile size.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector2 TileCenterToVector(Entity<MapGridComponent> grid, Vector2i gridTile)
|
||||
{
|
||||
return new Vector2(gridTile.X * grid.Comp.TileSize, gridTile.Y * grid.Comp.TileSize) + grid.Comp.TileSizeHalfVector;
|
||||
}
|
||||
|
||||
public Vector2 GridTileToWorldPos(EntityUid uid, MapGridComponent grid, Vector2i gridTile)
|
||||
|
||||
@@ -57,16 +57,16 @@ internal sealed class ParallelManager : IParallelManagerInternal
|
||||
// This lets us avoid re-allocating the ManualResetEventSlims constantly when we just need a way to signal job completion.
|
||||
|
||||
private readonly ObjectPool<InternalJob> _jobPool =
|
||||
new DefaultObjectPool<InternalJob>(new DefaultPooledObjectPolicy<InternalJob>(), 256);
|
||||
new DefaultObjectPool<InternalJob>(new DefaultPooledObjectPolicy<InternalJob>(), 1024);
|
||||
|
||||
private readonly ObjectPool<InternalParallelJob> _parallelPool =
|
||||
new DefaultObjectPool<InternalParallelJob>(new DefaultPooledObjectPolicy<InternalParallelJob>(), 256);
|
||||
new DefaultObjectPool<InternalParallelJob>(new DefaultPooledObjectPolicy<InternalParallelJob>(), 1024);
|
||||
|
||||
/// <summary>
|
||||
/// Used internally for Parallel jobs, for external callers it gets garbage collected.
|
||||
/// </summary>
|
||||
private readonly ObjectPool<ParallelTracker> _trackerPool =
|
||||
new DefaultObjectPool<ParallelTracker>(new DefaultPooledObjectPolicy<ParallelTracker>());
|
||||
new DefaultObjectPool<ParallelTracker>(new DefaultPooledObjectPolicy<ParallelTracker>(), 1024);
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user