From eaba489ba28dd0aaafedf87d6d9e2d570fcea924 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Tue, 12 Jan 2021 15:08:45 +0100 Subject: [PATCH 01/46] Initial Random class First Commit Static class that inhabits basic and common random functions, allows it to be used in visual scripting as well. --- Source/Engine/Core/Math/Randomf.cs | 143 +++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Source/Engine/Core/Math/Randomf.cs diff --git a/Source/Engine/Core/Math/Randomf.cs b/Source/Engine/Core/Math/Randomf.cs new file mode 100644 index 000000000..791de2cb8 --- /dev/null +++ b/Source/Engine/Core/Math/Randomf.cs @@ -0,0 +1,143 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +using System; + +namespace FlaxEngine +{ + /// + /// A collection of common random functions which supports various types. + /// + public static class Randomf + { + // Single instance for random + private static Random _rand = new Random(0); + + /// + /// Sets the seed of the random number generator. + /// Causes to construct a new instance. + /// + /// The new seed + public static void SetSeed(int newSeed) => _rand = new Random(newSeed); + + // Bool + + public static bool RandomBool() + { + return RandomInt() == 1 ? true : false; + } + + public static bool RandomBoolWithWeight(float weight = 0) + { + return weight >= RandomInt() ? true : false; + } + + // Byte + + public static byte RandomByte(byte min = 0, byte max = 1) + { + return (byte)_rand.Next(min, max+1); + } + + public static byte RandomUniformByte(byte value = 1) + { + int max = Math.Abs(value); + int min = max * -1; + + return (byte)_rand.Next(min, max); + } + + // Int + + public static int RandomInt(int min = 0, int max = 1) + { + return _rand.Next(min, max+1); + } + + public static int RandomUniformInt(int value = 1) + { + int max = Math.Abs(value); + int min = max * -1; + + return _rand.Next(min, max); + } + + // Float + + public static float RandomFloat(float min = 0.0f, float max = 1.0f) + { + return (float)_rand.NextDouble() * (max - min) + min; + } + + public static float RandomUniformFloat(float value = 1.0f) + { + // Ensure that in case of negative values we still return a value between + value and - value. + float max = Math.Abs(value); + float min = max * -1; + + return (float)_rand.NextDouble() * (max - min) + min; + } + + // Quaternion + + public static Quaternion RandomQuaternion() + { + return Quaternion.Euler( + RandomUniformFloat(180), + RandomUniformFloat(180), + RandomUniformFloat(180) + ); + } + + // Vector + + public static Vector3 RandomVector3() + { + Vector3 output; + + do + { + // Create random float with a mean of 0 and deviation of ±1; + output.X = RandomFloat() * 2.0f - 1.0f; + output.Y = RandomFloat() * 2.0f - 1.0f; + output.Z = RandomFloat() * 2.0f - 1.0f; + + } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); + + output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); + + return output; + } + + public static Vector2 RandomVector2() + { + Vector2 output; + + do + { + // Create random float with a mean of 0 and deviation of +-1; + output.X = RandomFloat() * 2.0f - 1.0f; + output.Y = RandomFloat() * 2.0f - 1.0f; + + } while (output.LengthSquared > 1 || output.LengthSquared< 1e-6f); + + output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); + + return output; + } + + // Color + + public static Color RandomColor(bool trueRandom, bool randomAlpha) + { + float alpha = randomAlpha ? RandomFloat() : 1f; + + if (!trueRandom) + return Color.FromHSV(RandomFloat(0f, 360f), 1f, 1f, alpha); + + return new Color( + RandomFloat(0f, 255f), + RandomFloat(0f, 255f), + RandomFloat(0f, 255f), alpha); + } + } +} From 783b9107009384e8958a6a4a2a78577b333b5eb5 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Tue, 12 Jan 2021 20:29:32 +0100 Subject: [PATCH 02/46] Added XML comments --- Source/Engine/Core/Math/Randomf.cs | 94 +++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/Source/Engine/Core/Math/Randomf.cs b/Source/Engine/Core/Math/Randomf.cs index 791de2cb8..9e25456ab 100644 --- a/Source/Engine/Core/Math/Randomf.cs +++ b/Source/Engine/Core/Math/Randomf.cs @@ -12,32 +12,44 @@ namespace FlaxEngine // Single instance for random private static Random _rand = new Random(0); + //TODO: Implement some form of generic method for numerics? + /// /// Sets the seed of the random number generator. - /// Causes to construct a new instance. + /// Constructs a new instance. /// - /// The new seed + /// The new seed. public static void SetSeed(int newSeed) => _rand = new Random(newSeed); - // Bool + /// + /// Generates a random . + /// + /// A thats either true or false. + public static bool RandomBool() => RandomInt() == 1; - public static bool RandomBool() - { - return RandomInt() == 1 ? true : false; - } - - public static bool RandomBoolWithWeight(float weight = 0) - { - return weight >= RandomInt() ? true : false; - } - - // Byte + /// + /// Generates a random with a weight value to adjust preference. + /// + /// Normalized value that determines the chance to return true. + /// A thats either true or false. + public static bool RandomBoolWithWeight(float weight = 0) => weight >= RandomFloat(); + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A between min and max. public static byte RandomByte(byte min = 0, byte max = 1) { return (byte)_rand.Next(min, max+1); } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A that is between +value and -value. public static byte RandomUniformByte(byte value = 1) { int max = Math.Abs(value); @@ -46,13 +58,22 @@ namespace FlaxEngine return (byte)_rand.Next(min, max); } - // Int - + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A random between min and max. public static int RandomInt(int min = 0, int max = 1) { return _rand.Next(min, max+1); } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A random between +value and -value. public static int RandomUniformInt(int value = 1) { int max = Math.Abs(value); @@ -61,13 +82,22 @@ namespace FlaxEngine return _rand.Next(min, max); } - // Float - + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A random between min and max. public static float RandomFloat(float min = 0.0f, float max = 1.0f) { return (float)_rand.NextDouble() * (max - min) + min; } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A random between +value and -value. public static float RandomUniformFloat(float value = 1.0f) { // Ensure that in case of negative values we still return a value between + value and - value. @@ -77,19 +107,22 @@ namespace FlaxEngine return (float)_rand.NextDouble() * (max - min) + min; } - // Quaternion - + /// + /// Generates a random . + /// + /// A random . public static Quaternion RandomQuaternion() { return Quaternion.Euler( RandomUniformFloat(180), RandomUniformFloat(180), - RandomUniformFloat(180) - ); + RandomUniformFloat(180)); } - // Vector - + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere. + /// + /// A random . public static Vector3 RandomVector3() { Vector3 output; @@ -108,13 +141,16 @@ namespace FlaxEngine return output; } + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere in 2D. + /// + /// A random public static Vector2 RandomVector2() { Vector2 output; do { - // Create random float with a mean of 0 and deviation of +-1; output.X = RandomFloat() * 2.0f - 1.0f; output.Y = RandomFloat() * 2.0f - 1.0f; @@ -125,8 +161,12 @@ namespace FlaxEngine return output; } - // Color - + /// + /// Generates a random color. + /// + /// Should the color be generated from a single random Hue value or separate values for each channel. + /// Randomize the alpha value. + /// A nice random color. public static Color RandomColor(bool trueRandom, bool randomAlpha) { float alpha = randomAlpha ? RandomFloat() : 1f; From 604c583c36c3da255c28da2dd5d797d64c1b5202 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Wed, 13 Jan 2021 21:16:17 +0100 Subject: [PATCH 03/46] Moved all methods to Extension.cs Moved the methods for RandomUtils.cs to Extension.cs instead. --- Source/Engine/Core/Math/Randomf.cs | 183 ------------- Source/Engine/Utilities/Extensions.cs | 355 ++++++++++++++------------ 2 files changed, 189 insertions(+), 349 deletions(-) delete mode 100644 Source/Engine/Core/Math/Randomf.cs diff --git a/Source/Engine/Core/Math/Randomf.cs b/Source/Engine/Core/Math/Randomf.cs deleted file mode 100644 index 9e25456ab..000000000 --- a/Source/Engine/Core/Math/Randomf.cs +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. - -using System; - -namespace FlaxEngine -{ - /// - /// A collection of common random functions which supports various types. - /// - public static class Randomf - { - // Single instance for random - private static Random _rand = new Random(0); - - //TODO: Implement some form of generic method for numerics? - - /// - /// Sets the seed of the random number generator. - /// Constructs a new instance. - /// - /// The new seed. - public static void SetSeed(int newSeed) => _rand = new Random(newSeed); - - /// - /// Generates a random . - /// - /// A thats either true or false. - public static bool RandomBool() => RandomInt() == 1; - - /// - /// Generates a random with a weight value to adjust preference. - /// - /// Normalized value that determines the chance to return true. - /// A thats either true or false. - public static bool RandomBoolWithWeight(float weight = 0) => weight >= RandomFloat(); - - /// - /// Generates a random value between min and max. - /// - /// The lower boundary. - /// The upper boundary. - /// A between min and max. - public static byte RandomByte(byte min = 0, byte max = 1) - { - return (byte)_rand.Next(min, max+1); - } - - /// - /// Generates a random by using a single value as both upper and lower boundary. - /// - /// Defines both upper and lower boundary. - /// A that is between +value and -value. - public static byte RandomUniformByte(byte value = 1) - { - int max = Math.Abs(value); - int min = max * -1; - - return (byte)_rand.Next(min, max); - } - - /// - /// Generates a random value between min and max. - /// - /// The lower boundary. - /// The upper boundary. - /// A random between min and max. - public static int RandomInt(int min = 0, int max = 1) - { - return _rand.Next(min, max+1); - } - - /// - /// Generates a random by using a single value as both upper and lower boundary. - /// - /// Defines both upper and lower boundary. - /// A random between +value and -value. - public static int RandomUniformInt(int value = 1) - { - int max = Math.Abs(value); - int min = max * -1; - - return _rand.Next(min, max); - } - - /// - /// Generates a random value between min and max. - /// - /// The lower boundary. - /// The upper boundary. - /// A random between min and max. - public static float RandomFloat(float min = 0.0f, float max = 1.0f) - { - return (float)_rand.NextDouble() * (max - min) + min; - } - - /// - /// Generates a random by using a single value as both upper and lower boundary. - /// - /// Defines both upper and lower boundary. - /// A random between +value and -value. - public static float RandomUniformFloat(float value = 1.0f) - { - // Ensure that in case of negative values we still return a value between + value and - value. - float max = Math.Abs(value); - float min = max * -1; - - return (float)_rand.NextDouble() * (max - min) + min; - } - - /// - /// Generates a random . - /// - /// A random . - public static Quaternion RandomQuaternion() - { - return Quaternion.Euler( - RandomUniformFloat(180), - RandomUniformFloat(180), - RandomUniformFloat(180)); - } - - /// - /// Generates a uniformly distributed random unit length vector point on a unit sphere. - /// - /// A random . - public static Vector3 RandomVector3() - { - Vector3 output; - - do - { - // Create random float with a mean of 0 and deviation of ±1; - output.X = RandomFloat() * 2.0f - 1.0f; - output.Y = RandomFloat() * 2.0f - 1.0f; - output.Z = RandomFloat() * 2.0f - 1.0f; - - } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); - - output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); - - return output; - } - - /// - /// Generates a uniformly distributed random unit length vector point on a unit sphere in 2D. - /// - /// A random - public static Vector2 RandomVector2() - { - Vector2 output; - - do - { - output.X = RandomFloat() * 2.0f - 1.0f; - output.Y = RandomFloat() * 2.0f - 1.0f; - - } while (output.LengthSquared > 1 || output.LengthSquared< 1e-6f); - - output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); - - return output; - } - - /// - /// Generates a random color. - /// - /// Should the color be generated from a single random Hue value or separate values for each channel. - /// Randomize the alpha value. - /// A nice random color. - public static Color RandomColor(bool trueRandom, bool randomAlpha) - { - float alpha = randomAlpha ? RandomFloat() : 1f; - - if (!trueRandom) - return Color.FromHSV(RandomFloat(0f, 360f), 1f, 1f, alpha); - - return new Color( - RandomFloat(0f, 255f), - RandomFloat(0f, 255f), - RandomFloat(0f, 255f), alpha); - } - } -} diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index e9030af77..ff3439b77 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -60,172 +60,6 @@ namespace FlaxEngine.Utilities }, removeEmptyLines ? StringSplitOptions.RemoveEmptyEntries : StringSplitOptions.None); } - /// - /// Gets a random double. - /// - /// The random. - /// The maximum value - /// A random double - public static double NextDouble(this Random random, double maxValue) - { - return random.NextDouble() * maxValue; - } - - /// - /// Gets a random double. - /// - /// The random. - /// The minimum value - /// The maximum value - /// A random double - public static double NextDouble(this Random random, double minValue, double maxValue) - { - return random.NextDouble() * (maxValue - minValue) + minValue; - } - - /// - /// Gets a random float. - /// - /// The random. - /// A random float - public static float NextFloat(this Random random) - { - return (float)random.NextDouble(); - } - - /// - /// Gets a random float. - /// - /// The random. - /// The maximum value - /// A random float - public static float NextFloat(this Random random, float maxValue) - { - return (float)random.NextDouble() * maxValue; - } - - /// - /// Gets a random float. - /// - /// The random. - /// The minimum value - /// The maximum value - /// - public static float NextFloat(this Random random, float minValue, float maxValue) - { - return (float)random.NextDouble() * (maxValue - minValue) + minValue; - } - - /// - /// Gets a random Color. - /// - /// The random. - /// - public static Color NextColor(this Random random) - { - return new Color(NextFloat(random, 1.0f), - NextFloat(random, 1.0f), - NextFloat(random, 1.0f), - NextFloat(random, 1.0f)); - } - - /// - /// Gets a random Vector2 with components in range [0;1]. - /// - /// The random. - /// - public static Vector2 NextVector2(this Random random) - { - return new Vector2(NextFloat(random, 1.0f), - NextFloat(random, 1.0f)); - } - - /// - /// Gets a random Vector3 with components in range [0;1]. - /// - /// The random. - /// - public static Vector3 NextVector3(this Random random) - { - return new Vector3(NextFloat(random, 1.0f), - NextFloat(random, 1.0f), - NextFloat(random, 1.0f)); - } - - /// - /// Gets a random Vector4 with components in range [0;1]. - /// - /// The random. - /// - public static Vector4 NextVector4(this Random random) - { - return new Vector4(NextFloat(random, 1.0f), - NextFloat(random, 1.0f), - NextFloat(random, 1.0f), - NextFloat(random, 1.0f)); - } - - /// - /// Gets a random Quaternion. - /// - /// The random. - /// - public static Quaternion NextQuaternion(this Random random) - { - return Quaternion.Euler(NextFloat(random, -180, 180), - NextFloat(random, -180, 180), - NextFloat(random, -180, 180)); - } - - /// - /// Gets a random 64-bit signed integer value. - /// - /// The random. - /// - internal static long NextLong(this Random random) - { - var numArray = new byte[8]; - random.NextBytes(numArray); - return (long)(BitConverter.ToUInt64(numArray, 0) & 9223372036854775807L); - } - - /// - /// Generates a random normalized 2D direction vector. - /// - /// An instance of . - /// A random normalized 2D direction vector. - public static Vector2 NextDirection2D(this Random random) - { - return Vector2.Normalize(new Vector2((float)random.NextDouble(), (float)random.NextDouble())); - } - - /// - /// Generates a random normalized 3D direction vector. - /// - /// An instance of . - /// A random normalized 3D direction vector. - public static Vector3 NextDirection3D(this Random random) - { - return Vector3.Normalize(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())); - } - - /// - /// Generates a random point in a circle of a given radius. - /// - /// An instance of . - /// Radius of circle. Default 1.0f. - /// A random point in a circle of a given radius. - public static Vector2 PointInACircle(this Random random, float radius = 1.0f) - { - var randomRadius = (float)random.NextDouble() * radius; - - return new Vector2 - { - X = (float)Math.Cos(random.NextDouble()) * randomRadius, - Y = (float)Math.Sin(random.NextDouble()) * randomRadius, - }; - } - /// /// Adds the elements of the specified collection to the end of the . /// @@ -404,5 +238,194 @@ namespace FlaxEngine.Utilities collection[n] = value; } } + + /// + /// Generates a random . + /// + /// An instance of . + /// A thats either true or false. + public static bool NextBool(this Random random) => random.Next(2) == 1; + + /// + /// Generates a random with a weight value to adjust preference. + /// + /// An instance of . + /// Normalized value that determines the chance to return true. + /// A thats either true or false. + public static bool NextBool(this Random random, float weight = 0.5f) => weight >= NextFloat(random); + + /// + /// Generates a random value between min and max. + /// + /// An instance of . + /// The lower boundary. + /// The upper boundary. + /// A between min and max. + public static byte NextByte(this Random random, byte min = 0, byte max = 2) + { + return (byte)random.Next(min, max); + } + + /// + /// Generates a random value between min and max. + /// + /// An instance of . + /// The min value. + /// The max value. + /// A random between min and max. + public static float NextFloat(this Random random, float min = 0.0f, float max = 2.0f) + { + return (float)random.NextDouble() * (max - min) + min; + } + + /// + /// Generates a random . + /// + /// An instance of . + /// Should the roll value be randomized. + /// A random . + public static Quaternion NextQuaternion(this Random random, bool randomRoll = false) + { + return Quaternion.Euler( + NextFloat(random, -180, 180), + NextFloat(random, -180, 180), + randomRoll ? NextFloat(random, -180, 180) : 0); + } + + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere. + /// + /// An instance of . + /// A random . + public static Vector3 NextVector3(this Random random) + { + Vector3 output; + + do + { + // Create random float with a mean of 0 and deviation of ±1; + output.X = NextFloat(random) * 2.0f - 1.0f; + output.Y = NextFloat(random) * 2.0f - 1.0f; + output.Z = NextFloat(random) * 2.0f - 1.0f; + + } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); + + output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); + + return output; + } + + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere in 2D. + /// + /// An instance of . + /// A random . + public static Vector2 NextVector2(this Random random) + { + Vector2 output; + + do + { + output.X = NextFloat(random) * 2.0f - 1.0f; + output.Y = NextFloat(random) * 2.0f - 1.0f; + + } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); + + output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); + + return output; + } + + /// + /// Generates a random . + /// + /// An instance of . + /// Should the color be generated from a single random Hue value or separate values for each channel. + /// Randomize the alpha value. + /// A nice random . + public static Color NextColor(this Random random, bool trueRandom, bool randomAlpha) + { + float alpha = randomAlpha ? NextFloat(random) : 1f; + + if (!trueRandom) + return Color.FromHSV(NextFloat(random, 0f, 360f), 1f, 1f, alpha); + + return new Color( + NextFloat(random, 0f, 255f), + NextFloat(random, 0f, 255f), + NextFloat(random, 0f, 255f), alpha); + } + + /// + /// Gets a random . + /// + /// An instance of . + /// The maximum value + /// A random + public static double NextDouble(this Random random, double maxValue = 2.0d) + { + return random.NextDouble() * maxValue; + } + + /// + /// Gets a random . + /// + /// An instance of . + /// The minimum value + /// The maximum value + /// A random + public static double NextDouble(this Random random, double minValue = 0.0d, double maxValue = 2.0d) + { + return random.NextDouble() * (maxValue - minValue) + minValue; + } + + /// + /// Gets a random . + /// + /// An instance of . + /// A random + internal static long NextLong(this Random random) + { + var numArray = new byte[8]; + random.NextBytes(numArray); + return (long)(BitConverter.ToUInt64(numArray, 0) & 9223372036854775807L); + } + + /// + /// Generates a random normalized 2D direction . + /// + /// An instance of . + /// A random normalized 2D direction . + public static Vector2 NextDirection2D(this Random random) + { + return Vector2.Normalize(new Vector2((float)random.NextDouble(), (float)random.NextDouble())); + } + + /// + /// Generates a random normalized 3D direction . + /// + /// An instance of . + /// A random normalized 3D direction . + public static Vector3 NextDirection3D(this Random random) + { + return Vector3.Normalize(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())); + } + + /// + /// Generates a random point in a circle of a given radius. + /// + /// An instance of . + /// Radius of circle. Default 1.0f. + /// A random point in a circle of a given radius. + public static Vector2 PointInACircle(this Random random, float radius = 1.0f) + { + var randomRadius = (float)random.NextDouble() * radius; + + return new Vector2 + { + X = (float)Math.Cos(random.NextDouble()) * randomRadius, + Y = (float)Math.Sin(random.NextDouble()) * randomRadius, + }; + } } } From 6649f0d4c23dc680226cd270158ab43b1ab197a3 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Wed, 13 Jan 2021 21:58:16 +0100 Subject: [PATCH 04/46] Removed unnecessary overload Same can be achieved by specifiying max. --- Source/Engine/Utilities/Extensions.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index ff3439b77..15238a701 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -286,6 +286,7 @@ namespace FlaxEngine.Utilities /// A random . public static Quaternion NextQuaternion(this Random random, bool randomRoll = false) { + return Quaternion.Euler( NextFloat(random, -180, 180), NextFloat(random, -180, 180), @@ -360,23 +361,12 @@ namespace FlaxEngine.Utilities /// Gets a random . /// /// An instance of . - /// The maximum value + /// The minimum value + /// The maximum value /// A random - public static double NextDouble(this Random random, double maxValue = 2.0d) + public static double NextDouble(this Random random, double min = 0.0d, double max = 2.0d) { - return random.NextDouble() * maxValue; - } - - /// - /// Gets a random . - /// - /// An instance of . - /// The minimum value - /// The maximum value - /// A random - public static double NextDouble(this Random random, double minValue = 0.0d, double maxValue = 2.0d) - { - return random.NextDouble() * (maxValue - minValue) + minValue; + return random.NextDouble() * (max - min) + min; } /// From 31dd5b852e1cd15dd7f67c141371adac32b2301f Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Wed, 13 Jan 2021 22:04:16 +0100 Subject: [PATCH 05/46] Update Extensions.cs --- Source/Engine/Utilities/Extensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index 15238a701..1e22df1c4 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -258,8 +258,8 @@ namespace FlaxEngine.Utilities /// Generates a random value between min and max. /// /// An instance of . - /// The lower boundary. - /// The upper boundary. + /// The minimum value. + /// The maximum value. /// A between min and max. public static byte NextByte(this Random random, byte min = 0, byte max = 2) { @@ -270,8 +270,8 @@ namespace FlaxEngine.Utilities /// Generates a random value between min and max. /// /// An instance of . - /// The min value. - /// The max value. + /// The minimum value. + /// The maximum value. /// A random between min and max. public static float NextFloat(this Random random, float min = 0.0f, float max = 2.0f) { From 75c3388c00ff4d6e3ee93503b68ece30b9cce159 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Thu, 14 Jan 2021 01:12:13 +0100 Subject: [PATCH 06/46] Corrected comments --- Source/Engine/Utilities/Extensions.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index 1e22df1c4..a47a38ecb 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -304,7 +304,7 @@ namespace FlaxEngine.Utilities do { - // Create random float with a mean of 0 and deviation of ±1; + // Create random float with a mean of 0 and deviation of ±1 output.X = NextFloat(random) * 2.0f - 1.0f; output.Y = NextFloat(random) * 2.0f - 1.0f; output.Z = NextFloat(random) * 2.0f - 1.0f; @@ -361,9 +361,9 @@ namespace FlaxEngine.Utilities /// Gets a random . /// /// An instance of . - /// The minimum value - /// The maximum value - /// A random + /// The minimum value. + /// The maximum value. + /// A random . public static double NextDouble(this Random random, double min = 0.0d, double max = 2.0d) { return random.NextDouble() * (max - min) + min; @@ -373,7 +373,7 @@ namespace FlaxEngine.Utilities /// Gets a random . /// /// An instance of . - /// A random + /// A random . internal static long NextLong(this Random random) { var numArray = new byte[8]; From 437018e614aaf1eea97058aaaf37ced13f5b4d7b Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Thu, 14 Jan 2021 11:50:03 +0100 Subject: [PATCH 07/46] Applied review changes Applied almost all review changes. --- Source/Engine/Utilities/Extensions.cs | 118 ++++++++++---------------- 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index a47a38ecb..f6d2be4c5 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -243,16 +243,9 @@ namespace FlaxEngine.Utilities /// Generates a random . /// /// An instance of . - /// A thats either true or false. - public static bool NextBool(this Random random) => random.Next(2) == 1; - - /// - /// Generates a random with a weight value to adjust preference. - /// - /// An instance of . /// Normalized value that determines the chance to return true. /// A thats either true or false. - public static bool NextBool(this Random random, float weight = 0.5f) => weight >= NextFloat(random); + public static bool NextBool(this Random random, float weight = 0.5f) => random.NextDouble() < weight; /// /// Generates a random value between min and max. @@ -260,24 +253,35 @@ namespace FlaxEngine.Utilities /// An instance of . /// The minimum value. /// The maximum value. - /// A between min and max. - public static byte NextByte(this Random random, byte min = 0, byte max = 2) + /// A random between min and max. + public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue) { return (byte)random.Next(min, max); } /// - /// Generates a random value between min and max. + /// Generates a random value between min and max. /// /// An instance of . /// The minimum value. /// The maximum value. /// A random between min and max. - public static float NextFloat(this Random random, float min = 0.0f, float max = 2.0f) + public static float NextFloat(this Random random, float min = 0.0f, float max = 1.0f) { return (float)random.NextDouble() * (max - min) + min; } + /// + /// Generates a random value between 0 and max. + /// + /// An instance of . + /// The maximum value. + /// A random between min and max. + public static float NextFloat(this Random random, float max) + { + return (float)random.NextDouble() * max; + } + /// /// Generates a random . /// @@ -286,7 +290,6 @@ namespace FlaxEngine.Utilities /// A random . public static Quaternion NextQuaternion(this Random random, bool randomRoll = false) { - return Quaternion.Euler( NextFloat(random, -180, 180), NextFloat(random, -180, 180), @@ -301,6 +304,7 @@ namespace FlaxEngine.Utilities public static Vector3 NextVector3(this Random random) { Vector3 output; + float l; do { @@ -309,42 +313,40 @@ namespace FlaxEngine.Utilities output.Y = NextFloat(random) * 2.0f - 1.0f; output.Z = NextFloat(random) * 2.0f - 1.0f; - } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); + l = output.LengthSquared; - output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); + } while (l > 1 || l < Mathf.Epsilon); + + output.Normalize(); return output; } /// - /// Generates a uniformly distributed random unit length vector point on a unit sphere in 2D. + /// Generates a random point in a circle of a given radius. /// /// An instance of . + /// Radius of circle. Default 1.0f./>. /// A random . - public static Vector2 NextVector2(this Random random) + public static Vector2 NextVector2(this Random random, float radius = 1.0f) { - Vector2 output; + var randomRadius = (float)random.NextDouble() * radius; - do + return new Vector2 { - output.X = NextFloat(random) * 2.0f - 1.0f; - output.Y = NextFloat(random) * 2.0f - 1.0f; - - } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f); - - output *= (1.0f / (float)Math.Sqrt(output.LengthSquared)); - - return output; + X = (float)Math.Cos(random.NextDouble()) * randomRadius, + Y = (float)Math.Sin(random.NextDouble()) * randomRadius, + }; } /// /// Generates a random . /// /// An instance of . - /// Should the color be generated from a single random Hue value or separate values for each channel. + /// Should the color be generated from a single random hue value or separate values for each channel. /// Randomize the alpha value. /// A nice random . - public static Color NextColor(this Random random, bool trueRandom, bool randomAlpha) + public static Color NextColor(this Random random, bool trueRandom = false, bool randomAlpha = false) { float alpha = randomAlpha ? NextFloat(random) : 1f; @@ -352,9 +354,9 @@ namespace FlaxEngine.Utilities return Color.FromHSV(NextFloat(random, 0f, 360f), 1f, 1f, alpha); return new Color( - NextFloat(random, 0f, 255f), - NextFloat(random, 0f, 255f), - NextFloat(random, 0f, 255f), alpha); + NextFloat(random), + NextFloat(random), + NextFloat(random), alpha); } /// @@ -364,11 +366,22 @@ namespace FlaxEngine.Utilities /// The minimum value. /// The maximum value. /// A random . - public static double NextDouble(this Random random, double min = 0.0d, double max = 2.0d) + public static double NextDouble(this Random random, double min = 0.0d, double max = 1.0d) { return random.NextDouble() * (max - min) + min; } + /// + /// Gets a random . + /// + /// An instance of . + /// The maximum value. + /// A random . + public static double NextDouble(this Random random, double max = 1.0d) + { + return random.NextDouble() * max; + } + /// /// Gets a random . /// @@ -378,44 +391,7 @@ namespace FlaxEngine.Utilities { var numArray = new byte[8]; random.NextBytes(numArray); - return (long)(BitConverter.ToUInt64(numArray, 0) & 9223372036854775807L); - } - - /// - /// Generates a random normalized 2D direction . - /// - /// An instance of . - /// A random normalized 2D direction . - public static Vector2 NextDirection2D(this Random random) - { - return Vector2.Normalize(new Vector2((float)random.NextDouble(), (float)random.NextDouble())); - } - - /// - /// Generates a random normalized 3D direction . - /// - /// An instance of . - /// A random normalized 3D direction . - public static Vector3 NextDirection3D(this Random random) - { - return Vector3.Normalize(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())); - } - - /// - /// Generates a random point in a circle of a given radius. - /// - /// An instance of . - /// Radius of circle. Default 1.0f. - /// A random point in a circle of a given radius. - public static Vector2 PointInACircle(this Random random, float radius = 1.0f) - { - var randomRadius = (float)random.NextDouble() * radius; - - return new Vector2 - { - X = (float)Math.Cos(random.NextDouble()) * randomRadius, - Y = (float)Math.Sin(random.NextDouble()) * randomRadius, - }; + return (long)(BitConverter.ToUInt64(numArray, 0) & long.MaxValue); } } } From 8e44e6b23cf2494959c6d278f8bf73f1cc0ea4c9 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Thu, 14 Jan 2021 12:28:51 +0100 Subject: [PATCH 08/46] Applied additional review changes Moved out the random Color created via HSV to its own function as @stefnotch suggested. Added + 1 to the max value in NextByte to include max as a possible value. --- Source/Engine/Utilities/Extensions.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index f6d2be4c5..d7329c8bd 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -256,7 +256,7 @@ namespace FlaxEngine.Utilities /// A random between min and max. public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue) { - return (byte)random.Next(min, max); + return (byte)random.Next(min, max+1); } /// @@ -343,20 +343,25 @@ namespace FlaxEngine.Utilities /// Generates a random . /// /// An instance of . - /// Should the color be generated from a single random hue value or separate values for each channel. /// Randomize the alpha value. /// A nice random . - public static Color NextColor(this Random random, bool trueRandom = false, bool randomAlpha = false) + public static Color NextColor(this Random random, bool randomAlpha = false) { - float alpha = randomAlpha ? NextFloat(random) : 1f; - - if (!trueRandom) - return Color.FromHSV(NextFloat(random, 0f, 360f), 1f, 1f, alpha); - return new Color( NextFloat(random), NextFloat(random), - NextFloat(random), alpha); + NextFloat(random), randomAlpha ? NextFloat(random) : 1f); + } + + /// + /// Generates a random using a single random value for hue. + /// + /// An instance of . + /// Randomize the alpha value. + /// A nice random . + public static ColorHSV NextColorHSV(this Random random, bool randomAlpha = false) + { + return new ColorHSV(NextFloat(random, 0f, 360f), 1f, 1f, randomAlpha ? NextFloat(random) : 1f); } /// From 00c40e279cc7bb9c21fbde1357ac933477fe34f1 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Thu, 14 Jan 2021 13:56:10 +0100 Subject: [PATCH 09/46] Update Extensions.cs --- Source/Engine/Utilities/Extensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index d7329c8bd..339c1c368 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -256,7 +256,7 @@ namespace FlaxEngine.Utilities /// A random between min and max. public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue) { - return (byte)random.Next(min, max+1); + return (byte)random.Next(min, max == byte.MaxValue ? byte.MaxValue + 1 : max); } /// @@ -354,7 +354,7 @@ namespace FlaxEngine.Utilities } /// - /// Generates a random using a single random value for hue. + /// Generates a random . /// /// An instance of . /// Randomize the alpha value. From 042694f45e8c2aa3c7df6d64d0bd0d4122a687e7 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Tue, 9 Feb 2021 17:11:44 +0100 Subject: [PATCH 10/46] Added random enum --- Source/Engine/Utilities/Extensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index 339c1c368..29aa7329a 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -398,5 +398,17 @@ namespace FlaxEngine.Utilities random.NextBytes(numArray); return (long)(BitConverter.ToUInt64(numArray, 0) & long.MaxValue); } + + /// + /// Returns a random value of the given enum. + /// + /// The enum to get the value from. + /// An instance of . + /// A random enum value. + public static TEnum NextEnum(this Random random) + { + Array values = Enum.GetValues(typeof(TEnum)); + return (TEnum)values.GetValue(random.Next(values.Length)); + } } } From 6987834b2dd8343ed13f63c0bfd51614af6048bf Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 15 Feb 2021 10:53:49 +0100 Subject: [PATCH 11/46] Fix default actor bounds --- Source/Engine/Level/Actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index e88791442..f558f25a0 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -44,7 +44,7 @@ Actor::Actor(const SpawnParams& params) , _localTransform(Transform::Identity) , _transform(Transform::Identity) , _sphere(BoundingSphere::Empty) - , _box(BoundingBox::Empty) + , _box(BoundingBox::Zero) , HideFlags(HideFlags::None) { } From 674e09e72b387f5ca149b64cecffd03b81d47e00 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 15 Feb 2021 19:32:43 +0100 Subject: [PATCH 12/46] Add WriteTri helpers funcs. --- Source/Engine/Render2D/Render2D.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index c956566ca..e834c5939 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -270,6 +270,34 @@ FORCE_INLINE Render2DVertex MakeVertex(const Vector2& point, const Vector2& uv, }; } +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& uv0, const Vector2& uv1, const Vector2& uv2, const Color& color0, const Color& color1, const Color& color2) +{ + Render2DVertex tris[3]; + tris[0] = MakeVertex(p0, uv0, color0); + tris[1] = MakeVertex(p1, uv1, color1); + tris[2] = MakeVertex(p2, uv2, color2); + VB.Write(tris, sizeof(tris)); + + uint32 indices[3]; + indices[0] = VBIndex + 0; + indices[1] = VBIndex + 1; + indices[2] = VBIndex + 2; + IB.Write(indices, sizeof(indices)); + + VBIndex += 3; + IBIndex += 3; +} + +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color0, const Color& color1, const Color& color2) +{ + WriteTri(p0, p1, p2, Vector2::Zero, Vector2::Zero, Vector2::Zero, color0, color1, color2); +} + +void WriteTri(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& uv0, const Vector2& uv1, const Vector2& uv2) +{ + WriteTri(p0, p1, p2, uv0, uv1, uv2, Color::Black, Color::Black, Color::Black); +} + void WriteRect(const Rectangle& rect, const Color& color1, const Color& color2, const Color& color3, const Color& color4) { const Vector2 uvUpperLeft = Vector2::Zero; From b1f867f1072d68978e0de3a006987084cf7822c0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Mon, 15 Feb 2021 19:33:25 +0100 Subject: [PATCH 13/46] Add DrawVertices & FillTriangle funcs. --- Source/Engine/Render2D/Render2D.cpp | 38 +++++++++++++++++++++++++++++ Source/Engine/Render2D/Render2D.h | 26 ++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index e834c5939..818265551 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1744,3 +1744,41 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) drawCall.AsBlur.BottomRightY = p.Y; WriteRect(rect, Color::White); } + +void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const Array uvs) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = DrawCallType::FillTexture; + drawCall.StartIB = IBIndex; + drawCall.CountIB = vertices.Count(); + drawCall.AsTexture.Ptr = t; + + for (int32 i = 0; i < vertices.Count(); i += 3) + WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); +} + +void Render2D::DrawVertices(const Array vertices, const Array colors, bool useAlpha) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = useAlpha ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; + drawCall.StartIB = IBIndex; + drawCall.CountIB = vertices.Count(); + + for (int32 i = 0; i < vertices.Count(); i += 3) + WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], colors[i], colors[i + 1], colors[i + 2]); +} + +void Render2D::FillTriangle(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color) +{ + RENDER2D_CHECK_RENDERING_STATE; + + Render2DDrawCall& drawCall = DrawCalls.AddOne(); + drawCall.Type = color.A < 1.0f ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; + drawCall.StartIB = IBIndex; + drawCall.CountIB = 3; + WriteTri(p0, p1, p2, color, color, color); +} diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index a421c56a6..1cf32a886 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -4,6 +4,7 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" +#include "Engine/Core/Collections/Array.h" struct SpriteHandle; struct TextLayoutOptions; @@ -339,4 +340,29 @@ public: /// The target rectangle to draw (blurs its background). /// The blur strength defines how blurry the background is. Larger numbers increase blur, resulting in a larger runtime cost on the GPU. API_FUNCTION() static void DrawBlur(const Rectangle& rect, float blurStrength); + + /// + /// Draws vertices array. + /// + /// The texture. + /// The vertices array. + /// The uvs array. + API_FUNCTION() static void DrawVertices(GPUTexture* t, Array vertices, Array uvs); + + /// + /// Draws vertices array. + /// + /// The vertices array. + /// The colors array. + /// If true alpha blending will be enabled. + API_FUNCTION() static void DrawVertices(Array vertices, Array colors, bool useAlpha); + + /// + /// Fills a triangular area. + /// + /// The first point. + /// The second point. + /// The third point. + /// The color. + API_FUNCTION() static void FillTriangle(const Vector2& p0, const Vector2& p1, const Vector2& p2, const Color& color); }; From 653e9609e4b29116b410e443852bbbd5708bd510 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 10:14:42 +0100 Subject: [PATCH 14/46] Span + Naming --- Source/Engine/Render2D/Render2D.cpp | 4 ++-- Source/Engine/Render2D/Render2D.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 818265551..cd91430bf 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1745,7 +1745,7 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) WriteRect(rect, Color::White); } -void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const Array uvs) +void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs) { RENDER2D_CHECK_RENDERING_STATE; @@ -1759,7 +1759,7 @@ void Render2D::DrawVertices(GPUTexture* t, const Array vertices, const WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); } -void Render2D::DrawVertices(const Array vertices, const Array colors, bool useAlpha) +void Render2D::FillTriangles(const Span& vertices, const Span& colors, bool useAlpha) { RENDER2D_CHECK_RENDERING_STATE; diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index 1cf32a886..bd73fa137 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -5,6 +5,7 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Core/Collections/Array.h" +#include "Engine/Core/Types/Span.h" struct SpriteHandle; struct TextLayoutOptions; @@ -347,7 +348,7 @@ public: /// The texture. /// The vertices array. /// The uvs array. - API_FUNCTION() static void DrawVertices(GPUTexture* t, Array vertices, Array uvs); + API_FUNCTION() static void DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs); /// /// Draws vertices array. @@ -355,7 +356,7 @@ public: /// The vertices array. /// The colors array. /// If true alpha blending will be enabled. - API_FUNCTION() static void DrawVertices(Array vertices, Array colors, bool useAlpha); + API_FUNCTION() static void FillTriangles(const Span& vertices, const Span& colors, bool useAlpha); /// /// Fills a triangular area. From 588ad86f8ed0328dbab5e462bfc90b4d6f867d6d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:05:34 +0100 Subject: [PATCH 15/46] Fix Span Count -> length. --- Source/Engine/Render2D/Render2D.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index cd91430bf..a2e72eeb7 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1752,10 +1752,10 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertice Render2DDrawCall& drawCall = DrawCalls.AddOne(); drawCall.Type = DrawCallType::FillTexture; drawCall.StartIB = IBIndex; - drawCall.CountIB = vertices.Count(); + drawCall.CountIB = vertices.Length(); drawCall.AsTexture.Ptr = t; - for (int32 i = 0; i < vertices.Count(); i += 3) + for (int32 i = 0; i < vertices.Length(); i += 3) WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], uvs[i], uvs[i + 1], uvs[i + 2]); } @@ -1766,9 +1766,9 @@ void Render2D::FillTriangles(const Span& vertices, const Span& c Render2DDrawCall& drawCall = DrawCalls.AddOne(); drawCall.Type = useAlpha ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha; drawCall.StartIB = IBIndex; - drawCall.CountIB = vertices.Count(); + drawCall.CountIB = vertices.Length(); - for (int32 i = 0; i < vertices.Count(); i += 3) + for (int32 i = 0; i < vertices.Length(); i += 3) WriteTri(vertices[i], vertices[i + 1], vertices[i + 2], colors[i], colors[i + 1], colors[i + 2]); } From bc073b73cc33e1b6bbfb9cba27893434a846bc18 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:05:48 +0100 Subject: [PATCH 16/46] Add check. --- Source/Engine/Render2D/Render2D.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index a2e72eeb7..fe1c71c3c 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1747,6 +1747,8 @@ void Render2D::DrawBlur(const Rectangle& rect, float blurStrength) void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertices, const Span& uvs) { + CHECK(vertices.Length() == uvs.Length()) + RENDER2D_CHECK_RENDERING_STATE; Render2DDrawCall& drawCall = DrawCalls.AddOne(); @@ -1761,6 +1763,8 @@ void Render2D::DrawTexturedTriangles(GPUTexture* t, const Span& vertice void Render2D::FillTriangles(const Span& vertices, const Span& colors, bool useAlpha) { + CHECK(vertices.Length() == colors.Length()); + RENDER2D_CHECK_RENDERING_STATE; Render2DDrawCall& drawCall = DrawCalls.AddOne(); From 9144f6dcc92d75c005ddc06bd6844e2ef8ee8997 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 16 Feb 2021 16:08:20 +0100 Subject: [PATCH 17/46] Remove Array include. --- Source/Engine/Render2D/Render2D.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Engine/Render2D/Render2D.h b/Source/Engine/Render2D/Render2D.h index bd73fa137..a6eba94e4 100644 --- a/Source/Engine/Render2D/Render2D.h +++ b/Source/Engine/Render2D/Render2D.h @@ -4,7 +4,6 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Scripting/ScriptingType.h" -#include "Engine/Core/Collections/Array.h" #include "Engine/Core/Types/Span.h" struct SpriteHandle; From 654285e57f7b5a3345480c2d2e271b04bfed3cb2 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Wed, 17 Feb 2021 00:30:24 +0100 Subject: [PATCH 18/46] Separated NextVector and NextUnitVector, refactoring While I was at it I made some slight refactoring making it much more readable and establish consistency --- Source/Engine/Utilities/Extensions.cs | 94 ++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index 29aa7329a..d5e383ab6 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -291,9 +291,26 @@ namespace FlaxEngine.Utilities public static Quaternion NextQuaternion(this Random random, bool randomRoll = false) { return Quaternion.Euler( - NextFloat(random, -180, 180), - NextFloat(random, -180, 180), - randomRoll ? NextFloat(random, -180, 180) : 0); + NextFloat(random, -180.0f, 180.0f), + NextFloat(random, -180.0f, 180.0f), + randomRoll ? NextFloat(random, -180.0f, 180.0f) : 0.0f); + } + + /// + /// Generates a random point in a circle of a given radius. + /// + /// An instance of . + /// Radius of circle. Default 1.0f./>. + /// A random . + public static Vector2 NextUnitVector2(this Random random, float radius = 1.0f) + { + var randomRadius = (float)random.NextDouble() * radius; + + return new Vector2 + { + X = (float)Math.Cos(random.NextDouble()) * randomRadius, + Y = (float)Math.Sin(random.NextDouble()) * randomRadius, + }; } /// @@ -301,7 +318,7 @@ namespace FlaxEngine.Utilities /// /// An instance of . /// A random . - public static Vector3 NextVector3(this Random random) + public static Vector3 NextUnitVector3(this Random random) { Vector3 output; float l; @@ -323,19 +340,53 @@ namespace FlaxEngine.Utilities } /// - /// Generates a random point in a circle of a given radius. + /// Gets a random with components in a given range. /// /// An instance of . - /// Radius of circle. Default 1.0f./>. + /// The minimum value. + /// The maximum value. /// A random . - public static Vector2 NextVector2(this Random random, float radius = 1.0f) + public static Vector2 NextVector2(this Random random, float min = 0.0f, float max = 1.0f) { - var randomRadius = (float)random.NextDouble() * radius; - - return new Vector2 + return new Vector2 { - X = (float)Math.Cos(random.NextDouble()) * randomRadius, - Y = (float)Math.Sin(random.NextDouble()) * randomRadius, + X = NextFloat(random, min, max), + Y = NextFloat(random, min, max) + }; + } + + /// + /// Gets a random with components in a given range. + /// + /// An instance of . + /// The minimum value. + /// The maximum value. + /// A random . + public static Vector3 NextVector3(this Random random, float min = 0.0f, float max = 1.0f) + { + return new Vector3 + { + X = NextFloat(random, min, max), + Y = NextFloat(random, min, max), + Z = NextFloat(random, min, max) + }; + } + + /// + /// Gets a random with components in a given range. + /// + /// An instance of . + /// The minimum value. + /// The maximum value. + /// A random . + public static Vector4 NextVector4(this Random random, float min = 0.0f, float max = 1.0f) + { + return new Vector4 + { + X = NextFloat(random, min, max), + Y = NextFloat(random, min, max), + Z = NextFloat(random, min, max), + W = NextFloat(random, min, max) }; } @@ -347,10 +398,13 @@ namespace FlaxEngine.Utilities /// A nice random . public static Color NextColor(this Random random, bool randomAlpha = false) { - return new Color( - NextFloat(random), - NextFloat(random), - NextFloat(random), randomAlpha ? NextFloat(random) : 1f); + return new Color + { + R = NextFloat(random), + G = NextFloat(random), + B = NextFloat(random), + A = randomAlpha ? NextFloat(random) : 1.0f + }; } /// @@ -361,7 +415,13 @@ namespace FlaxEngine.Utilities /// A nice random . public static ColorHSV NextColorHSV(this Random random, bool randomAlpha = false) { - return new ColorHSV(NextFloat(random, 0f, 360f), 1f, 1f, randomAlpha ? NextFloat(random) : 1f); + return new ColorHSV + { + H = NextFloat(random, 0.0f, 360.0f), + S = 1.0f, + V = 1.0f, + A = randomAlpha ? NextFloat(random) : 1.0f + }; } /// From 1c1e9bb1053c994afd0a513e67b2b9b6beb6a95c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Wed, 17 Feb 2021 12:44:44 +0100 Subject: [PATCH 19/46] Fix re-drawing the background when alpha > 0 . --- Source/Engine/UI/GUI/Tooltip.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 24c0651ed..b4abfaf66 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -223,8 +223,6 @@ namespace FlaxEngine.GUI TextAlignment.Center, TextWrapping.WrapWords ); - - base.Draw(); } /// From 4aabb81c1f05d2a6de0ebe5a4e58e677a6f9f258 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 18 Feb 2021 22:43:46 +0100 Subject: [PATCH 20/46] Use constructors for random generation methods --- Source/Engine/Utilities/Extensions.cs | 86 +++------------------------ 1 file changed, 7 insertions(+), 79 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index d5e383ab6..b3f6d2053 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -70,15 +70,9 @@ namespace FlaxEngine.Utilities public static void AddRange(this ICollection destination, IEnumerable collection) { if (destination == null) - { throw new ArgumentNullException(nameof(destination)); - } - if (collection == null) - { throw new ArgumentNullException(nameof(collection)); - } - foreach (var item in collection) { destination.Add(item); @@ -95,15 +89,9 @@ namespace FlaxEngine.Utilities public static void EnqueueRange(this Queue queue, IEnumerable collection) { if (queue == null) - { throw new ArgumentNullException(nameof(queue)); - } - if (collection == null) - { throw new ArgumentNullException(nameof(collection)); - } - foreach (var item in collection) { queue.Enqueue(item); @@ -120,15 +108,9 @@ namespace FlaxEngine.Utilities public static void PushRange(this Stack stack, IEnumerable collection) { if (stack == null) - { throw new ArgumentNullException(nameof(stack)); - } - if (collection == null) - { throw new ArgumentNullException(nameof(collection)); - } - foreach (var item in collection) { stack.Push(item); @@ -145,15 +127,9 @@ namespace FlaxEngine.Utilities public static void ForEach(this IEnumerable source, Action action) { if (source == null) - { throw new ArgumentNullException(nameof(source)); - } - if (action == null) - { throw new ArgumentNullException(nameof(action)); - } - foreach (var item in source) { action(item); @@ -172,15 +148,9 @@ namespace FlaxEngine.Utilities public static T Choose(this Random random, IList collection) { if (random == null) - { throw new ArgumentNullException(nameof(random)); - } - if (collection == null) - { throw new ArgumentNullException(nameof(collection)); - } - return collection[random.Next(collection.Count)]; } @@ -196,15 +166,9 @@ namespace FlaxEngine.Utilities public static T Choose(this Random random, params T[] collection) { if (random == null) - { throw new ArgumentNullException(nameof(random)); - } - if (collection == null) - { throw new ArgumentNullException(nameof(collection)); - } - return collection[random.Next(collection.Length)]; } @@ -290,10 +254,7 @@ namespace FlaxEngine.Utilities /// A random . public static Quaternion NextQuaternion(this Random random, bool randomRoll = false) { - return Quaternion.Euler( - NextFloat(random, -180.0f, 180.0f), - NextFloat(random, -180.0f, 180.0f), - randomRoll ? NextFloat(random, -180.0f, 180.0f) : 0.0f); + return Quaternion.Euler(NextFloat(random, -180.0f, 180.0f), NextFloat(random, -180.0f, 180.0f), randomRoll ? NextFloat(random, -180.0f, 180.0f) : 0.0f); } /// @@ -305,12 +266,7 @@ namespace FlaxEngine.Utilities public static Vector2 NextUnitVector2(this Random random, float radius = 1.0f) { var randomRadius = (float)random.NextDouble() * radius; - - return new Vector2 - { - X = (float)Math.Cos(random.NextDouble()) * randomRadius, - Y = (float)Math.Sin(random.NextDouble()) * randomRadius, - }; + return new Vector2((float)Math.Cos(random.NextDouble()) * randomRadius, (float)Math.Sin(random.NextDouble()) * randomRadius); } /// @@ -331,7 +287,6 @@ namespace FlaxEngine.Utilities output.Z = NextFloat(random) * 2.0f - 1.0f; l = output.LengthSquared; - } while (l > 1 || l < Mathf.Epsilon); output.Normalize(); @@ -348,11 +303,7 @@ namespace FlaxEngine.Utilities /// A random . public static Vector2 NextVector2(this Random random, float min = 0.0f, float max = 1.0f) { - return new Vector2 - { - X = NextFloat(random, min, max), - Y = NextFloat(random, min, max) - }; + return new Vector2(NextFloat(random, min, max), NextFloat(random, min, max)); } /// @@ -364,12 +315,7 @@ namespace FlaxEngine.Utilities /// A random . public static Vector3 NextVector3(this Random random, float min = 0.0f, float max = 1.0f) { - return new Vector3 - { - X = NextFloat(random, min, max), - Y = NextFloat(random, min, max), - Z = NextFloat(random, min, max) - }; + return new Vector3(NextFloat(random, min, max), NextFloat(random, min, max), NextFloat(random, min, max)); } /// @@ -381,13 +327,7 @@ namespace FlaxEngine.Utilities /// A random . public static Vector4 NextVector4(this Random random, float min = 0.0f, float max = 1.0f) { - return new Vector4 - { - X = NextFloat(random, min, max), - Y = NextFloat(random, min, max), - Z = NextFloat(random, min, max), - W = NextFloat(random, min, max) - }; + return new Vector4(NextFloat(random, min, max), NextFloat(random, min, max), NextFloat(random, min, max), NextFloat(random, min, max)); } /// @@ -398,13 +338,7 @@ namespace FlaxEngine.Utilities /// A nice random . public static Color NextColor(this Random random, bool randomAlpha = false) { - return new Color - { - R = NextFloat(random), - G = NextFloat(random), - B = NextFloat(random), - A = randomAlpha ? NextFloat(random) : 1.0f - }; + return new Color(NextFloat(random), NextFloat(random), NextFloat(random), randomAlpha ? NextFloat(random) : 1.0f); } /// @@ -415,13 +349,7 @@ namespace FlaxEngine.Utilities /// A nice random . public static ColorHSV NextColorHSV(this Random random, bool randomAlpha = false) { - return new ColorHSV - { - H = NextFloat(random, 0.0f, 360.0f), - S = 1.0f, - V = 1.0f, - A = randomAlpha ? NextFloat(random) : 1.0f - }; + return new ColorHSV(NextFloat(random, 0.0f, 360.0f), 1.0f, 1.0f, randomAlpha ? NextFloat(random) : 1.0f); } /// From da24a474eaf3d0f0ad26030739f0a42006984ea9 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Fri, 19 Feb 2021 18:23:23 +0100 Subject: [PATCH 21/46] Add HSVToRGB --- Source/Editor/Surface/Archetypes/Material.cs | 17 +++++++++++++++++ .../MaterialGenerator.Material.cpp | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index ceb9921cb..1c679a039 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -815,6 +815,23 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Output(0, string.Empty, typeof(Vector3), 1), } }, + new NodeArchetype + { + TypeID = 36, + Title = "HSVToRGB", + Description = "Converts a HSV value to linear RGB", + Flags = NodeFlags.MaterialGraph, + Size = new Vector2(160, 25), + DefaultValues = new object[] + { + new Vector3(240, 1, 1), + }, + Elements = new[] + { + NodeElementArchetype.Factory.Input(0, "HSV", true, typeof(Vector3), 0, 0), + NodeElementArchetype.Factory.Output(0, "RGB", typeof(Vector3), 1), + } + } }; } } diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp index c1f250824..2abae3622 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp @@ -458,6 +458,22 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value) value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1} < 1000.0f ? {0} * {1}/1000.0f : {0}"), color.Value, temperature.Value), node); break; } + // HSVToRGB + case 36: + { + const auto hsv = tryGetValue(node->GetBox(0), node->Values[0]).AsVector3(); + + // Normalize + auto color = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}.x / 360, {0}.y, {0}.z)"), hsv.Value), node); + + auto x1 = writeLocal(ValueType::Vector3, String::Format(TEXT("clamp(abs(fmod({0}.x * 6.0 + float3(0.0f, 4.0f, 2.0f), 6.0f) - 3.0f) - 1.0f, 0.0f, 1.0f)"), color.Value), node); + + // Smooth out + auto x2 = writeLocal(ValueType::Vector3, String::Format(TEXT("{0} * {0} * (3.0 - 2.0 * {0})"), x1.Value), node); + value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1}.z * lerp(float3(1.0, 1.0, 1.0), {0}, {1}.y)"), x2.Value, color.Value), node); + + break; + } default: break; } From c475e83aa3910756a9e7f78a04fded1fead78bb4 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sat, 20 Feb 2021 15:44:06 +0100 Subject: [PATCH 22/46] Added RGBToHSV --- Source/Editor/Surface/Archetypes/Material.cs | 19 +++++++++++++- .../MaterialGenerator.Material.cpp | 25 ++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index 1c679a039..2b3bb4703 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -819,7 +819,7 @@ namespace FlaxEditor.Surface.Archetypes { TypeID = 36, Title = "HSVToRGB", - Description = "Converts a HSV value to linear RGB", + Description = "Converts a HSV value to linear RGB [X = 0/360, Y = 0/1, Z = 0/1]", Flags = NodeFlags.MaterialGraph, Size = new Vector2(160, 25), DefaultValues = new object[] @@ -831,6 +831,23 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Input(0, "HSV", true, typeof(Vector3), 0, 0), NodeElementArchetype.Factory.Output(0, "RGB", typeof(Vector3), 1), } + }, + new NodeArchetype + { + TypeID = 37, + Title = "RGBToHSV", + Description = "Converts a linear RGB value to HSV [X = 0/360, Y = 0/1, Z = 0/1]", + Flags = NodeFlags.MaterialGraph, + Size = new Vector2(160, 25), + DefaultValues = new object[] + { + new Vector3(0, 1, 0), + }, + Elements = new[] + { + NodeElementArchetype.Factory.Input(0, "RGB", true, typeof(Vector3), 0, 0), + NodeElementArchetype.Factory.Output(0, "HSV", typeof(Vector3), 1), + } } }; } diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp index 2abae3622..4866b3483 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp @@ -463,15 +463,28 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value) { const auto hsv = tryGetValue(node->GetBox(0), node->Values[0]).AsVector3(); - // Normalize - auto color = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}.x / 360, {0}.y, {0}.z)"), hsv.Value), node); + // Normalize from 360 + auto color = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}.x / 360.0f, {0}.y, {0}.z)"), hsv.Value), node); auto x1 = writeLocal(ValueType::Vector3, String::Format(TEXT("clamp(abs(fmod({0}.x * 6.0 + float3(0.0f, 4.0f, 2.0f), 6.0f) - 3.0f) - 1.0f, 0.0f, 1.0f)"), color.Value), node); - - // Smooth out - auto x2 = writeLocal(ValueType::Vector3, String::Format(TEXT("{0} * {0} * (3.0 - 2.0 * {0})"), x1.Value), node); - value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1}.z * lerp(float3(1.0, 1.0, 1.0), {0}, {1}.y)"), x2.Value, color.Value), node); + value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1}.z * lerp(float3(1.0, 1.0, 1.0), {0}, {1}.y)"), x1.Value, color.Value), node); + break; + } + // RGBToHSV + case 37: + { + // Reference: Ian Taylor, https://www.chilliant.com/rgb2hsv.html + const auto rgb = tryGetValue(node->GetBox(0), node->Values[0]).AsVector3(); + const auto epsilon = writeLocal(ValueType::Float, TEXT("1e-10"), node); + + auto p = writeLocal(ValueType::Vector4, String::Format(TEXT("({0}.g < {0}.b) ? float4({0}.bg, -1.0f, 2.0f/3.0f) : float4({0}.gb, 0.0f, -1.0f/3.0f)"), rgb.Value), node); + auto q = writeLocal(ValueType::Vector4, String::Format(TEXT("({0}.r < {1}.x) ? float4({1}.xyw, {0}.r) : float4({0}.r, {1}.yzx)"), rgb.Value, p.Value), node); + auto c = writeLocal(ValueType::Float, String::Format(TEXT("{0}.x - min({0}.w, {0}.y)"), q.Value), node); + auto h = writeLocal(ValueType::Float , String::Format(TEXT("abs(({0}.w - {0}.y) / (6 * {1} + {2}) + {0}.z)"), q.Value, c.Value, epsilon.Value), node); + + auto hcv = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}, {1}, {2}.x)"), h.Value, c.Value, q.Value), node); + value = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}.x * 360.0f, {0}.y / ({0}.z + {1}), {0}.z)"), hcv.Value, epsilon.Value), node); break; } default: From 05d5fd4fec9abfa493c4749db651133eaf0a7935 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 20 Feb 2021 19:45:58 +0100 Subject: [PATCH 23/46] Optimize compilation time for Win32 platforms --- .../Engine/Platform/Win32/Win32Platform.cpp | 20 ++++++++++++++++++- Source/Engine/Platform/Win32/Win32Platform.h | 19 +++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp index 129ff4249..9efd32cea 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.cpp +++ b/Source/Engine/Platform/Win32/Win32Platform.cpp @@ -11,12 +11,12 @@ #include "Engine/Core/Math/Math.h" #include "IncludeWindowsHeaders.h" #include "Engine/Core/Collections/HashFunctions.h" - #include #include #include #include #include +#include #pragma comment(lib, "Iphlpapi.lib") namespace @@ -299,6 +299,24 @@ void Win32Platform::AtomicStore(int64 volatile* dst, int64 value) InterlockedExchange64(dst, value); } +void Win32Platform::Prefetch(void const* ptr) +{ + _mm_prefetch((char const*)ptr, _MM_HINT_T0); +} + +void* Win32Platform::Allocate(uint64 size, uint64 alignment) +{ +#if COMPILE_WITH_PROFILER + TrackAllocation(size); +#endif + return _aligned_malloc((size_t)size, (size_t)alignment); +} + +void Win32Platform::Free(void* ptr) +{ + _aligned_free(ptr); +} + bool Win32Platform::Is64BitPlatform() { #ifdef PLATFORM_64BITS diff --git a/Source/Engine/Platform/Win32/Win32Platform.h b/Source/Engine/Platform/Win32/Win32Platform.h index b6a4cdd62..f8fb1baca 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.h +++ b/Source/Engine/Platform/Win32/Win32Platform.h @@ -5,7 +5,6 @@ #if PLATFORM_WIN32 #include "Engine/Platform/Base/PlatformBase.h" -#include /// /// The Win32 platform implementation and application management utilities. @@ -27,21 +26,9 @@ public: static int64 AtomicRead(int64 volatile* dst); static void AtomicStore(int32 volatile* dst, int32 value); static void AtomicStore(int64 volatile* dst, int64 value); - FORCE_INLINE static void Prefetch(void const* ptr) - { - _mm_prefetch((char const*)ptr, _MM_HINT_T0); - } - FORCE_INLINE static void* Allocate(uint64 size, uint64 alignment) - { -#if COMPILE_WITH_PROFILER - TrackAllocation(size); -#endif - return _aligned_malloc((size_t)size, (size_t)alignment); - } - FORCE_INLINE static void Free(void* ptr) - { - _aligned_free(ptr); - } + static void Prefetch(void const* ptr); + static void* Allocate(uint64 size, uint64 alignment); + static void Free(void* ptr); static bool Is64BitPlatform(); static BatteryInfo GetBatteryInfo(); static CPUInfo GetCPUInfo(); From 52bc268ee74f6b9ca2751e4a2af4b0cad35b9efa Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sun, 21 Feb 2021 10:05:47 +0100 Subject: [PATCH 24/46] Cleanup 1 --- Source/Editor/Content/Proxy/PrefabProxy.cs | 6 +- Source/Editor/Content/Tree/ContentTreeNode.cs | 3 +- .../CustomEditors/Dedicated/ActorEditor.cs | 13 +++-- .../CustomEditors/Dedicated/ScriptsEditor.cs | 12 ++-- .../CustomEditors/Elements/LabelElement.cs | 6 +- Source/Editor/GUI/ContextMenu/ContextMenu.cs | 48 ++++++++++------ .../Editor/GUI/Dialogs/ColorPickerDialog.cs | 56 ++++++++++++------- Source/Editor/GUI/Docking/DockPanel.cs | 6 +- Source/Editor/GUI/Docking/DockPanelProxy.cs | 6 +- Source/Editor/GUI/PrefabDiffContextMenu.cs | 19 +++++-- .../Editor/GUI/Timeline/Tracks/EventTrack.cs | 14 +++-- Source/Engine/UI/GUI/RenderOutputControl.cs | 4 +- 12 files changed, 126 insertions(+), 67 deletions(-) diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index 276bc0d30..ff3a5bd17 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -78,8 +78,10 @@ namespace FlaxEditor.Content if (actor == null) { // Create default prefab root object - actor = new EmptyActor(); - actor.Name = "Root"; + actor = new EmptyActor + { + Name = "Root" + }; // Cleanup it after usage Object.Destroy(actor, 20.0f); diff --git a/Source/Editor/Content/Tree/ContentTreeNode.cs b/Source/Editor/Content/Tree/ContentTreeNode.cs index 4370bc8e7..78cc7f2b5 100644 --- a/Source/Editor/Content/Tree/ContentTreeNode.cs +++ b/Source/Editor/Content/Tree/ContentTreeNode.cs @@ -120,9 +120,8 @@ namespace FlaxEditor.Content } else { - QueryFilterHelper.Range[] ranges; var text = Text; - if (QueryFilterHelper.Match(filterText, text, out ranges)) + if (QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges)) { // Update highlights if (_highlights == null) diff --git a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs index ad974c55a..93eed826f 100644 --- a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs @@ -70,8 +70,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var scriptsMember = type.GetProperty("Scripts"); if (scriptsMember != ScriptMemberInfo.Null) { - var item = new ItemInfo(scriptsMember); - item.CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor)); + var item = new ItemInfo(scriptsMember) + { + CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor)) + }; items.Add(item); } @@ -232,9 +234,10 @@ namespace FlaxEditor.CustomEditors.Dedicated private TreeNode CreateDiffNode(CustomEditor editor) { - var node = new TreeNode(false); - - node.Tag = editor; + var node = new TreeNode(false) + { + Tag = editor + }; // Removed Script if (editor is RemovedScriptDummy removed) diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index f577e9bae..1e4116894 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -493,8 +493,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var index = (int)image.Tag; - var cm = new ContextMenu(); - cm.Tag = index; + var cm = new ContextMenu + { + Tag = index + }; cm.AddButton("Remove", OnClickMissingRemove); cm.Show(image, image.Size); } @@ -746,8 +748,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var scriptType = TypeUtils.GetType(script.TypeName); var item = scriptType.ContentItem; - var cm = new ContextMenu(); - cm.Tag = script; + var cm = new ContextMenu + { + Tag = script + }; cm.AddButton("Remove", OnClickRemove).Icon = Editor.Instance.Icons.Cross12; cm.AddButton("Move up", OnClickMoveUp).Enabled = script.OrderInParent > 0; cm.AddButton("Move down", OnClickMoveDown).Enabled = script.OrderInParent < script.Actor.Scripts.Length - 1; diff --git a/Source/Editor/CustomEditors/Elements/LabelElement.cs b/Source/Editor/CustomEditors/Elements/LabelElement.cs index 4dd2b0302..d8a91b52e 100644 --- a/Source/Editor/CustomEditors/Elements/LabelElement.cs +++ b/Source/Editor/CustomEditors/Elements/LabelElement.cs @@ -21,8 +21,10 @@ namespace FlaxEditor.CustomEditors.Elements /// public LabelElement() { - Label = new Label(0, 0, 100, 18); - Label.HorizontalAlignment = TextAlignment.Near; + Label = new Label(0, 0, 100, 18) + { + HorizontalAlignment = TextAlignment.Near + }; // TODO: auto height for label } diff --git a/Source/Editor/GUI/ContextMenu/ContextMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenu.cs index 45eff148e..04dded53c 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenu.cs @@ -193,8 +193,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; SortButtons(); return item; } @@ -207,8 +209,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, string shortKeys) { - var item = new ContextMenuButton(this, text, shortKeys); - item.Parent = _panel; + var item = new ContextMenuButton(this, text, shortKeys) + { + Parent = _panel + }; SortButtons(); return item; } @@ -221,8 +225,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, Action clicked) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; item.Clicked += clicked; SortButtons(); return item; @@ -236,8 +242,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, Action clicked) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; item.ButtonClicked += clicked; SortButtons(); return item; @@ -252,8 +260,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, string shortKeys, Action clicked) { - var item = new ContextMenuButton(this, text, shortKeys); - item.Parent = _panel; + var item = new ContextMenuButton(this, text, shortKeys) + { + Parent = _panel + }; item.Clicked += clicked; SortButtons(); return item; @@ -285,8 +295,10 @@ namespace FlaxEditor.GUI.ContextMenu var item = GetChildMenu(text); if (item == null) { - item = new ContextMenuChildMenu(this, text); - item.Parent = _panel; + item = new ContextMenuChildMenu(this, text) + { + Parent = _panel + }; } return item; @@ -299,8 +311,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuChildMenu AddChildMenu(string text) { - var item = new ContextMenuChildMenu(this, text); - item.Parent = _panel; + var item = new ContextMenuChildMenu(this, text) + { + Parent = _panel + }; return item; } @@ -310,8 +324,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuSeparator AddSeparator() { - var item = new ContextMenuSeparator(this); - item.Parent = _panel; + var item = new ContextMenuSeparator(this) + { + Parent = _panel + }; return item; } diff --git a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs index 9eb63ee48..c409dbbd1 100644 --- a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs +++ b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs @@ -113,53 +113,71 @@ namespace FlaxEditor.GUI.Dialogs _onClosed = pickerClosed; // Selector - _cSelector = new ColorSelectorWithSliders(180, 18); - _cSelector.Location = new Vector2(PickerMargin, PickerMargin); + _cSelector = new ColorSelectorWithSliders(180, 18) + { + Location = new Vector2(PickerMargin, PickerMargin), + Parent = this + }; _cSelector.ColorChanged += x => SelectedColor = x; - _cSelector.Parent = this; // Red - _cRed = new FloatValueBox(0, _cSelector.Right + PickerMargin + RGBAMargin + ChannelTextWidth, PickerMargin, 100, 0, float.MaxValue, 0.001f); + _cRed = new FloatValueBox(0, _cSelector.Right + PickerMargin + RGBAMargin + ChannelTextWidth, PickerMargin, 100, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cRed.ValueChanged += OnRGBAChanged; - _cRed.Parent = this; // Green - _cGreen = new FloatValueBox(0, _cRed.X, _cRed.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cGreen = new FloatValueBox(0, _cRed.X, _cRed.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cGreen.ValueChanged += OnRGBAChanged; - _cGreen.Parent = this; // Blue - _cBlue = new FloatValueBox(0, _cRed.X, _cGreen.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cBlue = new FloatValueBox(0, _cRed.X, _cGreen.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cBlue.ValueChanged += OnRGBAChanged; - _cBlue.Parent = this; // Alpha - _cAlpha = new FloatValueBox(0, _cRed.X, _cBlue.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cAlpha = new FloatValueBox(0, _cRed.X, _cBlue.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cAlpha.ValueChanged += OnRGBAChanged; - _cAlpha.Parent = this; // Hue - _cHue = new FloatValueBox(0, PickerMargin + HSVMargin + ChannelTextWidth, _cSelector.Bottom + PickerMargin, 100, 0, 360); + _cHue = new FloatValueBox(0, PickerMargin + HSVMargin + ChannelTextWidth, _cSelector.Bottom + PickerMargin, 100, 0, 360) + { + Parent = this + }; _cHue.ValueChanged += OnHSVChanged; - _cHue.Parent = this; // Saturation - _cSaturation = new FloatValueBox(0, _cHue.X, _cHue.Bottom + ChannelsMargin, _cHue.Width, 0, 100.0f, 0.1f); + _cSaturation = new FloatValueBox(0, _cHue.X, _cHue.Bottom + ChannelsMargin, _cHue.Width, 0, 100.0f, 0.1f) + { + Parent = this + }; _cSaturation.ValueChanged += OnHSVChanged; - _cSaturation.Parent = this; // Value - _cValue = new FloatValueBox(0, _cHue.X, _cSaturation.Bottom + ChannelsMargin, _cHue.Width, 0, float.MaxValue, 0.1f); + _cValue = new FloatValueBox(0, _cHue.X, _cSaturation.Bottom + ChannelsMargin, _cHue.Width, 0, float.MaxValue, 0.1f) + { + Parent = this + }; _cValue.ValueChanged += OnHSVChanged; - _cValue.Parent = this; // Set valid dialog size based on UI content _dialogSize = Size = new Vector2(_cRed.Right + PickerMargin, 300); // Hex const float hexTextBoxWidth = 80; - _cHex = new TextBox(false, Width - hexTextBoxWidth - PickerMargin, _cSelector.Bottom + PickerMargin, hexTextBoxWidth); - _cHex.Parent = this; + _cHex = new TextBox(false, Width - hexTextBoxWidth - PickerMargin, _cSelector.Bottom + PickerMargin, hexTextBoxWidth) + { + Parent = this + }; _cHex.EditEnd += OnHexChanged; // Cancel diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index f6e10e653..2865515da 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -597,8 +597,10 @@ namespace FlaxEditor.GUI.Docking if (_tabsProxy == null) { // Create proxy and make set simple full dock - _tabsProxy = new DockPanelProxy(this); - _tabsProxy.Parent = this; + _tabsProxy = new DockPanelProxy(this) + { + Parent = this + }; _tabsProxy.UnlockChildrenRecursive(); } } diff --git a/Source/Editor/GUI/Docking/DockPanelProxy.cs b/Source/Editor/GUI/Docking/DockPanelProxy.cs index 748ae726c..f83f23ad9 100644 --- a/Source/Editor/GUI/Docking/DockPanelProxy.cs +++ b/Source/Editor/GUI/Docking/DockPanelProxy.cs @@ -496,8 +496,10 @@ namespace FlaxEditor.GUI.Docking private void ShowContextMenu(DockWindow tab, ref Vector2 location) { - var menu = new ContextMenu.ContextMenu(); - menu.Tag = tab; + var menu = new ContextMenu.ContextMenu + { + Tag = tab + }; tab.OnShowContextMenu(menu); menu.AddButton("Close", OnTabMenuCloseClicked); menu.AddButton("Close All", OnTabMenuCloseAllClicked); diff --git a/Source/Editor/GUI/PrefabDiffContextMenu.cs b/Source/Editor/GUI/PrefabDiffContextMenu.cs index 9f40b11fb..8adda75e5 100644 --- a/Source/Editor/GUI/PrefabDiffContextMenu.cs +++ b/Source/Editor/GUI/PrefabDiffContextMenu.cs @@ -41,13 +41,19 @@ namespace FlaxEditor.GUI // Buttons float buttonsWidth = (width - 6.0f) * 0.5f; float buttonsHeight = 20.0f; - var revertAll = new Button(2.0f, 2.0f, buttonsWidth, buttonsHeight); - revertAll.Text = "Revert All"; - revertAll.Parent = this; + + var revertAll = new Button(2.0f, 2.0f, buttonsWidth, buttonsHeight) + { + Text = "Revert All", + Parent = this + }; revertAll.Clicked += OnRevertAllClicked; - var applyAll = new Button(revertAll.Right + 2.0f, 2.0f, buttonsWidth, buttonsHeight); - applyAll.Text = "Apply All"; - applyAll.Parent = this; + + var applyAll = new Button(revertAll.Right + 2.0f, 2.0f, buttonsWidth, buttonsHeight) + { + Text = "Apply All", + Parent = this + }; applyAll.Clicked += OnApplyAllClicked; // Actual panel @@ -56,6 +62,7 @@ namespace FlaxEditor.GUI Bounds = new Rectangle(0, applyAll.Bottom + 2.0f, Width, Height - applyAll.Bottom - 2.0f), Parent = this }; + Tree = new Tree.Tree { AnchorPreset = AnchorPresets.HorizontalStretchTop, diff --git a/Source/Editor/GUI/Timeline/Tracks/EventTrack.cs b/Source/Editor/GUI/Timeline/Tracks/EventTrack.cs index 683458b16..cdd6fc83f 100644 --- a/Source/Editor/GUI/Timeline/Tracks/EventTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/EventTrack.cs @@ -72,8 +72,11 @@ namespace FlaxEditor.GUI.Timeline.Tracks { var time = stream.ReadSingle(); - var key = new EventKey(); - key.Parameters = new object[paramsCount]; + var key = new EventKey + { + Parameters = new object[paramsCount] + }; + for (int j = 0; j < paramsCount; j++) { stream.Read(dataBuffer, 0, e.EventParamsSizes[j]); @@ -316,8 +319,11 @@ namespace FlaxEditor.GUI.Timeline.Tracks } // Build default value - var defaultValue = new EventKey(); - defaultValue.Parameters = new object[EventParamsTypes.Length]; + var defaultValue = new EventKey + { + Parameters = new object[EventParamsTypes.Length] + }; + for (int i = 0; i < EventParamsTypes.Length; i++) defaultValue.Parameters[i] = Activator.CreateInstance(EventParamsTypes[i]); Events.DefaultValue = defaultValue; diff --git a/Source/Engine/UI/GUI/RenderOutputControl.cs b/Source/Engine/UI/GUI/RenderOutputControl.cs index 74210c9df..be0c300fe 100644 --- a/Source/Engine/UI/GUI/RenderOutputControl.cs +++ b/Source/Engine/UI/GUI/RenderOutputControl.cs @@ -89,13 +89,11 @@ namespace FlaxEngine.GUI /// Invalid task. public RenderOutputControl(SceneRenderTask task) { - if (task == null) - throw new ArgumentNullException(); + _task = task ?? throw new ArgumentNullException(); _backBuffer = GPUDevice.Instance.CreateTexture(); _resizeTime = ResizeCheckTime; - _task = task; _task.Output = _backBuffer; _task.End += OnEnd; From 92fafe877c44f2dd7656bd1b752cb47f229a28e0 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Sun, 21 Feb 2021 10:23:01 +0100 Subject: [PATCH 25/46] Cleanup 2 --- Source/Editor/Modules/SceneModule.cs | 7 +- Source/Editor/Modules/UIModule.cs | 6 +- Source/Editor/Options/Editor.cs | 8 +- Source/Editor/Options/OptionsModule.cs | 71 +++++++------- Source/Editor/SceneGraph/GUI/ActorTreeNode.cs | 87 ++++++++++------- .../Archetypes/Animation.MultiBlend.cs | 95 ++++++++++++------- .../Archetypes/Animation.StateMachine.cs | 8 +- Source/Editor/Surface/Archetypes/Function.cs | 7 +- .../Editor/Surface/ContextMenu/VisjectCM.cs | 76 ++++++++++----- .../Tools/Terrain/CreateTerrainDialog.cs | 6 +- .../Windows/Assets/PrefabWindow.Hierarchy.cs | 6 +- 11 files changed, 234 insertions(+), 143 deletions(-) diff --git a/Source/Editor/Modules/SceneModule.cs b/Source/Editor/Modules/SceneModule.cs index 9fd860a51..6334225fd 100644 --- a/Source/Editor/Modules/SceneModule.cs +++ b/Source/Editor/Modules/SceneModule.cs @@ -138,8 +138,11 @@ namespace FlaxEditor.Modules public void CreateSceneFile(string path) { // Create a sample scene - var scene = new Scene(); - scene.StaticFlags = StaticFlags.FullyStatic; + var scene = new Scene + { + StaticFlags = StaticFlags.FullyStatic + }; + // var sun = scene.AddChild(); sun.Name = "Sun"; diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index 6b01986a9..6d34114b1 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -378,8 +378,10 @@ namespace FlaxEditor.Modules private void InitMainMenu(RootControl mainWindow) { - MainMenu = new MainMenu(mainWindow); - MainMenu.Parent = mainWindow; + MainMenu = new MainMenu(mainWindow) + { + Parent = mainWindow + }; // File MenuFile = MainMenu.AddButton("File"); diff --git a/Source/Editor/Options/Editor.cs b/Source/Editor/Options/Editor.cs index 539cef444..0309187cd 100644 --- a/Source/Editor/Options/Editor.cs +++ b/Source/Editor/Options/Editor.cs @@ -21,9 +21,11 @@ namespace FlaxEditor.Options // Reset options button layout.Space(30); var panel = layout.Space(30); - var resetButton = new Button(4, 4, 100); - resetButton.Text = "Reset"; - resetButton.Parent = panel.ContainerControl; + var resetButton = new Button(4, 4, 100) + { + Text = "Reset", + Parent = panel.ContainerControl + }; resetButton.Clicked += OnResetButtonClicked; } diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index 3c501de85..fac8a4a78 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -212,45 +212,46 @@ namespace FlaxEditor.Options /// The style object. public Style CreateDefaultStyle() { - var style = new Style(); - // Metro Style colors - style.Background = Color.FromBgra(0xFF1C1C1C); - style.LightBackground = Color.FromBgra(0xFF2D2D30); - style.Foreground = Color.FromBgra(0xFFFFFFFF); - style.ForegroundGrey = Color.FromBgra(0xFFA9A9B3); - style.ForegroundDisabled = Color.FromBgra(0xFF787883); - style.BackgroundHighlighted = Color.FromBgra(0xFF54545C); - style.BorderHighlighted = Color.FromBgra(0xFF6A6A75); - style.BackgroundSelected = Color.FromBgra(0xFF007ACC); - style.BorderSelected = Color.FromBgra(0xFF1C97EA); - style.BackgroundNormal = Color.FromBgra(0xFF3F3F46); - style.BorderNormal = Color.FromBgra(0xFF54545C); - style.TextBoxBackground = Color.FromBgra(0xFF333337); - style.TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46); + var options = Options; + var style = new Style + { + Background = Color.FromBgra(0xFF1C1C1C), + LightBackground = Color.FromBgra(0xFF2D2D30), + Foreground = Color.FromBgra(0xFFFFFFFF), + ForegroundGrey = Color.FromBgra(0xFFA9A9B3), + ForegroundDisabled = Color.FromBgra(0xFF787883), + BackgroundHighlighted = Color.FromBgra(0xFF54545C), + BorderHighlighted = Color.FromBgra(0xFF6A6A75), + BackgroundSelected = Color.FromBgra(0xFF007ACC), + BorderSelected = Color.FromBgra(0xFF1C97EA), + BackgroundNormal = Color.FromBgra(0xFF3F3F46), + BorderNormal = Color.FromBgra(0xFF54545C), + TextBoxBackground = Color.FromBgra(0xFF333337), + TextBoxBackgroundSelected = Color.FromBgra(0xFF3F3F46), + + // Fonts + FontTitle = options.Interface.TitleFont.GetFont(), + FontLarge = options.Interface.LargeFont.GetFont(), + FontMedium = options.Interface.MediumFont.GetFont(), + FontSmall = options.Interface.SmallFont.GetFont(), + + // Icons + ArrowDown = Editor.Icons.ArrowDown12, + ArrowRight = Editor.Icons.ArrowRight12, + Search = Editor.Icons.Search12, + Settings = Editor.Icons.Settings12, + Cross = Editor.Icons.Cross12, + CheckBoxIntermediate = Editor.Icons.CheckBoxIntermediate12, + CheckBoxTick = Editor.Icons.CheckBoxTick12, + StatusBarSizeGrip = Editor.Icons.StatusBarSizeGrip12, + Translate = Editor.Icons.Translate16, + Rotate = Editor.Icons.Rotate16, + Scale = Editor.Icons.Scale16 + }; style.DragWindow = style.BackgroundSelected * 0.7f; style.ProgressNormal = Color.FromBgra(0xFF0ad328); - // Fonts - var options = Options; - style.FontTitle = options.Interface.TitleFont.GetFont(); - style.FontLarge = options.Interface.LargeFont.GetFont(); - style.FontMedium = options.Interface.MediumFont.GetFont(); - style.FontSmall = options.Interface.SmallFont.GetFont(); - - // Icons - style.ArrowDown = Editor.Icons.ArrowDown12; - style.ArrowRight = Editor.Icons.ArrowRight12; - style.Search = Editor.Icons.Search12; - style.Settings = Editor.Icons.Settings12; - style.Cross = Editor.Icons.Cross12; - style.CheckBoxIntermediate = Editor.Icons.CheckBoxIntermediate12; - style.CheckBoxTick = Editor.Icons.CheckBoxTick12; - style.StatusBarSizeGrip = Editor.Icons.StatusBarSizeGrip12; - style.Translate = Editor.Icons.Translate16; - style.Rotate = Editor.Icons.Rotate16; - style.Scale = Editor.Icons.Scale16; - style.SharedTooltip = new Tooltip(); return style; diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs index e04dd7741..3874b5011 100644 --- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs +++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs @@ -386,15 +386,20 @@ namespace FlaxEditor.SceneGraph.GUI public ReparentAction(List actors) { - var allActors = new List(); - allActors.Capacity = Mathf.NextPowerOfTwo(actors.Count); + var allActors = new List + { + Capacity = Mathf.NextPowerOfTwo(actors.Count) + }; + for (int i = 0; i < actors.Count; i++) { GetAllActors(allActors, actors[i]); } - var allScripts = new List