From 17a444ad495778880091474097849823ebd6a98b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 5 Aug 2024 17:55:38 -0500 Subject: [PATCH 01/33] Fix disabled streaming audio not resetting state correctly. --- Source/Engine/Audio/AudioSource.cpp | 18 ++++++++++++++++++ Source/Engine/Audio/AudioSource.h | 1 + 2 files changed, 19 insertions(+) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index c990332a0..8ba02ab76 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -338,6 +338,7 @@ void AudioSource::PlayInternal() AudioBackend::Source::Play(this); _isActuallyPlayingSth = true; + _startingToPlay = true; } #if USE_EDITOR @@ -419,6 +420,23 @@ void AudioSource::Update() AudioBackend::Source::VelocityChanged(this); } + if (!UseStreaming() && GetTime() == GetStartTime() && _isActuallyPlayingSth && !_startingToPlay) + { + if (GetIsLooping()) + { + Stop(); + Play(); + } + else + { + Stop(); + } + } + if (_startingToPlay) + { + _startingToPlay = false; + } + // Skip other update logic if it's not valid streamable source if (!UseStreaming() || SourceIDs.IsEmpty()) return; diff --git a/Source/Engine/Audio/AudioSource.h b/Source/Engine/Audio/AudioSource.h index 450edf44a..57aab9dc8 100644 --- a/Source/Engine/Audio/AudioSource.h +++ b/Source/Engine/Audio/AudioSource.h @@ -57,6 +57,7 @@ private: bool _clipChanged = false; bool _isActuallyPlayingSth = false; + bool _startingToPlay = false; bool _needToUpdateStreamingBuffers = false; States _state = States::Stopped; From e2df50a21a9089e7c4078d95361a0f99c53a1120 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 12:02:19 -0500 Subject: [PATCH 02/33] Use visject surface description panel for material surface and anim graph surface. --- Source/Editor/Surface/AnimGraphSurface.cs | 3 +++ Source/Editor/Surface/MaterialSurface.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Source/Editor/Surface/AnimGraphSurface.cs b/Source/Editor/Surface/AnimGraphSurface.cs index 4e8b6f11e..c33224072 100644 --- a/Source/Editor/Surface/AnimGraphSurface.cs +++ b/Source/Editor/Surface/AnimGraphSurface.cs @@ -89,6 +89,9 @@ namespace FlaxEditor.Surface private static NodesCache _nodesCache = new NodesCache(IterateNodesCache); + /// + public override bool UseContextMenuDescriptionPanel => true; + /// /// The state machine editing context menu. /// diff --git a/Source/Editor/Surface/MaterialSurface.cs b/Source/Editor/Surface/MaterialSurface.cs index f21be27c0..0d6e437b8 100644 --- a/Source/Editor/Surface/MaterialSurface.cs +++ b/Source/Editor/Surface/MaterialSurface.cs @@ -25,6 +25,9 @@ namespace FlaxEditor.Surface /// public override bool CanLivePreviewValueChanges => false; + /// + public override bool UseContextMenuDescriptionPanel => true; + /// public override string GetTypeName(ScriptType type) { From 08f286253c8057cbed6ea6f430e801542827c23c Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 12:30:59 -0500 Subject: [PATCH 03/33] Handle cpp .f in bindings generator. --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 70b23502b..3bc679a80 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -142,6 +142,7 @@ namespace Flax.Build.Bindings // Numbers if (float.TryParse(value, out _) || (value[value.Length - 1] == 'f' && float.TryParse(value.Substring(0, value.Length - 1), out _))) { + value = value.Replace(".f", ".0f"); // If the value type is different than the value (eg. value is int but the field is float) then cast it for the [DefaultValue] attribute if (valueType != null && attribute) return $"({GenerateCSharpNativeToManaged(buildData, valueType, caller)}){value}"; @@ -166,7 +167,7 @@ namespace Flax.Build.Bindings foreach (var vectorType in CSharpVectorTypes) { if (value.Length > vectorType.Length + 4 && value.StartsWith(vectorType) && value[vectorType.Length] == '(') - return $"typeof({vectorType}), \"{value.Substring(vectorType.Length + 1, value.Length - vectorType.Length - 2).Replace("f", "")}\""; + return $"typeof({vectorType}), \"{value.Substring(vectorType.Length + 1, value.Length - vectorType.Length - 2).Replace(".f", "").Replace("f", "")}\""; } return null; From 002ab366fec03b8b7c121db534509761cf61872d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 12:56:08 -0500 Subject: [PATCH 04/33] Only sort surface parameters alphabetically if script member order is set to Alphabetical. --- Source/Editor/Surface/SurfaceUtils.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Surface/SurfaceUtils.cs b/Source/Editor/Surface/SurfaceUtils.cs index ad77aa510..4767cf820 100644 --- a/Source/Editor/Surface/SurfaceUtils.cs +++ b/Source/Editor/Surface/SurfaceUtils.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors.Elements; +using FlaxEditor.Options; using FlaxEditor.Scripting; using FlaxEditor.Utilities; using FlaxEngine.Utilities; @@ -247,7 +248,9 @@ namespace FlaxEditor.Surface data[i] = new GraphParameterData(null, parameter.Name, parameter.IsPublic, ToType(parameter.ParameterType), attributes, parameter); i++; } - Array.Sort(data, GraphParameterData.Compare); + if (Editor.Instance.Options.Options.General.ScriptMembersOrder == GeneralOptions.MembersOrder.Alphabetical) + Array.Sort(data, GraphParameterData.Compare); + return data; } From 36eec5bf95757009d94d9685dc91c8ca632318f6 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 13:01:28 -0500 Subject: [PATCH 05/33] Better fix --- Source/Editor/Surface/SurfaceUtils.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Surface/SurfaceUtils.cs b/Source/Editor/Surface/SurfaceUtils.cs index 4767cf820..86acf7b26 100644 --- a/Source/Editor/Surface/SurfaceUtils.cs +++ b/Source/Editor/Surface/SurfaceUtils.cs @@ -72,7 +72,12 @@ namespace FlaxEditor.Surface } // By name - return string.Compare(x.DisplayName, y.DisplayName, StringComparison.InvariantCulture); + if (Editor.Instance.Options.Options.General.ScriptMembersOrder == GeneralOptions.MembersOrder.Alphabetical) + { + return string.Compare(x.DisplayName, y.DisplayName, StringComparison.InvariantCulture); + } + // Keep same order + return 0; } } @@ -248,9 +253,7 @@ namespace FlaxEditor.Surface data[i] = new GraphParameterData(null, parameter.Name, parameter.IsPublic, ToType(parameter.ParameterType), attributes, parameter); i++; } - if (Editor.Instance.Options.Options.General.ScriptMembersOrder == GeneralOptions.MembersOrder.Alphabetical) - Array.Sort(data, GraphParameterData.Compare); - + Array.Sort(data, GraphParameterData.Compare); return data; } From 31408657807f12b1fed4aa6062d1500f48885e65 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 17:06:23 -0500 Subject: [PATCH 06/33] Add physics and lights debug drawing in prefabs when enabled. --- .../Editor/Viewport/PrefabWindowViewport.cs | 30 +++++++++++++++++-- Source/Engine/Debug/DebugDraw.cpp | 19 ++++++++++++ Source/Engine/Debug/DebugDraw.h | 19 +++++++++++- Source/Engine/Physics/Colliders/Collider.h | 8 ++--- 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index f51abb1fc..b9a654cf9 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -12,6 +12,7 @@ using FlaxEditor.Viewport.Previews; using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; +using Utils = FlaxEditor.Utilities.Utils; namespace FlaxEditor.Viewport { @@ -624,12 +625,37 @@ namespace FlaxEditor.Viewport } } - // Debug draw all actors in prefab + // Debug draw all actors in prefab and collect actors + List pActors = new List(); foreach (var child in SceneGraphRoot.ChildNodes) { if (child is not ActorNode actorNode) continue; - DebugDraw.DrawActorsTree(actorNode.Actor); + var actor = actorNode.Actor; + Utils.GetActorsTree(pActors, actor); + DebugDraw.DrawActorsTree(actor); + } + + // Draw physics debug + if ((Task.ViewFlags & ViewFlags.PhysicsDebug) != 0) + { + foreach (var actor in pActors) + { + if (actor is Collider c && c.IsActiveInHierarchy) + { + DebugDraw.DrawColliderDebugPhysics(c, renderContext.View); + } + } + } + + // Draw lights debug + if ((Task.ViewFlags & ViewFlags.LightsDebug) != 0) + { + foreach (var actor in pActors) + { + if (actor is Light l && l.IsActiveInHierarchy) + DebugDraw.DrawLightDebug(l, renderContext.View); + } } } } diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 0bb97c0b2..496b4ab1f 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -27,6 +27,8 @@ #include "Engine/Render2D/FontAsset.h" #if USE_EDITOR #include "Editor/Editor.h" +#include "Engine/Level/Actors/Light.h" +#include "Engine/Physics/Colliders/Collider.h" #endif // Debug draw service configuration @@ -950,6 +952,23 @@ void DebugDraw::DrawActorsTree(Actor* actor) actor->TreeExecute(function); } +#if USE_EDITOR +void DebugDraw::DrawColliderDebugPhysics(Collider* collider, RenderView& view) +{ + if (!collider) + return; + + collider->DrawPhysicsDebug(view); +} + +void DebugDraw::DrawLightDebug(Light* light, RenderView& view) +{ + if (!light) + return; + + light->DrawLightsDebug(view); +} +#endif void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest) { ASSERT(direction.IsNormalized()); diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index ad5bd6fa1..13b556b1b 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -8,6 +8,9 @@ #include "Engine/Core/Math/Color.h" #include "Engine/Core/Types/Span.h" +struct RenderView; +class Collider; +class Light; struct RenderContext; class GPUTextureView; class GPUContext; @@ -70,9 +73,23 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw /// /// Draws the debug shapes for the given actor and the actor's children /// - /// /// The actor to start drawing at. + /// The actor to start drawing at. API_FUNCTION() static void DrawActorsTree(Actor* actor); +#if USE_EDITOR + /// + /// Draws the physics debug shapes for the given collider. Editor Only + /// + /// The collider to draw. + /// The render view to draw in. + API_FUNCTION() static void DrawColliderDebugPhysics(Collider* collider, RenderView& view); + /// + /// Draws the light debug shapes for the given light. Editor Only + /// + /// The light debug to draw. + /// The render view to draw in. + API_FUNCTION() static void DrawLightDebug(Light* light, RenderView& view); +#endif /// /// Draws the lines axis from direction. /// diff --git a/Source/Engine/Physics/Colliders/Collider.h b/Source/Engine/Physics/Colliders/Collider.h index a1660d531..e48bfa37a 100644 --- a/Source/Engine/Physics/Colliders/Collider.h +++ b/Source/Engine/Physics/Colliders/Collider.h @@ -154,10 +154,6 @@ protected: /// void RemoveStaticActor(); -#if USE_EDITOR - virtual void DrawPhysicsDebug(RenderView& view); -#endif - private: void OnMaterialChanged(); @@ -169,6 +165,10 @@ public: void ClosestPoint(const Vector3& point, Vector3& result) const final; bool ContainsPoint(const Vector3& point) const final; +#if USE_EDITOR + virtual void DrawPhysicsDebug(RenderView& view); +#endif + protected: // [PhysicsColliderActor] void OnEnable() override; From 443bc347efdcefe7b854ddd701208d6f0c65f0be Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 17:37:04 -0500 Subject: [PATCH 07/33] Fix vector type floats from .f to .0 --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 3bc679a80..a437a4158 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -167,7 +167,7 @@ namespace Flax.Build.Bindings foreach (var vectorType in CSharpVectorTypes) { if (value.Length > vectorType.Length + 4 && value.StartsWith(vectorType) && value[vectorType.Length] == '(') - return $"typeof({vectorType}), \"{value.Substring(vectorType.Length + 1, value.Length - vectorType.Length - 2).Replace(".f", "").Replace("f", "")}\""; + return $"typeof({vectorType}), \"{value.Substring(vectorType.Length + 1, value.Length - vectorType.Length - 2).Replace(".f", ".0").Replace("f", "")}\""; } return null; From 201fa888dd8ca6e946a4f1b72686afd832c80210 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 21:39:45 -0500 Subject: [PATCH 08/33] Add comment --- Source/Engine/Audio/AudioSource.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index 8ba02ab76..00e323a63 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -432,6 +432,8 @@ void AudioSource::Update() Stop(); } } + + // Reset starting to play value if (_startingToPlay) { _startingToPlay = false; From 3186b58ba8bc6863bba7ce246ecfcdd32b84833c Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 6 Aug 2024 21:43:38 -0500 Subject: [PATCH 09/33] Change to use near equal for float compare. --- Source/Engine/Audio/AudioSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index 00e323a63..0cb0ed87b 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -420,7 +420,7 @@ void AudioSource::Update() AudioBackend::Source::VelocityChanged(this); } - if (!UseStreaming() && GetTime() == GetStartTime() && _isActuallyPlayingSth && !_startingToPlay) + if (!UseStreaming() && Math::NearEqual(GetTime(), GetStartTime()) && _isActuallyPlayingSth && !_startingToPlay) { if (GetIsLooping()) { From 03de914dbcf1a496316069cfb7bbbc2748666eee Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 7 Aug 2024 12:16:07 -0500 Subject: [PATCH 10/33] Add Requesting engine exit event. Expose Fatal erro and requesting exit to c# --- Source/Engine/Engine/Base/GameBase.cpp | 1 + Source/Engine/Engine/Engine.cpp | 3 +++ Source/Engine/Engine/Engine.h | 5 +++++ Source/Engine/Engine/Globals.h | 13 ++++++++++++- Source/Engine/Platform/Base/PlatformBase.cpp | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Engine/Base/GameBase.cpp b/Source/Engine/Engine/Base/GameBase.cpp index 5fb28a118..ea4201142 100644 --- a/Source/Engine/Engine/Base/GameBase.cpp +++ b/Source/Engine/Engine/Base/GameBase.cpp @@ -199,6 +199,7 @@ void GameBaseImpl::OnMainWindowClosed() // Request engine exit Globals::IsRequestingExit = true; + Engine::RequestingExit(); } void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContext) diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index af62e0b6e..b26cbd25a 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -70,6 +70,7 @@ Action Engine::LateFixedUpdate; Action Engine::Draw; Action Engine::Pause; Action Engine::Unpause; +Action Engine::RequestingExit; Window* Engine::MainWindow = nullptr; int32 Engine::Main(const Char* cmdLine) @@ -259,10 +260,12 @@ void Engine::RequestExit(int32 exitCode) { Globals::IsRequestingExit = true; Globals::ExitCode = exitCode; + RequestingExit(); } #else Globals::IsRequestingExit = true; Globals::ExitCode = exitCode; + RequestingExit(); #endif } diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h index 15285a07e..85ffefda0 100644 --- a/Source/Engine/Engine/Engine.h +++ b/Source/Engine/Engine/Engine.h @@ -79,6 +79,11 @@ public: /// static Action Unpause; + /// + /// Event called when the engine is requesting exit. + /// + API_EVENT() static Action RequestingExit; + public: /// diff --git a/Source/Engine/Engine/Globals.h b/Source/Engine/Engine/Globals.h index 79b4955a3..670eecd4c 100644 --- a/Source/Engine/Engine/Globals.h +++ b/Source/Engine/Engine/Globals.h @@ -2,6 +2,7 @@ #pragma once +#include "Engine/Core/Delegate.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Input/Enums.h" @@ -59,9 +60,19 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Globals); // True if fatal error occurred (engine is exiting) static bool FatalErrorOccurred; - // True if engine need to be closed + // True if engine needs to be closed static bool IsRequestingExit; + /// + /// True if engine needs to be closed + /// + API_PROPERTY() FORCE_INLINE static bool GetIsRequestingExit() { return IsRequestingExit; } + + /// + /// True if fatal error occurred (engine is exiting) + /// + API_PROPERTY() FORCE_INLINE static bool GetFatalErrorOccurred() { return FatalErrorOccurred; } + // Exit code static int32 ExitCode; diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 8a6baf4bc..6efa3c8b4 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -271,6 +271,7 @@ void PlatformBase::Fatal(const Char* msg, void* context) Globals::FatalErrorOccurred = true; Globals::IsRequestingExit = true; Globals::ExitCode = -1; + Engine::RequestingExit(); // Collect crash info (platform-dependant implementation that might collect stack trace and/or create memory dump) { From a066e0078d48518a8bf65ab933ee3fbb2bbd04b8 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 7 Aug 2024 21:14:48 +0300 Subject: [PATCH 11/33] Add `CHECK_DEBUG` soft check for non-release builds --- Source/Engine/Platform/Platform.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Platform/Platform.h b/Source/Engine/Platform/Platform.h index c0ebe93c8..eb87db85c 100644 --- a/Source/Engine/Platform/Platform.h +++ b/Source/Engine/Platform/Platform.h @@ -35,7 +35,7 @@ #endif #if ENABLE_ASSERTION -// Performs hard assertion of the expression. Crashes the engine and inserts debugger break in case of expression fail. +// Performs a hard assertion of the expression. Crashes the engine and triggers a debugger break if the expression fails. #define ASSERT(expression) \ if (!(expression)) \ { \ @@ -46,24 +46,40 @@ Platform::Assert(#expression, __FILE__, __LINE__); \ } #else +// Performs a hard assertion of the expression. Crashes the engine and triggers a debugger break if the expression fails. #define ASSERT(expression) ((void)0) #endif #if ENABLE_ASSERTION_LOW_LAYERS +// Performs a hard assertion of the expression. Crashes the engine and triggers a debugger break if the expression fails. #define ASSERT_LOW_LAYER(x) ASSERT(x) #else +// Performs a hard assertion of the expression. Crashes the engine and triggers a debugger break if the expression fails. #define ASSERT_LOW_LAYER(x) #endif -// Performs soft check of the expression. Logs the expression fail to log and returns the function call. +// Performs a soft check of the expression. Logs the expression failure and returns from the function call. #define CHECK(expression) \ if (!(expression)) \ { \ Platform::CheckFailed(#expression, __FILE__, __LINE__); \ return; \ } +// Performs a soft check of the expression. Logs the expression failure and returns from the function call using the given return value. #define CHECK_RETURN(expression, returnValue) \ if (!(expression)) \ { \ Platform::CheckFailed(#expression, __FILE__, __LINE__); \ return returnValue; \ } + +#if ENABLE_ASSERTION +// Performs a soft check of the expression. Logs the expression failure and returns from the function call. +#define CHECK_DEBUG(expression) CHECK(expression) +// Performs a soft check of the expression. Logs the expression failure and returns from the function call using the given return value. +#define CHECK_RETURN_DEBUG(expression, returnValue) CHECK_RETURN(expression, returnValue) +#else +// Performs a soft check of the expression. Logs the expression failure and returns from the function call. +#define CHECK_DEBUG(expression) ((void)0) +// Performs a soft check of the expression. Logs the expression failure and returns from the function call using the given return value. +#define CHECK_RETURN_DEBUG(expression, returnValue) ((void)0) +#endif From f759f94cfa7c35a8cacf4ddd3a37df3b88637fd2 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 7 Aug 2024 21:15:34 +0300 Subject: [PATCH 12/33] Use `CHECK_DEBUG` over `ASSERT` in normalized direction checks --- Source/Engine/Core/Math/Quaternion.cpp | 2 +- Source/Engine/Core/Math/Ray.h | 2 +- Source/Engine/Debug/DebugDraw.cpp | 4 +- Source/Engine/Physics/Colliders/Collider.cpp | 4 +- Source/Engine/Physics/Physics.cpp | 60 ++++++++++---------- Source/Engine/Terrain/TerrainPatch.cpp | 8 +-- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cpp b/Source/Engine/Core/Math/Quaternion.cpp index 5eae439dd..ab92426d7 100644 --- a/Source/Engine/Core/Math/Quaternion.cpp +++ b/Source/Engine/Core/Math/Quaternion.cpp @@ -289,7 +289,7 @@ void Quaternion::Billboard(const Float3& objectPosition, const Float3& cameraPos Quaternion Quaternion::FromDirection(const Float3& direction) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), Quaternion::Identity); Quaternion orientation; if (Float3::Dot(direction, Float3::Up) >= 0.999f) { diff --git a/Source/Engine/Core/Math/Ray.h b/Source/Engine/Core/Math/Ray.h index 2f8b4b907..7fd2e81fa 100644 --- a/Source/Engine/Core/Math/Ray.h +++ b/Source/Engine/Core/Math/Ray.h @@ -46,7 +46,7 @@ public: : Position(position) , Direction(direction) { - ASSERT(Direction.IsNormalized()); + CHECK_DEBUG(Direction.IsNormalized()); } public: diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 0bb97c0b2..46549888b 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -952,7 +952,7 @@ void DebugDraw::DrawActorsTree(Actor* actor) void DebugDraw::DrawAxisFromDirection(const Vector3& origin, const Vector3& direction, float size, float duration, bool depthTest) { - ASSERT(direction.IsNormalized()); + CHECK_DEBUG(direction.IsNormalized()); const auto rot = Quaternion::FromDirection(direction); const Vector3 up = (rot * Vector3::Up); const Vector3 forward = (rot * Vector3::Forward); @@ -978,7 +978,7 @@ void DebugDraw::DrawRay(const Vector3& origin, const Vector3& direction, const C void DebugDraw::DrawRay(const Vector3& origin, const Vector3& direction, const Color& color, float length, float duration, bool depthTest) { - ASSERT(direction.IsNormalized()); + CHECK_DEBUG(direction.IsNormalized()); if (isnan(length) || isinf(length)) return; DrawLine(origin, origin + (direction * length), color, duration, depthTest); diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index 7e0a149aa..e5c3fa861 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -71,7 +71,7 @@ void Collider::SetContactOffset(float value) bool Collider::RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); resultHitDistance = MAX_float; if (_shape == nullptr) return false; @@ -80,7 +80,7 @@ bool Collider::RayCast(const Vector3& origin, const Vector3& direction, float& r bool Collider::RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); if (_shape == nullptr) return false; return PhysicsBackend::RayCastShape(_shape, _transform.Translation, _transform.Orientation, origin, direction, hitInfo, maxDistance); diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 85298bcff..42a80d440 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -235,91 +235,91 @@ bool Physics::LineCastAll(const Vector3& start, const Vector3& end, ArrayRayCast(origin, direction, maxDistance, layerMask, hitTriggers); } bool Physics::RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->RayCast(origin, direction, hitInfo, maxDistance, layerMask, hitTriggers); } bool Physics::RayCastAll(const Vector3& origin, const Vector3& direction, Array& results, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->RayCastAll(origin, direction, results, maxDistance, layerMask, hitTriggers); } bool Physics::BoxCast(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->BoxCast(center, halfExtents, direction, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::BoxCast(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->BoxCast(center, halfExtents, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::BoxCastAll(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, Array& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->BoxCastAll(center, halfExtents, direction, results, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::SphereCast(const Vector3& center, const float radius, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->SphereCast(center, radius, direction, maxDistance, layerMask, hitTriggers); } bool Physics::SphereCast(const Vector3& center, const float radius, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->SphereCast(center, radius, direction, hitInfo, maxDistance, layerMask, hitTriggers); } bool Physics::SphereCastAll(const Vector3& center, const float radius, const Vector3& direction, Array& results, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->SphereCastAll(center, radius, direction, results, maxDistance, layerMask, hitTriggers); } 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) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->CapsuleCast(center, radius, height, direction, rotation, maxDistance, layerMask, hitTriggers); } 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) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->CapsuleCast(center, radius, height, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } 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) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->CapsuleCastAll(center, radius, height, direction, results, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->ConvexCast(center, convexMesh, scale, direction, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->ConvexCast(center, convexMesh, scale, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } bool Physics::ConvexCastAll(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, Array& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return DefaultScene->ConvexCastAll(center, convexMesh, scale, direction, results, rotation, maxDistance, layerMask, hitTriggers); } @@ -520,91 +520,91 @@ bool PhysicsScene::LineCastAll(const Vector3& start, const Vector3& end, Array& results, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::RayCastAll(_scene, origin, direction, results, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::BoxCast(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::BoxCast(_scene, center, halfExtents, direction, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::BoxCast(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::BoxCast(_scene, center, halfExtents, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::BoxCastAll(const Vector3& center, const Vector3& halfExtents, const Vector3& direction, Array& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::BoxCastAll(_scene, center, halfExtents, direction, results, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::SphereCast(const Vector3& center, const float radius, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::SphereCast(_scene, center, radius, direction, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::SphereCast(const Vector3& center, const float radius, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::SphereCast(_scene, center, radius, direction, hitInfo, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::SphereCastAll(const Vector3& center, const float radius, const Vector3& direction, Array& results, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::SphereCastAll(_scene, center, radius, direction, results, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::CapsuleCast(const Vector3& center, const float radius, const float height, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::CapsuleCast(_scene, center, radius, height, direction, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::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) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::CapsuleCast(_scene, center, radius, height, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::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) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::CapsuleCastAll(_scene, center, radius, height, direction, results, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::ConvexCast(_scene, center, convexMesh, scale, direction, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::ConvexCast(_scene, center, convexMesh, scale, direction, hitInfo, rotation, maxDistance, layerMask, hitTriggers); } bool PhysicsScene::ConvexCastAll(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, Array& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers) { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); return PhysicsBackend::ConvexCastAll(_scene, center, convexMesh, scale, direction, results, rotation, maxDistance, layerMask, hitTriggers); } diff --git a/Source/Engine/Terrain/TerrainPatch.cpp b/Source/Engine/Terrain/TerrainPatch.cpp index b7947288b..93269269a 100644 --- a/Source/Engine/Terrain/TerrainPatch.cpp +++ b/Source/Engine/Terrain/TerrainPatch.cpp @@ -1963,7 +1963,7 @@ bool TerrainPatch::UpdateCollision() bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); if (_physicsShape == nullptr) return false; Vector3 shapePos; @@ -1974,7 +1974,7 @@ bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, floa bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, Vector3& resultHitNormal, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); if (_physicsShape == nullptr) return false; Vector3 shapePos; @@ -1992,7 +1992,7 @@ bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, floa bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, TerrainChunk*& resultChunk, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); if (_physicsShape == nullptr) return false; Vector3 shapePos; @@ -2030,7 +2030,7 @@ bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, floa bool TerrainPatch::RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance) const { - ASSERT(direction.IsNormalized()); + CHECK_RETURN_DEBUG(direction.IsNormalized(), false); if (_physicsShape == nullptr) return false; Vector3 shapePos; From ddbdf479ae25d0df801d50ee8096f0e5796aa593 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 7 Aug 2024 21:16:28 +0300 Subject: [PATCH 13/33] Add assertion check for normalized rections to C# `Ray` constructor --- Source/Engine/Core/Math/Ray.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Engine/Core/Math/Ray.cs b/Source/Engine/Core/Math/Ray.cs index 3ed5e8257..8998cbb2a 100644 --- a/Source/Engine/Core/Math/Ray.cs +++ b/Source/Engine/Core/Math/Ray.cs @@ -57,6 +57,7 @@ using Real = System.Single; using System; using System.Globalization; using System.Runtime.CompilerServices; +using FlaxEngine.Assertions; namespace FlaxEngine { @@ -77,6 +78,7 @@ namespace FlaxEngine { Position = position; Direction = direction; + Assert.IsTrue(Direction.IsNormalized, "The Ray Direction was not normalized"); } /// From 830db22dcc306618f87768326d0c8df8d98c48b5 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 9 Aug 2024 09:05:53 -0500 Subject: [PATCH 14/33] Blend out of anim slots when stopped. --- .../Animations/Graph/AnimGroup.Animation.cpp | 65 ++++++++++++++++--- Source/Engine/Level/Actors/AnimatedModel.cpp | 2 +- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 7538e06b5..6763f6d5d 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -2237,8 +2237,9 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu { // Start playing animation bucket.Index = i; - bucket.TimePosition = 0.0f; - bucket.BlendInPosition = 0.0f; + // Keep bucket time position and blend in time for if blending between two anims in the same slot. + bucket.TimePosition = bucket.TimePosition; + bucket.BlendInPosition = bucket.BlendInPosition; bucket.BlendOutPosition = 0.0f; bucket.LoopsDone = 0; bucket.LoopsLeft = slot.LoopCount; @@ -2248,6 +2249,12 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu if (bucket.Index == -1 || !slots[bucket.Index].Animation->IsLoaded()) { value = tryGetValue(node->GetBox(1), Value::Null); + // Reset times if time is left over from playing between different anims in the same slot. + if (bucket.BlendInPosition > 0) + { + bucket.TimePosition = 0; + bucket.BlendInPosition = 0; + } return; } } @@ -2256,12 +2263,6 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu auto& slot = slots[bucket.Index]; Animation* anim = slot.Animation; ASSERT(slot.Animation && slot.Animation->IsLoaded()); - if (slot.Reset) - { - // Start from the begining - slot.Reset = false; - bucket.TimePosition = 0.0f; - } const float deltaTime = slot.Pause ? 0.0f : context.DeltaTime * slot.Speed; const float length = anim->GetLength(); const bool loop = bucket.LoopsLeft != 0; @@ -2285,6 +2286,54 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu // Speed is accounted for in the new time pos, so keep sample speed at 1 value = SampleAnimation(node, loop, length, 0.0f, bucket.TimePosition, newTimePos, anim, 1); bucket.TimePosition = newTimePos; + + // On animation slot stop + if (slot.Reset) + { + // Blend between last anim and new anim if found, otherwise blend back to input. + Animation* sAnim = nullptr; + for (int32 i = 0; i < slots.Count(); i++) + { + auto& s = slots[i]; + if (s.Animation && s.Name == slotName && s.Animation != slot.Animation) + { + sAnim = s.Animation; + } + } + float oldTimePos = bucket.BlendOutPosition; + bucket.BlendOutPosition += deltaTime; + bucket.BlendInPosition = bucket.BlendOutPosition; + const float alpha = bucket.BlendOutPosition / slot.BlendOutTime; + if (sAnim != nullptr) + { + auto sValue = SampleAnimation(node, false, sAnim->GetLength(), 0.0f, oldTimePos, bucket.BlendInPosition, sAnim, 1); + //value = SampleAnimationsWithBlend(node, false, length, 0.0f, bucket.TimePosition, newTimePos, anim, sAnim, 1, 1, alpha); + value = Blend(node, value, sValue, alpha, AlphaBlendMode::HermiteCubic); + } + else + { + auto input = tryGetValue(node->GetBox(1), Value::Null); + value = Blend(node, value, input, alpha, AlphaBlendMode::HermiteCubic); + } + + if (bucket.BlendOutPosition >= slot.BlendOutTime) + { + // Start from the beginning or the blend in position if next anim found. + slot.Animation = nullptr; + slot.Reset = false; + if (!sAnim) + { + bucket.TimePosition = 0; + bucket.BlendInPosition = 0; + } + else + { + bucket.TimePosition = bucket.BlendInPosition; + } + } + break; + } + if (bucket.LoopsLeft == 0 && slot.BlendOutTime > 0.0f && length - slot.BlendOutTime < bucket.TimePosition) { // Blend out diff --git a/Source/Engine/Level/Actors/AnimatedModel.cpp b/Source/Engine/Level/Actors/AnimatedModel.cpp index 2c0e8474d..0eab292c5 100644 --- a/Source/Engine/Level/Actors/AnimatedModel.cpp +++ b/Source/Engine/Level/Actors/AnimatedModel.cpp @@ -506,7 +506,7 @@ void AnimatedModel::StopSlotAnimation(const StringView& slotName, Animation* ani { if (slot.Animation == anim && slot.Name == slotName) { - slot.Animation = nullptr; + //slot.Animation = nullptr; slot.Reset = true; break; } From 588861757a30e337d62f1aebaf2403a1a3bcefee Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 9 Aug 2024 10:00:36 -0500 Subject: [PATCH 15/33] Only reset starting value once time has progressed past zero. --- Source/Engine/Audio/AudioSource.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index 0cb0ed87b..e85280f90 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -420,7 +420,15 @@ void AudioSource::Update() AudioBackend::Source::VelocityChanged(this); } - if (!UseStreaming() && Math::NearEqual(GetTime(), GetStartTime()) && _isActuallyPlayingSth && !_startingToPlay) + // Reset starting to play value once time is greater than zero + if (_startingToPlay && GetTime() > 0.0f) + { + _startingToPlay = false; + } + + int32 queuedBuffers; + AudioBackend::Source::GetQueuedBuffersCount(this, queuedBuffers); + if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && queuedBuffers > 0 && _isActuallyPlayingSth && !_startingToPlay) { if (GetIsLooping()) { @@ -433,12 +441,6 @@ void AudioSource::Update() } } - // Reset starting to play value - if (_startingToPlay) - { - _startingToPlay = false; - } - // Skip other update logic if it's not valid streamable source if (!UseStreaming() || SourceIDs.IsEmpty()) return; From a599615c1ae1839e6bd9b2b0a9f9452b6e39e052 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 9 Aug 2024 10:47:52 -0500 Subject: [PATCH 16/33] use bucket index instead of anim for check. --- Source/Engine/Animations/Graph/AnimGroup.Animation.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 6763f6d5d..831561d35 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -2294,8 +2294,11 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu Animation* sAnim = nullptr; for (int32 i = 0; i < slots.Count(); i++) { + if (bucket.Index == i) + continue; + auto& s = slots[i]; - if (s.Animation && s.Name == slotName && s.Animation != slot.Animation) + if (s.Animation && s.Name == slotName) { sAnim = s.Animation; } From e954417c2f7563d567d4acf0ba2fb2177226cc09 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 9 Aug 2024 13:31:27 -0500 Subject: [PATCH 17/33] Set EnableHRTF on audio init to match audio settings value. --- Source/Engine/Audio/Audio.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Engine/Audio/Audio.cpp b/Source/Engine/Audio/Audio.cpp index 6c2710947..a5be5a03c 100644 --- a/Source/Engine/Audio/Audio.cpp +++ b/Source/Engine/Audio/Audio.cpp @@ -237,6 +237,7 @@ bool AudioService::Init() LOG(Info, "Audio system initialization... (backend: {0})", AudioBackend::Name()); + EnableHRTF = settings->EnableHRTF; if (AudioBackend::Init()) { LOG(Warning, "Failed to initialize audio backend."); From 9d7d66f2350415b40217003f0147c58cc2c0ccfa Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 10 Aug 2024 09:19:34 -0500 Subject: [PATCH 18/33] Add check for not having right mouse button down for changing terrain gizmo sizes. --- Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs | 2 +- Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs index 447e45b81..65c7eb956 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs @@ -151,7 +151,7 @@ namespace FlaxEditor.Tools.Terrain } // Increase or decrease brush size with scroll - if (Input.GetKey(KeyboardKeys.Shift)) + if (Input.GetKey(KeyboardKeys.Shift) && !Input.GetMouseButton(MouseButton.Right)) { Mode.CurrentBrush.Size += dt * Mode.CurrentBrush.Size * Input.Mouse.ScrollDelta * 5f; } diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs index f5feef3d2..4a7ba4eaa 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs @@ -159,7 +159,7 @@ namespace FlaxEditor.Tools.Terrain } // Increase or decrease brush size with scroll - if (Input.GetKey(KeyboardKeys.Shift)) + if (Input.GetKey(KeyboardKeys.Shift) && !Input.GetMouseButton(MouseButton.Right)) { Mode.CurrentBrush.Size += dt * Mode.CurrentBrush.Size * Input.Mouse.ScrollDelta * 5f; } From 002aac08e86be4309143b34ce397f2686b1eecdd Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 10 Aug 2024 09:31:00 -0500 Subject: [PATCH 19/33] Add resizing foliage paint gizmo with shift scroll. --- Source/Editor/Tools/Foliage/PaintFoliageGizmo.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Editor/Tools/Foliage/PaintFoliageGizmo.cs b/Source/Editor/Tools/Foliage/PaintFoliageGizmo.cs index 8d20e3119..66c845a04 100644 --- a/Source/Editor/Tools/Foliage/PaintFoliageGizmo.cs +++ b/Source/Editor/Tools/Foliage/PaintFoliageGizmo.cs @@ -197,6 +197,12 @@ namespace FlaxEditor.Tools.Foliage { PaintEnd(); } + + // Increase or decrease brush size with scroll + if (Input.GetKey(KeyboardKeys.Shift) && !Input.GetMouseButton(MouseButton.Right)) + { + Mode.CurrentBrush.Size += dt * Mode.CurrentBrush.Size * Input.Mouse.ScrollDelta * 5f; + } // Perform detailed tracing to find cursor location for the foliage placement var mouseRay = Owner.MouseRay; From 94334ae52d586dfc3169fe4a4db2ab5a7c07e85d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 10 Aug 2024 10:02:31 -0500 Subject: [PATCH 20/33] Dont zoom in edit game window if shift is clicked and window is not focused --- Source/Editor/Viewport/EditorViewport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index c7b845c89..d30fb6cbc 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1612,7 +1612,7 @@ namespace FlaxEditor.Viewport _input.IsPanning = !isAltDown && mbDown && !rbDown; _input.IsRotating = !isAltDown && !mbDown && rbDown; _input.IsMoving = !isAltDown && mbDown && rbDown; - _input.IsZooming = wheelInUse && !_input.IsShiftDown; + _input.IsZooming = wheelInUse && !(_input.IsShiftDown || (!ContainsFocus && FlaxEngine.Input.GetKey(KeyboardKeys.Shift))); _input.IsOrbiting = isAltDown && lbDown && !mbDown && !rbDown; // Control move speed with RMB+Wheel From c871613616de2934ce759afa4f6ed3a636e1fc16 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 10 Aug 2024 10:30:26 -0500 Subject: [PATCH 21/33] Change terrain modes to not be visible if no terrain panel is showing --- Source/Editor/Tools/Terrain/CarveTab.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Editor/Tools/Terrain/CarveTab.cs b/Source/Editor/Tools/Terrain/CarveTab.cs index 8f5caea5f..182c09dca 100644 --- a/Source/Editor/Tools/Terrain/CarveTab.cs +++ b/Source/Editor/Tools/Terrain/CarveTab.cs @@ -113,6 +113,7 @@ namespace FlaxEditor.Tools.Terrain } _createTerrainButton.Clicked += OnCreateNewTerrainClicked; + OnSelectionChanged(); } private void OnSceneLoaded(Scene arg1, Guid arg2) @@ -159,6 +160,7 @@ namespace FlaxEditor.Tools.Terrain } _noTerrainPanel.Visible = terrain == null; + _modes.Visible = !_noTerrainPanel.Visible; } private void InitSculptMode() From ae7a21504bc6c5a0277a98eaac8baffbfdda41b8 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 10 Aug 2024 10:42:27 -0500 Subject: [PATCH 22/33] Increase Lerp node size --- Source/Editor/Surface/Archetypes/Math.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Surface/Archetypes/Math.cs b/Source/Editor/Surface/Archetypes/Math.cs index cdbcaac03..dec8def55 100644 --- a/Source/Editor/Surface/Archetypes/Math.cs +++ b/Source/Editor/Surface/Archetypes/Math.cs @@ -156,7 +156,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Lerp", Description = "Performs a linear interpolation", Flags = NodeFlags.AllGraphs, - Size = new Float2(110, 60), + Size = new Float2(150, 60), ConnectionsHints = ConnectionsHint.Numeric, IndependentBoxes = new[] { 0, 1 }, DependentBoxes = new[] { 3 }, From 9c4129a2a3efd80b3fe7dc762f87ccb5c66b504e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 11 Aug 2024 13:24:57 -0500 Subject: [PATCH 23/33] Add todo for immediate transition. --- Source/Engine/Level/Actors/AnimatedModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actors/AnimatedModel.cpp b/Source/Engine/Level/Actors/AnimatedModel.cpp index 0eab292c5..a13085651 100644 --- a/Source/Engine/Level/Actors/AnimatedModel.cpp +++ b/Source/Engine/Level/Actors/AnimatedModel.cpp @@ -506,7 +506,7 @@ void AnimatedModel::StopSlotAnimation(const StringView& slotName, Animation* ani { if (slot.Animation == anim && slot.Name == slotName) { - //slot.Animation = nullptr; + //slot.Animation = nullptr; // TODO: make an immediate version of this method and set the animation to nullptr. slot.Reset = true; break; } From ace45eabf3149e79e1058c419d970c22ff98d6ab Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 12 Aug 2024 20:36:26 -0500 Subject: [PATCH 24/33] Keep properties window scroll for actors. --- Source/Editor/Windows/PropertiesWindow.cs | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index 9c1cbec0d..23aedf46a 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -1,11 +1,13 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using System.Xml; using FlaxEditor.CustomEditors; using FlaxEditor.SceneGraph; using FlaxEditor.Viewport; +using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Windows @@ -19,6 +21,8 @@ namespace FlaxEditor.Windows { private IEnumerable undoRecordObjects; + private readonly Dictionary _actorScrollValues = new Dictionary(); + /// public override bool UseLayoutData => true; @@ -57,7 +61,46 @@ namespace FlaxEditor.Windows Presenter.GetUndoObjects += GetUndoObjects; Presenter.Features |= FeatureFlags.CacheExpandedGroups; + VScrollBar.ValueChanged += OnScrollValueChanged; Editor.SceneEditing.SelectionChanged += OnSelectionChanged; + Editor.Scene.ActorRemoved += OnActorRemoved; + } + + /// + public override void OnSceneLoaded(Scene scene, Guid sceneId) + { + base.OnSceneLoaded(scene, sceneId); + + // Clear scroll values if new scene is loaded non additively + if (Level.ScenesCount > 1) + return; + _actorScrollValues.Clear(); + } + + private void OnActorRemoved(ActorNode node) + { + _actorScrollValues.Remove(node.ID.ToString()); + } + + private void OnScrollValueChanged() + { + if (Editor.SceneEditing.SelectionCount > 1) + return; + + // Clear first 10 scroll values to keep the memory down. Dont need to cache very single value in a scene. We could expose this as a editor setting in the future. + if (_actorScrollValues.Count >= 20) + { + int i = 0; + foreach (var e in _actorScrollValues) + { + if (i >= 10) + break; + _actorScrollValues.Remove(e.Key); + i += 1; + } + } + + _actorScrollValues[Editor.SceneEditing.Selection[0].ID.ToString()] = VScrollBar.TargetValue.ToString("0"); } private IEnumerable GetUndoObjects(CustomEditorPresenter customEditorPresenter) @@ -75,6 +118,15 @@ namespace FlaxEditor.Windows undoRecordObjects = Editor.SceneEditing.Selection.ConvertAll(x => x.UndoRecordObject).Distinct(); var objects = Editor.SceneEditing.Selection.ConvertAll(x => x.EditableObject).Distinct(); Presenter.Select(objects); + + // Set scroll value of window if it exists + if (Editor.SceneEditing.SelectionCount == 1) + { + if (_actorScrollValues.TryGetValue(Editor.SceneEditing.Selection[0].ID.ToString(), out var outValue)) + VScrollBar.TargetValue = Convert.ToSingle(outValue); + else + VScrollBar.TargetValue = 0; + } } /// From 77729bc340a12b15d3971ee7bf4af5db2fdea318 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 12 Aug 2024 20:46:29 -0500 Subject: [PATCH 25/33] Remove default value comment from terrain LOD. --- Source/Engine/Terrain/Terrain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Terrain/Terrain.h b/Source/Engine/Terrain/Terrain.h index 6cf53d80b..17f4bdccd 100644 --- a/Source/Engine/Terrain/Terrain.h +++ b/Source/Engine/Terrain/Terrain.h @@ -130,7 +130,7 @@ public: } /// - /// Gets the terrain LODs distribution parameter. Adjusts terrain chunks transitions distances. Use lower value to increase terrain quality or higher value to increase performance. Default value is 0.75. + /// Gets the terrain LODs distribution parameter. Adjusts terrain chunks transitions distances. Use lower value to increase terrain quality or higher value to increase performance. /// API_PROPERTY(Attributes="EditorOrder(70), DefaultValue(0.6f), Limit(0, 5, 0.01f), EditorDisplay(\"Terrain\", \"LOD Distribution\")") FORCE_INLINE float GetLODDistribution() const @@ -139,7 +139,7 @@ public: } /// - /// Sets the terrain LODs distribution parameter. Adjusts terrain chunks transitions distances. Use lower value to increase terrain quality or higher value to increase performance. Default value is 0.75. + /// Sets the terrain LODs distribution parameter. Adjusts terrain chunks transitions distances. Use lower value to increase terrain quality or higher value to increase performance. /// API_PROPERTY() void SetLODDistribution(float value); From da4058141b124b3e8998082cd9d8edab8c5fff9e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 13 Aug 2024 14:24:43 -0500 Subject: [PATCH 26/33] Change Object Reference "None" to be grayed out instead of error orange. --- Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs index 530e8c2b1..bc31cd10b 100644 --- a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs @@ -208,7 +208,7 @@ namespace FlaxEditor.CustomEditors.Editors else { // Draw info - Render2D.DrawText(style.FontMedium, Type != null ? $"None ({Utilities.Utils.GetPropertyNameUI(Type.ToString())})" : "-", nameRect, isEnabled ? Color.OrangeRed : Color.DarkOrange, TextAlignment.Near, TextAlignment.Center); + Render2D.DrawText(style.FontMedium, Type != null ? $"None ({Utilities.Utils.GetPropertyNameUI(Type.ToString())})" : "-", nameRect, isEnabled ? style.ForegroundGrey : style.ForegroundGrey.AlphaMultiplied(0.75f), TextAlignment.Near, TextAlignment.Center); } // Draw picker button From 6f15bf720972568d26d70391f17bb9ab8d36993c Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 13 Aug 2024 15:14:07 -0500 Subject: [PATCH 27/33] Expose additional Actor virtual methods to c# --- Source/Engine/Level/Actor.h | 14 +++++++------- Source/Engine/UI/UICanvas.cpp | 6 +++--- Source/Engine/UI/UICanvas.cs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index 2a2fb1a4c..3f75557b8 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -996,37 +996,37 @@ public: /// /// Called when actor parent gets changed. /// - virtual void OnParentChanged(); + API_FUNCTION() virtual void OnParentChanged(); /// /// Called when actor transform gets changed. /// - virtual void OnTransformChanged(); + API_FUNCTION() virtual void OnTransformChanged(); /// /// Called when actor active state gets changed. /// - virtual void OnActiveChanged(); + API_FUNCTION() virtual void OnActiveChanged(); /// /// Called when actor active in tree state gets changed. /// - virtual void OnActiveInTreeChanged(); + API_FUNCTION() virtual void OnActiveInTreeChanged(); /// /// Called when order in parent children array gets changed. /// - virtual void OnOrderInParentChanged(); + API_FUNCTION() virtual void OnOrderInParentChanged(); /// /// Called when actor static flag gets changed. /// - virtual void OnStaticFlagsChanged(); + API_FUNCTION() virtual void OnStaticFlagsChanged(); /// /// Called when layer gets changed. /// - virtual void OnLayerChanged(); + API_FUNCTION() virtual void OnLayerChanged(); /// /// Called when adding object to the game. diff --git a/Source/Engine/UI/UICanvas.cpp b/Source/Engine/UI/UICanvas.cpp index d307bf7d6..a7af9c8c7 100644 --- a/Source/Engine/UI/UICanvas.cpp +++ b/Source/Engine/UI/UICanvas.cpp @@ -17,7 +17,7 @@ MMethod* UICanvas_PostDeserialize = nullptr; MMethod* UICanvas_Enable = nullptr; MMethod* UICanvas_Disable = nullptr; #if USE_EDITOR -MMethod* UICanvas_OnActiveInTreeChanged = nullptr; +MMethod* UICanvas_ActiveInTreeChanged = nullptr; #endif MMethod* UICanvas_EndPlay = nullptr; MMethod* UICanvas_ParentChanged = nullptr; @@ -49,7 +49,7 @@ UICanvas::UICanvas(const SpawnParams& params) UICanvas_Enable = mclass->GetMethod("Enable"); UICanvas_Disable = mclass->GetMethod("Disable"); #if USE_EDITOR - UICanvas_OnActiveInTreeChanged = mclass->GetMethod("OnActiveInTreeChanged"); + UICanvas_ActiveInTreeChanged = mclass->GetMethod("ActiveInTreeChanged"); #endif UICanvas_EndPlay = mclass->GetMethod("EndPlay"); UICanvas_ParentChanged = mclass->GetMethod("ParentChanged"); @@ -182,7 +182,7 @@ void UICanvas::OnTransformChanged() void UICanvas::OnActiveInTreeChanged() { - UICANVAS_INVOKE(OnActiveInTreeChanged); + UICANVAS_INVOKE(ActiveInTreeChanged); // Base Actor::OnActiveInTreeChanged(); diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index 0ddac70e1..9ca2a9ed8 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -773,7 +773,7 @@ namespace FlaxEngine } #if FLAX_EDITOR - internal void OnActiveInTreeChanged() + internal void ActiveInTreeChanged() { if (RenderMode == CanvasRenderMode.ScreenSpace && _editorRoot != null && _guiRoot != null) { From 1ca7261f063cd03e5be4c62eae9c6d73619d823a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 13 Aug 2024 16:49:34 -0500 Subject: [PATCH 28/33] Add description to cm in Particle emitter surface. --- Source/Editor/Surface/ParticleEmitterSurface.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/Surface/ParticleEmitterSurface.cs b/Source/Editor/Surface/ParticleEmitterSurface.cs index 6bf08dd3c..d334fdc2b 100644 --- a/Source/Editor/Surface/ParticleEmitterSurface.cs +++ b/Source/Editor/Surface/ParticleEmitterSurface.cs @@ -24,6 +24,9 @@ namespace FlaxEditor.Surface /// public FlaxEditor.Surface.Archetypes.Particles.ParticleEmitterNode RootNode => _rootNode; + /// + public override bool UseContextMenuDescriptionPanel => true; + /// public ParticleEmitterSurface(IVisjectSurfaceOwner owner, Action onSave, FlaxEditor.Undo undo) : base(owner, onSave, undo) From 45e83d6d153b4b28056c170a4693763bd31fb050 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 15 Aug 2024 13:01:40 +0200 Subject: [PATCH 29/33] Add feedback from PVS (static code analyzer) https://pvs-studio.com/en/blog/posts/cpp/1153/ --- Source/Editor/Content/Items/AssetItem.cs | 2 +- Source/Editor/GUI/Dialogs/Dialog.cs | 2 +- Source/Editor/Surface/VisjectSurface.Input.cs | 2 +- Source/Editor/Utilities/MemberComparison.cs | 2 +- Source/Engine/Content/Storage/FlaxStorage.cpp | 6 +++--- Source/Engine/Core/Math/Matrix2x2.cs | 4 ++-- Source/Engine/Core/Types/DataContainer.h | 7 +++---- Source/Engine/Core/Types/Variant.cpp | 4 ++-- Source/Engine/UI/GUI/WindowRootControl.cs | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs index b1a4996eb..466ef5c3f 100644 --- a/Source/Editor/Content/Items/AssetItem.cs +++ b/Source/Editor/Content/Items/AssetItem.cs @@ -80,7 +80,7 @@ namespace FlaxEditor.Content // Translate asset type name var typeName = TypeName; string[] typeNamespaces = typeName.Split('.'); - if (typeNamespaces.Length != 0 && typeNamespaces.Length != 0) + if (typeNamespaces.Length != 0 && typeNamespaces[typeNamespaces.Length - 1].Length != 0) { typeName = Utilities.Utils.GetPropertyNameUI(typeNamespaces[typeNamespaces.Length - 1]); } diff --git a/Source/Editor/GUI/Dialogs/Dialog.cs b/Source/Editor/GUI/Dialogs/Dialog.cs index 9d1461074..863ca1484 100644 --- a/Source/Editor/GUI/Dialogs/Dialog.cs +++ b/Source/Editor/GUI/Dialogs/Dialog.cs @@ -22,7 +22,7 @@ namespace FlaxEditor.GUI.Dialogs /// /// The parent window. /// - protected Window _window; + protected volatile Window _window; /// /// The dialog result. diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs index a867eec3d..9b6f86bcb 100644 --- a/Source/Editor/Surface/VisjectSurface.Input.cs +++ b/Source/Editor/Surface/VisjectSurface.Input.cs @@ -492,7 +492,7 @@ namespace FlaxEditor.Surface Focus(); return true; } - if (_rightMouseDown || (_middleMouseDown && _middleMouseDown)) + if (_rightMouseDown || _middleMouseDown) { // Start navigating StartMouseCapture(); diff --git a/Source/Editor/Utilities/MemberComparison.cs b/Source/Editor/Utilities/MemberComparison.cs index 0de7a682c..18d12c263 100644 --- a/Source/Editor/Utilities/MemberComparison.cs +++ b/Source/Editor/Utilities/MemberComparison.cs @@ -79,7 +79,7 @@ namespace FlaxEditor.Utilities value = Convert.ToInt32(value); else if (type.Type == typeof(long)) value = Convert.ToInt64(value); - else if (type.Type == typeof(int)) + else if (type.Type == typeof(ushort)) value = Convert.ToUInt16(value); else if (type.Type == typeof(uint)) value = Convert.ToUInt32(value); diff --git a/Source/Engine/Content/Storage/FlaxStorage.cpp b/Source/Engine/Content/Storage/FlaxStorage.cpp index c3e377110..f8c466deb 100644 --- a/Source/Engine/Content/Storage/FlaxStorage.cpp +++ b/Source/Engine/Content/Storage/FlaxStorage.cpp @@ -662,13 +662,13 @@ bool FlaxStorage::LoadAssetChunk(FlaxChunk* chunk) if (!failed) { stream->SetPosition(chunk->LocationInFile.Address); + if (!stream->HasError()) + break; } - if (!stream->HasError()) - break; } } - if (stream->HasError()) + if (!stream || stream->HasError()) { failed = true; UnlockChunks(); diff --git a/Source/Engine/Core/Math/Matrix2x2.cs b/Source/Engine/Core/Math/Matrix2x2.cs index fc4f52c74..862bd8f5a 100644 --- a/Source/Engine/Core/Math/Matrix2x2.cs +++ b/Source/Engine/Core/Math/Matrix2x2.cs @@ -94,8 +94,8 @@ namespace FlaxEngine throw new ArgumentOutOfRangeException(nameof(values), "There must be sixteen and only four input values for Matrix2x2."); M11 = values[0]; M12 = values[1]; - M21 = values[3]; - M22 = values[4]; + M21 = values[2]; + M22 = values[3]; } /// diff --git a/Source/Engine/Core/Types/DataContainer.h b/Source/Engine/Core/Types/DataContainer.h index 6ad6f75c9..7893eb1ca 100644 --- a/Source/Engine/Core/Types/DataContainer.h +++ b/Source/Engine/Core/Types/DataContainer.h @@ -324,15 +324,14 @@ public: { if (length <= 0) return; - if (Base::Length() == 0) + auto prev = Base::_data; + const auto prevLength = Base::_length; + if (prevLength == 0 || prev == nullptr) { Copy(data, length); return; } - auto prev = Base::_data; - const auto prevLength = Base::_length; - Base::_length = prevLength + length; Base::_data = (T*)Allocator::Allocate(Base::_length * sizeof(T)); diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index 7061567f7..3dd403d5f 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -2702,8 +2702,8 @@ void Variant::SetAsset(Asset* asset) SetType(VariantType(VariantType::Asset)); if (AsAsset) { - asset->OnUnloaded.Unbind(this); - asset->RemoveReference(); + AsAsset->OnUnloaded.Unbind(this); + AsAsset->RemoveReference(); } AsAsset = asset; if (asset) diff --git a/Source/Engine/UI/GUI/WindowRootControl.cs b/Source/Engine/UI/GUI/WindowRootControl.cs index 72ae2ade3..e6a86e64e 100644 --- a/Source/Engine/UI/GUI/WindowRootControl.cs +++ b/Source/Engine/UI/GUI/WindowRootControl.cs @@ -77,7 +77,7 @@ namespace FlaxEngine.GUI /// public void Hide() { - _window.Show(); + _window.Hide(); } /// From a6b4f2fc63d4b520d63bf4ccd66825a33becc0a7 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Aug 2024 08:07:04 -0500 Subject: [PATCH 30/33] Remove extra include. --- Source/Engine/Engine/Globals.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Engine/Engine/Globals.h b/Source/Engine/Engine/Globals.h index 670eecd4c..5e58d5039 100644 --- a/Source/Engine/Engine/Globals.h +++ b/Source/Engine/Engine/Globals.h @@ -2,7 +2,6 @@ #pragma once -#include "Engine/Core/Delegate.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Input/Enums.h" From 51bf5cd1bf2516d28158b5844de0643bc31fb0b0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 15 Aug 2024 15:16:32 +0200 Subject: [PATCH 31/33] Fix to not call `GetQueuedBuffersCount` unless needed for the looping fix #2834 --- Source/Engine/Audio/AudioSource.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index e85280f90..719961604 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -426,18 +426,21 @@ void AudioSource::Update() _startingToPlay = false; } - int32 queuedBuffers; - AudioBackend::Source::GetQueuedBuffersCount(this, queuedBuffers); - if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && queuedBuffers > 0 && _isActuallyPlayingSth && !_startingToPlay) + if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && _isActuallyPlayingSth && !_startingToPlay) { - if (GetIsLooping()) + int32 queuedBuffers; + AudioBackend::Source::GetQueuedBuffersCount(this, queuedBuffers); + if (queuedBuffers) { - Stop(); - Play(); - } - else - { - Stop(); + if (GetIsLooping()) + { + Stop(); + Play(); + } + else + { + Stop(); + } } } From 7ded585c0baf58978672533368dee03720361fb1 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 15 Aug 2024 15:31:04 +0200 Subject: [PATCH 32/33] Improve debug shapes drawing #2833 --- .../Editor/Viewport/PrefabWindowViewport.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index b9a654cf9..ceba98073 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -63,6 +63,7 @@ namespace FlaxEditor.Viewport private UpdateDelegate _update; private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32); + private readonly List _debugDrawActors = new List(); private PrefabSpritesRenderer _spritesRenderer; private IntPtr _tempDebugDrawContext; @@ -624,22 +625,25 @@ namespace FlaxEditor.Viewport DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount, false); } } - + // Debug draw all actors in prefab and collect actors - List pActors = new List(); + var viewFlags = Task.ViewFlags; + var collectActors = (viewFlags & ViewFlags.PhysicsDebug) != 0 || (viewFlags & ViewFlags.LightsDebug) != 0; + _debugDrawActors.Clear(); foreach (var child in SceneGraphRoot.ChildNodes) { if (child is not ActorNode actorNode) continue; var actor = actorNode.Actor; - Utils.GetActorsTree(pActors, actor); + if (collectActors) + Utils.GetActorsTree(_debugDrawActors, actor); DebugDraw.DrawActorsTree(actor); } - + // Draw physics debug - if ((Task.ViewFlags & ViewFlags.PhysicsDebug) != 0) + if ((viewFlags & ViewFlags.PhysicsDebug) != 0) { - foreach (var actor in pActors) + foreach (var actor in _debugDrawActors) { if (actor is Collider c && c.IsActiveInHierarchy) { @@ -647,16 +651,18 @@ namespace FlaxEditor.Viewport } } } - + // Draw lights debug - if ((Task.ViewFlags & ViewFlags.LightsDebug) != 0) + if ((viewFlags & ViewFlags.LightsDebug) != 0) { - foreach (var actor in pActors) + foreach (var actor in _debugDrawActors) { if (actor is Light l && l.IsActiveInHierarchy) DebugDraw.DrawLightDebug(l, renderContext.View); } } + + _debugDrawActors.Clear(); } } } From dcffb422e57b6f3488bb7f04b4da113c2488da0e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Aug 2024 08:37:00 -0500 Subject: [PATCH 33/33] Change actor scroll cache to use guid and float instead of strings, remove onactor removed code to keep values after undo. --- Source/Editor/Windows/PropertiesWindow.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index 23aedf46a..423d3af18 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -21,7 +21,7 @@ namespace FlaxEditor.Windows { private IEnumerable undoRecordObjects; - private readonly Dictionary _actorScrollValues = new Dictionary(); + private readonly Dictionary _actorScrollValues = new Dictionary(); /// public override bool UseLayoutData => true; @@ -63,7 +63,6 @@ namespace FlaxEditor.Windows VScrollBar.ValueChanged += OnScrollValueChanged; Editor.SceneEditing.SelectionChanged += OnSelectionChanged; - Editor.Scene.ActorRemoved += OnActorRemoved; } /// @@ -77,11 +76,6 @@ namespace FlaxEditor.Windows _actorScrollValues.Clear(); } - private void OnActorRemoved(ActorNode node) - { - _actorScrollValues.Remove(node.ID.ToString()); - } - private void OnScrollValueChanged() { if (Editor.SceneEditing.SelectionCount > 1) @@ -100,7 +94,7 @@ namespace FlaxEditor.Windows } } - _actorScrollValues[Editor.SceneEditing.Selection[0].ID.ToString()] = VScrollBar.TargetValue.ToString("0"); + _actorScrollValues[Editor.SceneEditing.Selection[0].ID] = VScrollBar.TargetValue; } private IEnumerable GetUndoObjects(CustomEditorPresenter customEditorPresenter) @@ -121,12 +115,7 @@ namespace FlaxEditor.Windows // Set scroll value of window if it exists if (Editor.SceneEditing.SelectionCount == 1) - { - if (_actorScrollValues.TryGetValue(Editor.SceneEditing.Selection[0].ID.ToString(), out var outValue)) - VScrollBar.TargetValue = Convert.ToSingle(outValue); - else - VScrollBar.TargetValue = 0; - } + VScrollBar.TargetValue = _actorScrollValues.GetValueOrDefault(Editor.SceneEditing.Selection[0].ID, 0); } ///