From cb59f2185cca6281200288fd8c98f579f13ac54c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 16 Jul 2021 13:08:37 +0200 Subject: [PATCH] Add memory usage info to Animation details --- Source/Editor/Windows/Assets/AnimationWindow.cs | 1 + Source/Engine/Animations/Curve.h | 3 --- Source/Engine/Content/Assets/Animation.cpp | 13 +++++++++++++ Source/Engine/Content/Assets/Animation.h | 11 +++++------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Windows/Assets/AnimationWindow.cs b/Source/Editor/Windows/Assets/AnimationWindow.cs index 5665a87ce..b6742c984 100644 --- a/Source/Editor/Windows/Assets/AnimationWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationWindow.cs @@ -75,6 +75,7 @@ namespace FlaxEditor.Windows.Assets group.Label("Frames: " + info.FramesCount); group.Label("Channels: " + info.ChannelsCount); group.Label("Keyframes: " + info.KeyframesCount); + group.Label("Memory Usage: " + Utilities.Utils.FormatBytesCount(info.MemoryUsage)); } // Import Settings diff --git a/Source/Engine/Animations/Curve.h b/Source/Engine/Animations/Curve.h index be5c268ef..8564f6912 100644 --- a/Source/Engine/Animations/Curve.h +++ b/Source/Engine/Animations/Curve.h @@ -564,7 +564,6 @@ public: /// /// Gets the keyframes collection (for read-only). /// - /// The keyframes. FORCE_INLINE const KeyFrameCollection& GetKeyframes() const { return _keyframes; @@ -573,7 +572,6 @@ public: /// /// Gets the keyframes collection. /// - /// The keyframes. FORCE_INLINE KeyFrameCollection& GetKeyframes() { return _keyframes; @@ -582,7 +580,6 @@ public: /// /// Determines whether this curve is empty (has no keyframes). /// - /// true if this curve is empty; otherwise, false. FORCE_INLINE bool IsEmpty() const { return _keyframes.IsEmpty(); diff --git a/Source/Engine/Content/Assets/Animation.cpp b/Source/Engine/Content/Assets/Animation.cpp index f45bceae3..468669a5c 100644 --- a/Source/Engine/Content/Assets/Animation.cpp +++ b/Source/Engine/Content/Assets/Animation.cpp @@ -21,13 +21,23 @@ Animation::Animation(const SpawnParams& params, const AssetInfo* info) Animation::InfoData Animation::GetInfo() const { + ScopeLock lock(Locker); InfoData info; + info.MemoryUsage = sizeof(Animation); if (IsLoaded()) { info.Length = Data.GetLength(); info.FramesCount = (int32)Data.Duration; info.ChannelsCount = Data.Channels.Count(); info.KeyframesCount = Data.GetKeyframesCount(); + info.MemoryUsage += Data.Channels.Capacity() * sizeof(NodeAnimationData); + for (auto& e : Data.Channels) + { + info.MemoryUsage += (e.NodeName.Length() + 1) * sizeof(Char); + info.MemoryUsage += e.Position.GetKeyframes().Capacity() * sizeof(LinearCurveKeyframe); + info.MemoryUsage += e.Rotation.GetKeyframes().Capacity() * sizeof(LinearCurveKeyframe); + info.MemoryUsage += e.Scale.GetKeyframes().Capacity() * sizeof(LinearCurveKeyframe); + } } else { @@ -36,6 +46,9 @@ Animation::InfoData Animation::GetInfo() const info.ChannelsCount = 0; info.KeyframesCount = 0; } + info.MemoryUsage += MappingCache.Capacity() * (sizeof(void*) + sizeof(NodeToChannel) + 1); + for (auto& e : MappingCache) + info.MemoryUsage += e.Value.Capacity() * sizeof(int32); return info; } diff --git a/Source/Engine/Content/Assets/Animation.h b/Source/Engine/Content/Assets/Animation.h index 6ce114867..0bdb9bdd4 100644 --- a/Source/Engine/Content/Assets/Animation.h +++ b/Source/Engine/Content/Assets/Animation.h @@ -15,8 +15,6 @@ API_CLASS(NoSpawn) class FLAXENGINE_API Animation : public BinaryAsset { DECLARE_BINARY_ASSET_HEADER(Animation, 1); -public: - /// /// Contains basic information about the animation asset contents. /// @@ -43,6 +41,11 @@ public: /// The total amount of keyframes in the animation tracks. /// API_FIELD() int32 KeyframesCount; + + /// + /// The estimated memory usage (in bytes) of the animation (all tracks and keyframes size in memory). + /// + API_FIELD() int32 MemoryUsage; }; public: @@ -68,7 +71,6 @@ public: /// /// Gets the length of the animation (in seconds). /// - /// The length in seconds. API_PROPERTY() float GetLength() const { return IsLoaded() ? Data.GetLength() : 0.0f; @@ -77,7 +79,6 @@ public: /// /// Gets the duration of the animation (in frames). /// - /// The duration in frames. API_PROPERTY() float GetDuration() const { return (float)Data.Duration; @@ -86,7 +87,6 @@ public: /// /// Gets the amount of the animation frames per second. /// - /// The frames per second. API_PROPERTY() float GetFramesPerSecond() const { return (float)Data.FramesPerSecond; @@ -95,7 +95,6 @@ public: /// /// Gets the animation clip info. /// - /// The animation info. API_PROPERTY() InfoData GetInfo() const; ///