Refactor engine to support double-precision vectors

This commit is contained in:
Wojtek Figat
2022-06-13 00:40:32 +02:00
parent f82e370392
commit a881c90b2e
744 changed files with 19062 additions and 12467 deletions

View File

@@ -17,8 +17,8 @@ namespace FlaxEditor.GUI.Timeline.GUI
private float[] _tickSteps;
private float[] _tickStrengths;
private bool _isSelecting;
private Vector2 _selectingStartPos = Vector2.Minimum;
private Vector2 _mousePos = Vector2.Minimum;
private Float2 _selectingStartPos = Float2.Minimum;
private Float2 _mousePos = Float2.Minimum;
/// <summary>
/// Initializes a new instance of the <see cref="Background"/> class.
@@ -38,7 +38,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (base.OnMouseDown(location, button))
return true;
@@ -59,7 +59,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
_mousePos = location;
if (_isSelecting && button == MouseButton.Left)
@@ -77,7 +77,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
_mousePos = location;
@@ -113,7 +113,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool IntersectsContent(ref Vector2 locationParent, out Vector2 location)
public override bool IntersectsContent(ref Float2 locationParent, out Float2 location)
{
// Pass all events
location = PointFromParent(ref locationParent);
@@ -142,14 +142,14 @@ namespace FlaxEditor.GUI.Timeline.GUI
var localRectMax = localRect.BottomRight;
// Draw lines between tracks
Render2D.DrawLine(new Vector2(areaLeft, 0.5f), new Vector2(areaRight, 0.5f), linesColor);
Render2D.DrawLine(new Float2(areaLeft, 0.5f), new Float2(areaRight, 0.5f), linesColor);
for (int i = 0; i < tracks.Count; i++)
{
var track = tracks[i];
if (track.Visible)
{
var top = track.Bottom + 0.5f;
Render2D.DrawLine(new Vector2(areaLeft, top), new Vector2(areaRight, top), linesColor);
Render2D.DrawLine(new Float2(areaLeft, top), new Float2(areaRight, top), linesColor);
}
}
@@ -167,8 +167,8 @@ namespace FlaxEditor.GUI.Timeline.GUI
var minDistanceBetweenTicks = 50.0f;
var maxDistanceBetweenTicks = 100.0f;
var zoom = Timeline.UnitsPerSecond * _timeline.Zoom;
var left = Vector2.Min(localRectMin, localRectMax).X;
var right = Vector2.Max(localRectMin, localRectMax).X;
var left = Float2.Min(localRectMin, localRectMax).X;
var right = Float2.Max(localRectMin, localRectMax).X;
var leftFrame = Mathf.Floor((left - Timeline.StartOffset) / zoom) * _timeline.FramesPerSecond;
var rightFrame = Mathf.Ceil((right - Timeline.StartOffset) / zoom) * _timeline.FramesPerSecond;
var min = leftFrame;
@@ -246,7 +246,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
// Darken area outside the duration
{
var outsideDurationAreaColor = new Color(0, 0, 0, 100);
var leftSideMin = PointFromParent(Vector2.Zero);
var leftSideMin = PointFromParent(Float2.Zero);
var leftSideMax = BottomLeft;
var rightSideMin = UpperRight;
var rightSideMax = PointFromParent(Parent.BottomRight) + mediaBackground.ControlsBounds.BottomRight;
@@ -307,7 +307,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseWheel(Vector2 location, float delta)
public override bool OnMouseWheel(Float2 location, float delta)
{
if (base.OnMouseWheel(location, delta))
return true;

View File

@@ -12,7 +12,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
{
private Timeline _timeline;
internal bool _rightMouseButtonDown;
private Vector2 _rightMouseButtonLastPos;
private Float2 _rightMouseButtonLastPos;
private float _rightMouseButtonMovement;
public BackgroundArea(Timeline timeline)
@@ -25,7 +25,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (base.OnMouseDown(location, button))
return true;
@@ -44,7 +44,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
// Panning timeline view with a right-mouse button
if (_rightMouseButtonDown)
@@ -78,7 +78,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Right && _rightMouseButtonDown)
{

View File

@@ -42,7 +42,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
public class StopControl : Control
{
private bool _isMoving;
private Vector2 _startMovePos;
private Float2 _startMovePos;
private IColorPickerDialog _currentDialog;
/// <summary>
@@ -70,7 +70,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{
@@ -86,7 +86,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left && _isMoving)
{
@@ -99,25 +99,25 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area)
public override bool OnShowTooltip(out string text, out Float2 location, out Rectangle area)
{
// Don't show tooltip is user is moving the stop
return base.OnShowTooltip(out text, out location, out area) && !_isMoving;
}
/// <inheritdoc />
public override bool OnTestTooltipOverControl(ref Vector2 location)
public override bool OnTestTooltipOverControl(ref Float2 location)
{
// Don't show tooltip is user is moving the stop
return base.OnTestTooltipOverControl(ref location) && !_isMoving;
}
/// <inheritdoc />
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
if (_isMoving && Vector2.DistanceSquared(ref location, ref _startMovePos) > 25.0f)
if (_isMoving && Float2.DistanceSquared(ref location, ref _startMovePos) > 25.0f)
{
_startMovePos = Vector2.Minimum;
_startMovePos = Float2.Minimum;
var x = PointToParent(location).X;
var frame = (int)((x - Width * 0.5f) / Gradient._scale);
Gradient.SetStopFrame(Index, frame);
@@ -127,7 +127,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDoubleClick(Vector2 location, MouseButton button)
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
if (base.OnMouseDoubleClick(location, button))
return true;
@@ -347,7 +347,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
{
AutoFocus = false,
Gradient = this,
Size = new Vector2(10.0f, 10.0f),
Size = new Float2(10.0f, 10.0f),
Parent = this,
};
_stops.Add(stop);
@@ -360,7 +360,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
{
var control = _stops[i];
var stop = _data[i];
control.Location = new Vector2(stop.Frame * scale - control.Width * 0.5f, (height - control.Height) * 0.5f);
control.Location = new Float2(stop.Frame * scale - control.Width * 0.5f, (height - control.Height) * 0.5f);
control.Index = i;
control.TooltipText = stop.Value + " at frame " + stop.Frame;
}
@@ -390,7 +390,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
Render2D.PushClip(ref clientArea);
var style = Style.Current;
var bounds = new Rectangle(Vector2.Zero, Size);
var bounds = new Rectangle(Float2.Zero, Size);
var count = _data.Count;
if (count == 0)
{
@@ -409,7 +409,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
if (prevStop.Frame > 0.0f)
{
Render2D.FillRectangle(new Rectangle(Vector2.Zero, prevStop.Frame * scale, height), prevStop.Value);
Render2D.FillRectangle(new Rectangle(Float2.Zero, prevStop.Frame * scale, height), prevStop.Value);
}
for (int i = 1; i < count; i++)
@@ -435,7 +435,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDoubleClick(Vector2 location, MouseButton button)
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
if (base.OnMouseDoubleClick(location, button))
return true;

View File

@@ -79,15 +79,15 @@ namespace FlaxEditor.GUI
private readonly KeyframesEditor _editor;
internal bool _leftMouseDown;
private bool _rightMouseDown;
internal Vector2 _leftMouseDownPos = Vector2.Minimum;
private Vector2 _rightMouseDownPos = Vector2.Minimum;
internal Vector2 _mousePos = Vector2.Minimum;
private Vector2 _movingViewLastPos;
internal Float2 _leftMouseDownPos = Float2.Minimum;
private Float2 _rightMouseDownPos = Float2.Minimum;
internal Float2 _mousePos = Float2.Minimum;
private Float2 _movingViewLastPos;
internal bool _isMovingSelection;
private bool _movedKeyframes;
private float _movingSelectionStart;
private float[] _movingSelectionOffsets;
private Vector2 _cmShowPos;
private Float2 _cmShowPos;
/// <summary>
/// Initializes a new instance of the <see cref="Contents"/> class.
@@ -119,7 +119,7 @@ namespace FlaxEditor.GUI
}
}
internal void OnMoveStart(Vector2 location)
internal void OnMoveStart(Float2 location)
{
// Start moving selected nodes
_isMovingSelection = true;
@@ -133,7 +133,7 @@ namespace FlaxEditor.GUI
_editor.OnEditingStart();
}
internal void OnMove(Vector2 location)
internal void OnMove(Float2 location)
{
var viewRect = _editor._mainPanel.GetClientArea();
var locationKeyframes = PointToKeyframes(location, ref viewRect);
@@ -170,7 +170,7 @@ namespace FlaxEditor.GUI
}
}
internal void OnMoveEnd(Vector2 location)
internal void OnMoveEnd(Float2 location)
{
if (_movedKeyframes)
{
@@ -183,7 +183,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override bool IntersectsContent(ref Vector2 locationParent, out Vector2 location)
public override bool IntersectsContent(ref Float2 locationParent, out Float2 location)
{
// Pass all events
location = PointFromParent(ref locationParent);
@@ -191,7 +191,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override void OnMouseEnter(Vector2 location)
public override void OnMouseEnter(Float2 location)
{
_mousePos = location;
@@ -199,7 +199,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
_mousePos = location;
@@ -216,7 +216,7 @@ namespace FlaxEditor.GUI
if (_rightMouseDown)
{
// Calculate delta
Vector2 delta = location - _movingViewLastPos;
Float2 delta = location - _movingViewLastPos;
if (delta.LengthSquared > 0.01f)
{
if (_editor.CustomViewPanning != null)
@@ -272,7 +272,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (base.OnMouseDown(location, button))
{
@@ -371,7 +371,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
_mousePos = location;
@@ -400,7 +400,7 @@ namespace FlaxEditor.GUI
Cursor = CursorType.Default;
// Check if no move has been made at all
if (Vector2.Distance(ref location, ref _rightMouseDownPos) < 2.0f)
if (Float2.Distance(ref location, ref _rightMouseDownPos) < 2.0f)
{
var selectionCount = _editor.SelectionCount;
var point = GetChildAt(location) as KeyframePoint;
@@ -458,7 +458,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override bool OnMouseWheel(Vector2 location, float delta)
public override bool OnMouseWheel(Float2 location, float delta)
{
if (base.OnMouseWheel(location, delta))
return true;
@@ -475,7 +475,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
protected override void SetScaleInternal(ref Vector2 scale)
protected override void SetScaleInternal(ref Float2 scale)
{
base.SetScaleInternal(ref scale);
@@ -488,10 +488,10 @@ namespace FlaxEditor.GUI
/// <param name="point">The point.</param>
/// <param name="keyframesContentAreaBounds">The keyframes contents area bounds.</param>
/// <returns>The result.</returns>
private Vector2 PointToKeyframes(Vector2 point, ref Rectangle keyframesContentAreaBounds)
private Float2 PointToKeyframes(Float2 point, ref Rectangle keyframesContentAreaBounds)
{
// Contents -> Keyframes
return new Vector2(
return new Float2(
(point.X + Location.X) / UnitsPerSecond,
(point.Y + Location.Y - keyframesContentAreaBounds.Height) / -UnitsPerSecond
);
@@ -526,7 +526,7 @@ namespace FlaxEditor.GUI
/// <inheritdoc />
public override void Draw()
{
var rect = new Rectangle(Vector2.Zero, Size);
var rect = new Rectangle(Float2.Zero, Size);
var color = Color.Gray;
if (IsSelected)
color = Editor.ContainsFocus ? Color.YellowGreen : Color.Lerp(Color.Gray, Color.YellowGreen, 0.4f);
@@ -544,7 +544,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public override bool OnMouseDoubleClick(Vector2 location, MouseButton button)
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
if (base.OnMouseDoubleClick(location, button))
return true;
@@ -576,7 +576,7 @@ namespace FlaxEditor.GUI
/// <summary>
/// The keyframes size.
/// </summary>
private static readonly Vector2 KeyframesSize = new Vector2(7.0f);
private static readonly Float2 KeyframesSize = new Float2(7.0f);
private Contents _contents;
private Panel _mainPanel;
@@ -603,7 +603,7 @@ namespace FlaxEditor.GUI
/// <summary>
/// Gets or sets the view offset (via scroll bars).
/// </summary>
public Vector2 ViewOffset
public Float2 ViewOffset
{
get => _mainPanel.ViewOffset;
set => _mainPanel.ViewOffset = value;
@@ -612,10 +612,10 @@ namespace FlaxEditor.GUI
/// <summary>
/// Gets or sets the view scale.
/// </summary>
public Vector2 ViewScale
public Float2 ViewScale
{
get => _contents.Scale;
set => _contents.Scale = Vector2.Clamp(value, new Vector2(0.0001f), new Vector2(1000.0f));
set => _contents.Scale = Float2.Clamp(value, new Float2(0.0001f), new Float2(1000.0f));
}
/// <summary>
@@ -636,7 +636,7 @@ namespace FlaxEditor.GUI
/// <summary>
/// The function for custom view panning. Gets input movement delta (in keyframes editor control space) and returns the renaming input delta to process by keyframes editor itself.
/// </summary>
public Func<Vector2, Vector2> CustomViewPanning;
public Func<Float2, Float2> CustomViewPanning;
/// <summary>
/// The maximum amount of keyframes to use.
@@ -896,7 +896,7 @@ namespace FlaxEditor.GUI
OnEdited();
}
private void AddKeyframe(Vector2 keyframesPos)
private void AddKeyframe(Float2 keyframesPos)
{
var k = new Keyframe
{
@@ -929,7 +929,7 @@ namespace FlaxEditor.GUI
{
_editor = editor;
const float width = 280.0f;
Size = new Vector2(width, height);
Size = new Float2(width, height);
var panel1 = new Panel(ScrollBars.Vertical)
{
Bounds = new Rectangle(0, 0.0f, width, height),
@@ -1032,13 +1032,13 @@ namespace FlaxEditor.GUI
public Keyframe[] Keyframes;
}
private void EditAllKeyframes(Control control, Vector2 pos)
private void EditAllKeyframes(Control control, Float2 pos)
{
_popup = new Popup(this, new object[] { new AllKeyframesProxy { Editor = this, Keyframes = _keyframes.ToArray(), } }, null, 400.0f);
_popup.Show(control, pos);
}
private void EditKeyframes(Control control, Vector2 pos)
private void EditKeyframes(Control control, Float2 pos)
{
var keyframeIndices = new List<int>();
for (int i = 0; i < _points.Count; i++)
@@ -1051,7 +1051,7 @@ namespace FlaxEditor.GUI
EditKeyframes(control, pos, keyframeIndices);
}
private void EditKeyframes(Control control, Vector2 pos, List<int> keyframeIndices)
private void EditKeyframes(Control control, Float2 pos, List<int> keyframeIndices)
{
var selection = new object[keyframeIndices.Count];
for (int i = 0; i < keyframeIndices.Count; i++)
@@ -1130,8 +1130,8 @@ namespace FlaxEditor.GUI
/// </summary>
public void ResetView()
{
ViewScale = Vector2.One;
ViewOffset = Vector2.Zero;
ViewScale = Float2.One;
ViewOffset = Float2.Zero;
UpdateKeyframes();
}
@@ -1156,8 +1156,8 @@ namespace FlaxEditor.GUI
var p = _points[i];
var k = _keyframes[p.Index];
p.Size = new Vector2(4.0f / viewScale.X, Height - 2.0f);
p.Location = new Vector2(k.Time * UnitsPerSecond - p.Width * 0.5f, 1.0f);
p.Size = new Float2(4.0f / viewScale.X, Height - 2.0f);
p.Location = new Float2(k.Time * UnitsPerSecond - p.Width * 0.5f, 1.0f);
p.UpdateTooltip();
}
@@ -1230,7 +1230,7 @@ namespace FlaxEditor.GUI
}
var style = Style.Current;
var rect = new Rectangle(Vector2.Zero, Size);
var rect = new Rectangle(Float2.Zero, Size);
// Draw selection rectangle
if (_contents._leftMouseDown && !_contents._isMovingSelection)
@@ -1344,7 +1344,7 @@ namespace FlaxEditor.GUI
}
/// <inheritdoc />
public void OnKeyframesMove(IKeyframesEditor editor, ContainerControl control, Vector2 location, bool start, bool end)
public void OnKeyframesMove(IKeyframesEditor editor, ContainerControl control, Float2 location, bool start, bool end)
{
if (SelectionCount == 0)
return;

View File

@@ -34,7 +34,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
var m2 = Matrix3x3.Translation2D(0, timeAxisHeaderOffset);
Matrix3x3.Multiply(ref m1, ref m2, out var m3);
Render2D.PushTransform(ref m3);
Render2D.DrawSprite(icon, new Rectangle(new Vector2(4, -Width), Size), _timeline.IsMovingPositionHandle ? style.ProgressNormal : style.Foreground);
Render2D.DrawSprite(icon, new Rectangle(new Float2(4, -Width), Size), _timeline.IsMovingPositionHandle ? style.ProgressNormal : style.Foreground);
Render2D.PopTransform();
Render2D.FillRectangle(new Rectangle(Width * 0.5f, Height + timeAxisHeaderOffset, 1, _timeline.MediaPanel.Height - timeAxisHeaderOffset - timeAxisOverlap), _timeline.IsMovingPositionHandle ? style.ProgressNormal : style.Foreground.RGBMultiplied(0.8f));

View File

@@ -14,7 +14,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
{
private Timeline _timeline;
private bool _isMoving;
private Vector2 _startMoveLocation;
private Float2 _startMoveLocation;
private int _startMoveDuration;
private bool _isStart;
private bool _canEdit;
@@ -47,7 +47,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (base.OnMouseDown(location, button))
return true;
@@ -67,7 +67,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
if (_isMoving)
{
@@ -97,7 +97,7 @@ namespace FlaxEditor.GUI.Timeline.GUI
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left && _isMoving)
{