From 12fd7274a9c5b8414850e7dec07c1f04ac70d9ae Mon Sep 17 00:00:00 2001 From: stefnotch Date: Mon, 29 Mar 2021 10:54:48 +0200 Subject: [PATCH 01/35] Fix DPI regression: use the overrideable RootWindow instead of _root --- Source/Engine/UI/GUI/Control.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index 96b7bf22b..1b6779ff8 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -313,7 +313,7 @@ namespace FlaxEngine.GUI /// /// Gets the control DPI scale factor (1 is default). Includes custom DPI scale. /// - public float DpiScale => _root?.RootWindow?.Window.DpiScale ?? Platform.DpiScale; + public float DpiScale => RootWindow?.Window.DpiScale ?? Platform.DpiScale; /// /// Gets screen position of the control (upper left corner). From 2abb21503454cb35327a7b02e4bad88d78def2fc Mon Sep 17 00:00:00 2001 From: stefnotch Date: Mon, 29 Mar 2021 12:06:24 +0200 Subject: [PATCH 02/35] Update CONTRIBUTING.md --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 236fa6d67..ada5e5fa5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,3 +32,19 @@ Go check out our [Trello](https://trello.com/b/NQjLXRCP/flax-roadmap). Thank you for taking interest in contributing to Flax! + +## **Common issues** + +Below are some common issues that someone working with the FlaxEngine source code might run into. Hopefully some of those issues will get fixed in the future. If you know how, please contribute! + +* Missing MSVC toolset + * Install it through the Visual Studio Installer +* Building or attaching fails + * Run `GenerateProjectFiles.bat` + * Rebuild `Flax.Build` + * Make sure that there isn't a stray FlaxEngine process running in the background + * First start Flax and then attach the C# debugger + * Configure the C# FlaxEngine project by going into the project properties, then the debug tab and selecting "Start external program" `Flax\FlaxEngine\Binaries\Editor\Win64\Debug\FlaxEditor.exe` + * Then you can also set command line arguments such as `-project "C:\Users\PROFILE\Documents\Flax Projects\FlaxSamples\BasicTemplate"` +* Git LFS + * Push with `git push --no-verify` From 9581f7b10ed46573db1903fdfd59e95edfa5dced Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 29 Mar 2021 14:41:29 +0200 Subject: [PATCH 03/35] Fix using cross-module references inside C++ game project --- Source/Tools/Flax.Build/Build/Builder.cs | 11 ++++++++++ .../Build/NativeCpp/Builder.NativeCpp.cs | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Source/Tools/Flax.Build/Build/Builder.cs b/Source/Tools/Flax.Build/Build/Builder.cs index 187a59776..1bcfca18e 100644 --- a/Source/Tools/Flax.Build/Build/Builder.cs +++ b/Source/Tools/Flax.Build/Build/Builder.cs @@ -82,6 +82,17 @@ namespace Flax.Build return GetModuleProject(module, buildData.Project); } + /// + /// Checks if the project that contains a given module (checks for modules located in the given project Source folder). + /// + /// The module. + /// The project to check. + /// True if project contains that module inside, otherwise it's external or referenced. + public static bool IsModuleFromProject(Module module, ProjectInfo project) + { + return GetModuleProject(module, project) == project; + } + /// /// Builds the targets. /// diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs b/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs index 5b748a481..0c3eedd53 100644 --- a/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs +++ b/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs @@ -696,6 +696,26 @@ namespace Flax.Build { // Export symbols from binary module moduleOptions.CompileEnv.PreprocessorDefinitions.Add(binaryModuleNameUpper + (target.UseSymbolsExports ? "_API=" + toolchain.DllExport : "_API=")); + + // Import symbols from binary modules containing the referenced modules (from this project only, external ones are handled via ReferenceBuilds below) + foreach (var moduleName in moduleOptions.PrivateDependencies) + { + var dependencyModule = buildData.Rules.GetModule(moduleName); + if (dependencyModule != null && !string.IsNullOrEmpty(dependencyModule.BinaryModuleName) && dependencyModule.BinaryModuleName != binaryModule.Key && IsModuleFromProject(dependencyModule, project) && buildData.Modules.TryGetValue(dependencyModule, out var dependencyOptions)) + { + // Import symbols from referenced binary module + moduleOptions.CompileEnv.PreprocessorDefinitions.Add(dependencyModule.BinaryModuleName.ToUpperInvariant() + "_API=" + toolchain.DllImport); + } + } + foreach (var moduleName in moduleOptions.PublicDependencies) + { + var dependencyModule = buildData.Rules.GetModule(moduleName); + if (dependencyModule != null && !string.IsNullOrEmpty(dependencyModule.BinaryModuleName) && dependencyModule.BinaryModuleName != binaryModule.Key && IsModuleFromProject(dependencyModule, project) && buildData.Modules.TryGetValue(dependencyModule, out var dependencyOptions)) + { + // Import symbols from referenced binary module + moduleOptions.CompileEnv.PreprocessorDefinitions.Add(dependencyModule.BinaryModuleName.ToUpperInvariant() + "_API=" + toolchain.DllImport); + } + } } else { From 2524d93f6b6cdd0cec961356c111136910a3ccd6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 30 Mar 2021 21:43:03 +0200 Subject: [PATCH 04/35] Add Set/Get Up direction. --- .../Engine/Physics/Colliders/CharacterController.cpp | 11 +++++++++++ Source/Engine/Physics/Colliders/CharacterController.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/Source/Engine/Physics/Colliders/CharacterController.cpp b/Source/Engine/Physics/Colliders/CharacterController.cpp index 4315ce8ba..d13aca3b7 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.cpp +++ b/Source/Engine/Physics/Colliders/CharacterController.cpp @@ -82,6 +82,17 @@ void CharacterController::SetStepOffset(float value) _controller->setStepOffset(value); } +void CharacterController::SetUpDirection(const Vector3& up) +{ + if (_controller) + _controller->setUpDirection(C2P(up)); +} + +Vector3 CharacterController::GetUpDirection() const +{ + return _controller ? P2C(_controller->getUpDirection()) : Vector3::Up; +} + void CharacterController::SetMinMoveDistance(float value) { _minMoveDistance = Math::Max(value, 0.0f); diff --git a/Source/Engine/Physics/Colliders/CharacterController.h b/Source/Engine/Physics/Colliders/CharacterController.h index f850b9124..5f0faa793 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.h +++ b/Source/Engine/Physics/Colliders/CharacterController.h @@ -141,6 +141,16 @@ public: /// API_PROPERTY() void SetStepOffset(float value); + /// + /// Sets the character up vector. + /// + API_PROPERTY() void SetUpDirection(const Vector3& up); + + /// + /// Gets the character up vector. + /// + API_PROPERTY() Vector3 GetUpDirection() const; + /// /// Gets the minimum move distance of the character controller. The minimum traveled distance to consider. If traveled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small. /// From a3ca6b0dca51271ce165fe705874827fdeb61cd7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Tue, 30 Mar 2021 21:47:18 +0200 Subject: [PATCH 05/35] Add overwrite prompt for SaveDialog. --- Source/Engine/Platform/Windows/WindowsFileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Platform/Windows/WindowsFileSystem.cpp b/Source/Engine/Platform/Windows/WindowsFileSystem.cpp index 1816c9552..6cf467976 100644 --- a/Source/Engine/Platform/Windows/WindowsFileSystem.cpp +++ b/Source/Engine/Platform/Windows/WindowsFileSystem.cpp @@ -260,7 +260,7 @@ bool WindowsFileSystem::ShowSaveFileDialog(Window* parentWindow, const StringVie of.lpstrFilter = filter.HasChars() ? filter.Get() : nullptr; of.lpstrFile = fileNamesBuffer.Get(); of.nMaxFile = maxFilenamesSize; - of.Flags = OFN_EXPLORER | OFN_ENABLESIZING; + of.Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT; of.lpstrTitle = title.HasChars() ? title.Get() : nullptr; of.lpstrInitialDir = initialDirectory.HasChars() ? initialDirectory.Get() : nullptr; if (parentWindow) From f8d6f8ffb54892cd7542bf14295d74d0e50743ff Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 30 Mar 2021 22:07:40 +0200 Subject: [PATCH 06/35] Fix using references to projects outside the main project #397 --- Source/Tools/Flax.Build/Build/Builder.Projects.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Build/Builder.Projects.cs b/Source/Tools/Flax.Build/Build/Builder.Projects.cs index b9ae1e319..ba3c4c7bd 100644 --- a/Source/Tools/Flax.Build/Build/Builder.Projects.cs +++ b/Source/Tools/Flax.Build/Build/Builder.Projects.cs @@ -246,7 +246,7 @@ namespace Flax.Build // Get all modules aggregated into all binary modules used in all configurations of this target foreach (var configurationData in mainProject.Configurations) { - var configurationBinaryModules = GetBinaryModules(rootProject, configurationData.Target, configurationData.Modules); + var configurationBinaryModules = GetBinaryModules(projectInfo, configurationData.Target, configurationData.Modules); foreach (var configurationBinaryModule in configurationBinaryModules) { // Skip if none of the included binary modules is inside the project workspace (eg. merged external binary modules from engine to game project) @@ -272,7 +272,7 @@ namespace Flax.Build { var referenceBuildOptions = GetBuildOptions(referenceTarget, configurationData.TargetBuildOptions.Platform, configurationData.TargetBuildOptions.Toolchain, configurationData.Architecture, configurationData.Configuration, reference.Project.ProjectFolderPath); var referenceModules = CollectModules(rules, referenceBuildOptions.Platform, referenceTarget, referenceBuildOptions, referenceBuildOptions.Toolchain, referenceBuildOptions.Architecture, referenceBuildOptions.Configuration); - var referenceBinaryModules = GetBinaryModules(rootProject, referenceTarget, referenceModules); + var referenceBinaryModules = GetBinaryModules(projectInfo, referenceTarget, referenceModules); foreach (var binaryModule in referenceBinaryModules) { project.Defines.Add(binaryModule.Key.ToUpperInvariant() + "_API="); From 77f971693226109c22d46f994eb11949abded0c8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 30 Mar 2021 22:27:24 +0200 Subject: [PATCH 07/35] Fix selecting spline points #409 --- Source/Editor/SceneGraph/Actors/SplineNode.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Editor/SceneGraph/Actors/SplineNode.cs b/Source/Editor/SceneGraph/Actors/SplineNode.cs index 293e7d030..b4914941a 100644 --- a/Source/Editor/SceneGraph/Actors/SplineNode.cs +++ b/Source/Editor/SceneGraph/Actors/SplineNode.cs @@ -367,6 +367,15 @@ namespace FlaxEditor.SceneGraph.Actors } } + /// + public override bool RayCastSelf(ref RayCastData ray, out float distance, out Vector3 normal) + { + // Select only spline points + normal = Vector3.Up; + distance = float.MaxValue; + return false; + } + /// public override void OnDispose() { From 93f23af92e7467eeb732e02a0a78de3e714608ce Mon Sep 17 00:00:00 2001 From: stefnotch Date: Tue, 30 Mar 2021 23:03:56 +0200 Subject: [PATCH 08/35] Scale dockwindow size by DPI scale For those gangstas with 4k screens ;) --- Source/Editor/GUI/Docking/DockWindow.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs index 5e94ef547..1a28b1307 100644 --- a/Source/Editor/GUI/Docking/DockWindow.cs +++ b/Source/Editor/GUI/Docking/DockWindow.cs @@ -59,7 +59,10 @@ namespace FlaxEditor.GUI.Docking /// /// Gets the default window size. /// - public virtual Vector2 DefaultSize => new Vector2(900, 580); + /// + /// Scaled by the DPI, because the window should be large enough for its content on every monitor + /// + public virtual Vector2 DefaultSize => new Vector2(900, 580) * DpiScale; /// /// Gets the serialization typename. From 20f9bdc2098101ab560500c77befddf90c80936d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 31 Mar 2021 10:12:05 +0200 Subject: [PATCH 09/35] Fix regression in adding model material slots --- Source/Editor/Windows/Assets/ModelWindow.cs | 15 ++++++++++++--- .../Editor/Windows/Assets/SkinnedModelWindow.cs | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Windows/Assets/ModelWindow.cs b/Source/Editor/Windows/Assets/ModelWindow.cs index e8a054222..b16a01a73 100644 --- a/Source/Editor/Windows/Assets/ModelWindow.cs +++ b/Source/Editor/Windows/Assets/ModelWindow.cs @@ -399,9 +399,18 @@ namespace FlaxEditor.Windows.Assets ShadowsCastingMode[] shadowsModes = new ShadowsCastingMode[value.Length]; for (int i = 0; i < value.Length; i++) { - materials[i] = value[i].Material; - names[i] = value[i].Name; - shadowsModes[i] = value[i].ShadowsMode; + if (value[i] != null) + { + materials[i] = value[i].Material; + names[i] = value[i].Name; + shadowsModes[i] = value[i].ShadowsMode; + } + else + { + materials[i] = null; + names[i] = "Material " + i; + shadowsModes[i] = ShadowsCastingMode.All; + } } Asset.SetupMaterialSlots(value.Length); diff --git a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs index b002aa0fe..f3d228f45 100644 --- a/Source/Editor/Windows/Assets/SkinnedModelWindow.cs +++ b/Source/Editor/Windows/Assets/SkinnedModelWindow.cs @@ -511,9 +511,18 @@ namespace FlaxEditor.Windows.Assets ShadowsCastingMode[] shadowsModes = new ShadowsCastingMode[value.Length]; for (int i = 0; i < value.Length; i++) { - materials[i] = value[i].Material; - names[i] = value[i].Name; - shadowsModes[i] = value[i].ShadowsMode; + if (value[i] != null) + { + materials[i] = value[i].Material; + names[i] = value[i].Name; + shadowsModes[i] = value[i].ShadowsMode; + } + else + { + materials[i] = null; + names[i] = "Material " + i; + shadowsModes[i] = ShadowsCastingMode.All; + } } Asset.SetupMaterialSlots(value.Length); From e7edb9d38cc324436e028213e96af460b69d5d17 Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Mon, 5 Apr 2021 19:36:36 +0300 Subject: [PATCH 10/35] Add sweep and overlap physics queries for capsule shapes --- Source/Engine/Physics/Physics.Queries.cpp | 90 +++++++++++++++++++++++ Source/Engine/Physics/Physics.h | 79 ++++++++++++++++++++ 2 files changed, 169 insertions(+) diff --git a/Source/Engine/Physics/Physics.Queries.cpp b/Source/Engine/Physics/Physics.Queries.cpp index 15630e7ff..6cf3c786d 100644 --- a/Source/Engine/Physics/Physics.Queries.cpp +++ b/Source/Engine/Physics/Physics.Queries.cpp @@ -358,6 +358,51 @@ bool Physics::SphereCastAll(const Vector3& center, const float radius, const Vec return true; } +bool Physics::CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_SWEEP_1(); + const PxTransform pose(C2P(center), C2P(rotation)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform sweep test + return GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback()); +} + +bool Physics::CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_SWEEP_1(); + const PxTransform pose(C2P(center), C2P(rotation)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform sweep test + if (!GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback())) + return false; + + // Collect results + SCENE_QUERY_COLLECT_SINGLE(); + + return true; +} + +bool Physics::CapsuleCastAll(const Vector3& center, const float radius, const float height, const Vector3& direction, Array& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_SWEEP(); + const PxTransform pose(C2P(center), C2P(rotation)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform sweep test + if (!GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback())) + return false; + + // Collect results + SCENE_QUERY_COLLECT_ALL(); + + return true; +} + bool Physics::CheckBox(const Vector3& center, const Vector3& halfExtents, const Quaternion& rotation, uint32 layerMask, bool hitTriggers) { // Prepare data @@ -380,6 +425,17 @@ bool Physics::CheckSphere(const Vector3& center, const float radius, uint32 laye return GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback()); } +bool Physics::CheckCapsule(const Vector3& center, const float radius, const float height, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_OVERLAP_1(); + const PxTransform pose(C2P(center)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform overlap test + return GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback()); +} + bool Physics::OverlapBox(const Vector3& center, const Vector3& halfExtents, Array& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers) { // Prepare data @@ -414,6 +470,23 @@ bool Physics::OverlapSphere(const Vector3& center, const float radius, Array& results, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_OVERLAP(); + const PxTransform pose(C2P(center)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform overlap test + if (!GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback())) + return false; + + // Collect results + SCENE_QUERY_COLLECT_OVERLAP_COLLIDER(); + + return true; +} + bool Physics::OverlapBox(const Vector3& center, const Vector3& halfExtents, Array& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers) { // Prepare data @@ -447,3 +520,20 @@ bool Physics::OverlapSphere(const Vector3& center, const float radius, Array& results, uint32 layerMask, bool hitTriggers) +{ + // Prepare data + SCENE_QUERY_SETUP_OVERLAP(); + const PxTransform pose(C2P(center)); + const PxCapsuleGeometry geometry(radius, height * 0.5f); + + // Perform overlap test + if (!GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback())) + return false; + + // Collect results + SCENE_QUERY_COLLECT_OVERLAP(); + + return true; +} diff --git a/Source/Engine/Physics/Physics.h b/Source/Engine/Physics/Physics.h index 05b64cb0f..275ae9cb9 100644 --- a/Source/Engine/Physics/Physics.h +++ b/Source/Engine/Physics/Physics.h @@ -276,6 +276,50 @@ public: /// True if sphere hits an matching object, otherwise false. API_FUNCTION() static bool SphereCastAll(const Vector3& center, float radius, const Vector3& direction, API_PARAM(Out) Array& results, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// + /// Performs a sweep test against objects in the scene using a capsule geometry. + /// + /// The box center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The normalized direction in which cast a box. + /// The capsule rotation. + /// The maximum distance the ray should check for collisions. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule hits an matching object, otherwise false. + API_FUNCTION() static bool CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + + /// + /// Performs a sweep test against objects in the scene using a capsule geometry. + /// + /// The box center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The normalized direction in which cast a box. + /// The result hit information. Valid only when method returns true. + /// The capsule rotation. + /// The maximum distance the ray should check for collisions. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule hits an matching object, otherwise false. + API_FUNCTION() static bool CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + + /// + /// Performs a sweep test against objects in the scene using a capsule geometry. + /// + /// The box center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The normalized direction in which cast a box. + /// The result hits. Valid only when method returns true. + /// The capsule rotation. + /// The maximum distance the ray should check for collisions. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule hits an matching object, otherwise false. + API_FUNCTION() static bool CapsuleCastAll(const Vector3& center, const float radius, const float height, const Vector3& direction, API_PARAM(Out) Array& results, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Checks whether the given box overlaps with other colliders or not. /// @@ -297,6 +341,17 @@ public: /// True if sphere overlaps any matching object, otherwise false. API_FUNCTION() static bool CheckSphere(const Vector3& center, float radius, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// + /// Checks whether the given capsule overlaps with other colliders or not. + /// + /// The sphere center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule overlaps any matching object, otherwise false. + API_FUNCTION() static bool CheckCapsule(const Vector3& center, float radius, float height, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Finds all colliders touching or inside of the given box. /// @@ -320,6 +375,18 @@ public: /// True if sphere overlaps any matching object, otherwise false. API_FUNCTION() static bool OverlapSphere(const Vector3& center, float radius, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// + /// Finds all colliders touching or inside of the given sphere. + /// + /// The sphere center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The result colliders that overlap with the given sphere. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule overlaps any matching object, otherwise false. + API_FUNCTION() static bool OverlapCapsule(const Vector3& center, float radius, float height, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Finds all colliders touching or inside of the given box. /// @@ -343,6 +410,18 @@ public: /// True if sphere overlaps any matching object, otherwise false. API_FUNCTION() static bool OverlapSphere(const Vector3& center, float radius, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// + /// Finds all colliders touching or inside of the given sphere. + /// + /// The sphere center. + /// The radius of the capsule. + /// The height of the capsule, excluding the top and bottom spheres. + /// The result colliders that overlap with the given sphere. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if capsule overlaps any matching object, otherwise false. + API_FUNCTION() static bool OverlapCapsule(const Vector3& center, float radius, float height, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + public: /// From ca3d4a84adb7b81071fe9c71b1013a550e2631c5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 6 Apr 2021 11:46:23 +0200 Subject: [PATCH 11/35] Fix text wrapping when no scene is loaded --- Source/Editor/Windows/SceneTreeWindow.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 5f6ab1613..e33d658e6 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -209,9 +209,11 @@ namespace FlaxEditor.Windows public override void Draw() { var style = Style.Current; + // Draw overlay string overlayText = null; var state = Editor.StateMachine.CurrentState; + var textWrap = TextWrapping.NoWrap; if (state is LoadingState) { overlayText = "Loading..."; @@ -223,10 +225,11 @@ namespace FlaxEditor.Windows else if (((ContainerControl)_tree.GetChild(0)).ChildrenCount == 0) { overlayText = "No scene\nOpen one from the content window"; + textWrap = TextWrapping.WrapWords; } if (overlayText != null) { - Render2D.DrawText(Style.Current.FontLarge, overlayText, GetClientArea(), style.ForegroundDisabled, TextAlignment.Center, TextAlignment.Center); + Render2D.DrawText(style.FontLarge, overlayText, GetClientArea(), style.ForegroundDisabled, TextAlignment.Center, TextAlignment.Center, textWrap); } base.Draw(); From ca6a075d8c45b2ee30b962e359e340eab643a9c6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 6 Apr 2021 11:46:30 +0200 Subject: [PATCH 12/35] Fix typos and code style --- Source/Engine/Physics/Physics.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Physics/Physics.h b/Source/Engine/Physics/Physics.h index 275ae9cb9..71e172699 100644 --- a/Source/Engine/Physics/Physics.h +++ b/Source/Engine/Physics/Physics.h @@ -288,7 +288,7 @@ public: /// The layer mask used to filter the results. /// If set to true triggers will be hit, otherwise will skip them. /// True if capsule hits an matching object, otherwise false. - API_FUNCTION() static bool CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + API_FUNCTION() static bool CapsuleCast(const Vector3& center, float radius, float height, const Vector3& direction, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); /// /// Performs a sweep test against objects in the scene using a capsule geometry. @@ -303,7 +303,7 @@ public: /// The layer mask used to filter the results. /// If set to true triggers will be hit, otherwise will skip them. /// True if capsule hits an matching object, otherwise false. - API_FUNCTION() static bool CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + API_FUNCTION() static bool CapsuleCast(const Vector3& center, float radius, float height, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); /// /// Performs a sweep test against objects in the scene using a capsule geometry. @@ -318,8 +318,8 @@ public: /// The layer mask used to filter the results. /// If set to true triggers will be hit, otherwise will skip them. /// True if capsule hits an matching object, otherwise false. - API_FUNCTION() static bool CapsuleCastAll(const Vector3& center, const float radius, const float height, const Vector3& direction, API_PARAM(Out) Array& results, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); - + API_FUNCTION() static bool CapsuleCastAll(const Vector3& center, float radius, float height, const Vector3& direction, API_PARAM(Out) Array& results, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Checks whether the given box overlaps with other colliders or not. /// @@ -344,7 +344,7 @@ public: /// /// Checks whether the given capsule overlaps with other colliders or not. /// - /// The sphere center. + /// The capsule center. /// The radius of the capsule. /// The height of the capsule, excluding the top and bottom spheres. /// The layer mask used to filter the results. @@ -413,7 +413,7 @@ public: /// /// Finds all colliders touching or inside of the given sphere. /// - /// The sphere center. + /// The capsule center. /// The radius of the capsule. /// The height of the capsule, excluding the top and bottom spheres. /// The result colliders that overlap with the given sphere. Valid only when method returns true. From 2622482b12915b358bad2980240ca70a5158929b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 6 Apr 2021 12:17:32 +0200 Subject: [PATCH 13/35] Change libcurl dependency on Linux --- .github/workflows/build_linux.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 3238ce5c2..d00019e0a 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Install dependencies run: | - sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev build-essential gettext curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4-gnutls-dev + sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev build-essential gettext curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4 - name: Checkout repo uses: actions/checkout@v2 - name: Checkout LFS diff --git a/README.md b/README.md index 7d836ed55..4fddf1adc 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Flax Visual Studio extension provides better programming workflow, C# scripts de * Install Visual Studio Code * Install Mono ([https://www.mono-project.com/download/stable](https://www.mono-project.com/download/stable)) * Install Git with LFS -* Install requried packages: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev nuget autoconf libogg-dev automake build-essential gettext cmake python curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4-gnutls-dev` +* Install requried packages: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev nuget autoconf libogg-dev automake build-essential gettext cmake python curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4` * Install compiler `sudo apt-get install clang lldb lld` (Clang 6 or newer) * Clone repo (with LFS) * Run `./GenerateProjectFiles.sh` From ecc055d8b887f9958a31be264a22536f62e4a845 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 6 Apr 2021 12:40:24 +0200 Subject: [PATCH 14/35] Fix compilation warnings --- Source/ThirdParty/OpenFBX/ofbx.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/ThirdParty/OpenFBX/ofbx.cpp b/Source/ThirdParty/OpenFBX/ofbx.cpp index 36f942cf8..94fc6684b 100644 --- a/Source/ThirdParty/OpenFBX/ofbx.cpp +++ b/Source/ThirdParty/OpenFBX/ofbx.cpp @@ -3172,6 +3172,8 @@ static bool parseObjects(const Element& root, Scene* scene, u64 flags, Allocator node->bone_link_property = con.property; } break; + default: + break; } switch (parent->getType()) @@ -3190,6 +3192,8 @@ static bool parseObjects(const Element& root, Scene* scene, u64 flags, Allocator mesh->geometry = (Geometry*)child; break; case Object::Type::MATERIAL: mesh->materials.push_back((Material*)child); break; + default: + break; } break; } @@ -3323,6 +3327,8 @@ static bool parseObjects(const Element& root, Scene* scene, u64 flags, Allocator } break; } + default: + break; } } @@ -3350,6 +3356,8 @@ static bool parseObjects(const Element& root, Scene* scene, u64 flags, Allocator return false; } break; + default: + break; } } } From 60e926a62f893b08990195e385134c91abf0b9b9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Wed, 7 Apr 2021 17:01:37 +0200 Subject: [PATCH 15/35] Serialize UpDirection. --- Source/Engine/Physics/Colliders/CharacterController.cpp | 5 +++++ Source/Engine/Physics/Colliders/CharacterController.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Source/Engine/Physics/Colliders/CharacterController.cpp b/Source/Engine/Physics/Colliders/CharacterController.cpp index d13aca3b7..951f79d37 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.cpp +++ b/Source/Engine/Physics/Colliders/CharacterController.cpp @@ -22,6 +22,7 @@ CharacterController::CharacterController(const SpawnParams& params) , _radius(50.0f) , _height(150.0f) , _minMoveDistance(0.0f) + , _upDirection(Vector3::Up) , _isUpdatingTransform(false) , _nonWalkableMode(CharacterController::NonWalkableModes::PreventClimbing) , _lastFlags(CollisionFlags::None) @@ -86,6 +87,7 @@ void CharacterController::SetUpDirection(const Vector3& up) { if (_controller) _controller->setUpDirection(C2P(up)); + _upDirection = up; } Vector3 CharacterController::GetUpDirection() const @@ -191,6 +193,7 @@ void CharacterController::CreateActor() // Create controller _controller = (PxCapsuleController*)Physics::GetControllerManager()->createController(desc); ASSERT(_controller); + _controller->setUpDirection(C2P(_upDirection)); const auto actor = _controller->getActor(); ASSERT(actor && actor->getNbShapes() == 1); actor->getShapes(&_shape, 1); @@ -374,6 +377,7 @@ void CharacterController::Serialize(SerializeStream& stream, const void* otherOb SERIALIZE_MEMBER(Radius, _radius); SERIALIZE_MEMBER(Height, _height); SERIALIZE_MEMBER(MinMoveDistance, _minMoveDistance); + SERIALIZE_MEMBER(UpDirection, _upDirection); } void CharacterController::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) @@ -387,4 +391,5 @@ void CharacterController::Deserialize(DeserializeStream& stream, ISerializeModif DESERIALIZE_MEMBER(Radius, _radius); DESERIALIZE_MEMBER(Height, _height); DESERIALIZE_MEMBER(MinMoveDistance, _minMoveDistance); + DESERIALIZE_MEMBER(UpDirection, _upDirection); } diff --git a/Source/Engine/Physics/Colliders/CharacterController.h b/Source/Engine/Physics/Colliders/CharacterController.h index 5f0faa793..712ab6296 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.h +++ b/Source/Engine/Physics/Colliders/CharacterController.h @@ -65,6 +65,7 @@ private: float _height; float _minMoveDistance; bool _isUpdatingTransform; + Vector3 _upDirection; NonWalkableModes _nonWalkableMode; CollisionFlags _lastFlags; uint32 _filterData[4]; From 6001eb88fa47deac9ed1cb447122d79b6f5df1e2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 20:52:22 +0200 Subject: [PATCH 16/35] Fix Dropdown control #334 --- Source/Engine/UI/GUI/Common/Dropdown.cs | 192 ++++++++++++++++-------- 1 file changed, 128 insertions(+), 64 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Dropdown.cs b/Source/Engine/UI/GUI/Common/Dropdown.cs index 917e51f6e..3bb00990f 100644 --- a/Source/Engine/UI/GUI/Common/Dropdown.cs +++ b/Source/Engine/UI/GUI/Common/Dropdown.cs @@ -8,8 +8,8 @@ namespace FlaxEngine.GUI /// /// Dropdown menu control allows to choose one item from the provided collection of options. /// - /// - public class Dropdown : Control + /// + public class Dropdown : ContainerControl { /// /// The root control used by the to show the items collections and track item selecting event. @@ -18,7 +18,7 @@ namespace FlaxEngine.GUI [HideInEditor] protected class DropdownRoot : Panel { - private bool isMouseDown; + private bool _isMouseDown; /// /// Occurs when item gets clicked. Argument is item index. @@ -38,9 +38,9 @@ namespace FlaxEngine.GUI /// public override bool OnMouseDown(Vector2 location, MouseButton button) { - isMouseDown = true; + _isMouseDown = true; var result = base.OnMouseDown(location, button); - isMouseDown = false; + _isMouseDown = false; if (!result) return false; @@ -57,8 +57,10 @@ namespace FlaxEngine.GUI { base.OnLostFocus(); - if (!isMouseDown) - LostFocus(); + if (!_isMouseDown) + { + LostFocus?.Invoke(); + } } /// @@ -82,7 +84,7 @@ namespace FlaxEngine.GUI /// protected DropdownRoot _popup; - private bool _mouseDown; + private bool _touchDown; /// /// The selected index of the item (-1 for no selection). @@ -118,13 +120,9 @@ namespace FlaxEngine.GUI get => _selectedIndex; set { - // Clamp index value = Mathf.Min(value, _items.Count - 1); - - // Check if index will change if (value != _selectedIndex) { - // Select _selectedIndex = value; OnSelectedIndexChanged(); } @@ -225,6 +223,8 @@ namespace FlaxEngine.GUI public Dropdown() : base(0, 0, 120, 18.0f) { + AutoFocus = false; + var style = Style.Current; Font = new FontReference(style.FontMedium); TextColor = style.Foreground; @@ -334,6 +334,7 @@ namespace FlaxEngine.GUI } */ var itemsWidth = Width; + var height = container.Margin.Height; for (int i = 0; i < _items.Count; i++) { @@ -347,35 +348,51 @@ namespace FlaxEngine.GUI var label = new Label { X = itemsMargin, - Width = itemsWidth - itemsMargin, + Size = new Vector2(itemsWidth - itemsMargin, itemsHeight), Font = Font, TextColor = Color.White * 0.9f, TextColorHighlighted = Color.White, HorizontalAlignment = TextAlignment.Near, - AnchorPreset = AnchorPresets.VerticalStretchRight, Text = _items[i], Parent = item, }; + height += itemsHeight; + if (i != 0) + height += container.Spacing; if (_selectedIndex == i) { var icon = new Image { Brush = CheckedImage, - Width = itemsMargin, + Size = new Vector2(itemsMargin, itemsHeight), Margin = new Margin(4.0f, 6.0f, 4.0f, 4.0f), - AnchorPreset = AnchorPresets.VerticalStretchLeft, + //AnchorPreset = AnchorPresets.VerticalStretchLeft, Parent = item, }; } } - popup.Size = new Vector2(itemsWidth, (itemsHeight + container.Spacing) * _items.Count + container.Margin.Height); + popup.Size = new Vector2(itemsWidth, height); popup.ItemsContainer = container; return popup; } + /// + /// Called when popup menu gets shown. + /// + protected virtual void OnPopupShow() + { + } + + /// + /// Called when popup menu gets hidden. + /// + protected virtual void OnPopupHide() + { + } + /// /// Destroys the popup. /// @@ -383,11 +400,59 @@ namespace FlaxEngine.GUI { if (_popup != null) { + OnPopupHide(); _popup.Dispose(); _popup = null; } } + /// + /// Shows the popup. + /// + public void ShowPopup() + { + var root = Root; + if (_items.Count == 0 || root == null) + return; + + // Setup popup + DestroyPopup(); + _popup = CreatePopup(); + + // Update layout + _popup.UnlockChildrenRecursive(); + _popup.PerformLayout(); + + // Bind events + _popup.ItemClicked += index => + { + OnItemClicked(index); + DestroyPopup(); + }; + _popup.LostFocus += DestroyPopup; + + // Show dropdown popup + Vector2 locationRootSpace = Location + new Vector2(0, Height); + var parent = Parent; + while (parent != null && parent != Root) + { + locationRootSpace = parent.PointToParent(ref locationRootSpace); + parent = parent.Parent; + } + _popup.Location = locationRootSpace; + _popup.Parent = root; + _popup.Focus(); + OnPopupShow(); + } + + /// + /// Hides the popup. + /// + public void HidePopup() + { + DestroyPopup(); + } + /// public override void OnDestroy() { @@ -397,7 +462,7 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { // Cache data var clientRect = new Rectangle(Vector2.Zero, Size); @@ -413,7 +478,7 @@ namespace FlaxEngine.GUI backgroundColor *= 0.5f; arrowColor *= 0.7f; } - else if (isOpened || _mouseDown) + else if (isOpened || _touchDown) { backgroundColor = BackgroundColorSelected; borderColor = BorderColorSelected; @@ -448,17 +513,15 @@ namespace FlaxEngine.GUI /// public override void OnLostFocus() { - base.OnLostFocus(); + _touchDown = false; - // Clear flags - _mouseDown = false; + base.OnLostFocus(); } /// public override void OnMouseLeave() { - // Clear flags - _mouseDown = false; + _touchDown = false; base.OnMouseLeave(); } @@ -466,59 +529,60 @@ namespace FlaxEngine.GUI /// public override bool OnMouseDown(Vector2 location, MouseButton button) { - // Check mouse buttons + if (base.OnMouseDown(location, button)) + return true; + if (button == MouseButton.Left) { - // Set flag - _mouseDown = true; + _touchDown = true; + return true; } - return base.OnMouseDown(location, button); + return false; } /// public override bool OnMouseUp(Vector2 location, MouseButton button) { - // Check flags - if (_mouseDown) + if (_touchDown && button == MouseButton.Left) { - // Clear flag - _mouseDown = false; - - var root = Root; - if (_items.Count > 0 && root != null) - { - // Setup popup - DestroyPopup(); - _popup = CreatePopup(); - - // Update layout - _popup.UnlockChildrenRecursive(); - _popup.PerformLayout(); - - // Bind events - _popup.ItemClicked += (index) => - { - OnItemClicked(index); - DestroyPopup(); - }; - _popup.LostFocus += DestroyPopup; - - // Show dropdown popup - Vector2 locationRootSpace = Location + new Vector2(0, Height); - var parent = Parent; - while (parent != null && parent != Root) - { - locationRootSpace = parent.PointToParent(ref location); - parent = parent.Parent; - } - _popup.Location = locationRootSpace; - _popup.Parent = root; - _popup.Focus(); - } + _touchDown = false; + ShowPopup(); + return true; } + return base.OnMouseUp(location, button); + } + + /// + public override bool OnTouchDown(Vector2 location, int pointerId) + { + if (base.OnTouchDown(location, pointerId)) + return true; + + _touchDown = true; return true; } + + /// + public override bool OnTouchUp(Vector2 location, int pointerId) + { + if (base.OnTouchUp(location, pointerId)) + return true; + + if (_touchDown) + { + ShowPopup(); + } + return true; + } + + /// + public override void OnTouchLeave(int pointerId) + { + _touchDown = false; + + base.OnTouchLeave(pointerId); + } } } From 7e622a69a691b59e63cbd5ce1fb533fc4e15d2e5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 20:53:18 +0200 Subject: [PATCH 17/35] Fix `AutoFocus` saved in data for controls --- Source/Engine/UI/GUI/Control.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index 1b6779ff8..afdd86bcb 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -456,9 +456,9 @@ namespace FlaxEngine.GUI #region Focus /// - /// Gets a value indicating whether the control can receive automatic focus on user events (eg. mouse down. + /// Gets a value indicating whether the control can receive automatic focus on user events (eg. mouse down). /// - [HideInEditor] + [HideInEditor, NoSerialize] public bool AutoFocus { get => _autoFocus; From d073a13f57e037922f3694efa84571d166fb5529 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 21:10:09 +0200 Subject: [PATCH 18/35] Fix removing Gameplay Globals #427 --- Source/Engine/Engine/GameplayGlobals.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Engine/GameplayGlobals.cpp b/Source/Engine/Engine/GameplayGlobals.cpp index 944253b4a..e8e08444f 100644 --- a/Source/Engine/Engine/GameplayGlobals.cpp +++ b/Source/Engine/Engine/GameplayGlobals.cpp @@ -67,7 +67,7 @@ Dictionary GameplayGlobals::GetValues() const void GameplayGlobals::SetValues(const Dictionary& values) { - for (auto& e : values) + for (auto& e : Variables) { bool hasKey = false; for (auto& q : values) @@ -105,7 +105,7 @@ Dictionary GameplayGlobals::GetDefaultValues() const void GameplayGlobals::SetDefaultValues(const Dictionary& values) { - for (auto& e : values) + for (auto& e : Variables) { bool hasKey = false; for (auto& q : values) From 9a17f2141ba461d05fb3eb541dc924cd0c04442c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 22:21:37 +0200 Subject: [PATCH 19/35] Add lock for Gameplay Globals access --- Source/Engine/Engine/GameplayGlobals.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Engine/GameplayGlobals.cpp b/Source/Engine/Engine/GameplayGlobals.cpp index e8e08444f..f945832cc 100644 --- a/Source/Engine/Engine/GameplayGlobals.cpp +++ b/Source/Engine/Engine/GameplayGlobals.cpp @@ -59,6 +59,7 @@ GameplayGlobals::GameplayGlobals(const SpawnParams& params, const AssetInfo* inf Dictionary GameplayGlobals::GetValues() const { + ScopeLock lock(Locker); Dictionary result; for (auto& e : Variables) result.Add(e.Key, e.Value.Value); @@ -67,7 +68,8 @@ Dictionary GameplayGlobals::GetValues() const void GameplayGlobals::SetValues(const Dictionary& values) { - for (auto& e : Variables) + ScopeLock lock(Locker); + for (auto& e : values) { bool hasKey = false; for (auto& q : values) @@ -97,6 +99,7 @@ void GameplayGlobals::SetValues(const Dictionary& values) Dictionary GameplayGlobals::GetDefaultValues() const { + ScopeLock lock(Locker); Dictionary result; for (auto& e : Variables) result.Add(e.Key, e.Value.DefaultValue); @@ -105,7 +108,8 @@ Dictionary GameplayGlobals::GetDefaultValues() const void GameplayGlobals::SetDefaultValues(const Dictionary& values) { - for (auto& e : Variables) + ScopeLock lock(Locker); + for (auto& e : values) { bool hasKey = false; for (auto& q : values) @@ -135,12 +139,14 @@ void GameplayGlobals::SetDefaultValues(const Dictionary& values Variant GameplayGlobals::GetValue(const StringView& name) const { + ScopeLock lock(Locker); auto e = Variables.TryGet(name); return e ? e->Value : Variant::Zero; } void GameplayGlobals::SetValue(const StringView& name, const Variant& value) { + ScopeLock lock(Locker); auto e = Variables.TryGet(name); if (e) { @@ -150,6 +156,7 @@ void GameplayGlobals::SetValue(const StringView& name, const Variant& value) void GameplayGlobals::ResetValues() { + ScopeLock lock(Locker); for (auto& e : Variables) { e.Value.Value = e.Value.DefaultValue; From eff5d0899d5eab96712650b922a80485d89c54ac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 20:35:01 +0200 Subject: [PATCH 20/35] Order + Attributes + Return _up. --- .../Engine/Physics/Colliders/CharacterController.cpp | 2 +- Source/Engine/Physics/Colliders/CharacterController.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Physics/Colliders/CharacterController.cpp b/Source/Engine/Physics/Colliders/CharacterController.cpp index 951f79d37..419b6b052 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.cpp +++ b/Source/Engine/Physics/Colliders/CharacterController.cpp @@ -92,7 +92,7 @@ void CharacterController::SetUpDirection(const Vector3& up) Vector3 CharacterController::GetUpDirection() const { - return _controller ? P2C(_controller->getUpDirection()) : Vector3::Up; + return _controller ? P2C(_controller->getUpDirection()) : _upDirection; } void CharacterController::SetMinMoveDistance(float value) diff --git a/Source/Engine/Physics/Colliders/CharacterController.h b/Source/Engine/Physics/Colliders/CharacterController.h index 712ab6296..8ae992c59 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.h +++ b/Source/Engine/Physics/Colliders/CharacterController.h @@ -142,15 +142,16 @@ public: /// API_PROPERTY() void SetStepOffset(float value); + /// + /// Gets the character up vector. + /// + API_PROPERTY(Attributes="EditorOrder(240), DefaultValue(true), EditorDisplay(\"Character Controller\")") + Vector3 GetUpDirection() const; + /// /// Sets the character up vector. /// API_PROPERTY() void SetUpDirection(const Vector3& up); - - /// - /// Gets the character up vector. - /// - API_PROPERTY() Vector3 GetUpDirection() const; /// /// Gets the minimum move distance of the character controller. The minimum traveled distance to consider. If traveled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small. From 3e080c44c67b2e2b8af69ef546a76a8097e29aee Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 8 Apr 2021 22:12:55 +0200 Subject: [PATCH 21/35] Fix using curl lib on Linux (use self compiled static lib) --- .github/workflows/build_linux.yml | 2 +- README.md | 2 +- .../Linux/Binaries/ThirdParty/x64/libcurl.a | 3 ++ Source/ThirdParty/curl/curl.Build.cs | 2 +- .../Flax.Build/Deps/Dependencies/curl.cs | 38 ++++++++++++++++++- 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 Source/Platforms/Linux/Binaries/ThirdParty/x64/libcurl.a diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index d00019e0a..3d99537ba 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Install dependencies run: | - sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev build-essential gettext curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4 + sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev build-essential gettext libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev - name: Checkout repo uses: actions/checkout@v2 - name: Checkout LFS diff --git a/README.md b/README.md index 4fddf1adc..be785107d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Flax Visual Studio extension provides better programming workflow, C# scripts de * Install Visual Studio Code * Install Mono ([https://www.mono-project.com/download/stable](https://www.mono-project.com/download/stable)) * Install Git with LFS -* Install requried packages: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev nuget autoconf libogg-dev automake build-essential gettext cmake python curl libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev libcurl4` +* Install requried packages: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev nuget autoconf libogg-dev automake build-essential gettext cmake python libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev` * Install compiler `sudo apt-get install clang lldb lld` (Clang 6 or newer) * Clone repo (with LFS) * Run `./GenerateProjectFiles.sh` diff --git a/Source/Platforms/Linux/Binaries/ThirdParty/x64/libcurl.a b/Source/Platforms/Linux/Binaries/ThirdParty/x64/libcurl.a new file mode 100644 index 000000000..f722e3a16 --- /dev/null +++ b/Source/Platforms/Linux/Binaries/ThirdParty/x64/libcurl.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b7f66f58d5e7dabe0a0ec7e01ae5dd3683c2ae474ac6dbc133393b2be715bbf +size 574086 diff --git a/Source/ThirdParty/curl/curl.Build.cs b/Source/ThirdParty/curl/curl.Build.cs index 35943d9f1..ac77162a1 100644 --- a/Source/ThirdParty/curl/curl.Build.cs +++ b/Source/ThirdParty/curl/curl.Build.cs @@ -38,7 +38,7 @@ public class curl : DepsModule options.OutputFiles.Add("crypt32.lib"); break; case TargetPlatform.Linux: - options.Libraries.Add("curl"); + options.OutputFiles.Add(Path.Combine(depsRoot, "libcurl.a")); break; default: throw new InvalidPlatformException(options.Platform.Target); } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs b/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs index 4fdc68067..6461706df 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. +using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; @@ -25,6 +26,11 @@ namespace Flax.Deps.Dependencies { TargetPlatform.Windows, }; + case TargetPlatform.Linux: + return new[] + { + TargetPlatform.Linux, + }; default: return new TargetPlatform[0]; } } @@ -76,7 +82,37 @@ namespace Flax.Deps.Dependencies foreach (var filename in binariesToCopyWin) Utilities.FileCopy(Path.Combine(root, "build", "Win64", vcVersion, configuration, filename), Path.Combine(depsFolder, Path.GetFileName(filename))); } - + break; + } + case TargetPlatform.Linux: + { + // Build for Linux + var settings = new [] + { + "-without-librtmp", + "--without-ssl", + "--with-gnutls", + "--disable-ipv6", + "--disable-manual", + "--disable-verbose", + "--disable-shared", + "--enable-static", + "-disable-ldap --disable-sspi --disable-ftp --disable-file --disable-dict --disable-telnet --disable-tftp --disable-rtsp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-smb", + }; + var envVars = new Dictionary + { + { "CC", "clang-7" }, + { "CC_FOR_BUILD", "clang-7" } + }; + var buildDir = Path.Combine(root, "build"); + SetupDirectory(buildDir, true); + Utilities.Run("chmod", "+x configure", null, root, Utilities.RunOptions.None); + Utilities.Run(Path.Combine(root, "configure"), string.Join(" ", settings) + " --prefix=\"" + buildDir + "\"", null, root, Utilities.RunOptions.None, envVars); + Utilities.Run("make", null, null, root, Utilities.RunOptions.None); + Utilities.Run("make", "install", null, root, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Linux, TargetArchitecture.x64); + var filename = "libcurl.a"; + Utilities.FileCopy(Path.Combine(buildDir, "lib", filename), Path.Combine(depsFolder, filename)); break; } } From 5b1c5824c8323182a5c4c1bfba4f12e3c0c307cf Mon Sep 17 00:00:00 2001 From: stefnotch Date: Sat, 10 Apr 2021 09:13:19 +0200 Subject: [PATCH 22/35] Fix #408 by being more precise in some places IEEE floating point numbers are fun :tm: --- Source/Engine/Level/Actors/SplineModel.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Level/Actors/SplineModel.cpp b/Source/Engine/Level/Actors/SplineModel.cpp index 794658afb..ffa995f58 100644 --- a/Source/Engine/Level/Actors/SplineModel.cpp +++ b/Source/Engine/Level/Actors/SplineModel.cpp @@ -138,11 +138,10 @@ void SplineModel::OnSplineUpdated() Vector3 tmp = corners[i] * _preTransform.Scale; double rotation[4] = { (double)_preTransform.Orientation.X, (double)_preTransform.Orientation.Y, (double)_preTransform.Orientation.Z, (double)_preTransform.Orientation.W }; const double length = sqrt(rotation[0] * rotation[0] + rotation[1] * rotation[1] + rotation[2] * rotation[2] + rotation[3] * rotation[3]); - const double inv = 1.0 / length; - rotation[0] *= inv; - rotation[1] *= inv; - rotation[2] *= inv; - rotation[3] *= inv; + rotation[0] /= length; + rotation[1] /= length; + rotation[2] /= length; + rotation[3] /= length; double pos[3] = { (double)tmp.X, (double)tmp.Y, (double)tmp.Z }; const double x = rotation[0] + rotation[0]; const double y = rotation[1] + rotation[1]; @@ -251,7 +250,7 @@ void SplineModel::UpdateDeformationBuffer() AnimationUtils::GetTangent(end.Value, end.TangentIn, length, rightTangent); for (int32 chunk = 0; chunk < chunksPerSegment; chunk++) { - const float alpha = (float)chunk * chunksPerSegmentInv; + const float alpha = (chunk == chunksPerSegment - 1)? 1.0f : ((float)chunk * chunksPerSegmentInv); // Evaluate transformation at the curve AnimationUtils::Bezier(start.Value, leftTangent, rightTangent, end.Value, alpha, transform); From a58645da0f57d2b9f4e2afcde0ba68096dbc3f3b Mon Sep 17 00:00:00 2001 From: stefnotch Date: Mon, 12 Apr 2021 10:46:00 +0200 Subject: [PATCH 23/35] Slightly improve the random byte generation code --- Source/Engine/Utilities/Extensions.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs index b3f6d2053..3eb31e1d2 100644 --- a/Source/Engine/Utilities/Extensions.cs +++ b/Source/Engine/Utilities/Extensions.cs @@ -211,6 +211,17 @@ namespace FlaxEngine.Utilities /// A thats either true or false. public static bool NextBool(this Random random, float weight = 0.5f) => random.NextDouble() < weight; + /// + /// Generates a random value up until an exclusive maximum. + /// + /// An instance of . + /// The maximum value. If it's zero, a maximum of 256 is used + /// A random between min and max. + public static byte NextByte(this Random random, byte max = 0) + { + return max == 0 ? (byte)(random.Next() % 256) : (byte)random.Next(max); + } + /// /// Generates a random value between min and max. /// @@ -218,9 +229,9 @@ namespace FlaxEngine.Utilities /// The minimum value. /// The maximum value. /// A random between min and max. - public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue) + public static byte NextByte(this Random random, byte min, byte max) { - return (byte)random.Next(min, max == byte.MaxValue ? byte.MaxValue + 1 : max); + return (byte)random.Next(min, max); } /// From 81305a10cfc2241e3c0c1a2b08505557cbc89dc3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 12:50:46 +0200 Subject: [PATCH 24/35] Fix crash on relocation in BitArray --- Source/Engine/Core/Collections/BitArray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Core/Collections/BitArray.h b/Source/Engine/Core/Collections/BitArray.h index c3051c678..dc20d1cd7 100644 --- a/Source/Engine/Core/Collections/BitArray.h +++ b/Source/Engine/Core/Collections/BitArray.h @@ -236,7 +236,7 @@ public: return; ASSERT(capacity >= 0); const int32 count = preserveContents ? (_count < capacity ? _count : capacity) : 0; - _allocation.Relocate(Math::Max(capacity / sizeof(ItemType), 1), _count, count); + _allocation.Relocate(Math::Max(capacity / sizeof(ItemType), 1), _count / sizeof(ItemType), count / sizeof(ItemType)); _capacity = capacity; _count = count; } From c47db14c83c359c7297ba9ce1a4e4dd1e4df248b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 12:50:59 +0200 Subject: [PATCH 25/35] Fix using Sorting in C++ game code --- Source/Engine/Core/Collections/Sorting.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Core/Collections/Sorting.h b/Source/Engine/Core/Collections/Sorting.h index 4fd26f794..6aa584ace 100644 --- a/Source/Engine/Core/Collections/Sorting.h +++ b/Source/Engine/Core/Collections/Sorting.h @@ -17,7 +17,7 @@ public: /// /// Helper collection used by the sorting algorithms. Implements stack using single linear allocation with variable capacity. /// - class SortingStack + class FLAXENGINE_API SortingStack { public: From cd1f57b634434198f2493e2aacc9f03867c38a2f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 12:51:10 +0200 Subject: [PATCH 26/35] Fix doc comments --- Source/Engine/Core/ISerializable.h | 6 +++--- Source/Engine/Core/Types/Version.h | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Core/ISerializable.h b/Source/Engine/Core/ISerializable.h index cfc5e1976..aaa2c241b 100644 --- a/Source/Engine/Core/ISerializable.h +++ b/Source/Engine/Core/ISerializable.h @@ -37,21 +37,21 @@ public: virtual ~ISerializable() = default; /// - /// Serialize object to the output stream compared to the values of the other object instance (eg. default class object). If other object is null then serialize all properties. + /// Serializes object to the output stream compared to the values of the other object instance (eg. default class object). If other object is null then serialize all properties. /// /// The output stream. /// The instance of the object to compare with and serialize only the modified properties. If null, then serialize all properties. virtual void Serialize(SerializeStream& stream, const void* otherObj) = 0; /// - /// Deserialize object from the input stream + /// Deserializes object from the input stream. /// /// The input stream. /// The deserialization modifier object. Always valid. virtual void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) = 0; /// - /// Deserialize object from the input stream child member. Won't deserialize it if member is missing. + /// Deserializes object from the input stream child member. Won't deserialize it if member is missing. /// /// The input stream. /// The input stream member to lookup. diff --git a/Source/Engine/Core/Types/Version.h b/Source/Engine/Core/Types/Version.h index 6d0bac6b1..323c894a5 100644 --- a/Source/Engine/Core/Types/Version.h +++ b/Source/Engine/Core/Types/Version.h @@ -4,11 +4,10 @@ #include "BaseTypes.h" #include "Engine/Core/Math/Math.h" -#include "Engine/Core/Formatting.h" #include "Engine/Core/Templates.h" /// -/// Represents the version number made of major, minor, patch and build numbers. +/// Represents the version number made of major, minor, build and revision numbers. /// struct FLAXENGINE_API Version { From 8a725ec243c7b6300ebcdaf5f88e0302006a2da1 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 12:51:26 +0200 Subject: [PATCH 27/35] Fix natvis for StringBuilder --- Source/flax.natvis | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/flax.natvis b/Source/flax.natvis index 550d8a4d4..774badad3 100644 --- a/Source/flax.natvis +++ b/Source/flax.natvis @@ -143,9 +143,9 @@ - {_data_allocation.._data,su} + {_data._allocation._data,su} - _data._data + _data._allocation._data _data._count _data._count From 5ab554f61cc378ce0e917eb4b8f9b7ed1da77385 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 12:57:15 +0200 Subject: [PATCH 28/35] Fix using Camera refs --- Source/Engine/Graphics/RenderTask.h | 2 +- Source/Engine/Level/Actors/Camera.cpp | 7 ++++--- Source/Engine/Level/Actors/Camera.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h index 5d6a47861..96048bcc2 100644 --- a/Source/Engine/Graphics/RenderTask.h +++ b/Source/Engine/Graphics/RenderTask.h @@ -251,7 +251,7 @@ public: /// /// The scene rendering camera. Can be used to override the rendering view properties based on the current camera setup. /// - API_FIELD() Camera* Camera = nullptr; + API_FIELD() ScriptingObjectReference Camera; /// /// The render view description. diff --git a/Source/Engine/Level/Actors/Camera.cpp b/Source/Engine/Level/Actors/Camera.cpp index 1f9de6d41..c37e30607 100644 --- a/Source/Engine/Level/Actors/Camera.cpp +++ b/Source/Engine/Level/Actors/Camera.cpp @@ -17,12 +17,13 @@ Array Camera::Cameras; Camera* Camera::CutSceneCamera = nullptr; -Camera* Camera::OverrideMainCamera = nullptr; +ScriptingObjectReference Camera::OverrideMainCamera; Camera* Camera::GetMainCamera() { - if (OverrideMainCamera) - return OverrideMainCamera; + Camera* overrideMainCamera = OverrideMainCamera.Get(); + if (overrideMainCamera) + return overrideMainCamera; if (CutSceneCamera) return CutSceneCamera; return Cameras.HasItems() ? Cameras.First() : nullptr; diff --git a/Source/Engine/Level/Actors/Camera.h b/Source/Engine/Level/Actors/Camera.h index 4bf277279..ecd93cef0 100644 --- a/Source/Engine/Level/Actors/Camera.h +++ b/Source/Engine/Level/Actors/Camera.h @@ -28,7 +28,7 @@ DECLARE_SCENE_OBJECT(Camera); static Camera* CutSceneCamera; // The overriden main camera. - API_FIELD() static Camera* OverrideMainCamera; + API_FIELD() static ScriptingObjectReference OverrideMainCamera; // Gets the main camera. API_PROPERTY() static Camera* GetMainCamera(); From 0dafa2f5624f699f23b9bfbac52eb49874108fbd Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 13:24:59 +0200 Subject: [PATCH 29/35] Expose TickData to scripting API --- Source/Engine/Engine/Time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Engine/Time.h b/Source/Engine/Engine/Time.h index eb176ae7c..af0545184 100644 --- a/Source/Engine/Engine/Time.h +++ b/Source/Engine/Engine/Time.h @@ -22,7 +22,7 @@ public: /// Engine subsystem updating data. /// Used to invoke game logic updates, physics updates and rendering with possibly different frequencies. /// - class TickData + class FLAXENGINE_API TickData { public: From 3bfeb1db763d6491c434b72209627cb6ff5998e2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 19:07:18 +0200 Subject: [PATCH 30/35] Add `BoxBrush::SetMaterial` --- Source/Engine/Level/Actors/BoxBrush.cpp | 34 +++++++++++++++++++- Source/Engine/Level/Actors/BoxBrush.h | 41 +++++++++---------------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Source/Engine/Level/Actors/BoxBrush.cpp b/Source/Engine/Level/Actors/BoxBrush.cpp index f02dd5bd3..4330424c7 100644 --- a/Source/Engine/Level/Actors/BoxBrush.cpp +++ b/Source/Engine/Level/Actors/BoxBrush.cpp @@ -128,6 +128,13 @@ void BoxBrush::GetSurfaces(CSG::Surface surfaces[6]) } } +void BoxBrush::SetMaterial(int32 surfaceIndex, MaterialBase* material) +{ + CHECK(Math::IsInRange(surfaceIndex, 0, 5)); + Surfaces[surfaceIndex].Material = material; + OnBrushModified(); +} + bool BoxBrush::Intersects(int32 surfaceIndex, const Ray& ray, float& distance, Vector3& normal) const { distance = MAX_float; @@ -232,6 +239,26 @@ void BoxBrush::OnDebugDrawSelected() #endif +Scene* BoxBrush::GetBrushScene() const +{ + return GetScene(); +} + +Guid BoxBrush::GetBrushID() const +{ + return GetID(); +} + +bool BoxBrush::CanUseCSG() const +{ + return IsActiveInHierarchy(); +} + +CSG::Mode BoxBrush::GetBrushMode() const +{ + return _mode; +} + void BoxBrush::GetSurfaces(Array& surfaces) { surfaces.Clear(); @@ -240,6 +267,11 @@ void BoxBrush::GetSurfaces(Array& surfaces) GetSurfaces(surfaces.Get()); } +int32 BoxBrush::GetSurfacesCount() +{ + return 6; +} + void BoxBrush::OnTransformChanged() { // Base @@ -272,7 +304,7 @@ void BoxBrush::OnParentChanged() { // Base Actor::OnParentChanged(); - + if (!IsDuringPlay()) return; diff --git a/Source/Engine/Level/Actors/BoxBrush.h b/Source/Engine/Level/Actors/BoxBrush.h index e8fc63e3f..ae9be5b83 100644 --- a/Source/Engine/Level/Actors/BoxBrush.h +++ b/Source/Engine/Level/Actors/BoxBrush.h @@ -153,6 +153,13 @@ public: /// Surfaces void GetSurfaces(CSG::Surface surfaces[6]); + /// + /// Sets the brush surface material. + /// + /// The brush surface index. + /// The material. + API_FUNCTION() void SetMaterial(int32 surfaceIndex, MaterialBase* material); + public: /// @@ -169,7 +176,7 @@ public: /// Otherwise performs simple vs test. /// For more efficient collisions detection and ray casting use physics. /// - /// The brush surface index.. + /// The brush surface index. /// The ray to test. /// When the method completes and returns true, contains the distance of the intersection (if any valid). /// When the method completes, contains the intersection surface normal vector (if any valid). @@ -179,7 +186,7 @@ public: /// /// Gets the brush surface triangles array (group by 3 vertices). /// - /// The brush surface index.. + /// The brush surface index. /// The output vertices buffer with triangles or empty if no data loaded. API_FUNCTION() void GetVertices(int32 surfaceIndex, API_PARAM(Out) Array& outputData) const; @@ -204,32 +211,12 @@ public: #endif // [CSG::Brush] - Scene* GetBrushScene() const override - { - return GetScene(); - } - - Guid GetBrushID() const override - { - return GetID(); - } - - bool CanUseCSG() const override - { - return IsActiveInHierarchy(); - } - - CSG::Mode GetBrushMode() const override - { - return _mode; - } - + Scene* GetBrushScene() const override; + Guid GetBrushID() const override; + bool CanUseCSG() const override; + CSG::Mode GetBrushMode() const override; void GetSurfaces(Array& surfaces) override; - - int32 GetSurfacesCount() override - { - return 6; - } + int32 GetSurfacesCount() override; protected: From 55155630ca8cf422d4eedab5bd62be3a85ec6887 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 21:06:34 +0200 Subject: [PATCH 31/35] Fix duplicating spline #452 --- Source/Editor/Modules/SceneModule.cs | 13 ++++++++++++- Source/Editor/SceneGraph/Actors/SplineNode.cs | 2 +- Source/Editor/SceneGraph/RootNode.cs | 6 ++++++ Source/Editor/SceneGraph/SceneGraphNode.cs | 4 +++- .../Editor/Windows/Assets/PrefabWindow.Hierarchy.cs | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Modules/SceneModule.cs b/Source/Editor/Modules/SceneModule.cs index 6334225fd..86479b696 100644 --- a/Source/Editor/Modules/SceneModule.cs +++ b/Source/Editor/Modules/SceneModule.cs @@ -22,14 +22,25 @@ namespace FlaxEditor.Modules /// public class ScenesRootNode : RootNode { + private readonly Editor _editor; + + /// + public ScenesRootNode() + { + _editor = Editor.Instance; + } + /// public override void Spawn(Actor actor, Actor parent) { - Editor.Instance.SceneEditing.Spawn(actor, parent); + _editor.SceneEditing.Spawn(actor, parent); } /// public override Undo Undo => Editor.Instance.Undo; + + /// + public override List Selection => _editor.SceneEditing.Selection; } /// diff --git a/Source/Editor/SceneGraph/Actors/SplineNode.cs b/Source/Editor/SceneGraph/Actors/SplineNode.cs index b4914941a..7f9e4ca70 100644 --- a/Source/Editor/SceneGraph/Actors/SplineNode.cs +++ b/Source/Editor/SceneGraph/Actors/SplineNode.cs @@ -29,7 +29,7 @@ namespace FlaxEditor.SceneGraph.Actors public override bool CanBeSelectedDirectly => true; - public override bool CanDuplicate => true; + public override bool CanDuplicate => !Root?.Selection.Contains(ParentNode) ?? true; public override bool CanDelete => true; diff --git a/Source/Editor/SceneGraph/RootNode.cs b/Source/Editor/SceneGraph/RootNode.cs index 10af88489..485c656b1 100644 --- a/Source/Editor/SceneGraph/RootNode.cs +++ b/Source/Editor/SceneGraph/RootNode.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using System; +using System.Collections.Generic; using FlaxEditor.SceneGraph.Actors; using FlaxEngine; @@ -146,5 +147,10 @@ namespace FlaxEditor.SceneGraph /// Gets the undo. /// public abstract Undo Undo { get; } + + /// + /// Gets the list of selected scene graph nodes in the editor context. + /// + public abstract List Selection { get; } } } diff --git a/Source/Editor/SceneGraph/SceneGraphNode.cs b/Source/Editor/SceneGraph/SceneGraphNode.cs index 11c3b7709..76327918d 100644 --- a/Source/Editor/SceneGraph/SceneGraphNode.cs +++ b/Source/Editor/SceneGraph/SceneGraphNode.cs @@ -57,7 +57,9 @@ namespace FlaxEditor.SceneGraph /// public virtual RootNode Root => ParentNode?.Root; - /// + /// + /// Gets or sets the transform of the node. + /// public abstract Transform Transform { get; set; } /// diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs index e671ba1de..afba74fbc 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs @@ -36,6 +36,9 @@ namespace FlaxEditor.Windows.Assets /// public override Undo Undo => _window.Undo; + + /// + public override List Selection => _window.Selection; } /// From 3a03fe5f7f020a69bc81b73078f456e438e35cff Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 12 Apr 2021 23:26:49 +0200 Subject: [PATCH 32/35] Format code --- Source/Engine/Physics/Colliders/CharacterController.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Physics/Colliders/CharacterController.h b/Source/Engine/Physics/Colliders/CharacterController.h index 8ae992c59..e3f690f8c 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.h +++ b/Source/Engine/Physics/Colliders/CharacterController.h @@ -147,12 +147,12 @@ public: /// API_PROPERTY(Attributes="EditorOrder(240), DefaultValue(true), EditorDisplay(\"Character Controller\")") Vector3 GetUpDirection() const; - + /// /// Sets the character up vector. /// API_PROPERTY() void SetUpDirection(const Vector3& up); - + /// /// Gets the minimum move distance of the character controller. The minimum traveled distance to consider. If traveled distance is smaller, the character doesn't move. This is used to stop the recursive motion algorithm when remaining distance to travel is small. /// From a7e29c5784dcb95a84ef60f97e17d028187008c3 Mon Sep 17 00:00:00 2001 From: Tayler Mauk <44530136+TaylerMauk@users.noreply.github.com> Date: Mon, 12 Apr 2021 22:06:01 -0700 Subject: [PATCH 33/35] Fix 3D audio placement for XAudio2 and OpenAL Corrected inverted x-axis for XAudio2 Corrected inverted z-axis for OpenAL --- Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp | 2 +- Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp index 89c8f3d02..374ab646f 100644 --- a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp +++ b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp @@ -18,7 +18,7 @@ #include #include -#define FLAX_POS_TO_OAL(vec) -vec.X * 0.01f, vec.Y * 0.01f, vec.Z * 0.01f +#define FLAX_POS_TO_OAL(vec) -vec.X * 0.01f, vec.Y * 0.01f, -vec.Z * 0.01f namespace ALC { diff --git a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp index aac3979ce..a287f40f2 100644 --- a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp +++ b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp @@ -26,7 +26,7 @@ #define MAX_OUTPUT_CHANNELS 8 #define MAX_CHANNELS_MATRIX_SIZE (MAX_INPUT_CHANNELS*MAX_OUTPUT_CHANNELS) -#define FLAX_POS_TO_XAUDIO(vec) X3DAUDIO_VECTOR(-vec.X * 0.01f, vec.Y * 0.01f, vec.Z * 0.01f) +#define FLAX_POS_TO_XAUDIO(vec) X3DAUDIO_VECTOR(vec.X * 0.01f, vec.Y * 0.01f, vec.Z * 0.01f) #define FLAX_VEC_TO_XAUDIO(vec) (*((X3DAUDIO_VECTOR*)&vec)) namespace XAudio2 From af9962c30f00865472768e5d5cdbec7312dcfe6e Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 13 Apr 2021 09:28:34 +0200 Subject: [PATCH 34/35] Fix render layers mask usage for shadows rendering --- Source/Engine/Renderer/ShadowsPass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Engine/Renderer/ShadowsPass.cpp b/Source/Engine/Renderer/ShadowsPass.cpp index 0552fc598..7e1504e42 100644 --- a/Source/Engine/Renderer/ShadowsPass.cpp +++ b/Source/Engine/Renderer/ShadowsPass.cpp @@ -251,6 +251,7 @@ void ShadowsPass::Prepare(RenderContext& renderContext, GPUContext* context) auto& shadowView = _shadowContext.View; shadowView.Flags = view.Flags; shadowView.StaticFlagsMask = view.StaticFlagsMask; + shadowView.RenderLayersMask = view.RenderLayersMask; shadowView.IsOfflinePass = view.IsOfflinePass; shadowView.ModelLODBias = view.ModelLODBias + view.ShadowModelLODBias; shadowView.ModelLODDistanceFactor = view.ModelLODDistanceFactor * view.ShadowModelLODDistanceFactor; From df07529f21273df3c5310dc1ee175f4cb9bc398e Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 13 Apr 2021 09:34:23 +0200 Subject: [PATCH 35/35] Fix game build --- Source/Engine/Level/Actors/Camera.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Engine/Level/Actors/Camera.h b/Source/Engine/Level/Actors/Camera.h index ecd93cef0..505479e98 100644 --- a/Source/Engine/Level/Actors/Camera.h +++ b/Source/Engine/Level/Actors/Camera.h @@ -8,6 +8,7 @@ #include "Engine/Core/Math/Viewport.h" #include "Engine/Core/Math/Ray.h" #include "Engine/Core/Types/LayersMask.h" +#include "Engine/Scripting/ScriptingObjectReference.h" #if USE_EDITOR #include "Engine/Content/AssetReference.h" #include "Engine/Graphics/Models/ModelInstanceEntry.h"