From 7a73c04688e2169ad04d77530e50218e6355254d Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Sat, 16 Sep 2023 21:18:00 +0200 Subject: [PATCH 01/54] SmoothDamp implementation for Vector2 and Vector3 --- Source/Engine/Core/Math/Vector2.cs | 86 ++++++++++++++++++++++++++ Source/Engine/Core/Math/Vector3.cs | 98 ++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 2af365638..4b6fb5e59 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -58,6 +58,7 @@ using Mathr = FlaxEngine.Mathf; */ using System; using System.Globalization; +using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -953,6 +954,91 @@ namespace FlaxEngine return result; } + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + /// Defines the upper limit on the speed of the Smooth Damp. + public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed) + { + return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, Time.DeltaTime); + } + + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime) + { + return SmoothDamp(current, target, ref currentVelocity, smoothTime, float.PositiveInfinity, Time.DeltaTime); + } + + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + /// Defines the upper limit on the speed of the Smooth Damp. + /// Delta Time, represents the time elapsed since last frame. + public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, [DefaultValue("float.PositiveInfinity")] float maxSpeed, [DefaultValue("Time.DeltaTime")] float deltaTime) + { + smoothTime = Mathf.Max(0.0001f, smoothTime); + float a = 2f / smoothTime; + float b = a * deltaTime; + float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); + + float change_x = current.X - target.X; + float change_y = current.Y - target.Y; + Vector2 originalTo = target; + + float change = maxSpeed * smoothTime; + float changeSq = change * change; + float sqrmag = change_x * change_x + change_y * change_y; + if (sqrmag > changeSq) + { + var mag = (float)Math.Sqrt(sqrmag); + change_x = change_x / mag * change; + change_y = change_y / mag * change; + } + + target.X = current.X - change_x; + target.Y = current.Y - change_y; + + float temp_x = (currentVelocity.X + a * change_x) * deltaTime; + float temp_y = (currentVelocity.Y + a * change_y) * deltaTime; + + currentVelocity.X = (currentVelocity.X - a * temp_x) * e; + currentVelocity.Y = (currentVelocity.Y - a * temp_y) * e; + + float output_x = target.X + (change_x + temp_x) * e; + float output_y = target.Y + (change_y + temp_y) * e; + + float x1 = originalTo.X - current.X; + float y1 = originalTo.Y - current.Y; + + float x2 = output_x - originalTo.X; + float y2 = output_y - originalTo.Y; + + if (x1 * x2 + y1 * y2 > 0) + { + output_x = originalTo.X; + output_y = originalTo.Y; + + currentVelocity.X = (output_x - originalTo.X) / deltaTime; + currentVelocity.Y = (output_y - originalTo.Y) / deltaTime; + } + + return new Vector2(output_x, output_y); + } + /// /// Performs a cubic interpolation between two vectors. /// diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 4442d3334..c1ea6bb67 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -58,6 +58,7 @@ using Mathr = FlaxEngine.Mathf; */ using System; using System.Globalization; +using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -1042,6 +1043,103 @@ namespace FlaxEngine return result; } + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + /// Defines the upper limit on the speed of the Smooth Damp. + public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed) + { + return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, Time.DeltaTime); + } + + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime) + { + return SmoothDamp(current, target, ref currentVelocity, smoothTime, float.PositiveInfinity, Time.DeltaTime); + } + + /// + /// Performs a gradual change of a vector towards a specified target over time + /// + /// Current vector. + /// Target vector. + /// Used to store the current velocity. + /// Determines the approximate time it should take to reach the target vector. + /// Defines the upper limit on the speed of the Smooth Damp. + /// Delta Time, represents the time elapsed since last frame. + public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, [DefaultValue("float.PositiveInfinity")] float maxSpeed, [DefaultValue("Time.DeltaTime")] float deltaTime) + { + smoothTime = Mathf.Max(0.0001f, smoothTime); + float a = 2f / smoothTime; + float b = a * deltaTime; + float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); + + float change_x = current.X - target.X; + float change_y = current.Y - target.Y; + float change_z = current.Z - target.Z; + + Vector3 originalTo = target; + + float maxChangeSpeed = maxSpeed * smoothTime; + float changeSq = maxChangeSpeed * maxChangeSpeed; + float sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; + if (sqrMag > changeSq) + { + var mag = (float)Math.Sqrt(sqrMag); + change_x = change_x / mag * maxChangeSpeed; + change_y = change_y / mag * maxChangeSpeed; + change_z = change_z / mag * maxChangeSpeed; + } + + target.X = current.X - change_x; + target.Y = current.Y - change_y; + target.Z = current.Z - change_z; + + float temp_x = (currentVelocity.X + a * change_x) * deltaTime; + float temp_y = (currentVelocity.Y + a * change_y) * deltaTime; + float temp_z = (currentVelocity.Z + a * change_z) * deltaTime; + + currentVelocity.X = (currentVelocity.X - a * temp_x) * e; + currentVelocity.Y = (currentVelocity.Y - a * temp_y) * e; + currentVelocity.Z = (currentVelocity.Z - a * temp_z) * e; + + float output_x = target.X + (change_x + temp_x) * e; + float output_y = target.Y + (change_y + temp_y) * e; + float output_z = target.Z + (change_z + temp_z) * e; + + float x1 = originalTo.X - current.X; + float y1 = originalTo.Y - current.Y; + float z1 = originalTo.Z - current.Z; + + float x2 = output_x - originalTo.X; + float y2 = output_y - originalTo.Y; + float z2 = output_z - originalTo.Z; + + if (x1 * x2 + y1 * y2 + z1 * z2 > 0) + { + output_x = originalTo.X; + output_y = originalTo.Y; + output_z = originalTo.Z; + + currentVelocity.X = (output_x - originalTo.X) / deltaTime; + currentVelocity.Y = (output_y - originalTo.Y) / deltaTime; + currentVelocity.Z = (output_z - originalTo.Z) / deltaTime; + } + + return new Vector3(output_x, output_y, output_z); + } + + /// /// Performs a cubic interpolation between two vectors. /// From 1d08e4b1b8517fc673585c44ead34df243be4790 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 16 Sep 2023 14:28:21 -0500 Subject: [PATCH 02/54] Add several fixes to button sizes when fonts are larger. --- .../CustomEditors/Dedicated/ScriptsEditor.cs | 16 ++++++++++------ .../CustomEditors/Dedicated/UIControlEditor.cs | 6 ++++-- .../Editors/ActorTransformEditor.cs | 8 ++++---- Source/Editor/CustomEditors/Editors/TagEditor.cs | 7 ++++++- Source/Editor/Tools/Foliage/FoliageTab.cs | 11 ++++++++++- Source/Editor/Tools/Terrain/CarveTab.cs | 11 ++++++++++- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index bf82e19da..d84414fcf 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -25,6 +25,7 @@ namespace FlaxEditor.CustomEditors.Dedicated private DragHandlers _dragHandlers; private DragScriptItems _dragScripts; private DragAssets _dragAssets; + private Button _addScriptsButton; /// /// The parent scripts editor. @@ -40,16 +41,19 @@ namespace FlaxEditor.CustomEditors.Dedicated AutoFocus = false; // Add script button - float addScriptButtonWidth = 60.0f; - var addScriptButton = new Button + var buttonText = "Add script"; + var textSize = Style.Current.FontMedium.MeasureText(buttonText); + float addScriptButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4; + var buttonHeight = (textSize.Y < 18) ? 18 : textSize.Y + 4; + _addScriptsButton = new Button { TooltipText = "Add new scripts to the actor", AnchorPreset = AnchorPresets.MiddleCenter, - Text = "Add script", + Text = buttonText, Parent = this, - Bounds = new Rectangle((Width - addScriptButtonWidth) / 2, 1, addScriptButtonWidth, 18), + Bounds = new Rectangle((Width - addScriptButtonWidth) / 2, 1, addScriptButtonWidth, buttonHeight), }; - addScriptButton.ButtonClicked += OnAddScriptButtonClicked; + _addScriptsButton.ButtonClicked += OnAddScriptButtonClicked; } private void OnAddScriptButtonClicked(Button button) @@ -82,7 +86,7 @@ namespace FlaxEditor.CustomEditors.Dedicated var size = Size; // Info - Render2D.DrawText(style.FontSmall, "Drag scripts here", new Rectangle(2, 22, size.X - 4, size.Y - 4 - 20), style.ForegroundDisabled, TextAlignment.Center, TextAlignment.Center); + Render2D.DrawText(style.FontSmall, "Drag scripts here", new Rectangle(2, _addScriptsButton.Height + 4, size.X - 4, size.Y - 4 - 20), style.ForegroundDisabled, TextAlignment.Center, TextAlignment.Center); // Check if drag is over if (IsDragOver && _dragHandlers != null && _dragHandlers.HasValidDrag) diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index fde4967e8..5215e23a4 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -422,12 +422,14 @@ namespace FlaxEditor.CustomEditors.Dedicated // Set control type button var space = layout.Space(20); - float setTypeButtonWidth = 60.0f; + var buttonText = "Set Type"; + var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(buttonText); + float setTypeButtonWidth = (textSize.X < 60.0f) ? 60.0f : textSize.X + 4; var setTypeButton = new Button { TooltipText = "Sets the control to the given type", AnchorPreset = AnchorPresets.MiddleCenter, - Text = "Set Type", + Text = buttonText, Parent = space.Spacer, Bounds = new Rectangle((space.Spacer.Width - setTypeButtonWidth) / 2, 1, setTypeButtonWidth, 18), }; diff --git a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs index cb4e7b9c1..4aa02ac78 100644 --- a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs @@ -88,20 +88,20 @@ namespace FlaxEditor.CustomEditors.Editors LinkValues = Editor.Instance.Windows.PropertiesWin.ScaleLinked; // Add button with the link icon + _linkButton = new Button { BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Link32), Parent = LinkedLabel, Width = 18, Height = 18, - AnchorPreset = AnchorPresets.TopLeft, + AnchorPreset = AnchorPresets.MiddleLeft, }; _linkButton.Clicked += ToggleLink; ToggleEnabled(); SetLinkStyle(); - var x = LinkedLabel.Text.Value.Length * 7 + 5; - _linkButton.LocalX += x; - _linkButton.LocalY += 1; + var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(LinkedLabel.Text.Value); + _linkButton.LocalX += textSize.X + 10; LinkedLabel.SetupContextMenu += (label, menu, editor) => { menu.AddSeparator(); diff --git a/Source/Editor/CustomEditors/Editors/TagEditor.cs b/Source/Editor/CustomEditors/Editors/TagEditor.cs index 3d2dd86aa..d69571dee 100644 --- a/Source/Editor/CustomEditors/Editors/TagEditor.cs +++ b/Source/Editor/CustomEditors/Editors/TagEditor.cs @@ -623,13 +623,18 @@ namespace FlaxEditor.CustomEditors.Editors { _label = layout.ClickableLabel(GetText(out _)).CustomControl; _label.RightClick += ShowPicker; + var buttonText = "..."; var button = new Button { Size = new Float2(16.0f), - Text = "...", + Text = buttonText, TooltipText = "Edit...", Parent = _label, }; + var textSize = FlaxEngine.GUI.Style.Current.FontMedium.MeasureText(buttonText); + if (textSize.Y > button.Width) + button.Width = textSize.Y + 2; + button.SetAnchorPreset(AnchorPresets.MiddleRight, false, true); button.Clicked += ShowPicker; } diff --git a/Source/Editor/Tools/Foliage/FoliageTab.cs b/Source/Editor/Tools/Foliage/FoliageTab.cs index 814376c75..10358a8c0 100644 --- a/Source/Editor/Tools/Foliage/FoliageTab.cs +++ b/Source/Editor/Tools/Foliage/FoliageTab.cs @@ -137,14 +137,23 @@ namespace FlaxEditor.Tools.Foliage Offsets = Margin.Zero, Parent = _noFoliagePanel }; + + var buttonText = "Create new foliage"; _createNewFoliage = new Button { - Text = "Create new foliage", + Text = buttonText, AnchorPreset = AnchorPresets.MiddleCenter, Offsets = new Margin(-60, 120, -12, 24), Parent = _noFoliagePanel, Enabled = false }; + var textSize = Style.Current.FontMedium.MeasureText(buttonText); + if (_createNewFoliage.Width < textSize.X) + { + _createNewFoliage.LocalX -= (textSize.X - _createNewFoliage.Width) / 2; + _createNewFoliage.Width = textSize.X + 6; + } + _createNewFoliage.Clicked += OnCreateNewFoliageClicked; } diff --git a/Source/Editor/Tools/Terrain/CarveTab.cs b/Source/Editor/Tools/Terrain/CarveTab.cs index 6bee0bd92..000f90817 100644 --- a/Source/Editor/Tools/Terrain/CarveTab.cs +++ b/Source/Editor/Tools/Terrain/CarveTab.cs @@ -95,14 +95,23 @@ namespace FlaxEditor.Tools.Terrain Offsets = Margin.Zero, Parent = _noTerrainPanel }; + + var buttonText = "Create new terrain"; _createTerrainButton = new Button { - Text = "Create new terrain", + Text = buttonText, AnchorPreset = AnchorPresets.MiddleCenter, Offsets = new Margin(-60, 120, -12, 24), Parent = _noTerrainPanel, Enabled = false }; + var textSize = Style.Current.FontMedium.MeasureText(buttonText); + if (_createTerrainButton.Width < textSize.X) + { + _createTerrainButton.LocalX -= (textSize.X - _createTerrainButton.Width) / 2; + _createTerrainButton.Width = textSize.X + 6; + } + _createTerrainButton.Clicked += OnCreateNewTerrainClicked; } From f4b7ae41a987a0077d077f01c8f0a619b5f02e7a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 16 Sep 2023 14:51:47 -0500 Subject: [PATCH 03/54] Fix profiler rows with larger font sizes. --- Source/Editor/GUI/Row.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/GUI/Row.cs b/Source/Editor/GUI/Row.cs index 8dad8b20d..b07d693e5 100644 --- a/Source/Editor/GUI/Row.cs +++ b/Source/Editor/GUI/Row.cs @@ -37,6 +37,9 @@ namespace FlaxEditor.GUI : base(0, 0, 100, height) { Depth = -1; + + if (Height < Style.Current.FontMedium.Height) + Height = Style.Current.FontMedium.Height + 4; } /// From e9bafed2c76cda023a1d26d0cbabe1a9a5e27adb Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 16 Sep 2023 15:22:15 -0500 Subject: [PATCH 04/54] Fix about dialog button --- Source/Editor/Windows/AboutDialog.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Windows/AboutDialog.cs b/Source/Editor/Windows/AboutDialog.cs index 4b9595445..b059dadcb 100644 --- a/Source/Editor/Windows/AboutDialog.cs +++ b/Source/Editor/Windows/AboutDialog.cs @@ -52,9 +52,11 @@ namespace FlaxEditor.Windows VerticalAlignment = TextAlignment.Near, Parent = this }; - var copyVersionButton = new Button(Width - 104, 6, 100, 20) + var buttonText = "Copy version info"; + var fontSize = Style.Current.FontMedium.MeasureText(buttonText); + var copyVersionButton = new Button(Width - fontSize.X - 8, 6, fontSize.X + 4, 20) { - Text = "Copy version info", + Text = buttonText, TooltipText = "Copies the current engine version information to system clipboard.", Parent = this }; From d87a60de4848c1e9c7312d518b6c1c92e925095e Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Sat, 16 Sep 2023 22:27:12 +0200 Subject: [PATCH 05/54] Naming scheme for Vector2 fix --- Source/Engine/Core/Math/Vector2.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 4b6fb5e59..9fe3c6944 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -1001,12 +1001,12 @@ namespace FlaxEngine float change = maxSpeed * smoothTime; float changeSq = change * change; - float sqrmag = change_x * change_x + change_y * change_y; - if (sqrmag > changeSq) + float sqrDist = change_x * change_x + change_y * change_y; + if (sqrDist > changeSq) { - var mag = (float)Math.Sqrt(sqrmag); - change_x = change_x / mag * change; - change_y = change_y / mag * change; + var dist = (float)Math.Sqrt(sqrDist); + change_x = change_x / dist * change; + change_y = change_y / dist * change; } target.X = current.X - change_x; From ab2d60e6d2693e7b9da179324f23c549747769cd Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 16 Sep 2023 15:30:49 -0500 Subject: [PATCH 06/54] Fix viewport options extras locations. --- Source/Editor/Viewport/EditorViewport.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index ad7e06ba5..6d92dce3c 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -441,6 +441,9 @@ namespace FlaxEditor.Viewport if (useWidgets) { + var largestText = "Invert Panning"; + var textSize = Style.Current.FontMedium.MeasureText(largestText); + var xLocationForExtras = textSize.X + 5; // Camera speed widget var camSpeed = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight); var camSpeedCM = new ContextMenu(); @@ -541,7 +544,7 @@ namespace FlaxEditor.Viewport { var ortho = ViewWidgetButtonMenu.AddButton("Orthographic"); ortho.CloseMenuOnClick = false; - var orthoValue = new CheckBox(90, 2, _isOrtho) + var orthoValue = new CheckBox(xLocationForExtras, 2, _isOrtho) { Parent = ortho }; @@ -581,7 +584,7 @@ namespace FlaxEditor.Viewport { var fov = ViewWidgetButtonMenu.AddButton("Field Of View"); fov.CloseMenuOnClick = false; - var fovValue = new FloatValueBox(1, 90, 2, 70.0f, 35.0f, 160.0f, 0.1f) + var fovValue = new FloatValueBox(1, xLocationForExtras, 2, 70.0f, 35.0f, 160.0f, 0.1f) { Parent = fov }; @@ -598,7 +601,7 @@ namespace FlaxEditor.Viewport { var orthoSize = ViewWidgetButtonMenu.AddButton("Ortho Scale"); orthoSize.CloseMenuOnClick = false; - var orthoSizeValue = new FloatValueBox(_orthoSize, 90, 2, 70.0f, 0.001f, 100000.0f, 0.01f) + var orthoSizeValue = new FloatValueBox(_orthoSize, xLocationForExtras, 2, 70.0f, 0.001f, 100000.0f, 0.01f) { Parent = orthoSize }; @@ -615,7 +618,7 @@ namespace FlaxEditor.Viewport { var nearPlane = ViewWidgetButtonMenu.AddButton("Near Plane"); nearPlane.CloseMenuOnClick = false; - var nearPlaneValue = new FloatValueBox(2.0f, 90, 2, 70.0f, 0.001f, 1000.0f) + var nearPlaneValue = new FloatValueBox(2.0f, xLocationForExtras, 2, 70.0f, 0.001f, 1000.0f) { Parent = nearPlane }; @@ -627,7 +630,7 @@ namespace FlaxEditor.Viewport { var farPlane = ViewWidgetButtonMenu.AddButton("Far Plane"); farPlane.CloseMenuOnClick = false; - var farPlaneValue = new FloatValueBox(1000, 90, 2, 70.0f, 10.0f) + var farPlaneValue = new FloatValueBox(1000, xLocationForExtras, 2, 70.0f, 10.0f) { Parent = farPlane }; @@ -639,7 +642,7 @@ namespace FlaxEditor.Viewport { var brightness = ViewWidgetButtonMenu.AddButton("Brightness"); brightness.CloseMenuOnClick = false; - var brightnessValue = new FloatValueBox(1.0f, 90, 2, 70.0f, 0.001f, 10.0f, 0.001f) + var brightnessValue = new FloatValueBox(1.0f, xLocationForExtras, 2, 70.0f, 0.001f, 10.0f, 0.001f) { Parent = brightness }; @@ -651,7 +654,7 @@ namespace FlaxEditor.Viewport { var resolution = ViewWidgetButtonMenu.AddButton("Resolution"); resolution.CloseMenuOnClick = false; - var resolutionValue = new FloatValueBox(1.0f, 90, 2, 70.0f, 0.1f, 4.0f, 0.001f) + var resolutionValue = new FloatValueBox(1.0f, xLocationForExtras, 2, 70.0f, 0.1f, 4.0f, 0.001f) { Parent = resolution }; @@ -663,7 +666,7 @@ namespace FlaxEditor.Viewport { var invert = ViewWidgetButtonMenu.AddButton("Invert Panning"); invert.CloseMenuOnClick = false; - var invertValue = new CheckBox(90, 2, _invertPanning) + var invertValue = new CheckBox(xLocationForExtras, 2, _invertPanning) { Parent = invert }; From 831500faa7d6dd08956774492a7d8be9f67a2d6e Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Sun, 17 Sep 2023 23:16:08 +0200 Subject: [PATCH 07/54] Fix type definition for Vector2 and Vector3 --- Source/Engine/Core/Math/Vector2.cs | 30 ++++++++++++++-------------- Source/Engine/Core/Math/Vector3.cs | 32 +++++++++++++++--------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 9fe3c6944..cb0cd17d1 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -995,37 +995,37 @@ namespace FlaxEngine float b = a * deltaTime; float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); - float change_x = current.X - target.X; - float change_y = current.Y - target.Y; + Real change_x = current.X - target.X; + Real change_y = current.Y - target.Y; Vector2 originalTo = target; - float change = maxSpeed * smoothTime; - float changeSq = change * change; + float maxChangeSpeed = maxSpeed * smoothTime; + float changeSq = maxChangeSpeed * maxChangeSpeed; float sqrDist = change_x * change_x + change_y * change_y; if (sqrDist > changeSq) { - var dist = (float)Math.Sqrt(sqrDist); - change_x = change_x / dist * change; - change_y = change_y / dist * change; + var dist = (Real)Math.Sqrt(sqrDist); + change_x = change_x / dist * maxChangeSpeed; + change_y = change_y / dist * maxChangeSpeed; } target.X = current.X - change_x; target.Y = current.Y - change_y; - float temp_x = (currentVelocity.X + a * change_x) * deltaTime; - float temp_y = (currentVelocity.Y + a * change_y) * deltaTime; + Real temp_x = (currentVelocity.X + a * change_x) * deltaTime; + Real temp_y = (currentVelocity.Y + a * change_y) * deltaTime; currentVelocity.X = (currentVelocity.X - a * temp_x) * e; currentVelocity.Y = (currentVelocity.Y - a * temp_y) * e; - float output_x = target.X + (change_x + temp_x) * e; - float output_y = target.Y + (change_y + temp_y) * e; + Real output_x = target.X + (change_x + temp_x) * e; + Real output_y = target.Y + (change_y + temp_y) * e; - float x1 = originalTo.X - current.X; - float y1 = originalTo.Y - current.Y; + Real x1 = originalTo.X - current.X; + Real y1 = originalTo.Y - current.Y; - float x2 = output_x - originalTo.X; - float y2 = output_y - originalTo.Y; + Real x2 = output_x - originalTo.X; + Real y2 = output_y - originalTo.Y; if (x1 * x2 + y1 * y2 > 0) { diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index c1ea6bb67..53ec824fe 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1084,9 +1084,9 @@ namespace FlaxEngine float b = a * deltaTime; float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); - float change_x = current.X - target.X; - float change_y = current.Y - target.Y; - float change_z = current.Z - target.Z; + Real change_x = current.X - target.X; + Real change_y = current.Y - target.Y; + Real change_z = current.Z - target.Z; Vector3 originalTo = target; @@ -1095,7 +1095,7 @@ namespace FlaxEngine float sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; if (sqrMag > changeSq) { - var mag = (float)Math.Sqrt(sqrMag); + var mag = (Real)Math.Sqrt(sqrMag); change_x = change_x / mag * maxChangeSpeed; change_y = change_y / mag * maxChangeSpeed; change_z = change_z / mag * maxChangeSpeed; @@ -1105,25 +1105,25 @@ namespace FlaxEngine target.Y = current.Y - change_y; target.Z = current.Z - change_z; - float temp_x = (currentVelocity.X + a * change_x) * deltaTime; - float temp_y = (currentVelocity.Y + a * change_y) * deltaTime; - float temp_z = (currentVelocity.Z + a * change_z) * deltaTime; + Real temp_x = (currentVelocity.X + a * change_x) * deltaTime; + Real temp_y = (currentVelocity.Y + a * change_y) * deltaTime; + Real temp_z = (currentVelocity.Z + a * change_z) * deltaTime; currentVelocity.X = (currentVelocity.X - a * temp_x) * e; currentVelocity.Y = (currentVelocity.Y - a * temp_y) * e; currentVelocity.Z = (currentVelocity.Z - a * temp_z) * e; - float output_x = target.X + (change_x + temp_x) * e; - float output_y = target.Y + (change_y + temp_y) * e; - float output_z = target.Z + (change_z + temp_z) * e; + Real output_x = target.X + (change_x + temp_x) * e; + Real output_y = target.Y + (change_y + temp_y) * e; + Real output_z = target.Z + (change_z + temp_z) * e; - float x1 = originalTo.X - current.X; - float y1 = originalTo.Y - current.Y; - float z1 = originalTo.Z - current.Z; + Real x1 = originalTo.X - current.X; + Real y1 = originalTo.Y - current.Y; + Real z1 = originalTo.Z - current.Z; - float x2 = output_x - originalTo.X; - float y2 = output_y - originalTo.Y; - float z2 = output_z - originalTo.Z; + Real x2 = output_x - originalTo.X; + Real y2 = output_y - originalTo.Y; + Real z2 = output_z - originalTo.Z; if (x1 * x2 + y1 * y2 + z1 * z2 > 0) { From 4e44002259bd10af946b60eab855127dd64526dc Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj <40241148+AndrejStojkovic@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:47:38 +0200 Subject: [PATCH 08/54] Fix SmoothDamp missed type casting for Vector 3 --- Source/Engine/Core/Math/Vector3.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 53ec824fe..d009a692e 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1092,7 +1092,7 @@ namespace FlaxEngine float maxChangeSpeed = maxSpeed * smoothTime; float changeSq = maxChangeSpeed * maxChangeSpeed; - float sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; + Real sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; if (sqrMag > changeSq) { var mag = (Real)Math.Sqrt(sqrMag); From e1f528ec9acb74689d95b169252e6dfdb1dcfcb3 Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj <40241148+AndrejStojkovic@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:48:16 +0200 Subject: [PATCH 09/54] Fix SmoothDamp missed type casting for Vector2 --- Source/Engine/Core/Math/Vector2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index cb0cd17d1..3eea3890f 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -1001,7 +1001,7 @@ namespace FlaxEngine float maxChangeSpeed = maxSpeed * smoothTime; float changeSq = maxChangeSpeed * maxChangeSpeed; - float sqrDist = change_x * change_x + change_y * change_y; + Real sqrDist = change_x * change_x + change_y * change_y; if (sqrDist > changeSq) { var dist = (Real)Math.Sqrt(sqrDist); From 3f299f4cf6aba92760b644b980cc977e4a9295e2 Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Tue, 19 Sep 2023 15:57:33 +0200 Subject: [PATCH 10/54] Just in case change type cast for other variables as well --- Source/Engine/Core/Math/Vector2.cs | 10 +++++----- Source/Engine/Core/Math/Vector3.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 3eea3890f..568c51764 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -991,16 +991,16 @@ namespace FlaxEngine public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, [DefaultValue("float.PositiveInfinity")] float maxSpeed, [DefaultValue("Time.DeltaTime")] float deltaTime) { smoothTime = Mathf.Max(0.0001f, smoothTime); - float a = 2f / smoothTime; - float b = a * deltaTime; - float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); + Real a = 2f / smoothTime; + Real b = a * deltaTime; + Real e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); Real change_x = current.X - target.X; Real change_y = current.Y - target.Y; Vector2 originalTo = target; - float maxChangeSpeed = maxSpeed * smoothTime; - float changeSq = maxChangeSpeed * maxChangeSpeed; + Real maxChangeSpeed = maxSpeed * smoothTime; + Real changeSq = maxChangeSpeed * maxChangeSpeed; Real sqrDist = change_x * change_x + change_y * change_y; if (sqrDist > changeSq) { diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index d009a692e..0ad557a32 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1080,9 +1080,9 @@ namespace FlaxEngine public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, [DefaultValue("float.PositiveInfinity")] float maxSpeed, [DefaultValue("Time.DeltaTime")] float deltaTime) { smoothTime = Mathf.Max(0.0001f, smoothTime); - float a = 2f / smoothTime; - float b = a * deltaTime; - float e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); + Real a = 2f / smoothTime; + Real b = a * deltaTime; + Real e = 1f / (1f + b + 0.48f * b * b + 0.235f * b * b * b); Real change_x = current.X - target.X; Real change_y = current.Y - target.Y; @@ -1090,8 +1090,8 @@ namespace FlaxEngine Vector3 originalTo = target; - float maxChangeSpeed = maxSpeed * smoothTime; - float changeSq = maxChangeSpeed * maxChangeSpeed; + Real maxChangeSpeed = maxSpeed * smoothTime; + Real changeSq = maxChangeSpeed * maxChangeSpeed; Real sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; if (sqrMag > changeSq) { From 8930c7ba565def87f8c618d7359dfb036eb97ad4 Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Tue, 19 Sep 2023 16:09:18 +0200 Subject: [PATCH 11/54] Implemented static functions for length and length squared for Vectors --- Source/Engine/Core/Math/Vector2.cs | 18 ++++++++++++++++++ Source/Engine/Core/Math/Vector3.cs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 568c51764..e953acfd6 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -821,6 +821,24 @@ namespace FlaxEngine return value; } + /// + /// Returns the length of a vector. + /// + /// The vector to get the length from. + public static Real Length(Vector2 vector) + { + return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y); + } + + /// + /// Returns the length squared of a vector. + /// + /// The vector to get the length squared from. + public static Real LengthSquared(Vector2 vector) + { + return vector.X * vector.X + vector.Y * vector.Y; + } + /// /// Makes sure that Length of the output vector is always below max and above 0. /// diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 0ad557a32..c4bcf6979 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -963,6 +963,24 @@ namespace FlaxEngine return value; } + /// + /// Returns the length of a vector. + /// + /// The vector to get the length from. + public static Real Length(Vector3 vector) + { + return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); + } + + /// + /// Returns the length squared of a vector. + /// + /// The vector to get the length squared from. + public static Real LengthSquared(Vector3 vector) + { + return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z; + } + /// /// Makes sure that Length of the output vector is always below max and above 0. /// From cb460af2646090718b7bb30c6df652ba91f3d139 Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Tue, 19 Sep 2023 19:29:59 +0200 Subject: [PATCH 12/54] Revert last feature since feature already exists --- Source/Engine/Core/Math/Vector2.cs | 18 ------------------ Source/Engine/Core/Math/Vector3.cs | 18 ------------------ 2 files changed, 36 deletions(-) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index e953acfd6..568c51764 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -821,24 +821,6 @@ namespace FlaxEngine return value; } - /// - /// Returns the length of a vector. - /// - /// The vector to get the length from. - public static Real Length(Vector2 vector) - { - return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y); - } - - /// - /// Returns the length squared of a vector. - /// - /// The vector to get the length squared from. - public static Real LengthSquared(Vector2 vector) - { - return vector.X * vector.X + vector.Y * vector.Y; - } - /// /// Makes sure that Length of the output vector is always below max and above 0. /// diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index c4bcf6979..0ad557a32 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -963,24 +963,6 @@ namespace FlaxEngine return value; } - /// - /// Returns the length of a vector. - /// - /// The vector to get the length from. - public static Real Length(Vector3 vector) - { - return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); - } - - /// - /// Returns the length squared of a vector. - /// - /// The vector to get the length squared from. - public static Real LengthSquared(Vector3 vector) - { - return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z; - } - /// /// Makes sure that Length of the output vector is always below max and above 0. /// From 35ee890f9fcc725ec2188ce4ea554d853eaf758e Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Tue, 19 Sep 2023 19:33:25 +0200 Subject: [PATCH 13/54] Fix in typo, should be length instead of magnitude --- Source/Engine/Core/Math/Vector3.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 0ad557a32..59d1f63db 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -1092,13 +1092,13 @@ namespace FlaxEngine Real maxChangeSpeed = maxSpeed * smoothTime; Real changeSq = maxChangeSpeed * maxChangeSpeed; - Real sqrMag = change_x * change_x + change_y * change_y + change_z * change_z; - if (sqrMag > changeSq) + Real sqrLen = change_x * change_x + change_y * change_y + change_z * change_z; + if (sqrLen > changeSq) { - var mag = (Real)Math.Sqrt(sqrMag); - change_x = change_x / mag * maxChangeSpeed; - change_y = change_y / mag * maxChangeSpeed; - change_z = change_z / mag * maxChangeSpeed; + var len = (Real)Math.Sqrt(sqrLen); + change_x = change_x / len * maxChangeSpeed; + change_y = change_y / len * maxChangeSpeed; + change_z = change_z / len * maxChangeSpeed; } target.X = current.X - change_x; From 21c742bd8a2d2b5f55d916649d9fab1d75af8586 Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Thu, 21 Sep 2023 14:54:57 +0200 Subject: [PATCH 14/54] Customizable statusbar --- Source/Editor/Editor.cs | 6 ++- Source/Editor/GUI/StatusBar.cs | 2 +- .../Editor/Modules/ProgressReportingModule.cs | 1 + Source/Editor/Modules/UIModule.cs | 16 ++++++-- Source/Editor/Options/OptionsModule.cs | 9 +++++ Source/Engine/Scripting/Scripting.cs | 8 ++++ Source/Engine/UI/GUI/Style.cs | 38 +++++++++++++++++++ 7 files changed, 74 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 7f0359331..308e40bc1 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -568,7 +568,8 @@ namespace FlaxEditor BackgroundColorSelected = Color.Transparent, BorderColorHighlighted = Color.Transparent, Text = "Save Now", - TooltipText = "Saves now and restarts the auto save timer." + TooltipText = "Saves now and restarts the auto save timer.", + TextColor = Style.Current.Statusbar.TextColor }; _saveNowButton.LocalX += 120; _saveNowButton.Clicked += () => _autoSaveNow = true; @@ -590,7 +591,8 @@ namespace FlaxEditor BackgroundColorSelected = Color.Transparent, BorderColorHighlighted = Color.Transparent, Text = "Cancel", - TooltipText = "Cancels this auto save." + TooltipText = "Cancels this auto save.", + TextColor = Style.Current.Statusbar.TextColor }; _cancelSaveButton.LocalX += 180; _cancelSaveButton.Clicked += () => diff --git a/Source/Editor/GUI/StatusBar.cs b/Source/Editor/GUI/StatusBar.cs index f8f7ae839..93c8f7218 100644 --- a/Source/Editor/GUI/StatusBar.cs +++ b/Source/Editor/GUI/StatusBar.cs @@ -33,7 +33,7 @@ namespace FlaxEditor.GUI /// /// Gets or sets the status text color /// - public Color TextColor { get; set; } = Style.Current.Foreground; + public Color TextColor { get; set; } = Style.Current.Statusbar.TextColor; /// /// Initializes a new instance of the class. diff --git a/Source/Editor/Modules/ProgressReportingModule.cs b/Source/Editor/Modules/ProgressReportingModule.cs index 16acd7f8b..22ae5ea98 100644 --- a/Source/Editor/Modules/ProgressReportingModule.cs +++ b/Source/Editor/Modules/ProgressReportingModule.cs @@ -129,6 +129,7 @@ namespace FlaxEditor.Modules else { Editor.UI.UpdateProgress(string.Empty, 0); + Editor.UI.UpdateStatusBar(); } } diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index 08ec09de8..a4a96d075 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -279,9 +279,9 @@ namespace FlaxEditor.Modules Color color; if (Editor.StateMachine.IsPlayMode) - color = Color.OrangeRed; + color = Style.Current.Statusbar.PlayMode; else - color = Style.Current.BackgroundSelected; + color = Style.Current.Statusbar.Normal; string text; if (_statusMessages != null && _statusMessages.Count != 0) @@ -293,6 +293,11 @@ namespace FlaxEditor.Modules else text = "Ready"; + if(ProgressVisible) + { + color = Style.Current.Statusbar.Loading; + } + StatusBar.Text = text; StatusBar.StatusColor = color; _contentStats = contentStats; @@ -338,7 +343,7 @@ namespace FlaxEditor.Modules internal void ProgressFailed(string message) { _progressFailed = true; - StatusBar.StatusColor = Color.Red; + StatusBar.StatusColor = Style.Current.Statusbar.Failed; StatusBar.Text = message; _outputLogButton.Visible = true; } @@ -391,6 +396,10 @@ namespace FlaxEditor.Modules { UpdateStatusBar(); } + else if(ProgressVisible) + { + UpdateStatusBar(); + } } private class CustomWindowBorderControl : Control @@ -753,6 +762,7 @@ namespace FlaxEditor.Modules AnchorPreset = AnchorPresets.HorizontalStretchMiddle, Parent = progressPanel, Offsets = new Margin(progressBarRightMargin, progressBarWidth + progressBarLeftMargin + progressBarRightMargin, 0, 0), + TextColor = Style.Current.Statusbar.TextColor }; UpdateStatusBar(); diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index 68aa11626..4584395be 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -244,6 +244,15 @@ namespace FlaxEditor.Options CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC), ProgressNormal = Color.FromBgra(0xFF0ad328), + Statusbar = new Style.StatusbarStyle() + { + TextColor = Color.White, + Normal = Color.FromBgra(0xFF007ACC), + PlayMode = Color.ParseHex("#2f9135"), + Failed = Color.ParseHex("#9c2424"), + Loading = Color.ParseHex("#2d2d30") + }, + // Fonts FontTitle = options.Interface.TitleFont.GetFont(), FontLarge = options.Interface.LargeFont.GetFont(), diff --git a/Source/Engine/Scripting/Scripting.cs b/Source/Engine/Scripting/Scripting.cs index 68da64bf7..4215f09b3 100644 --- a/Source/Engine/Scripting/Scripting.cs +++ b/Source/Engine/Scripting/Scripting.cs @@ -277,6 +277,14 @@ namespace FlaxEngine TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46), CollectionBackgroundColor = Color.FromBgra(0x14CCCCCC), SharedTooltip = new Tooltip(), + Statusbar = new Style.StatusbarStyle() + { + TextColor = Color.White, + Normal = Color.FromBgra(0xFF007ACC), + PlayMode = Color.ParseHex("#2f9135"), + Failed = Color.ParseHex("#9c2424"), + Loading = Color.ParseHex("#2d2d30") + } }; style.DragWindow = style.BackgroundSelected * 0.7f; diff --git a/Source/Engine/UI/GUI/Style.cs b/Source/Engine/UI/GUI/Style.cs index fac65e22f..c98c37b78 100644 --- a/Source/Engine/UI/GUI/Style.cs +++ b/Source/Engine/UI/GUI/Style.cs @@ -164,6 +164,12 @@ namespace FlaxEngine.GUI [EditorOrder(200)] public Color ProgressNormal; + /// + /// The status bar style + /// + [EditorOrder(210)] + public StatusbarStyle Statusbar; + /// /// The arrow right icon. /// @@ -241,5 +247,37 @@ namespace FlaxEngine.GUI /// [EditorOrder(340)] public Tooltip SharedTooltip; + + /// + /// Style for the Statusbar + /// + [System.Serializable, ShowInEditor] + public struct StatusbarStyle + { + /// + /// Color of the text in the Statusbar + /// + public Color TextColor; + + /// + /// Color of the Statusbar in its default state + /// + public Color Normal; + + /// + /// Color of the Statusbar when in Play Mode + /// + public Color PlayMode; + + /// + /// Color of the Statusbar when in loading state (e.g. when importing assets) + /// + public Color Loading; + + /// + /// Color of the Statusbar in its failed state (e.g. with compilation errors) + /// + public Color Failed; + } } } From 80a3bb2ae21bc93d6f6559103a29b46e2fcedc6f Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Thu, 21 Sep 2023 17:10:49 +0200 Subject: [PATCH 15/54] Replaced string color lookups --- Source/Editor/Options/OptionsModule.cs | 6 +++--- Source/Engine/Scripting/Scripting.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index 4584395be..05a75fa4a 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -248,9 +248,9 @@ namespace FlaxEditor.Options { TextColor = Color.White, Normal = Color.FromBgra(0xFF007ACC), - PlayMode = Color.ParseHex("#2f9135"), - Failed = Color.ParseHex("#9c2424"), - Loading = Color.ParseHex("#2d2d30") + PlayMode = Color.FromBgra(0xFF2F9135), + Failed = Color.FromBgra(0xFF9C2424), + Loading = Color.FromBgra(0xFF2D2D30) }, // Fonts diff --git a/Source/Engine/Scripting/Scripting.cs b/Source/Engine/Scripting/Scripting.cs index 4215f09b3..7e3226412 100644 --- a/Source/Engine/Scripting/Scripting.cs +++ b/Source/Engine/Scripting/Scripting.cs @@ -281,9 +281,9 @@ namespace FlaxEngine { TextColor = Color.White, Normal = Color.FromBgra(0xFF007ACC), - PlayMode = Color.ParseHex("#2f9135"), - Failed = Color.ParseHex("#9c2424"), - Loading = Color.ParseHex("#2d2d30") + PlayMode = Color.FromBgra(0xFF2F9135), + Failed = Color.FromBgra(0xFF9C2424), + Loading = Color.FromBgra(0xFF2D2D30) } }; style.DragWindow = style.BackgroundSelected * 0.7f; From 5fc9176ce7110030a96c728a46d1eb9e37765200 Mon Sep 17 00:00:00 2001 From: davevanegdom Date: Thu, 21 Sep 2023 23:18:46 +0200 Subject: [PATCH 16/54] Removed customization for "Normal" and "TextColor" --- Source/Editor/Editor.cs | 6 ++---- Source/Editor/GUI/StatusBar.cs | 2 +- Source/Editor/Modules/UIModule.cs | 5 ++--- Source/Editor/Options/OptionsModule.cs | 2 -- Source/Engine/Scripting/Scripting.cs | 2 -- Source/Engine/UI/GUI/Style.cs | 10 ---------- 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 308e40bc1..7f0359331 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -568,8 +568,7 @@ namespace FlaxEditor BackgroundColorSelected = Color.Transparent, BorderColorHighlighted = Color.Transparent, Text = "Save Now", - TooltipText = "Saves now and restarts the auto save timer.", - TextColor = Style.Current.Statusbar.TextColor + TooltipText = "Saves now and restarts the auto save timer." }; _saveNowButton.LocalX += 120; _saveNowButton.Clicked += () => _autoSaveNow = true; @@ -591,8 +590,7 @@ namespace FlaxEditor BackgroundColorSelected = Color.Transparent, BorderColorHighlighted = Color.Transparent, Text = "Cancel", - TooltipText = "Cancels this auto save.", - TextColor = Style.Current.Statusbar.TextColor + TooltipText = "Cancels this auto save." }; _cancelSaveButton.LocalX += 180; _cancelSaveButton.Clicked += () => diff --git a/Source/Editor/GUI/StatusBar.cs b/Source/Editor/GUI/StatusBar.cs index 93c8f7218..f8f7ae839 100644 --- a/Source/Editor/GUI/StatusBar.cs +++ b/Source/Editor/GUI/StatusBar.cs @@ -33,7 +33,7 @@ namespace FlaxEditor.GUI /// /// Gets or sets the status text color /// - public Color TextColor { get; set; } = Style.Current.Statusbar.TextColor; + public Color TextColor { get; set; } = Style.Current.Foreground; /// /// Initializes a new instance of the class. diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index a4a96d075..69e610c07 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -281,7 +281,7 @@ namespace FlaxEditor.Modules if (Editor.StateMachine.IsPlayMode) color = Style.Current.Statusbar.PlayMode; else - color = Style.Current.Statusbar.Normal; + color = Style.Current.BackgroundSelected; string text; if (_statusMessages != null && _statusMessages.Count != 0) @@ -761,8 +761,7 @@ namespace FlaxEditor.Modules HorizontalAlignment = TextAlignment.Far, AnchorPreset = AnchorPresets.HorizontalStretchMiddle, Parent = progressPanel, - Offsets = new Margin(progressBarRightMargin, progressBarWidth + progressBarLeftMargin + progressBarRightMargin, 0, 0), - TextColor = Style.Current.Statusbar.TextColor + Offsets = new Margin(progressBarRightMargin, progressBarWidth + progressBarLeftMargin + progressBarRightMargin, 0, 0) }; UpdateStatusBar(); diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index 05a75fa4a..c2d744239 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -246,8 +246,6 @@ namespace FlaxEditor.Options Statusbar = new Style.StatusbarStyle() { - TextColor = Color.White, - Normal = Color.FromBgra(0xFF007ACC), PlayMode = Color.FromBgra(0xFF2F9135), Failed = Color.FromBgra(0xFF9C2424), Loading = Color.FromBgra(0xFF2D2D30) diff --git a/Source/Engine/Scripting/Scripting.cs b/Source/Engine/Scripting/Scripting.cs index 7e3226412..d43804586 100644 --- a/Source/Engine/Scripting/Scripting.cs +++ b/Source/Engine/Scripting/Scripting.cs @@ -279,8 +279,6 @@ namespace FlaxEngine SharedTooltip = new Tooltip(), Statusbar = new Style.StatusbarStyle() { - TextColor = Color.White, - Normal = Color.FromBgra(0xFF007ACC), PlayMode = Color.FromBgra(0xFF2F9135), Failed = Color.FromBgra(0xFF9C2424), Loading = Color.FromBgra(0xFF2D2D30) diff --git a/Source/Engine/UI/GUI/Style.cs b/Source/Engine/UI/GUI/Style.cs index c98c37b78..8f34a703c 100644 --- a/Source/Engine/UI/GUI/Style.cs +++ b/Source/Engine/UI/GUI/Style.cs @@ -254,16 +254,6 @@ namespace FlaxEngine.GUI [System.Serializable, ShowInEditor] public struct StatusbarStyle { - /// - /// Color of the text in the Statusbar - /// - public Color TextColor; - - /// - /// Color of the Statusbar in its default state - /// - public Color Normal; - /// /// Color of the Statusbar when in Play Mode /// From d0679c1f9bd6c7c1dfef3ac4808f5e9e3cfc025a Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Fri, 22 Sep 2023 15:28:46 +0200 Subject: [PATCH 17/54] - Made Visject connection bezier curves bend around nodes --- Source/Editor/Surface/Elements/OutputBox.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 67b6e8409..2a2b87486 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -33,11 +33,20 @@ namespace FlaxEditor.Surface.Elements /// The connection thickness. public static void DrawConnection(ref Float2 start, ref Float2 end, ref Color color, float thickness = 1) { + // Control points parameters + const float minControlLength = 100f; + const float maxControlLength = 150f; + var dst = (end - start).Length; + var yDst = Mathf.Abs(start.Y - end.Y); + // Calculate control points - var dst = (end - start) * new Float2(0.5f, 0.05f); - var control1 = new Float2(start.X + dst.X, start.Y + dst.Y); - var control2 = new Float2(end.X - dst.X, end.Y + dst.Y); - + var minControlDst = dst * 0.5f; + var maxControlDst = Mathf.Max(Mathf.Min(maxControlLength, dst), minControlLength); + var controlDst = Mathf.Lerp(minControlDst, maxControlDst, Mathf.Clamp(yDst / minControlLength, 0f, 1f)); + + var control1 = new Float2(start.X + controlDst, start.Y); + var control2 = new Float2(end.X - controlDst, end.Y); + // Draw line Render2D.DrawBezier(start, control1, control2, end, color, thickness); From 15859134a3fb59c14fda1d17f0d80aa1eee04be0 Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 17:33:17 +0200 Subject: [PATCH 18/54] Refactor splash screen quotes Removed bad and weird quotes, added nice ones. --- Source/Editor/Windows/SplashScreen.cpp | 37 +++++++------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index 7cf7a7f78..c682210cf 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -18,34 +18,30 @@ const Char* SplashScreenQuotes[] = TEXT("Loading"), TEXT("Unloading"), TEXT("Reloading"), - TEXT("Reloading gun"), + TEXT("Downloading more RAM"), TEXT("Consuming your RAM"), TEXT("Burning your CPU"), - TEXT("#BetterThanUnity"), TEXT("Rendering buttons"), TEXT("Collecting crash data"), - TEXT("Downloading porn"), #if PLATFORM_WINDOWS - TEXT("Removing 'C:\\Windows\\'"), + TEXT("We're getting everything ready for you."), #elif PLATFORM_LINUX - TEXT("Time to switch to Windows?"), - TEXT("Installing Windows 10"), + TEXT("don't compare Macbooks to oranges."), + TEXT("trying to exit vim"), + TEXT("sudo flax --loadproject"), #elif PLATFORM_MAC - TEXT("Hacking your iPhone"), + TEXT("don't compare Macbooks to oranges."), TEXT("Why does macbook heat up?\nBecause it doesn't have windows"), #endif - TEXT("Kappa!"), TEXT("How you doin'?"), TEXT("Why so serious?"), TEXT("Bond. James Bond."), TEXT("To infinity and beyond!"), TEXT("Houston, we have a problem"), - TEXT("NotImplementedEngineException"), TEXT("Made in Poland"), TEXT("We like you"), TEXT("Compiling the compiler"), TEXT("Flax it up!"), - TEXT("Fun fact: Fortnite runs on Flax"), TEXT("Toss a coin to your Witcher!!!"), TEXT("Holy Moly!"), TEXT("Just Read the Instructions"), @@ -60,7 +56,6 @@ const Char* SplashScreenQuotes[] = TEXT("They see me loadin'"), TEXT("Loadin' loadin' and loadin' loadin'"), TEXT("Procedurally generating buttons"), - TEXT("Out of Memory Exception!"), TEXT("Running Big Bang simulation"), TEXT("Calculating infinity"), TEXT("Dividing infinity by zero"), @@ -70,10 +65,7 @@ const Char* SplashScreenQuotes[] = TEXT("Whatever you do, do it well.\n~Walt Disney"), TEXT("Here's Johnny!"), TEXT("Did you see that? No... I don't think so"), - TEXT("Collecting unreal power"), TEXT("Stay safe, friend"), - TEXT("trolololololololololololo"), - TEXT("xD"), TEXT("Come to the dark side"), TEXT("Flax Facts: This is a loading screen"), TEXT("Don't Stop Me Now"), @@ -87,7 +79,6 @@ const Char* SplashScreenQuotes[] = TEXT("A martini. Shaken, not stirred"), TEXT("Hasta la vista, baby"), TEXT("Winter is coming"), - TEXT("You know nothing, Jon Snow"), TEXT("Create something awesome!"), TEXT("Well Polished Engine"), TEXT("Error 404: Joke Not Found"), @@ -96,45 +87,37 @@ const Char* SplashScreenQuotes[] = TEXT("Loading Simulation"), TEXT("Get ready for a surprise!"), TEXT("Coffee is my fuel"), - TEXT("Installing a free copy of Cyberpunk 2077"), TEXT("With great power comes great electricity bill"), TEXT("Flax was made in the same city as Witcher 3"), TEXT("So JavaScript is a scripting version of Java"), TEXT("Good things take time.\n~Someone"), - TEXT("Get shit done"), TEXT("Hold Tight! Loading Flax"), TEXT("That's one small step for a man,\none giant leap for mankind"), TEXT("Remember to save your work frequently"), TEXT("In case of fire:\ngit commit, git push, leave building"), TEXT("Keep calm and make games"), TEXT("You're breathtaking!!!"), - TEXT("Do regular dogs see police dogs & think,\nOh no it's a cop?"), - TEXT("Dear Santa,\nDefine naughty."), TEXT("Blah, blah"), TEXT("My PRECIOUS!!!!"), TEXT("YOU SHALL NOT PASS!"), TEXT("You have my bow.\nAnd my axe!"), TEXT("To the bridge of Khazad-dum."), - TEXT("One ring to rule them all.\nOne ring to find them."), - TEXT("Ladies and gentelman, we got him"), - TEXT("Cyberpunk of game engines"), - TEXT("That's what she said"), TEXT("Compiling Shaders (93,788)"), TEXT("Hello There"), TEXT("BAGUETTE"), - TEXT("All we had to do was follow the damn train, CJ"), TEXT("Here we go again"), TEXT("@everyone"), TEXT("Potato"), TEXT("Python is a programming snek"), TEXT("Flax will start when pigs will fly"), - TEXT("I'm the android sent by CyberLife"), - TEXT("Fancy-ass ray tracing, rtx on, lighting"), TEXT("ZOINKS"), TEXT("Scooby dooby doo"), TEXT("You shall not load!"), TEXT("The roof, the roof, the roof is on fire!"), - TEXT("I've seen better documentation...\nFrom ransomware gangs!"), + TEXT("Slava Ukraini!"), + TEXT("RTX off... for now!"), + TEXT("Increasing Fiber count"), + TEXT("Now this is podracing!"), TEXT("Slava Ukraini!"), }; From b82436cf4e6f9dd3b9c3abd08c9db0890eb3bd51 Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 17:57:19 +0200 Subject: [PATCH 19/54] Refactor splash screen quotes removed bad ones and added more nice quotes. --- Source/Editor/Windows/SplashScreen.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index c682210cf..f26e45e81 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -26,12 +26,13 @@ const Char* SplashScreenQuotes[] = #if PLATFORM_WINDOWS TEXT("We're getting everything ready for you."), #elif PLATFORM_LINUX - TEXT("don't compare Macbooks to oranges."), - TEXT("trying to exit vim"), - TEXT("sudo flax --loadproject"), + TEXT("Don't compare Macbooks to oranges."), + TEXT("Trying to exit vim"), + TEXT("Sudo flax --loadproject"), #elif PLATFORM_MAC TEXT("don't compare Macbooks to oranges."), TEXT("Why does macbook heat up?\nBecause it doesn't have windows"), + TEXT("Starting Direc... um, Vulkan renderer."), #endif TEXT("How you doin'?"), TEXT("Why so serious?"), @@ -73,7 +74,6 @@ const Char* SplashScreenQuotes[] = TEXT("Made with Flax"), TEXT("This is the way"), TEXT("The quick brown fox jumps over the lazy dog"), - TEXT("Hit The Road Jack"), TEXT("You have 7 lives left"), TEXT("May the Force be with you"), TEXT("A martini. Shaken, not stirred"), @@ -84,7 +84,7 @@ const Char* SplashScreenQuotes[] = TEXT("Error 404: Joke Not Found"), TEXT("Rushing B"), TEXT("Putting pineapple on pizza"), - TEXT("Loading Simulation"), + TEXT("Entering the Matrix"), TEXT("Get ready for a surprise!"), TEXT("Coffee is my fuel"), TEXT("With great power comes great electricity bill"), @@ -102,7 +102,8 @@ const Char* SplashScreenQuotes[] = TEXT("YOU SHALL NOT PASS!"), TEXT("You have my bow.\nAnd my axe!"), TEXT("To the bridge of Khazad-dum."), - TEXT("Compiling Shaders (93,788)"), + TEXT("That's what she said"), + TEXT("We could be compiling shaders here"), TEXT("Hello There"), TEXT("BAGUETTE"), TEXT("Here we go again"), @@ -119,6 +120,9 @@ const Char* SplashScreenQuotes[] = TEXT("Increasing Fiber count"), TEXT("Now this is podracing!"), TEXT("Slava Ukraini!"), + TEXT("Weird flax, but ok"), + TEXT("Reticulating Splines"), + TEXT("Discombobulating"), }; SplashScreen::~SplashScreen() From 7b051ce827bf1169625c683685158c4c2c300dde Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 18:07:42 +0200 Subject: [PATCH 20/54] Update SplashScreen.cpp --- Source/Editor/Windows/SplashScreen.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index f26e45e81..e986257f6 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -119,7 +119,6 @@ const Char* SplashScreenQuotes[] = TEXT("RTX off... for now!"), TEXT("Increasing Fiber count"), TEXT("Now this is podracing!"), - TEXT("Slava Ukraini!"), TEXT("Weird flax, but ok"), TEXT("Reticulating Splines"), TEXT("Discombobulating"), From 45231a8b04ec1eadca008122261e290c63de8a8a Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 18:13:31 +0200 Subject: [PATCH 21/54] Update SplashScreen.cpp --- Source/Editor/Windows/SplashScreen.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index e986257f6..a2d180a63 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -26,7 +26,6 @@ const Char* SplashScreenQuotes[] = #if PLATFORM_WINDOWS TEXT("We're getting everything ready for you."), #elif PLATFORM_LINUX - TEXT("Don't compare Macbooks to oranges."), TEXT("Trying to exit vim"), TEXT("Sudo flax --loadproject"), #elif PLATFORM_MAC From 25708e2875377a743936404c2428a3d767191704 Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 19:01:37 +0200 Subject: [PATCH 22/54] add more quotes --- Source/Editor/Windows/SplashScreen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index a2d180a63..a2e299347 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -26,6 +26,7 @@ const Char* SplashScreenQuotes[] = #if PLATFORM_WINDOWS TEXT("We're getting everything ready for you."), #elif PLATFORM_LINUX + TEXT("Try it on a Raspberry"), TEXT("Trying to exit vim"), TEXT("Sudo flax --loadproject"), #elif PLATFORM_MAC @@ -101,6 +102,7 @@ const Char* SplashScreenQuotes[] = TEXT("YOU SHALL NOT PASS!"), TEXT("You have my bow.\nAnd my axe!"), TEXT("To the bridge of Khazad-dum."), + TEXT("One ring to rule them all.\nOne ring to find them."), TEXT("That's what she said"), TEXT("We could be compiling shaders here"), TEXT("Hello There"), @@ -121,6 +123,9 @@ const Char* SplashScreenQuotes[] = TEXT("Weird flax, but ok"), TEXT("Reticulating Splines"), TEXT("Discombobulating"), + TEXT("Who is signing all these integers?!"), + TEXT("Flax fact: Flax was called Celelej once."), + TEXT("Changing text overflow setti-"), }; SplashScreen::~SplashScreen() From d11e3b5bd4d4c2678c6c02e362cd6c6d238c6aa5 Mon Sep 17 00:00:00 2001 From: Meh Date: Fri, 22 Sep 2023 19:25:16 +0200 Subject: [PATCH 23/54] Update SplashScreen.cpp --- Source/Editor/Windows/SplashScreen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index a2e299347..d2371a540 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -34,6 +34,7 @@ const Char* SplashScreenQuotes[] = TEXT("Why does macbook heat up?\nBecause it doesn't have windows"), TEXT("Starting Direc... um, Vulkan renderer."), #endif + TEXT("Kappa!"), TEXT("How you doin'?"), TEXT("Why so serious?"), TEXT("Bond. James Bond."), From 1e3debf1ec0dca404733d549c3f0aabe3bae02a6 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sun, 24 Sep 2023 11:37:14 -0400 Subject: [PATCH 24/54] Remake #1413 --- Source/Editor/Windows/Assets/CollisionDataWindow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Editor/Windows/Assets/CollisionDataWindow.cs b/Source/Editor/Windows/Assets/CollisionDataWindow.cs index cc1daa45b..85d4bbecc 100644 --- a/Source/Editor/Windows/Assets/CollisionDataWindow.cs +++ b/Source/Editor/Windows/Assets/CollisionDataWindow.cs @@ -200,6 +200,7 @@ namespace FlaxEditor.Windows.Assets ViewportCamera = new FPSCamera(), Parent = _split.Panel1 }; + _preview.Task.ViewFlags = ViewFlags.Reflections | ViewFlags.DebugDraw | ViewFlags.AO | ViewFlags.DirectionalLights | ViewFlags.SkyLights | ViewFlags.Shadows | ViewFlags.SpecularLight | ViewFlags.AntiAliasing | ViewFlags.ToneMapping; // Asset properties _propertiesPresenter = new CustomEditorPresenter(null); From 0de31f630f0758d6f240eba6d0726dc53bbae4da Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Sun, 24 Sep 2023 18:40:34 +0200 Subject: [PATCH 25/54] - Moved control point calculation into its own function since multiple parts of the code depend on it - 'DrawConnection' function now calls the control point calculation function - 'IntersectsConnection' function now calls the control point calculation function --- Source/Editor/Surface/Elements/OutputBox.cs | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 2a2b87486..cf78b559c 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -33,19 +33,8 @@ namespace FlaxEditor.Surface.Elements /// The connection thickness. public static void DrawConnection(ref Float2 start, ref Float2 end, ref Color color, float thickness = 1) { - // Control points parameters - const float minControlLength = 100f; - const float maxControlLength = 150f; - var dst = (end - start).Length; - var yDst = Mathf.Abs(start.Y - end.Y); - // Calculate control points - var minControlDst = dst * 0.5f; - var maxControlDst = Mathf.Max(Mathf.Min(maxControlLength, dst), minControlLength); - var controlDst = Mathf.Lerp(minControlDst, maxControlDst, Mathf.Clamp(yDst / minControlLength, 0f, 1f)); - - var control1 = new Float2(start.X + controlDst, start.Y); - var control2 = new Float2(end.X - controlDst, end.Y); + CalculateBezierControlPoints(start, end, out var control1, out var control2); // Draw line Render2D.DrawBezier(start, control1, control2, end, color, thickness); @@ -58,6 +47,23 @@ namespace FlaxEditor.Surface.Elements */ } + private static void CalculateBezierControlPoints(Float2 start, Float2 end, out Float2 control1, out Float2 control2) + { + // Control points parameters + const float minControlLength = 100f; + const float maxControlLength = 150f; + var dst = (end - start).Length; + var yDst = Mathf.Abs(start.Y - end.Y); + + // Calculate control points + var minControlDst = dst * 0.5f; + var maxControlDst = Mathf.Max(Mathf.Min(maxControlLength, dst), minControlLength); + var controlDst = Mathf.Lerp(minControlDst, maxControlDst, Mathf.Clamp(yDst / minControlLength, 0f, 1f)); + + control1 = new Float2(start.X + controlDst, start.Y); + control2 = new Float2(end.X - controlDst, end.Y); + } + /// /// Checks if a point intersects a connection /// @@ -84,13 +90,9 @@ namespace FlaxEditor.Surface.Elements float offset = Mathf.Sign(end.Y - start.Y) * distance; if ((point.Y - (start.Y - offset)) * ((end.Y + offset) - point.Y) < 0) return false; - - // Taken from the Render2D.DrawBezier code + float squaredDistance = distance; - - var dst = (end - start) * new Float2(0.5f, 0.05f); - var control1 = new Float2(start.X + dst.X, start.Y + dst.Y); - var control2 = new Float2(end.X - dst.X, end.Y + dst.Y); + CalculateBezierControlPoints(start, end, out var control1, out var control2); var d1 = control1 - start; var d2 = control2 - control1; From ea201b617326949d26b310b61ab56872a77ecca7 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Mon, 25 Sep 2023 22:05:37 +0300 Subject: [PATCH 26/54] Fix null check in SceneAnimationWindow The null-conditional operator checks for reference equality of the Object, but doesn't check the unmanaged pointer validity. --- Source/Editor/Windows/Assets/SceneAnimationWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs index 824928743..0d7fa1c78 100644 --- a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs +++ b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs @@ -821,7 +821,7 @@ namespace FlaxEditor.Windows.Assets if (_timeline.IsModified) { var time = _timeline.CurrentTime; - var isPlaying = _previewPlayer?.IsPlaying ?? false; + var isPlaying = _previewPlayer != null ? _previewPlayer.IsPlaying : false; _timeline.Save(_asset); if (_previewButton.Checked && _previewPlayer != null) { From 58445f04c4aa3cd6d06e5212d895287c03e8bc1b Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Mon, 25 Sep 2023 23:06:14 +0300 Subject: [PATCH 27/54] Fix potential incorrect null checks in `FlaxEngine.Object`s The null-conditional operator checks for reference equality of the Object, but doesn't check the validity of the unmanaged pointer. This check is corrected in cases where the object was not immediately returned from the bindings layer and may have been destroyed earlier. --- .../CustomEditors/Dedicated/ScriptsEditor.cs | 4 ++-- Source/Editor/EditorAssets.cs | 4 +++- .../Editor/GUI/Timeline/SceneAnimationTimeline.cs | 4 ++-- Source/Editor/Tools/Foliage/FoliageTypesTab.cs | 2 +- Source/Editor/Tools/Foliage/PaintTab.cs | 2 +- Source/Editor/Tools/VertexPainting.cs | 2 +- Source/Editor/Undo/Actions/PasteActorsAction.cs | 2 +- .../Viewport/Previews/ParticleSystemPreview.cs | 4 ++-- Source/Editor/Viewport/Previews/TexturePreview.cs | 8 ++++---- .../Windows/Assets/MaterialInstanceWindow.cs | 14 +++++++++----- Source/Editor/Windows/Assets/ModelWindow.cs | 6 +++--- .../Editor/Windows/Assets/ParticleSystemWindow.cs | 2 +- .../Editor/Windows/Assets/SceneAnimationWindow.cs | 2 +- Source/Editor/Windows/Assets/SkinnedModelWindow.cs | 6 +++--- Source/Engine/UI/GUI/Brushes/GPUTextureBrush.cs | 2 +- Source/Engine/UI/GUI/Brushes/TextureBrush.cs | 2 +- Source/Engine/UI/UICanvas.cs | 3 ++- Source/Engine/UI/UIControl.cs | 8 ++++---- 18 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index bf82e19da..acd27d7ef 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -576,8 +576,8 @@ namespace FlaxEditor.CustomEditors.Dedicated return; for (int j = 0; j < e.Length; j++) { - var t1 = scripts[j]?.TypeName; - var t2 = e[j]?.TypeName; + var t1 = scripts[j] != null ? scripts[j].TypeName : null; + var t2 = e[j] != null ? e[j].TypeName : null; if (t1 != t2) return; } diff --git a/Source/Editor/EditorAssets.cs b/Source/Editor/EditorAssets.cs index 7fa920ca6..eb2f21356 100644 --- a/Source/Editor/EditorAssets.cs +++ b/Source/Editor/EditorAssets.cs @@ -36,7 +36,9 @@ namespace FlaxEditor public static void OnEditorOptionsChanged(Options.EditorOptions options) { - var param = _highlightMaterial?.GetParameter("Color"); + if (!_highlightMaterial) + return; + var param = _highlightMaterial.GetParameter("Color"); if (param != null) param.Value = options.Visual.HighlightColor; } diff --git a/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs b/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs index c5989cca5..76b6ca246 100644 --- a/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs +++ b/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs @@ -33,7 +33,7 @@ namespace FlaxEditor.GUI.Timeline /// public SceneAnimationPlayer Player { - get => _player; + get => _player != null ? _player : null; set { if (_player == value) @@ -268,7 +268,7 @@ namespace FlaxEditor.GUI.Timeline /// public override void OnSeek(int frame) { - if (_player?.Animation) + if (_player != null && _player.Animation) { _player.Animation.WaitForLoaded(); _player.Time = frame / _player.Animation.FramesPerSecond; diff --git a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs index 2a51d972c..8934f5058 100644 --- a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs +++ b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs @@ -375,7 +375,7 @@ namespace FlaxEditor.Tools.Foliage private void OnModified() { - Editor.Instance.Scene.MarkSceneEdited(_proxy.Foliage?.Scene); + Editor.Instance.Scene.MarkSceneEdited(_proxy.Foliage != null ? _proxy.Foliage.Scene : null); } private void OnSelectedFoliageChanged() diff --git a/Source/Editor/Tools/Foliage/PaintTab.cs b/Source/Editor/Tools/Foliage/PaintTab.cs index e4f01661b..ba31ca18b 100644 --- a/Source/Editor/Tools/Foliage/PaintTab.cs +++ b/Source/Editor/Tools/Foliage/PaintTab.cs @@ -218,7 +218,7 @@ namespace FlaxEditor.Tools.Foliage private void OnModified() { - Editor.Instance.Scene.MarkSceneEdited(_proxy.Foliage?.Scene); + Editor.Instance.Scene.MarkSceneEdited(_proxy.Foliage != null ? _proxy.Foliage.Scene : null); } private void OnSelectedFoliageChanged() diff --git a/Source/Editor/Tools/VertexPainting.cs b/Source/Editor/Tools/VertexPainting.cs index 0863569c2..6934a754b 100644 --- a/Source/Editor/Tools/VertexPainting.cs +++ b/Source/Editor/Tools/VertexPainting.cs @@ -544,7 +544,7 @@ namespace FlaxEditor.Tools public override bool IsControllingMouse => IsPainting; /// - public override BoundingSphere FocusBounds => _selectedModel?.Sphere ?? base.FocusBounds; + public override BoundingSphere FocusBounds => _selectedModel != null ? _selectedModel.Sphere : base.FocusBounds; /// public override void Update(float dt) diff --git a/Source/Editor/Undo/Actions/PasteActorsAction.cs b/Source/Editor/Undo/Actions/PasteActorsAction.cs index 8b0d040d8..7aee40878 100644 --- a/Source/Editor/Undo/Actions/PasteActorsAction.cs +++ b/Source/Editor/Undo/Actions/PasteActorsAction.cs @@ -144,7 +144,7 @@ namespace FlaxEditor.Actions { var node = nodeParents[i]; var actor = node.Actor; - var parent = actor?.Parent; + var parent = actor != null ? actor.Parent : null; if (parent != null) { bool IsNameValid(string name) diff --git a/Source/Editor/Viewport/Previews/ParticleSystemPreview.cs b/Source/Editor/Viewport/Previews/ParticleSystemPreview.cs index fc7fcdbe1..c6ce5a7b5 100644 --- a/Source/Editor/Viewport/Previews/ParticleSystemPreview.cs +++ b/Source/Editor/Viewport/Previews/ParticleSystemPreview.cs @@ -68,7 +68,7 @@ namespace FlaxEditor.Viewport.Previews /// public bool ShowBounds { - get => _boundsModel?.IsActive ?? false; + get => _boundsModel != null ? _boundsModel.IsActive : false; set { if (value == ShowBounds) @@ -110,7 +110,7 @@ namespace FlaxEditor.Viewport.Previews /// public bool ShowOrigin { - get => _originModel?.IsActive ?? false; + get => _originModel != null ? _originModel.IsActive : false; set { if (value == ShowOrigin) diff --git a/Source/Editor/Viewport/Previews/TexturePreview.cs b/Source/Editor/Viewport/Previews/TexturePreview.cs index a33a61f86..ec10bb019 100644 --- a/Source/Editor/Viewport/Previews/TexturePreview.cs +++ b/Source/Editor/Viewport/Previews/TexturePreview.cs @@ -500,7 +500,7 @@ namespace FlaxEditor.Viewport.Previews /// protected override void CalculateTextureRect(out Rectangle rect) { - CalculateTextureRect(_asset?.Size ?? new Float2(100), Size, out rect); + CalculateTextureRect(_asset != null ? _asset.Size : new Float2(100), Size, out rect); } /// @@ -549,7 +549,7 @@ namespace FlaxEditor.Viewport.Previews /// protected override void CalculateTextureRect(out Rectangle rect) { - CalculateTextureRect(_asset?.Size ?? new Float2(100), Size, out rect); + CalculateTextureRect(_asset != null ? _asset.Size : new Float2(100), Size, out rect); } /// @@ -604,7 +604,7 @@ namespace FlaxEditor.Viewport.Previews /// protected override void CalculateTextureRect(out Rectangle rect) { - CalculateTextureRect(_asset?.Size ?? new Float2(100), Size, out rect); + CalculateTextureRect(_asset != null ? _asset.Size : new Float2(100), Size, out rect); } /// @@ -659,7 +659,7 @@ namespace FlaxEditor.Viewport.Previews /// protected override void CalculateTextureRect(out Rectangle rect) { - CalculateTextureRect(_asset?.Size ?? new Float2(100), Size, out rect); + CalculateTextureRect(_asset != null ? _asset.Size : new Float2(100), Size, out rect); } /// diff --git a/Source/Editor/Windows/Assets/MaterialInstanceWindow.cs b/Source/Editor/Windows/Assets/MaterialInstanceWindow.cs index d5ab2ae8a..5f1273999 100644 --- a/Source/Editor/Windows/Assets/MaterialInstanceWindow.cs +++ b/Source/Editor/Windows/Assets/MaterialInstanceWindow.cs @@ -69,7 +69,7 @@ namespace FlaxEditor.Windows.Assets [EditorDisplay("General"), Tooltip("The base material used to override it's properties")] public MaterialBase BaseMaterial { - get => Window?.Asset?.BaseMaterial; + get => Window?.Asset != null ? Window?.Asset.BaseMaterial : null; set { var asset = Window?.Asset; @@ -101,10 +101,12 @@ namespace FlaxEditor.Windows.Assets [HideInEditor] public object[] Values { - get => Window?.Asset?.Parameters.Select(x => x.Value).ToArray(); + get => Window?.Asset != null ? Window?.Asset.Parameters.Select(x => x.Value).ToArray() : null; set { - var parameters = Window?.Asset?.Parameters; + if (Window?.Asset == null) + return; + var parameters = Window?.Asset.Parameters; if (value != null && parameters != null) { if (value.Length != parameters.Length) @@ -131,9 +133,11 @@ namespace FlaxEditor.Windows.Assets [HideInEditor] public FlaxEngine.Object[] ValuesRef { - get => Window?.Asset?.Parameters.Select(x => x.Value as FlaxEngine.Object).ToArray(); + get => Window?.Asset != null ? Window?.Asset.Parameters.Select(x => x.Value as FlaxEngine.Object).ToArray() : null; set { + if (Window?.Asset == null) + return; var parameters = Window?.Asset?.Parameters; if (value != null && parameters != null) { @@ -293,7 +297,7 @@ namespace FlaxEditor.Windows.Assets var p = (MaterialParameter)e.Tag; // Try to get default value (from the base material) - var pBase = baseMaterial?.GetParameter(p.Name); + var pBase = baseMaterial != null ? baseMaterial.GetParameter(p.Name) : null; if (pBase != null && pBase.ParameterType == p.ParameterType) { valueContainer.SetDefaultValue(pBase.Value); diff --git a/Source/Editor/Windows/Assets/ModelWindow.cs b/Source/Editor/Windows/Assets/ModelWindow.cs index f70f6a3b5..c2764a5a6 100644 --- a/Source/Editor/Windows/Assets/ModelWindow.cs +++ b/Source/Editor/Windows/Assets/ModelWindow.cs @@ -134,7 +134,7 @@ namespace FlaxEditor.Windows.Assets if (Window._skipEffectsGuiEvents) return; - Window._isolateIndex = mesh?.MaterialSlotIndex ?? -1; + Window._isolateIndex = mesh != null ? mesh.MaterialSlotIndex : -1; Window.UpdateEffectsOnAsset(); UpdateEffectsOnUI(); } @@ -144,7 +144,7 @@ namespace FlaxEditor.Windows.Assets if (Window._skipEffectsGuiEvents) return; - Window._highlightIndex = mesh?.MaterialSlotIndex ?? -1; + Window._highlightIndex = mesh != null ? mesh.MaterialSlotIndex : -1; Window.UpdateEffectsOnAsset(); UpdateEffectsOnUI(); } @@ -326,7 +326,7 @@ namespace FlaxEditor.Windows.Assets [EditorOrder(10), EditorDisplay("Materials", EditorDisplayAttribute.InlineStyle)] public MaterialSlot[] MaterialSlots { - get => Asset?.MaterialSlots; + get => Asset != null ? Asset.MaterialSlots : null; set { if (Asset != null) diff --git a/Source/Editor/Windows/Assets/ParticleSystemWindow.cs b/Source/Editor/Windows/Assets/ParticleSystemWindow.cs index 328369680..17eda1358 100644 --- a/Source/Editor/Windows/Assets/ParticleSystemWindow.cs +++ b/Source/Editor/Windows/Assets/ParticleSystemWindow.cs @@ -187,7 +187,7 @@ namespace FlaxEditor.Windows.Assets base.Initialize(layout); var emitterTrack = Values[0] as EmitterTrackProxy; - if (emitterTrack?._effect?.Parameters == null) + if (emitterTrack?._effect == null || emitterTrack?._effect.Parameters == null) return; var group = layout.Group("Parameters"); diff --git a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs index 0d7fa1c78..162944144 100644 --- a/Source/Editor/Windows/Assets/SceneAnimationWindow.cs +++ b/Source/Editor/Windows/Assets/SceneAnimationWindow.cs @@ -792,7 +792,7 @@ namespace FlaxEditor.Windows.Assets { if (_previewButton.Checked) return; - _previewPlayerPicker.Value = _timeline.Player; + _previewPlayerPicker.Value = _timeline.Player != null ? _timeline.Player : null; _cachedPlayerId = _timeline.Player?.ID ?? Guid.Empty; } diff --git a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs index a7ee6e767..d360e5570 100644 --- a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs +++ b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs @@ -151,7 +151,7 @@ namespace FlaxEditor.Windows.Assets if (Window._skipEffectsGuiEvents) return; - Window._isolateIndex = mesh?.MaterialSlotIndex ?? -1; + Window._isolateIndex = mesh != null ? mesh.MaterialSlotIndex : -1; Window.UpdateEffectsOnAsset(); UpdateEffectsOnUI(); } @@ -165,7 +165,7 @@ namespace FlaxEditor.Windows.Assets if (Window._skipEffectsGuiEvents) return; - Window._highlightIndex = mesh?.MaterialSlotIndex ?? -1; + Window._highlightIndex = mesh != null ? mesh.MaterialSlotIndex : -1; Window.UpdateEffectsOnAsset(); UpdateEffectsOnUI(); } @@ -415,7 +415,7 @@ namespace FlaxEditor.Windows.Assets [EditorOrder(10), EditorDisplay("Materials", EditorDisplayAttribute.InlineStyle)] public MaterialSlot[] MaterialSlots { - get => Asset?.MaterialSlots; + get => Asset != null ? Asset.MaterialSlots : null; set { if (Asset != null) diff --git a/Source/Engine/UI/GUI/Brushes/GPUTextureBrush.cs b/Source/Engine/UI/GUI/Brushes/GPUTextureBrush.cs index 9ad9db1d3..d3469670a 100644 --- a/Source/Engine/UI/GUI/Brushes/GPUTextureBrush.cs +++ b/Source/Engine/UI/GUI/Brushes/GPUTextureBrush.cs @@ -37,7 +37,7 @@ namespace FlaxEngine.GUI } /// - public Float2 Size => Texture?.Size ?? Float2.Zero; + public Float2 Size => Texture != null ? Texture.Size : Float2.Zero; /// public void Draw(Rectangle rect, Color color) diff --git a/Source/Engine/UI/GUI/Brushes/TextureBrush.cs b/Source/Engine/UI/GUI/Brushes/TextureBrush.cs index d49e5519b..755f7527b 100644 --- a/Source/Engine/UI/GUI/Brushes/TextureBrush.cs +++ b/Source/Engine/UI/GUI/Brushes/TextureBrush.cs @@ -104,7 +104,7 @@ namespace FlaxEngine.GUI } /// - public Float2 Size => Texture?.Size ?? Float2.Zero; + public Float2 Size => Texture != null ? Texture.Size : Float2.Zero; /// public unsafe void Draw(Rectangle rect, Color color) diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index 8cb43af62..edbec7f7d 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -493,7 +493,8 @@ namespace FlaxEngine if (_renderer) { #if FLAX_EDITOR - _editorTask?.RemoveCustomPostFx(_renderer); + if (_editorTask != null) + _editorTask.RemoveCustomPostFx(_renderer); #endif SceneRenderTask.RemoveGlobalCustomPostFx(_renderer); _renderer.Canvas = null; diff --git a/Source/Engine/UI/UIControl.cs b/Source/Engine/UI/UIControl.cs index dc76122c0..219a4fa4e 100644 --- a/Source/Engine/UI/UIControl.cs +++ b/Source/Engine/UI/UIControl.cs @@ -204,7 +204,7 @@ namespace FlaxEngine up = value; Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right)); if (_control != null) - _control.NavTargetUp = value?.Control; + _control.NavTargetUp = value != null ? value.Control : null; } } @@ -228,7 +228,7 @@ namespace FlaxEngine down = value; Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right)); if (_control != null) - _control.NavTargetDown = value?.Control; + _control.NavTargetDown = value != null ? value.Control : null; } } @@ -252,7 +252,7 @@ namespace FlaxEngine left = value; Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right)); if (_control != null) - _control.NavTargetLeft = value?.Control; + _control.NavTargetLeft = value != null ? value.Control : null; } } @@ -276,7 +276,7 @@ namespace FlaxEngine right = value; Internal_SetNavTargets(__unmanagedPtr, GetUnmanagedPtr(up), GetUnmanagedPtr(down), GetUnmanagedPtr(left), GetUnmanagedPtr(right)); if (_control != null) - _control.NavTargetRight = value?.Control; + _control.NavTargetRight = value != null ? value.Control : null; } } From 96d880df6a9d8c95cbaf7de056f99f3c88fea0c7 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 28 Sep 2023 21:49:39 +0300 Subject: [PATCH 28/54] Fix crash in SceneAnimationPlayer --- .../Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp | 2 +- Source/Engine/Engine/NativeInterop.Unmanaged.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp index fa7999ce0..8fef8e6d3 100644 --- a/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp +++ b/Source/Engine/Animations/SceneAnimations/SceneAnimationPlayer.cpp @@ -905,7 +905,7 @@ void SceneAnimationPlayer::Tick(SceneAnimation* anim, float time, float dt, int3 MException ex(exception); ex.Log(LogType::Error, TEXT("Property")); } - else if (!MCore::Type::IsPointer(valueType)) + else if (!MCore::Type::IsPointer(valueType) && !MCore::Type::IsReference(valueType)) { if (boxed) Platform::MemoryCopy(value, MCore::Object::Unbox(boxed), valueSize); diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index a2647dd10..54c1c21ec 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -1230,7 +1230,7 @@ namespace FlaxEngine.Interop internal static bool GetTypeIsReference(ManagedHandle typeHandle) { Type type = Unsafe.As(typeHandle.Target); - return type.IsByRef; + return !type.IsValueType; // Maybe also type.IsByRef? } [UnmanagedCallersOnly] From 9a5d8e2c51cc0bff78af3388ca86fc8719033c59 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 28 Sep 2023 15:31:30 -0500 Subject: [PATCH 29/54] Fix tooltip crash --- Source/Engine/UI/GUI/Tooltip.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index e98c07cc5..734fb078f 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -181,6 +181,9 @@ namespace FlaxEngine.GUI private void WrapPosition(ref Float2 locationSS, float flipOffset = 0.0f) { + if (_showTarget?.RootWindow == null) + return; + // Calculate popup direction var dpiScale = _showTarget.RootWindow.DpiScale; var dpiSize = Size * dpiScale; @@ -207,7 +210,8 @@ namespace FlaxEngine.GUI // Move window with mouse location var mousePos = Input.MouseScreenPosition; WrapPosition(ref mousePos, 10); - _window.Position = mousePos + new Float2(15, 10); + if (_window) + _window.Position = mousePos + new Float2(15, 10); // Auto hide if mouse leaves control area var location = _showTarget.PointFromScreen(mousePos); From 8eed667d5a161c5a60aed7eeb245c367d6f43a7e Mon Sep 17 00:00:00 2001 From: Edu Garcia <28616+Arcnor@users.noreply.github.com> Date: Thu, 28 Sep 2023 22:41:24 +0100 Subject: [PATCH 30/54] Makes BaseLinesGapScale configurable for Label --- Source/Engine/UI/GUI/Common/Label.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Label.cs b/Source/Engine/UI/GUI/Common/Label.cs index 2779dfdea..0e2d3c9cf 100644 --- a/Source/Engine/UI/GUI/Common/Label.cs +++ b/Source/Engine/UI/GUI/Common/Label.cs @@ -74,10 +74,16 @@ namespace FlaxEngine.GUI [EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The text wrapping within the control bounds.")] public TextWrapping Wrapping { get; set; } = TextWrapping.NoWrap; + /// + /// Gets or sets the text wrapping within the control bounds. + /// + [EditorDisplay("Text Style"), EditorOrder(2023), Tooltip("The gap between lines when wrapping and more than a single line is displayed."), Limit(0f)] + public float BaseLinesGapScale { get; set; } = 1.0f; + /// /// Gets or sets the font. /// - [EditorDisplay("Text Style"), EditorOrder(2023)] + [EditorDisplay("Text Style"), EditorOrder(2024)] public FontReference Font { get => _font; @@ -99,7 +105,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// - [EditorDisplay("Text Style"), EditorOrder(2024)] + [EditorDisplay("Text Style"), EditorOrder(2025)] public MaterialBase Material { get; set; } /// @@ -227,7 +233,7 @@ namespace FlaxEngine.GUI } } - Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, 1.0f, scale); + Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale); if (ClipText) Render2D.PopClip(); @@ -249,6 +255,7 @@ namespace FlaxEngine.GUI else if (_autoWidth && !_autoHeight) layout.Bounds.Size.Y = Height - Margin.Height; _textSize = font.MeasureText(_text, ref layout); + _textSize.Y *= BaseLinesGapScale; // Check if size is controlled via text if (_autoWidth || _autoHeight) From 6d3fdeec8a533ef4bec073dedc05ddef5a96a63d Mon Sep 17 00:00:00 2001 From: Edu Garcia <28616+Arcnor@users.noreply.github.com> Date: Thu, 28 Sep 2023 22:50:07 +0100 Subject: [PATCH 31/54] Rename new actor after creating it --- Source/Editor/Windows/SceneTreeWindow.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 609f98f83..fba052269 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -173,6 +173,9 @@ namespace FlaxEditor.Windows // Spawn it Editor.SceneEditing.Spawn(actor, parentActor); + + Editor.SceneEditing.Select(actor); + Rename(); } /// From 1d42988f399d217fd094571ba620d101c1ec9553 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 00:49:51 +0300 Subject: [PATCH 32/54] Fix VisualScript method calls not working with value types --- Source/Engine/Scripting/BinaryModule.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Engine/Scripting/BinaryModule.cpp b/Source/Engine/Scripting/BinaryModule.cpp index 8f1bb27d0..7bdffd581 100644 --- a/Source/Engine/Scripting/BinaryModule.cpp +++ b/Source/Engine/Scripting/BinaryModule.cpp @@ -1237,8 +1237,12 @@ bool ManagedBinaryModule::InvokeMethod(void* method, const Variant& instance, Sp return true; } +#if USE_NETCORE + mInstance = instanceObject; +#else // For value-types instance is the actual boxed object data, not te object itself mInstance = instanceObjectClass->IsValueType() ? MCore::Object::Unbox(instanceObject) : instanceObject; +#endif } // Marshal parameters From fd3f10864b8c09289971d8cb2cfd64090d0cd026 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 29 Sep 2023 00:00:21 +0200 Subject: [PATCH 33/54] Fixes for iOS #1312 --- Flax.sln.DotSettings | 2 + .../Engine/Engine/NativeInterop.Unmanaged.cs | 2 +- Source/Engine/Engine/NativeInterop.cs | 68 ++++++++++--------- Source/Engine/Scripting/Runtime/DotNet.cpp | 24 +++---- 4 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Flax.sln.DotSettings b/Flax.sln.DotSettings index e8af1461c..6a22f211b 100644 --- a/Flax.sln.DotSettings +++ b/Flax.sln.DotSettings @@ -291,6 +291,8 @@ True True True + True + True True True True diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index a2647dd10..9cc5a1f1c 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -853,7 +853,7 @@ namespace FlaxEngine.Interop { object fieldOwner = fieldOwnerHandle.Target; FieldHolder field = Unsafe.As(fieldHandle.Target); - field.toNativeMarshaller(field.fieldOffset, fieldOwner, valuePtr, out int fieldSize); + field.toNativeMarshaller(field.field, field.fieldOffset, fieldOwner, valuePtr, out int fieldSize); } [UnmanagedCallersOnly] diff --git a/Source/Engine/Engine/NativeInterop.cs b/Source/Engine/Engine/NativeInterop.cs index 0b6aa2320..500636290 100644 --- a/Source/Engine/Engine/NativeInterop.cs +++ b/Source/Engine/Engine/NativeInterop.cs @@ -363,7 +363,7 @@ namespace FlaxEngine.Interop internal delegate object MarshalToManagedDelegate(IntPtr nativePtr, bool byRef); internal delegate void MarshalToNativeDelegate(object managedObject, IntPtr nativePtr); - internal delegate void MarshalToNativeFieldDelegate(int fieldOffset, object fieldOwner, IntPtr nativePtr, out int fieldSize); + internal delegate void MarshalToNativeFieldDelegate(FieldInfo field, int fieldOffset, object fieldOwner, IntPtr nativePtr, out int fieldSize); internal static ConcurrentDictionary toManagedMarshallers = new ConcurrentDictionary(1, 3); internal static ConcurrentDictionary toNativeMarshallers = new ConcurrentDictionary(1, 3); @@ -471,7 +471,7 @@ namespace FlaxEngine.Interop { private delegate void MarshalToNativeTypedDelegate(ref T managedValue, IntPtr nativePtr); private delegate void MarshalToManagedTypedDelegate(ref T managedValue, IntPtr nativePtr, bool byRef); - internal delegate void MarshalFieldTypedDelegate(int managedFieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize); + internal delegate void MarshalFieldTypedDelegate(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize); internal delegate void* GetBasePointer(ref T fieldOwner); internal static FieldInfo[] marshallableFields; @@ -605,7 +605,6 @@ namespace FlaxEngine.Interop methodName = nameof(MarshalHelperValueType.ToManagedWithMarshallableFields); else methodName = nameof(MarshalHelperValueType.ToManaged); - toManagedMethod = typeof(MarshalHelperValueType<>).MakeGenericType(type).GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic); } else if (type.IsArray) @@ -716,7 +715,7 @@ namespace FlaxEngine.Interop toNativeTypedMarshaller(ref managedValue, nativePtr); } - internal static void ToNativeField(int fieldOffset, ref T fieldOwner, IntPtr nativePtr, out int fieldSize) + internal static void ToNativeField(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativePtr, out int fieldSize) { if (marshallableFields != null) { @@ -724,7 +723,7 @@ namespace FlaxEngine.Interop { if (marshallableFieldOffsets[i] == fieldOffset) { - toNativeFieldMarshallers[i](fieldOffset, ref fieldOwner, nativePtr, out fieldSize); + toNativeFieldMarshallers[i](field, fieldOffset, ref fieldOwner, nativePtr, out fieldSize); return; } } @@ -732,28 +731,28 @@ namespace FlaxEngine.Interop throw new NativeInteropException($"Invalid field with offset {fieldOffset} to marshal for type {typeof(T).Name}"); } - private static void ToManagedFieldPointerValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + private static void ToManagedFieldPointerValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { ref IntPtr fieldValueRef = ref FieldHelper.GetValueTypeFieldReference(fieldOffset, ref fieldOwner); fieldValueRef = Unsafe.Read(nativeFieldPtr.ToPointer()); fieldSize = IntPtr.Size; } - private static void ToManagedFieldPointerReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + private static void ToManagedFieldPointerReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { ref IntPtr fieldValueRef = ref FieldHelper.GetReferenceTypeFieldReference(fieldOffset, ref fieldOwner); fieldValueRef = Unsafe.Read(nativeFieldPtr.ToPointer()); fieldSize = IntPtr.Size; } - private static void ToNativeFieldPointerValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + private static void ToNativeFieldPointerValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { ref IntPtr fieldValueRef = ref FieldHelper.GetValueTypeFieldReference(fieldOffset, ref fieldOwner); Unsafe.Write(nativeFieldPtr.ToPointer(), fieldValueRef); fieldSize = IntPtr.Size; } - private static void ToNativeFieldPointerReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + private static void ToNativeFieldPointerReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { ref IntPtr fieldValueRef = ref FieldHelper.GetReferenceTypeFieldReference(fieldOffset, ref fieldOwner); Unsafe.Write(nativeFieldPtr.ToPointer(), fieldValueRef); @@ -788,7 +787,7 @@ namespace FlaxEngine.Interop fieldAlignment = GetTypeSize(fieldType); } - internal static void ToManagedFieldValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToManagedFieldValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { fieldSize = Unsafe.SizeOf(); if (fieldAlignment > 1) @@ -802,7 +801,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, nativeFieldPtr, false); } - internal static void ToManagedFieldReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToManagedFieldReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { fieldSize = Unsafe.SizeOf(); if (fieldAlignment > 1) @@ -816,7 +815,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, nativeFieldPtr, false); } - internal static void ToManagedFieldArrayValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToManagedFieldArrayValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { // Follows the same marshalling semantics with reference types fieldSize = Unsafe.SizeOf(); @@ -828,7 +827,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToManagedFieldArrayReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToManagedFieldArrayReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { // Follows the same marshalling semantics with reference types fieldSize = Unsafe.SizeOf(); @@ -840,7 +839,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToNativeFieldValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToNativeFieldValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { fieldSize = Unsafe.SizeOf(); if (fieldAlignment > 1) @@ -858,7 +857,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToNative(ref fieldValueRef, nativeFieldPtr); } - internal static void ToNativeFieldReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToNativeFieldReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { fieldSize = Unsafe.SizeOf(); if (fieldAlignment > 1) @@ -883,12 +882,12 @@ namespace FlaxEngine.Interop { } - internal static void ToManagedField(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) + internal static void ToManagedField(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) { fieldSize = 0; } - internal static void ToNativeField(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) + internal static void ToNativeField(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) { fieldSize = 0; } @@ -896,7 +895,7 @@ namespace FlaxEngine.Interop private static class ReferenceTypeField where TField : class { - internal static void ToManagedFieldValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToManagedFieldValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -907,7 +906,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToManagedFieldReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToManagedFieldReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -918,7 +917,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToManagedFieldArrayValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToManagedFieldArrayValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -929,7 +928,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToManagedFieldArrayReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToManagedFieldArrayReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -940,7 +939,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToManaged(ref fieldValueRef, Unsafe.Read(nativeFieldPtr.ToPointer()), false); } - internal static void ToNativeFieldValueType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct + internal static void ToNativeFieldValueType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : struct { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -951,7 +950,7 @@ namespace FlaxEngine.Interop MarshalHelper.ToNative(ref fieldValueRef, nativeFieldPtr); } - internal static void ToNativeFieldReferenceType(int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class + internal static void ToNativeFieldReferenceType(FieldInfo field, int fieldOffset, ref T fieldOwner, IntPtr nativeFieldPtr, out int fieldSize) // where T : class { fieldSize = Unsafe.SizeOf(); IntPtr fieldStartPtr = nativeFieldPtr; @@ -971,9 +970,9 @@ namespace FlaxEngine.Interop MarshalHelper.ToNative(ref Unsafe.Unbox(managedObject), nativePtr); } - internal static void ToNativeFieldWrapper(int fieldOffset, object fieldOwner, IntPtr nativePtr, out int fieldSize) + internal static void ToNativeFieldWrapper(FieldInfo field, int fieldOffset, object fieldOwner, IntPtr nativePtr, out int fieldSize) { - MarshalHelper.ToNativeField(fieldOffset, ref Unsafe.Unbox(fieldOwner), nativePtr, out fieldSize); + MarshalHelper.ToNativeField(field, fieldOffset, ref Unsafe.Unbox(fieldOwner), nativePtr, out fieldSize); } internal static void ToManagedPointer(ref IntPtr managedValue, IntPtr nativePtr, bool byRef) @@ -982,7 +981,6 @@ namespace FlaxEngine.Interop byRef |= type.IsByRef; // Is this needed? if (type.IsByRef) Assert.IsTrue(type.GetElementType().IsValueType); - managedValue = byRef ? nativePtr : Unsafe.Read(nativePtr.ToPointer()); } @@ -994,9 +992,12 @@ namespace FlaxEngine.Interop internal static void ToManagedWithMarshallableFields(ref T managedValue, IntPtr nativePtr, bool byRef) { IntPtr fieldPtr = nativePtr; - for (int i = 0; i < MarshalHelper.marshallableFields.Length; i++) + var fields = MarshalHelper.marshallableFields; + var offsets = MarshalHelper.marshallableFieldOffsets; + var marshallers = MarshalHelper.toManagedFieldMarshallers; + for (int i = 0; i < fields.Length; i++) { - MarshalHelper.toManagedFieldMarshallers[i](MarshalHelper.marshallableFieldOffsets[i], ref managedValue, fieldPtr, out int fieldSize); + marshallers[i](fields[i], offsets[i], ref managedValue, fieldPtr, out int fieldSize); fieldPtr += fieldSize; } Assert.IsTrue((fieldPtr - nativePtr) <= Unsafe.SizeOf()); @@ -1038,9 +1039,12 @@ namespace FlaxEngine.Interop internal static void ToNativeWithMarshallableFields(ref T managedValue, IntPtr nativePtr) { IntPtr fieldPtr = nativePtr; + var fields = MarshalHelper.marshallableFields; + var offsets = MarshalHelper.marshallableFieldOffsets; + var marshallers = MarshalHelper.toNativeFieldMarshallers; for (int i = 0; i < MarshalHelper.marshallableFields.Length; i++) { - MarshalHelper.toNativeFieldMarshallers[i](MarshalHelper.marshallableFieldOffsets[i], ref managedValue, nativePtr, out int fieldSize); + marshallers[i](fields[i], offsets[i], ref managedValue, nativePtr, out int fieldSize); nativePtr += fieldSize; } Assert.IsTrue((nativePtr - fieldPtr) <= Unsafe.SizeOf()); @@ -1060,10 +1064,10 @@ namespace FlaxEngine.Interop MarshalHelper.ToNative(ref managedValue, nativePtr); } - internal static void ToNativeFieldWrapper(int fieldOffset, object managedObject, IntPtr nativePtr, out int fieldSize) + internal static void ToNativeFieldWrapper(FieldInfo field, int fieldOffset, object fieldOwner, IntPtr nativePtr, out int fieldSize) { - T managedValue = Unsafe.As(managedObject); - MarshalHelper.ToNativeField(fieldOffset, ref managedValue, nativePtr, out fieldSize); + T managedValue = Unsafe.As(fieldOwner); + MarshalHelper.ToNativeField(field, fieldOffset, ref managedValue, nativePtr, out fieldSize); } internal static void ToManagedString(ref string managedValue, IntPtr nativePtr, bool byRef) diff --git a/Source/Engine/Scripting/Runtime/DotNet.cpp b/Source/Engine/Scripting/Runtime/DotNet.cpp index 047423994..1d01a8ea3 100644 --- a/Source/Engine/Scripting/Runtime/DotNet.cpp +++ b/Source/Engine/Scripting/Runtime/DotNet.cpp @@ -614,6 +614,18 @@ bool MCore::Type::IsReference(MType* type) return CallStaticMethod(GetTypeIsReferencePtr, type); } +void MCore::ScriptingObject::SetInternalValues(MClass* klass, MObject* object, void* unmanagedPtr, const Guid* id) +{ + static void* ScriptingObjectSetInternalValuesPtr = GetStaticMethodPointer(TEXT("ScriptingObjectSetInternalValues")); + CallStaticMethod(ScriptingObjectSetInternalValuesPtr, object, unmanagedPtr, id); +} + +MObject* MCore::ScriptingObject::CreateScriptingObject(MClass* klass, void* unmanagedPtr, const Guid* id) +{ + static void* ScriptingObjectSetInternalValuesPtr = GetStaticMethodPointer(TEXT("ScriptingObjectCreate")); + return CallStaticMethod(ScriptingObjectSetInternalValuesPtr, klass->_handle, unmanagedPtr, id); +} + const MAssembly::ClassesDictionary& MAssembly::GetClasses() const { if (_hasCachedClasses || !IsLoaded()) @@ -1737,18 +1749,6 @@ void* GetStaticMethodPointer(const String& methodName) return fun; } -void MCore::ScriptingObject::SetInternalValues(MClass* klass, MObject* object, void* unmanagedPtr, const Guid* id) -{ - static void* ScriptingObjectSetInternalValuesPtr = GetStaticMethodPointer(TEXT("ScriptingObjectSetInternalValues")); - CallStaticMethod(ScriptingObjectSetInternalValuesPtr, object, unmanagedPtr, id); -} - -MObject* MCore::ScriptingObject::CreateScriptingObject(MClass* klass, void* unmanagedPtr, const Guid* id) -{ - static void* ScriptingObjectSetInternalValuesPtr = GetStaticMethodPointer(TEXT("ScriptingObjectCreate")); - return CallStaticMethod(ScriptingObjectSetInternalValuesPtr, klass->_handle, unmanagedPtr, id); -} - #elif DOTNET_HOST_MONO #ifdef USE_MONO_AOT_MODULE From 9975bde78c27c5d7cee7ed517b469569a33cdaef Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 28 Sep 2023 19:09:02 -0500 Subject: [PATCH 34/54] Change output window search and scroll bars to be like other windows. --- Source/Editor/Windows/OutputLogWindow.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Windows/OutputLogWindow.cs b/Source/Editor/Windows/OutputLogWindow.cs index 4ea31b35e..1d188a32c 100644 --- a/Source/Editor/Windows/OutputLogWindow.cs +++ b/Source/Editor/Windows/OutputLogWindow.cs @@ -160,7 +160,7 @@ namespace FlaxEditor.Windows Parent = this, }; _viewDropdown.Clicked += OnViewButtonClicked; - _searchBox = new SearchBox(false, _viewDropdown.Right + 2, 2, Width - _viewDropdown.Right - 2 - _scrollSize) + _searchBox = new SearchBox(false, _viewDropdown.Right + 2, 2, Width - _viewDropdown.Right - 4) { Parent = this, }; @@ -171,11 +171,12 @@ namespace FlaxEditor.Windows Maximum = 0, }; _hScroll.ValueChanged += OnHScrollValueChanged; - _vScroll = new VScrollBar(this, Width - _scrollSize, Height, _scrollSize) + _vScroll = new VScrollBar(this, Width - _scrollSize, Height - _viewDropdown.Height - 2, _scrollSize) { ThumbThickness = 10, Maximum = 0, }; + _vScroll.Y += _viewDropdown.Height + 2; _vScroll.ValueChanged += OnVScrollValueChanged; _output = new OutputTextBox { @@ -409,7 +410,7 @@ namespace FlaxEditor.Windows if (_output != null) { - _searchBox.Width = Width - _viewDropdown.Right - 2 - _scrollSize; + _searchBox.Width = Width - _viewDropdown.Right - 4; _output.Size = new Float2(_vScroll.X - 2, _hScroll.Y - 4 - _viewDropdown.Bottom); } } From bb54229760332b96e0d5a7745f7c5a7cac05ec89 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:13:57 -0400 Subject: [PATCH 35/54] Simplify code --- Source/Editor/Windows/Assets/CollisionDataWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Windows/Assets/CollisionDataWindow.cs b/Source/Editor/Windows/Assets/CollisionDataWindow.cs index 85d4bbecc..1b6ed914c 100644 --- a/Source/Editor/Windows/Assets/CollisionDataWindow.cs +++ b/Source/Editor/Windows/Assets/CollisionDataWindow.cs @@ -200,7 +200,7 @@ namespace FlaxEditor.Windows.Assets ViewportCamera = new FPSCamera(), Parent = _split.Panel1 }; - _preview.Task.ViewFlags = ViewFlags.Reflections | ViewFlags.DebugDraw | ViewFlags.AO | ViewFlags.DirectionalLights | ViewFlags.SkyLights | ViewFlags.Shadows | ViewFlags.SpecularLight | ViewFlags.AntiAliasing | ViewFlags.ToneMapping; + _preview.Task.ViewFlags &= ~ViewFlags.Sky & ~ViewFlags.Bloom; // Asset properties _propertiesPresenter = new CustomEditorPresenter(null); From 8f5af2e149bd0937244dd6b7a7cc5712ae0ee945 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 28 Sep 2023 19:49:59 -0500 Subject: [PATCH 36/54] Fix bool editor when null. --- Source/Editor/CustomEditors/Editors/BooleanEditor.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Editor/CustomEditors/Editors/BooleanEditor.cs b/Source/Editor/CustomEditors/Editors/BooleanEditor.cs index f5edafed8..803b7b4dd 100644 --- a/Source/Editor/CustomEditors/Editors/BooleanEditor.cs +++ b/Source/Editor/CustomEditors/Editors/BooleanEditor.cs @@ -34,7 +34,9 @@ namespace FlaxEditor.CustomEditors.Editors } else { - element.CheckBox.Checked = (bool)Values[0]; + var value = (bool?)Values[0]; + if (value != null) + element.CheckBox.Checked = value.Value; } } } From db8f721fa7adf88ee5861950bf03e2d12c049865 Mon Sep 17 00:00:00 2001 From: Zode Date: Fri, 29 Sep 2023 11:20:24 +0300 Subject: [PATCH 37/54] Fix build project generation under arch --- Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index 20f64b92e..eff24dbf3 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -192,11 +192,9 @@ namespace Flax.Build case TargetPlatform.Linux: { rid = $"linux-{arch}"; - ridFallback = ""; + ridFallback = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); if (string.IsNullOrEmpty(dotnetPath)) dotnetPath ??= SearchForDotnetLocationLinux(); - if (dotnetPath == null) - ridFallback = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim(); break; } case TargetPlatform.Mac: From 18310c92647827d3ce4f6a01dc062ebb349b90f7 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 22:06:55 +0300 Subject: [PATCH 38/54] Fix loading shared managed assemblies multiple times --- Source/Engine/Scripting/Scripting.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Scripting/Scripting.cpp b/Source/Engine/Scripting/Scripting.cpp index 6210063b8..28c9a4ed1 100644 --- a/Source/Engine/Scripting/Scripting.cpp +++ b/Source/Engine/Scripting/Scripting.cpp @@ -104,7 +104,7 @@ namespace MMethod* _method_LateFixedUpdate = nullptr; MMethod* _method_Draw = nullptr; MMethod* _method_Exit = nullptr; - Array> _nonNativeModules; + Dictionary> _nonNativeModules; #if USE_EDITOR bool LastBinariesLoadTriggeredCompilation = false; #endif @@ -334,6 +334,8 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde // Check if that module has been already registered BinaryModule* module = BinaryModule::GetModule(nameAnsi); + if (!module) + _nonNativeModules.TryGet(nameAnsi, module); if (!module) { // C++ @@ -403,7 +405,7 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde { // Create module if native library is not used module = New(nameAnsi); - _nonNativeModules.Add(module); + _nonNativeModules.Add(nameAnsi, module); } } From 811d6395736bd9a31d34a37cfb046070ddce3f2a Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 22:07:45 +0300 Subject: [PATCH 39/54] Generate Visual Studio Code build tasks for C#-projects --- .../VisualStudioCodeProjectGenerator.cs | 222 +++++++++--------- 1 file changed, 109 insertions(+), 113 deletions(-) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index fdf1df4e2..2fdff6fa4 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -155,122 +155,118 @@ namespace Flax.Build.Projects.VisualStudioCode { foreach (var project in solution.Projects) { - // C++ project - if (project.Type == TargetType.NativeCpp) + if (project.Name == "BuildScripts") + continue; + + bool defaultTask = project == solution.MainProject; + foreach (var configuration in project.Configurations) { - bool defaultTask = project == solution.MainProject; - foreach (var configuration in project.Configurations) + var target = configuration.Target; + var name = project.Name + '|' + configuration.Name; + + json.BeginObject(); + + json.AddField("label", name); + + bool isDefaultTask = defaultTask && configuration.Configuration == TargetConfiguration.Development && configuration.Platform == Platform.BuildPlatform.Target; + + json.BeginObject("group"); { - var target = configuration.Target; - var name = project.Name + '|' + configuration.Name; - - json.BeginObject(); - - json.AddField("label", name); - - if (defaultTask && configuration.Configuration == TargetConfiguration.Development && configuration.Platform == Platform.BuildPlatform.Target) - { - defaultTask = false; - json.BeginObject("group"); - { - json.AddField("kind", "build"); - json.AddField("isDefault", true); - } - json.EndObject(); - } - else - { - json.AddField("group", "build"); - } - - switch (Platform.BuildPlatform.Target) - { - case TargetPlatform.Windows: - { - json.AddField("command", buildToolPath); - json.BeginArray("args"); - { - json.AddUnnamedField("-build"); - json.AddUnnamedField("-log"); - json.AddUnnamedField("-mutex"); - json.AddUnnamedField(string.Format("\\\"-workspace={0}\\\"", buildToolWorkspace)); - json.AddUnnamedField(string.Format("-arch={0}", configuration.ArchitectureName)); - json.AddUnnamedField(string.Format("-configuration={0}", configuration.ConfigurationName)); - json.AddUnnamedField(string.Format("-platform={0}", configuration.PlatformName)); - json.AddUnnamedField(string.Format("-buildTargets={0}", target.Name)); - if (!string.IsNullOrEmpty(Configuration.Compiler)) - json.AddUnnamedField(string.Format("-compiler={0}", Configuration.Compiler)); - } - json.EndArray(); - - json.AddField("type", "shell"); - - json.BeginObject("options"); - { - json.AddField("cwd", buildToolWorkspace); - } - json.EndObject(); - break; - } - case TargetPlatform.Linux: - { - json.AddField("command", buildToolPath); - json.BeginArray("args"); - { - json.AddUnnamedField("--build"); - json.AddUnnamedField("--log"); - json.AddUnnamedField("--mutex"); - json.AddUnnamedField(string.Format("--workspace=\\\"{0}\\\"", buildToolWorkspace)); - json.AddUnnamedField(string.Format("--arch={0}", configuration.Architecture)); - json.AddUnnamedField(string.Format("--configuration={0}", configuration.ConfigurationName)); - json.AddUnnamedField(string.Format("--platform={0}", configuration.PlatformName)); - json.AddUnnamedField(string.Format("--buildTargets={0}", target.Name)); - if (!string.IsNullOrEmpty(Configuration.Compiler)) - json.AddUnnamedField(string.Format("--compiler={0}", Configuration.Compiler)); - } - json.EndArray(); - - json.AddField("type", "shell"); - - json.BeginObject("options"); - { - json.AddField("cwd", buildToolWorkspace); - } - json.EndObject(); - break; - } - case TargetPlatform.Mac: - { - json.AddField("command", buildToolPath); - json.BeginArray("args"); - { - json.AddUnnamedField("--build"); - json.AddUnnamedField("--log"); - json.AddUnnamedField("--mutex"); - json.AddUnnamedField(string.Format("--workspace=\\\"{0}\\\"", buildToolWorkspace)); - json.AddUnnamedField(string.Format("--arch={0}", configuration.Architecture)); - json.AddUnnamedField(string.Format("--configuration={0}", configuration.ConfigurationName)); - json.AddUnnamedField(string.Format("--platform={0}", configuration.PlatformName)); - json.AddUnnamedField(string.Format("--buildTargets={0}", target.Name)); - if (!string.IsNullOrEmpty(Configuration.Compiler)) - json.AddUnnamedField(string.Format("--compiler={0}", Configuration.Compiler)); - } - json.EndArray(); - - json.AddField("type", "shell"); - - json.BeginObject("options"); - { - json.AddField("cwd", buildToolWorkspace); - } - json.EndObject(); - break; - } - default: throw new Exception("Visual Code project generator does not support current platform."); - } - - json.EndObject(); + json.AddField("kind", "build"); + json.AddField("isDefault", isDefaultTask); } + json.EndObject(); + + if (isDefaultTask) + defaultTask = false; + + switch (Platform.BuildPlatform.Target) + { + case TargetPlatform.Windows: + { + json.AddField("command", buildToolPath); + json.BeginArray("args"); + { + json.AddUnnamedField("-build"); + json.AddUnnamedField("-log"); + json.AddUnnamedField("-mutex"); + json.AddUnnamedField(string.Format("\\\"-workspace={0}\\\"", buildToolWorkspace)); + json.AddUnnamedField(string.Format("-arch={0}", configuration.ArchitectureName)); + json.AddUnnamedField(string.Format("-configuration={0}", configuration.ConfigurationName)); + json.AddUnnamedField(string.Format("-platform={0}", configuration.PlatformName)); + json.AddUnnamedField(string.Format("-buildTargets={0}", target.Name)); + if (!string.IsNullOrEmpty(Configuration.Compiler)) + json.AddUnnamedField(string.Format("-compiler={0}", Configuration.Compiler)); + } + json.EndArray(); + + json.AddField("type", "shell"); + + json.BeginObject("options"); + { + json.AddField("cwd", buildToolWorkspace); + } + json.EndObject(); + break; + } + case TargetPlatform.Linux: + { + json.AddField("command", buildToolPath); + json.BeginArray("args"); + { + json.AddUnnamedField("--build"); + json.AddUnnamedField("--log"); + json.AddUnnamedField("--mutex"); + json.AddUnnamedField(string.Format("--workspace=\\\"{0}\\\"", buildToolWorkspace)); + json.AddUnnamedField(string.Format("--arch={0}", configuration.Architecture)); + json.AddUnnamedField(string.Format("--configuration={0}", configuration.ConfigurationName)); + json.AddUnnamedField(string.Format("--platform={0}", configuration.PlatformName)); + json.AddUnnamedField(string.Format("--buildTargets={0}", target.Name)); + if (!string.IsNullOrEmpty(Configuration.Compiler)) + json.AddUnnamedField(string.Format("--compiler={0}", Configuration.Compiler)); + } + json.EndArray(); + + json.AddField("type", "shell"); + + json.BeginObject("options"); + { + json.AddField("cwd", buildToolWorkspace); + } + json.EndObject(); + break; + } + case TargetPlatform.Mac: + { + json.AddField("command", buildToolPath); + json.BeginArray("args"); + { + json.AddUnnamedField("--build"); + json.AddUnnamedField("--log"); + json.AddUnnamedField("--mutex"); + json.AddUnnamedField(string.Format("--workspace=\\\"{0}\\\"", buildToolWorkspace)); + json.AddUnnamedField(string.Format("--arch={0}", configuration.Architecture)); + json.AddUnnamedField(string.Format("--configuration={0}", configuration.ConfigurationName)); + json.AddUnnamedField(string.Format("--platform={0}", configuration.PlatformName)); + json.AddUnnamedField(string.Format("--buildTargets={0}", target.Name)); + if (!string.IsNullOrEmpty(Configuration.Compiler)) + json.AddUnnamedField(string.Format("--compiler={0}", Configuration.Compiler)); + } + json.EndArray(); + + json.AddField("type", "shell"); + + json.BeginObject("options"); + { + json.AddField("cwd", buildToolWorkspace); + } + json.EndObject(); + break; + } + default: throw new Exception("Visual Code project generator does not support current platform."); + } + + json.EndObject(); } } } From 8a19b5ddd6c4754a6ca45be7b4a20a52cb31bc9a Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 23:46:57 +0300 Subject: [PATCH 40/54] Skip adding VSCode task and launch profiles for plugins and dependencies --- .../VisualStudioCodeProjectGenerator.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index 2fdff6fa4..743a643f3 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -158,6 +158,10 @@ namespace Flax.Build.Projects.VisualStudioCode if (project.Name == "BuildScripts") continue; + // Skip duplicate build tasks + if (project.Name == "FlaxEngine" || (solution.MainProject.Name != "Flax" && solution.MainProject != project)) + continue; + bool defaultTask = project == solution.MainProject; foreach (var configuration in project.Configurations) { @@ -288,9 +292,15 @@ namespace Flax.Build.Projects.VisualStudioCode { foreach (var project in solution.Projects) { + if (project.Name == "BuildScripts") + continue; // C++ project if (project.Type == TargetType.NativeCpp) { + // Skip generating launch profiles for plugins and dependencies + if (solution.MainProject.Name != "Flax" && project.Name != "Flax.Build" && solution.MainProject.WorkspaceRootPath != project.WorkspaceRootPath) + continue; + foreach (var configuration in project.Configurations) { var name = project.Name + '|' + configuration.Name; From bf2c10b036a484705add7e3b8b0a7409eb67df69 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 23:50:15 +0300 Subject: [PATCH 41/54] Generate one VSCode debugger attach launch profile per debugger type --- .../VisualStudioCodeProjectGenerator.cs | 238 +++++++++--------- 1 file changed, 115 insertions(+), 123 deletions(-) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index 743a643f3..f1f7e415e 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -281,6 +281,9 @@ namespace Flax.Build.Projects.VisualStudioCode json.Save(Path.Combine(vsCodeFolder, "tasks.json")); } + bool hasMonoProjects = solution.Projects.Any(x => x.Type == TargetType.DotNet); + bool hasDotnetProjects = solution.Projects.Any(x => x.Type == TargetType.DotNetCore); + // Create launch file using (var json = new JsonWriter()) { @@ -320,115 +323,49 @@ namespace Flax.Build.Projects.VisualStudioCode json.AddField("preLaunchTask", name); json.AddField("cwd", buildToolWorkspace); - switch (Platform.BuildPlatform.Target) + WriteNativePlatformLaunchSettings(json, configuration.Platform); + + if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor.")) { - case TargetPlatform.Windows: - if (configuration.Platform == TargetPlatform.Windows && outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor.")) + if (configuration.Platform == TargetPlatform.Windows) { var editorFolder = configuration.Architecture == TargetArchitecture.x64 ? "Win64" : "Win32"; json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", editorFolder, configuration.ConfigurationName, "FlaxEditor.exe")); - json.BeginArray("args"); + } + else if (configuration.Platform == TargetPlatform.Linux) + json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor")); + else if (configuration.Platform == TargetPlatform.Mac) + json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Mac", configuration.ConfigurationName, "FlaxEditor")); + + json.BeginArray("args"); + { + json.AddUnnamedField("-project"); + json.AddUnnamedField(buildToolWorkspace); + json.AddUnnamedField("-skipCompile"); + if (hasMonoProjects) { - json.AddUnnamedField("-project"); - json.AddUnnamedField(buildToolWorkspace); - json.AddUnnamedField("-skipCompile"); json.AddUnnamedField("-debug"); json.AddUnnamedField("127.0.0.1:55555"); } - json.EndArray(); } - else - { - json.AddField("program", outputTargetFilePath); - } - break; - case TargetPlatform.Linux: - if (configuration.Platform == TargetPlatform.Linux && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor.")) - { - json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor")); - } - else - { - json.AddField("program", outputTargetFilePath); - } - if (configuration.Platform == TargetPlatform.Linux) - { - json.AddField("MIMode", "gdb"); - json.BeginArray("setupCommands"); - { - json.BeginObject(); - json.AddField("description", "Enable pretty-printing for gdb"); - json.AddField("text", "-enable-pretty-printing"); - json.AddField("ignoreFailures", true); - json.EndObject(); - - // Ignore signals used by C# runtime - json.BeginObject(); - json.AddField("description", "ignore SIG34 signal"); - json.AddField("text", "handle SIG34 nostop noprint pass"); - json.EndObject(); - json.BeginObject(); - json.AddField("description", "ignore SIG35 signal"); - json.AddField("text", "handle SIG35 nostop noprint pass"); - json.EndObject(); - json.BeginObject(); - json.AddField("description", "ignore SIG36 signal"); - json.AddField("text", "handle SIG36 nostop noprint pass"); - json.EndObject(); - json.BeginObject(); - json.AddField("description", "ignore SIG357 signal"); - json.AddField("text", "handle SIG37 nostop noprint pass"); - json.EndObject(); - } - json.EndArray(); - json.BeginArray("args"); - { - json.AddUnnamedField("--std"); - if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor.")) - { - json.AddUnnamedField("--project"); - json.AddUnnamedField(buildToolWorkspace); - json.AddUnnamedField("--skipCompile"); - } - } - json.EndArray(); - } - break; - case TargetPlatform.Mac: - if (configuration.Platform == TargetPlatform.Mac && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor.")) - { - json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Mac", configuration.ConfigurationName, "FlaxEditor")); - } - else - { - json.AddField("program", outputTargetFilePath); - } - if (configuration.Platform == TargetPlatform.Mac) - { - json.AddField("MIMode", "lldb"); - json.BeginArray("args"); - { - json.AddUnnamedField("--std"); - if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor.")) - { - json.AddUnnamedField("--project"); - json.AddUnnamedField(buildToolWorkspace); - json.AddUnnamedField("--skipCompile"); - } - } - json.EndArray(); - } - break; + json.EndArray(); } - switch (configuration.Platform) + else { - case TargetPlatform.Windows: - json.AddField("stopAtEntry", false); - json.AddField("externalConsole", true); - break; - case TargetPlatform.Linux: - break; + json.AddField("program", outputTargetFilePath); + json.BeginArray("args"); + { + if (configuration.Platform == TargetPlatform.Linux || configuration.Platform == TargetPlatform.Mac) + json.AddUnnamedField("--std"); + if (hasMonoProjects) + { + json.AddUnnamedField("-debug"); + json.AddUnnamedField("127.0.0.1:55555"); + } + } + json.EndArray(); } + json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis")); } json.EndObject(); @@ -437,16 +374,9 @@ namespace Flax.Build.Projects.VisualStudioCode // C# project else if (project.Type == TargetType.DotNetCore) { - // TODO: Skip generating launch profiles for plugins and dependencies - - json.BeginObject(); - { - json.AddField("type", "coreclr"); - json.AddField("name", project.Name + " (C# attach Editor)"); - json.AddField("request", "attach"); - json.AddField("processName", "FlaxEditor"); - } - json.EndObject(); + // Skip generating launch profiles for plugins and dependencies + if (solution.MainProject.WorkspaceRootPath != project.WorkspaceRootPath) + continue; foreach (var configuration in project.Configurations) { @@ -490,24 +420,33 @@ namespace Flax.Build.Projects.VisualStudioCode json.EndObject(); } } - // Mono C# project - else if (project.Type == TargetType.DotNet) - { - foreach (var configuration in project.Configurations) - { - json.BeginObject(); - { - json.AddField("type", "mono"); - json.AddField("name", project.Name + " (C# attach)" + '|' + configuration.Name); - json.AddField("request", "attach"); - json.AddField("address", "localhost"); - json.AddField("port", 55555); - } - json.EndObject(); - } - } } } + + if (hasDotnetProjects) + { + json.BeginObject(); + { + json.AddField("type", "coreclr"); + json.AddField("name", solution.Name + " (C# Attach Editor)"); + json.AddField("request", "attach"); + json.AddField("processName", "FlaxEditor"); + } + json.EndObject(); + } + if (hasMonoProjects) + { + json.BeginObject(); + { + json.AddField("type", "mono"); + json.AddField("name", solution.Name + " (C# Attach)"); + json.AddField("request", "attach"); + json.AddField("address", "localhost"); + json.AddField("port", 55555); + } + json.EndObject(); + } + json.EndArray(); } json.EndRootObject(); @@ -515,6 +454,59 @@ namespace Flax.Build.Projects.VisualStudioCode json.Save(Path.Combine(vsCodeFolder, "launch.json")); } + static void WriteNativePlatformLaunchSettings(JsonWriter json, TargetPlatform platform) + { + switch (Platform.BuildPlatform.Target) + { + case TargetPlatform.Linux: + if (platform == TargetPlatform.Linux) + { + json.AddField("MIMode", "gdb"); + json.BeginArray("setupCommands"); + { + json.BeginObject(); + json.AddField("description", "Enable pretty-printing for gdb"); + json.AddField("text", "-enable-pretty-printing"); + json.AddField("ignoreFailures", true); + json.EndObject(); + + // Ignore signals used by C# runtime + json.BeginObject(); + json.AddField("description", "ignore SIG34 signal"); + json.AddField("text", "handle SIG34 nostop noprint pass"); + json.EndObject(); + json.BeginObject(); + json.AddField("description", "ignore SIG35 signal"); + json.AddField("text", "handle SIG35 nostop noprint pass"); + json.EndObject(); + json.BeginObject(); + json.AddField("description", "ignore SIG36 signal"); + json.AddField("text", "handle SIG36 nostop noprint pass"); + json.EndObject(); + json.BeginObject(); + json.AddField("description", "ignore SIG357 signal"); + json.AddField("text", "handle SIG37 nostop noprint pass"); + json.EndObject(); + } + json.EndArray(); + } + break; + case TargetPlatform.Mac: + if (platform == TargetPlatform.Mac) + { + json.AddField("MIMode", "lldb"); + } + break; + } + switch (platform) + { + case TargetPlatform.Windows: + json.AddField("stopAtEntry", false); + json.AddField("externalConsole", true); + break; + } + } + // Create C++ properties file using (var json = new JsonWriter()) { From 8b8970e4b96527d4b363feef89fc0cc441b36cb2 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 29 Sep 2023 23:50:50 +0300 Subject: [PATCH 42/54] Generate VSCode attach profile for native debugging --- .../VisualStudioCodeProjectGenerator.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index f1f7e415e..887197258 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -281,6 +281,7 @@ namespace Flax.Build.Projects.VisualStudioCode json.Save(Path.Combine(vsCodeFolder, "tasks.json")); } + bool hasNativeProjects = solution.Projects.Any(x => x.Type == TargetType.NativeCpp); bool hasMonoProjects = solution.Projects.Any(x => x.Type == TargetType.DotNet); bool hasDotnetProjects = solution.Projects.Any(x => x.Type == TargetType.DotNetCore); @@ -423,6 +424,27 @@ namespace Flax.Build.Projects.VisualStudioCode } } + if (hasNativeProjects) + { + foreach (var platform in solution.Projects.SelectMany(x => x.Configurations).Select(x => x.Platform).Distinct()) + { + json.BeginObject(); + { + if (platform == TargetPlatform.Windows) + json.AddField("type", "cppvsdbg"); + else + json.AddField("type", "cppdbg"); + json.AddField("name", solution.Name + " (Attach Editor)"); + json.AddField("request", "attach"); + json.AddField("processId", "${command:pickProcess}"); // Does not seem to be possible to attach by process name? + + WriteNativePlatformLaunchSettings(json, platform); + + json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis")); + } + json.EndObject(); + } + } if (hasDotnetProjects) { json.BeginObject(); From c9324004eb818a55c9e14a8371989fad123e1e7e Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 30 Sep 2023 01:22:02 +0300 Subject: [PATCH 43/54] Build C# bindings after generating engine project files --- GenerateProjectFiles.bat | 15 +++++++++++---- GenerateProjectFiles.command | 5 +++++ GenerateProjectFiles.sh | 5 +++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/GenerateProjectFiles.bat b/GenerateProjectFiles.bat index 1b766457f..622939c34 100644 --- a/GenerateProjectFiles.bat +++ b/GenerateProjectFiles.bat @@ -1,15 +1,22 @@ @echo off - -rem Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. +:: Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. setlocal pushd + echo Generating Flax Engine project files... -rem Run Flax.Build to generate Visual Studio solution and project files (also pass the arguments) -call "Development\Scripts\Windows\CallBuildTool.bat" -genproject %* +:: Change the path to the script root +cd /D "%~dp0" + +:: Run Flax.Build to generate Visual Studio solution and project files (also pass the arguments) +call "Development\Scripts\Windows\CallBuildTool.bat" -genproject %* if errorlevel 1 goto BuildToolFailed +:: Build bindings for all editor configurations +echo Building C# bindings... +Binaries\Tools\Flax.Build.exe -build -BuildBindingsOnly -arch=x64 -platform=Windows --buildTargets=FlaxEditor,FlaxGame + popd echo Done! exit /B 0 diff --git a/GenerateProjectFiles.command b/GenerateProjectFiles.command index 6554886bc..5ee5c0783 100755 --- a/GenerateProjectFiles.command +++ b/GenerateProjectFiles.command @@ -10,3 +10,8 @@ cd "`dirname "$0"`" # Run Flax.Build to generate project files (also pass the arguments) bash ./Development/Scripts/Mac/CallBuildTool.sh --genproject "$@" + +# Build bindings for all editor configurations +echo Building C# bindings... +# TODO: Detect the correct architecture here +Binaries/Tools/Flax.Build -build -BuildBindingsOnly -arch=ARM64 -platform=Mac --buildTargets=FlaxEditor,FlaxGame diff --git a/GenerateProjectFiles.sh b/GenerateProjectFiles.sh index fcda1acc1..dceb8abe8 100755 --- a/GenerateProjectFiles.sh +++ b/GenerateProjectFiles.sh @@ -10,3 +10,8 @@ cd "`dirname "$0"`" # Run Flax.Build to generate project files (also pass the arguments) bash ./Development/Scripts/Linux/CallBuildTool.sh --genproject "$@" + +# Build bindings for all editor configurations +echo Building C# bindings... +# TODO: Detect the correct architecture here +Binaries/Tools/Flax.Build -build -BuildBindingsOnly -arch=x64 -platform=Linux --buildTargets=FlaxEditor,FlaxGame From cc318dddd7dd1bade4a269bfe39a402c335a0441 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 30 Sep 2023 02:36:05 +0300 Subject: [PATCH 44/54] Remap non-native Editor VS build configurations to native configurations --- .../VisualStudioProjectGenerator.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs index 6dcc12a4f..debf827a6 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs @@ -479,7 +479,7 @@ namespace Flax.Build.Projects.VisualStudio { SolutionConfiguration projectConfiguration; bool build = false; - int firstFullMatch = -1, firstPlatformMatch = -1; + int firstFullMatch = -1, firstPlatformMatch = -1, firstEditorMatch = -1; for (int i = 0; i < project.Configurations.Count; i++) { var e = new SolutionConfiguration(project.Configurations[i]); @@ -492,18 +492,31 @@ namespace Flax.Build.Projects.VisualStudio { firstPlatformMatch = i; } + if (firstEditorMatch == -1 && e.Configuration == configuration.Configuration) + { + firstEditorMatch = i; + } } if (firstFullMatch != -1) { projectConfiguration = configuration; build = solution.MainProject == project || (solution.MainProject == null && project.Name == solution.Name); } - else if (firstPlatformMatch != -1) + else if (firstPlatformMatch != -1 && !configuration.Name.StartsWith("Editor.")) { + // No exact match, pick the first configuration for matching platform projectConfiguration = new SolutionConfiguration(project.Configurations[firstPlatformMatch]); } + else if (firstEditorMatch != -1 && configuration.Name.StartsWith("Editor.")) + { + // No exact match, pick the matching editor configuration for different platform. + // As an example, Editor configuration for Android projects should be remapped + // to desktop platform in order to provide working Intellisense information. + projectConfiguration = new SolutionConfiguration(project.Configurations[firstEditorMatch]); + } else { + // No match projectConfiguration = new SolutionConfiguration(project.Configurations[0]); } From 6483f95450b2feb76c8e32facd5751898dbbf3dc Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 30 Sep 2023 03:25:58 +0300 Subject: [PATCH 45/54] Fix Visual Studio project folder GUIDs randomization during regeneration --- .../VisualStudio/VisualStudioProjectGenerator.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs index 6dcc12a4f..21db89d60 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs @@ -166,12 +166,14 @@ namespace Flax.Build.Projects.VisualStudio { try { - Regex projectRegex = new Regex(@"Project\(.*\) = \""(\S+)\"", \""(\S+)\"", \""{(\S+)}\"""); + Regex projectRegex = new Regex(@"Project\(""{(\S+)}""\) = \""(\S+)\"", \""(\S+)\"", \""{(\S+)}\"""); MatchCollection matches = projectRegex.Matches(File.ReadAllText(path)); for (int i = 0; i < matches.Count; i++) { - if (matches[i].Groups[1].Value == projectName) - return Guid.ParseExact(matches[i].Groups[3].Value, "D"); + if (matches[i].Groups[1].Value.Equals("2150E333-8FDC-42A3-9474-1A3956D46DE8", StringComparison.OrdinalIgnoreCase)) + continue; + if (matches[i].Groups[2].Value == projectName) + return Guid.ParseExact(matches[i].Groups[4].Value, "D"); } } catch @@ -376,7 +378,8 @@ namespace Flax.Build.Projects.VisualStudio { if (!folderIds.TryGetValue(folderPath, out project.FolderGuid)) { - project.FolderGuid = Guid.NewGuid(); + if (!folderIds.TryGetValue(folderParents[i], out project.FolderGuid)) + project.FolderGuid = Guid.NewGuid(); folderIds.Add(folderPath, project.FolderGuid); } folderNames.Add(folderPath); From 85a985cd7fa6592ec09d34b858ed6c5a7ce16f3b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 13:52:20 -0500 Subject: [PATCH 46/54] Expose Main Window to c# through Screen class. --- Source/Engine/Engine/Screen.cpp | 9 +++++++++ Source/Engine/Engine/Screen.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/Source/Engine/Engine/Screen.cpp b/Source/Engine/Engine/Screen.cpp index 2bc6e1f58..207d6a87c 100644 --- a/Source/Engine/Engine/Screen.cpp +++ b/Source/Engine/Engine/Screen.cpp @@ -181,6 +181,15 @@ void Screen::SetGameWindowMode(GameWindowMode windowMode) #endif } +Window* Screen::GetMainWindow() +{ + Window* win = nullptr; +#if !USE_EDITOR + win = Engine::MainWindow; +#endif + return win; +} + void ScreenService::Update() { #if USE_EDITOR diff --git a/Source/Engine/Engine/Screen.h b/Source/Engine/Engine/Screen.h index 42be20a38..7785ee7b3 100644 --- a/Source/Engine/Engine/Screen.h +++ b/Source/Engine/Engine/Screen.h @@ -96,4 +96,10 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen); /// /// The window mode. API_PROPERTY() static void SetGameWindowMode(GameWindowMode windowMode); + + /// + /// Gets the main window. Only during built game. + /// + /// The current window. Will be null if fails. + API_PROPERTY() static Window* GetMainWindow(); }; From 1366c2850f748ccb7613b076d86fdf7cdaac8214 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 17:21:48 -0500 Subject: [PATCH 47/54] Fix `Actor.RotateAround` to rotate the actors orientation. --- Source/Engine/Level/Actor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 661b350cb..ff3c7c4fa 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -370,7 +370,7 @@ namespace FlaxEngine var q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians); var dif = (transform.Translation - point) * q; transform.Translation = point + dif; - transform.Orientation = q; + transform.Orientation *= q; Transform = transform; } From bae1cfbc8a073221a58e96d99a63015487e74a9d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 17:35:42 -0500 Subject: [PATCH 48/54] Change base editor window size to 75% of desktop size when restored for first time. --- Source/Editor/Modules/WindowsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Modules/WindowsModule.cs b/Source/Editor/Modules/WindowsModule.cs index 086772ca2..d0c8b9747 100644 --- a/Source/Editor/Modules/WindowsModule.cs +++ b/Source/Editor/Modules/WindowsModule.cs @@ -721,7 +721,7 @@ namespace FlaxEditor.Modules // Create main window var settings = CreateWindowSettings.Default; settings.Title = "Flax Editor"; - //settings.Size = Platform.DesktopSize; + settings.Size = Platform.DesktopSize * 0.75f; settings.StartPosition = WindowStartPosition.CenterScreen; settings.ShowAfterFirstPaint = true; From 260c48e41de9ac6e939635820450c37157d70f47 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 17:44:42 -0500 Subject: [PATCH 49/54] Change blur panel to draw self. Fix issue with blur strength slider. --- Source/Engine/UI/GUI/Panels/BlurPanel.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/BlurPanel.cs b/Source/Engine/UI/GUI/Panels/BlurPanel.cs index 0fe506e44..055535aa8 100644 --- a/Source/Engine/UI/GUI/Panels/BlurPanel.cs +++ b/Source/Engine/UI/GUI/Panels/BlurPanel.cs @@ -11,7 +11,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the blur strength. Defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU. /// - [EditorOrder(0), Limit(0, 100, 0.0f)] + [EditorOrder(0), Limit(0, 100, 0.1f)] public float BlurStrength { get; set; } /// @@ -29,10 +29,9 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { - base.Draw(); - + base.DrawSelf(); var size = Size; var strength = BlurStrength; if (BlurScaleWithSize) From cc681de30edf9e331777d5afb0cd6a6f347f571a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 21:33:27 -0500 Subject: [PATCH 50/54] Fix more and add bool check to orient the actor or not. --- Source/Engine/Level/Actor.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index ff3c7c4fa..bcb91a3bc 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -364,13 +364,20 @@ namespace FlaxEngine /// The point (world-space). /// The axis (normalized). /// The angle (in degrees). - public void RotateAround(Vector3 point, Vector3 axis, float angle) + /// /// Whether to orient the actor the same amount as rotation. + public void RotateAround(Vector3 point, Vector3 axis, float angle, bool orientActor = true) { var transform = Transform; var q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians); var dif = (transform.Translation - point) * q; - transform.Translation = point + dif; - transform.Orientation *= q; + if (Vector3.NearEqual(point, transform.Translation)) + transform.Orientation *= q; + else + { + transform.Translation = point + dif; + if (orientActor) + transform.Orientation *= q; + } Transform = transform; } From 8edd50c293b0dfbcbd5b9c9ba5e10ee0337564d5 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 21:34:40 -0500 Subject: [PATCH 51/54] Simplify --- Source/Engine/Level/Actor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index bcb91a3bc..79e3d4716 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -369,11 +369,11 @@ namespace FlaxEngine { var transform = Transform; var q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians); - var dif = (transform.Translation - point) * q; if (Vector3.NearEqual(point, transform.Translation)) transform.Orientation *= q; else { + var dif = (transform.Translation - point) * q; transform.Translation = point + dif; if (orientActor) transform.Orientation *= q; From 113307ddf9e52128added38793c74bd9784f0895 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 21:36:41 -0500 Subject: [PATCH 52/54] Simplify to return main window even in editor. --- Source/Engine/Engine/Screen.cpp | 6 +----- Source/Engine/Engine/Screen.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Engine/Screen.cpp b/Source/Engine/Engine/Screen.cpp index 207d6a87c..fc7e8a022 100644 --- a/Source/Engine/Engine/Screen.cpp +++ b/Source/Engine/Engine/Screen.cpp @@ -183,11 +183,7 @@ void Screen::SetGameWindowMode(GameWindowMode windowMode) Window* Screen::GetMainWindow() { - Window* win = nullptr; -#if !USE_EDITOR - win = Engine::MainWindow; -#endif - return win; + return Engine::MainWindow; } void ScreenService::Update() diff --git a/Source/Engine/Engine/Screen.h b/Source/Engine/Engine/Screen.h index 7785ee7b3..b7bd89c38 100644 --- a/Source/Engine/Engine/Screen.h +++ b/Source/Engine/Engine/Screen.h @@ -98,7 +98,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen); API_PROPERTY() static void SetGameWindowMode(GameWindowMode windowMode); /// - /// Gets the main window. Only during built game. + /// Gets the main window. /// /// The current window. Will be null if fails. API_PROPERTY() static Window* GetMainWindow(); From b943c7ca3ebfd9a163d342a6bb0021bb2b715279 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 30 Sep 2023 22:19:09 -0500 Subject: [PATCH 53/54] Add extra check for stationary rotation. --- Source/Engine/Level/Actor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 79e3d4716..dbe8a89b5 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -369,7 +369,7 @@ namespace FlaxEngine { var transform = Transform; var q = Quaternion.RotationAxis(axis, angle * Mathf.DegreesToRadians); - if (Vector3.NearEqual(point, transform.Translation)) + if (Vector3.NearEqual(point, transform.Translation) && orientActor) transform.Orientation *= q; else { From 0eda67bd738dbb061a9214700bb1d5a0626ea362 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 1 Oct 2023 11:56:54 +0200 Subject: [PATCH 54/54] Fix nested profiler events usage #https://github.com/FlaxEngine/FlaxEngine/issues/1380 --- Source/Engine/Profiler/ProfilerCPU.cpp | 11 ++++-- Source/Engine/Profiler/ProfilerCPU.h | 48 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Profiler/ProfilerCPU.cpp b/Source/Engine/Profiler/ProfilerCPU.cpp index 26f9e49c2..7b9e2c6e3 100644 --- a/Source/Engine/Profiler/ProfilerCPU.cpp +++ b/Source/Engine/Profiler/ProfilerCPU.cpp @@ -129,8 +129,15 @@ void ProfilerCPU::Thread::EndEvent() { const double time = Platform::GetTimeSeconds() * 1000.0; _depth--; - Event& e = (Buffer.Last()--).Event(); - e.End = time; + for (auto i = Buffer.Last(); i != Buffer.Begin(); --i) + { + Event& e = i.Event(); + if (e.End <= 0) + { + e.End = time; + break; + } + } } bool ProfilerCPU::IsProfilingCurrentThread() diff --git a/Source/Engine/Profiler/ProfilerCPU.h b/Source/Engine/Profiler/ProfilerCPU.h index 124082c9b..ccfeb8ac4 100644 --- a/Source/Engine/Profiler/ProfilerCPU.h +++ b/Source/Engine/Profiler/ProfilerCPU.h @@ -121,15 +121,39 @@ public: EventBuffer* _buffer; int32 _index; - Iterator(EventBuffer* buffer, const int32 index) + FORCE_INLINE Iterator(EventBuffer* buffer, const int32 index) : _buffer(buffer) , _index(index) { } - Iterator(const Iterator& i) = default; - public: + FORCE_INLINE Iterator(const Iterator& other) + : _buffer(other._buffer) + , _index(other._index) + { + } + + FORCE_INLINE Iterator(Iterator&& other) noexcept + : _buffer(other._buffer) + , _index(other._index) + { + } + + FORCE_INLINE Iterator& operator=(Iterator&& other) + { + _buffer = other._buffer; + _index = other._index; + return *this; + } + + FORCE_INLINE Iterator& operator=(const Iterator& other) + { + _buffer = other._buffer; + _index = other._index; + return *this; + } + FORCE_INLINE int32 Index() const { return _index; @@ -141,15 +165,13 @@ public: return _buffer->Get(_index); } - bool IsEnd() const + FORCE_INLINE bool IsEnd() const { - ASSERT_LOW_LAYER(_buffer); return _index == _buffer->_head; } - bool IsNotEnd() const + FORCE_INLINE bool IsNotEnd() const { - ASSERT_LOW_LAYER(_buffer); return _index != _buffer->_head; } @@ -164,31 +186,27 @@ public: } public: - Iterator& operator++() + FORCE_INLINE Iterator& operator++() { - ASSERT(_buffer); _index = (_index + 1) & _buffer->_capacityMask; return *this; } - Iterator operator++(int) + FORCE_INLINE Iterator operator++(int) { - ASSERT(_buffer); Iterator temp = *this; _index = (_index + 1) & _buffer->_capacityMask; return temp; } - Iterator& operator--() + FORCE_INLINE Iterator& operator--() { - ASSERT(_buffer); _index = (_index - 1) & _buffer->_capacityMask; return *this; } - Iterator operator--(int) + FORCE_INLINE Iterator operator--(int) { - ASSERT(_buffer); Iterator temp = *this; _index = (_index - 1) & _buffer->_capacityMask; return temp;